changed 'Activity' -> 'Track'
authorpavelpa <pavelpa@localhost>
Wed, 20 Jan 2010 21:02:30 +0000 (21:02 +0000)
committerpavelpa <pavelpa@localhost>
Wed, 20 Jan 2010 21:02:30 +0000 (21:02 +0000)
15 files changed:
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/gui/mainwindow.ui
src/mvc/activity.cpp [deleted file]
src/mvc/activity.h [deleted file]
src/mvc/delegate.cpp
src/mvc/event.cpp
src/mvc/event.h
src/mvc/eventmodel.cpp
src/mvc/eventmodel.h
src/mvc/mvc.pro
src/mvc/track.cpp [new file with mode: 0644]
src/mvc/track.h [new file with mode: 0644]
src/sql/sqlengine.cpp
src/test/mvc/eventtest.cpp

index 1c1becf..00ae49b 100644 (file)
@@ -6,7 +6,7 @@
 #include <sqlengine.h>
 #include <schedulexmlparser.h>
 
-#include <activity.h>
+#include <track.h>
 #include <eventmodel.h>
 #include <delegate.h>
 
@@ -39,12 +39,12 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
     connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
     statusBar()->showMessage(tr("Ready"));
 
-    //update activity map
-    Activity::updateActivityMap();
+    //update track map
+    Track::updateTrackMap();
 
     connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
-    connect(activityDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateActivitiesDayView(const QDate &)));
-    connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesDayView(const QDate &)));
+    connect(trackDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTracksView(const QDate &)));
+    connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesView(const QDate &)));
 
     // DAY EVENTS View
     dayTreeView->setHeaderHidden(true);
@@ -63,12 +63,12 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
     favTreeView->setItemDelegate(new Delegate(favTreeView));
 
     //ACTIVITIES View
-    actTreeView->setHeaderHidden(true);
-    actTreeView->setRootIsDecorated(false);
-    actTreeView->setIndentation(0);
-    actTreeView->setAnimated(true);
-    actTreeView->setModel(new EventModel());
-    actTreeView->setItemDelegate(new Delegate(actTreeView));
+    trackTreeView->setHeaderHidden(true);
+    trackTreeView->setRootIsDecorated(false);
+    trackTreeView->setIndentation(0);
+    trackTreeView->setAnimated(true);
+    trackTreeView->setModel(new EventModel());
+    trackTreeView->setItemDelegate(new Delegate(trackTreeView));
 
     // DAY EVENTS View
        searchTreeView->setHeaderHidden(true);
@@ -82,12 +82,12 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
     // event clicked
     connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
     connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
-    connect(actTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
+    connect(trackTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
     connect(searchTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
     // request for map to be displayed
     connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
     connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
-    connect(actTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
+    connect(trackTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
     connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
     // event search button clicked
     connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
@@ -102,14 +102,14 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
     if(!Conference::getAll().count()) // no conference(s) in the DB
     {
         dayNavigator->hide(); // hide DayNavigatorWidget
-        activityDayNavigator->hide();
+        trackDayNavigator->hide();
     }
     else
     {
         QDate aStartDate = Conference::getById(confId).start();
         QDate aEndDate = Conference::getById(confId).end();
         dayNavigator->setDates(aStartDate, aEndDate);
-        activityDayNavigator->setDates(aStartDate, aEndDate);
+        trackDayNavigator->setDates(aStartDate, aEndDate);
         favouriteDayNavigator->setDates(aStartDate, aEndDate);
     }
 
@@ -161,10 +161,10 @@ void MainWindow::importSchedule()
         QDate aStartDate = Conference::getById(confId).start();
         QDate aEndDate = Conference::getById(confId).end();
         dayNavigator->setDates(aStartDate, aEndDate);
-        activityDayNavigator->setDates(aStartDate, aEndDate);
+        trackDayNavigator->setDates(aStartDate, aEndDate);
     }
-    //update activity map
-    Activity::updateActivityMap();
+    //update track map
+    Track::updateTrackMap();
 }
 
 void MainWindow::showParsingProgress(int aStatus)
@@ -206,11 +206,11 @@ void MainWindow::updateTab(const int aIndex)
             favouriteDayNavigator->show();
         }
         break;
-    case 2: //index 2 of tabWidget: activitiesTab
+    case 2: //index 2 of tabWidget: trackTab
         {
-            static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(Conference::getById(confId).start(), confId);
-            actTreeView->reset();
-            activityDayNavigator->show();
+            static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(Conference::getById(confId).start(), confId);
+            trackTreeView->reset();
+            trackDayNavigator->show();
         }
         break;
     default:
@@ -220,14 +220,14 @@ void MainWindow::updateTab(const int aIndex)
     };
 }
 
-void MainWindow::updateActivitiesDayView(const QDate &aDate)
+void MainWindow::updateTracksView(const QDate &aDate)
 {
-    static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(aDate, confId);
-    actTreeView->reset();
-    activityDayNavigator->show();
+    static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(aDate, confId);
+    trackTreeView->reset();
+    trackDayNavigator->show();
 }
 
-void MainWindow::updateFavouritesDayView(const QDate &aDate)
+void MainWindow::updateFavouritesView(const QDate &aDate)
 {
     static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,confId);
     favTreeView->reset();
index c55b121..25fa6c8 100644 (file)
@@ -22,8 +22,8 @@ private slots:
     void aboutApp();
     void updateDayView(const QDate &aDate);
     void updateTab(const int n);
-    void updateActivitiesDayView(const QDate &aDate);
-    void updateFavouritesDayView(const QDate &aDate);
+    void updateTracksView(const QDate &aDate);
+    void updateFavouritesView(const QDate &aDate);
     void itemClicked(const QModelIndex &aIndex);
     void displayMap(const QModelIndex &aIndex);
     void searchClicked();
index c2df896..57d3afa 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>531</width>
-    <height>373</height>
+    <width>609</width>
+    <height>431</height>
    </rect>
   </property>
   <property name="minimumSize" >
       </widget>
       <widget class="QWidget" name="activitiesTab" >
        <attribute name="title" >
-        <string>Activities</string>
+        <string>Tracks</string>
        </attribute>
        <layout class="QGridLayout" name="gridLayout_4" >
         <item row="0" column="0" >
          <layout class="QVBoxLayout" name="activitiesVerticalLayout" >
           <item>
-           <widget class="DayNavigatorWidget" native="1" name="activityDayNavigator" />
+           <widget class="DayNavigatorWidget" native="1" name="trackDayNavigator" />
           </item>
           <item>
-           <widget class="TreeView" name="actTreeView" >
+           <widget class="TreeView" name="trackTreeView" >
             <property name="maximumSize" >
              <size>
               <width>16777215</width>
         </item>
        </layout>
       </widget>
-      <widget class="QWidget" name="searchTab">
-       <attribute name="title">
+      <widget class="QWidget" name="searchTab" >
+       <attribute name="title" >
         <string>Search</string>
        </attribute>
-       <layout class="QVBoxLayout" name="verticalLayout_3">
-         <item>
-          <layout class="QFormLayout" name="formLayout">
-           <property name="fieldGrowthPolicy">
-            <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
-           </property>
-           <item row="0" column="0">
-            <widget class="QCheckBox" name="searchTitle">
-             <property name="text">
-              <string>Title</string>
-             </property>
-            </widget>
-           </item>
-           <item row="0" column="1">
-            <layout class="QHBoxLayout" name="horizontalLayout">
-             <item>
-              <widget class="QLineEdit" name="searchEdit">
-               <property name="enabled">
-                <bool>true</bool>
-               </property>
-               <property name="toolTip">
-                <string>type a keyword to search</string>
-               </property>
-              </widget>
-             </item>
-             <item>
-              <widget class="QPushButton" name="searchButton">
-               <property name="text">
-                <string>Search</string>
-               </property>
-               <property name="checkable">
-                <bool>false</bool>
-               </property>
-               <property name="autoDefault">
-                <bool>false</bool>
-               </property>
-               <property name="default">
-                <bool>true</bool>
-               </property>
-               <property name="flat">
-                <bool>false</bool>
-               </property>
-              </widget>
-             </item>
-            </layout>
-           </item>
-           <item row="1" column="0">
-            <widget class="QCheckBox" name="searchAbstract">
-             <property name="text">
-              <string>Abstract</string>
-             </property>
-            </widget>
-           </item>
-          </layout>
-         </item>
-         <item>
-          <widget class="DayNavigatorWidget" name="searchDayNavigator" native="true">
-           <property name="maximumSize">
-            <size>
-             <width>16777215</width>
-             <height>16777215</height>
-            </size>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="TreeView" name="searchTreeView">
-           <property name="maximumSize">
-            <size>
-             <width>16777215</width>
-             <height>16777215</height>
-            </size>
-           </property>
-          </widget>
-         </item>
-        </layout>
+       <layout class="QVBoxLayout" name="verticalLayout_3" >
+        <item>
+         <layout class="QFormLayout" name="formLayout" >
+          <property name="fieldGrowthPolicy" >
+           <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
+          </property>
+          <item row="0" column="0" >
+           <widget class="QCheckBox" name="searchTitle" >
+            <property name="text" >
+             <string>Title</string>
+            </property>
+           </widget>
+          </item>
+          <item row="0" column="1" >
+           <layout class="QHBoxLayout" name="horizontalLayout" >
+            <item>
+             <widget class="QLineEdit" name="searchEdit" >
+              <property name="enabled" >
+               <bool>true</bool>
+              </property>
+              <property name="toolTip" >
+               <string>type a keyword to search</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QPushButton" name="searchButton" >
+              <property name="text" >
+               <string>Search</string>
+              </property>
+              <property name="checkable" >
+               <bool>false</bool>
+              </property>
+              <property name="autoDefault" >
+               <bool>false</bool>
+              </property>
+              <property name="default" >
+               <bool>true</bool>
+              </property>
+              <property name="flat" >
+               <bool>false</bool>
+              </property>
+             </widget>
+            </item>
+           </layout>
+          </item>
+          <item row="1" column="0" >
+           <widget class="QCheckBox" name="searchAbstract" >
+            <property name="text" >
+             <string>Abstract</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </item>
+        <item>
+         <widget class="DayNavigatorWidget" native="1" name="searchDayNavigator" >
+          <property name="maximumSize" >
+           <size>
+            <width>16777215</width>
+            <height>16777215</height>
+           </size>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="TreeView" name="searchTreeView" >
+          <property name="maximumSize" >
+           <size>
+            <width>16777215</width>
+            <height>16777215</height>
+           </size>
+          </property>
+         </widget>
+        </item>
+       </layout>
       </widget>
-      <widget class="QWidget" name="mapTab">
-       <attribute name="title">
+      <widget class="QWidget" name="mapTab" >
+       <attribute name="title" >
         <string>Map</string>
        </attribute>
       </widget>
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>531</width>
+     <width>609</width>
      <height>22</height>
     </rect>
    </property>
diff --git a/src/mvc/activity.cpp b/src/mvc/activity.cpp
deleted file mode 100644 (file)
index 2ff2d6b..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * activity.cpp
- *
- *  Created on: Dec 27, 2009
- *      Author: Pavol Korinek
- */
-
-#include "activity.h"
-
-QString const Activity::sTableName = QString("activity");
-int const Activity::sTableColCount = 2;
-
-QSqlRecord const Activity::sColumns = Activity::toRecord(QList<QSqlField>()
-    << QSqlField("id", QVariant::Int)
-    << QSqlField("name", QVariant::String));
-
-QMap<int, Activity> Activity::mIdToActivity;
-
-QList<Activity> Activity::getAll()
-{
-    QSqlQuery query;
-    query.prepare(selectQuery());
-    return load(query);
-}
-
-void Activity::updateActivityMap()
-{
-    mIdToActivity.clear();
-    QList<Activity> activityList = Activity::getAll();
-    Activity activity;
-    for (int id = 0; id < activityList.count(); ++id) {
-        activity = activityList.at(id);
-        mIdToActivity.insert(activity.id(), activity);
-    }
-}
-
-QString Activity::getActivityName(int id)
-{
-    QString name = mIdToActivity.value(id).name();
-    if (name == "") {
-        qDebug() << QString("Error: undefined activity name for id %1").arg(id);
-    }
-    return name;
-}
diff --git a/src/mvc/activity.h b/src/mvc/activity.h
deleted file mode 100644 (file)
index 7a300ec..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * activity.h
- *
- *  Created on: Dec 27, 2009
- *      Author: Pavol Korinek
- */
-
-#ifndef ACTIVITY_H_
-#define ACTIVITY_H_
-
-#include <ormrecord.h>
-
-class Activity : public OrmRecord<Activity>
-{
-public:
-    static const QSqlRecord sColumns;
-    static QString const sTableName;
-    static const int sTableColCount;
-public:
-    static QMap<int, Activity> mIdToActivity;
-public:
-    static QList<Activity> getAll();
-    int id() const { return value("id").toInt(); }
-    void setId(int id) { setValue("id", id); }
-    QString name() const { return value("name").toString(); }
-    void setName(const QString & type) { setValue("name", type); }
-public:
-    static void updateActivityMap();
-    static QString getActivityName(int id);
-};
-
-#endif /* ACTIVITY_H_ */
index 59d6489..54808b8 100644 (file)
@@ -1,6 +1,6 @@
 #include "delegate.h"
 #include "eventmodel.h"
-#include <activity.h>
+#include <track.h>
 
 #include <QDebug>
 #include <QPainter>
@@ -62,7 +62,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         fontBigB.setBold(true);
         QFontMetrics fmBigB(fontBigB);
 
-        int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width();
+        //int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width();
 
         if(isLast(index))
         {
@@ -164,7 +164,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         painter->drawText(titlePointF,"Presenter(s): " + event->persons().join(" and "));
         // track
         titlePointF.setY(titlePointF.y()+fmSmall.height()-fmSmall.descent());
-        painter->drawText(titlePointF,"Activity(s): " + Activity::getActivityName(event->activityId()));
+        painter->drawText(titlePointF,"Track: " + Track::getTrackName(event->trackId()));
     }
     else // doesn't have parent - time-groups' elements (top items)
     {
index 18b6e33..022a8ac 100644 (file)
@@ -7,10 +7,6 @@ QString const Event::sTable1Name = QString("event");
 QString const Event::sTable2Name = QString("virtual_event");
 int const Event::sTable1ColCount = 9; // see 'toRecord()' for more details
 int const Event::sTable2ColCount = 5; // see 'toRecord()' for more details
-const QString Event::XID_ACTIVITY = "xid_activity";
-const QString Event::START = "start";
-
-
 
 QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
     /* 'columns from Table 1 */
@@ -18,7 +14,7 @@ QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
     << QSqlField("xid_conference", QVariant::Int)
     << QSqlField("start", QVariant::DateTime)
     << QSqlField("duration", QVariant::Int)
-    << QSqlField("xid_activity", QVariant::Int)
+    << QSqlField("xid_track", QVariant::Int)
     << QSqlField("type", QVariant::String)
     << QSqlField("language", QVariant::String)
     << QSqlField("favourite", QVariant::Bool)
index 8c99f4f..2b392dc 100644 (file)
@@ -23,8 +23,6 @@ public:
     static const QString sTable2Name;
     static const int sTable1ColCount;
     static const int sTable2ColCount;
-    static const QString XID_ACTIVITY;
-    static const QString START;
 public:
     static Event getById(int id, int conferenceId);
     static QList<Event> getByDate(const QDate & date, int conferenceId, QString orderBy);
@@ -33,9 +31,9 @@ public:
     // Table 1
     int id() const { return value("id").toInt(); }
     int conferenceId() const { return value("xid_conference").toInt(); }
-    QDateTime start() const { return value(START).toDateTime(); }
+    QDateTime start() const { return value("start").toDateTime(); }
     int duration() const { return value("duration").toInt(); }
-    int activityId() const { return value(XID_ACTIVITY).toInt(); }
+    int trackId() const { return value("xid_track").toInt(); }
     QString type() const { return value("type").toString(); }
     QString language() const { return value("language").toString(); }
     bool isFavourite() const { return value("favourite").toBool(); }
@@ -54,9 +52,9 @@ public:
     // Table 1
     void setId(int id) { setValue("id", id); }
     void setConferenceId(int conferenceId) { setValue("xid_conference", conferenceId); }
-    void setStart(const QDateTime & start) { setValue(START, start); }
+    void setStart(const QDateTime & start) { setValue("start", start); }
     void setDuration(int duration) { setValue("duration", duration); }
-    void setActivityId(int activityId) { setValue(XID_ACTIVITY, activityId); }
+    void setTrackId(int trackId) { setValue("xid_track", trackId); }
     void setType(const QString & type) { setValue("type", type); }
     void setLanguage(const QString & language) { setValue("language", language); }
     void setFavourite(bool favourite) { setValue("favourite", (int)((favourite))); }
index 498677c..c877f02 100644 (file)
@@ -1,8 +1,6 @@
 #include "eventmodel.h"
 #include <conference.h>
-#include <activity.h>
-
-const QString EventModel::COMMA_SEPARATOR = ", ";
+#include <track.h>
 
 EventModel::EventModel()
 {
@@ -45,26 +43,26 @@ void EventModel::createTimeGroups()
     mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex;
 }
 
-void EventModel::createActivityGroups() {
+void EventModel::createTrackGroups() {
     mGroups.clear();
     mParents.clear();
     if (mEvents.empty())
     {
         return;
     }
-    int activityId = mEvents.first().activityId();
+    int trackId = mEvents.first().trackId();
 
-    mGroups << EventModel::Group(Activity::getActivityName(activityId), 0);
-    int nextActivityId = activityId;
+    mGroups << EventModel::Group(Track::getTrackName(trackId), 0);
+    int nextTrackId = trackId;
 
     for (int i=0; i<mEvents.count(); i++)
     {
-        activityId = mEvents.at(i).activityId();
-        if (nextActivityId != activityId)
+        trackId = mEvents.at(i).trackId();
+        if (nextTrackId != trackId)
         {
             mGroups.last().mChildCount = i - mGroups.last().mFirstEventIndex;
-            mGroups << EventModel::Group(Activity::getActivityName(activityId), i);
-            nextActivityId = activityId;
+            mGroups << EventModel::Group(Track::getTrackName(trackId), i);
+            nextTrackId = trackId;
         }
         // add parent-child relation
         mParents[mEvents.at(i).id()] = mGroups.count() - 1;
@@ -167,7 +165,7 @@ void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
     if(Conference::getAll().count())
     {
         qDebug() << "Loading Conference Data: [" << Conference::getById(aConferenceId).title() << "] " << aDate;
-        mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, Event::START);
+        mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start");
     }
     createTimeGroups();
 }
@@ -184,15 +182,15 @@ void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId)
     createTimeGroups();
 }
 
-void EventModel::loadEventsByActivities(const QDate &aDate, int aConferenceId)
+void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId)
 {
     clearModel();
     if(Conference::getAll().count())
     {
-        qDebug() << "Loading Conference Data (by Activities): [" << Conference::getById(aConferenceId).title() << "] " << aDate;
-        mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, Event::XID_ACTIVITY + COMMA_SEPARATOR + Event::START);
+        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");
     }
-    createActivityGroups();
+    createTrackGroups();
 }
 
 void EventModel::emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight)
index 55c3840..0fdbe9b 100644 (file)
@@ -18,7 +18,7 @@ public:
     int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
     void loadEvents(const QDate &aDate, int aConferenceId); // loads Events from the DB
     void loadFavEvents(const QDate &aDate, int aConferenceId); // loads Favourite events from the DB
-    void loadEventsByActivities(const QDate &aDate, int aConferenceId); // loads Events grouped by Activities from the DB
+    void loadEventsByTrack(const QDate &aDate, int aConferenceId); // loads Events grouped by Track from the DB
     // a method to force 'EventModel' emit signal 'dataChanged()'
     // a 'view', eg. 'TreeView' listens for this signal and redraws changed items(indexes)
     void emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight);
@@ -41,7 +41,7 @@ private:
 
 private:
     void createTimeGroups();
-    void createActivityGroups();
+    void createTrackGroups();
     void clearModel();
 
 private:
index 3df8840..6dfbec7 100644 (file)
@@ -18,16 +18,16 @@ maemo {
     TARGETDEPS += $$DESTDIR/libqalarm.a
 }
 
-HEADERS += activity.h \
-           event.h \
+HEADERS += event.h \
            conference.h \
+           track.h \
            delegate.h \
            eventmodel.h \
            treeview.h
 
-SOURCES += activity.cpp \
-           event.cpp \
+SOURCES += event.cpp \
            conference.cpp \
+           track.cpp \
            delegate.cpp \
            eventmodel.cpp \
            treeview.cpp
diff --git a/src/mvc/track.cpp b/src/mvc/track.cpp
new file mode 100644 (file)
index 0000000..4ac3e4b
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * track.cpp
+ *
+ *  Created on: Dec 27, 2009
+ *      Author: Pavol Korinek
+ */
+
+#include "track.h"
+
+QString const Track::sTableName = QString("track");
+int const Track::sTableColCount = 2;
+
+QSqlRecord const Track::sColumns = Track::toRecord(QList<QSqlField>()
+    << QSqlField("id", QVariant::Int)
+    << QSqlField("name", QVariant::String));
+
+QMap<int, Track> Track::mIdToTrack;
+
+QList<Track> Track::getAll()
+{
+    QSqlQuery query;
+    query.prepare(selectQuery());
+    return load(query);
+}
+
+void Track::updateTrackMap()
+{
+    mIdToTrack.clear();
+    QList<Track> trackList = Track::getAll();
+    Track track;
+    for (int id = 0; id < trackList.count(); ++id) {
+        track = trackList.at(id);
+        mIdToTrack.insert(track.id(), track);
+    }
+}
+
+QString Track::getTrackName(int id)
+{
+    QString name = mIdToTrack.value(id).name();
+    if (name == "") {
+        qDebug() << QString("Error: undefined track name for id %1").arg(id);
+    }
+    return name;
+}
diff --git a/src/mvc/track.h b/src/mvc/track.h
new file mode 100644 (file)
index 0000000..194fe9c
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * track.h
+ *
+ *  Created on: Dec 27, 2009
+ *      Author: Pavol Korinek
+ */
+
+#ifndef TRACK_H
+#define TRACK_H
+
+#include <ormrecord.h>
+
+class Track : public OrmRecord<Track>
+{
+public:
+    static const QSqlRecord sColumns;
+    static QString const sTableName;
+    static const int sTableColCount;
+public:
+    static QMap<int, Track> mIdToTrack;
+public:
+    static QList<Track> getAll();
+    int id() const { return value("id").toInt(); }
+    void setId(int id) { setValue("id", id); }
+    QString name() const { return value("name").toString(); }
+    void setName(const QString & type) { setValue("name", type); }
+public:
+    static void updateTrackMap();
+    static QString getTrackName(int id);
+};
+
+#endif /* TRACK_H */
+
index d0efe13..d74792b 100644 (file)
@@ -86,24 +86,23 @@ void SqlEngine::addEventToDB(QHash<QString,QString> &aEvent)
 
     if (db.isValid() && db.isOpen())
     {
-        // track/activity has to be handled as the first, since it is necessary to get
-        // track ID from the ACTIVITY table, or to create new ACTIVITY record
+        // track has to be handled as the first, since it is necessary to get
+        // track ID from the TRACK table, or to create new TRACK record
         // and get the ID from newly created record
-        QString queryExist = QString("SELECT id FROM activity WHERE name='%1'").arg(aEvent["track"]);
+        QString queryExist = QString("SELECT id FROM track WHERE name='%1'").arg(aEvent["track"]);
         QSqlQuery resultExist(queryExist,db);
-        // now we have to check whether ACTIVITY record with 'name' exists or not,
-        // - if it doesn't exist yet, then we have to add that record to 'ACTIVITY' table
-        //   and assign autoincremented 'id' to aActivity
-        // - if it exists, then we need to get its 'id' and assign it to aRoom
+        // now we have to check whether TRACK record with 'name' exists or not,
+        // - if it doesn't exist yet, then we have to add that record to 'TRACK' table
+        // - if it exists, then we need to get its 'id'
         int actId = -1;
-        if(resultExist.next()) // ACTIVITY record with 'name' already exists: we need to get its 'id'
+        if(resultExist.next()) // TRACK record with 'name' already exists: we need to get its 'id'
         {
             actId = resultExist.value(0).toInt();
         }
-        else // ACTIVITY record doesn't exist yet, need to create it
+        else // TRACK record doesn't exist yet, need to create it
         {
             QString values = QString("'%1'").arg(aEvent["track"]);
-            QString query = QString("INSERT INTO activity (name) VALUES (%1)").arg(values);
+            QString query = QString("INSERT INTO track (name) VALUES (%1)").arg(values);
             QSqlQuery result (query, db);
             actId = result.lastInsertId().toInt(); // 'id' is assigned automatically
         }
@@ -122,7 +121,7 @@ void SqlEngine::addEventToDB(QHash<QString,QString> &aEvent)
                          .arg("0") \
                          .arg("0");
 
-        QString query = QString("INSERT INTO EVENT (xid_conference, id, start, duration, xid_activity, type, language, favourite, alarm) VALUES (%1)").arg(values);
+        QString query = QString("INSERT INTO EVENT (xid_conference, id, start, duration, xid_track, type, language, favourite, alarm) VALUES (%1)").arg(values);
         QSqlQuery result (query, db);
         //LOG_AUTOTEST(query);
 
@@ -232,7 +231,7 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
             day_change INTEGER, \
             timeslot_duration INTEGER)");
 
