]> ToastFreeware Gitweb - toast/confclerk.git/blobdiff - src/mvc/eventmodel.cpp
Bump copyright years.
[toast/confclerk.git] / src / mvc / eventmodel.cpp
index cfac1eece3ad501f919ddfa1284367eede07d0b8..a140efdac496ed00bac06368825351e757164aa2 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2010 Ixonos Plc.
- * Copyright (C) 2011-2012 Philipp Spitzer, gregor herrmann
+ * Copyright (C) 2011-2024 Philipp Spitzer, gregor herrmann, Stefan Stahl
  *
  * This file is part of ConfClerk.
  *
  * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include "eventmodel.h"
-#include <conference.h>
-#include <track.h>
-#include <room.h>
+#include "conference.h"
+#include "track.h"
+#include "room.h"
+#include "application.h"
 
 const QString EventModel::COMMA_SEPARATOR = ", ";
 
@@ -29,12 +30,15 @@ EventModel::EventModel()
 
 
 void EventModel::Group::setTitle(const QList<Event>& mEvents) {
-    QTime startTime = mEvents.at(mFirstEventIndex).start().time();
-    QTime endTime(0, 0);
+    QDateTime startTime = mEvents.at(mFirstEventIndex).start();
+    QDateTime endTime(startTime);
     for (int i = mFirstEventIndex; i != mFirstEventIndex + mChildCount; ++i) {
-        endTime = qMax(mEvents.at(i).start().time().addSecs(mEvents.at(i).duration()), endTime);
+        endTime = qMax(mEvents.at(i).start().addSecs(mEvents.at(i).duration()), endTime);
     }
-    mTitle = QString("%1 - %2").arg(startTime.toString("HH:mm")).arg(endTime.toString("HH:mm"));
+    Conference& conference = ((Application*) qApp)->activeConference();
+    QTime s = conference.shiftTime(startTime.time());
+    QTime e = conference.shiftTime(endTime.time());
+    mTitle = QString("%1 - %2").arg(s.toString("HH:mm")).arg(e.toString("HH:mm"));
 }
 
 
@@ -44,22 +48,16 @@ void EventModel::Group::setTitle(const QList<Event>& mEvents) {
 // multiple of one hour.
 void EventModel::createTimeGroups()
 {
+    beginResetModel();
+
     mGroups.clear();
     mParents.clear();
     if (mEvents.empty()) return;
 
-    const int minTimeSpan = 3600; // one hour // minimum duration of a group
+    const int minTimeSpan = 3600; // one hour // minimum duration of a group in seconds
     const int minChildCount = 3;  // minimum number of events in one group
 
-    // Create the first time group. The events have to be sorted by start time at this point!
-    //    Remarks for the following non-comment line:
-    //    * As it is right now it could be written as
-    //      QDateTime groupStartDateTime = mEvents.first().start();
-    //    * Before r1444 the minutes were set to zero so that the time groups started at
-    //      whole hours.
-
-    // QDateTime groupStartDateTime(mEvents.first().start().date(), QTime(mEvents.first().start().time().hour(), 0));
-    QDateTime groupStartDateTime = mEvents.first().start();
+    QDateTime groupStartDateTime(mEvents.first().start().date(), QTime(mEvents.first().start().time().hour(), 0), mEvents.first().start().timeSpec());
     QDateTime groupEndDateTime = groupStartDateTime.addSecs(mEvents.first().duration());
     mGroups << EventModel::Group("", 0);
     int timeSpan = minTimeSpan;
@@ -98,7 +96,7 @@ void EventModel::createTimeGroups()
     // the last group needs a title as well
     mGroups.last().setTitle(mEvents);
 
-    reset();
+    endResetModel();
 }
 
 void EventModel::createTrackGroups() {
@@ -182,7 +180,7 @@ QModelIndex EventModel::index(int row, int column, const QModelIndex& parent) co
 
     if (!parent.isValid())
     {
-        return createIndex(row, column, 0);
+        return createIndex(row, column);
     }
     else if (parent.internalId() == 0)
     {
@@ -207,7 +205,7 @@ QModelIndex EventModel::parent(const QModelIndex & index) const
 
         Event * event = static_cast<Event*>(index.internalPointer());
 
-        return createIndex(mParents[event->id()], 0, 0);
+        return createIndex(mParents[event->id()], 0);
     }
 
     return QModelIndex();
@@ -236,51 +234,38 @@ int EventModel::rowCount (const QModelIndex & parent) const
 
 void EventModel::clearModel()
 {
+    beginResetModel();
     mGroups.clear();
     mEvents.clear();
     mParents.clear();
-
-    reset();
+    endResetModel();
 }
 
-void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
-{
+
+void EventModel::loadEvents(const QDate &aDate, int aConferenceId) {
     clearModel();
-    // check for existence of the conference in the DB
-    if(Conference::getAll().count())
-    {
-        mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start, duration");
-    }
+    mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start, duration");
     createTimeGroups();
 }
 
-void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId)
-{
+
+void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId) {
     clearModel();
-    // check for existence of the conference in the DB
-    if(Conference::getAll().count())
-    {
-        mEvents = Event::getFavByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
-    }
+    mEvents = Event::getFavByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
     createTimeGroups();
 }
 
-int EventModel::loadSearchResultEvents(const QDate &aDate, int aConferenceId)
-{
-    clearModel();
-    // check for existence of the conference in the DB
-    if(Conference::getAll().count())
-    {
-        try{
-            mEvents = Event::getSearchResultByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start, duration");
-        }
-        catch( OrmException &e  ){
-            qDebug() << "Event::getSearchResultByDate failed: " << e.text();
-        }
-        catch(...){
-            qDebug() << "Event::getSearchResultByDate failed";
-        }
 
+int EventModel::loadSearchResultEvents(const QDate &aDate, int aConferenceId) {
+    clearModel();
+    try {
+        mEvents = Event::getSearchResultByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start, duration");
+    }
+    catch( OrmException &e  ){
+        qDebug() << "Event::getSearchResultByDate failed: " << e.text();
+    }
+    catch(...){
+        qDebug() << "Event::getSearchResultByDate failed";
     }
 
     createTimeGroups();
@@ -288,37 +273,28 @@ int EventModel::loadSearchResultEvents(const QDate &aDate, int aConferenceId)
     return mEvents.count();
 }
 
-void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId)
-{
+
+void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId) {
     clearModel();
-    if (Conference::getAll().count())
-    {
-        mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "xid_track, start, duration");
-    }
+    mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "xid_track, start, duration");
     createTrackGroups();
 }
 
-void EventModel::loadEventsByRoom(const QDate &aDate, int aConferenceId)
-{
+
+void EventModel::loadEventsByRoom(const QDate &aDate, int aConferenceId) {
     clearModel();
-    if (Conference::getAll().count())
-    {
-        mEvents = Event::getByDateAndRoom(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
-    }
+    mEvents = Event::getByDateAndRoom(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
     createRoomGroups();
 }
 
 
 void EventModel::loadConflictEvents(int aEventId, int aConferenceId) {
     clearModel();
-    // check for existence of the conference in the DB
-    if(Conference::getAll().count())
-    {
-        mEvents = Event::conflictEvents(aEventId, aConferenceId);
-    }
+    mEvents = Event::conflictEvents(aEventId, aConferenceId);
     createTimeGroups();
 }
 
+
 void EventModel::updateModel(int aEventId)
 {
     for(int i=0; i<mEvents.count(); i++)