X-Git-Url: https://git.toastfreeware.priv.at/toast/confclerk.git/blobdiff_plain/68b2df2aae1c3894cb2a720d088b5f41e17a93e1..080dc7d603d45ba0662aa731418993ddd45b5fe8:/src/gui/searchtabcontainer.cpp diff --git a/src/gui/searchtabcontainer.cpp b/src/gui/searchtabcontainer.cpp index d9b050c..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); @@ -33,118 +32,76 @@ SearchTabContainer::SearchTabContainer(QWidget *aParent) : TabContainer( aParent sizePolicy.setHeightForWidth(header->sizePolicy().hasHeightForWidth()); header->setSizePolicy(sizePolicy); header->setMinimumSize(QSize(10, 10)); - verticalLayout->insertWidget(0,header); + connect(header, SIGNAL(searchClicked()), SLOT(searchButtonClicked())); + showSearchDialog(); +} - header->show(); - - searchAgainButton = new QToolButton(this); - searchAgainButton->setObjectName(QString::fromUtf8("button")); - QIcon icon; - icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/search.png")), QIcon::Normal, QIcon::Off); - searchAgainButton->setIcon(icon); - QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Minimum); - sizePolicy1.setHorizontalStretch(0); - sizePolicy1.setVerticalStretch(0); - sizePolicy1.setHeightForWidth(searchAgainButton->sizePolicy().hasHeightForWidth()); - searchAgainButton->setSizePolicy(sizePolicy1); - - verticalLayout_2->insertWidget(0,searchAgainButton); - - searchAgainButton->hide(); - treeView->hide(); - // do not show 'search' header if there are no conferences in the DB - if(Conference::getAll().count()==0) - { - header->hide(); - } - connect( header, SIGNAL(searchClicked()), SLOT(searchButtonClicked())); - connect( searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked())); +bool SearchTabContainer::searchDialogIsVisible() const { + return header->isVisible(); } -SearchTabContainer::~SearchTabContainer() -{ + +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::searchButtonClicked() -{ - QHash columns; + +void SearchTabContainer::showSearchDialog(bool show) { + header->setVisible(show); + treeView->setVisible(!show); + if (show) header->searchEdit->setFocus(Qt::OtherFocusReason); +} + + +void SearchTabContainer::searchButtonClicked() { + 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"; - - QString keyword = searchHeader->searchEdit->text().replace( QString("%"), QString("\\%") ); - //qDebug() << "\nKeyword to search: " << keyword; + 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(); - SqlEngine::searchEvent( confId, columns, keyword ); + if (confId == -1) return; + Conference conf = Conference::getById(confId); - 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").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(); - searchAgainButton->hide(); - dayNavigator->hide(); header->show(); QMessageBox::information( this, QString("Keyword '%1' not found!").arg(keyword), QString("No events containing '%1' found!").arg(keyword), QMessageBox::Ok); - } - else - { - searchAgainButton->show(); - dayNavigator->show(); + } else { treeView->show(); header->hide(); - updateTreeView( firstDateWithFounds ); - dayNavigator->setDates(firstDateWithFounds, lastDateWithFounds); + emit searchResultChanged(); } } -void SearchTabContainer::searchAgainClicked() -{ - header->show(); - searchAgainButton->hide(); - dayNavigator->hide(); - treeView->hide(); -} void SearchTabContainer::loadEvents( const QDate &aDate, const int aConferenceId ) {