X-Git-Url: https://git.toastfreeware.priv.at/toast/confclerk.git/blobdiff_plain/9196cb0ea3f4fcc8b89f343b8305e1af575c1350..080dc7d603d45ba0662aa731418993ddd45b5fe8:/src/gui/searchtabcontainer.cpp diff --git a/src/gui/searchtabcontainer.cpp b/src/gui/searchtabcontainer.cpp index 86c9fcc..5551b0c 100644 --- a/src/gui/searchtabcontainer.cpp +++ b/src/gui/searchtabcontainer.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2010 Ixonos Plc. - * Copyright (C) 2011 Philipp Spitzer, gregor herrmann + * Copyright (C) 2011-2024 Philipp Spitzer, gregor herrmann, Stefan Stahl * * This file is part of ConfClerk. * @@ -22,8 +22,7 @@ #include "searchhead.h" #include -SearchTabContainer::SearchTabContainer(QWidget *aParent) : TabContainer( aParent ) -{ +SearchTabContainer::SearchTabContainer(QWidget *aParent): TabContainer(aParent), sqlEngine(0) { header = new SearchHead(this); header->setObjectName(QString::fromUtf8("header")); QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding); @@ -39,61 +38,55 @@ SearchTabContainer::SearchTabContainer(QWidget *aParent) : TabContainer( aParent } -void SearchTabContainer::showSearchDialog() { - header->show(); - treeView->hide(); +bool SearchTabContainer::searchDialogIsVisible() const { + return header->isVisible(); +} + + +int SearchTabContainer::searchResultCount(const QDate& date) const { + int confId = Conference::activeConference(); + if (confId == -1) return 0; + return Event::getSearchResultByDate(date, confId, "start, duration").count(); +} + + +void SearchTabContainer::showSearchDialog(bool show) { + header->setVisible(show); + treeView->setVisible(!show); + if (show) header->searchEdit->setFocus(Qt::OtherFocusReason); } void SearchTabContainer::searchButtonClicked() { - QHash columns; + if (!sqlEngine) return; + + QMultiHash columns; SearchHead *searchHeader = static_cast(header); - if( searchHeader->searchTitle->isChecked() ) - columns.insertMulti("EVENT", "title"); - if( searchHeader->searchAbstract->isChecked() ) - columns.insertMulti("EVENT", "abstract"); - if( searchHeader->searchTag->isChecked() ) - columns.insertMulti("EVENT", "tag"); - if( searchHeader->searchSpeaker->isChecked() ) - columns["PERSON"] = "name"; - if( searchHeader->searchRoom->isChecked() ) - columns["ROOM"] = "name"; + if (searchHeader->searchTitle->isChecked()) + columns.insert("EVENT", "title"); + if (searchHeader->searchAbstract->isChecked()) + columns.insert("EVENT", "abstract"); + if (searchHeader->searchTag->isChecked()) + columns.insert("EVENT", "tag"); + if (searchHeader->searchSpeaker->isChecked()) + columns.insert("PERSON", "name"); + if (searchHeader->searchRoom->isChecked()) + columns.insert("ROOM", "name"); QString keyword = searchHeader->searchEdit->text(); int confId = Conference::activeConference(); if (confId == -1) return; + Conference conf = Conference::getById(confId); - SqlEngine::searchEvent( confId, columns, keyword ); - - QDate startDate = Conference::getById(confId).start(); - QDate endDate = Conference::getById(confId).end(); + sqlEngine->searchEvent( confId, columns, keyword ); int nrofFounds = 0; - QDate firstDateWithFounds = endDate; - QDate lastDateWithFounds = startDate; - for(QDate d=startDate; d<=endDate; d=d.addDays(1)) - { - try{ - int count = Event::getSearchResultByDate(d, confId, "start, duration").count(); - if(count && (firstDateWithFounds==endDate)) - firstDateWithFounds=d; - if(count) - lastDateWithFounds=d; - nrofFounds+=count; - } - catch( OrmException &e ){ - qDebug() << "Event::getSearchResultByDate failed: " << e.text(); - } - catch(...){ - qDebug() << "Event::getSearchResultByDate failed"; - } - } + for (QDate d = conf.start(); d <= conf.end(); d = d.addDays(1)) + nrofFounds += Event::getSearchResultByDate(d, confId, "start, duration").count(); - if(!nrofFounds) - { - // TODO: display some message + if (!nrofFounds) { treeView->hide(); header->show(); QMessageBox::information( @@ -101,13 +94,11 @@ void SearchTabContainer::searchButtonClicked() { QString("Keyword '%1' not found!").arg(keyword), QString("No events containing '%1' found!").arg(keyword), QMessageBox::Ok); - } - else - { + } else { treeView->show(); header->hide(); - updateTreeView( firstDateWithFounds ); + emit searchResultChanged(); } }