/*
* Copyright (C) 2010 Ixonos Plc.
- * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
+ * Copyright (C) 2011-2012 Philipp Spitzer, gregor herrmann
*
* This file is part of ConfClerk.
*
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()
-{
+
+void SearchTabContainer::showSearchDialog(bool show) {
+ header->setVisible(show);
+ treeView->setVisible(!show);
+}
+
+
+void SearchTabContainer::searchButtonClicked() {
QHash<QString,QString> columns;
SearchHead *searchHeader = static_cast<SearchHead*>(header);
if( searchHeader->searchRoom->isChecked() )
columns["ROOM"] = "name";
- QString keyword = searchHeader->searchEdit->text().replace( QString("%"), QString("\\%") );
- //qDebug() << "\nKeyword to search: " << keyword;
+ 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 )
{