From 6f39595883e1d011cb9bf61a5eab264bd4b8d86e Mon Sep 17 00:00:00 2001 From: pavelpa Date: Sun, 17 Jan 2010 17:18:22 +0000 Subject: [PATCH] started work on 'favourities' - created tavourities tree view in the MainWindow 'Favourities' tab - listed some testing 'fav' events - TODO: list isn't updated dynamically, which means that the list isn't updated if the user adds/removes an event(s) to/from the 'favourities' list --- src/gui/mainwindow.cpp | 32 +++++++++---- src/gui/mainwindow.ui | 106 +++++++++++++++++++++-------------------- src/mvc/event.cpp | 11 +++++ src/mvc/event.h | 3 +- src/mvc/eventmodel.cpp | 13 +++++ src/mvc/eventmodel.h | 1 + 6 files changed, 106 insertions(+), 60 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index dac002d..12dc2c2 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -36,12 +36,28 @@ MainWindow::MainWindow(QWidget *parent) 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)); + // DAY EVENTS View + dayTreeView->setHeaderHidden(true); + dayTreeView->setRootIsDecorated(false); + dayTreeView->setIndentation(0); + dayTreeView->setAnimated(true); + dayTreeView->setModel(new EventModel()); + dayTreeView->setItemDelegate(new Delegate(dayTreeView)); + + // FAVOURITIES View + favTreeView->setHeaderHidden(true); + favTreeView->setRootIsDecorated(false); + favTreeView->setIndentation(0); + favTreeView->setAnimated(true); + favTreeView->setModel(new EventModel()); + favTreeView->setItemDelegate(new Delegate(favTreeView)); + // TESTING: load some 'fav' data + if(Conference::getAll().count()) // no conference(s) in the DB + { + int confId = 1; + static_cast(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId); + favTreeView->reset(); + } if(!Conference::getAll().count()) // no conference(s) in the DB dayNavigator->hide(); // hide DayNavigatorWidget @@ -103,8 +119,8 @@ void MainWindow::aboutApp() void MainWindow::updateDayView(const QDate &aDate) { int confId = 1; - static_cast(treeView->model())->loadEvents(aDate,confId); - treeView->reset(); + static_cast(dayTreeView->model())->loadEvents(aDate,confId); + dayTreeView->reset(); dayNavigator->show(); } diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index f5ff71d..016ab34 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -1,38 +1,37 @@ - - + MainWindow - - + + 0 0 - 856 - 558 + 534 + 375 - + MainWindow - - - - - - 0 + + + + + + 1 - - + + Day View - - - + + + - + - - + + 16777215 16777215 @@ -44,23 +43,28 @@ - - - Activities + + + Favourites + + + + + - - - Favourites + + + Activities - - + + Search - - + + Map @@ -68,44 +72,44 @@ - - + + 0 0 - 856 - 24 + 534 + 22 - - + + File - + - - + + Help - - + + - - + + - - - + + + Import Schedule - - + + About Qt - - + + About application diff --git a/src/mvc/event.cpp b/src/mvc/event.cpp index 56acfdb..f4c1a99 100644 --- a/src/mvc/event.cpp +++ b/src/mvc/event.cpp @@ -47,3 +47,14 @@ QList Event::getByDate(const QDate& date, int conferenceId) return load(query); } +QList Event::getFavByDate(const QDate& date, int conferenceId) +{ + QSqlQuery query; + query.prepare(selectQueryJoin2T("id") + "WHERE event.xid_conference = :conf AND event.start >= :start AND event.start < :end AND event.favourite = 1 ORDER BY event.start"); + query.bindValue(":conf", conferenceId); + query.bindValue(":start", convertToDb(date, QVariant::DateTime)); + query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime)); + + return load(query); +} + diff --git a/src/mvc/event.h b/src/mvc/event.h index 4089f4f..b09daa8 100644 --- a/src/mvc/event.h +++ b/src/mvc/event.h @@ -27,6 +27,7 @@ public: public: static Event getById(int id, int conferenceId); static QList getByDate(const QDate& date, int conferenceId); + static QList getFavByDate(const QDate& date, int conferenceId); // get Favourities by Date public: // Table 1 @@ -53,7 +54,7 @@ public: void setActivityId(int activityId) { setValue("xid_activity", activityId); } void setType(const QString& type) { setValue("type", type); } void setLanguage(const QString& language) { setValue("language", language); } - void setFavourite(bool favourite) { setValue("favourite", favourite); } + void setFavourite(bool favourite) { setValue("favourite", (int)favourite); } // Table 2 : virtual table for FTS (Full Text Search) void setTag(const QString& tag) { setValue("tag", tag); } void setTitle(const QString& title) { setValue("title", title); } diff --git a/src/mvc/eventmodel.cpp b/src/mvc/eventmodel.cpp index 6d88977..24e1b47 100644 --- a/src/mvc/eventmodel.cpp +++ b/src/mvc/eventmodel.cpp @@ -130,3 +130,16 @@ void EventModel::loadEvents(const QDate &aDate, int aConferenceId) createTimeGroups(); } +void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId) +{ + mEvents.clear(); + + // check for existence of the conference in the DB + if(Conference::getAll().count()) + { + qDebug() << "Loading FAV Conference Data: [" << Conference::getById(aConferenceId).title() << "] " << aDate; + mEvents = Event::getFavByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId); + } + createTimeGroups(); +} + diff --git a/src/mvc/eventmodel.h b/src/mvc/eventmodel.h index b22e3e5..b7fafdc 100644 --- a/src/mvc/eventmodel.h +++ b/src/mvc/eventmodel.h @@ -15,6 +15,7 @@ public: int columnCount ( const QModelIndex & parent = QModelIndex() ) const; int rowCount ( const QModelIndex & parent = QModelIndex() ) const; void loadEvents(const QDate &aDate, int aConferenceId); // loads Events from the DB + void loadFavEvents(const QDate &aDate, int aConferenceId); // loads Favourite events from the DB private: struct Group -- 2.39.5