Changeset 412cef6


Ignore:
Timestamp:
01/28/10 13:43:19 (12 years ago)
Author:
pavelpa <pavelpa@…>
Branches:
master, qt5
Children:
8cb5c4f
Parents:
438699c
Message:

some 'delegate' drawing optimizations

  • removed EVENT_CONFLICT table - used one SQL SELECT instead
Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/gui/eventdialog.cpp

    r438699c r412cef6  
    4646    Event event = Event::getById(mEventId,Conference::activeConference());
    4747
     48    QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
    4849    if(event.isFavourite())
    4950    {
     
    5758    }
    5859    event.update("favourite");
     60
     61    if(event.isFavourite())
     62    {
     63        // event has became 'favourite' and so 'conflicts' list may have changed
     64        conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
     65    }
     66
    5967    qDebug() << " FAVOURITE [" << event.id() << "] -> " << event.isFavourite();
    60     // update EVENT_CONFLICT table
    61     event.updateConflicts();
     68
    6269    // since the Favourite icon has changed, update TreeViews accordingly
    6370    // all TreeViews have to listen on this signal
    6471    emit(eventHasChanged(event.id()));
     72
     73    // have to emit 'eventHasChanged' signal on all events in conflict
     74    for(int i=0; i<conflicts.count(); i++)
     75        emit(eventHasChanged(conflicts[i].id()));
    6576}
    6677
  • src/mvc/delegate.cpp

    r438699c r412cef6  
    6666
    6767        //Time conflicts are colored differently
    68         if(static_cast<Event*>(index.internalPointer())->isFavourite())
    6968        if(static_cast<Event*>(index.internalPointer())->hasTimeConflict())
    70         {
    7169            bkgrColor = Qt::yellow;
    72         }
    7370
    7471        if(isLast(index))
  • src/mvc/event.cpp

    r438699c r412cef6  
    7272{
    7373    QSqlQuery query;
    74     query.prepare( selectQuery() + QString("WHERE id IN ( SELECT conflict_event FROM event_conflict WHERE xid_event = :id AND xid_conference = :conf ) ORDER BY %1").arg("start"));
    75     query.bindValue(":id", aEventId);
    76     query.bindValue(":conf", conferenceId);
     74    Event event = Event::getById(aEventId,conferenceId);
     75    query.prepare(selectQuery() + "WHERE xid_conference = :conf AND ( \
     76           ( start <= :start1 AND ( start + duration ) >= :start2 ) \
     77        OR ( start >= :start3 AND ( start + duration ) <= :end1 ) \
     78        OR ( start <= :end2  AND ( start + duration ) >= :end3 ) ) AND favourite = 1 AND NOT id = :id ORDER BY start");
     79    query.bindValue(":conf", event.conferenceId());
     80    query.bindValue(":start1", convertToDb(event.start(), QVariant::DateTime));
     81    query.bindValue(":start2", convertToDb(event.start(), QVariant::DateTime));
     82    query.bindValue(":start3", convertToDb(event.start(), QVariant::DateTime));
     83    query.bindValue(":end1", convertToDb(event.start().toTime_t()+event.duration(), QVariant::DateTime));
     84    query.bindValue(":end2", convertToDb(event.start().toTime_t()+event.duration(), QVariant::DateTime));
     85    query.bindValue(":end3", convertToDb(event.start().toTime_t()+event.duration(), QVariant::DateTime));
     86    query.bindValue(":id", event.id());
    7787
    7888    return load(query);
     
    152162}
    153163
    154 QList<int> Event::conflicts() const
    155 {
    156     QSqlQuery query;
    157     // TODO: conference ID isn't used here
    158     query.prepare("SELECT conflict_event FROM event_conflict WHERE xid_event = :id AND xid_conference = :conf");
    159     query.bindValue(":id", id());
    160     query.bindValue(":conf", conferenceId());
    161     query.exec();
    162     // TODO: handle qeury error
    163     //qDebug() << query.lastError();
    164 
    165     QList<int> conflicts;
    166     while(query.next())
    167         conflicts.append(query.record().value("conflict_event").toInt());
    168 
    169     return conflicts;
    170 }
    171 
    172164bool Event::hasTimeConflict() const
    173165{
    174     return conflicts().count() > 0 ? true : false;
    175 }
    176 
    177 void Event::updateConflicts()
    178 {
    179     qDebug() << "updating conflicts";
    180     QSqlQuery query;
    181     query.prepare("SELECT id FROM event WHERE xid_conference = :conf AND ( \
    182            ( start <= :start1 AND ( start + duration ) >= :start2 ) \
    183         OR ( start >= :start3 AND ( start + duration ) <= :end1 ) \
    184         OR ( start <= :end2  AND ( start + duration ) >= :end3 ) ) AND favourite = 1 ORDER BY start");
    185     query.bindValue(":conf", conferenceId());
    186     query.bindValue(":start1", convertToDb(start(), QVariant::DateTime));
    187     query.bindValue(":start2", convertToDb(start(), QVariant::DateTime));
    188     query.bindValue(":start3", convertToDb(start(), QVariant::DateTime));
    189     query.bindValue(":end1", convertToDb(start().toTime_t()+duration(), QVariant::DateTime));
    190     query.bindValue(":end2", convertToDb(start().toTime_t()+duration(), QVariant::DateTime));
    191     query.bindValue(":end3", convertToDb(start().toTime_t()+duration(), QVariant::DateTime));
    192     query.exec();
    193 
    194     QList<int> conflicts;
    195     while(query.next())
    196     {
    197         int idx = query.record().value("id").toInt();
    198         if(idx != id())
    199             conflicts.append(idx);
    200     }
    201 
    202     if(isFavourite()) // event became favourite
    203     {
    204         for(int i=0; i<conflicts.count(); i++)
    205         {
    206             QSqlQuery query;
    207             query.prepare("INSERT INTO event_conflict (xid_conference, xid_event, conflict_event) VALUES ( ? , ? , ? )");
    208             query.bindValue(0, conferenceId());
    209             query.bindValue(1, id());
    210             query.bindValue(2, conflicts[i]);
    211             query.exec();
    212 
    213             QSqlQuery query2;
    214             query2.prepare("INSERT INTO event_conflict (xid_conference, xid_event, conflict_event) VALUES ( ? , ? , ? )");
    215             query2.bindValue(0, conferenceId());
    216             query2.bindValue(1, conflicts[i]);
    217             query2.bindValue(2, id());
    218             query2.exec();
    219         }
    220     }
    221     else // event removed from favourities
    222     {
    223         qDebug() << "removing";
    224 
    225         QSqlQuery queryRemove;
    226         queryRemove.prepare("DELETE FROM event_conflict WHERE xid_event = :id AND xid_conference = :conf");
    227         queryRemove.bindValue(":id",id());
    228         queryRemove.bindValue(":conf",conferenceId());
    229         queryRemove.exec();
    230 
    231         for(int i=0; i<conflicts.count(); i++)
    232         {
    233             qDebug() << "removing: " << id() << " -> " << conflicts[i];
    234 
    235             QSqlQuery queryRemove;
    236             queryRemove.prepare("DELETE FROM event_conflict WHERE xid_event = :id1 AND xid_conference = :conf AND conflict_event = :id2");
    237             queryRemove.bindValue(":id1",conflicts[i]);
    238             queryRemove.bindValue(":conf",conferenceId());
    239             queryRemove.bindValue(":id2",id());
    240             queryRemove.exec();
    241         }
    242     }
     166    if(!isFavourite()) // if it's not favourite, it can't have time-conflict
     167        return false;
     168
     169    return conflictEvents(id(),conferenceId()).count() > 0 ? true : false;
    243170}
    244171
  • src/mvc/event.h

    r438699c r412cef6  
    4949    int roomId() const;
    5050    QStringList persons() const;
    51     QList<int> conflicts() const;
    5251    QMap<QString,QString> links() const;
    5352
     
    7069    void setPersons(const QStringList &persons);
    7170    void setLinks(const QMap<QString,QString> &aLinks);
    72     void updateConflicts();
    7371
    7472friend class EventTest;
  • src/mvc/treeview.cpp

    r438699c r412cef6  
    5858
    5959                qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite();
    60                 // update EVENT_CONFLICT table
    61                 event.updateConflicts();
     60
    6261                if(event.isFavourite())
    6362                {
  • src/sql/sqlengine.cpp

    r438699c r412cef6  
    152152    }
    153153}
    154 
    155154
    156155void SqlEngine::addPersonToDB(QHash<QString,QString> &aPerson)
     
    290289            "FOREIGN KEY(xid_room) REFERENCES ROOM(id));");
    291290
    292         query.exec("CREATE TABLE EVENT_CONFLICT ( "
    293             "xid_conference INTEGER NOT NULL, "
    294             "xid_event INTEGER NOT NULL, "
    295             "conflict_event INTEGER NOT NULL, "
    296             "UNIQUE ( xid_conference, xid_event, conflict_event ) ON CONFLICT IGNORE, "
    297             "FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id), "
    298             "FOREIGN KEY(xid_event) REFERENCES EVENT(id));");
    299 
    300291        query.exec("CREATE TABLE LINK ( "
    301292            "id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
Note: See TracChangeset for help on using the changeset viewer.