temp commit for search tab
authortimkoma <timkoma@localhost>
Wed, 20 Jan 2010 14:50:12 +0000 (14:50 +0000)
committertimkoma <timkoma@localhost>
Wed, 20 Jan 2010 14:50:12 +0000 (14:50 +0000)
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/gui/mainwindow.ui
src/sql/sqlengine.cpp
src/sql/sqlengine.h

index 241cf9f..977baea 100644 (file)
@@ -70,15 +70,27 @@ MainWindow::MainWindow(QWidget *parent)
     actTreeView->setModel(new EventModel());
     actTreeView->setItemDelegate(new Delegate(actTreeView));
 
+    // DAY EVENTS View
+       searchTreeView->setHeaderHidden(true);
+       searchTreeView->setRootIsDecorated(false);
+       searchTreeView->setIndentation(0);
+       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 &)));
     connect(actTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
+    connect(searchTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
     // request for map to be displayed
     connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
     connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
     connect(actTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
-
+    connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
+    // event search button clicked
+    connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
 
     // TESTING: load some 'fav' data
     if(Conference::getAll().count()) // no conference(s) in the DB
@@ -240,3 +252,19 @@ void MainWindow::displayMap(const QModelIndex &aIndex)
     MapWindow window(map,roomName,this);
     window.exec();
 }
+
+void MainWindow::searchClicked()
+{
+    QList<QString> columns;
+
+    if( searchTitle->isChecked() )
+        columns.append( "title" );
+    if( searchAbstract->isChecked() )
+        columns.append( "abstract" );
+
+    if( mSqlEngine->searchEvent( confId, columns, searchEdit->text() ) > 0 ){
+        searchTreeView->setVisible(true);
+        searchDayNavigator->setVisible(true);
+    }
+}
+
index 59cadf0..c4b7466 100644 (file)
@@ -24,6 +24,7 @@ private slots:
     void updateFavouritesDayView(const QDate &aDate);
     void itemClicked(const QModelIndex &aIndex);
     void displayMap(const QModelIndex &aIndex);
+    void searchClicked();
 private:
     SqlEngine *mSqlEngine;
     ScheduleXmlParser *mXmlParser;
index 024a1a3..c2df896 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">
+         <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>
       </widget>
-      <widget class="QWidget" name="mapTab" >
-       <attribute name="title" >
+      <widget class="QWidget" name="mapTab">
+       <attribute name="title">
         <string>Map</string>
        </attribute>
       </widget>
index e135f43..9150bb0 100644 (file)
@@ -289,3 +289,38 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
     return result;
 }
 
+int SqlEngine::searchEvent(int aConferenceId, const QList<QString> &aColumns, const QString &aKeyword)
+{
+    QSqlDatabase db = QSqlDatabase::database();
+
+    if ( !db.isValid() || !db.isOpen())
+        return -1;
+
+    QString query = QString(
+        "DROP TABLE IF EXISTS SEARCH_EVENT;"
+        "CREATE TEMP TABLE SEARCH_EVENT ( xid_conference INTEGER  NOT NULL, id INTEGER NOT NULL );"
+        "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) "
+            "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 );
+    }
+    query.chop( QString(" OR ").length() );
+    query += QString(");");
+
+    qDebug() << "\nSQL: " << query;
+
+    db.exec();
+
+    if( db.lastError().isValid() && db.lastError().number() != 0 ){
+        qDebug() << "SQL ERR: " << db.lastError().number() << ", " << db.lastError().text();
+        return 0;
+    }
+    else{
+        qDebug() << "SQL OK.\n";
+        return 1;
+    }
+
+}
index afad5ae..110eb24 100644 (file)
@@ -18,6 +18,9 @@ class SqlEngine : public QObject
         void addPersonToDB(QHash<QString,QString> &aPerson);
         void addLinkToDB(QHash<QString,QString> &aLink);
         void addRoomToDB(QHash<QString,QString> &aRoom);
+
+        // search Events for ....
+        int searchEvent(int conferenceId, const QList<QString> &columns, const QString &keyword);
     private:
         QString login(const QString &aDatabaseType, const QString &aDatabaseName);
         bool createTables(QSqlDatabase &aDatabase);