From: timkoma Date: Mon, 25 Jan 2010 13:05:23 +0000 (+0000) Subject: search upgrade X-Git-Tag: 0.5.0~203 X-Git-Url: https://git.toastfreeware.priv.at/toast/confclerk.git/commitdiff_plain/c7b58d4c882748317d69e979202dd2eb3cc2aed8 search upgrade --- diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 47bb535..f2f4873 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -246,10 +246,11 @@ void MainWindow::updateFavouritesView(const QDate &aDate) void MainWindow::updateSearchView(const QDate &aDate) { -/* + qDebug() << "MainWindow::updateSearchView(), aDate: " << aDate.toString() ; searchTreeView->reset(); int eventsCount = static_cast(searchTreeView->model())->loadSearchResultEvents(aDate,AppSettings::confId()); - if( eventsCount ){ + if( eventsCount || + searchDayNavigator->getCurrentDate() != Conference::getById(AppSettings::confId()).start() ){ searchVerticalWidget->show(); searchAgainButton->show(); searchTreeView->show(); @@ -260,7 +261,6 @@ void MainWindow::updateSearchView(const QDate &aDate) searchVerticalWidget->hide(); searchHead->show(); } -*/ } void MainWindow::updateNowView() @@ -311,14 +311,23 @@ void MainWindow::displayMap(const QModelIndex &aIndex) void MainWindow::searchClicked() { - QList columns; + QHash columns; if( searchTitle->isChecked() ) - columns.append( "title" ); + columns.insertMulti("EVENT", "title"); 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() ); } diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index d5c48ce..7c35a74 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -118,83 +118,119 @@ - - + + 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 + + + + + + + Abstract + + + + + + + Speaker + + + + + + + Tag + + + + + + + Room + + + + + + + + + true + + + type a keyword to search + + + + + + + Search + + + false + + + true + + + true + + + false + + + + + + + - - + + 16777215 16777215 @@ -202,31 +238,8 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 16777215 - 16777215 - - - - diff --git a/src/sql/sqlengine.cpp b/src/sql/sqlengine.cpp index b48e49d..476e812 100644 --- a/src/sql/sqlengine.cpp +++ b/src/sql/sqlengine.cpp @@ -306,7 +306,7 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase) return result; } -int SqlEngine::searchEvent(int aConferenceId, const QList &aColumns, const QString &aKeyword) +int SqlEngine::searchEvent(int aConferenceId, const QHash &aColumns, const QString &aKeyword) { QSqlDatabase db = QSqlDatabase::database(); @@ -320,11 +320,21 @@ int SqlEngine::searchEvent(int aConferenceId, const QList &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) " - "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(");"); diff --git a/src/sql/sqlengine.h b/src/sql/sqlengine.h index 272865f..0ac9fa3 100644 --- a/src/sql/sqlengine.h +++ b/src/sql/sqlengine.h @@ -20,7 +20,7 @@ class SqlEngine : public QObject void addRoomToDB(QHash &aRoom); // search Events for .... - int searchEvent(int conferenceId, const QList &columns, const QString &keyword); + int searchEvent(int conferenceId, const QHash &columns, const QString &keyword); private: QString login(const QString &aDatabaseType, const QString &aDatabaseName); bool createTables(QSqlDatabase &aDatabase);