9 TreeView::TreeView(QWidget *aParent)
14 void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
16 QModelIndex index = currentIndex();
17 QPoint point = aEvent->pos();
19 testForControlClicked(index,point);
21 // pass the event to the Base class, so item clicks/events are handled correctly
22 QTreeView::mouseReleaseEvent(aEvent);
25 void TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint)
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))
34 case Delegate::FavouriteControlOn:
35 case Delegate::FavouriteControlOff:
37 // handle Favourite Control clicked
38 Event event = Event::getById(aIndex.data().toInt(),1);
39 if(event.isFavourite())
41 static_cast<Event*>(aIndex.internalPointer())->setFavourite(false); // list of events
42 event.setFavourite(false); // update DB
46 static_cast<Event*>(aIndex.internalPointer())->setFavourite(true); // list of events
47 event.setFavourite(true);
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 ???
58 case Delegate::AlarmControlOn:
59 case Delegate::AlarmControlOff:
61 // handle Alarm Control clicked
62 qDebug() << "ALARM CLICKED: " << qVariantValue<QString>(aIndex.data());
65 case Delegate::MapControl:
67 // handle Alarm Control clicked
68 qDebug() << "MAP CLICKED: " << qVariantValue<QString>(aIndex.data());
71 case Delegate::ControlNone:
74 // item was clicked, but not a control