]> ToastFreeware Gitweb - toast/confclerk.git/blobdiff - src/mvc/eventmodel.cpp
activities tab implemented
[toast/confclerk.git] / src / mvc / eventmodel.cpp
index 2753223117237d4d82ad6382eed8eb780a230d62..3015565b6a6a4633ce170f060b7e5e3ee25301a2 100644 (file)
@@ -1,5 +1,8 @@
 #include "eventmodel.h"
 #include <conference.h>
+#include <track.h>
+
+const QString EventModel::COMMA_SEPARATOR = ", ";
 
 EventModel::EventModel()
 {
@@ -42,26 +45,26 @@ void EventModel::createTimeGroups()
     mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex;
 }
 
-void EventModel::createActivityGroups() {
+void EventModel::createTrackGroups() {
     mGroups.clear();
     mParents.clear();
     if (mEvents.empty())
     {
         return;
     }
-    int activityId = mEvents.first().activityId();
-    //TODO korinpa: get activity name
-    mGroups << EventModel::Group(QString("activity %1").arg(activityId), 0);
-    int nextActivityId = activityId;
+    int trackId = mEvents.first().trackId();
+
+    mGroups << EventModel::Group(Track::getTrackName(trackId), 0);
+    int nextTrackId = trackId;
 
     for (int i=0; i<mEvents.count(); i++)
     {
-        activityId = mEvents.at(i).activityId();
-        if (nextActivityId != activityId)
+        trackId = mEvents.at(i).trackId();
+        if (nextTrackId != trackId)
         {
             mGroups.last().mChildCount = i - mGroups.last().mFirstEventIndex;
-            mGroups << EventModel::Group(QString("activity %1").arg(activityId), 0);
-            int nextActivityId = activityId;
+            mGroups << EventModel::Group(Track::getTrackName(trackId), i);
+            nextTrackId = trackId;
         }
         // add parent-child relation
         mParents[mEvents.at(i).id()] = mGroups.count() - 1;
@@ -150,7 +153,7 @@ void EventModel::clearModel()
         QModelIndex idx = index(i, 0);
         Group group = mGroups[i];
         beginRemoveRows(idx, 0, group.mChildCount - 1);
-        bool ok = removeRows(0, group.mChildCount, idx);
+        /*bool ok =*/ removeRows(0, group.mChildCount, idx);
         endRemoveRows();
         //qDebug() << "removing " << group.mChildCount << " events from group:" << i << idx.data() << ":" << ok;
     }
@@ -164,7 +167,7 @@ void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
     if(Conference::getAll().count())
     {
         qDebug() << "Loading Conference Data: [" << Conference::getById(aConferenceId).title() << "] " << aDate;
-        mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
+        mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, Event::START);
     }
     createTimeGroups();
 }
@@ -181,15 +184,27 @@ void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId)
     createTimeGroups();
 }
 
-void EventModel::loadEventsByActivities(const QDate &aDate, int aConferenceId)
+void EventModel::loadSearchResultEvents(const QDate &aDate, int aConferenceId)
+{
+    clearModel();
+    // check for existence of the conference in the DB
+    if(Conference::getAll().count())
+    {
+        qDebug() << "Loading search result Data: [" << Conference::getById(aConferenceId).title() << "] " << aDate;
+        mEvents = Event::getSearchResultByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start");
+    }
+    createTimeGroups();
+}
+
+void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId)
 {
     clearModel();
     if(Conference::getAll().count())
     {
-        qDebug() << "Loading Conference Data (by Activities): [" << Conference::getById(aConferenceId).title() << "] " << aDate;
-        mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
+        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");
     }
-    createActivityGroups();
+    createTrackGroups();
 }
 
 void EventModel::emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight)