activities tab implemented - not finished yet
authorkorrco <korrco@localhost>
Mon, 18 Jan 2010 15:25:57 +0000 (15:25 +0000)
committerkorrco <korrco@localhost>
Mon, 18 Jan 2010 15:25:57 +0000 (15:25 +0000)
src/gui/daynavigatorwidget.cpp
src/gui/daynavigatorwidget.h
src/gui/daynavigatorwidget.ui
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/gui/mainwindow.ui
src/mvc/eventmodel.cpp
src/mvc/eventmodel.h

index 20b2778..5c7b8d0 100644 (file)
@@ -82,3 +82,8 @@ void DayNavigatorWidget::nextDayButtonClicked()
     }
 }
 
+QDate DayNavigatorWidget::getCurrentDate()
+{
+    return mCurDate;
+}
+
index 63643f7..bf4b43d 100644 (file)
@@ -5,13 +5,14 @@
 #include <QObject>
 #include <QDate>
 
-class DayNavigatorWidget : public QWidget, Ui::DayNavigatorWidget
+class DayNavigatorWidget : public QWidget, private Ui::DayNavigatorWidget
 {
     Q_OBJECT
     public:
         DayNavigatorWidget(QWidget *aParent = NULL);
         ~DayNavigatorWidget() {}
         void setDates(const QDate &aStartDate, const QDate &aEndDate);
+        QDate getCurrentDate();
     private slots:
         void prevDayButtonClicked();
         void nextDayButtonClicked();
index 90e5e34..9de6ba1 100644 (file)
@@ -6,7 +6,7 @@
     <x>0</x>
     <y>0</y>
     <width>360</width>
-    <height>50</height>
+    <height>52</height>
    </rect>
   </property>
   <property name="windowTitle" >
index 0ab7bd5..eab5120 100644 (file)
@@ -35,7 +35,8 @@ MainWindow::MainWindow(QWidget *parent)
     statusBar()->showMessage(tr("Ready"));
 
     connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
-
+    connect(activityDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateActivitiesDayView(const QDate &)));
+    connect(tabWidget, SIGNAL(currentChanged(int)), SLOT(updateView(int)));
 
     // DAY EVENTS View
     dayTreeView->setHeaderHidden(true);
@@ -104,7 +105,7 @@ void MainWindow::importSchedule()
     {
         int confId = 1;
         // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
-        dayNavigator->setDates(Conference::getById(confId).start(),Conference::getById(confId).end());
+        dayNavigator->setDates(Conference::getById(confId).start(), Conference::getById(confId).end());
     }
 }
 
@@ -144,3 +145,23 @@ void MainWindow::updateFavViewComplete()
     updateFavView();
     updateDayView(Conference::getById(confId).start());
 }
+
+void MainWindow::updateActivitiesDayView(const QDate &aDate)
+{
+    int confId = 1;
+    static_cast<EventModel*>(activityDayTreeView->model())->loadEventsByActivities(aDate,confId);
+    activityDayTreeView->reset();
+    activityDayNavigator->show();
+}
+
+void MainWindow::updateView(int tabIndex)
+{
+    //TODO korinpa: skraslit ! aj pre ine taby
+    qDebug() << "updateView index: " << tabIndex;
+    if (tabIndex == 2)
+    {
+        QDate date = activityDayNavigator->getCurrentDate();
+        updateActivitiesDayView(date);
+    }
+}
+
index bf3429d..eae7f5e 100644 (file)
@@ -21,6 +21,8 @@ private slots:
     void updateDayView(const QDate &aDate);
     void updateFavView();
     void updateFavViewComplete();
+    void updateActivitiesDayView(const QDate &aDate);
+    void updateView(int tabIndex);
 private:
     SqlEngine *mSqlEngine;
     ScheduleXmlParser *mXmlParser;
index 9003faa..b388bc3 100644 (file)
        <attribute name="title" >
         <string>Activities</string>
        </attribute>
+       <widget class="QWidget" name="verticalLayoutWidget" >
+        <property name="geometry" >
+         <rect>
+          <x>0</x>
+          <y>0</y>
+          <width>501</width>
+          <height>231</height>
+         </rect>
+        </property>
+        <layout class="QVBoxLayout" name="activitiesVerticalLayout" >
+         <item>
+          <widget class="DayNavigatorWidget" native="1" name="activityDayNavigator" />
+         </item>
+         <item>
+          <widget class="TreeView" name="activityDayTreeView" >
+           <property name="maximumSize" >
+            <size>
+             <width>16777215</width>
+             <height>16777215</height>
+            </size>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </widget>
       </widget>
       <widget class="QWidget" name="searchTab" >
        <attribute name="title" >
      <x>0</x>
      <y>0</y>
      <width>534</width>
