Add api to filter for thing class ids

pull/585/head
Michael Zanetti 2021-04-10 01:47:15 +02:00
parent 3c5b25ffae
commit 6407b81428
2 changed files with 51 additions and 0 deletions

View File

@ -130,6 +130,36 @@ void ThingClassesProxy::setFilterString(const QString &filterString)
}
}
QList<QUuid> ThingClassesProxy::shownThingClassIds() const
{
return m_shownThingClassIds;
}
void ThingClassesProxy::setShownThingClassIds(const QList<QUuid> &shownThingClassIds)
{
if (m_shownThingClassIds != shownThingClassIds) {
m_shownThingClassIds = shownThingClassIds;
emit shownThingClassIdsChanged();
invalidateFilter();
emit countChanged();
}
}
QList<QUuid> ThingClassesProxy::hiddenThingClassIds() const
{
return m_hiddenThingClassIds;
}
void ThingClassesProxy::setHiddenThingClassIds(const QList<QUuid> &hiddenThingClassIds)
{
if (m_hiddenThingClassIds != hiddenThingClassIds) {
m_hiddenThingClassIds = hiddenThingClassIds;
emit hiddenThingClassIdsChanged();
invalidateFilter();
emit countChanged();
}
}
bool ThingClassesProxy::groupByInterface() const
{
return m_groupByInterface;
@ -192,6 +222,14 @@ bool ThingClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourc
}
}
if (!m_shownThingClassIds.isEmpty() && !m_shownThingClassIds.contains(thingClass->id())) {
return false;
}
if (!m_hiddenThingClassIds.isEmpty() && m_hiddenThingClassIds.contains(thingClass->id())) {
return false;
}
if (!m_filterString.isEmpty()) {
Vendor *vendor = m_engine->thingManager()->vendors()->getVendor(thingClass->vendorId());
if (!vendor) {

View File

@ -50,6 +50,9 @@ class ThingClassesProxy : public QSortFilterProxyModel
Q_PROPERTY(QUuid filterVendorId READ filterVendorId WRITE setFilterVendorId NOTIFY filterVendorIdChanged)
Q_PROPERTY(QString filterVendorName READ filterVendorName WRITE setFilterVendorName NOTIFY filterVendorNameChanged)
Q_PROPERTY(QList<QUuid> shownThingClassIds READ shownThingClassIds WRITE setShownThingClassIds NOTIFY shownThingClassIdsChanged)
Q_PROPERTY(QList<QUuid> hiddenThingClassIds READ hiddenThingClassIds WRITE setHiddenThingClassIds NOTIFY hiddenThingClassIdsChanged)
// Filters by thingClass' displayName or vendor's displayName
Q_PROPERTY(QString filterString READ filterString WRITE setFilterString NOTIFY filterStringChanged)
@ -76,6 +79,12 @@ public:
QString filterString() const;
void setFilterString(const QString &filterString);
QList<QUuid> shownThingClassIds() const;
void setShownThingClassIds(const QList<QUuid> &shownThingClassIds);
QList<QUuid> hiddenThingClassIds() const;
void setHiddenThingClassIds(const QList<QUuid> &hiddenThingClassIds);
bool groupByInterface() const;
void setGroupByInterface(bool groupByInterface);
@ -90,6 +99,8 @@ signals:
void filterVendorIdChanged();
void filterVendorNameChanged();
void filterStringChanged();
void shownThingClassIdsChanged();
void hiddenThingClassIdsChanged();
void groupByInterfaceChanged();
void countChanged();
@ -103,6 +114,8 @@ private:
QString m_filterDisplayName;
QUuid m_filterVendorId;
QString m_filterVendorName;
QList<QUuid> m_hiddenThingClassIds;
QList<QUuid> m_shownThingClassIds;
QString m_filterString;
bool m_groupByInterface = false;
};