source: src/mvc/treeview.cpp @ b6cd05c

qt5
Last change on this file since b6cd05c was b6cd05c, checked in by pavelpa <pavelpa@…>, 12 years ago

added 'alarm' columnt to the 'EVENT' table to signalize
that the event has/hasn't alarm set

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[66327a0]1#include <QMouseEvent>
2
3#include "treeview.h"
4#include "delegate.h"
[680a4da]5#include "event.h"
[67c59a7]6#include "eventmodel.h"
[66327a0]7
8#include <QDebug>
9
10TreeView::TreeView(QWidget *aParent)
11    : QTreeView(aParent)
12{
13}
14
15void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
16{
17    QModelIndex index = currentIndex();
18    QPoint point = aEvent->pos();
19
20    testForControlClicked(index,point);
21
22    // pass the event to the Base class, so item clicks/events are handled correctly
23    QTreeView::mouseReleaseEvent(aEvent);
24}
25
26void TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint)
27{
28    if(!aIndex.isValid())
29        return;
30
31    QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list
32    Delegate *delegate = static_cast<Delegate*>(itemDelegate(aIndex));
33    switch(delegate->whichControlClicked(aIndex,aPoint))
34    {
[680a4da]35        case Delegate::FavouriteControlOn:
36        case Delegate::FavouriteControlOff:
[66327a0]37            {
38                // handle Favourite Control clicked
[680a4da]39                Event event = Event::getById(aIndex.data().toInt(),1);
40                if(event.isFavourite())
41                {
42                    static_cast<Event*>(aIndex.internalPointer())->setFavourite(false); // list of events
43                    event.setFavourite(false); // update DB
44                }
45                else
46                {
47                    static_cast<Event*>(aIndex.internalPointer())->setFavourite(true); // list of events
48                    event.setFavourite(true);
49                }
50                qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite();
51                event.update("favourite");
[67c59a7]52                // since the Favourite icon has changed, update TreeView accordingly
53                static_cast<EventModel*>(model())->emitDataChangedSignal(aIndex,aIndex);
[66327a0]54            }
55            break;
[680a4da]56        case Delegate::AlarmControlOn:
57        case Delegate::AlarmControlOff:
[66327a0]58            {
59                // handle Alarm Control clicked
[b6cd05c]60                Event event = Event::getById(aIndex.data().toInt(),1);
61                if(event.hasAlarm())
62                {
63                    static_cast<Event*>(aIndex.internalPointer())->setHasAlarm(false); // list of events
64                    event.setHasAlarm(false); // update DB
65                }
66                else
67                {
68                    static_cast<Event*>(aIndex.internalPointer())->setHasAlarm(true); // list of events
69                    event.setHasAlarm(true);
70                }
71                qDebug() << " ALARM [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.hasAlarm();
72                event.update("alarm");
73                // since the Alarm icon has changed, update TreeView accordingly
74                static_cast<EventModel*>(model())->emitDataChangedSignal(aIndex,aIndex);
75
[66327a0]76            }
77            break;
[03ff157]78        case Delegate::MapControl:
79            {
80                // handle Alarm Control clicked
81                qDebug() << "MAP CLICKED: " << qVariantValue<QString>(aIndex.data());
82            }
83        break;
[66327a0]84        case Delegate::ControlNone:
85        default:
86            {
87                // item was clicked, but not a control
88            }
89    };
90}
91
Note: See TracBrowser for help on using the repository browser.