- Timestamp:
- 01/28/10 13:43:19 (13 years ago)
- Branches:
- master, qt5
- Children:
- 8cb5c4f
- Parents:
- 438699c
- Location:
- src/mvc
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mvc/delegate.cpp
r438699c r412cef6 66 66 67 67 //Time conflicts are colored differently 68 if(static_cast<Event*>(index.internalPointer())->isFavourite())69 68 if(static_cast<Event*>(index.internalPointer())->hasTimeConflict()) 70 {71 69 bkgrColor = Qt::yellow; 72 }73 70 74 71 if(isLast(index)) -
src/mvc/event.cpp
r438699c r412cef6 72 72 { 73 73 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()); 77 87 78 88 return load(query); … … 152 162 } 153 163 154 QList<int> Event::conflicts() const155 {156 QSqlQuery query;157 // TODO: conference ID isn't used here158 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 error163 //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 172 164 bool Event::hasTimeConflict() const 173 165 { 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; 243 170 } 244 171 -
src/mvc/event.h
r438699c r412cef6 49 49 int roomId() const; 50 50 QStringList persons() const; 51 QList<int> conflicts() const;52 51 QMap<QString,QString> links() const; 53 52 … … 70 69 void setPersons(const QStringList &persons); 71 70 void setLinks(const QMap<QString,QString> &aLinks); 72 void updateConflicts();73 71 74 72 friend class EventTest; -
src/mvc/treeview.cpp
r438699c r412cef6 58 58 59 59 qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite(); 60 // update EVENT_CONFLICT table 61 event.updateConflicts(); 60 62 61 if(event.isFavourite()) 63 62 {
Note: See TracChangeset
for help on using the changeset viewer.