QByteArray data = file.readAll();
mXmlParser->parseData(data,mSqlEngine);
- static_cast<EventModel*>(treeView->model())->reload();
+ static_cast<EventModel*>(treeView->model())->loadEvents();
treeView->reset();
}
--- /dev/null
+#include "conference.h"
+
+QSqlRecord const Conference::sColumns = Conference::toRecord(QList<QSqlField>()
+ << QSqlField("id", QVariant::Int)
+ << QSqlField("title", QVariant::String)
+ << QSqlField("subtitle", QVariant::String)
+ << QSqlField("venue", QVariant::String)
+ << QSqlField("city", QVariant::String)
+ << QSqlField("start", QVariant::DateTime)
+ << QSqlField("end", QVariant::DateTime)
+ << QSqlField("days", QVariant::Int)
+ << QSqlField("day_change", QVariant::Int)
+ << QSqlField("timeslot_duration", QVariant::Int));
+
+QString const Conference::sTableName = QString("conference");
+
+Conference Conference::getById(int id)
+{
+ QSqlQuery query;
+ query.prepare(selectQuery() + "WHERE id = :id");
+ query.bindValue(":id", id);
+ return loadOne(query);
+}
+
+QList<Conference> Conference::getAll()
+{
+ QSqlQuery query;
+ query.prepare(selectQuery());
+ return load(query);
+}
+
--- /dev/null
+#ifndef CONFERENCE_H
+#define CONFERENCE_H
+
+#include <QDateTime>
+#include <QVector>
+#include <QStringList>
+
+#include <ormrecord.h>
+
+class Conference : public OrmRecord<Conference>
+{
+public:
+ static QSqlRecord const sColumns;
+ static QString const sTableName;
+
+public:
+ static Conference getById(int id);
+ static QList<Conference> getAll();
+
+public:
+ int id() const { return value("id").toInt(); }
+ QString title() const { return value("title").toString(); }
+ QString subtitle() const { return value("subtitle").toString(); }
+ QString venue() const { return value("venue").toString(); }
+ QString city() const { return value("city").toString(); }
+ QDate start() const { return value("start").toDate(); }
+ QDate end() const { return value("end").toDate(); }
+ int days() const { return value("days").toInt(); }
+ int dayChange() const { return value("day_change").toInt(); } // in seconds from 00:00
+ int timeslotDuration() const { return value("timeslot_duration").toInt(); } // in seconds
+
+ void setId(int id) { setValue("id", id); }
+ void setTitle(const QString& title) { setValue("title", title); }
+ void setSubtitle(const QString& subtitle) { setValue("subtitle", subtitle); }
+ void setVenue(const QString& venue) { setValue("venue", venue); }
+ void setCity(const QString& city) { setValue("city", city); }
+ //void setStart(const QDate& start) { setValue("start", QDateTime(start)); }
+ void setStart(const QDate& start) { setValue("start", start); }
+ //void setEnd(const QDate& end) { setValue("end", QDateTime(end)); }
+ void setEnd(const QDate& end) { setValue("end", end); }
+ void setDays(int days) { setValue("days", days); }
+ void setDayChange(int dayChange) { setValue("day_change", dayChange); }
+ void setTimeslotDuration(int timeslotDuration) { setValue("timeslot_duration", timeslotDuration); }
+};
+
+#endif /* CONFERENCE_H */
+
#include "eventmodel.h"
+#include <conference.h>
-EventModel::EventModel() :
- mEvents(Event::getByDate(QDate(2009, 2, 7), 1))
+EventModel::EventModel()
{
- createTimeGroups();
+
+ loadEvents();
}
void EventModel::createTimeGroups()
return 0;
}
-void EventModel::reload()
+void EventModel::loadEvents()
{
mEvents.clear();
- mEvents=Event::getByDate(QDate(2009, 2, 7), 1);
+
+ mConfId = 1; // current conference selected: we have only one DB so far
+ // check for existence of conference in the DB
+ if(Conference::getAll().count())
+ {
+ mCurrentDate = Conference::getById(mConfId).start();
+ qDebug() << "Loading Conference Data: [" << Conference::getById(mConfId).title() << "] " << mCurrentDate;
+ mEvents = Event::getByDate(QDate(mCurrentDate.year(), mCurrentDate.month(), mCurrentDate.day()), mConfId);
+ }
+ mEvents = Event::getByDate(QDate(mCurrentDate.year(), mCurrentDate.month(), mCurrentDate.day()), mConfId);
createTimeGroups();
}
QModelIndex parent ( const QModelIndex & index ) const;
int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
- void reload(); // reloads Events from the DB
+ void loadEvents(); // loads Events from the DB
private:
struct Group
QList<Event> mEvents;
QList<Group> mGroups;
QHash<int, int> mParents;
+ QDate mCurrentDate;
+ int mConfId;
};
#endif // EVENTMODEL_H
+
HEADERS += \
event.h \
+ conference.h \
delegate.h \
eventmodel.h \
treeview.h
SOURCES += \
event.cpp \
+ conference.cpp \
delegate.cpp \
eventmodel.cpp \
treeview.cpp
.arg(aConference["subtitle"]) \
.arg(aConference["venue"]) \
.arg(aConference["city"]) \
- .arg(aConference["start"]) \
- .arg(aConference["end"]) \
+ .arg(QDateTime(QDate::fromString(aConference["start"],DATE_FORMAT)).toTime_t()) \
+ .arg(QDateTime(QDate::fromString(aConference["end"],DATE_FORMAT)).toTime_t()) \
.arg(aConference["days"]) \
- .arg(aConference["day_change"]) \
- .arg(aConference["timeslot_duration"]);
+ .arg(-QTime::fromString(aConference["day_change"],TIME_FORMAT).secsTo(QTime(0,0))) \
+ .arg(-QTime::fromString(aConference["timeslot_duration"],TIME_FORMAT).secsTo(QTime(0,0)));
QString query = QString("INSERT INTO CONFERENCE (id,title,subtitle,venue,city,start,end,days,day_change,timeslot_duration) VALUES (%1)").arg(values);
QSqlQuery result (query, db);
{
// The items of the Event are divided into the two tables EVENT and VIRTUAL_EVENT
// VIRTUAL_EVENT is for Full-Text-Serach Support
- QTime duration = QTime::fromString(aEvent["duration"],TIME_FORMAT);
QDateTime startDateTime = QDateTime(QDate::fromString(aEvent["date"],DATE_FORMAT),QTime::fromString(aEvent["start"],TIME_FORMAT));
QString values = QString("'%1', '%2', '%3', '%4', '%5', '%6', '%7'") \
.arg(aEvent["conference_id"]) \
.arg(aEvent["id"]) \
.arg(QString::number(startDateTime.toTime_t())) \
- .arg(QString::number(duration.hour()*3600 + duration.minute()*60 + duration.second())) \
+ .arg(-QTime::fromString(aEvent["duration"],TIME_FORMAT).secsTo(QTime(0,0))) \
.arg("123456") \
.arg(aEvent["type"]) \
.arg(aEvent["language"]);
subtitle VARCHAR, \
venue VARCHAR, \
city VARCHAR NOT NULL , \
- start DATETIME NOT NULL , \
- end DATETIME NOT NULL , \
+ start INTEGER NOT NULL , \
+ end INTEGER NOT NULL , \
days INTEGER, \
- day_change DATETIME, \
- timeslot_duration DATETIME)");
+ day_change INTEGER, \
+ timeslot_duration INTEGER)");
query.exec("CREATE TABLE ACTIVITY ( \
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , \