update for the search
authortimkoma <timkoma@localhost>
Thu, 21 Jan 2010 14:12:57 +0000 (14:12 +0000)
committertimkoma <timkoma@localhost>
Thu, 21 Jan 2010 14:12:57 +0000 (14:12 +0000)
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/gui/mainwindow.ui
src/mvc/event.cpp
src/mvc/eventmodel.cpp
src/mvc/eventmodel.h
src/orm/ormrecord.h
src/sql/sqlengine.cpp

index 0e530e8..dd21ee9 100644 (file)
@@ -45,6 +45,7 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
     connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
     connect(trackDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTracksView(const QDate &)));
     connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesView(const QDate &)));
+    connect(searchDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateSearchView(const QDate &)));
 
     // DAY EVENTS View
     dayTreeView->setHeaderHidden(true);
@@ -77,8 +78,7 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
        searchTreeView->setAnimated(true);
        searchTreeView->setModel(new EventModel());
        searchTreeView->setItemDelegate(new Delegate(searchTreeView));
-       searchTreeView->setVisible(false);
-       searchDayNavigator->setVisible(false);
+
     // event clicked
     connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
     connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
@@ -116,6 +116,9 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
 
     connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)));
 
+    searchTreeView->hide();
+    searchDayNavigator->hide();
+
     // open dialog for given Event ID
     // this is used in case Alarm Dialog request application to start
     if(aEventId)
@@ -208,6 +211,11 @@ void MainWindow::updateTab(const int aIndex)
             updateTracksView(trackDayNavigator->getCurrentDate());
         }
         break;
+    case 3: //index 3 of tabWidget: searchTab
+       {
+           updateSearchView( searchDayNavigator->getCurrentDate() );
+       }
+       break;
     default:
         {
 
@@ -229,6 +237,20 @@ void MainWindow::updateFavouritesView(const QDate &aDate)
     favouriteDayNavigator->show();
 }
 
+void MainWindow::updateSearchView(const QDate &aDate)
+{
+    searchTreeView->reset();
+    int eventsCount = static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(aDate,confId);
+    if( eventsCount ){
+        searchDayNavigator->show();
+        searchTreeView->show();
+    }
+    else{
+        searchTreeView->hide();
+        searchDayNavigator->hide();
+    }
+}
+
 void MainWindow::itemClicked(const QModelIndex &aIndex)
 {
     // have to handle only events, not time-groups
@@ -269,11 +291,7 @@ void MainWindow::searchClicked()
     if( searchAbstract->isChecked() )
         columns.append( "abstract" );
 
-    searchTreeView->reset();
-    if( mSqlEngine->searchEvent( confId, columns, searchEdit->text() ) > 0 ){
-        static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(Conference::getById(confId).start(),confId);
-        searchDayNavigator->show();
-        searchTreeView->show();
-    }
+    mSqlEngine->searchEvent( confId, columns, searchEdit->text() );
+    updateSearchView( Conference::getById(confId).start() );
 }
 
index 25fa6c8..19410cf 100644 (file)
@@ -24,6 +24,7 @@ private slots:
     void updateTab(const int n);
     void updateTracksView(const QDate &aDate);
     void updateFavouritesView(const QDate &aDate);
+    void updateSearchView(const QDate &aDate);
     void itemClicked(const QModelIndex &aIndex);
     void displayMap(const QModelIndex &aIndex);
     void searchClicked();
index abde2b0..4760cfa 100644 (file)
         <string>Search</string>
        </attribute>
        <layout class="QVBoxLayout" name="verticalLayout_3">
-         <item>
-          <layout class="QFormLayout" name="formLayout">
-           <property name="fieldGrowthPolicy">
-            <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
-           </property>
-           <item row="0" column="0">
-            <widget class="QCheckBox" name="searchTitle">
-             <property name="text">
-              <string>Title</string>
-             </property>
-            </widget>
-           </item>
-           <item row="0" column="1">
-            <layout class="QHBoxLayout" name="horizontalLayout">
-             <item>
-              <widget class="QLineEdit" name="searchEdit">
-               <property name="enabled">
-                <bool>true</bool>
-               </property>
-               <property name="toolTip">
-                <string>type a keyword to search</string>
-               </property>
-              </widget>
-             </item>
-             <item>
-              <widget class="QPushButton" name="searchButton">
-               <property name="text">
-                <string>Search</string>
-               </property>
-               <property name="checkable">
-                <bool>false</bool>
-               </property>
-               <property name="autoDefault">
-                <bool>false</bool>
-               </property>
-               <property name="default">
-                <bool>true</bool>
-               </property>
-               <property name="flat">
-                <bool>false</bool>
-               </property>
-              </widget>
-             </item>
-            </layout>
-           </item>
-           <item row="1" column="0">
-            <widget class="QCheckBox" name="searchAbstract">
-             <property name="text">
-              <string>Abstract</string>
-             </property>
-            </widget>
-           </item>
-          </layout>
-         </item>
-         <item>
-          <widget class="DayNavigatorWidget" name="searchDayNavigator" native="true">
-           <property name="maximumSize">
-            <size>
-             <width>16777215</width>
-             <height>16777215</height>
-            </size>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="TreeView" name="searchTreeView">
-           <property name="maximumSize">
-            <size>
-             <width>16777215</width>
-             <height>16777215</height>
-            </size>
-           </property>
-          </widget>
-         </item>
-        </layout>
+        <item>
+         <layout class="QFormLayout" name="searchHeadLayout">
+          <property name="fieldGrowthPolicy">
+           <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
+          </property>
+          <item row="0" column="0">
+           <widget class="QCheckBox" name="searchTitle">
+            <property name="text">
+             <string>Title</string>
+            </property>
+           </widget>
+          </item>
+          <item row="0" column="1">
+           <layout class="QHBoxLayout" name="horizontalLayout">
+            <item>
+             <widget class="QLineEdit" name="searchEdit">
+              <property name="enabled">
+               <bool>true</bool>
+              </property>
+              <property name="toolTip">
+               <string>type a keyword to search</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QPushButton" name="searchButton">
+              <property name="text">
+               <string>Search</string>
+              </property>
+              <property name="checkable">
+               <bool>false</bool>
+              </property>
+              <property name="autoDefault">
+               <bool>false</bool>
+              </property>
+              <property name="default">
+               <bool>true</bool>
+              </property>
+              <property name="flat">
+               <bool>false</bool>
+              </property>
+             </widget>
+            </item>
+           </layout>
+          </item>
+          <item row="1" column="0">
+           <widget class="QCheckBox" name="searchAbstract">
+            <property name="text">
+             <string>Abstract</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </item>
+        <item>
+         <layout class="QHBoxLayout" name="searchDayNavigatorHorizontalLayout">
+          <item>
+           <spacer name="horizontalSpacer_2">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>40</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+          <item>
+           <widget class="DayNavigatorWidget" name="searchDayNavigator" native="true">
+            <property name="maximumSize">
+             <size>
+              <width>16777215</width>
+              <height>16777215</height>
+             </size>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <spacer name="horizontalSpacer">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>40</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+         </layout>
+        </item>
+        <item>
+         <widget class="TreeView" name="searchTreeView">
+          <property name="maximumSize">
+           <size>
+            <width>16777215</width>
+            <height>16777215</height>
+           </size>
+          </property>
+         </widget>
+        </item>
+       </layout>
       </widget>
       <widget class="QWidget" name="mapTab" >
        <attribute name="title" >
