When the search result is not on the current date, the date is changed.
~DayNavigatorWidget() {}
void setDates(const QDate &aStartDate, const QDate &aEndDate);
void setCurDate(const QDate& curDate);
+ QDate startDate() const {return mStartDate;}
QDate curDate() const {return mCurDate;}
+ QDate endDate() const {return mEndDate;}
void unsetDates();
protected:
void paintEvent(QPaintEvent *);
connect(dayNavigator, SIGNAL(dateChanged(QDate)), roomsTabContainer, SLOT(redisplayDate(QDate)));
connect(dayNavigator, SIGNAL(dateChanged(QDate)), searchTabContainer, SLOT(redisplayDate(QDate)));
+ // search result has changed
+ connect(searchTabContainer, SIGNAL(searchResultChanged()), SLOT(onSearchResultChanged()));
+
+
useConference(Conference::activeConference());
// optimization, see useConference() code
try {
}
+void MainWindow::onSearchResultChanged() {
+ // Are results found on the current date?
+ QDate date = dayNavigator->curDate();
+ int count = searchTabContainer->searchResultCount(date);
+ if (count > 0) {searchTabContainer->redisplayDate(date); return;}
+
+ // Are results found in the future?
+ for (date = date.addDays(1); date <= dayNavigator->endDate(); date = date.addDays(1)) {
+ int count = searchTabContainer->searchResultCount(date);
+ if (count > 0) {dayNavigator->setCurDate(date); return;}
+ }
+
+ // Are results found in the past?
+ for (date = dayNavigator->startDate(); date < dayNavigator->curDate(); date = date.addDays(1)) {
+ int count = searchTabContainer->searchResultCount(date);
+ if (count > 0) {dayNavigator->setCurDate(date); return;}
+ }
+ // No results were found
+ searchTabContainer->redisplayDate(dayNavigator->curDate());
+}
+
+
void MainWindow::useConference(int id)
{
if (id == -1) // in case no conference is active
void on_searchAction_triggered();
void onEventChanged(int aEventId, bool favouriteChanged);
+ void onSearchResultChanged();
// TODO: remove
void networkQueryFinished(QNetworkReply*);
void importFromNetwork(const QString&);
}
+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() {
header->show();
treeView->hide();
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();
-
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(
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();
}
}
public:
SearchTabContainer(QWidget *aParent);
virtual ~SearchTabContainer() {}
+ int searchResultCount(const QDate& date) const; ///< returns the number of events found on that specific date
+
protected:
virtual void loadEvents( const QDate &aDate, const int aConferenceId );
+signals:
+ void searchResultChanged();
+
public slots:
void showSearchDialog();