From: korrco Date: Mon, 25 Jan 2010 12:52:01 +0000 (+0000) Subject: room view added - need to test it X-Git-Tag: 0.5.0~204 X-Git-Url: https://git.toastfreeware.priv.at/toast/confclerk.git/commitdiff_plain/7620de0102dfa0ebd5430ae5d64d11ea76b259d3?ds=sidebyside room view added - need to test it --- diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 43ae8b2..47bb535 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -53,6 +53,7 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) connect(trackDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTracksView(const QDate &))); connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesView(const QDate &))); connect(searchDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateSearchView(const QDate &))); + connect(roomDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateRoomView(const QDate &))); // DAY EVENTS View dayTreeView->setHeaderHidden(true); @@ -94,12 +95,21 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) nowTreeView->setModel(new EventModel()); nowTreeView->setItemDelegate(new Delegate(nowTreeView)); + // ROOMS View + roomTreeView->setHeaderHidden(true); + roomTreeView->setRootIsDecorated(false); + roomTreeView->setIndentation(0); + roomTreeView->setAnimated(true); + roomTreeView->setModel(new EventModel()); + roomTreeView->setItemDelegate(new Delegate(roomTreeView)); + // event details have changed connect(dayTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int))); connect(favTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int))); connect(trackTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int))); connect(searchTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int))); connect(nowTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int))); + connect(roomTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int))); // event clicked connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); @@ -107,18 +117,21 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) connect(trackTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); connect(searchTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); connect(nowTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); + connect(roomTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); // request for map to be displayed connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); connect(trackTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); connect(nowTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); + connect(roomTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); // request for warning to be displayed connect(dayTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &))); connect(favTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &))); connect(trackTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &))); connect(searchTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &))); connect(nowTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &))); + connect(roomTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &))); // event search button clicked connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked())); connect(searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked())); @@ -131,6 +144,7 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) { dayNavigator->hide(); // hide DayNavigatorWidget trackDayNavigator->hide(); + roomDayNavigator->hide(); } else { @@ -140,6 +154,7 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) trackDayNavigator->setDates(aStartDate, aEndDate); favouriteDayNavigator->setDates(aStartDate, aEndDate); searchDayNavigator->setDates(aStartDate, aEndDate); + roomDayNavigator->setDates(aStartDate, aEndDate); // conferenceTitle->setText(Conference::getById(AppSettings::confId()).title()); conferenceSubtitle->setText(Conference::getById(AppSettings::confId()).subtitle()); @@ -231,6 +246,7 @@ void MainWindow::updateFavouritesView(const QDate &aDate) void MainWindow::updateSearchView(const QDate &aDate) { +/* searchTreeView->reset(); int eventsCount = static_cast(searchTreeView->model())->loadSearchResultEvents(aDate,AppSettings::confId()); if( eventsCount ){ @@ -244,6 +260,7 @@ void MainWindow::updateSearchView(const QDate &aDate) searchVerticalWidget->hide(); searchHead->show(); } +*/ } void MainWindow::updateNowView() @@ -254,6 +271,13 @@ void MainWindow::updateNowView() nowTreeView->setAllExpanded(true); } +void MainWindow::updateRoomView(const QDate &aDate) +{ + static_cast(roomTreeView->model())->loadEventsByRoom(aDate, AppSettings::confId()); + roomTreeView->reset(); + roomDayNavigator->show(); +} + void MainWindow::itemClicked(const QModelIndex &aIndex) { // have to handle only events, not time-groups diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 8e311c2..f79c2f3 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -23,6 +23,7 @@ private slots: void updateFavouritesView(const QDate &aDate); void updateSearchView(const QDate &aDate); void updateNowView(); + void updateRoomView(const QDate &aDate); void itemClicked(const QModelIndex &aIndex); void displayMap(const QModelIndex &aIndex); void displayWarning(const QModelIndex &aIndex); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 9abb7e4..d5c48ce 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -5,8 +5,8 @@ 0 0 - 654 - 444 + 935 + 530 @@ -118,98 +118,133 @@ - - + + Search - + - - - - - - Search again - - - Qt::ToolButtonTextOnly - - - - - - - - 16777215 - 16777215 - - - - - - + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Title + + + + + + + + + true + + + type a keyword to search + + + + + + + Search + + + false + + + false + + + true + + + false + + + + + + + + + Abstract + + + + - + - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Title - - - - - - - - - true - - - type a keyword to search - - - - - - - Search - - - false - - - true - - - true - - - false - - - - - - - - - Abstract - - - - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 16777215 + 16777215 + + - - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 16777215 + 16777215 + + + + + + + + + Rooms + + + + + + QLayout::SetDefaultConstraint + + + + + + + 16777215 16777215 @@ -221,8 +256,8 @@ - - + + Conference @@ -355,7 +390,7 @@ 0 0 - 654 + 935 26 diff --git a/src/mvc/event.cpp b/src/mvc/event.cpp index 2685fb4..1af20d5 100644 --- a/src/mvc/event.cpp +++ b/src/mvc/event.cpp @@ -1,4 +1,5 @@ #include "event.h" +#include "room.h" QString const Event::sTableName = QString("event"); @@ -39,6 +40,20 @@ QList Event::getByDate(const QDate& date, int conferenceId, QString order return load(query); } +QList Event::getByDateAndRoom(const QDate& date, int conferenceId) +{ + QSqlQuery query; + QString aliasEvent("E"); + QString aliasEventRoom("R"); + 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( + columnsForSelect(aliasEvent), Event::sTableName, aliasEvent, "EVENT_ROOM", aliasEventRoom)); + query.bindValue(":conf", conferenceId); + query.bindValue(":start", convertToDb(date, QVariant::DateTime)); + query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime)); + + return load(query); +} + QList Event::nowEvents(int conferenceId, QString orderBy) { //uint curTime_t = QDateTime(QDate::currentDate(),QTime::currentTime(),Qt::UTC).toTime_t(); @@ -64,15 +79,6 @@ QList Event::getFavByDate(const QDate& date, int conferenceId) return load(query); } -QList Event::getByTrack(int trackId) -{ - QSqlQuery query; - query.prepare(selectQuery() + QString("WHERE xid_track = :trackId ORDER BY start")); - query.bindValue(":trackId", trackId); - - return load(query); -} - QString Event::room() const { QSqlQuery query; @@ -88,6 +94,19 @@ QString Event::room() const return QString("not-available"); } +int Event::roomId() const +{ + QSqlQuery query; + query.prepare("SELECT xid_room FROM event_room WHERE xid_event = :id"); + query.bindValue(":id", id()); + if (!query.isActive()) + if (!query.exec()) + throw OrmSqlException(query.lastError().text()); + if (!query.next()) + throw OrmNoObjectException(); + return query.record().value("xid_room").toInt(); +} + QStringList Event::persons() const { QSqlQuery query; diff --git a/src/mvc/event.h b/src/mvc/event.h index 8eaedc1..6c82a2b 100644 --- a/src/mvc/event.h +++ b/src/mvc/event.h @@ -26,6 +26,7 @@ public: static QList getSearchResultByDate(const QDate& date, int conferenceId, QString orderBy); static QList nowEvents(int conferenceId, QString orderBy); // get events scheduled NOW static QList getByTrack(int id); + static QList getByDateAndRoom(const QDate& date, int conferenceId); public: int id() const { return value("id").toInt(); } int conferenceId() const { return value("xid_conference").toInt(); } @@ -44,6 +45,7 @@ public: QString description() const { return value("description").toString(); } // records from other tables associated with 'id' QString room() const; + int roomId() const; QStringList persons() const; void setId(int id) { setValue("id", id); } diff --git a/src/mvc/eventmodel.cpp b/src/mvc/eventmodel.cpp index 4fb24b7..03b2ba4 100644 --- a/src/mvc/eventmodel.cpp +++ b/src/mvc/eventmodel.cpp @@ -2,6 +2,7 @@ #include #include #include +#include const QString EventModel::COMMA_SEPARATOR = ", "; @@ -73,26 +74,35 @@ void EventModel::createTrackGroups() { mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex; } -void EventModel::createTrackGroupsNew() { +void EventModel::createRoomGroups() +{ mGroups.clear(); mParents.clear(); if (mEvents.empty()) { return; } - QList trackList = Track::getAll(); - QList::iterator track = trackList.begin(); - while (track != trackList.end()) + int roomId = mEvents.first().roomId(); + + mGroups << EventModel::Group(Room::retrieveRoomName(roomId), 0); + int nextRoomId = roomId; + + QList::iterator event = mEvents.begin(); + int i = 0; + while (event != mEvents.end()) { - QList eventList = Event::getByTrack(track->id()); - QList::iterator event = eventList.begin(); - while (event != eventList.end()) + roomId = event->roomId(); + if (nextRoomId != roomId) { - //TODO korinpa: pokracuj - event++; + mGroups.last().mChildCount = i - mGroups.last().mFirstEventIndex; + mGroups << EventModel::Group(Room::retrieveRoomName(roomId), i); + nextRoomId = roomId; } - track++; + mParents[event->id()] = mGroups.count() - 1; + event++; + i++; } + mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex; } QVariant EventModel::data(const QModelIndex& index, int role) const @@ -234,7 +244,7 @@ int EventModel::loadSearchResultEvents(const QDate &aDate, int aConferenceId) void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId) { clearModel(); - if(Conference::getAll().count()) + if (Conference::getAll().count()) { qDebug() << "Loading Conference Data (by Track): [" << Conference::getById(aConferenceId).title() << "] " << aDate; mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "xid_track, start"); @@ -242,6 +252,17 @@ void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId) createTrackGroups(); } +void EventModel::loadEventsByRoom(const QDate &aDate, int aConferenceId) +{ + clearModel(); + if (Conference::getAll().count()) + { + qDebug() << "Loading Conference Data (by Room): [" << Conference::getById(aConferenceId).title() << "] " << aDate; + mEvents = Event::getByDateAndRoom(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId); + } + createRoomGroups(); +} + void EventModel::loadNowEvents(int aConferenceId) { clearModel(); diff --git a/src/mvc/eventmodel.h b/src/mvc/eventmodel.h index 44ad43c..67d1820 100644 --- a/src/mvc/eventmodel.h +++ b/src/mvc/eventmodel.h @@ -18,9 +18,10 @@ public: int rowCount ( const QModelIndex & parent = QModelIndex() ) const; void loadEvents(const QDate &aDate, int aConferenceId); // loads Events from the DB void loadFavEvents(const QDate &aDate, int aConferenceId); // loads Favourite events from the DB - void loadEventsByTrack(const QDate &aDate, int aConferenceId); // loads Events grouped by Track from the DB + void loadEventsByTrack(const QDate &aDate, int aConferenceId); // loads Events sorted by Track id and Event start from the DB int loadSearchResultEvents(const QDate &aDate, int aConferenceId); void loadNowEvents(int aConferenceId); // loads Now events from the DB + void loadEventsByRoom(const QDate &aDate, int aConferenceId); private: struct Group @@ -43,6 +44,7 @@ private: void createTrackGroups(); void createTrackGroupsNew(); void clearModel(); + void createRoomGroups(); public slots: void updateModel(int aEventId); diff --git a/src/mvc/mvc.pro b/src/mvc/mvc.pro index 69f875b..03cea46 100644 --- a/src/mvc/mvc.pro +++ b/src/mvc/mvc.pro @@ -25,10 +25,12 @@ HEADERS += event.h \ track.h \ delegate.h \ eventmodel.h \ - treeview.h + treeview.h \ + room.h SOURCES += event.cpp \ conference.cpp \ track.cpp \ delegate.cpp \ eventmodel.cpp \ - treeview.cpp + treeview.cpp \ + room.cpp diff --git a/src/mvc/room.cpp b/src/mvc/room.cpp new file mode 100644 index 0000000..429a0c7 --- /dev/null +++ b/src/mvc/room.cpp @@ -0,0 +1,50 @@ +/* + * room.cpp + * + * Created on: Dec 27, 2009 + * Author: user + */ + +#include "room.h"" + +QString const Room::sTableName = QString("room"); +int const Room::sTableColCount = 3; +const QString Room::NAME = "name"; + +QSqlRecord const Room::sColumns = Room::toRecord(QList() + << QSqlField("id", QVariant::Int) + << QSqlField(NAME, QVariant::String) + << QSqlField("picture", QVariant::String)); + +Room Room::retrieveByName(QString name) +{ + QSqlQuery query; + query.prepare( + selectQuery() + + QString("WHERE %1.name = :name").arg(sTableName)); + query.bindValue(":name", name); + return loadOne(query); +} + +QList Room::getAll() +{ + QSqlQuery query; + query.prepare(selectQuery()); + return load(query); +} + +Room Room::retrieve(int id) +{ + QSqlQuery query; + query.prepare(selectQuery() + + QString("WHERE %1.id = :id").arg(sTableName)); + query.bindValue(":id", id); + return loadOne(query); +} + +QString Room::retrieveRoomName(int id) +{ + Room room = retrieve(id); + return room.name(); +} + diff --git a/src/mvc/room.h b/src/mvc/room.h new file mode 100644 index 0000000..037a3f2 --- /dev/null +++ b/src/mvc/room.h @@ -0,0 +1,33 @@ +/* + * room.h + * + * Created on: Dec 27, 2009 + * Author: Pavol Korinek + */ + +#ifndef ROOM_H_ +#define ROOM_H_ + +#include + +class Room : public OrmRecord +{ +public: + static const QSqlRecord sColumns; + static QString const sTableName; + static const int sTableColCount; + static const QString NAME; +public: + 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); } + int insert(); +public: + static QList getAll(); + static Room retrieve(int id); + static QString retrieveRoomName(int id); + static Room retrieveByName(QString name); +}; + +#endif /* ROOM_H_ */ diff --git a/src/mvc/track.cpp b/src/mvc/track.cpp index d0d8c12..25df934 100644 --- a/src/mvc/track.cpp +++ b/src/mvc/track.cpp @@ -6,7 +6,6 @@ */ #include "track.h" -#include QString const Track::sTableName = QString("track"); int const Track::sTableColCount = 2; @@ -16,8 +15,6 @@ QSqlRecord const Track::sColumns = Track::toRecord(QList() << QSqlField("id", QVariant::Int) << QSqlField(NAME, QVariant::String)); -//QMap Track::mIdToTrack; - class TrackInsertException : OrmSqlException { public: diff --git a/src/mvc/track.h b/src/mvc/track.h index 425af6c..be6c041 100644 --- a/src/mvc/track.h +++ b/src/mvc/track.h @@ -14,18 +14,15 @@ class Track : public OrmRecord { public: static const QSqlRecord sColumns; - static const QSqlRecord sInsertColumns; static QString const sTableName; static const int sTableColCount; static const QString NAME; public: - static QMap mIdToTrack; -public: - int insert(); 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); } + int insert(); public: static QList getAll(); static Track retrieve(int id);