//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<Event*>(index.internalPointer())->isFavourite())
+ if(static_cast<Event*>(index.internalPointer())->hasTimeConflict())
{
bkgrColor = Qt::yellow;
}
// map
painter->drawImage(mControls[MapControl]->drawPoint(option.rect),*mControls[MapControl]->image());
// Time conflict
- //if(static_cast<Event*>(index.internalPointer())->hasTimeConflict())
-
- if(hasTimeConflict(index, index.parent()))
+ if(static_cast<Event*>(index.internalPointer())->hasTimeConflict())
painter->drawImage(mControls[WarningControl]->drawPoint(option.rect),*mControls[WarningControl]->image());
// draw texts
{
if(id == WarningControl)
{
- if(mControls[id]->hasConflict)
+ if(static_cast<Event*>(aIndex.internalPointer())->hasTimeConflict())
return id;
}
else
// 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);
return nrofAlarms;
}
-bool Delegate::hasTimeConflict(const QModelIndex &index, const QModelIndex &parent) const
-{
- Event *event = static_cast<Event*>(index.internalPointer());
- QTime start = event->start().time();
- QTime end = start.addSecs(event->duration());
- for(int i=0; i<parent.model()->rowCount(parent); i++)
- {
- if((event->id()!=static_cast<Event*>(parent.child(i,0).internalPointer())->id())
- &&
- (static_cast<Event*>(parent.child(i,0).internalPointer())->isFavourite()))
- {
- if (((start >= static_cast<Event*>(parent.child(i,0).internalPointer())->start().time())
- &&
- (start < static_cast<Event*>(parent.child(i,0).internalPointer())->start().time().addSecs(static_cast<Event*>(parent.child(i,0).internalPointer())->duration())))
- ||
- ((end > static_cast<Event*>(parent.child(i,0).internalPointer())->start().time())
- &&
- (end <= static_cast<Event*>(parent.child(i,0).internalPointer())->start().time().addSecs(static_cast<Event*>(parent.child(i,0).internalPointer())->duration()))))
- {
- return true;
- }
- }
- }
- return false;
-}
-
{
return QRect(drawPoint(aRect), drawPoint(aRect)+QPoint(mImage->size().width(),mImage->size().height()));
}
- bool hasConflict;
private:
ControlId mId;
QImage *mImage;
// 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<QTreeView> mViewPtr;
return persons;
}
+QList<int> 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<int> 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<int> 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.count(); i++)
+ {
+ QSqlQuery query;
+ query.prepare("INSERT INTO event_conflict (xid_conference, xid_event, conflict_event) VALUES ( ? , ? , ? )");
+ query.bindValue(0, conferenceId());
+ query.bindValue(1, id());
+ query.bindValue(2, conflicts[i]);
+ query.exec();
+
+ QSqlQuery query2;
+ query2.prepare("INSERT INTO event_conflict (xid_conference, xid_event, conflict_event) VALUES ( ? , ? , ? )");
+ query2.bindValue(0, conferenceId());
+ query2.bindValue(1, conflicts[i]);
+ query2.bindValue(2, id());
+ query2.exec();
+ }
+ }
+ else // event removed from favourities
+ {
+ qDebug() << "removing";
+
+ QSqlQuery queryRemove;
+ queryRemove.prepare("DELETE FROM event_conflict WHERE xid_event = :id AND xid_conference = :conf");
+ queryRemove.bindValue(":id",id());
+ queryRemove.bindValue(":conf",conferenceId());
+ queryRemove.exec();
+
+ for(int i=0; i<conflicts.count(); i++)
+ {
+ qDebug() << "removing: " << id() << " -> " << 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);
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(); }
QString room() const;
int roomId() const;
QStringList persons() const;
+ QList<int> conflicts() const;
void setId(int id) { setValue("id", id); }
void setConferenceId(int conferenceId) { setValue("xid_conference", conferenceId); }
// records from other tables associated with 'id'
void setRoom(const QString& room);
void setPersons(const QStringList &persons);
+ void updateConflicts();
friend class EventTest;
};
event.setFavourite(true);
event.update("favourite");
qDebug() << " FAVOURITE [" << qVariantValue<QString>(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()));
"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, "
return true;
}
}
+