implemented day navigator widget
authorpavelpa <pavelpa@localhost>
Wed, 13 Jan 2010 20:51:06 +0000 (20:51 +0000)
committerpavelpa <pavelpa@localhost>
Wed, 13 Jan 2010 20:51:06 +0000 (20:51 +0000)
 - to switch between conference days

src/gui/daynavigatorwidget.cpp [new file with mode: 0644]
src/gui/daynavigatorwidget.h [new file with mode: 0644]
src/gui/daynavigatorwidget.ui [new file with mode: 0644]
src/gui/gui.pro
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/gui/mainwindow.ui
src/model/conference.h
src/model/eventmodel.cpp
src/model/eventmodel.h

diff --git a/src/gui/daynavigatorwidget.cpp b/src/gui/daynavigatorwidget.cpp
new file mode 100644 (file)
index 0000000..4f4ce54
--- /dev/null
@@ -0,0 +1,84 @@
+#include "daynavigatorwidget.h"
+
+#include <QDebug>
+
+DayNavigatorWidget::DayNavigatorWidget(QWidget *aParent)
+    : QWidget(aParent)
+    , mStartDate(QDate())
+    , mEndDate(QDate())
+    , mCurDate(QDate())
+{
+    setupUi(this);
+    connect(prevDayButton, SIGNAL(clicked()), SLOT(prevDayButtonClicked()));
+    connect(nextDayButton, SIGNAL(clicked()), SLOT(nextDayButtonClicked()));
+}
+
+void DayNavigatorWidget::setDates(const QDate &aStartDate, const QDate &aEndDate)
+{
+    Q_ASSERT(aStartDate>=aEndDate);
+
+    //qDebug() << "DayNavigatorWidget::setDates(): " << aStartDate << ", " << aEndDate;
+    mStartDate = aStartDate;
+    mEndDate = aEndDate;
+    mCurDate = aStartDate;
+
+    currentDateLabel->setText(mCurDate.toString());
+    if(mStartDate==mEndDate) // only one day conference
+    {
+        prevDayButton->setDisabled(true);
+        nextDayButton->setDisabled(true);
+        emit(dateChanged(mCurDate));
+    }
+    else
+    {
+        // at least 2-days conference
+        prevDayButton->setDisabled(true);
+        nextDayButton->setDisabled(false);
+        emit(dateChanged(mCurDate));
+    }
+}
+
+void DayNavigatorWidget::prevDayButtonClicked()
+{
+    //qDebug() << mStartDate << ":" << mCurDate << ":" << mEndDate;
+    if(mCurDate>mStartDate)
+    {
+        mCurDate = mCurDate.addDays(-1);
+        currentDateLabel->setText(mCurDate.toString());
+        // check start date
+        if(mCurDate==mStartDate || mStartDate==mEndDate)
+            prevDayButton->setDisabled(true);
+        else
+            prevDayButton->setDisabled(false);
+        // check end date
+        if(mCurDate==mEndDate || mStartDate==mEndDate)
+            nextDayButton->setDisabled(true);
+        else
+            nextDayButton->setDisabled(false);
+
+        emit(dateChanged(mCurDate));
+    }
+}
+
+void DayNavigatorWidget::nextDayButtonClicked()
+{
+    //qDebug() << mStartDate << ":" << mCurDate << ":" << mEndDate;
+    if(mCurDate<mEndDate)
+    {
+        mCurDate = mCurDate.addDays(1);
+        currentDateLabel->setText(mCurDate.toString());
+        // check start date
+        if(mCurDate==mStartDate || mStartDate==mEndDate)
+            prevDayButton->setDisabled(true);
+        else
+            prevDayButton->setDisabled(false);
+        // check end date
+        if(mCurDate==mEndDate || mStartDate==mEndDate)
+            nextDayButton->setDisabled(true);
+        else
+            nextDayButton->setDisabled(false);
+
+        emit(dateChanged(mCurDate));
+    }
+}
+
diff --git a/src/gui/daynavigatorwidget.h b/src/gui/daynavigatorwidget.h
new file mode 100644 (file)
index 0000000..63643f7
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef DAYNAVIGATORWIDGET_H
+#define DAYNAVIGATORWIDGET_H
+
+#include "ui_daynavigatorwidget.h"
+#include <QObject>
+#include <QDate>
+
+class DayNavigatorWidget : public QWidget, Ui::DayNavigatorWidget
+{
+    Q_OBJECT
+    public:
+        DayNavigatorWidget(QWidget *aParent = NULL);
+        ~DayNavigatorWidget() {}
+        void setDates(const QDate &aStartDate, const QDate &aEndDate);
+    private slots:
+        void prevDayButtonClicked();
+        void nextDayButtonClicked();
+    signals:
+        void dateChanged(const QDate &aDate);
+    private:
+        QDate mStartDate;
+        QDate mEndDate;
+        QDate mCurDate;
+};
+
+#endif /* DAYNAVIGATORWIDGET_H */
+
diff --git a/src/gui/daynavigatorwidget.ui b/src/gui/daynavigatorwidget.ui
new file mode 100644 (file)
index 0000000..90e5e34
--- /dev/null
@@ -0,0 +1,87 @@
+<ui version="4.0" >
+ <class>DayNavigatorWidget</class>
+ <widget class="QWidget" name="DayNavigatorWidget" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>360</width>
+    <height>50</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Form</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout" >
+   <item row="0" column="0" >
+    <layout class="QHBoxLayout" name="horizontalLayout" >
+     <item>
+      <widget class="QToolButton" name="prevDayButton" >
+       <property name="text" >
+        <string>...</string>
+       </property>
+       <property name="autoRaise" >
+        <bool>true</bool>
+       </property>
+       <property name="arrowType" >
+        <enum>Qt::LeftArrow</enum>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer" >
+       <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0" >
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QLabel" name="currentDateLabel" >
+       <property name="text" >
+        <string>Currently selected date</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_2" >
+       <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0" >
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QToolButton" name="nextDayButton" >
+       <property name="text" >
+        <string>...</string>
+       </property>
+       <property name="autoRaise" >
+        <bool>true</bool>
+       </property>
+       <property name="arrowType" >
+        <enum>Qt::RightArrow</enum>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+ <slots>
+  <slot>prevDayButtonClicked()</slot>
+  <slot>nextDayButtonClicked()</slot>
+ </slots>
+</ui>
index 26c53868ea57835a45ed75679efb3a395f522fd8..9849e2747d67da46220768d693bb0702fb1ea2e8 100644 (file)
@@ -15,8 +15,14 @@ TARGETDEPS += $$DESTDIR/liborm.a $$DESTDIR/libmodel.a $$DESTDIR/libsql.a
 # Please note that resources MUST be added to the app module
 # (which means they need to be added to the test module as well,
 # but I am sure you can live with that for the time being).
