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