search upgrade
authortimkoma <timkoma@localhost>
Mon, 25 Jan 2010 13:05:23 +0000 (13:05 +0000)
committertimkoma <timkoma@localhost>
Mon, 25 Jan 2010 13:05:23 +0000 (13:05 +0000)
src/gui/mainwindow.cpp
src/gui/mainwindow.ui
src/sql/sqlengine.cpp
src/sql/sqlengine.h

index 47bb535..f2f4873 100644 (file)
@@ -246,10 +246,11 @@ void MainWindow::updateFavouritesView(const QDate &aDate)
 
 void MainWindow::updateSearchView(const QDate &aDate)
 {
 
 void MainWindow::updateSearchView(const QDate &aDate)
 {
-/*
+    qDebug() << "MainWindow::updateSearchView(), aDate: " << aDate.toString() ;
     searchTreeView->reset();
     int eventsCount = static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(aDate,AppSettings::confId());
     searchTreeView->reset();
     int eventsCount = static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(aDate,AppSettings::confId());
-    if( eventsCount ){
+    if( eventsCount ||
+            searchDayNavigator->getCurrentDate() != Conference::getById(AppSettings::confId()).start() ){
         searchVerticalWidget->show();
         searchAgainButton->show();
         searchTreeView->show();
         searchVerticalWidget->show();
         searchAgainButton->show();
         searchTreeView->show();
@@ -260,7 +261,6 @@ void MainWindow::updateSearchView(const QDate &aDate)
         searchVerticalWidget->hide();
         searchHead->show();
     }
         searchVerticalWidget->hide();
         searchHead->show();
     }
-*/
 }
 
 void MainWindow::updateNowView()
 }
 
 void MainWindow::updateNowView()
@@ -311,14 +311,23 @@ void MainWindow::displayMap(const QModelIndex &aIndex)
 
 void MainWindow::searchClicked()
 {
 
 void MainWindow::searchClicked()
 {
-    QList<QString> columns;
+    QHash<QString,QString> columns;
 
     if( searchTitle->isChecked() )
 
     if( searchTitle->isChecked() )
-        columns.append( "title" );
+        columns.insertMulti("EVENT", "title");
     if( searchAbstract->isChecked() )
     if( searchAbstract->isChecked() )
-        columns.append( "abstract" );
+        columns.insertMulti("EVENT", "abstract");
+    if( searchTag->isChecked() )
+        columns.insertMulti("EVENT", "tag");
+    if( searchSpeaker->isChecked() )
+        columns["PERSON"] = "name";
+    if( searchRoom->isChecked() )
+        columns["ROOM"] = "name";
+
+    QString keyword = searchEdit->text().replace( QString("%"), QString("\\%") );
+    qDebug() << "\nKeyword to search: " << keyword;
+    mSqlEngine->searchEvent( AppSettings::confId(), columns, keyword );
 
 
-    mSqlEngine->searchEvent( AppSettings::confId(), columns, searchEdit->text() );
     updateSearchView( Conference::getById(AppSettings::confId()).start() );
 }
 
     updateSearchView( Conference::getById(AppSettings::confId()).start() );
 }
 
index d5c48ce..7c35a74 100644 (file)
         </item>
        </layout>
       </widget>
         </item>
        </layout>
       </widget>
-      <widget class="QWidget" name="searchTab" >
-       <attribute name="title" >
+      <widget class="QWidget" name="searchTab">
+       <attribute name="title">
         <string>Search</string>
        </attribute>
         <string>Search</string>
        </attribute>
-       <layout class="QVBoxLayout" name="verticalLayout_3" >
+       <layout class="QHBoxLayout" name="horizontalLayout_1">
         <item>
         <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>
         </item>
         <item>
-         <layout class="QHBoxLayout" name="searchDayNavigatorHorizontalLayout" >
+         <layout class="QVBoxLayout" name="verticalLayout_3">
           <item>
           <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="1" column="0">
+              <widget class="QCheckBox" name="searchAbstract">
+               <property name="text">
+                <string>Abstract</string>
+               </property>
+              </widget>
+             </item>
+             <item row="2" column="0">
+              <widget class="QCheckBox" name="searchSpeaker">
+               <property name="text">
+                <string>Speaker</string>
+               </property>
+              </widget>
+             </item>
+             <item row="0" column="1">
+              <widget class="QCheckBox" name="searchTag">
+               <property name="text">
+                <string>Tag</string>
+               </property>
+              </widget>
+             </item>
+             <item row="1" column="1">
+              <widget class="QCheckBox" name="searchRoom">
+               <property name="text">
+                <string>Room</string>
+               </property>
+              </widget>
+             </item>
+             <item row="2" 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>
+            </layout>
+           </widget>
           </item>
           <item>
           </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>
              <size>
               <width>16777215</width>
               <height>16777215</height>
             </property>
            </widget>
           </item>
             </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>
          </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="roomsTab" >
        </layout>
       </widget>
       <widget class="QWidget" name="roomsTab" >
index b48e49d..476e812 100644 (file)
@@ -306,7 +306,7 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
     return result;
 }
 
     return result;
 }
 
-int SqlEngine::searchEvent(int aConferenceId, const QList<QString> &aColumns, const QString &aKeyword)
+int SqlEngine::searchEvent(int aConferenceId, const QHash<QString,QString> &aColumns, const QString &aKeyword)
 {
     QSqlDatabase db = QSqlDatabase::database();
 
 {
     QSqlDatabase db = QSqlDatabase::database();
 
@@ -320,11 +320,21 @@ int SqlEngine::searchEvent(int aConferenceId, const QList<QString> &aColumns, co
     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) "
     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 "
-                "WHERE xid_conference = %1 AND (").arg( aConferenceId );
-    int i = 0;
-    foreach (QString str, aColumns){
-        query += QString("%1 LIKE '\%%2\%' OR ").arg( aColumns.at(i++), aKeyword );
+                "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 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 PERSON ON ( EVENT_PERSON.xid_person = PERSON.id ) ";
+    }
+    query += QString("WHERE EVENT.xid_conference = %1 AND (").arg( aConferenceId );
+
+    foreach (QString table, aColumns.uniqueKeys()){
+        foreach (QString column, aColumns.values(table)){
+            query += QString("%1.%2 LIKE '\%%3\%' OR ").arg( table, column, aKeyword );
+        }
     }
     query.chop( QString(" OR ").length() );
     query += QString(");");
     }
     query.chop( QString(" OR ").length() );
     query += QString(");");
index 272865f..0ac9fa3 100644 (file)
@@ -20,7 +20,7 @@ class SqlEngine : public QObject
         void addRoomToDB(QHash<QString,QString> &aRoom);
 
         // search Events for ....
         void addRoomToDB(QHash<QString,QString> &aRoom);
 
         // search Events for ....
-        int searchEvent(int conferenceId, const QList<QString> &columns, const QString &keyword);
+        int searchEvent(int conferenceId, const QHash<QString,QString> &columns, const QString &keyword);
     private:
         QString login(const QString &aDatabaseType, const QString &aDatabaseName);
         bool createTables(QSqlDatabase &aDatabase);
     private:
         QString login(const QString &aDatabaseType, const QString &aDatabaseName);
         bool createTables(QSqlDatabase &aDatabase);