/*
* 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 = ", ";
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"));
}
// multiple of one hour.
void EventModel::createTimeGroups()
{
+ beginResetModel();
+
mGroups.clear();
mParents.clear();
if (mEvents.empty()) return;
// the last group needs a title as well
mGroups.last().setTitle(mEvents);
- reset();
+ endResetModel();
}
void EventModel::createTrackGroups() {
if (!parent.isValid())
{
- return createIndex(row, column, 0);
+ return createIndex(row, column);
}
else if (parent.internalId() == 0)
{
Event * event = static_cast<Event*>(index.internalPointer());
- return createIndex(mParents[event->id()], 0, 0);
+ return createIndex(mParents[event->id()], 0);
}
return QModelIndex();
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();
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++)