Ignore:
Timestamp:
01/28/10 22:55:25 (13 years ago)
Author:
pavelpa <pavelpa@…>
Branches:
master, qt5
Children:
8b0bf22
Parents:
83020cd
Message:

search fixed

  • only the dates (range) which contain at least one event are selectable
    • if there is only one event at a specified date - user can't switch to the next/prev date
  • if search gives no results - a message is displayed to inform user about it
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gui/searchtabcontainer.cpp

    r83020cd rbcf67d6  
    22#include "searchtabcontainer.h"
    33#include "searchhead.h"
    4 
     4#include <QMessageBox>
    55
    66SearchTabContainer::SearchTabContainer(QWidget *aParent) : TabContainer( aParent )
     
    6666
    6767    QString keyword = searchHeader->searchEdit->text().replace( QString("%"), QString("\\%") );
    68     qDebug() << "\nKeyword to search: " << keyword;
     68    //qDebug() << "\nKeyword to search: " << keyword;
    6969
    7070    int confId = Conference::activeConference();
     
    7373    QDate startDate = Conference::getById(confId).start();
    7474    QDate endDate = Conference::getById(confId).end();
    75     dayNavigator->setDates(startDate, endDate);
    76     updateTreeView( Conference::getById(confId).start() );
     75
     76    int nrofFounds = 0;
     77    QDate firstDateWithFounds = endDate;
     78    QDate lastDateWithFounds = startDate;
     79    for(QDate d=startDate; d<=endDate; d=d.addDays(1))
     80    {
     81        try{
     82            int count = Event::getSearchResultByDate(d, confId, "start").count();
     83            if(count && (firstDateWithFounds==endDate))
     84                firstDateWithFounds=d;
     85            if(count)
     86                lastDateWithFounds=d;
     87            nrofFounds+=count;
     88        }
     89        catch( OrmException &e  ){
     90            qDebug() << "Event::getSearchResultByDate failed: " << e.text();
     91        }
     92        catch(...){
     93            qDebug() << "Event::getSearchResultByDate failed";
     94        }
     95    }
     96
     97    if(!nrofFounds)
     98    {
     99        // TODO: display some message
     100        treeView->hide();
     101        searchAgainButton->hide();
     102        dayNavigator->hide();
     103        header->show();
     104        QMessageBox::information(
     105                this,
     106                QString("Keyword '%1' not found!").arg(keyword),
     107                QString("No events containing '%1' found!").arg(keyword),
     108                QMessageBox::Ok);
     109    }
     110    else
     111    {
     112        searchAgainButton->show();
     113        dayNavigator->show();
     114        treeView->show();
     115        header->hide();
     116
     117        updateTreeView( firstDateWithFounds );
     118        dayNavigator->setDates(firstDateWithFounds, lastDateWithFounds);
     119    }
    77120}
    78121
    79122void SearchTabContainer::searchAgainClicked()
    80123{
    81     qDebug() << "SearchTab::searchAgainClicked()";
    82124    header->show();
    83125    searchAgainButton->hide();
     
    88130void SearchTabContainer::loadEvents( const QDate &aDate, const int aConferenceId )
    89131{
    90     int eventsCount = static_cast<EventModel*>(treeView->model())->loadSearchResultEvents( aDate, aConferenceId );
    91     if( eventsCount ||
    92             //TODO: this is not good test
    93             dayNavigator->getCurrentDate() != Conference::getById( aConferenceId ).start()
    94             ){
    95         searchAgainButton->show();
    96         dayNavigator->show();
    97         treeView->show();
    98         header->hide();
    99     }
    100     else{
    101         treeView->hide();
    102         searchAgainButton->hide();
    103         dayNavigator->hide();
    104         header->show();
    105     }
     132    static_cast<EventModel*>(treeView->model())->loadSearchResultEvents( aDate, aConferenceId );
    106133}
     134
Note: See TracChangeset for help on using the changeset viewer.