Changeset 680a4da for src/mvc


Ignore:
Timestamp:
01/16/10 16:31:15 (12 years ago)
Author:
pavelpa <pavelpa@…>
Branches:
master, qt5
Children:
c790268
Parents:
8860ff4
Message:

work on favourite

  • created 'favourite' column in EVENT table
  • modified 'ormrecord' for setting record's elements
  • favourities view not implemented
Location:
src/mvc
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/mvc/delegate.cpp

    r8860ff4 r680a4da  
    8484
    8585        // draw Controls
    86         painter->drawImage(mControls[FavouriteControl]->drawPoint(option.rect),*mControls[FavouriteControl]->image());
    87         painter->drawImage(mControls[AlarmControl]->drawPoint(option.rect),*mControls[AlarmControl]->image());
     86        if(static_cast<Event*>(index.internalPointer())->isFavourite())
     87            painter->drawImage(mControls[FavouriteControlOn]->drawPoint(option.rect),*mControls[FavouriteControlOn]->image());
     88        else
     89            painter->drawImage(mControls[FavouriteControlOff]->drawPoint(option.rect),*mControls[FavouriteControlOff]->image());
     90        painter->drawImage(mControls[AlarmControlOn]->drawPoint(option.rect),*mControls[AlarmControlOn]->image());
    8891        painter->drawImage(mControls[MapControl]->drawPoint(option.rect),*mControls[MapControl]->image());
    8992    }
     
    201204{
    202205    Control *control;
    203     // FAVOURITE ICON
    204     control = new Control(FavouriteControl,QString(":icons/favourite-on.png"));
     206    // FAVOURITE ICONs
     207    // on
     208    control = new Control(FavouriteControlOn,QString(":icons/favourite-on.png"));
    205209    control->setDrawPoint(QPoint(-control->image()->width()-SPACER,SPACER));
    206     mControls.insert(FavouriteControl,control);
    207 
    208     // ALARM ICON
    209     control = new Control(AlarmControl,QString(":icons/alarm-on.png"));
    210     control->setDrawPoint(QPoint(-mControls[FavouriteControl]->image()->width()-control->image()->width()-2*SPACER,SPACER));
    211     mControls.insert(AlarmControl,control);
     210    mControls.insert(FavouriteControlOn,control);
     211    // off
     212    control = new Control(FavouriteControlOff,QString(":icons/favourite-off.png"));
     213    control->setDrawPoint(QPoint(-control->image()->width()-SPACER,SPACER));
     214    mControls.insert(FavouriteControlOff,control);
     215
     216    // ALARM ICONs
     217    // on
     218    control = new Control(AlarmControlOn,QString(":icons/alarm-on.png"));
     219    control->setDrawPoint(QPoint(-mControls[FavouriteControlOn]->image()->width()-control->image()->width()-2*SPACER,SPACER));
     220    mControls.insert(AlarmControlOn,control);
     221    // off
     222    control = new Control(AlarmControlOff,QString(":icons/alarm-off.png"));
     223    control->setDrawPoint(QPoint(-mControls[FavouriteControlOff]->image()->width()-control->image()->width()-2*SPACER,SPACER));
     224    mControls.insert(AlarmControlOff,control);
    212225
    213226    // MAP ICON
    214227    control = new Control(MapControl,QString(":icons/compass.png"));
    215     control->setDrawPoint(QPoint(-mControls[AlarmControl]->image()->width()-control->image()->width()
    216                                  -mControls[FavouriteControl]->image()->width()-3*SPACER,SPACER));
     228    control->setDrawPoint(QPoint(-mControls[AlarmControlOn]->image()->width()-control->image()->width()
     229                                 -mControls[FavouriteControlOn]->image()->width()-3*SPACER,SPACER));
    217230    mControls.insert(MapControl,control);
    218231}
  • src/mvc/delegate.h

    r8860ff4 r680a4da  
    1515        {
    1616            ControlNone = 0,
    17             FavouriteControl,
    18             AlarmControl,
     17            FavouriteControlOn,
     18            FavouriteControlOff,
     19            AlarmControlOn,
     20            AlarmControlOff,
    1921            MapControl
    2022        };
  • src/mvc/event.cpp

    r8860ff4 r680a4da  
    88    << QSqlField("xid_activity", QVariant::Int)
    99    << QSqlField("type", QVariant::String)
    10     << QSqlField("language", QVariant::String));
     10    << QSqlField("language", QVariant::String)
     11    << QSqlField("favourite", QVariant::Bool));
    1112
    1213QString const Event::sTableName = QString("event");
     
    3132    return load(query);
    3233}
     34
  • src/mvc/event.h

    r8860ff4 r680a4da  
    77
    88#include <ormrecord.h>
    9 
    109
    1110/**
     
    3433    QString type() const { return value("type").toString(); }
    3534    QString language() const { return value("language").toString(); }
     35    bool isFavourite() const { return value("favourite").toBool(); }
    3636
    3737    void setId(int id) { setValue("id", id); }
     
    4242    void setType(const QString& type) { setValue("type", type); }
    4343    void setLanguage(const QString& language) { setValue("language", language); }
     44    void setFavourite(bool favourite) { setValue("favourite", favourite); }
    4445
    4546friend class EventTest;
    4647};
    4748
     49#endif // EVENT_H
    4850
    49 
    50 #endif // EVENT_H
  • src/mvc/treeview.cpp

    r8860ff4 r680a4da  
    33#include "treeview.h"
    44#include "delegate.h"
     5#include "event.h"
    56
    67#include <QDebug>
     
    3132    switch(delegate->whichControlClicked(aIndex,aPoint))
    3233    {
    33         case Delegate::FavouriteControl:
     34        case Delegate::FavouriteControlOn:
     35        case Delegate::FavouriteControlOff:
    3436            {
    3537                // handle Favourite Control clicked
    36                 qDebug() << "FAVOURITE CLICKED: " << qVariantValue<QString>(aIndex.data());
     38                Event event = Event::getById(aIndex.data().toInt(),1);
     39                if(event.isFavourite())
     40                {
     41                    static_cast<Event*>(aIndex.internalPointer())->setFavourite(false); // list of events
     42                    event.setFavourite(false); // update DB
     43                }
     44                else
     45                {
     46                    static_cast<Event*>(aIndex.internalPointer())->setFavourite(true); // list of events
     47                    event.setFavourite(true);
     48                }
     49                qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite();
     50                event.update("favourite");
     51                // TODO: since the Favourite icon has changed, update TreeView accordingly
     52                // not really working solution is the following
     53                // maybe the call to MainWindow->update() fix the problem ???
     54                QTreeView::update();
     55                update();
    3756            }
    3857            break;
    39         case Delegate::AlarmControl:
     58        case Delegate::AlarmControlOn:
     59        case Delegate::AlarmControlOff:
    4060            {
    4161                // handle Alarm Control clicked
Note: See TracChangeset for help on using the changeset viewer.