support for view activities with their names added
authorkorrco <korrco@localhost>
Tue, 19 Jan 2010 20:58:29 +0000 (20:58 +0000)
committerkorrco <korrco@localhost>
Tue, 19 Jan 2010 20:58:29 +0000 (20:58 +0000)
src/gui/mainwindow.cpp
src/mvc/activity.cpp [new file with mode: 0644]
src/mvc/activity.h [new file with mode: 0644]
src/mvc/eventmodel.cpp
src/mvc/mvc.pro

index b133986..4abb672 100644 (file)
@@ -6,6 +6,7 @@
 #include <sqlengine.h>
 #include <schedulexmlparser.h>
 
+#include <activity.h>
 #include <eventmodel.h>
 #include <delegate.h>
 
@@ -38,6 +39,9 @@ MainWindow::MainWindow(QWidget *parent)
     connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
     statusBar()->showMessage(tr("Ready"));
 
+    //create activity map
+    Activity::updateActivityMap();
+
     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 &)));
@@ -135,6 +139,8 @@ void MainWindow::importSchedule()
         dayNavigator->setDates(aStartDate, aEndDate);
         activityDayNavigator->setDates(aStartDate, aEndDate);
     }
+    //update activity map
+    Activity::updateActivityMap();
 }
 
 void MainWindow::showParsingProgress(int aStatus)
@@ -178,7 +184,7 @@ void MainWindow::updateTab(const int aIndex)
         break;
     case 2: //index 2 of tabWidget: activitiesTab
         {
-            static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(Conference::getById(confId).start(),confId);
+            static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(Conference::getById(confId).start(), confId);
             actTreeView->reset();
             activityDayNavigator->show();
         }
@@ -192,7 +198,7 @@ void MainWindow::updateTab(const int aIndex)
 
 void MainWindow::updateActivitiesDayView(const QDate &aDate)
 {
-    static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(aDate,confId);
+    static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(aDate, confId);
     actTreeView->reset();
     activityDayNavigator->show();
 }
@@ -234,4 +240,3 @@ void MainWindow::displayMap(const QModelIndex &aIndex)
     MapWindow window(map,roomName,this);
     window.exec();
 }
-
diff --git a/src/mvc/activity.cpp b/src/mvc/activity.cpp
new file mode 100644 (file)
index 0000000..36ecaa1
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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));
+
+QList<Activity> Activity::getAll()
+{
+    QSqlQuery query;
+    query.prepare(selectQuery());
+    return load(query);
+}
+
+QMap<int, Activity>* Activity::mIdToActivity = 0;
+
+void Activity::updateActivityMap()
+{
+    if (mIdToActivity)
+    {
+        delete mIdToActivity;
+    }
+    mIdToActivity = new QMap<int, Activity>;
+    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
new file mode 100644 (file)
index 0000000..86be082
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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 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);
+private:
+    static QMap<int, Activity>* mIdToActivity;
+};
+
+#endif /* ACTIVITY_H_ */
index fb14a56..cefea46 100644 (file)
@@ -1,5 +1,6 @@
 #include "eventmodel.h"
 #include <conference.h>
+#include <activity.h>
 
 EventModel::EventModel()
 {
@@ -50,8 +51,8 @@ void EventModel::createActivityGroups() {
         return;
     }
     int activityId = mEvents.first().activityId();
-    //TODO korinpa: get activity name
-    mGroups << EventModel::Group(QString("activity %1").arg(activityId), 0);
+
+    mGroups << EventModel::Group(Activity::getActivityName(activityId), 0);
     int nextActivityId = activityId;
 
     for (int i=0; i<mEvents.count(); i++)
@@ -60,8 +61,8 @@ void EventModel::createActivityGroups() {
         if (nextActivityId != activityId)
         {
             mGroups.last().mChildCount = i - mGroups.last().mFirstEventIndex;
-            mGroups << EventModel::Group(QString("activity %1").arg(activityId), 0);
-            //int nextActivityId = activityId;
+            mGroups << EventModel::Group(Activity::getActivityName(activityId), i);
+            nextActivityId = activityId;
         }
         // add parent-child relation
         mParents[mEvents.at(i).id()] = mGroups.count() - 1;
index 98d9e9b..600392d 100644 (file)
@@ -6,27 +6,29 @@ CONFIG += static
 QT += sql
 
 # module dependencies
-LIBS += -L$$DESTDIR -lorm
+LIBS += -L$$DESTDIR \
+    -lorm
 INCLUDEPATH += ../orm
-DEPENDPATH += . ../orm
+DEPENDPATH += . \
+    ../orm
 TARGETDEPS += $$DESTDIR/liborm.a
-maemo {
-    LIBS += -L$$DESTDIR -lqalarm -lalarm
+maemo { 
+    LIBS += -L$$DESTDIR \
+        -lqalarm \
+        -lalarm
     INCLUDEPATH += ../alarm
-    DEPENDPATH +=  ../alarm
+    DEPENDPATH += ../alarm
     TARGETDEPS += $$DESTDIR/libqalarm.a
 }
-
-HEADERS += \
+HEADERS += activity.h \
     event.h \
     conference.h \
     delegate.h \
     eventmodel.h \
     treeview.h
-SOURCES += \
+SOURCES += activity.cpp \
     event.cpp \
     conference.cpp \
     delegate.cpp \
     eventmodel.cpp \
     treeview.cpp
-