--- /dev/null
+#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));
+ }
+}
+
--- /dev/null
+#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 */
+
--- /dev/null
+<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>
# 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
#include <eventmodel.h>
#include <delegate.h>
+#include <conference.h>
+
#include <QDialog>
#include "ui_about.h"
+#include "daynavigatorwidget.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(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()
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)
dialog.exec();
}
+void MainWindow::updateDayView(const QDate &aDate)
+{
+ int confId = 1;
+ static_cast<EventModel*>(treeView->model())->loadEvents(aDate,confId);
+ treeView->reset();
+ dayNavigator->show();
+}
+
void importSchedule();
void showParsingProgress(int aStatus);
void aboutApp();
+ void updateDayView(const QDate &aDate);
private:
SqlEngine *mSqlEngine;
ScheduleXmlParser *mXmlParser;
<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><|</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/>
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
EventModel::EventModel()
{
-
- loadEvents();
+ mEvents.clear();
}
void EventModel::createTimeGroups()
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();
}
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
QList<Event> mEvents;
QList<Group> mGroups;
QHash<int, int> mParents;
- QDate mCurrentDate;
- int mConfId;
};
#endif // EVENTMODEL_H