source: src/mvc/activity.cpp @ 5d7c9e5

qt5
Last change on this file since 5d7c9e5 was 9208bdb, checked in by korrco <korrco@…>, 13 years ago

support for view activities with their names added

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/*
2 * activity.cpp
3 *
4 *  Created on: Dec 27, 2009
5 *      Author: Pavol Korinek
6 */
7
8#include "activity.h"
9
10QString const Activity::sTableName = QString("activity");
11int const Activity::sTableColCount = 2;
12
13QSqlRecord const Activity::sColumns = Activity::toRecord(QList<QSqlField>()
14    << QSqlField("id", QVariant::Int)
15    << QSqlField("name", QVariant::String));
16
17QList<Activity> Activity::getAll()
18{
19    QSqlQuery query;
20    query.prepare(selectQuery());
21    return load(query);
22}
23
24QMap<int, Activity>* Activity::mIdToActivity = 0;
25
26void Activity::updateActivityMap()
27{
28    if (mIdToActivity)
29    {
30        delete mIdToActivity;
31    }
32    mIdToActivity = new QMap<int, Activity>;
33    QList<Activity> activityList = Activity::getAll();
34    Activity activity;
35    for (int id = 0; id < activityList.count(); ++id) {
36        activity = activityList.at(id);
37        mIdToActivity->insert(activity.id(), activity);
38    }
39}
40
41QString Activity::getActivityName(int id)
42{
43    QString name = mIdToActivity->value(id).name();
44    if (name == "") {
45        qDebug() << QString("Error: undefined activity name for id %1").arg(id);
46    }
47    return name;
48}
Note: See TracBrowser for help on using the repository browser.