started work on 'favourities'
authorpavelpa <pavelpa@localhost>
Sun, 17 Jan 2010 17:18:22 +0000 (17:18 +0000)
committerpavelpa <pavelpa@localhost>
Sun, 17 Jan 2010 17:18:22 +0000 (17:18 +0000)
 - 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
src/gui/mainwindow.ui
src/mvc/event.cpp
src/mvc/event.h
src/mvc/eventmodel.cpp
src/mvc/eventmodel.h

index dac002d..12dc2c2 100644 (file)
@@ -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<EventModel*>(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<EventModel*>(treeView->model())->loadEvents(aDate,confId);
-    treeView->reset();
+    static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId);
+    dayTreeView->reset();
     dayNavigator->show();
 }
 
index f5ff71d..016ab34 100644 (file)
@@ -1,38 +1,37 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
+<ui version="4.0" >
  <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow">
-  <property name="geometry">
+ <widget class="QMainWindow" name="MainWindow" >
+  <property name="geometry" >
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>856</width>
-    <height>558</height>
+    <width>534</width>
+    <height>375</height>
    </rect>
   </property>
-  <property name="windowTitle">
+  <property name="windowTitle" >
    <string>MainWindow</string>
   </property>
-  <widget class="QWidget" name="centralwidget">
-   <layout class="QGridLayout" name="gridLayout">
-    <item row="0" column="0">
-     <widget class="QTabWidget" name="tabWidget">
-      <property name="currentIndex">
-       <number>0</number>
+  <widget class="QWidget" name="centralwidget" >
+   <layout class="QGridLayout" name="gridLayout" >
+    <item row="0" column="0" >
+     <widget class="QTabWidget" name="tabWidget" >
+      <property name="currentIndex" >
+       <number>1</number>
       </property>
-      <widget class="QWidget" name="dayViewTab">
-       <attribute name="title">
+      <widget class="QWidget" name="dayViewTab" >
+       <attribute name="title" >
         <string>Day View</string>
        </attribute>
-       <layout class="QGridLayout" name="gridLayout_2">
-        <item row="0" column="0">
-         <layout class="QVBoxLayout" name="verticalLayout">
+       <layout class="QGridLayout" name="gridLayout_2" >
+        <item row="0" column="0" >
+         <layout class="QVBoxLayout" name="verticalLayout" >
           <item>
-           <widget class="DayNavigatorWidget" name="dayNavigator" native="true"/>
+           <widget class="DayNavigatorWidget" native="1" name="dayNavigator" />
           </item>
           <item>
-           <widget class="TreeView" name="treeView">
-            <property name="maximumSize">
+           <widget class="TreeView" name="dayTreeView" >
+            <property name="maximumSize" >
              <size>
               <width>16777215</width>
               <height>16777215</height>
         </item>
        </layout>
       </widget>
-      <widget class="QWidget" name="activitiesTab">
-       <attribute name="title">
-        <string>Activities</string>
+      <widget class="QWidget" name="favouritesTab" >
+       <attribute name="title" >
+        <string>Favourites</string>
        </attribute>
+       <layout class="QGridLayout" name="gridLayout_3" >
+        <item row="0" column="0" >
+         <widget class="TreeView" name="favTreeView" />
+        </item>
+       </layout>
       </widget>
-      <widget class="QWidget" name="favouritesTab">
-       <attribute name="title">
-        <string>Favourites</string>
+      <widget class="QWidget" name="activitiesTab" >
+       <attribute name="title" >
+        <string>Activities</string>
        </attribute>
       </widget>
-      <widget class="QWidget" name="searchTab">
-       <attribute name="title">
+      <widget class="QWidget" name="searchTab" >
+       <attribute name="title" >
         <string>Search</string>
        </attribute>
       </widget>
-      <widget class="QWidget" name="mapTab">
-       <attribute name="title">
+      <widget class="QWidget" name="mapTab" >
+       <attribute name="title" >
         <string>Map</string>
        </attribute>
       </widget>
     </item>
    </layout>
   </widget>
-  <widget class="QMenuBar" name="menubar">
-   <property name="geometry">
+  <widget class="QMenuBar" name="menubar" >
+   <property name="geometry" >
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>856</width>
-     <height>24</height>
+     <width>534</width>
+     <height>22</height>
     </rect>
    </property>
-   <widget class="QMenu" name="menuFile">
-    <property name="title">
+   <widget class="QMenu" name="menuFile" >
+    <property name="title" >
      <string>File</string>
     </property>
-    <addaction name="actionImportSchedule"/>
+    <addaction name="actionImportSchedule" />
    </widget>
-   <widget class="QMenu" name="menuAbout">
-    <property name="title">
+   <widget class="QMenu" name="menuAbout" >
+    <property name="title" >
      <string>Help</string>
     </property>
-    <addaction name="actionAboutQt"/>
-    <addaction name="actionAboutApplication"/>
+    <addaction name="actionAboutQt" />
+    <addaction name="actionAboutApplication" />
    </widget>
-   <addaction name="menuFile"/>
-   <addaction name="menuAbout"/>
+   <addaction name="menuFile" />
+   <addaction name="menuAbout" />
   </widget>
-  <widget class="QStatusBar" name="statusbar"/>
-  <action name="actionImportSchedule">
-   <property name="text">
+  <widget class="QStatusBar" name="statusbar" />
+  <action name="actionImportSchedule" >
+   <property name="text" >
     <string>Import Schedule</string>
    </property>
   </action>
-  <action name="actionAboutQt">
-   <property name="text">
+  <action name="actionAboutQt" >
+   <property name="text" >
     <string>About Qt</string>
    </property>
   </action>
-  <action name="actionAboutApplication">
-   <property name="text">
+  <action name="actionAboutApplication" >
+   <property name="text" >
     <string>About application</string>
    </property>
   </action>
index 56acfdb..f4c1a99 100644 (file)
@@ -47,3 +47,14 @@ QList<Event> Event::getByDate(const QDate& date, int conferenceId)
     return load(query);
 }
 
+QList<Event> 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);
+}
+
index 4089f4f..b09daa8 100644 (file)
@@ -27,6 +27,7 @@ public:
 public:
     static Event getById(int id, int conferenceId);
     static QList<Event> getByDate(const QDate& date, int conferenceId);
+    static QList<Event> 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); }
index 6d88977..24e1b47 100644 (file)
@@ -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();
+}
+
index b22e3e5..b7fafdc 100644 (file)
@@ -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