EventModel signaling changed
[toast/confclerk.git] / src / gui / mainwindow.cpp
index 7fa5c6411d44768255ebb8a99b2bed89978bc4bb..d2d1138df507de48386a29d68a09c08a52f3d961 100644 (file)
@@ -79,6 +79,12 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
        searchTreeView->setModel(new EventModel());
        searchTreeView->setItemDelegate(new Delegate(searchTreeView));
 
+    // event details have changed
+    connect(dayTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
+    connect(favTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
+    connect(trackTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
+    connect(searchTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
+
     // event clicked
     connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
     connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
@@ -96,13 +102,8 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
     connect(searchTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
     // event search button clicked
     connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
-
-    // TESTING: load some 'fav' data
-    if(Conference::getAll().count()) // no conference(s) in the DB
-    {
-        static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(AppSettings::confId()).start(),AppSettings::confId());
-        favTreeView->reset();
-    }
+    //
+    connect(tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHasChanged(int)));
 
     if(!Conference::getAll().count()) // no conference(s) in the DB
     {
@@ -127,8 +128,6 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
                 Conference::getById(AppSettings::confId()).end().toString("dd-MM-yyyy"));
     }
 
-    connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)));
-
     searchTreeView->hide();
     searchDayNavigator->hide();
 
@@ -187,37 +186,6 @@ void MainWindow::updateDayView(const QDate &aDate)
     dayNavigator->show();
 }
 
-void MainWindow::updateTab(const int aIndex)
-{
-    switch(aIndex)
-    {
-    case 0://index 0 of tabWidget: dayViewTab
-        {
-            updateDayView(dayNavigator->getCurrentDate());
-        }
-        break;
-    case 1: //index 1 of tabWidget: favouritesTab
-        {
-            updateFavouritesView(favouriteDayNavigator->getCurrentDate());
-        }
-        break;
-    case 2: //index 2 of tabWidget: activitiesTab
-        {
-            updateTracksView(trackDayNavigator->getCurrentDate());
-        }
-        break;
-    case 3: //index 3 of tabWidget: searchTab
-       {
-           updateSearchView( searchDayNavigator->getCurrentDate() );
-       }
-       break;
-    default:
-        {
-
-        }
-    };
-}
-
 void MainWindow::updateTracksView(const QDate &aDate)
 {
     static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(aDate, AppSettings::confId());
@@ -300,3 +268,18 @@ void MainWindow::displayWarning(const QModelIndex &aIndex)
     tr("This event happens at the same time than another one of your favourites.") );
 }
 
+void MainWindow::eventHasChanged(int aEventId)
+{
+    static_cast<EventModel*>(dayTreeView->model())->updateModel(aEventId);
+    static_cast<EventModel*>(favTreeView->model())->updateModel(aEventId);
+    static_cast<EventModel*>(trackTreeView->model())->updateModel(aEventId);
+    static_cast<EventModel*>(searchTreeView->model())->updateModel(aEventId);
+}
+
+void MainWindow::tabHasChanged(int aIndex)
+{
+    Q_UNUSED(aIndex);
+
+    updateFavouritesView(favouriteDayNavigator->getCurrentDate());
+}
+