-     <height>26</height>
+     <height>40</height>
     </rect>
    </property>
    <widget class="QMenu" name="menuFile" >
index e3ad84f..bd45b4f 100644 (file)
@@ -42,6 +42,33 @@ void EventModel::createTimeGroups()
     mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex;
 }
 
+void EventModel::createActivityGroups() {
+    mGroups.clear();
+    mParents.clear();
+    if (mEvents.empty())
+    {
+        return;
+    }
+    int activityId = mEvents.first().activityId();
+    //TODO korinpa: get activity name
+    mGroups << EventModel::Group(QString("activity %1").arg(activityId), 0);
+    int nextActivityId = activityId;
+
+    for (int i=0; i<mEvents.count(); i++)
+    {
+        activityId = mEvents.at(i).activityId();
+        if (nextActivityId != activityId)
+        {
+            mGroups.last().mChildCount = i - mGroups.last().mFirstEventIndex;
+            mGroups << EventModel::Group(QString("activity %1").arg(activityId), 0);
+            int nextActivityId = activityId;
+        }
+        // add parent-child relation
+        mParents[mEvents.at(i).id()] = mGroups.count() - 1;
+    }
+    mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex;
+}
+
 QVariant EventModel::data(const QModelIndex& index, int role) const
 {
     if (index.isValid() && role == Qt::DisplayRole)
@@ -117,20 +144,25 @@ int EventModel::rowCount (const QModelIndex & parent) const
     return 0;
 }
 
-void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
+void EventModel::clearModel()
 {
-    for(int i=0; i<mGroups.count(); i++)
-    {
-        QModelIndex idx = index(i,0);
+/*
+    for(int i = 0;i < mGroups.count();i++){
+        QModelIndex idx = index(i, 0);
         Group group = mGroups[i];
-        beginRemoveRows(idx,0,group.mChildCount-1);
-        removeRows(0,group.mChildCount,idx);
+        beginRemoveRows(idx, 0, group.mChildCount - 1);
+        bool ok = removeRows(0, group.mChildCount, idx);
         endRemoveRows();
         //qDebug() << "removing " << group.mChildCount << " events from group:" << i << idx.data() << ":" << ok;
     }
-
+*/
+    mGroups.clear();
     mEvents.clear();
+}
 
+void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
+{
+    clearModel();
     // check for existence of the conference in the DB
     if(Conference::getAll().count())
     {
@@ -142,18 +174,7 @@ void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
 
 void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId)
 {
-    for(int i=0; i<mGroups.count(); i++)
-    {
-        QModelIndex idx = index(i,0);
-        Group group = mGroups[i];
-        beginRemoveRows(idx,0,group.mChildCount-1);
-        removeRows(0,group.mChildCount,idx);
-        endRemoveRows();
-        //qDebug() << "removing " << group.mChildCount << " events from group:" << i << idx.data() << ":" << ok;
-    }
-
-    mEvents.clear();
-
+    clearModel();
     // check for existence of the conference in the DB
     if(Conference::getAll().count())
     {
@@ -163,6 +184,17 @@ void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId)
     createTimeGroups();
 }
 
+void EventModel::loadEventsByActivities(const QDate &aDate, int aConferenceId)
+{
+    clearModel();
+    if(Conference::getAll().count())
+        {
+            qDebug() << "Loading Conference Data (by Activities): [" << Conference::getById(aConferenceId).title() << "] " << aDate;
+            mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
+        }
+    createActivityGroups();
+}
+
 void EventModel::emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight)
 {
     emit(dataChanged(aTopLeft,aBottomRight));
index 2a00177..962d130 100644 (file)
@@ -16,7 +16,7 @@ public:
     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
-    
+    void loadEventsByActivities(const QDate &aDate, int aConferenceId); // loads Events grouped by Activities from the DB
     // a method to force 'EventModel' emit signal 'dataChanged()'
     // a 'view', eg. 'TreeView' listens for this signal and redraws changed items(indexes)
     void emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight);
@@ -39,6 +39,8 @@ private:
 
 private:
     void createTimeGroups();
+    void createActivityGroups();
+    void clearModel();
 
 private:
     QList<Event> mEvents;