-        query.exec("CREATE TABLE ACTIVITY ( \
+        query.exec("CREATE TABLE TRACK ( \
             id INTEGER  PRIMARY KEY AUTOINCREMENT  NOT NULL , \
             name VARCHAR NOT NULL )");
 
@@ -250,14 +249,14 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
             id INTEGER NOT NULL , \
             start INTEGER NOT NULL , \
             duration INTEGER NOT NULL , \
-            xid_activity INTEGER NOT NULL REFERENCES ACTIVITY(id), \
+            xid_track INTEGER NOT NULL REFERENCES TRACK(id), \
             type VARCHAR, \
             language VARCHAR, \
             favourite INTEGER DEFAULT 0, \
             alarm INTEGER DEFAULT 0, \
             PRIMARY KEY (xid_conference,id), \
             FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id) \
-            FOREIGN KEY(xid_activity) REFERENCES ACTIVITY(id))");
+            FOREIGN KEY(xid_track) REFERENCES TRACK(id))");
 
 #ifdef MAEMO
         // TBD: MAEMO Virtual tables compatibility (waiting for Marek).
index 232421a..59b0eb3 100644 (file)
@@ -21,7 +21,7 @@ void EventTest::getById()
 
     QCOMPARE(event.id(), 500);
     QCOMPARE(event.start(), QDateTime(QDate(2009, 2, 7), QTime(11, 30, 0), Qt::UTC));
-    QCOMPARE(event.activityId(), 123);
+    QCOMPARE(event.trackId(), 123);
 
     // !!! TODO: typeId and languageId
     QCOMPARE(event.type(), QString("Podium"));
@@ -42,7 +42,7 @@ void EventTest::storingValues()
     event.setConferenceId(20);
     event.setStart(QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
     event.setDuration(30);
-    event.setActivityId(40);
+    event.setTrackId(40);
     event.setType(QString("type"));
     event.setLanguage(QString("language"));
 
@@ -50,7 +50,7 @@ void EventTest::storingValues()
     QCOMPARE(event.conferenceId(), 20);
     QCOMPARE(event.start(), QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
     QCOMPARE(event.duration(), 30);
-    QCOMPARE(event.activityId(), 40);
+    QCOMPARE(event.trackId(), 40);
     QCOMPARE(event.type(), QString("type"));
     QCOMPARE(event.language(), QString("language"));
 }
@@ -70,12 +70,12 @@ void EventTest::hydrate()
 
 void EventTest::columnsForSelect()
 {
-    QCOMPARE(Event::columnsForSelect(), QString("id,xid_conference,start,duration,xid_activity,type,language"));
+    QCOMPARE(Event::columnsForSelect(), QString("id,xid_conference,start,duration,xid_track,type,language"));
     QCOMPARE(Event::columnsForSelect("t0"),
-             QString("t0.id,t0.xid_conference,t0.start,t0.duration,t0.xid_activity,t0.type,t0.language"));
+             QString("t0.id,t0.xid_conference,t0.start,t0.duration,t0.xid_track,t0.type,t0.language"));
 }
 
 void EventTest::selectQuery()
 {
-    QCOMPARE(Event::selectQuery(), QString("SELECT id,xid_conference,start,duration,xid_activity,type,language FROM event "));
+    QCOMPARE(Event::selectQuery(), QString("SELECT id,xid_conference,start,duration,xid_track,type,language FROM event "));
 }