]> ToastFreeware Gitweb - toast/confclerk.git/blobdiff - src/mvc/eventmodel.cpp
updated also groupings item (event parent item) if the
[toast/confclerk.git] / src / mvc / eventmodel.cpp
index 3015565b6a6a4633ce170f060b7e5e3ee25301a2..4fb24b79fa73eb75c7a4d1551aa89c7a25e234ad 100644 (file)
@@ -1,4 +1,5 @@
 #include "eventmodel.h"
+#include <appsettings.h>
 #include <conference.h>
 #include <track.h>
 
@@ -54,7 +55,7 @@ void EventModel::createTrackGroups() {
     }
     int trackId = mEvents.first().trackId();
 
-    mGroups << EventModel::Group(Track::getTrackName(trackId), 0);
+    mGroups << EventModel::Group(Track::retrieveTrackName(trackId), 0);
     int nextTrackId = trackId;
 
     for (int i=0; i<mEvents.count(); i++)
@@ -63,7 +64,7 @@ void EventModel::createTrackGroups() {
         if (nextTrackId != trackId)
         {
             mGroups.last().mChildCount = i - mGroups.last().mFirstEventIndex;
-            mGroups << EventModel::Group(Track::getTrackName(trackId), i);
+            mGroups << EventModel::Group(Track::retrieveTrackName(trackId), i);
             nextTrackId = trackId;
         }
         // add parent-child relation
@@ -72,6 +73,28 @@ void EventModel::createTrackGroups() {
     mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex;
 }
 
+void EventModel::createTrackGroupsNew() {
+    mGroups.clear();
+    mParents.clear();
+    if (mEvents.empty())
+    {
+        return;
+    }
+    QList<Track> trackList = Track::getAll();
+    QList<Track>::iterator track = trackList.begin();
+    while (track != trackList.end())
+    {
+        QList<Event> eventList = Event::getByTrack(track->id());
+        QList<Event>::iterator event = eventList.begin();
+        while (event != eventList.end())
+        {
+            //TODO korinpa: pokracuj
+            event++;
+        }
+        track++;
+    }
+}
+
 QVariant EventModel::data(const QModelIndex& index, int role) const
 {
     if (index.isValid() && role == Qt::DisplayRole)
@@ -167,7 +190,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, Event::START);
+        mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start");
     }
     createTimeGroups();
 }
@@ -184,16 +207,28 @@ void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId)
     createTimeGroups();
 }
 
-void EventModel::loadSearchResultEvents(const QDate &aDate, int aConferenceId)
+int 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");
+        try{
+            mEvents = Event::getSearchResultByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start");
+        }
+        catch( OrmException &e  ){
+            qDebug() << "Event::getSearchResultByDate failed: " << e.text();
+        }
+        catch(...){
+            qDebug() << "Event::getSearchResultByDate failed";
+        }
+
     }
+
     createTimeGroups();
+
+    return mEvents.count();
 }
 
 void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId)
@@ -207,8 +242,39 @@ void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId)
     createTrackGroups();
 }
 
-void EventModel::emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight)
+void EventModel::loadNowEvents(int aConferenceId)
 {
-    emit(dataChanged(aTopLeft,aBottomRight));
+    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::updateModel(int aEventId)
+{
+    for(int i=0; i<mEvents.count(); i++)
+    {
+        if(mEvents[i].id() == aEventId)
+            mEvents[i] = Event::getById(aEventId,AppSettings::confId());
+    }
+
+    // find the ModelIndex for given aEventId
+    for(int i=0; i<mGroups.count(); i++)
+    {
+        QModelIndex groupIndex = index(i,0,QModelIndex());
+        for(int j=0; j<mGroups[i].mChildCount; j++)
+        {
+            QModelIndex eventIndex = index(j,0,groupIndex);
+            if(static_cast<Event*>(eventIndex.internalPointer())->id() == aEventId)
+            {
+                emit(dataChanged(groupIndex,groupIndex));
+                emit(dataChanged(eventIndex,eventIndex));
+            }
+        }
+    }
 }