implemented NOW tab
authorpavelpa <pavelpa@localhost>
Fri, 22 Jan 2010 06:18:25 +0000 (06:18 +0000)
committerpavelpa <pavelpa@localhost>
Fri, 22 Jan 2010 06:18:25 +0000 (06:18 +0000)
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/gui/mainwindow.ui
src/mvc/event.cpp
src/mvc/event.h
src/mvc/eventmodel.cpp
src/mvc/eventmodel.h
src/mvc/treeview.cpp
src/mvc/treeview.h

index d2d1138df507de48386a29d68a09c08a52f3d961..7323a4245a434559cdebe9e023ca9d7def032358 100644 (file)
@@ -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<EventModel*>(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<EventModel*>(favTreeView->model())->updateModel(aEventId);
     static_cast<EventModel*>(trackTreeView->model())->updateModel(aEventId);
     static_cast<EventModel*>(searchTreeView->model())->updateModel(aEventId);
+    static_cast<EventModel*>(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();
 }
 
index 00b35dcfdb0cd46a6b6d1bf02c0175f4e746398c..df6b57d4647b49d611de7c5dec5aa6cd2f4e9cac 100644 (file)
@@ -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);
index 69b9cd0a6222266b6223f8ab9c41b8db215dc951..4346117a2e3a21d9e3deb7fa021fc1f5308ece99 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>609</width>
-    <height>431</height>
+    <width>654</width>
+    <height>444</height>
    </rect>
   </property>
   <property name="minimumSize" >
         </item>
        </layout>
       </widget>
+      <widget class="QWidget" name="tab" >
+       <attribute name="title" >
+        <string>Now</string>
+       </attribute>
+       <layout class="QGridLayout" name="gridLayout_7" >
+        <item row="0" column="0" >
+         <widget class="TreeView" name="nowTreeView" />
+        </item>
+       </layout>
+      </widget>
      </widget>
     </item>
    </layout>
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>609</width>
+     <width>654</width>
      <height>22</height>
     </rect>
    </property>
index eccad94d65230288e418167404a1305ca7ce04b2..821ccaf8b081f740fb8e9aab75b68577eccb331e 100644 (file)
@@ -39,6 +39,20 @@ QList<Event> Event::getByDate(const QDate& date, int conferenceId, QString order
     return load(query);
 }
 
+QList<Event> 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> Event::getFavByDate(const QDate& date, int conferenceId)
 {
     QSqlQuery query;
index a667e4fe8acce3c7df515e6d96d349805cf51d2a..9e3b7e8af43e1269adc2186f0d479772c0b9dd3f 100644 (file)
@@ -24,6 +24,7 @@ public:
     static QList<Event> getByDate(const QDate & date, int conferenceId, QString orderBy);
     static QList<Event> getFavByDate(const QDate & date, int conferenceId); // get Favourities by Date
     static QList<Event> getSearchResultByDate(const QDate& date, int conferenceId, QString orderBy);
+    static QList<Event> 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(); }
index 813844fe4177a887a374a513c40fcaaaf020e3d4..db0917841d8a7b71b21062027f3887ae1e5752d2 100644 (file)
@@ -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; i<mEvents.count(); i++)
index c23ba9e98f347e5e25c31fc0b32ad5a5c0e86e46..9764ee05bad4409c428b8477b0ef97ad9ab86fe1 100644 (file)
@@ -20,6 +20,7 @@ public:
     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
     int loadSearchResultEvents(const QDate &aDate, int aConferenceId);
+    void loadNowEvents(int aConferenceId); // loads Now events from the DB
 
 private:
     struct Group
index 8b3b64715051480ffdc6abf25af641fc79ebdc02..8e32690ef9541ed0be51d504e8f8890cfd6b2b4f 100644 (file)
@@ -132,3 +132,11 @@ void TreeView::handleItemClicked(const QModelIndex &index)
     }
 }
 
+void TreeView::setAllExpanded(bool aExpanded)
+{
+    for(int i=0; i<model()->rowCount(QModelIndex()); i++)
+    {
+        setExpanded(model()->index(i,0,QModelIndex()),aExpanded);
+    }
+}
+
index d46ae4ca2228f16adc60ab6e72722be83acb39db..e7cd52c041c84a374438e25646e342e47031cc18 100644 (file)
@@ -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: