From b8a3ad1b0e9a8f56c97758f05897372e2355e6aa Mon Sep 17 00:00:00 2001 From: pavelpa Date: Fri, 22 Jan 2010 06:18:25 +0000 Subject: [PATCH] implemented NOW tab --- src/gui/mainwindow.cpp | 28 ++++++++++++++++++++++++---- src/gui/mainwindow.h | 1 + src/gui/mainwindow.ui | 16 +++++++++++++--- src/mvc/event.cpp | 14 ++++++++++++++ src/mvc/event.h | 1 + src/mvc/eventmodel.cpp | 12 ++++++++++++ src/mvc/eventmodel.h | 1 + src/mvc/treeview.cpp | 8 ++++++++ src/mvc/treeview.h | 2 ++ 9 files changed, 76 insertions(+), 7 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index d2d1138..7323a42 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -25,10 +25,6 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) { setupUi(this); - // TODO: conference ID should be assigned based on actual data in the DB - // for testing only - AppSettings::setConfId(1); - // connect Menu actions connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule())); connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); @@ -79,27 +75,39 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) searchTreeView->setModel(new EventModel()); searchTreeView->setItemDelegate(new Delegate(searchTreeView)); + // NOW View + nowTreeView->setHeaderHidden(true); + nowTreeView->setRootIsDecorated(false); + nowTreeView->setIndentation(0); + nowTreeView->setAnimated(true); + nowTreeView->setModel(new EventModel()); + nowTreeView->setItemDelegate(new Delegate(nowTreeView)); + // 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))); // event clicked connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); 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 &))); // 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 &))); // 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 &))); // event search button clicked connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked())); // @@ -214,6 +222,14 @@ void MainWindow::updateSearchView(const QDate &aDate) } } +void MainWindow::updateNowView() +{ + EventModel *model = static_cast(nowTreeView->model()); + model->loadNowEvents(AppSettings::confId()); + nowTreeView->reset(); + nowTreeView->setAllExpanded(true); +} + void MainWindow::itemClicked(const QModelIndex &aIndex) { // have to handle only events, not time-groups @@ -274,12 +290,16 @@ void MainWindow::eventHasChanged(int aEventId) static_cast(favTreeView->model())->updateModel(aEventId); static_cast(trackTreeView->model())->updateModel(aEventId); static_cast(searchTreeView->model())->updateModel(aEventId); + static_cast(nowTreeView->model())->updateModel(aEventId); } void MainWindow::tabHasChanged(int aIndex) { Q_UNUSED(aIndex); + // TODO: only if it changed to favourities tab updateFavouritesView(favouriteDayNavigator->getCurrentDate()); + // TODO: only if it changed to now tab + updateNowView(); } diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 00b35dc..df6b57d 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -22,6 +22,7 @@ private slots: void updateTracksView(const QDate &aDate); void updateFavouritesView(const QDate &aDate); void updateSearchView(const QDate &aDate); + void updateNowView(); 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 69b9cd0..4346117 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -5,8 +5,8 @@ 0 0 - 609 - 431 + 654 + 444 @@ -321,6 +321,16 @@ + + + Now + + + + + + + @@ -330,7 +340,7 @@ 0 0 - 609 + 654 22 diff --git a/src/mvc/event.cpp b/src/mvc/event.cpp index eccad94..821ccaf 100644 --- a/src/mvc/event.cpp +++ b/src/mvc/event.cpp @@ -39,6 +39,20 @@ QList Event::getByDate(const QDate& date, int conferenceId, QString order return load(query); } +QList Event::nowEvents(int conferenceId, QString orderBy) +{ + //uint curTime_t = QDateTime(QDate::currentDate(),QTime::currentTime(),Qt::UTC).toTime_t(); + uint curTime_t = 1265457610; // for testing + + QSqlQuery query; + query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start <= :now1 AND ( start + duration ) > :now2 ORDER BY %1").arg(orderBy)); + query.bindValue(":conf", conferenceId); + query.bindValue(":now1", convertToDb(curTime_t, QVariant::DateTime)); + query.bindValue(":now2", convertToDb(curTime_t, QVariant::DateTime)); + + return load(query); +} + QList Event::getFavByDate(const QDate& date, int conferenceId) { QSqlQuery query; diff --git a/src/mvc/event.h b/src/mvc/event.h index a667e4f..9e3b7e8 100644 --- a/src/mvc/event.h +++ b/src/mvc/event.h @@ -24,6 +24,7 @@ public: static QList getByDate(const QDate & date, int conferenceId, QString orderBy); static QList getFavByDate(const QDate & date, int conferenceId); // get Favourities by Date static QList getSearchResultByDate(const QDate& date, int conferenceId, QString orderBy); + static QList nowEvents(int conferenceId, QString orderBy); // get events scheduled NOW public: int id() const { return value("id").toInt(); } int conferenceId() const { return value("xid_conference").toInt(); } diff --git a/src/mvc/eventmodel.cpp b/src/mvc/eventmodel.cpp index 813844f..db09178 100644 --- a/src/mvc/eventmodel.cpp +++ b/src/mvc/eventmodel.cpp @@ -220,6 +220,18 @@ void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId) createTrackGroups(); } +void EventModel::loadNowEvents(int aConferenceId) +{ + clearModel(); + // check for existence of the conference in the DB + if(Conference::getAll().count()) + { + qDebug() << "Loading Conference Data: [" << Conference::getById(aConferenceId).title() << "] scheduled NOW"; + mEvents = Event::nowEvents(aConferenceId, "start"); + } + createTimeGroups(); +} + void EventModel::updateModel(int aEventId) { for(int i=0; irowCount(QModelIndex()); i++) + { + setExpanded(model()->index(i,0,QModelIndex()),aExpanded); + } +} + diff --git a/src/mvc/treeview.h b/src/mvc/treeview.h index d46ae4c..e7cd52c 100644 --- a/src/mvc/treeview.h +++ b/src/mvc/treeview.h @@ -12,6 +12,8 @@ public: private: void mouseReleaseEvent(QMouseEvent *aEvent); bool testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint); +public slots: + void setAllExpanded(bool aExpanded); // (aExpanded==true) => expanded; (aExpanded==false) => collapsed private slots: void handleItemClicked(const QModelIndex &index); signals: -- 2.30.2