Ignore:
Timestamp:
05/03/12 22:36:20 (10 years ago)
Author:
gregor herrmann <gregoa@…>
Branches:
master, qt5
Children:
b686173
Parents:
a96e91c
Message:

createTimeGroups(): use QDateTime instead of QTime to avoid "midnight overflow".
Cf. #42

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mvc/eventmodel.cpp

    ra96e91c r0b595d2  
    5353
    5454    // 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());
     55    QDateTime groupStartDateTime(mEvents.first().start().date(), mEvents.first().start().time());
     56    QDateTime groupEndDateTime = groupStartDateTime.addSecs(mEvents.first().duration());
    5757    mGroups << EventModel::Group("", 0);
    5858    int timeSpan = minTimeSpan;
    5959
    6060    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)) {
     61        QDateTime eventStartDateTime (mEvents.at(i).start().date(), mEvents.at(i).start().time());
     62        QDateTime eventEndDateTime = eventStartDateTime.addSecs(mEvents.at(i).duration());
     63
     64        if (eventStartDateTime >= groupStartDateTime.addSecs(timeSpan)) {
    6565            // a new group could be necessary
    6666            if (mGroups.last().mChildCount < minChildCount) {
    6767                // too few events in the group => no new group
    6868                // 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) {
     69                QDateTime prevEventStartDateTime (mEvents.at(i).start().date(), mEvents.at(i).start().time());
     70                if (i > 0 && qMax(prevEventStartDateTime.addSecs(mEvents.at(i-1).duration()), groupEndDateTime).secsTo(eventStartDateTime) < minTimeSpan) {
    7071                    timeSpan += minTimeSpan;
    7172                    --i;
     
    7677            // a new group is necessary
    7778            mGroups.last().setTitle(mEvents);
    78             groupStartTime = groupStartTime.addSecs(timeSpan);
    79             groupEndTime = groupStartTime.addSecs(mEvents.at(i).duration());
     79            groupStartDateTime = groupStartDateTime.addSecs(timeSpan);
     80            groupEndDateTime = groupStartDateTime.addSecs(mEvents.at(i).duration());
    8081            mGroups << EventModel::Group("", i);
    8182            timeSpan = minTimeSpan;
     
    8586        mParents[mEvents.at(i).id()] = mGroups.count() - 1;
    8687        mGroups.last().mChildCount += 1;
    87         groupEndTime = qMax(eventEndTime, groupEndTime);
     88        groupEndDateTime = qMax(eventEndDateTime, groupEndDateTime);
    8889    }
    8990
Note: See TracChangeset for help on using the changeset viewer.