Changeset 412cef6 for src/mvc/event.cpp


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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.