source: src/mvc/treeview.cpp @ 446bce4

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

started work on displaying map

  • implemented mapwindow
  • map is hard-coded for now

TODO: finish getting map path from the event

  • Property mode set to 100644
File size: 3.2 KB
Line 
1#include <QMouseEvent>
2
3#include "treeview.h"
4#include "delegate.h"
5#include "event.h"
6#include "eventmodel.h"
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    {
35        case Delegate::FavouriteControlOn:
36        case Delegate::FavouriteControlOff:
37            {
38                // handle Favourite Control clicked
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");
52                // since the Favourite icon has changed, update TreeView accordingly
53                static_cast<EventModel*>(model())->emitDataChangedSignal(aIndex,aIndex);
54            }
55            break;
56        case Delegate::AlarmControlOn:
57        case Delegate::AlarmControlOff:
58            {
59                // handle Alarm Control clicked
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
76            }
77            break;
78        case Delegate::MapControl:
79            {
80                // handle Alarm Control clicked
81                qDebug() << "MAP CLICKED: " << qVariantValue<QString>(aIndex.data());
82                emit(requestForMap(aIndex));
83            }
84        break;
85        case Delegate::ControlNone:
86        default:
87            {
88                // item was clicked, but not a control
89            }
90    };
91}
92
Note: See TracBrowser for help on using the repository browser.