Changeset 12fe870
- Timestamp:
- 08/24/11 00:07:45 (11 years ago)
- Branches:
- master, qt5
- Children:
- 55ee953
- Parents:
- ec813bb
- Location:
- src/mvc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mvc/eventmodel.cpp
rec813bb r12fe870 28 28 { } 29 29 30 31 void EventModel::Group::setTitle(const QList<Event>& mEvents) { 32 QTime startTime = mEvents.at(mFirstEventIndex).start().time(); 33 QTime endTime(0, 0); 34 for (int i = mFirstEventIndex; i != mFirstEventIndex + mChildCount; ++i) { 35 endTime = qMax(mEvents.at(i).start().time().addSecs(mEvents.at(i).duration()), endTime); 36 } 37 mTitle = QString("%1 - %2").arg(startTime.toString("HH:mm")).arg(endTime.toString("HH:mm")); 38 } 39 40 41 // We want to group the events into "time slots/time groups" that 42 // should start at full hours and have the duration of either 43 // one hour or (if less than 3 events are in one time slot) 44 // multiple of one hour. 30 45 void EventModel::createTimeGroups() 31 46 { 32 47 mGroups.clear(); 33 48 mParents.clear(); 34 35 if (mEvents.empty()) 36 { 37 return; 38 } 39 40 const int timeSpan = 5400; 41 42 QTime startTime = mEvents.first().start().time(); 43 mGroups << EventModel::Group(QString("%1 - %2").arg(startTime.toString("HH:mm"), 44 startTime.addSecs(timeSpan).toString("HH:mm")), 0); 45 QTime nextGroupTime = mEvents.first().start().time().addSecs(timeSpan); 46 47 for (int i=0; i<mEvents.count(); i++) 48 { 49 QTime eventTime = mEvents.at(i).start().time(); 50 51 if (nextGroupTime <= eventTime) 52 { 53 mGroups.last().mChildCount = i - mGroups.last().mFirstEventIndex; 54 mGroups << EventModel::Group(QString("%1 - %2").arg(nextGroupTime.toString("HH:mm"), 55 nextGroupTime.addSecs(timeSpan).toString("HH:mm")), i); 56 nextGroupTime = nextGroupTime.addSecs(timeSpan); 57 } 58 59 // add parent-child relation 49 if (mEvents.empty()) return; 50 51 const int minTimeSpan = 3600; // one hour 52 const int minChildCount = 3; // minimum number of events in one group 53 54 // Create the first time group. The events have to be sorted by start time at this point! 55 QTime groupStartTime(mEvents.first().start().time().hour(), 0); 56 QTime groupEndTime = groupStartTime.addSecs(mEvents.first().duration()); 57 mGroups << EventModel::Group("", 0); 58 int timeSpan = minTimeSpan; 59 60 for (int i = 0; i != mEvents.count(); ++i) { 61 QTime eventStartTime = mEvents.at(i).start().time(); 62 QTime eventEndTime = eventStartTime.addSecs(mEvents.at(i).duration()); 63 64 if (eventStartTime >= groupStartTime.addSecs(timeSpan)) { 65 // a new group could be necessary 66 if (mGroups.last().mChildCount < minChildCount) { 67 // too few events in the group => no new group 68 // except a gap in time would occur that is longer than minTimeSpan 69 if (i > 0 && qMax(mEvents.at(i-1).start().time().addSecs(mEvents.at(i-1).duration()), groupEndTime).secsTo(eventStartTime) < minTimeSpan) { 70 timeSpan += minTimeSpan; 71 --i; 72 continue; // repeat with the same event 73 } 74 } 75 76 // a new group is necessary 77 mGroups.last().setTitle(mEvents); 78 groupStartTime = groupStartTime.addSecs(timeSpan); 79 groupEndTime = groupStartTime.addSecs(mEvents.at(i).duration()); 80 mGroups << EventModel::Group("", i); 81 timeSpan = minTimeSpan; 82 } 83 84 // insert event into current group 60 85 mParents[mEvents.at(i).id()] = mGroups.count() - 1; 61 } 62 63 mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex; 86 mGroups.last().mChildCount += 1; 87 groupEndTime = qMax(eventEndTime, groupEndTime); 88 } 89 90 // the last group needs a title as well 91 mGroups.last().setTitle(mEvents); 64 92 65 93 reset(); -
src/mvc/eventmodel.h
rec813bb r12fe870 59 59 int mFirstEventIndex; 60 60 int mChildCount; 61 62 void setTitle(const QList<Event>& mEvents); 61 63 }; 62 64 … … 73 75 QList<Event> mEvents; 74 76 QList<Group> mGroups; 75 QHash<int, int> mParents; 77 QHash<int, int> mParents; ///< eventId, groupId 76 78 }; 77 79
Note: See TracChangeset
for help on using the changeset viewer.