From 969a840b06a2fc45f74352478cf5eb811d0b0f29 Mon Sep 17 00:00:00 2001 From: pavelpa Date: Wed, 13 Jan 2010 20:51:06 +0000 Subject: [PATCH] implemented day navigator widget - to switch between conference days --- src/gui/daynavigatorwidget.cpp | 84 ++++++++++++++++++++++++++++++++ src/gui/daynavigatorwidget.h | 27 +++++++++++ src/gui/daynavigatorwidget.ui | 87 ++++++++++++++++++++++++++++++++++ src/gui/gui.pro | 10 +++- src/gui/mainwindow.cpp | 30 +++++++++++- src/gui/mainwindow.h | 1 + src/gui/mainwindow.ui | 68 +++----------------------- src/model/conference.h | 7 ++- src/model/eventmodel.cpp | 14 ++---- src/model/eventmodel.h | 4 +- 10 files changed, 253 insertions(+), 79 deletions(-) create mode 100644 src/gui/daynavigatorwidget.cpp create mode 100644 src/gui/daynavigatorwidget.h create mode 100644 src/gui/daynavigatorwidget.ui diff --git a/src/gui/daynavigatorwidget.cpp b/src/gui/daynavigatorwidget.cpp new file mode 100644 index 0000000..4f4ce54 --- /dev/null +++ b/src/gui/daynavigatorwidget.cpp @@ -0,0 +1,84 @@ +#include "daynavigatorwidget.h" + +#include + +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(mCurDatesetText(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 index 0000000..63643f7 --- /dev/null +++ b/src/gui/daynavigatorwidget.h @@ -0,0 +1,27 @@ +#ifndef DAYNAVIGATORWIDGET_H +#define DAYNAVIGATORWIDGET_H + +#include "ui_daynavigatorwidget.h" +#include +#include + +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 index 0000000..90e5e34 --- /dev/null +++ b/src/gui/daynavigatorwidget.ui @@ -0,0 +1,87 @@ + + DayNavigatorWidget + + + + 0 + 0 + 360 + 50 + + + + Form + + + + + + + + ... + + + true + + + Qt::LeftArrow + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Currently selected date + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ... + + + true + + + Qt::RightArrow + + + + + + + + + + + prevDayButtonClicked() + nextDayButtonClicked() + + diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 26c5386..9849e27 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -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 diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index c96079d..dac002d 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -9,8 +9,11 @@ #include #include +#include + #include #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(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(treeView->model())->loadEvents(aDate,confId); + treeView->reset(); + dayNavigator->show(); +} + diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 94a04cf..c0716be 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -18,6 +18,7 @@ private slots: void importSchedule(); void showParsingProgress(int aStatus); void aboutApp(); + void updateDayView(const QDate &aDate); private: SqlEngine *mSqlEngine; ScheduleXmlParser *mXmlParser; diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index eca186c..72ccbfd 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -27,67 +27,7 @@ - - - - - <| - - - true - - - Qt::LeftArrow - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Selected Date Goes Here - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - |> - - - true - - - Qt::RightArrow - - - - + @@ -160,6 +100,12 @@ QTreeView
../model/treeview.h
+ + DayNavigatorWidget + QWidget +
daynavigatorwidget.h
+ 1 +
diff --git a/src/model/conference.h b/src/model/conference.h index c6c8e01..c904b51 100644 --- a/src/model/conference.h +++ b/src/model/conference.h @@ -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 diff --git a/src/model/eventmodel.cpp b/src/model/eventmodel.cpp index 727fedd..6d88977 100644 --- a/src/model/eventmodel.cpp +++ b/src/model/eventmodel.cpp @@ -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(); } diff --git a/src/model/eventmodel.h b/src/model/eventmodel.h index b4b4bcf..b22e3e5 100644 --- a/src/model/eventmodel.h +++ b/src/model/eventmodel.h @@ -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 mEvents; QList mGroups; QHash mParents; - QDate mCurrentDate; - int mConfId; }; #endif // EVENTMODEL_H -- 2.39.5