- Timestamp:
- 01/18/10 16:25:57 (13 years ago)
- Branches:
- master, qt5
- Children:
- 28d9e28
- Parents:
- b6cd05c
- Location:
- src/mvc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mvc/eventmodel.cpp
rb6cd05c rf6300c7 43 43 } 44 44 45 void EventModel::createActivityGroups() { 46 mGroups.clear(); 47 mParents.clear(); 48 if (mEvents.empty()) 49 { 50 return; 51 } 52 int activityId = mEvents.first().activityId(); 53 //TODO korinpa: get activity name 54 mGroups << EventModel::Group(QString("activity %1").arg(activityId), 0); 55 int nextActivityId = activityId; 56 57 for (int i=0; i<mEvents.count(); i++) 58 { 59 activityId = mEvents.at(i).activityId(); 60 if (nextActivityId != activityId) 61 { 62 mGroups.last().mChildCount = i - mGroups.last().mFirstEventIndex; 63 mGroups << EventModel::Group(QString("activity %1").arg(activityId), 0); 64 int nextActivityId = activityId; 65 } 66 // add parent-child relation 67 mParents[mEvents.at(i).id()] = mGroups.count() - 1; 68 } 69 mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex; 70 } 71 45 72 QVariant EventModel::data(const QModelIndex& index, int role) const 46 73 { … … 118 145 } 119 146 120 void EventModel:: loadEvents(const QDate &aDate, int aConferenceId)121 { 122 for(int i=0; i<mGroups.count(); i++) 123 {124 QModelIndex idx = index(i, 0);147 void EventModel::clearModel() 148 { 149 /* 150 for(int i = 0;i < mGroups.count();i++){ 151 QModelIndex idx = index(i, 0); 125 152 Group group = mGroups[i]; 126 beginRemoveRows(idx, 0,group.mChildCount-1);127 removeRows(0,group.mChildCount,idx);153 beginRemoveRows(idx, 0, group.mChildCount - 1); 154 bool ok = removeRows(0, group.mChildCount, idx); 128 155 endRemoveRows(); 129 156 //qDebug() << "removing " << group.mChildCount << " events from group:" << i << idx.data() << ":" << ok; 130 157 } 131 158 */ 159 mGroups.clear(); 132 160 mEvents.clear(); 133 161 } 162 163 void EventModel::loadEvents(const QDate &aDate, int aConferenceId) 164 { 165 clearModel(); 134 166 // check for existence of the conference in the DB 135 167 if(Conference::getAll().count()) … … 143 175 void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId) 144 176 { 145 for(int i=0; i<mGroups.count(); i++) 146 { 147 QModelIndex idx = index(i,0); 148 Group group = mGroups[i]; 149 beginRemoveRows(idx,0,group.mChildCount-1); 150 removeRows(0,group.mChildCount,idx); 151 endRemoveRows(); 152 //qDebug() << "removing " << group.mChildCount << " events from group:" << i << idx.data() << ":" << ok; 153 } 154 155 mEvents.clear(); 156 177 clearModel(); 157 178 // check for existence of the conference in the DB 158 179 if(Conference::getAll().count()) … … 164 185 } 165 186 187 void EventModel::loadEventsByActivities(const QDate &aDate, int aConferenceId) 188 { 189 clearModel(); 190 if(Conference::getAll().count()) 191 { 192 qDebug() << "Loading Conference Data (by Activities): [" << Conference::getById(aConferenceId).title() << "] " << aDate; 193 mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId); 194 } 195 createActivityGroups(); 196 } 197 166 198 void EventModel::emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight) 167 199 { -
src/mvc/eventmodel.h
rb6cd05c rf6300c7 17 17 void loadEvents(const QDate &aDate, int aConferenceId); // loads Events from the DB 18 18 void loadFavEvents(const QDate &aDate, int aConferenceId); // loads Favourite events from the DB 19 19 void loadEventsByActivities(const QDate &aDate, int aConferenceId); // loads Events grouped by Activities from the DB 20 20 // a method to force 'EventModel' emit signal 'dataChanged()' 21 21 // a 'view', eg. 'TreeView' listens for this signal and redraws changed items(indexes) … … 40 40 private: 41 41 void createTimeGroups(); 42 void createActivityGroups(); 43 void clearModel(); 42 44 43 45 private:
Note: See TracChangeset
for help on using the changeset viewer.