YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
customtreewidget.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6#include "customtreewidget.h"
7#include <QMouseEvent>
8#include <QHeaderView>
9CustomTreeWidget::CustomTreeWidget(QWidget *parent) : QTreeWidget(parent)
10{
11 connect(this,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(onConnContext(QPoint)));
12 connect(header(),SIGNAL(sectionClicked(int)),this,SLOT(onHeaderClicked(int)));
13 setSortingEnabled(true);
14 sort = Qt::AscendingOrder;
15 sortByColumn(1,sort);
16 setContextMenuPolicy(Qt::ActionsContextMenu);
17 setSelectionMode(QAbstractItemView::ExtendedSelection);
18 contextMenu = nullptr;
19}
20
25{
26
27
28 if(e->button() == Qt::RightButton){
29 if(itemAt(e->pos()) == nullptr){
30 setCurrentItem(nullptr);
31 }
32 if(currentItem() == nullptr){
33 emit itemSelectionChanged();
34 }
35 }
36 QTreeWidget::mousePressEvent(e);
37}
38
42void CustomTreeWidget::onHeaderClicked(int index)
43{
44 if(index == sortColumn()){
45 if(sort == Qt::AscendingOrder){
46 sort = Qt::DescendingOrder;
47 }else{
48 sort = Qt::AscendingOrder;
49 }
50 }else{
51 sort = Qt::AscendingOrder;
52 }
53
54 sortByColumn(index,sort);
55}
56
61{
62 setContextMenuPolicy(Qt::CustomContextMenu);
63 contextMenu = menu;
64}
65
69void CustomTreeWidget::onConnContext(QPoint p)
70{
71 if(contextMenu){
72 QPoint pp = QPoint(p.x(),p.y() + header()->height());
73 contextMenu->exec(mapToGlobal(pp));
74 }
75}
int SIGNAL(int pid, int signum)
void mousePressEvent(QMouseEvent *e) override
the mouse press event
CustomTreeWidget(QWidget *parent=0)
void setContextMenu(QMenu *)
Sets a context menu to the tree.