source: src/gui/searchtabcontainer.cpp @ f48bf9f

qt5
Last change on this file since f48bf9f was f48bf9f, checked in by Philipp Spitzer <philipp@…>, 11 years ago

The '%' character doesn't have to be escaped anymore.

  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[ca90cb1]1/*
2 * Copyright (C) 2010 Ixonos Plc.
[68b2df2]3 * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
[ca90cb1]4 *
[6df32f2]5 * This file is part of ConfClerk.
[ca90cb1]6 *
[6df32f2]7 * ConfClerk is free software: you can redistribute it and/or modify it
[ca90cb1]8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 2 of the License, or (at your option)
10 * any later version.
11 *
[6df32f2]12 * ConfClerk is distributed in the hope that it will be useful, but
[ca90cb1]13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
[6df32f2]18 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
[ca90cb1]19 */
[07ae23a]20
21#include "searchtabcontainer.h"
22#include "searchhead.h"
[bcf67d6]23#include <QMessageBox>
[07ae23a]24
25SearchTabContainer::SearchTabContainer(QWidget *aParent) : TabContainer( aParent )
26{
27    header = new SearchHead(this);
28    header->setObjectName(QString::fromUtf8("header"));
[b667db5]29    QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
[07ae23a]30    sizePolicy.setHorizontalStretch(0);
31    sizePolicy.setVerticalStretch(0);
32    //sizePolicy.setHeightForWidth(TabContainer::sizePolicy().hasHeightForWidth());
33    sizePolicy.setHeightForWidth(header->sizePolicy().hasHeightForWidth());
34    header->setSizePolicy(sizePolicy);
35    header->setMinimumSize(QSize(10, 10));
36
37    verticalLayout->insertWidget(0,header);
38
39    header->show();
40
41    searchAgainButton = new QToolButton(this);
42    searchAgainButton->setObjectName(QString::fromUtf8("button"));
43    QIcon icon;
44    icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/search.png")), QIcon::Normal, QIcon::Off);
45    searchAgainButton->setIcon(icon);
46    QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Minimum);
47    sizePolicy1.setHorizontalStretch(0);
48    sizePolicy1.setVerticalStretch(0);
49    sizePolicy1.setHeightForWidth(searchAgainButton->sizePolicy().hasHeightForWidth());
50    searchAgainButton->setSizePolicy(sizePolicy1);
51
52    verticalLayout_2->insertWidget(0,searchAgainButton);
53
[b667db5]54    searchAgainButton->hide();
55    treeView->hide();
[bb6f7d6]56    // do not show 'search' header if there are no conferences in the DB
57    if(Conference::getAll().count()==0)
58    {
59        header->hide();
60    }
[07ae23a]61
62    connect( header, SIGNAL(searchClicked()), SLOT(searchButtonClicked()));
63    connect( searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
64}
65
66SearchTabContainer::~SearchTabContainer()
67{
68}
69
70void SearchTabContainer::searchButtonClicked()
71{
72    QHash<QString,QString> columns;
73
74    SearchHead *searchHeader = static_cast<SearchHead*>(header);
75    if( searchHeader->searchTitle->isChecked() )
76        columns.insertMulti("EVENT", "title");
77    if( searchHeader->searchAbstract->isChecked() )
78        columns.insertMulti("EVENT", "abstract");
79    if( searchHeader->searchTag->isChecked() )
80        columns.insertMulti("EVENT", "tag");
81    if( searchHeader->searchSpeaker->isChecked() )
82        columns["PERSON"] = "name";
83    if( searchHeader->searchRoom->isChecked() )
84        columns["ROOM"] = "name";
85
[f48bf9f]86    QString keyword = searchHeader->searchEdit->text();
[07ae23a]87
[0bb39f5]88    int confId = Conference::activeConference();
89    SqlEngine::searchEvent( confId, columns, keyword );
90
91    QDate startDate = Conference::getById(confId).start();
92    QDate endDate = Conference::getById(confId).end();
[bcf67d6]93
94    int nrofFounds = 0;
95    QDate firstDateWithFounds = endDate;
96    QDate lastDateWithFounds = startDate;
97    for(QDate d=startDate; d<=endDate; d=d.addDays(1))
98    {
99        try{
100            int count = Event::getSearchResultByDate(d, confId, "start").count();
101            if(count && (firstDateWithFounds==endDate))
102                firstDateWithFounds=d;
103            if(count)
104                lastDateWithFounds=d;
105            nrofFounds+=count;
106        }
107        catch( OrmException &e  ){
108            qDebug() << "Event::getSearchResultByDate failed: " << e.text();
109        }
110        catch(...){
111            qDebug() << "Event::getSearchResultByDate failed";
112        }
113    }
114
115    if(!nrofFounds)
116    {
117        // TODO: display some message
118        treeView->hide();
119        searchAgainButton->hide();
120        dayNavigator->hide();
121        header->show();
122        QMessageBox::information(
123                this,
124                QString("Keyword '%1' not found!").arg(keyword),
125                QString("No events containing '%1' found!").arg(keyword),
126                QMessageBox::Ok);
127    }
128    else
129    {
130        searchAgainButton->show();
131        dayNavigator->show();
132        treeView->show();
133        header->hide();
134
135        updateTreeView( firstDateWithFounds );
136        dayNavigator->setDates(firstDateWithFounds, lastDateWithFounds);
137    }
[07ae23a]138}
139
140void SearchTabContainer::searchAgainClicked()
141{
142    header->show();
143    searchAgainButton->hide();
144    dayNavigator->hide();
145    treeView->hide();
146}
147
148void SearchTabContainer::loadEvents( const QDate &aDate, const int aConferenceId )
149{
[bcf67d6]150    static_cast<EventModel*>(treeView->model())->loadSearchResultEvents( aDate, aConferenceId );
[07ae23a]151}
[bcf67d6]152
Note: See TracBrowser for help on using the repository browser.