+
 FORMS += mainwindow.ui \
+         daynavigatorwidget.ui \
          about.ui
-SOURCES += mainwindow.cpp
-HEADERS += mainwindow.h
+
+HEADERS += mainwindow.h \
+           daynavigatorwidget.h
+
+SOURCES += mainwindow.cpp \
+           daynavigatorwidget.cpp
 
index c96079d21bf0bccead26ddeb76462fcefc2599d4..dac002daaf34775c3b9930efaeb369e1380ecd4d 100644 (file)
@@ -9,8 +9,11 @@
 #include <eventmodel.h>
 #include <delegate.h>
 
+#include <conference.h>
+
 #include <QDialog>
 #include "ui_about.h"
+#include "daynavigatorwidget.h"
 
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
@@ -31,12 +34,22 @@ MainWindow::MainWindow(QWidget *parent)
     connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
     statusBar()->showMessage(tr("Ready"));
 
+    connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
+
     treeView->setHeaderHidden(true);
     treeView->setRootIsDecorated(false);
     treeView->setIndentation(0);
     treeView->setAnimated(true);
     treeView->setModel(new EventModel());
     treeView->setItemDelegate(new Delegate(treeView));
+
+    if(!Conference::getAll().count()) // no conference(s) in the DB
+        dayNavigator->hide(); // hide DayNavigatorWidget
+    else
+    {
+        int confId = 1;
+        dayNavigator->setDates(Conference::getById(confId).start(),Conference::getById(confId).end());
+    }
 }
 
 MainWindow::~MainWindow()
@@ -64,8 +77,13 @@ void MainWindow::importSchedule()
 
     QByteArray data = file.readAll();
     mXmlParser->parseData(data,mSqlEngine);
-    static_cast<EventModel*>(treeView->model())->loadEvents();
-    treeView->reset();
+
+    if(Conference::getAll().count())
+    {
+        int confId = 1;
+        // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
+        dayNavigator->setDates(Conference::getById(confId).start(),Conference::getById(confId).end());
+    }
 }
 
 void MainWindow::showParsingProgress(int aStatus)
@@ -82,3 +100,11 @@ void MainWindow::aboutApp()
     dialog.exec();
 }
 
+void MainWindow::updateDayView(const QDate &aDate)
+{
+    int confId = 1;
+    static_cast<EventModel*>(treeView->model())->loadEvents(aDate,confId);
+    treeView->reset();
+    dayNavigator->show();
+}
+
index 94a04cff1c638077e5d96cf1112f98acfcb0e885..c0716beec86131a2d92d4e5d8c481c8094ae957a 100644 (file)
@@ -18,6 +18,7 @@ private slots:
     void importSchedule();
     void showParsingProgress(int aStatus);
     void aboutApp();
+    void updateDayView(const QDate &aDate);
 private:
     SqlEngine *mSqlEngine;
     ScheduleXmlParser *mXmlParser;
index eca186cad8a4fedad48938656d0cf95151692840..72ccbfd17e5e1ba09a5fd3f43c1e63c06c2125c4 100644 (file)
         <item row="0" column="0" >
          <layout class="QVBoxLayout" name="verticalLayout" >
           <item>
