From ac2b0b28c916db1e80c8f2c436e0351acad140b1 Mon Sep 17 00:00:00 2001 From: Philipp Spitzer Date: Mon, 12 Dec 2011 19:59:00 +0000 Subject: [PATCH] The search result is now synced with the daynavigator. When the search result is not on the current date, the date is changed. --- src/gui/daynavigatorwidget.h | 2 ++ src/gui/mainwindow.cpp | 26 +++++++++++++++++++++ src/gui/mainwindow.h | 1 + src/gui/searchtabcontainer.cpp | 42 +++++++++++----------------------- src/gui/searchtabcontainer.h | 5 ++++ 5 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/gui/daynavigatorwidget.h b/src/gui/daynavigatorwidget.h index e16017c..a06d8b1 100644 --- a/src/gui/daynavigatorwidget.h +++ b/src/gui/daynavigatorwidget.h @@ -34,7 +34,9 @@ class DayNavigatorWidget : public QWidget, private Ui::DayNavigatorWidget { ~DayNavigatorWidget() {} void setDates(const QDate &aStartDate, const QDate &aEndDate); void setCurDate(const QDate& curDate); + QDate startDate() const {return mStartDate;} QDate curDate() const {return mCurDate;} + QDate endDate() const {return mEndDate;} void unsetDates(); protected: void paintEvent(QPaintEvent *); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index b9969a9..c6505ad 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -97,6 +97,10 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) connect(dayNavigator, SIGNAL(dateChanged(QDate)), roomsTabContainer, SLOT(redisplayDate(QDate))); connect(dayNavigator, SIGNAL(dateChanged(QDate)), searchTabContainer, SLOT(redisplayDate(QDate))); + // search result has changed + connect(searchTabContainer, SIGNAL(searchResultChanged()), SLOT(onSearchResultChanged())); + + useConference(Conference::activeConference()); // optimization, see useConference() code try { @@ -172,6 +176,28 @@ void MainWindow::onEventChanged(int aEventId, bool favouriteChanged) { } +void MainWindow::onSearchResultChanged() { + // Are results found on the current date? + QDate date = dayNavigator->curDate(); + int count = searchTabContainer->searchResultCount(date); + if (count > 0) {searchTabContainer->redisplayDate(date); return;} + + // Are results found in the future? + for (date = date.addDays(1); date <= dayNavigator->endDate(); date = date.addDays(1)) { + int count = searchTabContainer->searchResultCount(date); + if (count > 0) {dayNavigator->setCurDate(date); return;} + } + + // Are results found in the past? + for (date = dayNavigator->startDate(); date < dayNavigator->curDate(); date = date.addDays(1)) { + int count = searchTabContainer->searchResultCount(date); + if (count > 0) {dayNavigator->setCurDate(date); return;} + } + // No results were found + searchTabContainer->redisplayDate(dayNavigator->curDate()); +} + + void MainWindow::useConference(int id) { if (id == -1) // in case no conference is active diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 127620d..42dfbb7 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -49,6 +49,7 @@ private slots: void on_searchAction_triggered(); void onEventChanged(int aEventId, bool favouriteChanged); + void onSearchResultChanged(); // TODO: remove void networkQueryFinished(QNetworkReply*); void importFromNetwork(const QString&); diff --git a/src/gui/searchtabcontainer.cpp b/src/gui/searchtabcontainer.cpp index 86c9fcc..3abc8e5 100644 --- a/src/gui/searchtabcontainer.cpp +++ b/src/gui/searchtabcontainer.cpp @@ -39,6 +39,13 @@ SearchTabContainer::SearchTabContainer(QWidget *aParent) : TabContainer( aParent } +int SearchTabContainer::searchResultCount(const QDate& date) const { + int confId = Conference::activeConference(); + if (confId == -1) return 0; + return Event::getSearchResultByDate(date, confId, "start, duration").count(); +} + + void SearchTabContainer::showSearchDialog() { header->show(); treeView->hide(); @@ -64,36 +71,15 @@ void SearchTabContainer::searchButtonClicked() { int confId = Conference::activeConference(); if (confId == -1) return; + Conference conf = Conference::getById(confId); SqlEngine::searchEvent( confId, columns, keyword ); - QDate startDate = Conference::getById(confId).start(); - QDate endDate = Conference::getById(confId).end(); - int nrofFounds = 0; - QDate firstDateWithFounds = endDate; - QDate lastDateWithFounds = startDate; - for(QDate d=startDate; d<=endDate; d=d.addDays(1)) - { - try{ - int count = Event::getSearchResultByDate(d, confId, "start, duration").count(); - if(count && (firstDateWithFounds==endDate)) - firstDateWithFounds=d; - if(count) - lastDateWithFounds=d; - nrofFounds+=count; - } - catch( OrmException &e ){ - qDebug() << "Event::getSearchResultByDate failed: " << e.text(); - } - catch(...){ - qDebug() << "Event::getSearchResultByDate failed"; - } - } + for (QDate d = conf.start(); d <= conf.end(); d = d.addDays(1)) + nrofFounds += Event::getSearchResultByDate(d, confId, "start, duration").count(); - if(!nrofFounds) - { - // TODO: display some message + if (!nrofFounds) { treeView->hide(); header->show(); QMessageBox::information( @@ -101,13 +87,11 @@ void SearchTabContainer::searchButtonClicked() { QString("Keyword '%1' not found!").arg(keyword), QString("No events containing '%1' found!").arg(keyword), QMessageBox::Ok); - } - else - { + } else { treeView->show(); header->hide(); - updateTreeView( firstDateWithFounds ); + emit searchResultChanged(); } } diff --git a/src/gui/searchtabcontainer.h b/src/gui/searchtabcontainer.h index fdb1bc3..80ecd4c 100644 --- a/src/gui/searchtabcontainer.h +++ b/src/gui/searchtabcontainer.h @@ -31,9 +31,14 @@ class SearchTabContainer: public TabContainer { public: SearchTabContainer(QWidget *aParent); virtual ~SearchTabContainer() {} + int searchResultCount(const QDate& date) const; ///< returns the number of events found on that specific date + protected: virtual void loadEvents( const QDate &aDate, const int aConferenceId ); +signals: + void searchResultChanged(); + public slots: void showSearchDialog(); -- 2.39.5