From: pavelpa Date: Wed, 27 Jan 2010 06:41:47 +0000 (+0000) Subject: 'conflicts' modifications X-Git-Tag: 0.5.0~181 X-Git-Url: https://git.toastfreeware.priv.at/toast/confclerk.git/commitdiff_plain/9f367eb1ca61e58058b62e462f1759d87aa10ec3 '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 --- diff --git a/src/mvc/delegate.cpp b/src/mvc/delegate.cpp index 79d94db..d7c6db1 100644 --- a/src/mvc/delegate.cpp +++ b/src/mvc/delegate.cpp @@ -65,7 +65,8 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons //int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width(); //Time conflicts are colored differently - if(hasTimeConflict(index, index.parent())) + if(static_cast(index.internalPointer())->isFavourite()) + if(static_cast(index.internalPointer())->hasTimeConflict()) { bkgrColor = Qt::yellow; } @@ -132,9 +133,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons // map painter->drawImage(mControls[MapControl]->drawPoint(option.rect),*mControls[MapControl]->image()); // Time conflict - //if(static_cast(index.internalPointer())->hasTimeConflict()) - - if(hasTimeConflict(index, index.parent())) + if(static_cast(index.internalPointer())->hasTimeConflict()) painter->drawImage(mControls[WarningControl]->drawPoint(option.rect),*mControls[WarningControl]->image()); // draw texts @@ -311,7 +310,7 @@ Delegate::ControlId Delegate::whichControlClicked(const QModelIndex &aIndex, con { if(id == WarningControl) { - if(mControls[id]->hasConflict) + if(static_cast(aIndex.internalPointer())->hasTimeConflict()) return id; } else @@ -373,7 +372,6 @@ void Delegate::defineControls() // WARNING ICON control = new Control(WarningControl,QString(":icons/exclamation.png")); p = mControls[MapControl]->drawPoint(); - control->hasConflict = false; p.setX(p.x()-control->image()->width()-SPACER); control->setDrawPoint(p); mControls.insert(WarningControl,control); @@ -413,29 +411,3 @@ int Delegate::numberOfAlarms(const QModelIndex &index) const return nrofAlarms; } -bool Delegate::hasTimeConflict(const QModelIndex &index, const QModelIndex &parent) const -{ - Event *event = static_cast(index.internalPointer()); - QTime start = event->start().time(); - QTime end = start.addSecs(event->duration()); - for(int i=0; irowCount(parent); i++) - { - if((event->id()!=static_cast(parent.child(i,0).internalPointer())->id()) - && - (static_cast(parent.child(i,0).internalPointer())->isFavourite())) - { - if (((start >= static_cast(parent.child(i,0).internalPointer())->start().time()) - && - (start < static_cast(parent.child(i,0).internalPointer())->start().time().addSecs(static_cast(parent.child(i,0).internalPointer())->duration()))) - || - ((end > static_cast(parent.child(i,0).internalPointer())->start().time()) - && - (end <= static_cast(parent.child(i,0).internalPointer())->start().time().addSecs(static_cast(parent.child(i,0).internalPointer())->duration())))) - { - return true; - } - } - } - return false; -} - diff --git a/src/mvc/delegate.h b/src/mvc/delegate.h index 42cce94..3f544f7 100644 --- a/src/mvc/delegate.h +++ b/src/mvc/delegate.h @@ -43,7 +43,6 @@ class Delegate : public QItemDelegate { return QRect(drawPoint(aRect), drawPoint(aRect)+QPoint(mImage->size().width(),mImage->size().height())); } - bool hasConflict; private: ControlId mId; QImage *mImage; @@ -71,7 +70,6 @@ class Delegate : public QItemDelegate // every time it requires them int numberOfFavourities(const QModelIndex &index) const; int numberOfAlarms(const QModelIndex &index) const; - bool hasTimeConflict(const QModelIndex &index, const QModelIndex &parent) const; private: QPointer mViewPtr; diff --git a/src/mvc/event.cpp b/src/mvc/event.cpp index 1af20d5..1dc3af7 100644 --- a/src/mvc/event.cpp +++ b/src/mvc/event.cpp @@ -124,6 +124,97 @@ QStringList Event::persons() const return persons; } +QList Event::conflicts() const +{ + QSqlQuery query; + // TODO: conference ID isn't used here + query.prepare("SELECT conflict_event FROM event_conflict WHERE xid_event = :id AND xid_conference = :conf"); + query.bindValue(":id", id()); + query.bindValue(":conf", conferenceId()); + query.exec(); + // TODO: handle qeury error + //qDebug() << query.lastError(); + + QList conflicts; + while(query.next()) + conflicts.append(query.record().value("conflict_event").toInt()); + + return conflicts; +} + +bool Event::hasTimeConflict() const +{ + return conflicts().count() > 0 ? true : false; +} + +void Event::updateConflicts() +{ + qDebug() << "updating conflicts"; + QSqlQuery query; + query.prepare("SELECT id FROM event WHERE xid_conference = :conf AND ( \ + ( start <= :start1 AND ( start + duration ) >= :start2 ) \ + OR ( start >= :start3 AND ( start + duration ) <= :end1 ) \ + OR ( start <= :end2 AND ( start + duration ) >= :end3 ) ) AND favourite = 1 ORDER BY start"); + query.bindValue(":conf", conferenceId()); + query.bindValue(":start1", convertToDb(start(), QVariant::DateTime)); + query.bindValue(":start2", convertToDb(start(), QVariant::DateTime)); + query.bindValue(":start3", convertToDb(start(), QVariant::DateTime)); + query.bindValue(":end1", convertToDb(start().toTime_t()+duration(), QVariant::DateTime)); + query.bindValue(":end2", convertToDb(start().toTime_t()+duration(), QVariant::DateTime)); + query.bindValue(":end3", convertToDb(start().toTime_t()+duration(), QVariant::DateTime)); + query.exec(); + + QList conflicts; + while(query.next()) + { + int idx = query.record().value("id").toInt(); + if(idx != id()) + conflicts.append(idx); + } + + if(isFavourite()) // event became favourite + { + for(int i=0; i " << conflicts[i]; + + QSqlQuery queryRemove; + queryRemove.prepare("DELETE FROM event_conflict WHERE xid_event = :id1 AND xid_conference = :conf AND conflict_event = :id2"); + queryRemove.bindValue(":id1",conflicts[i]); + queryRemove.bindValue(":conf",conferenceId()); + queryRemove.bindValue(":id2",id()); + queryRemove.exec(); + } + } +} + void Event::setRoom(const QString &room) { Q_UNUSED(room); diff --git a/src/mvc/event.h b/src/mvc/event.h index 6c82a2b..a96ed19 100644 --- a/src/mvc/event.h +++ b/src/mvc/event.h @@ -37,7 +37,7 @@ public: QString language() const { return value("language").toString(); } bool isFavourite() const { return value("favourite").toBool(); } bool hasAlarm() const { return value("alarm").toBool(); } - bool hasTimeConflict() const { return true; /*return value("warning").toBool()*/; } //TODO + bool hasTimeConflict() const; QString tag() const { return value("tag").toString(); } QString title() const { return value("title").toString(); } QString subtitle() const { return value("subtitle").toString(); } @@ -47,6 +47,7 @@ public: QString room() const; int roomId() const; QStringList persons() const; + QList conflicts() const; void setId(int id) { setValue("id", id); } void setConferenceId(int conferenceId) { setValue("xid_conference", conferenceId); } @@ -65,6 +66,7 @@ public: // records from other tables associated with 'id' void setRoom(const QString& room); void setPersons(const QStringList &persons); + void updateConflicts(); friend class EventTest; }; diff --git a/src/mvc/treeview.cpp b/src/mvc/treeview.cpp index d18c873..e1dc9b7 100644 --- a/src/mvc/treeview.cpp +++ b/src/mvc/treeview.cpp @@ -53,6 +53,8 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP event.setFavourite(true); event.update("favourite"); qDebug() << " FAVOURITE [" << qVariantValue(aIndex.data()) << "] -> " << event.isFavourite(); + // update EVENT_CONFLICT table + event.updateConflicts(); // since the Favourite icon has changed, update TreeViews accordingly // all TreeViews have to listen on this signal emit(eventHasChanged(event.id())); diff --git a/src/sql/sqlengine.cpp b/src/sql/sqlengine.cpp index faed167..14c68fc 100644 --- a/src/sql/sqlengine.cpp +++ b/src/sql/sqlengine.cpp @@ -291,6 +291,14 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase) "FOREIGN KEY(xid_event) REFERENCES EVENT(id), " "FOREIGN KEY(xid_room) REFERENCES ROOM(id));"); + query.exec("CREATE TABLE EVENT_CONFLICT ( " + "xid_conference INTEGER NOT NULL, " + "xid_event INTEGER NOT NULL, " + "conflict_event INTEGER NOT NULL, " + "UNIQUE ( xid_conference, xid_event, conflict_event ) ON CONFLICT IGNORE, " + "FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id), " + "FOREIGN KEY(xid_event) REFERENCES EVENT(id));"); + query.exec("CREATE TABLE LINK ( " "id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " "xid_conference INTEGER NOT NULL, " @@ -362,3 +370,4 @@ bool SqlEngine::execQuery(QSqlDatabase &aDatabase, const QString &aQuery) return true; } } +