Changeset c718a77 for src


Ignore:
Timestamp:
01/21/10 23:03:07 (13 years ago)
Author:
pavelpa <pavelpa@…>
Branches:
master, qt5
Children:
d336730
Parents:
1735f55
Message:

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
Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/gui/mainwindow.cpp

    r1735f55 rc718a77  
    7979        searchTreeView->setModel(new EventModel());
    8080        searchTreeView->setItemDelegate(new Delegate(searchTreeView));
     81
     82    // event details have changed
     83    connect(dayTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
     84    connect(favTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
     85    connect(trackTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
     86    connect(searchTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
    8187
    8288    // event clicked
     
    97103    // event search button clicked
    98104    connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
    99 
    100     // TESTING: load some 'fav' data
    101     if(Conference::getAll().count()) // no conference(s) in the DB
    102     {
    103         static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(AppSettings::confId()).start(),AppSettings::confId());
    104         favTreeView->reset();
    105     }
     105    //
     106    connect(tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHasChanged(int)));
    106107
    107108    if(!Conference::getAll().count()) // no conference(s) in the DB
     
    128129    }
    129130
    130     connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)));
    131 
    132131    searchTreeView->hide();
    133132    searchDayNavigator->hide();
     
    188187}
    189188
    190 void MainWindow::updateTab(const int aIndex)
    191 {
    192     switch(aIndex)
    193     {
    194     case 0://index 0 of tabWidget: dayViewTab
    195         {
    196             updateDayView(dayNavigator->getCurrentDate());
    197         }
    198         break;
    199     case 1: //index 1 of tabWidget: favouritesTab
    200         {
    201             updateFavouritesView(favouriteDayNavigator->getCurrentDate());
    202         }
    203         break;
    204     case 2: //index 2 of tabWidget: activitiesTab
    205         {
    206             updateTracksView(trackDayNavigator->getCurrentDate());
    207         }
    208         break;
    209     case 3: //index 3 of tabWidget: searchTab
    210        {
    211            updateSearchView( searchDayNavigator->getCurrentDate() );
    212        }
    213        break;
    214     default:
    215         {
    216 
    217         }
    218     };
    219 }
    220 
    221189void MainWindow::updateTracksView(const QDate &aDate)
    222190{
     
    301269}
    302270
     271void MainWindow::eventHasChanged(int aEventId)
     272{
     273    static_cast<EventModel*>(dayTreeView->model())->updateModel(aEventId);
     274    static_cast<EventModel*>(favTreeView->model())->updateModel(aEventId);
     275    static_cast<EventModel*>(trackTreeView->model())->updateModel(aEventId);
     276    static_cast<EventModel*>(searchTreeView->model())->updateModel(aEventId);
     277}
     278
     279void MainWindow::tabHasChanged(int aIndex)
     280{
     281    Q_UNUSED(aIndex);
     282
     283    updateFavouritesView(favouriteDayNavigator->getCurrentDate());
     284}
     285
  • src/gui/mainwindow.h

    r1735f55 rc718a77  
    2020    void aboutApp();
    2121    void updateDayView(const QDate &aDate);
    22     void updateTab(const int n);
    2322    void updateTracksView(const QDate &aDate);
    2423    void updateFavouritesView(const QDate &aDate);
     
    2827    void displayWarning(const QModelIndex &aIndex);
    2928    void searchClicked();
     29    void tabHasChanged(int aIndex);
     30    void eventHasChanged(int aEventId);
    3031private:
    3132    SqlEngine *mSqlEngine;
  • src/mvc/eventmodel.cpp

    r1735f55 rc718a77  
    11#include "eventmodel.h"
     2#include <appsettings.h>
    23#include <conference.h>
    34#include <track.h>
     
    220221}
    221222
    222 void EventModel::emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight)
    223 {
    224     emit(dataChanged(aTopLeft,aBottomRight));
    225 }
    226 
     223void EventModel::updateModel(int aEventId)
     224{
     225    for(int i=0; i<mEvents.count(); i++)
     226    {
     227        if(mEvents[i].id() == aEventId)
     228            mEvents[i] = Event::getById(aEventId,AppSettings::confId());
     229    }
     230
     231    // find the ModelIndex for given aEventId
     232    for(int i=0; i<mGroups.count(); i++)
     233    {
     234        QModelIndex groupIndex = index(i,0,QModelIndex());
     235        for(int j=0; j<mGroups[i].mChildCount; j++)
     236        {
     237            QModelIndex eventIndex = index(j,0,groupIndex);
     238            if(static_cast<Event*>(eventIndex.internalPointer())->id() == aEventId)
     239            {
     240                emit(dataChanged(eventIndex,eventIndex));
     241            }
     242        }
     243    }
     244}
     245
  • src/mvc/eventmodel.h

    r1735f55 rc718a77  
    2121    void loadEventsByTrack(const QDate &aDate, int aConferenceId); // loads Events grouped by Track from the DB
    2222    int loadSearchResultEvents(const QDate &aDate, int aConferenceId);
    23     // a method to force 'EventModel' emit signal 'dataChanged()'
    24     // a 'view', eg. 'TreeView' listens for this signal and redraws changed items(indexes)
    25     void emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight);
    2623
    2724private:
     
    4643    void clearModel();
    4744
     45public slots:
     46    void updateModel(int aEventId);
     47
    4848private:
    4949    QList<Event> mEvents;
  • src/mvc/mvc.pro

    r1735f55 rc718a77  
    88# module dependencies
    99LIBS += -L$$DESTDIR -lorm
    10 INCLUDEPATH += ../orm
     10INCLUDEPATH += ../orm ../app
    1111DEPENDPATH += . ../orm
    1212TARGETDEPS += $$DESTDIR/liborm.a
  • src/mvc/treeview.cpp

    r1735f55 rc718a77  
    4949                Event event = Event::getById(aIndex.data().toInt(),1);
    5050                if(event.isFavourite())
    51                 {
    52                     static_cast<Event*>(aIndex.internalPointer())->setFavourite(false); // list of events
    53                     event.setFavourite(false); // update DB
    54                 }
     51                    event.setFavourite(false);
    5552                else
    56                 {
    57                     static_cast<Event*>(aIndex.internalPointer())->setFavourite(true); // list of events
    5853                    event.setFavourite(true);
    59                 }
     54                event.update("favourite");
    6055                qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite();
    61                 event.update("favourite");
    62                 // since the Favourite icon has changed, update TreeView accordingly
    63                 static_cast<EventModel*>(model())->emitDataChangedSignal(aIndex,aIndex);
     56                // since the Favourite icon has changed, update TreeViews accordingly
     57                // all TreeViews have to listen on this signal
     58                emit(eventHasChanged(event.id()));
    6459                handled = true;
    6560            }
     
    7267                if(event.hasAlarm())
    7368                {
    74                     static_cast<Event*>(aIndex.internalPointer())->setHasAlarm(false); // list of events
    7569                    event.setHasAlarm(false); // update DB
    7670#ifdef MAEMO
     
    8377                else
    8478                {
    85                     static_cast<Event*>(aIndex.internalPointer())->setHasAlarm(true); // list of events
    8679                    event.setHasAlarm(true);
    8780#ifdef MAEMO
     
    9285#endif /* MAEMO */
    9386                }
     87                event.update("alarm");
    9488                qDebug() << " ALARM [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.hasAlarm();
    95                 event.update("alarm");
    9689                // since the Alarm icon has changed, update TreeView accordingly
    97                 static_cast<EventModel*>(model())->emitDataChangedSignal(aIndex,aIndex);
     90                // all TreeViews have to listen on this signal
     91                emit(eventHasChanged(event.id()));
    9892                handled = true;
    9993            }
  • src/mvc/treeview.h

    r1735f55 rc718a77  
    1818    void requestForMap(const QModelIndex &aIndex);
    1919    void requestForWarning(const QModelIndex &aIndex);
     20    void eventHasChanged(int aEventId); // emited when user changes some event details, eg. sets it Favourite
    2021};
    2122
Note: See TracChangeset for help on using the changeset viewer.