From 0d4ecc29c4f823831acd446c4784054682c20d07 Mon Sep 17 00:00:00 2001 From: timkoma Date: Mon, 25 Jan 2010 08:02:15 +0000 Subject: [PATCH] search update --- src/gui/mainwindow.cpp | 17 +++- src/gui/mainwindow.h | 1 + src/gui/mainwindow.ui | 176 ++++++++++++++++++++--------------------- src/mvc/event.cpp | 27 +++++-- src/orm/ormrecord.h | 4 +- src/sql/sqlengine.cpp | 17 ++-- 6 files changed, 132 insertions(+), 110 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index ec6fc0e..43ae8b2 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -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(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() { diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index af0b5e7..8e311c2 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -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); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index a5e7d6a..9abb7e4 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -118,83 +118,98 @@ - - + + Search - + - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Title - - - - - - - - - true - - - type a keyword to search - - - - - - - Search - - - false - - - false - - - true - - - false - - - - - - - - - Abstract - - - - + + + + + + Search again + + + Qt::ToolButtonTextOnly + + + + + + + + 16777215 + 16777215 + + + + + + - + - - - Qt::Horizontal - - - - 40 - 20 - - - + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Title + + + + + + + + + true + + + type a keyword to search + + + + + + + Search + + + false + + + true + + + true + + + false + + + + + + + + + Abstract + + + + + - - + + 16777215 16777215 @@ -202,31 +217,8 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 16777215 - 16777215 - - - - diff --git a/src/mvc/event.cpp b/src/mvc/event.cpp index 9a60576..2685fb4 100644 --- a/src/mvc/event.cpp +++ b/src/mvc/event.cpp @@ -127,12 +127,27 @@ QList 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 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; } diff --git a/src/orm/ormrecord.h b/src/orm/ormrecord.h index d25553b..ef074ed 100644 --- a/src/orm/ormrecord.h +++ b/src/orm/ormrecord.h @@ -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 ) {}; diff --git a/src/sql/sqlengine.cpp b/src/sql/sqlengine.cpp index 335359a..b48e49d 100644 --- a/src/sql/sqlengine.cpp +++ b/src/sql/sqlengine.cpp @@ -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 &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 " -- 2.39.5