#include "eventmodel.h"
+#include <appsettings.h>
#include <conference.h>
+#include <track.h>
+
+const QString EventModel::COMMA_SEPARATOR = ", ";
EventModel::EventModel()
{
{
QTime eventTime = mEvents.at(i).start().time();
- if (nextGroupTime < eventTime)
+ if (nextGroupTime <= eventTime)
{
mGroups.last().mChildCount = i - mGroups.last().mFirstEventIndex;
mGroups << EventModel::Group(QString("%1 - %2").arg(nextGroupTime.toString("HH:mm"),
mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex;
}
+void EventModel::createTrackGroups() {
+ mGroups.clear();
+ mParents.clear();
+ if (mEvents.empty())
+ {
+ return;
+ }
+ int trackId = mEvents.first().trackId();
+
+ mGroups << EventModel::Group(Track::retrieveTrackName(trackId), 0);
+ int nextTrackId = trackId;
+
+ for (int i=0; i<mEvents.count(); i++)
+ {
+ trackId = mEvents.at(i).trackId();
+ if (nextTrackId != trackId)
+ {
+ mGroups.last().mChildCount = i - mGroups.last().mFirstEventIndex;
+ mGroups << EventModel::Group(Track::retrieveTrackName(trackId), i);
+ nextTrackId = trackId;
+ }
+ // add parent-child relation
+ mParents[mEvents.at(i).id()] = mGroups.count() - 1;
+ }
+ 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)
{
return mGroups.at(index.row()).mTitle;
}
- else
+ else //event data
{
return static_cast<Event*>(index.internalPointer())->id();
}
return 0;
}
-void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
+void EventModel::clearModel()
{
- for(int i=0; i<mGroups.count(); i++)
- {
- QModelIndex idx = index(i,0);
+ for(int i = 0;i < mGroups.count();i++){
+ QModelIndex idx = index(i, 0);
Group group = mGroups[i];
- beginRemoveRows(idx,0,group.mChildCount-1);
- bool ok = removeRows(0,group.mChildCount,idx);
+ beginRemoveRows(idx, 0, group.mChildCount - 1);
+ /*bool ok =*/ removeRows(0, group.mChildCount, idx);
endRemoveRows();
//qDebug() << "removing " << group.mChildCount << " events from group:" << i << idx.data() << ":" << ok;
}
-
mEvents.clear();
+}
+void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
+{
+ clearModel();
// 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);
+ mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start");
}
createTimeGroups();
}
void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId)
{
- for(int i=0; i<mGroups.count(); i++)
+ clearModel();
+ // check for existence of the conference in the DB
+ if(Conference::getAll().count())
{
- QModelIndex idx = index(i,0);
- Group group = mGroups[i];
- beginRemoveRows(idx,0,group.mChildCount-1);
- bool ok = removeRows(0,group.mChildCount,idx);
- endRemoveRows();
- //qDebug() << "removing " << group.mChildCount << " events from group:" << i << idx.data() << ":" << ok;
+ qDebug() << "Loading FAV Conference Data: [" << Conference::getById(aConferenceId).title() << "] " << aDate;
+ mEvents = Event::getFavByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
}
+ createTimeGroups();
+}
- mEvents.clear();
+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;
+ 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)
+{
+ 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");
+ }
+ createTrackGroups();
+}
+void EventModel::loadNowEvents(int aConferenceId)
+{
+ clearModel();
// 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);
+ qDebug() << "Loading Conference Data: [" << Conference::getById(aConferenceId).title() << "] scheduled NOW";
+ mEvents = Event::nowEvents(aConferenceId, "start");
}
createTimeGroups();
}
-void EventModel::emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight)
+void EventModel::updateModel(int aEventId)
{
- emit(dataChanged(aTopLeft,aBottomRight));
+ 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));
+ }
+ }
+ }
}