-           <layout class="QHBoxLayout" name="horizontalLayout_2" >
-            <item>
-             <widget class="QToolButton" name="buttonPrevDay" >
-              <property name="text" >
-               <string>&lt;|</string>
-              </property>
-              <property name="autoRaise" >
-               <bool>true</bool>
-              </property>
-              <property name="arrowType" >
-               <enum>Qt::LeftArrow</enum>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <spacer name="horizontalSpacer" >
-              <property name="orientation" >
-               <enum>Qt::Horizontal</enum>
-              </property>
-              <property name="sizeHint" stdset="0" >
-               <size>
-                <width>40</width>
-                <height>20</height>
-               </size>
-              </property>
-             </spacer>
-            </item>
-            <item>
-             <widget class="QLabel" name="label" >
-              <property name="text" >
-               <string>Selected Date Goes Here</string>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <spacer name="horizontalSpacer_2" >
-              <property name="orientation" >
-               <enum>Qt::Horizontal</enum>
-              </property>
-              <property name="sizeHint" stdset="0" >
-               <size>
-                <width>40</width>
-                <height>20</height>
-               </size>
-              </property>
-             </spacer>
-            </item>
-            <item>
-             <widget class="QToolButton" name="buttonNextDay" >
-              <property name="text" >
-               <string>|></string>
-              </property>
-              <property name="autoRaise" >
-               <bool>true</bool>
-              </property>
-              <property name="arrowType" >
-               <enum>Qt::RightArrow</enum>
-              </property>
-             </widget>
-            </item>
-           </layout>
+           <widget class="DayNavigatorWidget" native="1" name="dayNavigator" />
           </item>
           <item>
            <widget class="TreeView" name="treeView" >
    <extends>QTreeView</extends>
    <header>../model/treeview.h</header>
   </customwidget>
+  <customwidget>
+   <class>DayNavigatorWidget</class>
+   <extends>QWidget</extends>
+   <header>daynavigatorwidget.h</header>
+   <container>1</container>
+  </customwidget>
  </customwidgets>
  <resources/>
  <connections/>
index c6c8e017746b1384dd6b5cf4e64638ece0a6e289..c904b51c084077eb5d724f049484a239f589ef88 100644 (file)
@@ -23,8 +23,11 @@ public:
     QString subtitle() const { return value("subtitle").toString(); }
     QString venue() const { return value("venue").toString(); }
     QString city() const { return value("city").toString(); }
-    QDate start() const { return value("start").toDate(); }
-    QDate end() const { return value("end").toDate(); }
+    // TODO: there is some problem with converting "Time_t" to QDateTime: had to manually add 1 day
+    // NEEDS TO BE FIXED
+    QDate start() const { return value("start").toDateTime().addDays(1).date(); }
+    QDate end() const { return value("end").toDateTime().addDays(1).date(); }
+    //
     int days() const { return value("days").toInt(); }
     int dayChange() const { return value("day_change").toInt(); } // in seconds from 00:00
     int timeslotDuration() const { return value("timeslot_duration").toInt(); } // in seconds
index 727fedd686ad051c853a8ebf9d5e4ebd2c7e7532..6d88977f9169d65f481a7276235e1d623a57eb54 100644 (file)
@@ -3,8 +3,7 @@
 
 EventModel::EventModel()
 {
-
-    loadEvents();
+    mEvents.clear();
 }
 
 void EventModel::createTimeGroups()
@@ -118,19 +117,16 @@ int EventModel::rowCount (const QModelIndex & parent) const
     return 0;
 }
 
-void EventModel::loadEvents()
+void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
 {
     mEvents.clear();
 
-    mConfId = 1; // current conference selected: we have only one DB so far
-    // check for existence of conference in the DB
+    // check for existence of the conference in the DB
     if(Conference::getAll().count())
     {
-        mCurrentDate = Conference::getById(mConfId).start();
-        qDebug() << "Loading Conference Data: [" << Conference::getById(mConfId).title() << "] " << mCurrentDate;
-        mEvents = Event::getByDate(QDate(mCurrentDate.year(), mCurrentDate.month(), mCurrentDate.day()), mConfId);
+        qDebug() << "Loading Conference Data: [" << Conference::getById(aConferenceId).title() << "] " << aDate;
+        mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
     }
-    mEvents = Event::getByDate(QDate(mCurrentDate.year(), mCurrentDate.month(), mCurrentDate.day()), mConfId);
     createTimeGroups();
 }
 
index b4b4bcf5396d193b2f060528021f4016b0a18471..b22e3e52fb3d168e2d76e9c33e7459107390f39f 100644 (file)
@@ -14,7 +14,7 @@ public:
     QModelIndex parent ( const QModelIndex & index ) const;
     int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
     int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
-    void loadEvents(); // loads Events from the DB
+    void loadEvents(const QDate &aDate, int aConferenceId); // loads Events from the DB
 
 private:
     struct Group
@@ -39,8 +39,6 @@ private:
     QList<Event> mEvents;
     QList<Group> mGroups;
     QHash<int, int> mParents;
-    QDate mCurrentDate;
-    int mConfId;
 };
 
 #endif // EVENTMODEL_H