Changeset c718a77 for src/mvc


Ignore:
Timestamp:
01/21/10 23:03:07 (12 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/mvc
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 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.