Changeset 5a73d27 for src


Ignore:
Timestamp:
12/29/09 18:04:41 (13 years ago)
Author:
komarma <komarma@…>
Branches:
master, qt5
Children:
20a6010
Parents:
e5bc908
Message:

Adding orm module

Location:
src
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/fosdem.pro

    re5bc908 r5a73d27  
    11TEMPLATE = subdirs
    2 SUBDIRS  = model gui app test
     2SUBDIRS  = orm model gui app test
    33CONFIG += ordered
    44
  • src/model/event.cpp

    re5bc908 r5a73d27  
    11#include "event.h"
    22
    3 Event Event::getById(int id, int conferenceId)
    4 {
    5     Event newEvent;
    6     return newEvent;
    7 }
     3QStringList const Event::sColNames = QStringList()
     4    << "id" << "xid_conference" << "start" << "duration" << "xid_activity" << "type" << "language";
     5
     6QString const Event::sTableName = QString("event");
  • src/model/event.h

    re5bc908 r5a73d27  
    33
    44#include <QDateTime>
     5#include <QVector>
     6#include <QStringList>
    57
    6 class Event
     8#include <ormrecord.h>
     9
     10
     11/**
     12  NoSuchEventException is thrown when required event does not exist.
     13*/
     14class NoSuchEventException
     15{
     16};
     17
     18class Event : public OrmRecord <Event>
    719{
    820public:
    9     static Event getById(int id, int conferenceId);
     21    // column definition
     22    enum Column
     23    {
     24        Id = 0,
     25        Conference,
     26        Start,
     27        Duration,
     28        Activity,
     29        Type,
     30        Language
     31    };
     32
     33    static QStringList const sColNames;
     34
     35    static QString const sTableName;
    1036
    1137public:
    12     int id() const { return mId; }
    13     int conferenceId() const { return mConferenceId; }
    14     QDateTime start() const { return mStart; }
    15     int duration() const { return mDuration; }
    16     int activityId() const { return mActivityId; }
    17     int typeId() const { return mTypeId; }
    18     int languageId() const { return mLanguageId; }
     38    static Event getById(int id, int conferenceId) { return Event(); } //EventTable::selectOne("id=1"); }
    1939
    20 private:
    21     Event() {}; // private constructor, use static methods to access instances
     40public:
     41    int id() const { return value(Id).toInt(); }
     42    int conferenceId() const { return value(Conference).toInt(); }
     43    QDateTime start() const { return value(Start).toDateTime(); }
     44    int duration() const { return value(Duration).toInt(); }
     45    int activityId() const { return value(Activity).toInt(); }
     46    int typeId() const { return value(Type).toInt(); }
     47    int languageId() const { return value(Language).toInt(); }
    2248
    23 private:
    24     int mId;
    25     int mConferenceId;
    26     QDateTime mStart;
    27     int mDuration;
    28     int mActivityId;
    29     int mTypeId;
    30     int mLanguageId;
     49    void setId(int id) { setValue(Id, id); }
     50    void setConferenceId(int conferenceId) { setValue(Conference, conferenceId); }
     51    void setStart(const QDateTime& start) { setValue(Start, start); }
     52    void setDuration(int duration) { setValue(Duration, duration); }
     53    void setActivityId(int activityId) { setValue(Activity, activityId); }
     54    void setTypeId(int typeId) { setValue(Type, typeId); }
     55    void setLanguageId(int languageId) { setValue(Language, languageId); }
    3156};
    3257
     58
     59
    3360#endif // EVENT_H
  • src/model/model.pro

    re5bc908 r5a73d27  
    33DESTDIR = ../bin
    44CONFIG += static
     5QT += sql
    56
    67# module dependencies
    7 DEPENDPATH += .
     8LIBS += -L$$DESTDIR -lorm
     9INCLUDEPATH += ../orm
     10DEPENDPATH += . ../orm
     11TARGETDEPS += $$DESTDIR/liborm.a
    812
    913HEADERS += event.h
  • src/test/model/eventtest.cpp

    re5bc908 r5a73d27  
    33#include <QtTest>
    44#include <QSqlDatabase>
     5
     6#include <QDebug>
    57
    68#include <event.h>
     
    2527    QCOMPARE(event.languageId(), 0);
    2628}
     29
     30void EventTest::colNames()
     31{
     32    QCOMPARE(Event::colName(Event::Id), QString("id"));
     33    QCOMPARE(Event::colName(Event::Conference), QString("xid_conference"));
     34    QCOMPARE(Event::colName(Event::Start), QString("start"));
     35    QCOMPARE(Event::colName(Event::Duration), QString("duration"));
     36    QCOMPARE(Event::colName(Event::Activity), QString("xid_activity"));
     37    QCOMPARE(Event::colName(Event::Type), QString("type"));
     38    QCOMPARE(Event::colName(Event::Language), QString("language"));
     39}
     40
     41void EventTest::storingValues()
     42{
     43    Event event;
     44    QCOMPARE(event.id(), 0);
     45
     46    event.setId(10);
     47    QCOMPARE(event.id(), 10);
     48
     49    event.setConferenceId(20);
     50    QCOMPARE(event.conferenceId(), 20);
     51
     52    event.setStart(QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
     53    QCOMPARE(event.start(), QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
     54
     55    event.setDuration(30);
     56    QCOMPARE(event.duration(), 30);
     57
     58    event.setActivityId(40);
     59    QCOMPARE(event.activityId(), 40);
     60
     61    event.setTypeId(50);
     62    QCOMPARE(event.typeId(), 50);
     63
     64    event.setLanguageId(60);
     65    QCOMPARE(event.languageId(), 60);
     66}
  • src/test/model/eventtest.h

    re5bc908 r5a73d27  
    1212
    1313    void getById();
     14    void colNames();
     15    void storingValues();
    1416};
    1517
  • src/test/test.pro

    re5bc908 r5a73d27  
    77# module dependencies
    88LIBS += -L$$DESTDIR -lgui -lmodel
    9 INCLUDEPATH += ../gui ../model
    10 DEPENDPATH += . ../gui ../model
    11 TARGETDEPS += $$DESTDIR/libmodel.a $$DESTDIR/libgui.a
     9INCLUDEPATH += ../gui ../model ../orm
     10DEPENDPATH += . ../gui ../model ../orm
     11TARGETDEPS += $$DESTDIR/libmodel.a $$DESTDIR/libgui.a $$DESTDIR/liborm.a
    1212
    1313SOURCES += main.cpp \
Note: See TracChangeset for help on using the changeset viewer.