Add support for the providedInterfaces thing class property

This commit is contained in:
Michael Zanetti 2021-11-11 01:32:23 +01:00
parent 291ed6cf64
commit a7210b2837
8 changed files with 55 additions and 10 deletions

View File

@ -70,6 +70,21 @@ void ThingClassesProxy::setFilterInterface(const QString &filterInterface)
}
}
bool ThingClassesProxy::includeProvidedInterfaces() const
{
return m_includeProvidedInterfaces;
}
void ThingClassesProxy::setIncludeProvidedInterfaces(bool includeProvidedInterfaces)
{
if (m_includeProvidedInterfaces != includeProvidedInterfaces) {
m_includeProvidedInterfaces = includeProvidedInterfaces;
emit includeProvidedInterfacesChanged();
invalidateFilter();
emit countChanged();
}
}
QString ThingClassesProxy::filterDisplayName() const
{
return m_filterDisplayName;
@ -207,7 +222,11 @@ bool ThingClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourc
return false;
if (!m_filterInterface.isEmpty() && !thingClass->interfaces().contains(m_filterInterface)) {
return false;
if (!m_includeProvidedInterfaces) {
return false;
} else if (!thingClass->providedInterfaces().contains(m_filterInterface)) {
return false;
}
}
if (!m_filterDisplayName.isEmpty() && !thingClass->displayName().toLower().contains(m_filterDisplayName.toLower())) {

View File

@ -46,6 +46,7 @@ class ThingClassesProxy : public QSortFilterProxyModel
Q_PROPERTY(Engine *engine READ engine WRITE setEngine NOTIFY engineChanged)
Q_PROPERTY(QString filterInterface READ filterInterface WRITE setFilterInterface NOTIFY filterInterfaceChanged)
Q_PROPERTY(bool includeProvidedInterfaces READ includeProvidedInterfaces WRITE setIncludeProvidedInterfaces NOTIFY includeProvidedInterfacesChanged)
Q_PROPERTY(QString filterDisplayName READ filterDisplayName WRITE setFilterDisplayName NOTIFY filterDisplayNameChanged)
Q_PROPERTY(QUuid filterVendorId READ filterVendorId WRITE setFilterVendorId NOTIFY filterVendorIdChanged)
Q_PROPERTY(QString filterVendorName READ filterVendorName WRITE setFilterVendorName NOTIFY filterVendorNameChanged)
@ -67,6 +68,9 @@ public:
QString filterInterface() const;
void setFilterInterface(const QString &filterInterface);
bool includeProvidedInterfaces() const;
void setIncludeProvidedInterfaces(bool includeProvidedInterfaces);
QString filterDisplayName() const;
void setFilterDisplayName(const QString &filter);
@ -95,6 +99,7 @@ public:
signals:
void engineChanged();
void filterInterfaceChanged();
void includeProvidedInterfacesChanged();
void filterDisplayNameChanged();
void filterVendorIdChanged();
void filterVendorNameChanged();
@ -111,6 +116,7 @@ protected:
private:
Engine *m_engine = nullptr;
QString m_filterInterface;
bool m_includeProvidedInterfaces = false;
QString m_filterDisplayName;
QUuid m_filterVendorId;
QString m_filterVendorName;

View File

@ -774,6 +774,7 @@ ThingClass *ThingManager::unpackThingClass(const QVariantMap &thingClassMap)
thingClass->setCreateMethods(createMethods);
thingClass->setSetupMethod(stringToSetupMethod(thingClassMap.value("setupMethod").toString()));
thingClass->setInterfaces(thingClassMap.value("interfaces").toStringList());
thingClass->setProvidedInterfaces(thingClassMap.value("providedInterfaces").toStringList());
// ParamTypes
ParamTypes *paramTypes = new ParamTypes(thingClass);

View File

@ -117,6 +117,16 @@ void ThingClass::setInterfaces(const QStringList &interfaces)
m_interfaces = interfaces;
}
QStringList ThingClass::providedInterfaces() const
{
return m_providedInterfaces;
}
void ThingClass::setProvidedInterfaces(const QStringList &providedInterfaces)
{
m_providedInterfaces = providedInterfaces;
}
QString ThingClass::baseInterface() const
{
foreach (const QString &interface, m_interfaces) {

View File

@ -52,6 +52,7 @@ class ThingClass : public QObject
Q_PROPERTY(QStringList createMethods READ createMethods CONSTANT)
Q_PROPERTY(SetupMethod setupMethod READ setupMethod CONSTANT)
Q_PROPERTY(QStringList interfaces READ interfaces CONSTANT)
Q_PROPERTY(QStringList providedInterfaces READ providedInterfaces CONSTANT)
Q_PROPERTY(QString baseInterface READ baseInterface CONSTANT)
Q_PROPERTY(bool browsable READ browsable CONSTANT)
Q_PROPERTY(ParamTypes *paramTypes READ paramTypes NOTIFY paramTypesChanged)
@ -100,6 +101,9 @@ public:
QStringList interfaces() const;
void setInterfaces(const QStringList &interfaces);
QStringList providedInterfaces() const;
void setProvidedInterfaces(const QStringList &providedInterfaces);
QString baseInterface() const;
bool browsable() const;
@ -146,6 +150,7 @@ private:
QStringList m_createMethods;
SetupMethod m_setupMethod;
QStringList m_interfaces;
QStringList m_providedInterfaces;
bool m_browsable = false;
ParamTypes *m_paramTypes = nullptr;

View File

@ -226,6 +226,8 @@ ApplicationWindow {
return qsTr("Smart meters");
case "heating":
return qsTr("Heating");
case "cooling":
return qsTr("Cooling");
case "thermostat":
return qsTr("Thermostats");
case "evcharger":
@ -360,6 +362,8 @@ ApplicationWindow {
return Qt.resolvedUrl("images/fingerprint.svg")
case "accesscontrol":
return Qt.resolvedUrl("images/lock-closed.svg");
case "solarinverter":
return Qt.resolvedUrl("images/weathericons/weather-clear-day.svg")
case "smartmeter":
case "smartmeterconsumer":
case "smartmeterproducer":

View File

@ -149,12 +149,13 @@ Page {
id: thingClassesProxy
engine: _engine
filterInterface: typeFilterModel.get(typeFilterComboBox.currentIndex).interfaceName
includeProvidedInterfaces: true
filterVendorId: vendorFilterComboBox.currentIndex >= 0 ? vendorsFilterModel.get(vendorFilterComboBox.currentIndex).vendorId : ""
filterString: displayNameFilterField.displayText
groupByInterface: true
}
delegate: NymeaSwipeDelegate {
delegate: NymeaItemDelegate {
id: tingClassDelegate
width: parent.width
text: model.displayName

View File

@ -64,16 +64,15 @@ SettingsPageBase {
text: qsTr("Interfaces")
}
Repeater {
model: root.thingClass.interfaces
delegate: Label {
Layout.fillWidth: true
Layout.leftMargin: Style.margins
Layout.rightMargin: Style.margins
text: modelData
}
Label {
Layout.fillWidth: true
Layout.leftMargin: Style.margins
Layout.rightMargin: Style.margins
wrapMode: Text.WordWrap
text: root.thingClass.interfaces.join(", ") + (root.thingClass.providedInterfaces.length > 0 ? " (" + root.thingClass.providedInterfaces.join(", ") + ")" : "")
}
SettingsPageSectionHeader {
text: qsTr("Parameters")
visible: root.thingClass.paramTypes.count > 0