The search result is now synced with the daynavigator.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Mon, 12 Dec 2011 19:59:00 +0000 (19:59 +0000)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Mon, 12 Dec 2011 19:59:00 +0000 (19:59 +0000)
When the search result is not on the current date, the date is changed.

src/gui/daynavigatorwidget.h
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/gui/searchtabcontainer.cpp
src/gui/searchtabcontainer.h

index e16017c..a06d8b1 100644 (file)
@@ -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 *);
index b9969a9..c6505ad 100644 (file)
@@ -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
index 127620d..42dfbb7 100644 (file)
@@ -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&);
index 86c9fcc..3abc8e5 100644 (file)
@@ -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();
     }
 }
 
index fdb1bc3..80ecd4c 100644 (file)
@@ -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();