Merge PR #531: Update devices to things in interfacesproxy
This commit is contained in:
commit
298ab714b6
@ -69,16 +69,15 @@ Engine *InterfacesModel::engine() const
|
||||
void InterfacesModel::setEngine(Engine *engine)
|
||||
{
|
||||
if (m_engine != engine) {
|
||||
static QMetaObject::Connection countChangedConnection;
|
||||
|
||||
if (m_engine) {
|
||||
disconnect(countChangedConnection);
|
||||
disconnect(m_thingClassesCountChangedConnection);
|
||||
}
|
||||
|
||||
m_engine = engine;
|
||||
emit engineChanged();
|
||||
|
||||
countChangedConnection = connect(engine->deviceManager()->deviceClasses(), &DeviceClasses::countChanged, this, [this]() {
|
||||
m_thingClassesCountChangedConnection = connect(engine->deviceManager()->deviceClasses(), &DeviceClasses::countChanged, this, [this]() {
|
||||
syncInterfaces();
|
||||
});
|
||||
|
||||
@ -86,24 +85,22 @@ void InterfacesModel::setEngine(Engine *engine)
|
||||
}
|
||||
}
|
||||
|
||||
DevicesProxy *InterfacesModel::devices() const
|
||||
DevicesProxy *InterfacesModel::things() const
|
||||
{
|
||||
return m_devicesProxy;
|
||||
return m_thingsProxy;
|
||||
}
|
||||
|
||||
void InterfacesModel::setDevices(DevicesProxy *devices)
|
||||
void InterfacesModel::setThings(DevicesProxy *things)
|
||||
{
|
||||
if (m_devicesProxy != devices) {
|
||||
static QMetaObject::Connection countChangedConnection;
|
||||
|
||||
if (m_devicesProxy) {
|
||||
disconnect(countChangedConnection);
|
||||
if (m_thingsProxy != things) {
|
||||
if (m_thingsProxy) {
|
||||
disconnect(m_thingsCountChangedConnection);
|
||||
}
|
||||
|
||||
m_devicesProxy = devices;
|
||||
emit devicesChanged();
|
||||
m_thingsProxy = things;
|
||||
emit thingsChanged();
|
||||
|
||||
countChangedConnection = connect(devices, &DevicesProxy::countChanged, this, [this]() {
|
||||
m_thingsCountChangedConnection = connect(things, &DevicesProxy::countChanged, this, [this]() {
|
||||
syncInterfaces();
|
||||
});
|
||||
syncInterfaces();
|
||||
@ -153,9 +150,9 @@ void InterfacesModel::syncInterfaces()
|
||||
return;
|
||||
}
|
||||
QList<DeviceClass*> deviceClasses;
|
||||
if (m_devicesProxy) {
|
||||
for (int i = 0; i < m_devicesProxy->rowCount(); i++) {
|
||||
deviceClasses << m_engine->deviceManager()->deviceClasses()->getDeviceClass(m_devicesProxy->get(i)->deviceClassId());
|
||||
if (m_thingsProxy) {
|
||||
for (int i = 0; i < m_thingsProxy->rowCount(); i++) {
|
||||
deviceClasses << m_engine->deviceManager()->deviceClasses()->getDeviceClass(m_thingsProxy->get(i)->deviceClassId());
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < m_engine->deviceManager()->deviceClasses()->rowCount(); i++) {
|
||||
|
||||
@ -48,7 +48,7 @@ class InterfacesModel : public QAbstractListModel
|
||||
Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged)
|
||||
|
||||
// Optional filters
|
||||
Q_PROPERTY(DevicesProxy* devices READ devices WRITE setDevices NOTIFY devicesChanged)
|
||||
Q_PROPERTY(DevicesProxy* things READ things WRITE setThings NOTIFY thingsChanged)
|
||||
Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged)
|
||||
Q_PROPERTY(bool showUncategorized READ showUncategorized WRITE setShowUncategorized NOTIFY showUncategorizedChanged)
|
||||
|
||||
@ -67,8 +67,8 @@ public:
|
||||
Engine* engine() const;
|
||||
void setEngine(Engine *engine);
|
||||
|
||||
DevicesProxy* devices() const;
|
||||
void setDevices(DevicesProxy *devices);
|
||||
DevicesProxy* things() const;
|
||||
void setThings(DevicesProxy *things);
|
||||
|
||||
QStringList shownInterfaces() const;
|
||||
void setShownInterfaces(const QStringList &shownInterfaces);
|
||||
@ -84,7 +84,7 @@ public:
|
||||
signals:
|
||||
void countChanged();
|
||||
void engineChanged();
|
||||
void devicesChanged();
|
||||
void thingsChanged();
|
||||
void shownInterfacesChanged();
|
||||
bool onlyConfiguredDevicesChanged();
|
||||
void showUncategorizedChanged();
|
||||
@ -95,9 +95,13 @@ private slots:
|
||||
|
||||
private:
|
||||
Engine *m_engine = nullptr;
|
||||
QMetaObject::Connection m_thingClassesCountChangedConnection;
|
||||
|
||||
QStringList m_interfaces;
|
||||
|
||||
DevicesProxy *m_devicesProxy = nullptr;
|
||||
DevicesProxy *m_thingsProxy = nullptr;
|
||||
QMetaObject::Connection m_thingsCountChangedConnection;
|
||||
|
||||
QStringList m_shownInterfaces;
|
||||
bool m_showUncategorized = false;
|
||||
};
|
||||
|
||||
@ -98,11 +98,11 @@ bool InterfacesProxy::filterAcceptsRow(int source_row, const QModelIndex &source
|
||||
}
|
||||
}
|
||||
|
||||
if (m_devicesFilter != nullptr) {
|
||||
if (m_thingsFilter != nullptr) {
|
||||
// TODO: This could be improved *a lot* by caching interfaces in the devices model...
|
||||
bool found = false;
|
||||
for (int i = 0; i < m_devicesFilter->rowCount(); i++) {
|
||||
Device *d = m_devicesFilter->get(i);
|
||||
for (int i = 0; i < m_thingsFilter->rowCount(); i++) {
|
||||
Device *d = m_thingsFilter->get(i);
|
||||
if (!d->thingClass()) {
|
||||
qWarning() << "Cannot find DeviceClass for device:" << d->id() << d->name();
|
||||
return false;
|
||||
@ -116,11 +116,11 @@ bool InterfacesProxy::filterAcceptsRow(int source_row, const QModelIndex &source
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (m_devicesProxyFilter != nullptr) {
|
||||
if (m_thingsProxyFilter != nullptr) {
|
||||
// TODO: This could be improved *a lot* by caching interfaces in the devices model...
|
||||
bool found = false;
|
||||
for (int i = 0; i < m_devicesProxyFilter->rowCount(); i++) {
|
||||
Device *d = m_devicesProxyFilter->get(i);
|
||||
for (int i = 0; i < m_thingsProxyFilter->rowCount(); i++) {
|
||||
Device *d = m_thingsProxyFilter->get(i);
|
||||
if (!d->thingClass()) {
|
||||
qWarning() << "Cannot find ThingClass for thing:" << d->id() << d->name();
|
||||
return false;
|
||||
|
||||
@ -44,8 +44,8 @@ class InterfacesProxy: public QSortFilterProxyModel
|
||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||
|
||||
Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged)
|
||||
Q_PROPERTY(Devices* devicesFilter READ devicesFilter WRITE setDevicesFilter NOTIFY devicesFilterChanged)
|
||||
Q_PROPERTY(DevicesProxy* devicesProxyFilter READ devicesProxyFilter WRITE setDevicesProxyFilter NOTIFY devicesProxyFilterChanged)
|
||||
Q_PROPERTY(Devices* thingsFilter READ thingsFilter WRITE setThingsFilter NOTIFY thingsFilterChanged)
|
||||
Q_PROPERTY(DevicesProxy* thingsProxyFilter READ thingsProxyFilter WRITE setThingsProxyFilter NOTIFY thingsProxyFilterChanged)
|
||||
Q_PROPERTY(bool showEvents READ showEvents WRITE setShowEvents NOTIFY showEventsChanged)
|
||||
Q_PROPERTY(bool showActions READ showActions WRITE setShowActions NOTIFY showActionsChanged)
|
||||
Q_PROPERTY(bool showStates READ showStates WRITE setShowStates NOTIFY showStatesChanged)
|
||||
@ -56,11 +56,11 @@ public:
|
||||
QStringList shownInterfaces() const { return m_shownInterfaces; }
|
||||
void setShownInterfaces(const QStringList &shownInterfaces) { m_shownInterfaces = shownInterfaces; emit shownInterfacesChanged(); invalidateFilter(); }
|
||||
|
||||
Devices* devicesFilter() const { return m_devicesFilter; }
|
||||
void setDevicesFilter(Devices *devices) { m_devicesFilter = devices; emit devicesFilterChanged(); invalidateFilter(); }
|
||||
Devices* thingsFilter() const { return m_thingsFilter; }
|
||||
void setThingsFilter(Devices *things) { m_thingsFilter = things; emit thingsFilterChanged(); invalidateFilter(); }
|
||||
|
||||
DevicesProxy* devicesProxyFilter() const { return m_devicesProxyFilter; }
|
||||
void setDevicesProxyFilter(DevicesProxy *devicesProxy) { m_devicesProxyFilter = devicesProxy; emit devicesProxyFilterChanged(); invalidateFilter(); }
|
||||
DevicesProxy* thingsProxyFilter() const { return m_thingsProxyFilter; }
|
||||
void setThingsProxyFilter(DevicesProxy *thingsProxy) { m_thingsProxyFilter = thingsProxy; emit thingsProxyFilterChanged(); invalidateFilter(); }
|
||||
|
||||
bool showEvents() const;
|
||||
void setShowEvents(bool showEvents);
|
||||
@ -78,8 +78,8 @@ public:
|
||||
|
||||
signals:
|
||||
void shownInterfacesChanged();
|
||||
void devicesFilterChanged();
|
||||
void devicesProxyFilterChanged();
|
||||
void thingsFilterChanged();
|
||||
void thingsProxyFilterChanged();
|
||||
void showEventsChanged();
|
||||
void showActionsChanged();
|
||||
void showStatesChanged();
|
||||
@ -89,8 +89,8 @@ signals:
|
||||
private:
|
||||
Interfaces *m_interfaces = nullptr;
|
||||
QStringList m_shownInterfaces;
|
||||
Devices* m_devicesFilter = nullptr;
|
||||
DevicesProxy* m_devicesProxyFilter = nullptr;
|
||||
Devices* m_thingsFilter = nullptr;
|
||||
DevicesProxy* m_thingsProxyFilter = nullptr;
|
||||
bool m_showEvents = false;
|
||||
bool m_showActions = false;
|
||||
bool m_showStates = false;
|
||||
|
||||
@ -136,7 +136,7 @@ Item {
|
||||
ctx.beginPath();
|
||||
ctx.font = "" + app.hugeFont + "px " + Style.fontFamily;
|
||||
ctx.fillStyle = Style.foregroundColor;
|
||||
var roundedTargetTemp = Types.toUiValue(root.targetTemperatureState.value, root.targetTemperatureStateType.unit)
|
||||
var roundedTargetTemp = Types.toUiValue(currentValue, root.targetTemperatureStateType.unit)
|
||||
roundedTargetTemp = roundToPrecision(roundedTargetTemp).toFixed(1) + "°"
|
||||
var size = ctx.measureText(roundedTargetTemp)
|
||||
ctx.text(roundedTargetTemp, center.x - size.width / 2, center.y + app.hugeFont / 2);
|
||||
|
||||
@ -60,7 +60,7 @@ Page {
|
||||
model: InterfacesSortModel {
|
||||
interfacesModel: InterfacesModel {
|
||||
engine: _engine
|
||||
devices: devicesInGroup
|
||||
things: devicesInGroup
|
||||
shownInterfaces: app.supportedInterfaces
|
||||
showUncategorized: true
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ Page {
|
||||
|
||||
InterfacesProxy {
|
||||
id: interfacesInGroup
|
||||
devicesProxyFilter: devicesInGroup
|
||||
thingsProxyFilter: devicesInGroup
|
||||
showStates: true
|
||||
}
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ Page {
|
||||
|
||||
InterfacesProxy {
|
||||
id: interfacesProxy
|
||||
devicesFilter: engine.deviceManager.devices
|
||||
thingsFilter: engine.thingManager.things
|
||||
}
|
||||
|
||||
DevicesProxy {
|
||||
|
||||
@ -43,7 +43,7 @@ MainViewBase {
|
||||
id: mainModel
|
||||
interfacesModel: InterfacesModel {
|
||||
engine: _engine
|
||||
devices: DevicesProxy {
|
||||
things: DevicesProxy {
|
||||
engine: _engine
|
||||
}
|
||||
shownInterfaces: app.supportedInterfaces
|
||||
|
||||
Reference in New Issue
Block a user