source: src/model/treeview.cpp @ 969a840

qt5
Last change on this file since 969a840 was 66327a0, checked in by pavelpa <pavelpa@…>, 13 years ago

modified model-view

  • created own delegate to display TreeView? items
    • contains also 'controls' - which are clickable (handled in TreeView?)
  • created own TreeView? inherited from QTreeView
    • to handle control-clicks of the Delegate
  • minor modifications to MainWindow? UI
  • icons added
  • Property mode set to 100644
File size: 1.4 KB
Line 
1#include <QMouseEvent>
2
3#include "treeview.h"
4#include "delegate.h"
5
6#include <QDebug>
7
8TreeView::TreeView(QWidget *aParent)
9    : QTreeView(aParent)
10{
11}
12
13void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
14{
15    QModelIndex index = currentIndex();
16    QPoint point = aEvent->pos();
17
18    testForControlClicked(index,point);
19
20    // pass the event to the Base class, so item clicks/events are handled correctly
21    QTreeView::mouseReleaseEvent(aEvent);
22}
23
24void TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint)
25{
26    if(!aIndex.isValid())
27        return;
28
29    QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list
30    Delegate *delegate = static_cast<Delegate*>(itemDelegate(aIndex));
31    switch(delegate->whichControlClicked(aIndex,aPoint))
32    {
33        case Delegate::FavouriteControl:
34            {
35                // handle Favourite Control clicked
36                qDebug() << "FAVOURITE CLICKED: " << qVariantValue<QString>(aIndex.data());
37            }
38            break;
39        case Delegate::AlarmControl:
40            {
41                // handle Alarm Control clicked
42                qDebug() << "ALARM CLICKED: " << qVariantValue<QString>(aIndex.data());
43            }
44            break;
45        case Delegate::ControlNone:
46        default:
47            {
48                // item was clicked, but not a control
49            }
50    };
51}
52
Note: See TracBrowser for help on using the repository browser.