From c718a77f5a7fbf085dfe014e12a444be344a4140 Mon Sep 17 00:00:00 2001 From: pavelpa Date: Thu, 21 Jan 2010 22:03:07 +0000 Subject: [PATCH] EventModel signaling changed - if some of the data (favourite,alarm) has changed on the event, signal 'eventHasChanged' is emitted - all treeViews (eg. DayView, FavsView, TracksView, ...) have to listen on this signal Only favouritiesView is 'reset' when current tab is changed in mainWindow - 'cause time groupings have to be recreated, since favs may have changed --- src/gui/mainwindow.cpp | 63 +++++++++++++++--------------------------- src/gui/mainwindow.h | 3 +- src/mvc/eventmodel.cpp | 23 +++++++++++++-- src/mvc/eventmodel.h | 6 ++-- src/mvc/mvc.pro | 2 +- src/mvc/treeview.cpp | 22 ++++++--------- src/mvc/treeview.h | 1 + 7 files changed, 59 insertions(+), 61 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 7fa5c64..d2d1138 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -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(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(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(dayTreeView->model())->updateModel(aEventId); + static_cast(favTreeView->model())->updateModel(aEventId); + static_cast(trackTreeView->model())->updateModel(aEventId); + static_cast(searchTreeView->model())->updateModel(aEventId); +} + +void MainWindow::tabHasChanged(int aIndex) +{ + Q_UNUSED(aIndex); + + updateFavouritesView(favouriteDayNavigator->getCurrentDate()); +} + diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 3ee01f8..00b35dc 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -19,7 +19,6 @@ private slots: void importSchedule(); void aboutApp(); void updateDayView(const QDate &aDate); - void updateTab(const int n); void updateTracksView(const QDate &aDate); void updateFavouritesView(const QDate &aDate); void updateSearchView(const QDate &aDate); @@ -27,6 +26,8 @@ private slots: void displayMap(const QModelIndex &aIndex); void displayWarning(const QModelIndex &aIndex); void searchClicked(); + void tabHasChanged(int aIndex); + void eventHasChanged(int aEventId); private: SqlEngine *mSqlEngine; }; diff --git a/src/mvc/eventmodel.cpp b/src/mvc/eventmodel.cpp index 6295815..813844f 100644 --- a/src/mvc/eventmodel.cpp +++ b/src/mvc/eventmodel.cpp @@ -1,4 +1,5 @@ #include "eventmodel.h" +#include #include #include @@ -219,8 +220,26 @@ void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId) createTrackGroups(); } -void EventModel::emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight) +void EventModel::updateModel(int aEventId) { - emit(dataChanged(aTopLeft,aBottomRight)); + for(int i=0; i(eventIndex.internalPointer())->id() == aEventId) + { + emit(dataChanged(eventIndex,eventIndex)); + } + } + } } diff --git a/src/mvc/eventmodel.h b/src/mvc/eventmodel.h index bba5764..c23ba9e 100644 --- a/src/mvc/eventmodel.h +++ b/src/mvc/eventmodel.h @@ -20,9 +20,6 @@ public: void loadFavEvents(const QDate &aDate, int aConferenceId); // loads Favourite events from the DB void loadEventsByTrack(const QDate &aDate, int aConferenceId); // loads Events grouped by Track from the DB int loadSearchResultEvents(const QDate &aDate, int aConferenceId); - // 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); private: struct Group @@ -45,6 +42,9 @@ private: void createTrackGroups(); void clearModel(); +public slots: + void updateModel(int aEventId); + private: QList mEvents; QList mGroups; diff --git a/src/mvc/mvc.pro b/src/mvc/mvc.pro index 6dfbec7..7c2aec9 100644 --- a/src/mvc/mvc.pro +++ b/src/mvc/mvc.pro @@ -7,7 +7,7 @@ QT += sql # module dependencies LIBS += -L$$DESTDIR -lorm -INCLUDEPATH += ../orm +INCLUDEPATH += ../orm ../app DEPENDPATH += . ../orm TARGETDEPS += $$DESTDIR/liborm.a diff --git a/src/mvc/treeview.cpp b/src/mvc/treeview.cpp index 4a7a986..8b3b647 100644 --- a/src/mvc/treeview.cpp +++ b/src/mvc/treeview.cpp @@ -48,19 +48,14 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP // handle Favourite Control clicked Event event = Event::getById(aIndex.data().toInt(),1); if(event.isFavourite()) - { - static_cast(aIndex.internalPointer())->setFavourite(false); // list of events - event.setFavourite(false); // update DB - } + event.setFavourite(false); else - { - static_cast(aIndex.internalPointer())->setFavourite(true); // list of events event.setFavourite(true); - } - qDebug() << " FAVOURITE [" << qVariantValue(aIndex.data()) << "] -> " << event.isFavourite(); event.update("favourite"); - // since the Favourite icon has changed, update TreeView accordingly - static_cast(model())->emitDataChangedSignal(aIndex,aIndex); + qDebug() << " FAVOURITE [" << qVariantValue(aIndex.data()) << "] -> " << event.isFavourite(); + // since the Favourite icon has changed, update TreeViews accordingly + // all TreeViews have to listen on this signal + emit(eventHasChanged(event.id())); handled = true; } break; @@ -71,7 +66,6 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP Event event = Event::getById(aIndex.data().toInt(),1); if(event.hasAlarm()) { - static_cast(aIndex.internalPointer())->setHasAlarm(false); // list of events event.setHasAlarm(false); // update DB #ifdef MAEMO // remove alarm from the 'alarmd' alrms list @@ -82,7 +76,6 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP } else { - static_cast(aIndex.internalPointer())->setHasAlarm(true); // list of events event.setHasAlarm(true); #ifdef MAEMO // add alarm to the 'alarmd' @@ -91,10 +84,11 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP qDebug() << "cookie: " << cookie; #endif /* MAEMO */ } - qDebug() << " ALARM [" << qVariantValue(aIndex.data()) << "] -> " << event.hasAlarm(); event.update("alarm"); + qDebug() << " ALARM [" << qVariantValue(aIndex.data()) << "] -> " << event.hasAlarm(); // since the Alarm icon has changed, update TreeView accordingly - static_cast(model())->emitDataChangedSignal(aIndex,aIndex); + // all TreeViews have to listen on this signal + emit(eventHasChanged(event.id())); handled = true; } break; diff --git a/src/mvc/treeview.h b/src/mvc/treeview.h index e608ff1..d46ae4c 100644 --- a/src/mvc/treeview.h +++ b/src/mvc/treeview.h @@ -17,6 +17,7 @@ private slots: signals: void requestForMap(const QModelIndex &aIndex); void requestForWarning(const QModelIndex &aIndex); + void eventHasChanged(int aEventId); // emited when user changes some event details, eg. sets it Favourite }; #endif /* TREEVIEW_H */ -- 2.30.2