X-Git-Url: https://git.toastfreeware.priv.at/toast/confclerk.git/blobdiff_plain/68b2df2aae1c3894cb2a720d088b5f41e17a93e1..6bf226b78d949ea4bf6398eef7325672fd5d4ced:/src/mvc/eventmodel.cpp diff --git a/src/mvc/eventmodel.cpp b/src/mvc/eventmodel.cpp index 331d034..cfac1ee 100644 --- a/src/mvc/eventmodel.cpp +++ b/src/mvc/eventmodel.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2010 Ixonos Plc. - * Copyright (C) 2011 Philipp Spitzer, gregor herrmann + * Copyright (C) 2011-2012 Philipp Spitzer, gregor herrmann * * This file is part of ConfClerk. * @@ -27,40 +27,76 @@ const QString EventModel::COMMA_SEPARATOR = ", "; EventModel::EventModel() { } -void EventModel::createTimeGroups() -{ - mGroups.clear(); - mParents.clear(); - if (mEvents.empty()) - { - return; +void EventModel::Group::setTitle(const QList& mEvents) { + QTime startTime = mEvents.at(mFirstEventIndex).start().time(); + QTime endTime(0, 0); + for (int i = mFirstEventIndex; i != mFirstEventIndex + mChildCount; ++i) { + endTime = qMax(mEvents.at(i).start().time().addSecs(mEvents.at(i).duration()), endTime); } + mTitle = QString("%1 - %2").arg(startTime.toString("HH:mm")).arg(endTime.toString("HH:mm")); +} - const int timeSpan = 5400; - - QTime startTime = mEvents.first().start().time(); - mGroups << EventModel::Group(QString("%1 - %2").arg(startTime.toString("HH:mm"), - startTime.addSecs(timeSpan).toString("HH:mm")), 0); - QTime nextGroupTime = mEvents.first().start().time().addSecs(timeSpan); - for (int i=0; i= 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 + } + } - if (nextGroupTime <= eventTime) - { - mGroups.last().mChildCount = i - mGroups.last().mFirstEventIndex; - mGroups << EventModel::Group(QString("%1 - %2").arg(nextGroupTime.toString("HH:mm"), - nextGroupTime.addSecs(timeSpan).toString("HH:mm")), i); - nextGroupTime = nextGroupTime.addSecs(timeSpan); + // 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; } - // add parent-child relation + // insert event into current group mParents[mEvents.at(i).id()] = mGroups.count() - 1; + mGroups.last().mChildCount += 1; + groupEndDateTime = qMax(eventEndDateTime, groupEndDateTime); } - mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex; + // the last group needs a title as well + mGroups.last().setTitle(mEvents); reset(); } @@ -200,7 +236,6 @@ int EventModel::rowCount (const QModelIndex & parent) const void EventModel::clearModel() { - // qDebug() << __PRETTY_FUNCTION__ << this << mEvents.count(); mGroups.clear(); mEvents.clear(); mParents.clear(); @@ -214,8 +249,7 @@ void EventModel::loadEvents(const QDate &aDate, int aConferenceId) // check for existence of the conference in the DB if(Conference::getAll().count()) { - qDebug() << "Loading Conference Data: [" << Conference::getById(aConferenceId).title() << "] " << aDate; - mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start"); + mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start, duration"); } createTimeGroups(); } @@ -226,7 +260,6 @@ void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId) // check for existence of the conference in the DB if(Conference::getAll().count()) { - qDebug() << "Loading FAV Conference Data: [" << Conference::getById(aConferenceId).title() << "] " << aDate; mEvents = Event::getFavByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId); } createTimeGroups(); @@ -238,9 +271,8 @@ int EventModel::loadSearchResultEvents(const QDate &aDate, int aConferenceId) // check for existence of the conference in the DB if(Conference::getAll().count()) { - qDebug() << "Loading search result Data: [" << Conference::getById(aConferenceId).title() << "] " << aDate; try{ - mEvents = Event::getSearchResultByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start"); + mEvents = Event::getSearchResultByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start, duration"); } catch( OrmException &e ){ qDebug() << "Event::getSearchResultByDate failed: " << e.text(); @@ -261,8 +293,7 @@ void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId) clearModel(); if (Conference::getAll().count()) { - qDebug() << "Loading Conference Data (by Track): [" << Conference::getById(aConferenceId).title() << "] " << aDate; - mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "xid_track, start"); + mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "xid_track, start, duration"); } createTrackGroups(); } @@ -272,31 +303,17 @@ void EventModel::loadEventsByRoom(const QDate &aDate, int aConferenceId) clearModel(); if (Conference::getAll().count()) { - qDebug() << "Loading Conference Data (by Room): [" << Conference::getById(aConferenceId).title() << "] " << aDate; mEvents = Event::getByDateAndRoom(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId); } createRoomGroups(); } -void EventModel::loadNowEvents(int aConferenceId) -{ - clearModel(); - // check for existence of the conference in the DB - if(Conference::getAll().count()) - { - qDebug() << "Loading Conference Data: [" << Conference::getById(aConferenceId).title() << "] scheduled NOW"; - mEvents = Event::nowEvents(aConferenceId, "start"); - } - createTimeGroups(); -} -void EventModel::loadConflictEvents(int aEventId, int aConferenceId) -{ +void EventModel::loadConflictEvents(int aEventId, int aConferenceId) { clearModel(); // check for existence of the conference in the DB if(Conference::getAll().count()) { - qDebug() << "Loading Conference Data: [" << Conference::getById(aConferenceId).title() << "] in conflict with " << aEventId; mEvents = Event::conflictEvents(aEventId, aConferenceId); } createTimeGroups();