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 20b277893dc0fac6e3c3d0353413a57765eeb896..5c7b8d03d3d6e049826423c58f2cc9bc2acbff13 100644 (file)
@@ -82,3 +82,8 @@ void DayNavigatorWidget::nextDayButtonClicked()
     }
 }
 
+QDate DayNavigatorWidget::getCurrentDate()
+{
+    return mCurDate;
+}
+
index 63643f706aed77bdd2a93ee981928f1a37748544..bf4b43df0974c66ed19e2497e2b0ec87f0234f18 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 90e5e34f824c3ede7bec6aa44e1991c5dc5b5668..9de6ba106c0417f49abde0897438c073a6853c94 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 0ab7bd5583279ca98d8d033942e460ba8bbe3e1c..eab5120e2fac8c942f682e00e19f248742c61154 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 bf3429d99f1f8aa4359af81d69abcd8bc2e2216d..eae7f5eb144de7a100004790a00ad4c581fd4b2f 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 9003faadabb02d501a0fc5ebb499fb2bb1f38a82..b388bc36b69c4703f0b81780b2048af247905cbd 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 e3ad84fd2899ddd2d8e4c12acd087ff41e542653..bd45b4faa5cd16c36535b9423e8966a8866e67c0 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 2a001770e057fa3e77ee8834cc38164d73d37167..962d13049da47b3adaeee408dbe3e12f3040968d 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;