index d327d77..eccad94 100644 (file)
@@ -21,7 +21,6 @@ QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
 
 Event Event::getById(int id, int conferenceId)
 {
-
     QSqlQuery query;
     query.prepare(selectQuery() + "WHERE id = :id AND xid_conference = :conf");
     query.bindValue(":id", id);
index e497c25..6295815 100644 (file)
@@ -184,16 +184,28 @@ void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId)
     createTimeGroups();
 }
 
-void EventModel::loadSearchResultEvents(const QDate &aDate, int aConferenceId)
+int EventModel::loadSearchResultEvents(const QDate &aDate, int aConferenceId)
 {
     clearModel();
     // check for existence of the conference in the DB
     if(Conference::getAll().count())
     {
         qDebug() << "Loading search result Data: [" << Conference::getById(aConferenceId).title() << "] " << aDate;
-        mEvents = Event::getSearchResultByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start");
+        try{
+            mEvents = Event::getSearchResultByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start");
+        }
+        catch( OrmException &e  ){
+            qDebug() << "Event::getSearchResultByDate failed: " << e.text();
+        }
+        catch(...){
+            qDebug() << "Event::getSearchResultByDate failed";
+        }
+
     }
+
     createTimeGroups();
+
+    return mEvents.count();
 }
 
 void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId)
index c36917b..bba5764 100644 (file)
@@ -19,7 +19,7 @@ public:
     void loadEvents(const QDate &aDate, int aConferenceId); // loads Events from the DB
     void loadFavEvents(const QDate &aDate, int aConferenceId); // loads Favourite events from the DB
     void loadEventsByTrack(const QDate &aDate, int aConferenceId); // loads Events grouped by Track from the DB
-    void loadSearchResultEvents(const QDate &aDate, int aConferenceId);
+    int loadSearchResultEvents(const QDate &aDate, int aConferenceId);
     // a method to force 'EventModel' emit signal 'dataChanged()'
     // a 'view', eg. 'TreeView' listens for this signal and redraws changed items(indexes)
     void emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight);
index f3c0fcc..3667315 100644 (file)
 
 class OrmException
 {
+public:
+    OrmException(const QString& text) : mText(text) {};
+    virtual ~OrmException(){};
+    virtual const QString& text() const { return mText; }
+private:
+    QString mText;
 };
 
 class OrmNoObjectException : OrmException
 {
+public:
+    OrmNoObjectException() : OrmException("No object exception"){};
+    ~OrmNoObjectException(){};
 };
 
 class OrmSqlException : OrmException
 {
 public:
-    OrmSqlException(const QString& text) : mText(text) {}
-    QString text() const { return mText; }
-
-private:
-    QString mText;
+    OrmSqlException(const QString& text) : OrmException( QString("Sql error: ") + text ) {};
+    ~OrmSqlException(){};
 };
 
 template <typename T>
index 6034cc0..94eafd8 100644 (file)
@@ -294,7 +294,7 @@ int SqlEngine::searchEvent(int aConferenceId, const QList<QString> &aColumns, co
     execQuery( db, "CREATE TABLE SEARCH_EVENT ( xid_conference INTEGER  NOT NULL, id INTEGER NOT NULL );");
     // INSERT
     QString query = QString("INSERT INTO SEARCH_EVENT ( xid_conference, id) "
-                "SELECT xid_conference, id FROM EVENT AS e INNER JOIN VIRTUAL_EVENT AS ve USING (xid_conference, id) "
+                "SELECT xid_conference, id FROM EVENT "
                 "WHERE xid_conference = %1 AND (").arg( aConferenceId );
     int i = 0;
     foreach (QString str, aColumns){