##// END OF EJS Templates
Implements filter function for data source...
Alexandre Leroux -
r477:eab21078feec
parent child
Show More
@@ -21,6 +21,8 public:
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
@@ -131,6 +131,11 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const Da
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) {
@@ -3,6 +3,7
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>
@@ -68,6 +69,21 void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept
68
69
69 void DataSourceWidget::filterChanged(const QString &text) noexcept
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 = [&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);
71 }
87 }
72
88
73 void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept
89 void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept
General Comments 0
You need to be logged in to leave comments. Login now