From 69393c0658deabe966d9fa442bae753dfdc6a9ae Mon Sep 17 00:00:00 2001 From: pavelpa Date: Wed, 13 Jan 2010 13:27:33 +0000 Subject: [PATCH] implemented 'conference' record for accessing info about the conference - events are loaded from the first day of the conference --- src/gui/mainwindow.cpp | 2 +- src/model/conference.cpp | 31 ++++++++++++++++++++++++++ src/model/conference.h | 47 ++++++++++++++++++++++++++++++++++++++++ src/model/eventmodel.cpp | 20 ++++++++++++----- src/model/eventmodel.h | 5 ++++- src/model/model.pro | 2 ++ src/sql/sqlengine.cpp | 19 ++++++++-------- 7 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 src/model/conference.cpp create mode 100644 src/model/conference.h diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 5784d47..c96079d 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -64,7 +64,7 @@ void MainWindow::importSchedule() QByteArray data = file.readAll(); mXmlParser->parseData(data,mSqlEngine); - static_cast(treeView->model())->reload(); + static_cast(treeView->model())->loadEvents(); treeView->reset(); } diff --git a/src/model/conference.cpp b/src/model/conference.cpp new file mode 100644 index 0000000..c2d7d90 --- /dev/null +++ b/src/model/conference.cpp @@ -0,0 +1,31 @@ +#include "conference.h" + +QSqlRecord const Conference::sColumns = Conference::toRecord(QList() + << 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::getAll() +{ + QSqlQuery query; + query.prepare(selectQuery()); + return load(query); +} + diff --git a/src/model/conference.h b/src/model/conference.h new file mode 100644 index 0000000..c6c8e01 --- /dev/null +++ b/src/model/conference.h @@ -0,0 +1,47 @@ +#ifndef CONFERENCE_H +#define CONFERENCE_H + +#include +#include +#include + +#include + +class Conference : public OrmRecord +{ +public: + static QSqlRecord const sColumns; + static QString const sTableName; + +public: + static Conference getById(int id); + static QList 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 */ + diff --git a/src/model/eventmodel.cpp b/src/model/eventmodel.cpp index 425079f..727fedd 100644 --- a/src/model/eventmodel.cpp +++ b/src/model/eventmodel.cpp @@ -1,9 +1,10 @@ #include "eventmodel.h" +#include -EventModel::EventModel() : - mEvents(Event::getByDate(QDate(2009, 2, 7), 1)) +EventModel::EventModel() { - createTimeGroups(); + + loadEvents(); } void EventModel::createTimeGroups() @@ -117,10 +118,19 @@ int EventModel::rowCount (const QModelIndex & parent) const 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(); } diff --git a/src/model/eventmodel.h b/src/model/eventmodel.h index 10b817a..b4b4bcf 100644 --- a/src/model/eventmodel.h +++ b/src/model/eventmodel.h @@ -14,7 +14,7 @@ public: 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 @@ -39,6 +39,9 @@ private: QList mEvents; QList mGroups; QHash mParents; + QDate mCurrentDate; + int mConfId; }; #endif // EVENTMODEL_H + diff --git a/src/model/model.pro b/src/model/model.pro index 1a80365..87ce365 100644 --- a/src/model/model.pro +++ b/src/model/model.pro @@ -12,11 +12,13 @@ TARGETDEPS += $$DESTDIR/liborm.a HEADERS += \ event.h \ + conference.h \ delegate.h \ eventmodel.h \ treeview.h SOURCES += \ event.cpp \ + conference.cpp \ delegate.cpp \ eventmodel.cpp \ treeview.cpp diff --git a/src/sql/sqlengine.cpp b/src/sql/sqlengine.cpp index b77729f..48db577 100644 --- a/src/sql/sqlengine.cpp +++ b/src/sql/sqlengine.cpp @@ -67,11 +67,11 @@ void SqlEngine::addConferenceToDB(QHash &aConference) .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); @@ -89,13 +89,12 @@ void SqlEngine::addEventToDB(QHash &aEvent) { // 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"]); @@ -200,11 +199,11 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase) 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 , \ -- 2.39.5