+ if (eventStartDateTime >= groupStartDateTime.addSecs(timeSpan)) {
+ // a new group could be necessary
+ if (mGroups.last().mChildCount < minChildCount) {
+ // too few events in the group => no new group
+ // except a gap in time would occur that is longer than minTimeSpan
+ QDateTime prevEventStartDateTime = mEvents.at(i).start();
+ if (i > 0 && qMax(prevEventStartDateTime.addSecs(mEvents.at(i-1).duration()), groupEndDateTime).secsTo(eventStartDateTime) < minTimeSpan) {
+ timeSpan += minTimeSpan;
+ --i;
+ continue; // repeat with the same event
+ }
+ }
+
+ // a new group is necessary
+ mGroups.last().setTitle(mEvents);
+ groupStartDateTime = groupStartDateTime.addSecs(timeSpan);
+ groupEndDateTime = groupStartDateTime.addSecs(mEvents.at(i).duration());
+ mGroups << EventModel::Group("", i);
+ timeSpan = minTimeSpan;
+ }
+
+ // insert event into current group
+ mParents[mEvents.at(i).id()] = mGroups.count() - 1;
+ mGroups.last().mChildCount += 1;
+ groupEndDateTime = qMax(eventEndDateTime, groupEndDateTime);
+ }
+
+ // the last group needs a title as well
+ mGroups.last().setTitle(mEvents);
+
+ reset();
+}
+
+void EventModel::createTrackGroups() {
+ mGroups.clear();
+ mParents.clear();