YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
customtreewidget.h
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#ifndef CUSTOMTREEWIDGET_H
7#define CUSTOMTREEWIDGET_H
8
9#include <QTreeWidget>
10#include <QMenu>
11#include <yarp/conf/compiler.h>
12
13
20class CustomTreeWidgetItem : public QTreeWidgetItem
21{
22public:
23 CustomTreeWidgetItem(QTreeWidget *view, const QStringList &strings, int type = Type) :
24 QTreeWidgetItem(view,strings,type){}
25
26 CustomTreeWidgetItem(QTreeWidgetItem *item, const QStringList &strings, int type = Type) :
27 QTreeWidgetItem(item,strings,type){}
28 bool operator< (const QTreeWidgetItem &other) const override {
29 int sortCol = treeWidget()->sortColumn();
30 if(sortCol == 1){
31 int myNumber = text(sortCol).toInt();
32 int otherNumber = other.text(sortCol).toInt();
33 return myNumber < otherNumber;
34 }else{
35 return QTreeWidgetItem::operator <(other);
36 }
37 }
38
39};
40
46class CustomTreeWidget : public QTreeWidget
47{
48 Q_OBJECT
49public:
50 explicit CustomTreeWidget(QWidget *parent = 0);
51 void setContextMenu(QMenu *);
52
53protected:
54 void mousePressEvent(QMouseEvent *e) override;
55
56private:
57 Qt::SortOrder sort;
58 QMenu *contextMenu;
59signals:
60
61private slots:
62 void onHeaderClicked(int index);
63 void onConnContext(QPoint p);
64
65};
66
67#endif // CUSTOMTREEWIDGET_H
A custom QTreeWidgetItem.
CustomTreeWidgetItem(QTreeWidget *view, const QStringList &strings, int type=Type)
bool operator<(const QTreeWidgetItem &other) const override
CustomTreeWidgetItem(QTreeWidgetItem *item, const QStringList &strings, int type=Type)
A custom QTreeWidget.
void mousePressEvent(QMouseEvent *e) override
the mouse press event
void setContextMenu(QMenu *)
Sets a context menu to the tree.