source: src/gui/searchtabcontainer.cpp @ 6df32f2

qt5
Last change on this file since 6df32f2 was 6df32f2, checked in by gregor herrmann <gregoa@…>, 10 years ago

Update GPL blurb in source files.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 *
4 * This file is part of ConfClerk.
5 *
6 * ConfClerk is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * ConfClerk is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "searchtabcontainer.h"
21#include "searchhead.h"
22#include <QMessageBox>
23
24SearchTabContainer::SearchTabContainer(QWidget *aParent) : TabContainer( aParent )
25{
26    header = new SearchHead(this);
27    header->setObjectName(QString::fromUtf8("header"));
28    QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
29    sizePolicy.setHorizontalStretch(0);
30    sizePolicy.setVerticalStretch(0);
31    //sizePolicy.setHeightForWidth(TabContainer::sizePolicy().hasHeightForWidth());
32    sizePolicy.setHeightForWidth(header->sizePolicy().hasHeightForWidth());
33    header->setSizePolicy(sizePolicy);
34    header->setMinimumSize(QSize(10, 10));
35
36    verticalLayout->insertWidget(0,header);
37
38    header->show();
39
40    searchAgainButton = new QToolButton(this);
41    searchAgainButton->setObjectName(QString::fromUtf8("button"));
42    QIcon icon;
43    icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/search.png")), QIcon::Normal, QIcon::Off);
44    searchAgainButton->setIcon(icon);
45    QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Minimum);
46    sizePolicy1.setHorizontalStretch(0);
47    sizePolicy1.setVerticalStretch(0);
48    sizePolicy1.setHeightForWidth(searchAgainButton->sizePolicy().hasHeightForWidth());
49    searchAgainButton->setSizePolicy(sizePolicy1);
50
51    verticalLayout_2->insertWidget(0,searchAgainButton);
52
53    searchAgainButton->hide();
54    treeView->hide();
55    // do not show 'search' header if there are no conferences in the DB
56    if(Conference::getAll().count()==0)
57    {
58        header->hide();
59    }
60
61    connect( header, SIGNAL(searchClicked()), SLOT(searchButtonClicked()));
62    connect( searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
63}
64
65SearchTabContainer::~SearchTabContainer()
66{
67}
68
69void SearchTabContainer::searchButtonClicked()
70{
71    QHash<QString,QString> columns;
72
73    SearchHead *searchHeader = static_cast<SearchHead*>(header);
74    if( searchHeader->searchTitle->isChecked() )
75        columns.insertMulti("EVENT", "title");
76    if( searchHeader->searchAbstract->isChecked() )
77        columns.insertMulti("EVENT", "abstract");
78    if( searchHeader->searchTag->isChecked() )
79        columns.insertMulti("EVENT", "tag");
80    if( searchHeader->searchSpeaker->isChecked() )
81        columns["PERSON"] = "name";
82    if( searchHeader->searchRoom->isChecked() )
83        columns["ROOM"] = "name";
84
85    QString keyword = searchHeader->searchEdit->text().replace( QString("%"), QString("\\%") );
86    //qDebug() << "\nKeyword to search: " << keyword;
87
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();
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    }
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{
150    static_cast<EventModel*>(treeView->model())->loadSearchResultEvents( aDate, aConferenceId );
151}
152
Note: See TracBrowser for help on using the repository browser.