search update
authortimkoma <timkoma@localhost>
Mon, 25 Jan 2010 08:02:15 +0000 (08:02 +0000)
committertimkoma <timkoma@localhost>
Mon, 25 Jan 2010 08:02:15 +0000 (08:02 +0000)
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/gui/mainwindow.ui
src/mvc/event.cpp
src/orm/ormrecord.h
src/sql/sqlengine.cpp

index ec6fc0e..43ae8b2 100644 (file)
@@ -121,6 +121,7 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
     connect(nowTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
     // event search button clicked
     connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
+    connect(searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
     // event conference map button clicked
     connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
     //
@@ -150,7 +151,8 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
     }
 
     searchTreeView->hide();
-    searchDayNavigator->hide();
+    searchVerticalWidget->hide();
+    searchHead->show();
 
     // open dialog for given Event ID
     // this is used in case Alarm Dialog request application to start
@@ -232,12 +234,15 @@ void MainWindow::updateSearchView(const QDate &aDate)
     searchTreeView->reset();
     int eventsCount = static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(aDate,AppSettings::confId());
     if( eventsCount ){
-        searchDayNavigator->show();
+        searchVerticalWidget->show();
+        searchAgainButton->show();
         searchTreeView->show();
+        searchHead->hide();
     }
     else{
         searchTreeView->hide();
-        searchDayNavigator->hide();
+        searchVerticalWidget->hide();
+        searchHead->show();
     }
 }
 
@@ -293,6 +298,12 @@ void MainWindow::searchClicked()
     updateSearchView( Conference::getById(AppSettings::confId()).start() );
 }
 
+void MainWindow::searchAgainClicked()
+{
+    searchHead->show();
+    searchAgainButton->hide();
+}
+
 void MainWindow::conferenceMapClicked()
 {
 
index af0b5e7..8e311c2 100644 (file)
@@ -27,6 +27,7 @@ private slots:
     void displayMap(const QModelIndex &aIndex);
     void displayWarning(const QModelIndex &aIndex);
     void searchClicked();
+       void searchAgainClicked();
     void conferenceMapClicked();
     void tabHasChanged(int aIndex);
     void eventHasChanged(int aEventId);
index a5e7d6a..9abb7e4 100644 (file)
         </item>
        </layout>
       </widget>
-      <widget class="QWidget" name="searchTab" >
-       <attribute name="title" >
+      <widget class="QWidget" name="searchTab">
+       <attribute name="title">
         <string>Search</string>
        </attribute>
-       <layout class="QVBoxLayout" name="verticalLayout_3" >
+       <layout class="QHBoxLayout" name="horizontalLayout_1">
         <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>
+         <widget class="QWidget" name="searchVerticalWidget" native="true">
+          <layout class="QVBoxLayout" name="searchDayNavigatorVerticalLayout">
+           <item>
+            <widget class="QToolButton" name="searchAgainButton">
+             <property name="text">
+              <string>Search again</string>
+             </property>
+             <property name="toolButtonStyle">
+              <enum>Qt::ToolButtonTextOnly</enum>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <widget class="DayNavigatorWidget" name="searchDayNavigator" native="true">
+             <property name="maximumSize">
+              <size>
+               <width>16777215</width>
+               <height>16777215</height>
+              </size>
+             </property>
+            </widget>
+           </item>
+          </layout>
+         </widget>
         </item>
         <item>
-         <layout class="QHBoxLayout" name="searchDayNavigatorHorizontalLayout" >
+         <layout class="QVBoxLayout" name="verticalLayout_3">
           <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>
+           <widget class="QWidget" name="searchHead" native="true">
+            <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>true</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>
+           </widget>
           </item>
           <item>
-           <widget class="DayNavigatorWidget" native="1" name="searchDayNavigator" >
-            <property name="maximumSize" >
+           <widget class="TreeView" name="searchTreeView">
+            <property name="maximumSize">
              <size>
               <width>16777215</width>
               <height>16777215</height>
             </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="conferenceTab" >
index 9a60576..2685fb4 100644 (file)
@@ -127,12 +127,27 @@ QList<Event> Event::getSearchResultByDate(const QDate& date, int conferenceId, Q
     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;
+    QList<Event> list;
     QSqlQuery query;
-    query.prepare( strQuery );
-    query.bindValue(":conf", conferenceId);
-    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
-    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
-
-    return load(query);
+    try{
+        if( !query.prepare( strQuery ) ){
+            qDebug() << "QSqlQuery.prepare error";
+            throw OrmSqlException( query.lastError().text() );
+        }
+
+        query.bindValue(":conf", conferenceId);
+        query.bindValue(":start", convertToDb(date, QVariant::DateTime));
+        query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
+
+        list = load(query);
+    }
+    catch(OrmException &e)
+    {
+        qDebug() << "getSearchResultByDate error: " << e.text();
+    }
+    catch(...){
+        qDebug() << "getSearchResultByDate failed ...";
+    }
+    return list;
 }
 
index d25553b..ef074ed 100644 (file)
@@ -19,14 +19,14 @@ private:
     QString mText;
 };
 
