Changeset 7620de0 for src/mvc


Ignore:
Timestamp:
01/25/10 13:52:01 (12 years ago)
Author:
korrco <korrco@…>
Branches:
master, qt5
Children:
c7b58d4
Parents:
7b70507
Message:

room view added - need to test it

Location:
src/mvc
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/mvc/event.cpp

    r7b70507 r7620de0  
    11#include "event.h"
     2#include "room.h"
    23
    34QString const Event::sTableName = QString("event");
     
    4041}
    4142
     43QList<Event> Event::getByDateAndRoom(const QDate& date, int conferenceId)
     44{
     45    QSqlQuery query;
     46    QString aliasEvent("E");
     47    QString aliasEventRoom("R");
     48    query.prepare(QString("SELECT %1 FROM %2 %3, %4 %5 WHERE %3.xid_conference = :conf AND %3.start >= :start AND %3.start < :end AND %3.id = R.xid_event ORDER BY %5.xid_room, %3.start").arg(
     49                    columnsForSelect(aliasEvent), Event::sTableName, aliasEvent, "EVENT_ROOM", aliasEventRoom));
     50    query.bindValue(":conf", conferenceId);
     51    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
     52    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
     53
     54    return load(query);
     55}
     56
    4257QList<Event> Event::nowEvents(int conferenceId, QString orderBy)
    4358{
     
    6580}
    6681
    67 QList<Event> Event::getByTrack(int trackId)
    68 {
    69     QSqlQuery query;
    70     query.prepare(selectQuery() + QString("WHERE xid_track = :trackId ORDER BY start"));
    71     query.bindValue(":trackId", trackId);
    72 
    73     return load(query);
    74 }
    75 
    7682QString Event::room() const
    7783{
     
    8793    else
    8894        return QString("not-available");
     95}
     96
     97int Event::roomId() const
     98{
     99    QSqlQuery query;
     100    query.prepare("SELECT xid_room FROM event_room WHERE xid_event = :id");
     101    query.bindValue(":id", id());
     102    if (!query.isActive())
     103        if (!query.exec())
     104            throw OrmSqlException(query.lastError().text());
     105    if (!query.next())
     106        throw OrmNoObjectException();
     107    return query.record().value("xid_room").toInt();
    89108}
    90109
  • src/mvc/event.h

    r7b70507 r7620de0  
    2727    static QList<Event> nowEvents(int conferenceId, QString orderBy); // get events scheduled NOW
    2828    static QList<Event> getByTrack(int id);
     29    static QList<Event> getByDateAndRoom(const QDate& date, int conferenceId);
    2930public:
    3031    int id() const { return value("id").toInt(); }
     
    4546    // records from other tables associated with 'id'
    4647    QString room() const;
     48    int roomId() const;
    4749    QStringList persons() const;
    4850
  • src/mvc/eventmodel.cpp

    r7b70507 r7620de0  
    33#include <conference.h>
    44#include <track.h>
     5#include <room.h>
    56
    67const QString EventModel::COMMA_SEPARATOR = ", ";
     
    7475}
    7576
    76 void EventModel::createTrackGroupsNew() {
     77void EventModel::createRoomGroups()
     78{
    7779    mGroups.clear();
    7880    mParents.clear();
     
    8183        return;
    8284    }
    83     QList<Track> trackList = Track::getAll();
    84     QList<Track>::iterator track = trackList.begin();
    85     while (track != trackList.end())
    86     {
    87         QList<Event> eventList = Event::getByTrack(track->id());
    88         QList<Event>::iterator event = eventList.begin();
    89         while (event != eventList.end())
    90         {
    91             //TODO korinpa: pokracuj
    92             event++;
    93         }
    94         track++;
    95     }
     85    int roomId = mEvents.first().roomId();
     86
     87    mGroups << EventModel::Group(Room::retrieveRoomName(roomId), 0);
     88    int nextRoomId = roomId;
     89
     90    QList<Event>::iterator event = mEvents.begin();
     91    int i = 0;
     92    while (event != mEvents.end())
     93    {
     94        roomId = event->roomId();
     95        if (nextRoomId != roomId)
     96        {
     97            mGroups.last().mChildCount = i - mGroups.last().mFirstEventIndex;
     98            mGroups << EventModel::Group(Room::retrieveRoomName(roomId), i);
     99            nextRoomId = roomId;
     100        }
     101        mParents[event->id()] = mGroups.count() - 1;
     102        event++;
     103        i++;
     104    }
     105    mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex;
    96106}
    97107
     
    235245{
    236246    clearModel();
    237     if(Conference::getAll().count())
     247    if (Conference::getAll().count())
    238248    {
    239249        qDebug() << "Loading Conference Data (by Track): [" << Conference::getById(aConferenceId).title() << "] " << aDate;
     
    241251    }
    242252    createTrackGroups();
     253}
     254
     255void EventModel::loadEventsByRoom(const QDate &aDate, int aConferenceId)
     256{
     257    clearModel();
     258    if (Conference::getAll().count())
     259    {
     260        qDebug() << "Loading Conference Data (by Room): [" << Conference::getById(aConferenceId).title() << "] " << aDate;
     261        mEvents = Event::getByDateAndRoom(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
     262    }
     263    createRoomGroups();
    243264}
    244265
  • src/mvc/eventmodel.h

    r7b70507 r7620de0  
    1919    void loadEvents(const QDate &aDate, int aConferenceId); // loads Events from the DB
    2020    void loadFavEvents(const QDate &aDate, int aConferenceId); // loads Favourite events from the DB
    21     void loadEventsByTrack(const QDate &aDate, int aConferenceId); // loads Events grouped by Track from the DB
     21    void loadEventsByTrack(const QDate &aDate, int aConferenceId); // loads Events sorted by Track id and Event start from the DB
    2222    int loadSearchResultEvents(const QDate &aDate, int aConferenceId);
    2323    void loadNowEvents(int aConferenceId); // loads Now events from the DB
     24    void loadEventsByRoom(const QDate &aDate, int aConferenceId);
    2425
    2526private:
     
    4445    void createTrackGroupsNew();
    4546    void clearModel();
     47    void createRoomGroups();
    4648
    4749public slots:
  • src/mvc/mvc.pro

    r7b70507 r7620de0  
    2626    delegate.h \
    2727    eventmodel.h \
    28     treeview.h
     28    treeview.h \
     29    room.h
    2930SOURCES += event.cpp \
    3031    conference.cpp \
     
    3233    delegate.cpp \
    3334    eventmodel.cpp \
    34     treeview.cpp
     35    treeview.cpp \
     36    room.cpp
  • src/mvc/track.cpp

    r7b70507 r7620de0  
    77
    88#include "track.h"
    9 #include <QSqlTableModel>
    109
    1110QString const Track::sTableName = QString("track");
     
    1615    << QSqlField("id", QVariant::Int)
    1716    << QSqlField(NAME, QVariant::String));
    18 
    19 //QMap<int, Track> Track::mIdToTrack;
    2017
    2118class TrackInsertException : OrmSqlException
  • src/mvc/track.h

    r7b70507 r7620de0  
    1515public:
    1616    static const QSqlRecord sColumns;
    17     static const QSqlRecord sInsertColumns;
    1817    static QString const sTableName;
    1918    static const int sTableColCount;
    2019    static const QString NAME;
    2120public:
    22     static QMap<int, Track> mIdToTrack;
    23 public:
    24     int insert();
    2521    int id() const { return value("id").toInt(); }
    2622    void setId(int id) { setValue("id", id); }
    2723    QString name() const { return value("name").toString(); }
    2824    void setName(const QString & type) { setValue("name", type); }
     25    int insert();
    2926public:
    3027    static QList<Track> getAll();
Note: See TracChangeset for help on using the changeset viewer.