##// END OF EJS Templates
Merge branch 'feature/DataSourceFilter' into develop
Alexandre Leroux -
r441:5cdac9f101d7 merge
parent child
Show More
@@ -0,0 +1,23
1 #ifndef SCIQLOP_DATASOURCETREEWIDGETHELPER_H
2 #define SCIQLOP_DATASOURCETREEWIDGETHELPER_H
3
4 #include <functional>
5
6 class DataSourceTreeWidgetItem;
7 class QTreeWidget;
8
9 class DataSourceTreeWidgetHelper {
10 public:
11 /// Signature of the function associated to the filtering action
12 using FilterFunction = std::function<bool(const DataSourceTreeWidgetItem &dataSourceItem)>;
13
14 /**
15 * Filters a tree widget according to a function. If an item is valid according to this
16 * function, all of its ancestors and children are shown
17 * @param treeWidget the widget to filter
18 * @param fun the filter function
19 */
20 static void filter(QTreeWidget &treeWidget, FilterFunction fun) noexcept;
21 };
22
23 #endif // SCIQLOP_DATASOURCETREEWIDGETHELPER_H
@@ -0,0 +1,36
1 #include "DataSource/DataSourceTreeWidgetHelper.h"
2 #include "DataSource/DataSourceTreeWidgetItem.h"
3
4 namespace {
5
6 bool filterTreeItem(DataSourceTreeWidgetItem &treeItem,
7 DataSourceTreeWidgetHelper::FilterFunction fun, bool parentValid = false)
8 {
9 auto selfValid = parentValid || fun(treeItem);
10
11 auto childValid = false;
12 auto childCount = treeItem.childCount();
13 for (auto i = 0; i < childCount; ++i) {
14 if (auto childItem = dynamic_cast<DataSourceTreeWidgetItem *>(treeItem.child(i))) {
15 childValid |= filterTreeItem(*childItem, fun, selfValid);
16 }
17 }
18
19 auto valid = selfValid || childValid;
20
21 treeItem.setHidden(!valid);
22
23 return valid;
24 }
25
26 } // namespace
27
28 void DataSourceTreeWidgetHelper::filter(QTreeWidget &treeWidget, FilterFunction fun) noexcept
29 {
30 auto itemCount = treeWidget.topLevelItemCount();
31 for (auto i = 0; i < itemCount; ++i) {
32 if (auto item = dynamic_cast<DataSourceTreeWidgetItem *>(treeWidget.topLevelItem(i))) {
33 filterTreeItem(*item, fun);
34 }
35 }
36 }
@@ -1,35 +1,37
1 #ifndef SCIQLOP_DATASOURCETREEWIDGETITEM_H
1 #ifndef SCIQLOP_DATASOURCETREEWIDGETITEM_H
2 #define SCIQLOP_DATASOURCETREEWIDGETITEM_H
2 #define SCIQLOP_DATASOURCETREEWIDGETITEM_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QTreeWidgetItem>
7 #include <QTreeWidgetItem>
8
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem)
9 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem)
10
10
11 class DataSourceItem;
11 class DataSourceItem;
12
12
13 /**
13 /**
14 * @brief The DataSourceTreeWidgetItem is the graphical representation of a data source item. It is
14 * @brief The DataSourceTreeWidgetItem is the graphical representation of a data source item. It is
15 * intended to be displayed in a QTreeWidget.
15 * intended to be displayed in a QTreeWidget.
16 * @sa DataSourceItem
16 * @sa DataSourceItem
17 */
17 */
18 class DataSourceTreeWidgetItem : public QTreeWidgetItem {
18 class DataSourceTreeWidgetItem : public QTreeWidgetItem {
19 public:
19 public:
20 explicit DataSourceTreeWidgetItem(const DataSourceItem *data, int type = Type);
20 explicit DataSourceTreeWidgetItem(const DataSourceItem *data, int type = Type);
21 explicit DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
21 explicit DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
22 int type = Type);
22 int type = Type);
23
23
24 const DataSourceItem *data() const;
25
24 virtual QVariant data(int column, int role) const override;
26 virtual QVariant data(int column, int role) const override;
25 virtual void setData(int column, int role, const QVariant &value) override;
27 virtual void setData(int column, int role, const QVariant &value) override;
26
28
27 /// @return the actions associated to the item
29 /// @return the actions associated to the item
28 QList<QAction *> actions() const noexcept;
30 QList<QAction *> actions() const noexcept;
29
31
30 private:
32 private:
31 class DataSourceTreeWidgetItemPrivate;
33 class DataSourceTreeWidgetItemPrivate;
32 spimpl::unique_impl_ptr<DataSourceTreeWidgetItemPrivate> impl;
34 spimpl::unique_impl_ptr<DataSourceTreeWidgetItemPrivate> impl;
33 };
35 };
34
36
35 #endif // SCIQLOP_DATASOURCETREEWIDGETITEM_H
37 #endif // SCIQLOP_DATASOURCETREEWIDGETITEM_H
@@ -1,39 +1,42
1 #ifndef SCIQLOP_DATASOURCEWIDGET_H
1 #ifndef SCIQLOP_DATASOURCEWIDGET_H
2 #define SCIQLOP_DATASOURCEWIDGET_H
2 #define SCIQLOP_DATASOURCEWIDGET_H
3
3
4 #include <QWidget>
4 #include <QWidget>
5
5
6 namespace Ui {
6 namespace Ui {
7 class DataSourceWidget;
7 class DataSourceWidget;
8 } // Ui
8 } // Ui
9
9
10 class DataSourceItem;
10 class DataSourceItem;
11
11
12 /**
12 /**
13 * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources
13 * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources
14 * attached to SciQlop.
14 * attached to SciQlop.
15 */
15 */
16 class DataSourceWidget : public QWidget {
16 class DataSourceWidget : public QWidget {
17 Q_OBJECT
17 Q_OBJECT
18
18
19 public:
19 public:
20 explicit DataSourceWidget(QWidget *parent = 0);
20 explicit DataSourceWidget(QWidget *parent = 0);
21 virtual ~DataSourceWidget() noexcept;
21 virtual ~DataSourceWidget() noexcept;
22
22
23 public slots:
23 public slots:
24 /**
24 /**
25 * Adds a data source. An item associated to the data source is created and then added to the
25 * Adds a data source. An item associated to the data source is created and then added to the
26 * representation tree
26 * representation tree
27 * @param dataSource the data source to add. The pointer has to be not null
27 * @param dataSource the data source to add. The pointer has to be not null
28 */
28 */
29 void addDataSource(DataSourceItem *dataSource) noexcept;
29 void addDataSource(DataSourceItem *dataSource) noexcept;
30
30
31 private:
31 private:
32 Ui::DataSourceWidget *ui;
32 Ui::DataSourceWidget *ui;
33
33
34 private slots:
34 private slots:
35 /// Slot called when the filtering text has changed
36 void filterChanged(const QString &text) noexcept;
37
35 /// Slot called when right clicking on an item in the tree (displays a menu)
38 /// Slot called when right clicking on an item in the tree (displays a menu)
36 void onTreeMenuRequested(const QPoint &pos) noexcept;
39 void onTreeMenuRequested(const QPoint &pos) noexcept;
37 };
40 };
38
41
39 #endif // SCIQLOP_DATASOURCEWIDGET_H
42 #endif // SCIQLOP_DATASOURCEWIDGET_H
@@ -1,171 +1,176
1 #include <DataSource/DataSourceItem.h>
1 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceItemAction.h>
2 #include <DataSource/DataSourceItemAction.h>
3 #include <DataSource/DataSourceTreeWidgetItem.h>
3 #include <DataSource/DataSourceTreeWidgetItem.h>
4
4
5 #include <QAction>
5 #include <QAction>
6
6
7 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
7 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
8
8
9 namespace {
9 namespace {
10
10
11 // Column indexes
11 // Column indexes
12 const auto NAME_COLUMN = 0;
12 const auto NAME_COLUMN = 0;
13
13
14 QIcon itemIcon(const DataSourceItem *dataSource)
14 QIcon itemIcon(const DataSourceItem *dataSource)
15 {
15 {
16 if (dataSource) {
16 if (dataSource) {
17 auto dataSourceType = dataSource->type();
17 auto dataSourceType = dataSource->type();
18 switch (dataSourceType) {
18 switch (dataSourceType) {
19 case DataSourceItemType::NODE: {
19 case DataSourceItemType::NODE: {
20 return dataSource->isRoot() ? QIcon{":/icones/dataSourceRoot.png"}
20 return dataSource->isRoot() ? QIcon{":/icones/dataSourceRoot.png"}
21 : QIcon{":/icones/dataSourceNode.png"};
21 : QIcon{":/icones/dataSourceNode.png"};
22 }
22 }
23 case DataSourceItemType::PRODUCT:
23 case DataSourceItemType::PRODUCT:
24 return QIcon{":/icones/dataSourceProduct.png"};
24 return QIcon{":/icones/dataSourceProduct.png"};
25 case DataSourceItemType::COMPONENT:
25 case DataSourceItemType::COMPONENT:
26 return QIcon{":/icones/dataSourceComponent.png"};
26 return QIcon{":/icones/dataSourceComponent.png"};
27 default:
27 default:
28 // No action
28 // No action
29 break;
29 break;
30 }
30 }
31
31
32 qCWarning(LOG_DataSourceTreeWidgetItem())
32 qCWarning(LOG_DataSourceTreeWidgetItem())
33 << QObject::tr("Can't set data source icon : unknown data source type");
33 << QObject::tr("Can't set data source icon : unknown data source type");
34 }
34 }
35 else {
35 else {
36 qCCritical(LOG_DataSourceTreeWidgetItem())
36 qCCritical(LOG_DataSourceTreeWidgetItem())
37 << QObject::tr("Can't set data source icon : the data source is null");
37 << QObject::tr("Can't set data source icon : the data source is null");
38 }
38 }
39
39
40 // Default cases
40 // Default cases
41 return QIcon{};
41 return QIcon{};
42 }
42 }
43
43
44 /// @return the tooltip text for a variant. The text depends on whether the data is a simple variant
44 /// @return the tooltip text for a variant. The text depends on whether the data is a simple variant
45 /// or a list of variants
45 /// or a list of variants
46 QString tooltipValue(const QVariant &variant) noexcept
46 QString tooltipValue(const QVariant &variant) noexcept
47 {
47 {
48 // If the variant is a list of variants, the text of the tooltip is of the form: {val1, val2,
48 // If the variant is a list of variants, the text of the tooltip is of the form: {val1, val2,
49 // ...}
49 // ...}
50 if (variant.canConvert<QVariantList>()) {
50 if (variant.canConvert<QVariantList>()) {
51 auto valueString = QStringLiteral("{");
51 auto valueString = QStringLiteral("{");
52
52
53 auto variantList = variant.value<QVariantList>();
53 auto variantList = variant.value<QVariantList>();
54 for (auto it = variantList.cbegin(), end = variantList.cend(); it != end; ++it) {
54 for (auto it = variantList.cbegin(), end = variantList.cend(); it != end; ++it) {
55 valueString.append(it->toString());
55 valueString.append(it->toString());
56
56
57 if (std::distance(it, end) != 1) {
57 if (std::distance(it, end) != 1) {
58 valueString.append(", ");
58 valueString.append(", ");
59 }
59 }
60 }
60 }
61
61
62 valueString.append(QStringLiteral("}"));
62 valueString.append(QStringLiteral("}"));
63
63
64 return valueString;
64 return valueString;
65 }
65 }
66 else {
66 else {
67 return variant.toString();
67 return variant.toString();
68 }
68 }
69 }
69 }
70
70
71 QString itemTooltip(const DataSourceItem *dataSource) noexcept
71 QString itemTooltip(const DataSourceItem *dataSource) noexcept
72 {
72 {
73 // The tooltip displays all item's data
73 // The tooltip displays all item's data
74 if (dataSource) {
74 if (dataSource) {
75 auto result = QString{};
75 auto result = QString{};
76
76
77 const auto &data = dataSource->data();
77 const auto &data = dataSource->data();
78 for (auto it = data.cbegin(), end = data.cend(); it != end; ++it) {
78 for (auto it = data.cbegin(), end = data.cend(); it != end; ++it) {
79 result.append(QString{"<b>%1:</b> %2<br/>"}.arg(it.key(), tooltipValue(it.value())));
79 result.append(QString{"<b>%1:</b> %2<br/>"}.arg(it.key(), tooltipValue(it.value())));
80 }
80 }
81
81
82 return result;
82 return result;
83 }
83 }
84 else {
84 else {
85 qCCritical(LOG_DataSourceTreeWidgetItem())
85 qCCritical(LOG_DataSourceTreeWidgetItem())
86 << QObject::tr("Can't set data source tooltip : the data source is null");
86 << QObject::tr("Can't set data source tooltip : the data source is null");
87
87
88 return QString{};
88 return QString{};
89 }
89 }
90 }
90 }
91
91
92 } // namespace
92 } // namespace
93
93
94 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
94 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
95 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
95 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
96
96
97 /// Model used to retrieve data source information
97 /// Model used to retrieve data source information
98 const DataSourceItem *m_Data;
98 const DataSourceItem *m_Data;
99 /// Actions associated to the item. The parent of the item (QTreeWidget) takes the ownership of
99 /// Actions associated to the item. The parent of the item (QTreeWidget) takes the ownership of
100 /// the actions
100 /// the actions
101 QList<QAction *> m_Actions;
101 QList<QAction *> m_Actions;
102 };
102 };
103
103
104 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
104 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
105 : DataSourceTreeWidgetItem{nullptr, data, type}
105 : DataSourceTreeWidgetItem{nullptr, data, type}
106 {
106 {
107 }
107 }
108
108
109 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
109 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
110 int type)
110 int type)
111 : QTreeWidgetItem{parent, type},
111 : QTreeWidgetItem{parent, type},
112 impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
112 impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
113 {
113 {
114 // Sets the icon and the tooltip depending on the data source
114 // Sets the icon and the tooltip depending on the data source
115 setIcon(0, itemIcon(impl->m_Data));
115 setIcon(0, itemIcon(impl->m_Data));
116 setToolTip(0, itemTooltip(impl->m_Data));
116 setToolTip(0, itemTooltip(impl->m_Data));
117
117
118 // Generates tree actions based on the item actions
118 // Generates tree actions based on the item actions
119 auto createTreeAction = [this, &parent](const auto &itemAction) {
119 auto createTreeAction = [this, &parent](const auto &itemAction) {
120 auto treeAction = new QAction{itemAction->name(), parent};
120 auto treeAction = new QAction{itemAction->name(), parent};
121
121
122 // Executes item action when tree action is triggered
122 // Executes item action when tree action is triggered
123 QObject::connect(treeAction, &QAction::triggered, itemAction,
123 QObject::connect(treeAction, &QAction::triggered, itemAction,
124 &DataSourceItemAction::execute);
124 &DataSourceItemAction::execute);
125
125
126 return treeAction;
126 return treeAction;
127 };
127 };
128
128
129 auto itemActions = impl->m_Data->actions();
129 auto itemActions = impl->m_Data->actions();
130 std::transform(std::cbegin(itemActions), std::cend(itemActions),
130 std::transform(std::cbegin(itemActions), std::cend(itemActions),
131 std::back_inserter(impl->m_Actions), createTreeAction);
131 std::back_inserter(impl->m_Actions), createTreeAction);
132 }
132 }
133
133
134 const DataSourceItem *DataSourceTreeWidgetItem::data() const
135 {
136 return impl->m_Data;
137 }
138
134 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
139 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
135 {
140 {
136 if (role == Qt::DisplayRole) {
141 if (role == Qt::DisplayRole) {
137 if (impl->m_Data) {
142 if (impl->m_Data) {
138 switch (column) {
143 switch (column) {
139 case NAME_COLUMN:
144 case NAME_COLUMN:
140 return impl->m_Data->name();
145 return impl->m_Data->name();
141 default:
146 default:
142 // No action
147 // No action
143 break;
148 break;
144 }
149 }
145
150
146 qCWarning(LOG_DataSourceTreeWidgetItem())
151 qCWarning(LOG_DataSourceTreeWidgetItem())
147 << QObject::tr("Can't get data (unknown column %1)").arg(column);
152 << QObject::tr("Can't get data (unknown column %1)").arg(column);
148 }
153 }
149 else {
154 else {
150 qCCritical(LOG_DataSourceTreeWidgetItem()) << QObject::tr("Can't get data (null item)");
155 qCCritical(LOG_DataSourceTreeWidgetItem()) << QObject::tr("Can't get data (null item)");
151 }
156 }
152
157
153 return QVariant{};
158 return QVariant{};
154 }
159 }
155 else {
160 else {
156 return QTreeWidgetItem::data(column, role);
161 return QTreeWidgetItem::data(column, role);
157 }
162 }
158 }
163 }
159
164
160 void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
165 void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
161 {
166 {
162 // Data can't be changed by edition
167 // Data can't be changed by edition
163 if (role != Qt::EditRole) {
168 if (role != Qt::EditRole) {
164 QTreeWidgetItem::setData(column, role, value);
169 QTreeWidgetItem::setData(column, role, value);
165 }
170 }
166 }
171 }
167
172
168 QList<QAction *> DataSourceTreeWidgetItem::actions() const noexcept
173 QList<QAction *> DataSourceTreeWidgetItem::actions() const noexcept
169 {
174 {
170 return impl->m_Actions;
175 return impl->m_Actions;
171 }
176 }
@@ -1,77 +1,100
1 #include <DataSource/DataSourceWidget.h>
1 #include <DataSource/DataSourceWidget.h>
2
2
3 #include <ui_DataSourceWidget.h>
3 #include <ui_DataSourceWidget.h>
4
4
5 #include <DataSource/DataSourceItem.h>
5 #include <DataSource/DataSourceItem.h>
6 #include <DataSource/DataSourceTreeWidgetHelper.h>
6 #include <DataSource/DataSourceTreeWidgetItem.h>
7 #include <DataSource/DataSourceTreeWidgetItem.h>
7
8
8 #include <QMenu>
9 #include <QMenu>
9
10
10 namespace {
11 namespace {
11
12
12 /// Number of columns displayed in the tree
13 /// Number of columns displayed in the tree
13 const auto TREE_NB_COLUMNS = 1;
14 const auto TREE_NB_COLUMNS = 1;
14
15
15 /// Header labels for the tree
16 /// Header labels for the tree
16 const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")};
17 const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")};
17
18
18 /**
19 /**
19 * Creates the item associated to a data source
20 * Creates the item associated to a data source
20 * @param dataSource the data source for which to create the item
21 * @param dataSource the data source for which to create the item
21 * @return the new item
22 * @return the new item
22 */
23 */
23 DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource)
24 DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource)
24 {
25 {
25 // Creates item for the data source
26 // Creates item for the data source
26 auto item = new DataSourceTreeWidgetItem{dataSource};
27 auto item = new DataSourceTreeWidgetItem{dataSource};
27
28
28 // Generates items for the children of the data source
29 // Generates items for the children of the data source
29 for (auto i = 0; i < dataSource->childCount(); ++i) {
30 for (auto i = 0; i < dataSource->childCount(); ++i) {
30 item->addChild(createTreeWidgetItem(dataSource->child(i)));
31 item->addChild(createTreeWidgetItem(dataSource->child(i)));
31 }
32 }
32
33
33 return item;
34 return item;
34 }
35 }
35
36
36 } // namespace
37 } // namespace
37
38
38 DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::DataSourceWidget}
39 DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::DataSourceWidget}
39 {
40 {
40 ui->setupUi(this);
41 ui->setupUi(this);
41
42
42 // Set tree properties
43 // Set tree properties
43 ui->treeWidget->setColumnCount(TREE_NB_COLUMNS);
44 ui->treeWidget->setColumnCount(TREE_NB_COLUMNS);
44 ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS);
45 ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS);
45 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
46 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
46
47
47 // Connection to show a menu when right clicking on the tree
48 // Connection to show a menu when right clicking on the tree
48 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
49 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
49 &DataSourceWidget::onTreeMenuRequested);
50 &DataSourceWidget::onTreeMenuRequested);
51
52 // Connection to filter tree
53 connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &DataSourceWidget::filterChanged);
50 }
54 }
51
55
52 DataSourceWidget::~DataSourceWidget() noexcept
56 DataSourceWidget::~DataSourceWidget() noexcept
53 {
57 {
54 delete ui;
58 delete ui;
55 }
59 }
56
60
57 void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept
61 void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept
58 {
62 {
59 // Creates the item associated to the source and adds it to the tree widget. The tree widget
63 // Creates the item associated to the source and adds it to the tree widget. The tree widget
60 // takes the ownership of the item
64 // takes the ownership of the item
61 if (dataSource) {
65 if (dataSource) {
62 ui->treeWidget->addTopLevelItem(createTreeWidgetItem(dataSource));
66 ui->treeWidget->addTopLevelItem(createTreeWidgetItem(dataSource));
63 }
67 }
64 }
68 }
65
69
70 void DataSourceWidget::filterChanged(const QString &text) noexcept
71 {
72 auto validateItem = [&text](const DataSourceTreeWidgetItem &item) {
73 auto regExp = QRegExp{text, Qt::CaseInsensitive, QRegExp::Wildcard};
74
75 // An item is valid if any of its metadata validates the text filter
76 auto itemMetadata = item.data()->data();
77 auto itemMetadataEnd = itemMetadata.cend();
78 auto acceptFilter
79 = [&regExp](const auto &variant) { return variant.toString().contains(regExp); };
80
81 return std::find_if(itemMetadata.cbegin(), itemMetadataEnd, acceptFilter)
82 != itemMetadataEnd;
83 };
84
85 // Applies filter on tree widget
86 DataSourceTreeWidgetHelper::filter(*ui->treeWidget, validateItem);
87 }
88
66 void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept
89 void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept
67 {
90 {
68 // Retrieves the selected item in the tree, and build the menu from its actions
91 // Retrieves the selected item in the tree, and build the menu from its actions
69 if (auto selectedItem = dynamic_cast<DataSourceTreeWidgetItem *>(ui->treeWidget->itemAt(pos))) {
92 if (auto selectedItem = dynamic_cast<DataSourceTreeWidgetItem *>(ui->treeWidget->itemAt(pos))) {
70 QMenu treeMenu{};
93 QMenu treeMenu{};
71 treeMenu.addActions(selectedItem->actions());
94 treeMenu.addActions(selectedItem->actions());
72
95
73 if (!treeMenu.isEmpty()) {
96 if (!treeMenu.isEmpty()) {
74 treeMenu.exec(mapToGlobal(pos));
97 treeMenu.exec(mapToGlobal(pos));
75 }
98 }
76 }
99 }
77 }
100 }
@@ -1,42 +1,33
1 <?xml version="1.0" encoding="UTF-8"?>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
2 <ui version="4.0">
3 <class>DataSourceWidget</class>
3 <class>DataSourceWidget</class>
4 <widget class="QWidget" name="DataSourceWidget">
4 <widget class="QWidget" name="DataSourceWidget">
5 <property name="geometry">
5 <property name="geometry">
6 <rect>
6 <rect>
7 <x>0</x>
7 <x>0</x>
8 <y>0</y>
8 <y>0</y>
9 <width>400</width>
9 <width>400</width>
10 <height>300</height>
10 <height>300</height>
11 </rect>
11 </rect>
12 </property>
12 </property>
13 <property name="windowTitle">
13 <property name="windowTitle">
14 <string>Data sources</string>
14 <string>Data sources</string>
15 </property>
15 </property>
16 <layout class="QGridLayout" name="gridLayout">
16 <layout class="QGridLayout" name="gridLayout">
17 <property name="topMargin">
18 <number>0</number>
19 </property>
20 <property name="rightMargin">
21 <number>0</number>
22 </property>
23 <property name="bottomMargin">
24 <number>0</number>
25 </property>
26 <property name="spacing">
27 <number>0</number>
28 </property>
29 <item row="0" column="0">
17 <item row="0" column="0">
18 <widget class="QLineEdit" name="filterLineEdit"/>
19 </item>
20 <item row="1" column="0">
30 <widget class="QTreeWidget" name="treeWidget">
21 <widget class="QTreeWidget" name="treeWidget">
31 <column>
22 <column>
32 <property name="text">
23 <property name="text">
33 <string notr="true">1</string>
24 <string notr="true">1</string>
34 </property>
25 </property>
35 </column>
26 </column>
36 </widget>
27 </widget>
37 </item>
28 </item>
38 </layout>
29 </layout>
39 </widget>
30 </widget>
40 <resources/>
31 <resources/>
41 <connections/>
32 <connections/>
42 </ui>
33 </ui>
General Comments 0
You need to be logged in to leave comments. Login now