- Timestamp:
- 01/27/10 07:41:47 (13 years ago)
- Branches:
- master, qt5
- Children:
- 001c8cf
- Parents:
- 336fa33
- Location:
- src/mvc
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mvc/delegate.cpp
r336fa33 r9f367eb 66 66 67 67 //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()) 69 70 { 70 71 bkgrColor = Qt::yellow; … … 133 134 painter->drawImage(mControls[MapControl]->drawPoint(option.rect),*mControls[MapControl]->image()); 134 135 // 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()) 138 137 painter->drawImage(mControls[WarningControl]->drawPoint(option.rect),*mControls[WarningControl]->image()); 139 138 … … 312 311 if(id == WarningControl) 313 312 { 314 if( mControls[id]->hasConflict)313 if(static_cast<Event*>(aIndex.internalPointer())->hasTimeConflict()) 315 314 return id; 316 315 } … … 374 373 control = new Control(WarningControl,QString(":icons/exclamation.png")); 375 374 p = mControls[MapControl]->drawPoint(); 376 control->hasConflict = false;377 375 p.setX(p.x()-control->image()->width()-SPACER); 378 376 control->setDrawPoint(p); … … 414 412 } 415 413 416 bool Delegate::hasTimeConflict(const QModelIndex &index, const QModelIndex &parent) const417 {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 44 44 return QRect(drawPoint(aRect), drawPoint(aRect)+QPoint(mImage->size().width(),mImage->size().height())); 45 45 } 46 bool hasConflict;47 46 private: 48 47 ControlId mId; … … 72 71 int numberOfFavourities(const QModelIndex &index) const; 73 72 int numberOfAlarms(const QModelIndex &index) const; 74 bool hasTimeConflict(const QModelIndex &index, const QModelIndex &parent) const;75 73 76 74 private: -
src/mvc/event.cpp
r336fa33 r9f367eb 125 125 } 126 126 127 QList<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 145 bool Event::hasTimeConflict() const 146 { 147 return conflicts().count() > 0 ? true : false; 148 } 149 150 void 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 127 218 void Event::setRoom(const QString &room) 128 219 { -
src/mvc/event.h
r336fa33 r9f367eb 38 38 bool isFavourite() const { return value("favourite").toBool(); } 39 39 bool hasAlarm() const { return value("alarm").toBool(); } 40 bool hasTimeConflict() const { return true; /*return value("warning").toBool()*/; } //TODO40 bool hasTimeConflict() const; 41 41 QString tag() const { return value("tag").toString(); } 42 42 QString title() const { return value("title").toString(); } … … 48 48 int roomId() const; 49 49 QStringList persons() const; 50 QList<int> conflicts() const; 50 51 51 52 void setId(int id) { setValue("id", id); } … … 66 67 void setRoom(const QString& room); 67 68 void setPersons(const QStringList &persons); 69 void updateConflicts(); 68 70 69 71 friend class EventTest; -
src/mvc/treeview.cpp
r336fa33 r9f367eb 54 54 event.update("favourite"); 55 55 qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite(); 56 // update EVENT_CONFLICT table 57 event.updateConflicts(); 56 58 // since the Favourite icon has changed, update TreeViews accordingly 57 59 // all TreeViews have to listen on this signal
Note: See TracChangeset
for help on using the changeset viewer.