Changeset d0d0a66 for src


Ignore:
Timestamp:
01/02/10 22:14:10 (13 years ago)
Author:
komarma <komarma@…>
Branches:
master, qt5
Children:
9bbb44e
Parents:
489f262
Message:

Creating EventModel? class

Location:
src
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • src/app/app.pro

    r489f262 rd0d0a66  
    22TARGET = fosdem
    33DESTDIR = ../bin
     4QT += sql
    45
    56# module dependencies
  • src/gui/gui.pro

    r489f262 rd0d0a66  
    33DESTDIR = ../bin
    44CONFIG += static
     5QT += sql
    56
    67# module dependencies
    7 LIBS += -L$$DESTDIR -lmodel
    8 INCLUDEPATH += ../model
    9 DEPENDPATH += . ../model
    10 TARGETDEPS += $$DESTDIR/libmodel.a
     8LIBS += -L$$DESTDIR -lmodel -orm
     9INCLUDEPATH += ../orm ../model
     10DEPENDPATH += . ../orm ../model
     11TARGETDEPS += $$DESTDIR/liborm.a $$DESTDIR/libmodel.a
    1112
    1213
  • src/gui/mainwindow.cpp

    r489f262 rd0d0a66  
    11#include "mainwindow.h"
     2
     3#include <QTreeView>
     4
     5#include <eventmodel.h>
    26
    37MainWindow::MainWindow(QWidget *parent)
    48    : QMainWindow(parent)
    59{
     10    // open database connection
     11    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
     12    db.setDatabaseName("fosdem-test.sqlite");
     13    db.open();
     14
     15    QTreeView * view = new QTreeView(parent);
     16    this->setCentralWidget(view);
     17
     18    view->setModel(new EventModel());
    619}
  • src/model/event.cpp

    r489f262 rd0d0a66  
    1414Event Event::getById(int id, int conferenceId)
    1515{
    16     QString query = selectQuery() + "WHERE id = :id AND xid_conference = :conf";
     16    QSqlQuery query;
     17    query.prepare(selectQuery() + "WHERE id = :id AND xid_conference = :conf");
     18    query.bindValue(":id", id);
     19    query.bindValue(":conf", conferenceId);
     20    return loadOne(query);
     21}
    1722
    18     QSqlQuery q;
    19     q.prepare(query);
    20     q.bindValue(":id", id);
    21     q.bindValue(":conf", conferenceId);
    22     return loadOne(q);
     23QList<Event> Event::getByDate(const QDate& date, int conferenceId)
     24{
     25    QSqlQuery query;
     26    query.prepare(selectQuery() + "WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY start");
     27    query.bindValue(":conf", conferenceId);
     28    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
     29    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
     30
     31    return load(query);
    2332}
  • src/model/event.h

    r489f262 rd0d0a66  
    2424public:
    2525    static Event getById(int id, int conferenceId);
     26    static QList<Event> getByDate(const QDate& date, int conferenceId);
    2627
    2728public:
  • src/model/model.pro

    r489f262 rd0d0a66  
    1111TARGETDEPS += $$DESTDIR/liborm.a
    1212
    13 HEADERS += event.h
    14 SOURCES += event.cpp
     13HEADERS += \
     14    event.h \
     15    eventmodel.h
     16SOURCES += \
     17    event.cpp \
     18    eventmodel.cpp
    1519
  • src/orm/ormrecord.h

    r489f262 rd0d0a66  
    163163QVariant OrmRecord<T>::convertToDb(QVariant value, QVariant::Type colType)
    164164{
    165     if (colType == QVariant::DateTime && value.type() == QVariant::DateTime)
     165    if (colType == QVariant::DateTime && value.canConvert<QDateTime>())
    166166    {
    167167        return value.toDateTime().toTime_t();
  • src/test/model/eventtest.cpp

    r489f262 rd0d0a66  
    2727    QCOMPARE(event.type(), QString("Podium"));
    2828    QCOMPARE(event.language(), QString("English"));
     29}
     30
     31void EventTest::getByDate()
     32{
     33    QCOMPARE(Event::getByDate(QDate(2009, 2, 7), 1).count(), 127);
     34    QCOMPARE(Event::getByDate(QDate(2009, 2, 8), 1).count(), 154);
    2935}
    3036
  • src/test/model/eventtest.h

    r489f262 rd0d0a66  
    1212
    1313    void getById();
     14    void getByDate();
    1415    void storingValues();
    1516    void hydrate();
Note: See TracChangeset for help on using the changeset viewer.