Merge PR #303: Allow filtering by vendor when adding new things
This commit is contained in:
commit
6d906c44a6
@ -30,35 +30,22 @@ DeviceClassesProxy::DeviceClassesProxy(QObject *parent) :
|
|||||||
setSortRole(DeviceClasses::RoleDisplayName);
|
setSortRole(DeviceClasses::RoleDisplayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Engine *DeviceClassesProxy::engine() const
|
||||||
QUuid DeviceClassesProxy::vendorId() const
|
|
||||||
{
|
{
|
||||||
return m_vendorId;
|
return m_engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClassesProxy::setVendorId(const QUuid &vendorId)
|
void DeviceClassesProxy::setEngine(Engine *engine)
|
||||||
{
|
{
|
||||||
m_vendorId = vendorId;
|
if (m_engine != engine) {
|
||||||
emit vendorIdChanged();
|
m_engine = engine;
|
||||||
|
setSourceModel(engine->deviceManager()->deviceClasses());
|
||||||
qDebug() << "DeviceClassesProxy: set vendorId filter" << vendorId;
|
emit engineChanged();
|
||||||
|
emit countChanged();
|
||||||
invalidateFilter();
|
sort(0);
|
||||||
sort(0);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceClasses *DeviceClassesProxy::deviceClasses()
|
|
||||||
{
|
|
||||||
return m_deviceClasses;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceClassesProxy::setDeviceClasses(DeviceClasses *deviceClasses)
|
|
||||||
{
|
|
||||||
m_deviceClasses = deviceClasses;
|
|
||||||
setSourceModel(deviceClasses);
|
|
||||||
emit deviceClassesChanged();
|
|
||||||
sort(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DeviceClassesProxy::filterInterface() const
|
QString DeviceClassesProxy::filterInterface() const
|
||||||
{
|
{
|
||||||
@ -71,6 +58,7 @@ void DeviceClassesProxy::setFilterInterface(const QString &filterInterface)
|
|||||||
m_filterInterface = filterInterface;
|
m_filterInterface = filterInterface;
|
||||||
emit filterInterfaceChanged();
|
emit filterInterfaceChanged();
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
|
emit countChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +73,52 @@ void DeviceClassesProxy::setFilterDisplayName(const QString &filter)
|
|||||||
m_filterDisplayName = filter;
|
m_filterDisplayName = filter;
|
||||||
emit filterDisplayNameChanged();
|
emit filterDisplayNameChanged();
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
|
emit countChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid DeviceClassesProxy::filterVendorId() const
|
||||||
|
{
|
||||||
|
return m_filterVendorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClassesProxy::setFilterVendorId(const QUuid &filterVendorId)
|
||||||
|
{
|
||||||
|
if (m_filterVendorId != filterVendorId) {
|
||||||
|
m_filterVendorId = filterVendorId;
|
||||||
|
emit filterVendorIdChanged();
|
||||||
|
invalidateFilter();
|
||||||
|
emit countChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeviceClassesProxy::filterVendorName() const
|
||||||
|
{
|
||||||
|
return m_filterVendorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClassesProxy::setFilterVendorName(const QString &filterVendorName)
|
||||||
|
{
|
||||||
|
if (m_filterVendorName != filterVendorName) {
|
||||||
|
m_filterVendorName = filterVendorName;
|
||||||
|
emit filterVendorNameChanged();
|
||||||
|
invalidateFilter();
|
||||||
|
emit countChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeviceClassesProxy::filterString() const
|
||||||
|
{
|
||||||
|
return m_filterString;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClassesProxy::setFilterString(const QString &filterString)
|
||||||
|
{
|
||||||
|
if (m_filterString != filterString) {
|
||||||
|
m_filterString = filterString;
|
||||||
|
emit filterStringChanged();
|
||||||
|
invalidateFilter();
|
||||||
|
emit countChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,28 +138,31 @@ void DeviceClassesProxy::setGroupByInterface(bool groupByInterface)
|
|||||||
|
|
||||||
DeviceClass *DeviceClassesProxy::get(int index) const
|
DeviceClass *DeviceClassesProxy::get(int index) const
|
||||||
{
|
{
|
||||||
return m_deviceClasses->get(mapToSource(this->index(index, 0)).row());
|
return m_engine->deviceManager()->deviceClasses()->get(mapToSource(this->index(index, 0)).row());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DeviceClassesProxy::resetFilter()
|
void DeviceClassesProxy::resetFilter()
|
||||||
{
|
{
|
||||||
qDebug() << "DeviceClassesProxy: reset filter";
|
m_filterVendorId = QUuid();
|
||||||
setVendorId(QUuid());
|
m_filterInterface.clear();
|
||||||
|
m_filterVendorName.clear();
|
||||||
|
m_filterDisplayName.clear();
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
|
emit countChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
bool DeviceClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(sourceParent)
|
Q_UNUSED(sourceParent)
|
||||||
|
|
||||||
DeviceClass *deviceClass = m_deviceClasses->get(sourceRow);
|
DeviceClass *deviceClass = m_engine->deviceManager()->deviceClasses()->get(sourceRow);
|
||||||
|
|
||||||
// filter auto devices
|
// filter auto devices
|
||||||
if (deviceClass->createMethods().count() == 1 && deviceClass->createMethods().contains("CreateMethodAuto"))
|
if (deviceClass->createMethods().count() == 1 && deviceClass->createMethods().contains("CreateMethodAuto"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!m_vendorId.isNull() && deviceClass->vendorId() != m_vendorId)
|
if (!m_filterVendorId.isNull() && deviceClass->vendorId() != m_filterVendorId)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!m_filterInterface.isEmpty() && !deviceClass->interfaces().contains(m_filterInterface)) {
|
if (!m_filterInterface.isEmpty() && !deviceClass->interfaces().contains(m_filterInterface)) {
|
||||||
@ -136,6 +173,28 @@ bool DeviceClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sour
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!m_filterVendorName.isEmpty()) {
|
||||||
|
Vendor *vendor = m_engine->deviceManager()->vendors()->getVendor(deviceClass->vendorId());
|
||||||
|
if (!vendor) {
|
||||||
|
qWarning() << "Invalid vendor for deviceClass:" << deviceClass->name() << deviceClass->vendorId();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!vendor->displayName().toLower().contains(m_filterVendorName.toLower())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_filterString.isEmpty()) {
|
||||||
|
Vendor *vendor = m_engine->deviceManager()->vendors()->getVendor(deviceClass->vendorId());
|
||||||
|
if (!vendor) {
|
||||||
|
qWarning() << "Invalid vendor for deviceClass:" << deviceClass->name() << deviceClass->vendorId();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!vendor->displayName().toLower().contains(m_filterString.toLower()) && !deviceClass->displayName().toLower().contains(m_filterString.toLower())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,28 +27,31 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
#include "engine.h"
|
||||||
#include "deviceclasses.h"
|
#include "deviceclasses.h"
|
||||||
#include "types/deviceclass.h"
|
#include "types/deviceclass.h"
|
||||||
|
|
||||||
class DeviceClassesProxy : public QSortFilterProxyModel
|
class DeviceClassesProxy : public QSortFilterProxyModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QUuid vendorId READ vendorId WRITE setVendorId NOTIFY vendorIdChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
Q_PROPERTY(DeviceClasses *deviceClasses READ deviceClasses WRITE setDeviceClasses NOTIFY deviceClassesChanged)
|
Q_PROPERTY(Engine *engine READ engine WRITE setEngine NOTIFY engineChanged)
|
||||||
|
|
||||||
Q_PROPERTY(QString filterInterface READ filterInterface WRITE setFilterInterface NOTIFY filterInterfaceChanged)
|
Q_PROPERTY(QString filterInterface READ filterInterface WRITE setFilterInterface NOTIFY filterInterfaceChanged)
|
||||||
Q_PROPERTY(QString filterDisplayName READ filterDisplayName WRITE setFilterDisplayName NOTIFY filterDisplayNameChanged)
|
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)
|
||||||
|
|
||||||
|
// Filters by deviceClass' displayName or vendor's displayName
|
||||||
|
Q_PROPERTY(QString filterString READ filterString WRITE setFilterString NOTIFY filterStringChanged)
|
||||||
|
|
||||||
Q_PROPERTY(bool groupByInterface READ groupByInterface WRITE setGroupByInterface NOTIFY groupByInterfaceChanged)
|
Q_PROPERTY(bool groupByInterface READ groupByInterface WRITE setGroupByInterface NOTIFY groupByInterfaceChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DeviceClassesProxy(QObject *parent = nullptr);
|
explicit DeviceClassesProxy(QObject *parent = nullptr);
|
||||||
|
|
||||||
QUuid vendorId() const;
|
Engine *engine() const;
|
||||||
void setVendorId(const QUuid &vendorId);
|
void setEngine(Engine *engine);
|
||||||
|
|
||||||
DeviceClasses *deviceClasses();
|
|
||||||
void setDeviceClasses(DeviceClasses *deviceClasses);
|
|
||||||
|
|
||||||
QString filterInterface() const;
|
QString filterInterface() const;
|
||||||
void setFilterInterface(const QString &filterInterface);
|
void setFilterInterface(const QString &filterInterface);
|
||||||
@ -56,6 +59,15 @@ public:
|
|||||||
QString filterDisplayName() const;
|
QString filterDisplayName() const;
|
||||||
void setFilterDisplayName(const QString &filter);
|
void setFilterDisplayName(const QString &filter);
|
||||||
|
|
||||||
|
QUuid filterVendorId() const;
|
||||||
|
void setFilterVendorId(const QUuid &filterVendorId);
|
||||||
|
|
||||||
|
QString filterVendorName() const;
|
||||||
|
void setFilterVendorName(const QString &filterVendorName);
|
||||||
|
|
||||||
|
QString filterString() const;
|
||||||
|
void setFilterString(const QString &filterString);
|
||||||
|
|
||||||
bool groupByInterface() const;
|
bool groupByInterface() const;
|
||||||
void setGroupByInterface(bool groupByInterface);
|
void setGroupByInterface(bool groupByInterface);
|
||||||
|
|
||||||
@ -64,21 +76,26 @@ public:
|
|||||||
Q_INVOKABLE void resetFilter();
|
Q_INVOKABLE void resetFilter();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void vendorIdChanged();
|
void engineChanged();
|
||||||
void deviceClassesChanged();
|
|
||||||
void filterInterfaceChanged();
|
void filterInterfaceChanged();
|
||||||
void filterDisplayNameChanged();
|
void filterDisplayNameChanged();
|
||||||
|
void filterVendorIdChanged();
|
||||||
|
void filterVendorNameChanged();
|
||||||
|
void filterStringChanged();
|
||||||
void groupByInterfaceChanged();
|
void groupByInterfaceChanged();
|
||||||
|
void countChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE;
|
||||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid m_vendorId;
|
Engine *m_engine = nullptr;
|
||||||
DeviceClasses *m_deviceClasses;
|
|
||||||
QString m_filterInterface;
|
QString m_filterInterface;
|
||||||
QString m_filterDisplayName;
|
QString m_filterDisplayName;
|
||||||
|
QUuid m_filterVendorId;
|
||||||
|
QString m_filterVendorName;
|
||||||
|
QString m_filterString;
|
||||||
bool m_groupByInterface = false;
|
bool m_groupByInterface = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -119,10 +119,10 @@ Page {
|
|||||||
|
|
||||||
model: DeviceClassesProxy {
|
model: DeviceClassesProxy {
|
||||||
id: deviceClassesProxy
|
id: deviceClassesProxy
|
||||||
vendorId: vendorFilterComboBox.currentIndex >= 0 ? vendorsFilterModel.get(vendorFilterComboBox.currentIndex).vendorId : ""
|
engine: _engine
|
||||||
deviceClasses: engine.deviceManager.deviceClasses
|
|
||||||
filterInterface: typeFilterModel.get(typeFilterComboBox.currentIndex).interfaceName
|
filterInterface: typeFilterModel.get(typeFilterComboBox.currentIndex).interfaceName
|
||||||
filterDisplayName: displayNameFilterField.displayText
|
filterVendorId: vendorFilterComboBox.currentIndex >= 0 ? vendorsFilterModel.get(vendorFilterComboBox.currentIndex).vendorId : ""
|
||||||
|
filterString: displayNameFilterField.displayText
|
||||||
groupByInterface: true
|
groupByInterface: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user