Changeset 9f367eb for src


Ignore:
Timestamp:
01/27/10 07:41:47 (12 years ago)
Author:
pavelpa <pavelpa@…>
Branches:
master, qt5
Children:
001c8cf
Parents:
336fa33
Message:

'conflicts' modifications

  • preparing for the dialog showing also list of events in the conflict
  • created 'EVENT_CONFLICT' for flaging events in conflict state
  • TODO: not finished
Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/mvc/delegate.cpp

    r336fa33 r9f367eb  
    6666
    6767        //Time conflicts are colored differently
    68         if(hasTimeConflict(index, index.parent()))
     68        if(static_cast<Event*>(index.internalPointer())->isFavourite())
     69        if(static_cast<Event*>(index.internalPointer())->hasTimeConflict())
    6970        {
    7071            bkgrColor = Qt::yellow;
     
    133134        painter->drawImage(mControls[MapControl]->drawPoint(option.rect),*mControls[MapControl]->image());
    134135        // Time conflict
    135         //if(static_cast<Event*>(index.internalPointer())->hasTimeConflict())
    136 
    137         if(hasTimeConflict(index, index.parent()))
     136        if(static_cast<Event*>(index.internalPointer())->hasTimeConflict())
    138137            painter->drawImage(mControls[WarningControl]->drawPoint(option.rect),*mControls[WarningControl]->image());
    139138
     
    312311            if(id == WarningControl)
    313312            {
    314                 if(mControls[id]->hasConflict)
     313                if(static_cast<Event*>(aIndex.internalPointer())->hasTimeConflict())
    315314                    return id;
    316315            }
     
    374373    control = new Control(WarningControl,QString(":icons/exclamation.png"));
    375374    p = mControls[MapControl]->drawPoint();
    376     control->hasConflict = false;
    377375    p.setX(p.x()-control->image()->width()-SPACER);
    378376    control->setDrawPoint(p);
     
    414412}
    415413
    416 bool Delegate::hasTimeConflict(const QModelIndex &index, const QModelIndex &parent) const
    417 {
    418     Event *event = static_cast<Event*>(index.internalPointer());
    419     QTime start = event->start().time();
    420     QTime end = start.addSecs(event->duration());
    421     for(int i=0; i<parent.model()->rowCount(parent); i++)
    422     {
    423         if((event->id()!=static_cast<Event*>(parent.child(i,0).internalPointer())->id())
    424         &&
    425         (static_cast<Event*>(parent.child(i,0).internalPointer())->isFavourite()))
    426         {
    427             if (((start >= static_cast<Event*>(parent.child(i,0).internalPointer())->start().time())
    428             &&
    429             (start < static_cast<Event*>(parent.child(i,0).internalPointer())->start().time().addSecs(static_cast<Event*>(parent.child(i,0).internalPointer())->duration())))
    430             ||
    431             ((end > static_cast<Event*>(parent.child(i,0).internalPointer())->start().time())
    432             &&
    433             (end <= static_cast<Event*>(parent.child(i,0).internalPointer())->start().time().addSecs(static_cast<Event*>(parent.child(i,0).internalPointer())->duration()))))
    434             {
    435                 return true;
    436             }
    437         }
    438     }
    439     return false;
    440 }
    441 
  • src/mvc/delegate.h

    r336fa33 r9f367eb  
    4444                    return QRect(drawPoint(aRect), drawPoint(aRect)+QPoint(mImage->size().width(),mImage->size().height()));
    4545                }
    46                 bool hasConflict;
    4746            private:
    4847                ControlId mId;
     
    7271        int numberOfFavourities(const QModelIndex &index) const;
    7372        int numberOfAlarms(const QModelIndex &index) const;
    74         bool hasTimeConflict(const QModelIndex &index, const QModelIndex &parent) const;
    7573
    7674    private:
  • src/mvc/event.cpp

    r336fa33 r9f367eb  
    125125}
    126126
     127QList<int> Event::conflicts() const
     128{
     129    QSqlQuery query;
     130    // TODO: conference ID isn't used here
     131    query.prepare("SELECT conflict_event FROM event_conflict WHERE xid_event = :id AND xid_conference = :conf");
     132    query.bindValue(":id", id());
     133    query.bindValue(":conf", conferenceId());
     134    query.exec();
     135    // TODO: handle qeury error
     136    //qDebug() << query.lastError();
     137
     138    QList<int> conflicts;
     139    while(query.next())
     140        conflicts.append(query.record().value("conflict_event").toInt());
     141
     142    return conflicts;
     143}
     144
     145bool Event::hasTimeConflict() const
     146{
     147    return conflicts().count() > 0 ? true : false;
     148}
     149
     150void Event::updateConflicts()
     151{
     152    qDebug() << "updating conflicts";
     153    QSqlQuery query;
     154    query.prepare("SELECT id FROM event WHERE xid_conference = :conf AND ( \
     155           ( start <= :start1 AND ( start + duration ) >= :start2 ) \
     156        OR ( start >= :start3 AND ( start + duration ) <= :end1 ) \
     157        OR ( start <= :end2  AND ( start + duration ) >= :end3 ) ) AND favourite = 1 ORDER BY start");
     158    query.bindValue(":conf", conferenceId());
     159    query.bindValue(":start1", convertToDb(start(), QVariant::DateTime));
     160    query.bindValue(":start2", convertToDb(start(), QVariant::DateTime));
     161    query.bindValue(":start3", convertToDb(start(), QVariant::DateTime));
     162    query.bindValue(":end1", convertToDb(start().toTime_t()+duration(), QVariant::DateTime));
     163    query.bindValue(":end2", convertToDb(start().toTime_t()+duration(), QVariant::DateTime));
     164    query.bindValue(":end3", convertToDb(start().toTime_t()+duration(), QVariant::DateTime));
     165    query.exec();
     166
     167    QList<int> conflicts;
     168    while(query.next())
     169    {
     170        int idx = query.record().value("id").toInt();
     171        if(idx != id())
     172            conflicts.append(idx);
     173    }
     174
     175    if(isFavourite()) // event became favourite
     176    {
     177        for(int i=0; i<conflicts.count(); i++)
     178        {
     179            QSqlQuery query;
     180            query.prepare("INSERT INTO event_conflict (xid_conference, xid_event, conflict_event) VALUES ( ? , ? , ? )");
     181            query.bindValue(0, conferenceId());
     182            query.bindValue(1, id());
     183            query.bindValue(2, conflicts[i]);
     184            query.exec();
     185
     186            QSqlQuery query2;
     187            query2.prepare("INSERT INTO event_conflict (xid_conference, xid_event, conflict_event) VALUES ( ? , ? , ? )");
     188            query2.bindValue(0, conferenceId());
     189            query2.bindValue(1, conflicts[i]);
     190            query2.bindValue(2, id());
     191            query2.exec();
     192        }
     193    }
     194    else // event removed from favourities
     195    {
     196        qDebug() << "removing";
     197
     198        QSqlQuery queryRemove;
     199        queryRemove.prepare("DELETE FROM event_conflict WHERE xid_event = :id AND xid_conference = :conf");
     200        queryRemove.bindValue(":id",id());
     201        queryRemove.bindValue(":conf",conferenceId());
     202        queryRemove.exec();
     203
     204        for(int i=0; i<conflicts.count(); i++)
     205        {
     206            qDebug() << "removing: " << id() << " -> " << conflicts[i];
     207
     208            QSqlQuery queryRemove;
     209            queryRemove.prepare("DELETE FROM event_conflict WHERE xid_event = :id1 AND xid_conference = :conf AND conflict_event = :id2");
     210            queryRemove.bindValue(":id1",conflicts[i]);
     211            queryRemove.bindValue(":conf",conferenceId());
     212            queryRemove.bindValue(":id2",id());
     213            queryRemove.exec();
     214        }
     215    }
     216}
     217
    127218void Event::setRoom(const QString &room)
    128219{
  • src/mvc/event.h

    r336fa33 r9f367eb  
    3838    bool isFavourite() const { return value("favourite").toBool(); }
    3939    bool hasAlarm() const { return value("alarm").toBool(); }
    40     bool hasTimeConflict() const { return true; /*return value("warning").toBool()*/; } //TODO
     40    bool hasTimeConflict() const;
    4141    QString tag() const { return value("tag").toString(); }
    4242    QString title() const { return value("title").toString(); }
     
    4848    int roomId() const;
    4949    QStringList persons() const;
     50    QList<int> conflicts() const;
    5051
    5152    void setId(int id) { setValue("id", id); }
     
    6667    void setRoom(const QString& room);
    6768    void setPersons(const QStringList &persons);
     69    void updateConflicts();
    6870
    6971friend class EventTest;
  • src/mvc/treeview.cpp

    r336fa33 r9f367eb  
    5454                event.update("favourite");
    5555                qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite();
     56                // update EVENT_CONFLICT table
     57                event.updateConflicts();
    5658                // since the Favourite icon has changed, update TreeViews accordingly
    5759                // all TreeViews have to listen on this signal
  • src/sql/sqlengine.cpp

    r336fa33 r9f367eb  
    292292            "FOREIGN KEY(xid_room) REFERENCES ROOM(id));");
    293293
     294        query.exec("CREATE TABLE EVENT_CONFLICT ( "
     295            "xid_conference INTEGER NOT NULL, "
     296            "xid_event INTEGER NOT NULL, "
     297            "conflict_event INTEGER NOT NULL, "
     298            "UNIQUE ( xid_conference, xid_event, conflict_event ) ON CONFLICT IGNORE, "
     299            "FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id), "
     300            "FOREIGN KEY(xid_event) REFERENCES EVENT(id));");
     301
    294302        query.exec("CREATE TABLE LINK ( "
    295303            "id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
     
    363371    }
    364372}
     373
Note: See TracChangeset for help on using the changeset viewer.