implemented 'conference' record for accessing info about the conference
authorpavelpa <pavelpa@localhost>
Wed, 13 Jan 2010 13:27:33 +0000 (13:27 +0000)
committerpavelpa <pavelpa@localhost>
Wed, 13 Jan 2010 13:27:33 +0000 (13:27 +0000)
 - events are loaded from the first day of the conference

src/gui/mainwindow.cpp
src/model/conference.cpp [new file with mode: 0644]
src/model/conference.h [new file with mode: 0644]
src/model/eventmodel.cpp
src/model/eventmodel.h
src/model/model.pro
src/sql/sqlengine.cpp

index 5784d47..c96079d 100644 (file)
@@ -64,7 +64,7 @@ void MainWindow::importSchedule()
 
     QByteArray data = file.readAll();
     mXmlParser->parseData(data,mSqlEngine);
-    static_cast<EventModel*>(treeView->model())->reload();
+    static_cast<EventModel*>(treeView->model())->loadEvents();
     treeView->reset();
 }
 
diff --git a/src/model/conference.cpp b/src/model/conference.cpp
new file mode 100644 (file)
index 0000000..c2d7d90
--- /dev/null
@@ -0,0 +1,31 @@
+#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);
+}
+
diff --git a/src/model/conference.h b/src/model/conference.h
new file mode 100644 (file)
index 0000000..c6c8e01
--- /dev/null
@@ -0,0 +1,47 @@
+#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 */
+
index 425079f..727fedd 100644 (file)
@@ -1,9 +1,10 @@
 #include "eventmodel.h"
+#include <conference.h>
 
-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();
 }
 
index 10b817a..b4b4bcf 100644 (file)
@@ -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<Event> mEvents;
     QList<Group> mGroups;
     QHash<int, int> mParents;
+    QDate mCurrentDate;
+    int mConfId;
 };
 
 #endif // EVENTMODEL_H
+
index 1a80365..87ce365 100644 (file)
@@ -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
index b77729f..48db577 100644 (file)
@@ -67,11 +67,11 @@ void SqlEngine::addConferenceToDB(QHash<QString,QString> &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<QString,QString> &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 , \