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