From 9d8946b6d0c7c6ff1abee00dba12046f593e26f8 Mon Sep 17 00:00:00 2001 From: timkoma Date: Thu, 21 Jan 2010 14:12:57 +0000 Subject: [PATCH] update for the search --- src/gui/mainwindow.cpp | 34 ++++++-- src/gui/mainwindow.h | 1 + src/gui/mainwindow.ui | 180 ++++++++++++++++++++++++----------------- src/mvc/event.cpp | 1 - src/mvc/eventmodel.cpp | 16 +++- src/mvc/eventmodel.h | 2 +- src/orm/ormrecord.h | 16 ++-- src/sql/sqlengine.cpp | 2 +- 8 files changed, 159 insertions(+), 93 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 0e530e8..dd21ee9 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -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(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(searchTreeView->model())->loadSearchResultEvents(Conference::getById(confId).start(),confId); - searchDayNavigator->show(); - searchTreeView->show(); - } + mSqlEngine->searchEvent( confId, columns, searchEdit->text() ); + updateSearchView( Conference::getById(confId).start() ); } diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 25fa6c8..19410cf 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -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(); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index abde2b0..4760cfa 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -95,81 +95,111 @@ Search - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Title - - - - - - - - - true - - - type a keyword to search - - - - - - - Search - - - false - - - false - - - true - - - false - - - - - - - - - Abstract - - - - - - - - - - 16777215 - 16777215 - - - - - - - - - 16777215 - 16777215 - - - - - + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Title + + + + + + + + + true + + + type a keyword to search + + + + + + + Search + + + false + + + false + + + true + + + false + + + + + + + + + Abstract + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 16777215 + 16777215 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 16777215 + 16777215 + + + + + diff --git a/src/mvc/event.cpp b/src/mvc/event.cpp index d327d77..eccad94 100644 --- a/src/mvc/event.cpp +++ b/src/mvc/event.cpp @@ -21,7 +21,6 @@ QSqlRecord const Event::sColumns = Event::toRecord(QList() Event Event::getById(int id, int conferenceId) { - QSqlQuery query; query.prepare(selectQuery() + "WHERE id = :id AND xid_conference = :conf"); query.bindValue(":id", id); diff --git a/src/mvc/eventmodel.cpp b/src/mvc/eventmodel.cpp index e497c25..6295815 100644 --- a/src/mvc/eventmodel.cpp +++ b/src/mvc/eventmodel.cpp @@ -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) diff --git a/src/mvc/eventmodel.h b/src/mvc/eventmodel.h index c36917b..bba5764 100644 --- a/src/mvc/eventmodel.h +++ b/src/mvc/eventmodel.h @@ -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); diff --git a/src/orm/ormrecord.h b/src/orm/ormrecord.h index f3c0fcc..3667315 100644 --- a/src/orm/ormrecord.h +++ b/src/orm/ormrecord.h @@ -11,20 +11,26 @@ 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 diff --git a/src/sql/sqlengine.cpp b/src/sql/sqlengine.cpp index 6034cc0..94eafd8 100644 --- a/src/sql/sqlengine.cpp +++ b/src/sql/sqlengine.cpp @@ -294,7 +294,7 @@ int SqlEngine::searchEvent(int aConferenceId, const QList &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){ -- 2.39.5