-class OrmNoObjectException : OrmException
+class OrmNoObjectException : public OrmException
 {
 public:
     OrmNoObjectException() : OrmException("No object exception"){};
     ~OrmNoObjectException(){};
 };
 
-class OrmSqlException : OrmException
+class OrmSqlException : public OrmException
 {
 public:
     OrmSqlException(const QString& text) : OrmException( QString("Sql error: ") + text ) {};
index 335359a..b48e49d 100644 (file)
@@ -232,7 +232,7 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
 
         query.exec("CREATE TABLE CONFERENCE ( \
             id INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , \
-            title VARCHAR NOT NULL , \
+            title VARCHAR UNIQUE NOT NULL , \
             subtitle VARCHAR, \
             venue VARCHAR, \
             city VARCHAR NOT NULL , \
@@ -248,12 +248,12 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
 
         query.exec("CREATE TABLE ROOM ( \
             id INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , \
-            name VARCHAR NOT NULL , \
+            name VARCHAR UNIQUE NOT NULL , \
             picture VARCHAR NOT NULL)");
 
         query.exec("CREATE TABLE PERSON ( \
             id INTEGER PRIMARY KEY  NOT NULL , \
-            name VARCHAR NOT NULL)");
+            name VARCHAR UNIQUE NOT NULL)");
 
         query.exec("CREATE TABLE EVENT ( \
             xid_conference INTEGER  NOT NULL, \
@@ -277,14 +277,16 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
             xid_conference INTEGER NOT NULL , \
             xid_event INTEGER NOT NULL , \
             xid_person INTEGER NOT NULL, \
-            FOREIGN KEY(xid_conference, xid_event) REFERENCES EVENT(xid_conference, id), \
+            FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id), \
+            FOREIGN KEY(xid_event) REFERENCES EVENT(id), \
             FOREIGN KEY(xid_person) REFERENCES PERSON(id))");
 
         query.exec("CREATE TABLE EVENT_ROOM ( \
             xid_conference INTEGER NOT NULL , \
             xid_event INTEGER NOT NULL , \
             xid_room INTEGER NOT NULL, \
-            FOREIGN KEY(xid_conference, xid_event) REFERENCES EVENT(xid_conference, id), \
+            FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id), \
+            FOREIGN KEY(xid_event) REFERENCES EVENT(id), \
             FOREIGN KEY(xid_room) REFERENCES ROOM(id))");
 
         query.exec("CREATE TABLE LINK ( \
@@ -293,7 +295,8 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
             xid_event INTEGER NOT NULL, \
             name VARCHAR, \
             url VARCHAR NOT NULL, \
-            FOREIGN KEY(xid_conference, xid_event) REFERENCES EVENT(xid_conference, id))");
+            FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id), \
+            FOREIGN KEY(xid_event) REFERENCES EVENT(id)");
     }
     else
     {
@@ -314,7 +317,7 @@ int SqlEngine::searchEvent(int aConferenceId, const QList<QString> &aColumns, co
     // DROP
     execQuery( db, "DROP TABLE IF EXISTS SEARCH_EVENT;");
     // CREATE
-    execQuery( db, "CREATE TABLE SEARCH_EVENT ( xid_conference INTEGER  NOT NULL, id INTEGER NOT NULL );");
+    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) "
                 "SELECT xid_conference, id FROM EVENT "