1 | #include <QMouseEvent> |
---|
2 | |
---|
3 | #include "treeview.h" |
---|
4 | #include "delegate.h" |
---|
5 | #include "event.h" |
---|
6 | |
---|
7 | #include <QDebug> |
---|
8 | |
---|
9 | TreeView::TreeView(QWidget *aParent) |
---|
10 | : QTreeView(aParent) |
---|
11 | { |
---|
12 | } |
---|
13 | |
---|
14 | void TreeView::mouseReleaseEvent(QMouseEvent *aEvent) |
---|
15 | { |
---|
16 | QModelIndex index = currentIndex(); |
---|
17 | QPoint point = aEvent->pos(); |
---|
18 | |
---|
19 | testForControlClicked(index,point); |
---|
20 | |
---|
21 | // pass the event to the Base class, so item clicks/events are handled correctly |
---|
22 | QTreeView::mouseReleaseEvent(aEvent); |
---|
23 | } |
---|
24 | |
---|
25 | void TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint) |
---|
26 | { |
---|
27 | if(!aIndex.isValid()) |
---|
28 | return; |
---|
29 | |
---|
30 | QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list |
---|
31 | Delegate *delegate = static_cast<Delegate*>(itemDelegate(aIndex)); |
---|
32 | switch(delegate->whichControlClicked(aIndex,aPoint)) |
---|
33 | { |
---|
34 | case Delegate::FavouriteControlOn: |
---|
35 | case Delegate::FavouriteControlOff: |
---|
36 | { |
---|
37 | // handle Favourite Control clicked |
---|
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(); |
---|
56 | } |
---|
57 | break; |
---|
58 | case Delegate::AlarmControlOn: |
---|
59 | case Delegate::AlarmControlOff: |
---|
60 | { |
---|
61 | // handle Alarm Control clicked |
---|
62 | qDebug() << "ALARM CLICKED: " << qVariantValue<QString>(aIndex.data()); |
---|
63 | } |
---|
64 | break; |
---|
65 | case Delegate::MapControl: |
---|
66 | { |
---|
67 | // handle Alarm Control clicked |
---|
68 | qDebug() << "MAP CLICKED: " << qVariantValue<QString>(aIndex.data()); |
---|
69 | } |
---|
70 | break; |
---|
71 | case Delegate::ControlNone: |
---|
72 | default: |
---|
73 | { |
---|
74 | // item was clicked, but not a control |
---|
75 | } |
---|
76 | }; |
---|
77 | } |
---|
78 | |
---|