From 4579ce7405c1c7ad619b992584883d8fdf329bab Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 14 Nov 2019 10:40:18 +0100 Subject: [PATCH] Add a filter input field when adding new things --- libnymea-app-core/deviceclassesproxy.cpp | 18 ++++++++++++++++++ libnymea-app-core/deviceclassesproxy.h | 6 ++++++ .../ui/thingconfiguration/NewThingPage.qml | 19 ++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/libnymea-app-core/deviceclassesproxy.cpp b/libnymea-app-core/deviceclassesproxy.cpp index 6fdc10dd..6513c0d4 100644 --- a/libnymea-app-core/deviceclassesproxy.cpp +++ b/libnymea-app-core/deviceclassesproxy.cpp @@ -74,6 +74,20 @@ void DeviceClassesProxy::setFilterInterface(const QString &filterInterface) } } +QString DeviceClassesProxy::filterDisplayName() const +{ + return m_filterDisplayName; +} + +void DeviceClassesProxy::setFilterDisplayName(const QString &filter) +{ + if (m_filterDisplayName != filter) { + m_filterDisplayName = filter; + emit filterDisplayNameChanged(); + invalidateFilter(); + } +} + bool DeviceClassesProxy::groupByInterface() const { return m_groupByInterface; @@ -118,6 +132,10 @@ bool DeviceClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sour return false; } + if (!m_filterDisplayName.isEmpty() && !deviceClass->displayName().toLower().contains(m_filterDisplayName.toLower())) { + return false; + } + return true; } diff --git a/libnymea-app-core/deviceclassesproxy.h b/libnymea-app-core/deviceclassesproxy.h index 6a3a77bc..739b9aae 100644 --- a/libnymea-app-core/deviceclassesproxy.h +++ b/libnymea-app-core/deviceclassesproxy.h @@ -37,6 +37,7 @@ class DeviceClassesProxy : public QSortFilterProxyModel Q_PROPERTY(DeviceClasses *deviceClasses READ deviceClasses WRITE setDeviceClasses NOTIFY deviceClassesChanged) Q_PROPERTY(QString filterInterface READ filterInterface WRITE setFilterInterface NOTIFY filterInterfaceChanged) + Q_PROPERTY(QString filterDisplayName READ filterDisplayName WRITE setFilterDisplayName NOTIFY filterDisplayNameChanged) Q_PROPERTY(bool groupByInterface READ groupByInterface WRITE setGroupByInterface NOTIFY groupByInterfaceChanged) @@ -52,6 +53,9 @@ public: QString filterInterface() const; void setFilterInterface(const QString &filterInterface); + QString filterDisplayName() const; + void setFilterDisplayName(const QString &filter); + bool groupByInterface() const; void setGroupByInterface(bool groupByInterface); @@ -63,6 +67,7 @@ signals: void vendorIdChanged(); void deviceClassesChanged(); void filterInterfaceChanged(); + void filterDisplayNameChanged(); void groupByInterfaceChanged(); protected: @@ -73,6 +78,7 @@ private: QUuid m_vendorId; DeviceClasses *m_deviceClasses; QString m_filterInterface; + QString m_filterDisplayName; bool m_groupByInterface = false; }; diff --git a/nymea-app/ui/thingconfiguration/NewThingPage.qml b/nymea-app/ui/thingconfiguration/NewThingPage.qml index 0dc58ead..465f889e 100644 --- a/nymea-app/ui/thingconfiguration/NewThingPage.qml +++ b/nymea-app/ui/thingconfiguration/NewThingPage.qml @@ -33,7 +33,7 @@ Page { anchors.fill: parent anchors.margins: app.margins columnSpacing: app.margins - columns: 2 + columns: Math.max(1, Math.floor(width / 250)) * 2 Label { text: qsTr("Vendor") } @@ -87,6 +87,22 @@ Page { } } } + + Item { + Layout.preferredHeight: app.iconSize + Layout.minimumWidth: app.iconSize + + ColorIcon { + height: parent.height + width: height + name: "../images/find.svg" + } + } + + TextField { + id: displayNameFilterField + Layout.fillWidth: true + } } } } @@ -104,6 +120,7 @@ Page { vendorId: vendorsFilterModel.get(vendorFilterComboBox.currentIndex).vendorId deviceClasses: engine.deviceManager.deviceClasses filterInterface: typeFilterModel.get(typeFilterComboBox.currentIndex).interfaceName + filterDisplayName: displayNameFilterField.displayText groupByInterface: true }