search fixed
authorpavelpa <pavelpa@localhost>
Thu, 28 Jan 2010 21:55:25 +0000 (21:55 +0000)
committerpavelpa <pavelpa@localhost>
Thu, 28 Jan 2010 21:55:25 +0000 (21:55 +0000)
 - only the dates (range) which contain at least one event are selectable
   - if there is only one event at a specified date - user can't switch to the next/prev date
 - if search gives no results - a message is displayed to inform user about it

src/gui/daynavigatorwidget.cpp
src/gui/daynavigatorwidget.h
src/gui/searchtabcontainer.cpp
src/mvc/event.cpp
src/sql/sqlengine.cpp

index b799127..ebe439f 100644 (file)
@@ -89,11 +89,6 @@ void DayNavigatorWidget::nextDayButtonClicked()
     }
 }
 
-QDate DayNavigatorWidget::getCurrentDate()
-{
-    return mCurDate;
-}
-
 void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent)
 {
     Q_UNUSED(aEvent);
index a4a104d..0d57de5 100644 (file)
@@ -58,7 +58,6 @@ class DayNavigatorWidget : public QWidget, private Ui::DayNavigatorWidget
         DayNavigatorWidget(QWidget *aParent = NULL);
         ~DayNavigatorWidget() {}
         void setDates(const QDate &aStartDate, const QDate &aEndDate);
-        QDate getCurrentDate();
     protected:
         void paintEvent(QPaintEvent *);
     private slots:
index 310d692..014ca5a 100644 (file)
@@ -1,7 +1,7 @@
 
 #include "searchtabcontainer.h"
 #include "searchhead.h"
-
+#include <QMessageBox>
 
 SearchTabContainer::SearchTabContainer(QWidget *aParent) : TabContainer( aParent )
 {
@@ -65,20 +65,62 @@ void SearchTabContainer::searchButtonClicked()
         columns["ROOM"] = "name";
 
     QString keyword = searchHeader->searchEdit->text().replace( QString("%"), QString("\\%") );
-    qDebug() << "\nKeyword to search: " << keyword;
+    //qDebug() << "\nKeyword to search: " << keyword;
 
     int confId = Conference::activeConference();
     SqlEngine::searchEvent( confId, columns, keyword );
 
     QDate startDate = Conference::getById(confId).start();
     QDate endDate = Conference::getById(confId).end();
-    dayNavigator->setDates(startDate, endDate);
-    updateTreeView( Conference::getById(confId).start() );
+
+    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").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";
+        }
+    }
+
+    if(!nrofFounds)
+    {
+        // TODO: display some message
+        treeView->hide();
+        searchAgainButton->hide();
+        dayNavigator->hide();
+        header->show();
+        QMessageBox::information(
+                this,
+                QString("Keyword '%1' not found!").arg(keyword),
+                QString("No events containing '%1' found!").arg(keyword),
+                QMessageBox::Ok);
+    }
+    else
+    {
+        searchAgainButton->show();
+        dayNavigator->show();
+        treeView->show();
+        header->hide();
+
+        updateTreeView( firstDateWithFounds );
+        dayNavigator->setDates(firstDateWithFounds, lastDateWithFounds);
+    }
 }
 
 void SearchTabContainer::searchAgainClicked()
 {
-    qDebug() << "SearchTab::searchAgainClicked()";
     header->show();
     searchAgainButton->hide();
     dayNavigator->hide();
@@ -87,20 +129,6 @@ void SearchTabContainer::searchAgainClicked()
 
 void SearchTabContainer::loadEvents( const QDate &aDate, const int aConferenceId )
 {
-    int eventsCount = static_cast<EventModel*>(treeView->model())->loadSearchResultEvents( aDate, aConferenceId );
-    if( eventsCount ||
-            //TODO: this is not good test
-            dayNavigator->getCurrentDate() != Conference::getById( aConferenceId ).start()
-            ){
-        searchAgainButton->show();
-        dayNavigator->show();
-        treeView->show();
-        header->hide();
-    }
-    else{
-        treeView->hide();
-        searchAgainButton->hide();
-        dayNavigator->hide();
-        header->show();
-    }
+    static_cast<EventModel*>(treeView->model())->loadSearchResultEvents( aDate, aConferenceId );
 }
+
index 8dac7d7..d3c6920 100644 (file)
@@ -193,10 +193,9 @@ void Event::setLinks(const QMap<QString,QString> &aLinks)
 
 QList<Event> Event::getSearchResultByDate(const QDate& date, int conferenceId, QString orderBy)
 {
-
     QString strQuery = QString("SELECT %1 FROM EVENT INNER JOIN SEARCH_EVENT USING (xid_conference, id) ").arg(columnsForSelect());
     strQuery += QString("WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY %1").arg(orderBy);
-    qDebug() << strQuery;
+    //qDebug() << strQuery;
     QList<Event> list;
     QSqlQuery query;
     try{
index fcaceb2..07f6024 100644 (file)
@@ -319,14 +319,14 @@ int SqlEngine::searchEvent(int aConferenceId, const QHash<QString,QString> &aCol
     // CREATE
     execQuery( db, "CREATE TEMP TABLE SEARCH_EVENT ( xid_conference INTEGER  NOT NULL, id INTEGER NOT NULL );");
     // INSERT
-    QString query = QString("INSERT INTO SEARCH_EVENT ( xid_conference, id) "
+    QString query = QString("INSERT INTO SEARCH_EVENT ( xid_conference, id ) "
                 "SELECT EVENT.xid_conference, EVENT.id FROM EVENT ");
     if( aColumns.contains("ROOM") ){
-        query += "INNER JOIN EVENT_ROOM ON (EVENT.xid_conference = EVENT_ROOM.xid_conference AND EVENT.id = EVENT_ROOM.xid_event ) ";
+        query += "INNER JOIN EVENT_ROOM ON ( EVENT.xid_conference = EVENT_ROOM.xid_conference AND EVENT.id = EVENT_ROOM.xid_event ) ";
         query += "INNER JOIN ROOM ON ( EVENT_ROOM.xid_room = ROOM.id ) ";
     }
     if( aColumns.contains("PERSON") ){
-        query += "INNER JOIN EVENT_PERSON ON (EVENT.xid_conference = EVENT_PERSON.xid_conference AND EVENT.id = EVENT_PERSON.xid_event ) ";
+        query += "INNER JOIN EVENT_PERSON ON ( EVENT.xid_conference = EVENT_PERSON.xid_conference AND EVENT.id = EVENT_PERSON.xid_event ) ";
         query += "INNER JOIN PERSON ON ( EVENT_PERSON.xid_person = PERSON.id ) ";
     }
     query += QString("WHERE EVENT.xid_conference = %1 AND (").arg( aConferenceId );
@@ -347,7 +347,7 @@ int SqlEngine::searchEvent(int aConferenceId, const QHash<QString,QString> &aCol
 
 bool SqlEngine::execQuery(QSqlDatabase &aDatabase, const QString &aQuery)
 {
-    qDebug() << "\nSQL: " << aQuery;
+    //qDebug() << "\nSQL: " << aQuery;
 
     QSqlQuery sqlQuery(aDatabase);
     if( !sqlQuery.exec(aQuery) ){
@@ -355,7 +355,7 @@ bool SqlEngine::execQuery(QSqlDatabase &aDatabase, const QString &aQuery)
        return false;
     }
     else{
-       qDebug() << "SQL OK.\n";
+       //qDebug() << "SQL OK.\n";
        return true;
     }
 }