Changeset bcf67d6


Ignore:
Timestamp:
01/28/10 22:55:25 (12 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
Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/gui/daynavigatorwidget.cpp

    r83020cd rbcf67d6  
    9090}
    9191
    92 QDate DayNavigatorWidget::getCurrentDate()
    93 {
    94     return mCurDate;
    95 }
    96 
    9792void DayNavigatorWidget::paintEvent(QPaintEvent *aEvent)
    9893{
  • src/gui/daynavigatorwidget.h

    r83020cd rbcf67d6  
    5959        ~DayNavigatorWidget() {}
    6060        void setDates(const QDate &aStartDate, const QDate &aEndDate);
    61         QDate getCurrentDate();
    6261    protected:
    6362        void paintEvent(QPaintEvent *);
  • 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
  • src/mvc/event.cpp

    r83020cd rbcf67d6  
    194194QList<Event> Event::getSearchResultByDate(const QDate& date, int conferenceId, QString orderBy)
    195195{
    196 
    197196    QString strQuery = QString("SELECT %1 FROM EVENT INNER JOIN SEARCH_EVENT USING (xid_conference, id) ").arg(columnsForSelect());
    198197    strQuery += QString("WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY %1").arg(orderBy);
    199     qDebug() << strQuery;
     198    //qDebug() << strQuery;
    200199    QList<Event> list;
    201200    QSqlQuery query;
  • src/sql/sqlengine.cpp

    r83020cd rbcf67d6  
    320320    execQuery( db, "CREATE TEMP TABLE SEARCH_EVENT ( xid_conference INTEGER  NOT NULL, id INTEGER NOT NULL );");
    321321    // INSERT
    322     QString query = QString("INSERT INTO SEARCH_EVENT ( xid_conference, id) "
     322    QString query = QString("INSERT INTO SEARCH_EVENT ( xid_conference, id ) "
    323323                "SELECT EVENT.xid_conference, EVENT.id FROM EVENT ");
    324324    if( aColumns.contains("ROOM") ){
    325         query += "INNER JOIN EVENT_ROOM ON (EVENT.xid_conference = EVENT_ROOM.xid_conference AND EVENT.id = EVENT_ROOM.xid_event ) ";
     325        query += "INNER JOIN EVENT_ROOM ON ( EVENT.xid_conference = EVENT_ROOM.xid_conference AND EVENT.id = EVENT_ROOM.xid_event ) ";
    326326        query += "INNER JOIN ROOM ON ( EVENT_ROOM.xid_room = ROOM.id ) ";
    327327    }
    328328    if( aColumns.contains("PERSON") ){
    329         query += "INNER JOIN EVENT_PERSON ON (EVENT.xid_conference = EVENT_PERSON.xid_conference AND EVENT.id = EVENT_PERSON.xid_event ) ";
     329        query += "INNER JOIN EVENT_PERSON ON ( EVENT.xid_conference = EVENT_PERSON.xid_conference AND EVENT.id = EVENT_PERSON.xid_event ) ";
    330330        query += "INNER JOIN PERSON ON ( EVENT_PERSON.xid_person = PERSON.id ) ";
    331331    }
     
    348348bool SqlEngine::execQuery(QSqlDatabase &aDatabase, const QString &aQuery)
    349349{
    350     qDebug() << "\nSQL: " << aQuery;
     350    //qDebug() << "\nSQL: " << aQuery;
    351351
    352352    QSqlQuery sqlQuery(aDatabase);
     
    356356    }
    357357    else{
    358        qDebug() << "SQL OK.\n";
     358       //qDebug() << "SQL OK.\n";
    359359       return true;
    360360    }
Note: See TracChangeset for help on using the changeset viewer.