@@ -21,6 +21,8 public: | |||
|
21 | 21 | explicit DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data, |
|
22 | 22 | int type = Type); |
|
23 | 23 | |
|
24 | const DataSourceItem *data() const; | |
|
25 | ||
|
24 | 26 | virtual QVariant data(int column, int role) const override; |
|
25 | 27 | virtual void setData(int column, int role, const QVariant &value) override; |
|
26 | 28 |
@@ -131,6 +131,11 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const Da | |||
|
131 | 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 | 139 | QVariant DataSourceTreeWidgetItem::data(int column, int role) const |
|
135 | 140 | { |
|
136 | 141 | if (role == Qt::DisplayRole) { |
@@ -3,6 +3,7 | |||
|
3 | 3 | #include <ui_DataSourceWidget.h> |
|
4 | 4 | |
|
5 | 5 | #include <DataSource/DataSourceItem.h> |
|
6 | #include <DataSource/DataSourceTreeWidgetHelper.h> | |
|
6 | 7 | #include <DataSource/DataSourceTreeWidgetItem.h> |
|
7 | 8 | |
|
8 | 9 | #include <QMenu> |
@@ -68,6 +69,21 void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept | |||
|
68 | 69 | |
|
69 | 70 | void DataSourceWidget::filterChanged(const QString &text) noexcept |
|
70 | 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 | = [®Exp](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); | |
|
71 | 87 | } |
|
72 | 88 | |
|
73 | 89 | void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept |
General Comments 0
You need to be logged in to leave comments.
Login now