Changeset ac2b0b2 for src


Ignore:
Timestamp:
12/12/11 20:59:00 (11 years ago)
Author:
Philipp Spitzer <philipp@…>
Branches:
master, qt5
Children:
71c3eb6
Parents:
018d4d6
Message:

The search result is now synced with the daynavigator.
When the search result is not on the current date, the date is changed.

Location:
src/gui
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/gui/daynavigatorwidget.h

    r018d4d6 rac2b0b2  
    3535        void setDates(const QDate &aStartDate, const QDate &aEndDate);
    3636        void setCurDate(const QDate& curDate);
     37        QDate startDate() const {return mStartDate;}
    3738        QDate curDate() const {return mCurDate;}
     39        QDate endDate() const {return mEndDate;}
    3840        void unsetDates();
    3941    protected:
  • src/gui/mainwindow.cpp

    r018d4d6 rac2b0b2  
    9898    connect(dayNavigator, SIGNAL(dateChanged(QDate)), searchTabContainer, SLOT(redisplayDate(QDate)));
    9999
     100    // search result has changed
     101    connect(searchTabContainer, SIGNAL(searchResultChanged()), SLOT(onSearchResultChanged()));
     102
     103
    100104    useConference(Conference::activeConference());
    101105    // optimization, see useConference() code
     
    170174    roomsTabContainer->redisplayEvent(aEventId);
    171175    searchTabContainer->redisplayEvent(aEventId);
     176}
     177
     178
     179void MainWindow::onSearchResultChanged() {
     180    // Are results found on the current date?
     181    QDate date = dayNavigator->curDate();
     182    int count = searchTabContainer->searchResultCount(date);
     183    if (count > 0) {searchTabContainer->redisplayDate(date); return;}
     184
     185    // Are results found in the future?
     186    for (date = date.addDays(1); date <= dayNavigator->endDate(); date = date.addDays(1)) {
     187        int count = searchTabContainer->searchResultCount(date);
     188        if (count > 0) {dayNavigator->setCurDate(date); return;}
     189    }
     190
     191    // Are results found in the past?
     192    for (date = dayNavigator->startDate(); date < dayNavigator->curDate(); date = date.addDays(1)) {
     193        int count = searchTabContainer->searchResultCount(date);
     194        if (count > 0) {dayNavigator->setCurDate(date); return;}
     195    }
     196    // No results were found
     197    searchTabContainer->redisplayDate(dayNavigator->curDate());
    172198}
    173199
  • src/gui/mainwindow.h

    r018d4d6 rac2b0b2  
    5050
    5151    void onEventChanged(int aEventId, bool favouriteChanged);
     52    void onSearchResultChanged();
    5253    // TODO: remove
    5354    void networkQueryFinished(QNetworkReply*);
  • src/gui/searchtabcontainer.cpp

    r018d4d6 rac2b0b2  
    4040
    4141
     42int SearchTabContainer::searchResultCount(const QDate& date) const {
     43    int confId = Conference::activeConference();
     44    if (confId == -1) return 0;
     45    return Event::getSearchResultByDate(date, confId, "start, duration").count();
     46}
     47
     48
    4249void SearchTabContainer::showSearchDialog() {
    4350    header->show();
     
    6572    int confId = Conference::activeConference();
    6673    if (confId == -1) return;
     74    Conference conf = Conference::getById(confId);
    6775
    6876    SqlEngine::searchEvent( confId, columns, keyword );
    6977
    70     QDate startDate = Conference::getById(confId).start();
    71     QDate endDate = Conference::getById(confId).end();
     78    int nrofFounds = 0;
     79    for (QDate d = conf.start(); d <= conf.end(); d = d.addDays(1))
     80        nrofFounds += Event::getSearchResultByDate(d, confId, "start, duration").count();
    7281
    73     int nrofFounds = 0;
    74     QDate firstDateWithFounds = endDate;
    75     QDate lastDateWithFounds = startDate;
    76     for(QDate d=startDate; d<=endDate; d=d.addDays(1))
    77     {
    78         try{
    79             int count = Event::getSearchResultByDate(d, confId, "start, duration").count();
    80             if(count && (firstDateWithFounds==endDate))
    81                 firstDateWithFounds=d;
    82             if(count)
    83                 lastDateWithFounds=d;
    84             nrofFounds+=count;
    85         }
    86         catch( OrmException &e  ){
    87             qDebug() << "Event::getSearchResultByDate failed: " << e.text();
    88         }
    89         catch(...){
    90             qDebug() << "Event::getSearchResultByDate failed";
    91         }
    92     }
    93 
    94     if(!nrofFounds)
    95     {
    96         // TODO: display some message
     82    if (!nrofFounds) {
    9783        treeView->hide();
    9884        header->show();
     
    10288                QString("No events containing '%1' found!").arg(keyword),
    10389                QMessageBox::Ok);
    104     }
    105     else
    106     {
     90    } else {
    10791        treeView->show();
    10892        header->hide();
    10993
    110         updateTreeView( firstDateWithFounds );
     94        emit searchResultChanged();
    11195    }
    11296}
  • src/gui/searchtabcontainer.h

    r018d4d6 rac2b0b2  
    3232    SearchTabContainer(QWidget *aParent);
    3333    virtual ~SearchTabContainer() {}
     34    int searchResultCount(const QDate& date) const; ///< returns the number of events found on that specific date
     35
    3436protected:
    3537    virtual void loadEvents( const QDate &aDate, const int aConferenceId );
     38
     39signals:
     40    void searchResultChanged();
    3641
    3742public slots:
Note: See TracChangeset for help on using the changeset viewer.