diff --git a/libnymea-app/appdata.cpp b/libnymea-app/appdata.cpp index f8d66063..182afb4e 100644 --- a/libnymea-app/appdata.cpp +++ b/libnymea-app/appdata.cpp @@ -115,7 +115,7 @@ void AppData::load() for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); i++) { QMetaProperty prop = metaObject()->property(i); - qCDebug(dcAppData) << "ComponentComplete property:" << prop.name() << prop.isUser() << prop.type() << prop.isScriptable(this) << prop.isScriptable(); + qCDebug(dcAppData) << "ComponentComplete property:" << prop.name() << prop.isUser() << prop.type() << prop.isScriptable(); QVariantMap params; params.insert("appId", APPLICATION_NAME); if (!m_group.isEmpty()) { diff --git a/libnymea-app/appdata.h b/libnymea-app/appdata.h index 671e8eb5..6630eb5a 100644 --- a/libnymea-app/appdata.h +++ b/libnymea-app/appdata.h @@ -29,7 +29,7 @@ #include #include -class Engine; +#include "engine.h" class AppData : public QObject, public QQmlParserStatus { diff --git a/libnymea-app/configuration/networkmanager.h b/libnymea-app/configuration/networkmanager.h index 1bb5019a..30a63aaa 100644 --- a/libnymea-app/configuration/networkmanager.h +++ b/libnymea-app/configuration/networkmanager.h @@ -28,8 +28,10 @@ #include #include -class Engine; -class NetworkDevices; +#include "engine.h" +#include "types/networkdevices.h" + + class WiredNetworkDevices; class WirelessNetworkDevices; diff --git a/libnymea-app/configuration/nymeaconfiguration.h b/libnymea-app/configuration/nymeaconfiguration.h index c6cba934..7ae0d83f 100644 --- a/libnymea-app/configuration/nymeaconfiguration.h +++ b/libnymea-app/configuration/nymeaconfiguration.h @@ -27,6 +27,9 @@ #include +#include "serverconfigurations.h" +#include "mqttpolicies.h" + class JsonRpcClient; class ServerConfiguration; class ServerConfigurations; @@ -35,7 +38,6 @@ class WebServerConfigurations; class TunnelProxyServerConfiguration; class TunnelProxyServerConfigurations; class MqttPolicy; -class MqttPolicies; class NymeaConfiguration : public QObject { diff --git a/libnymea-app/connection/bluetoothtransport.cpp b/libnymea-app/connection/bluetoothtransport.cpp index dbb370c9..04706667 100644 --- a/libnymea-app/connection/bluetoothtransport.cpp +++ b/libnymea-app/connection/bluetoothtransport.cpp @@ -70,10 +70,10 @@ void BluetoothTransport::disconnect() NymeaTransportInterface::ConnectionState BluetoothTransport::connectionState() const { switch (m_socket->state()) { - case QBluetoothSocket::ConnectedState: + case QBluetoothSocket::SocketState::ConnectedState: return NymeaTransportInterface::ConnectionStateConnected; - case QBluetoothSocket::ConnectingState: - case QBluetoothSocket::ServiceLookupState: + case QBluetoothSocket::SocketState::ConnectingState: + case QBluetoothSocket::SocketState::ServiceLookupState: return NymeaTransportInterface::ConnectionStateConnecting; default: return NymeaTransportInterface::ConnectionStateDisconnected; diff --git a/libnymea-app/connection/discovery/nymeadiscovery.cpp b/libnymea-app/connection/discovery/nymeadiscovery.cpp index 45943f79..d7838a82 100644 --- a/libnymea-app/connection/discovery/nymeadiscovery.cpp +++ b/libnymea-app/connection/discovery/nymeadiscovery.cpp @@ -32,8 +32,8 @@ #include #include #include -#include -#include +//#include +//#include #include "logging.h" NYMEA_LOGGING_CATEGORY(dcDiscovery, "Discovery") @@ -192,7 +192,6 @@ void NymeaDiscovery::setUpnpDiscoveryEnabled(bool upnpDiscoveryEnabled) } } - void NymeaDiscovery::loadFromDisk() { QSettings settings; diff --git a/libnymea-app/connection/discovery/nymeadiscovery.h b/libnymea-app/connection/discovery/nymeadiscovery.h index a710c5c0..f0e13c29 100644 --- a/libnymea-app/connection/discovery/nymeadiscovery.h +++ b/libnymea-app/connection/discovery/nymeadiscovery.h @@ -30,8 +30,8 @@ #include #include "connection/nymeahost.h" +#include "connection/nymeahosts.h" -class NymeaHosts; class UpnpDiscovery; class ZeroconfDiscovery; class BluetoothServiceDiscovery; diff --git a/libnymea-app/connection/discovery/upnpdiscovery.cpp b/libnymea-app/connection/discovery/upnpdiscovery.cpp index 41d4376c..6a682da7 100644 --- a/libnymea-app/connection/discovery/upnpdiscovery.cpp +++ b/libnymea-app/connection/discovery/upnpdiscovery.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +//#include #include "logging.h" @@ -38,16 +38,16 @@ UpnpDiscovery::UpnpDiscovery(NymeaHosts *nymeaHosts, QObject *parent) : QObject(parent), m_nymeaHosts(nymeaHosts) { - m_networkConfigurationManager = new QNetworkConfigurationManager(this); +// m_networkConfigurationManager = new QNetworkConfigurationManager(this); m_networkAccessManager = new QNetworkAccessManager(this); connect(m_networkAccessManager, &QNetworkAccessManager::finished, this, &UpnpDiscovery::networkReplyFinished); m_repeatTimer.setInterval(500); connect(&m_repeatTimer, &QTimer::timeout, this, &UpnpDiscovery::writeDiscoveryPacket); - connect(m_networkConfigurationManager, &QNetworkConfigurationManager::configurationAdded, this, &UpnpDiscovery::updateInterfaces); - connect(m_networkConfigurationManager, &QNetworkConfigurationManager::configurationChanged, this, &UpnpDiscovery::updateInterfaces); - connect(m_networkConfigurationManager, &QNetworkConfigurationManager::configurationRemoved, this, &UpnpDiscovery::updateInterfaces); +// connect(m_networkConfigurationManager, &QNetworkConfigurationManager::configurationAdded, this, &UpnpDiscovery::updateInterfaces); +// connect(m_networkConfigurationManager, &QNetworkConfigurationManager::configurationChanged, this, &UpnpDiscovery::updateInterfaces); +// connect(m_networkConfigurationManager, &QNetworkConfigurationManager::configurationRemoved, this, &UpnpDiscovery::updateInterfaces); updateInterfaces(); } @@ -259,14 +259,14 @@ void UpnpDiscovery::networkReplyFinished(QNetworkReply *reply) } } - if (xml.name() == "friendlyName") { + if (xml.name() == QStringLiteral("friendlyName")) { name = xml.readElementText(); } - if (xml.name() == "modelNumber") { + if (xml.name() == QStringLiteral("modelNumber")) { version = xml.readElementText(); } - if (xml.name() == "UDN") { - uuid = xml.readElementText().split(':').last(); + if (xml.name() == QStringLiteral("UDN")) { + uuid = QUuid(xml.readElementText().split(':').last()); } } } diff --git a/libnymea-app/connection/discovery/upnpdiscovery.h b/libnymea-app/connection/discovery/upnpdiscovery.h index b05bd9aa..3e3dbf34 100644 --- a/libnymea-app/connection/discovery/upnpdiscovery.h +++ b/libnymea-app/connection/discovery/upnpdiscovery.h @@ -29,7 +29,7 @@ #include #include #include -#include +//#include #include #include "../nymeahost.h" @@ -63,7 +63,7 @@ private slots: private: QHash m_sockets; QNetworkAccessManager *m_networkAccessManager; - QNetworkConfigurationManager *m_networkConfigurationManager; +// QNetworkConfigurationManager *m_networkConfigurationManager; QTimer m_repeatTimer; diff --git a/libnymea-app/connection/discovery/zeroconfdiscovery.cpp b/libnymea-app/connection/discovery/zeroconfdiscovery.cpp index 202ffbd0..7633ef75 100644 --- a/libnymea-app/connection/discovery/zeroconfdiscovery.cpp +++ b/libnymea-app/connection/discovery/zeroconfdiscovery.cpp @@ -108,7 +108,7 @@ void ZeroconfDiscovery::serviceEntryAdded(const QZeroConfService &entry) qCDebug(dcZeroConf()) << "Service discovered" << entry->type() << entry->name() << " IP:" << entry->ip().toString() << entry->txt(); - QString uuid; + QUuid uuid; bool sslEnabled = false; QString serverName; QString version; @@ -118,7 +118,7 @@ void ZeroconfDiscovery::serviceEntryAdded(const QZeroConfService &entry) sslEnabled = (txtRecord.second == "true"); } if (txtRecord.first == "uuid") { - uuid = txtRecord.second; + uuid = QUuid(txtRecord.second); } if (txtRecord.first == "name") { serverName = txtRecord.second; @@ -167,7 +167,7 @@ void ZeroconfDiscovery::serviceEntryRemoved(const QZeroConfService &entry) return; } - QString uuid; + QUuid uuid; bool sslEnabled = false; QString serverName; QString version; @@ -177,7 +177,7 @@ void ZeroconfDiscovery::serviceEntryRemoved(const QZeroConfService &entry) sslEnabled = (txtRecord.second == "true"); } if (txtRecord.first == "uuid") { - uuid = txtRecord.second; + uuid = QUuid(txtRecord.second); } if (txtRecord.first == "name") { serverName = txtRecord.second; diff --git a/libnymea-app/connection/nymeaconnection.cpp b/libnymea-app/connection/nymeaconnection.cpp index c0a58997..84f3e53c 100644 --- a/libnymea-app/connection/nymeaconnection.cpp +++ b/libnymea-app/connection/nymeaconnection.cpp @@ -45,21 +45,18 @@ NYMEA_LOGGING_CATEGORY(dcNymeaConnection, "NymeaConnection") NymeaConnection::NymeaConnection(QObject *parent) : QObject(parent) { - m_networkReachabilityMonitor = new NetworkReachabilityMonitor(this); - connect(m_networkReachabilityMonitor, &NetworkReachabilityMonitor::availableBearerTypesChanged, this, &NymeaConnection::availableBearerTypesChanged); - connect(m_networkReachabilityMonitor, &NetworkReachabilityMonitor::availableBearerTypesUpdated, this, &NymeaConnection::onAvailableBearerTypesUpdated); +// m_networkConfigManager = new QNetworkConfigurationManager(this); -#ifdef Q_OS_IOS - connect(m_networkReachabilityMonitor, &NetworkReachabilityMonitor::availableBearerTypesChanged, this, [this](){ - if (m_currentTransport) { - qCInfo(dcNymeaConnection()) << "Available bearer types changed:" << m_networkReachabilityMonitor->availableBearerTypes() << "currently used:" << m_usedBearerType; - if (!m_networkReachabilityMonitor->availableBearerTypes().testFlag(m_usedBearerType)) { - qCInfo(dcNymeaConnection()) << "Used bearer type" << m_usedBearerType << "isn't available any more. Reconnecting."; - m_currentTransport->disconnect(); - } - } - }); -#endif +// QObject::connect(m_networkConfigManager, &QNetworkConfigurationManager::configurationAdded, this, [this](const QNetworkConfiguration &config){ +// Q_UNUSED(config) +// qCDebug(dcNymeaConnection()) << "Network configuration added:" << config.name() << config.bearerTypeName() << config.purpose(); +// updateActiveBearers(); +// }); +// QObject::connect(m_networkConfigManager, &QNetworkConfigurationManager::configurationRemoved, this, [this](const QNetworkConfiguration &config){ +// Q_UNUSED(config) +// qCDebug(dcNymeaConnection()) << "Network configuration removed:" << config.name() << config.bearerTypeName() << config.purpose(); +// updateActiveBearers(); +// }); QGuiApplication *app = static_cast(QGuiApplication::instance()); QObject::connect(app, &QGuiApplication::applicationStateChanged, this, [app, this](Qt::ApplicationState state) { @@ -398,6 +395,39 @@ void NymeaConnection::onDataAvailable(const QByteArray &data) void NymeaConnection::onAvailableBearerTypesUpdated() { + NymeaConnection::BearerTypes availableBearerTypes; +// QList configs = m_networkConfigManager->allConfigurations(QNetworkConfiguration::Active); +// qCDebug(dcNymeaConnection()) << "Network configuations:" << configs.count(); +// foreach (const QNetworkConfiguration &config, configs) { +// qCDebug(dcNymeaConnection()) << "Active network config:" << config.name() << config.bearerTypeFamily() << config.bearerTypeName(); + +// // NOTE: iOS doesn't correctly report bearer types. It'll be Unknown all the time. Let's hardcode it to WiFi for that... +//#if defined(Q_OS_IOS) + availableBearerTypes.setFlag(NymeaConnection::BearerTypeWiFi); +//#else +// availableBearerTypes.setFlag(qBearerTypeToNymeaBearerType(config.bearerType())); +//#endif +// } +// if (availableBearerTypes == NymeaConnection::BearerTypeNone) { +// // This is just debug info... On some platform bearer management seems a bit broken, so let's get some infos right away... +// qCDebug(dcNymeaConnection()) << "No active bearer available. Inactive bearers are:"; +// QList configs = m_networkConfigManager->allConfigurations(); +// foreach (const QNetworkConfiguration &config, configs) { +// qCDebug(dcNymeaConnection()) << "Inactive network config:" << config.name() << config.bearerTypeFamily() << config.bearerTypeName(); +// } + +// qCDebug(dcNymeaConnection()) << "Updating network manager"; +// m_networkConfigManager->updateConfigurations(); +// } + + if (m_availableBearerTypes != availableBearerTypes) { + qCInfo(dcNymeaConnection()) << "Available Bearer Types changed to:" << availableBearerTypes; + m_availableBearerTypes = availableBearerTypes; + emit availableBearerTypesChanged(); + } else { + qCDebug(dcNymeaConnection()) << "Available Bearer Types:" << availableBearerTypes; + } + if (!m_currentHost) { // No host set... Nothing to do... qCInfo(dcNymeaConnection()) << "No current host... Nothing to do..."; @@ -524,6 +554,33 @@ bool NymeaConnection::connectInternal(Connection *connection) return newTransport->connect(connection->url()); } +//NymeaConnection::BearerType NymeaConnection::qBearerTypeToNymeaBearerType(QNetworkConfiguration::BearerType type) const +//{ +// switch (type) { +// case QNetworkConfiguration::BearerUnknown: +// // Unable to determine the connection type. Assume it's something we can establish any connection type on +// return BearerTypeAll; +// case QNetworkConfiguration::BearerEthernet: +// return BearerTypeEthernet; +// case QNetworkConfiguration::BearerWLAN: +// return BearerTypeWiFi; +// case QNetworkConfiguration::Bearer2G: +// case QNetworkConfiguration::BearerCDMA2000: +// case QNetworkConfiguration::BearerWCDMA: +// case QNetworkConfiguration::BearerHSPA: +// case QNetworkConfiguration::BearerWiMAX: +// case QNetworkConfiguration::BearerEVDO: +// case QNetworkConfiguration::BearerLTE: +// case QNetworkConfiguration::Bearer3G: +// case QNetworkConfiguration::Bearer4G: +// return BearerTypeMobileData; +// case QNetworkConfiguration::BearerBluetooth: +// // Note: Do not confuse this with the Bluetooth transport... For Qt, this means IP over BT, not RFCOMM as we do it. +// return BearerTypeNone; +// } +// return BearerTypeAll; +//} + bool NymeaConnection::isConnectionBearerAvailable(Connection::BearerType connectionBearerType) const { switch (connectionBearerType) { diff --git a/libnymea-app/connection/nymeaconnection.h b/libnymea-app/connection/nymeaconnection.h index f805c25f..9a19269c 100644 --- a/libnymea-app/connection/nymeaconnection.h +++ b/libnymea-app/connection/nymeaconnection.h @@ -30,7 +30,7 @@ #include #include #include -#include +//#include #include #include "nymeahost.h" @@ -125,7 +125,8 @@ private: private: ConnectionStatus m_connectionStatus = ConnectionStatusUnconnected; - NetworkReachabilityMonitor *m_networkReachabilityMonitor = nullptr; +// QNetworkConfigurationManager *m_networkConfigManager = nullptr; + NymeaConnection::BearerTypes m_availableBearerTypes = BearerTypeNone; QHash m_transportFactories; QHash m_transportCandidates; diff --git a/libnymea-app/connection/nymeahosts.cpp b/libnymea-app/connection/nymeahosts.cpp index 45e11a17..fcf33920 100644 --- a/libnymea-app/connection/nymeahosts.cpp +++ b/libnymea-app/connection/nymeahosts.cpp @@ -162,138 +162,3 @@ QHash NymeaHosts::roleNames() const roles[VersionRole] = "version"; return roles; } - -NymeaHostsFilterModel::NymeaHostsFilterModel(QObject *parent): - QSortFilterProxyModel(parent) -{ - -} - -NymeaDiscovery *NymeaHostsFilterModel::discovery() const -{ - return m_nymeaDiscovery; -} - -void NymeaHostsFilterModel::setDiscovery(NymeaDiscovery *discovery) -{ - if (m_nymeaDiscovery != discovery) { - m_nymeaDiscovery = discovery; - setSourceModel(discovery->nymeaHosts()); - emit discoveryChanged(); - - connect(discovery->nymeaHosts(), &NymeaHosts::hostChanged, this, [this](){ -// qDebug() << "Host Changed!"; - invalidateFilter(); - emit countChanged(); - }); - - emit countChanged(); - } -} - -JsonRpcClient *NymeaHostsFilterModel::jsonRpcClient() const -{ - return m_jsonRpcClient; -} - -void NymeaHostsFilterModel::setJsonRpcClient(JsonRpcClient *jsonRpcClient) -{ - if (m_jsonRpcClient != jsonRpcClient) { - m_jsonRpcClient = jsonRpcClient; - emit jsonRpcClientChanged(); - - connect(m_jsonRpcClient, &JsonRpcClient::availableBearerTypesChanged, this, [this](){ -// qDebug() << "Bearer Types Changed!"; - invalidateFilter(); - emit countChanged(); - }); - - invalidateFilter(); - emit countChanged(); - } -} - -bool NymeaHostsFilterModel::showUnreachableBearers() const -{ - return m_showUneachableBearers; -} - -void NymeaHostsFilterModel::setShowUnreachableBearers(bool showUnreachableBearers) -{ - if (m_showUneachableBearers != showUnreachableBearers) { - m_showUneachableBearers = showUnreachableBearers; - emit showUnreachableBearersChanged(); - invalidateFilter(); - emit countChanged(); - } -} - -bool NymeaHostsFilterModel::showUnreachableHosts() const -{ - return m_showUneachableHosts; -} - -void NymeaHostsFilterModel::setShowUnreachableHosts(bool showUnreachableHosts) -{ - if (m_showUneachableHosts != showUnreachableHosts) { - m_showUneachableHosts = showUnreachableHosts; - emit showUnreachableHostsChanged(); - invalidateFilter(); - emit countChanged(); - } -} - -NymeaHost *NymeaHostsFilterModel::get(int index) const -{ - return m_nymeaDiscovery->nymeaHosts()->get(mapToSource(this->index(index, 0)).row()); -} - -bool NymeaHostsFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const -{ - Q_UNUSED(sourceParent) - NymeaHost *host = m_nymeaDiscovery->nymeaHosts()->get(sourceRow); - if (m_jsonRpcClient && !m_showUneachableBearers) { - bool hasReachableConnection = false; - for (int i = 0; i < host->connections()->rowCount(); i++) { -// qCritical() << "checking host for available bearer" << host->name() << host->connections()->get(i)->url() << "available bearer types:" << m_jsonRpcClient->availableBearerTypes() << "hosts bearer types" << host->connections()->get(i)->bearerType(); - // Either enable a connection when the Bearer type is directly available - switch (host->connections()->get(i)->bearerType()) { - case Connection::BearerTypeLan: - hasReachableConnection |= m_jsonRpcClient->availableBearerTypes().testFlag(NymeaConnection::BearerTypeEthernet); - hasReachableConnection |= m_jsonRpcClient->availableBearerTypes().testFlag(NymeaConnection::BearerTypeWiFi); - break; - case Connection::BearerTypeWan: - case Connection::BearerTypeCloud: - hasReachableConnection |= m_jsonRpcClient->availableBearerTypes().testFlag(NymeaConnection::BearerTypeEthernet); - hasReachableConnection |= m_jsonRpcClient->availableBearerTypes().testFlag(NymeaConnection::BearerTypeWiFi); - hasReachableConnection |= m_jsonRpcClient->availableBearerTypes().testFlag(NymeaConnection::BearerTypeMobileData); - break; - case Connection::BearerTypeBluetooth: - hasReachableConnection |= m_jsonRpcClient->availableBearerTypes().testFlag(NymeaConnection::BearerTypeBluetooth); - break; - case Connection::BearerTypeUnknown: - case Connection::BearerTypeLoopback: - hasReachableConnection = true; - break; - case Connection::BearerTypeNone: - break; - } - } - if (!hasReachableConnection) { - return false; - } - } - if (!m_showUneachableHosts) { - bool isOnline = false; - for (int i = 0; i < host->connections()->rowCount(); i++) { - if (host->connections()->get(i)->online()) { - isOnline = true; - break; - } - } - if (!isOnline) { - return false; - } - } - return true; -} diff --git a/libnymea-app/connection/nymeahosts.h b/libnymea-app/connection/nymeahosts.h index 725048bb..1ebdb15f 100644 --- a/libnymea-app/connection/nymeahosts.h +++ b/libnymea-app/connection/nymeahosts.h @@ -30,8 +30,6 @@ #include #include #include "nymeahost.h" - -class NymeaDiscovery; class JsonRpcClient; class NymeaHosts : public QAbstractListModel diff --git a/libnymea-app/connection/nymeatransportinterface.h b/libnymea-app/connection/nymeatransportinterface.h index 801bced5..980fd1b6 100644 --- a/libnymea-app/connection/nymeatransportinterface.h +++ b/libnymea-app/connection/nymeatransportinterface.h @@ -28,6 +28,7 @@ #include #include #include +#include class NymeaTransportInterface; diff --git a/libnymea-app/connection/tcpsockettransport.cpp b/libnymea-app/connection/tcpsockettransport.cpp index b7e8b13d..92346ec3 100644 --- a/libnymea-app/connection/tcpsockettransport.cpp +++ b/libnymea-app/connection/tcpsockettransport.cpp @@ -38,8 +38,7 @@ TcpSocketTransport::TcpSocketTransport(QObject *parent) : NymeaTransportInterfac typedef void (QSslSocket:: *sslErrorsSignal)(const QList &); QObject::connect(&m_socket, static_cast(&QSslSocket::sslErrors), this, &TcpSocketTransport::sslErrors); QObject::connect(&m_socket, &QSslSocket::readyRead, this, &TcpSocketTransport::socketReadyRead); - typedef void (QSslSocket:: *errorSignal)(QAbstractSocket::SocketError); - QObject::connect(&m_socket, static_cast(&QSslSocket::error), this, &TcpSocketTransport::error); + QObject::connect(&m_socket, &QSslSocket::errorOccurred, this, &TcpSocketTransport::error); QObject::connect(&m_socket, &QSslSocket::stateChanged, this, &TcpSocketTransport::onSocketStateChanged); } diff --git a/libnymea-app/energy/energymanager.h b/libnymea-app/energy/energymanager.h index cbeda3ad..3366a85f 100644 --- a/libnymea-app/energy/energymanager.h +++ b/libnymea-app/energy/energymanager.h @@ -28,7 +28,7 @@ #include #include -class Engine; +#include "engine.h" class EnergyManager : public QObject { diff --git a/libnymea-app/engine.cpp b/libnymea-app/engine.cpp index 1d42b9aa..10bb3b6a 100644 --- a/libnymea-app/engine.cpp +++ b/libnymea-app/engine.cpp @@ -49,7 +49,19 @@ Engine::Engine(QObject *parent) : connect(m_thingManager, &ThingManager::fetchingDataChanged, this, &Engine::onThingManagerFetchingChanged); connect(m_jsonRpcClient, &JsonRpcClient::connectedChanged, this, [this]() { - qDebug() << "JSONRpc connected changed:" << m_jsonRpcClient->connected(); + qDebug() << "JSONRpc connected changed:" << m_jsonRpcClient->connected() << "AWS status:" << AWSClient::instance()->awsDevices()->rowCount(); + if (m_jsonRpcClient->connected() && m_jsonRpcClient->cloudConnectionState() == JsonRpcClient::CloudConnectionStateConnected) { + if (AWSClient::instance()->awsDevices()->getDevice(m_jsonRpcClient->serverUuid().toString()) == nullptr) { + m_jsonRpcClient->setupRemoteAccess(AWSClient::instance()->idToken(), AWSClient::instance()->userId()); + } + } + }); + connect(m_jsonRpcClient, &JsonRpcClient::cloudConnectionStateChanged, this, [this](){ + if (m_jsonRpcClient->connected() && m_jsonRpcClient->cloudConnectionState() == JsonRpcClient::CloudConnectionStateConnected) { + if (AWSClient::instance()->awsDevices()->getDevice(m_jsonRpcClient->serverUuid().toString()) == nullptr) { + m_jsonRpcClient->setupRemoteAccess(AWSClient::instance()->idToken(), AWSClient::instance()->userId()); + } + } }); } @@ -93,6 +105,22 @@ SystemController *Engine::systemController() const return m_systemController; } +void Engine::deployCertificate() +{ + if (!m_jsonRpcClient->connected()) { + qWarning() << "JSONRPC not connected. Cannot deploy certificate"; + return; + } + if (!AWSClient::instance()->isLoggedIn()) { + qWarning() << "Not logged in at AWS. Cannot deploy certificate"; + return; + } + AWSClient::instance()->fetchCertificate(m_jsonRpcClient->serverUuid().toString(), [this](const QByteArray &rootCA, const QByteArray &certificate, const QByteArray &publicKey, const QByteArray &privateKey, const QString &endpoint){ + qDebug() << "Certificate received" << certificate << publicKey << privateKey; + m_jsonRpcClient->deployCertificate(rootCA, certificate, publicKey, privateKey, endpoint); + }); +} + void Engine::onConnectedChanged() { qDebug() << "Engine: connected changed:" << m_jsonRpcClient->connected(); diff --git a/libnymea-app/engine.h b/libnymea-app/engine.h index ce0a4b22..6f551c46 100644 --- a/libnymea-app/engine.h +++ b/libnymea-app/engine.h @@ -31,13 +31,12 @@ #include "connection/nymeatransportinterface.h" #include "jsonrpc/jsonrpcclient.h" -class RuleManager; -class ScriptManager; -class LogManager; -class TagsManager; -class NymeaConfiguration; -class SystemController; -class NetworkManager; +#include "rulemanager.h" +#include "scriptmanager.h" +#include "logmanager.h" +#include "tagsmanager.h" +#include "configuration/nymeaconfiguration.h" +#include "system/systemcontroller.h" class Engine : public QObject { @@ -78,4 +77,6 @@ private slots: }; +Q_DECLARE_METATYPE(Engine*) + #endif // ENGINE_H diff --git a/libnymea-app/interfacesmodel.h b/libnymea-app/interfacesmodel.h index fe2a6f8e..cd7d20e3 100644 --- a/libnymea-app/interfacesmodel.h +++ b/libnymea-app/interfacesmodel.h @@ -29,9 +29,8 @@ #include #include "things.h" - -class Engine; -class ThingsProxy; +#include "engine.h" +#include "thingsproxy.h" class InterfacesModel : public QAbstractListModel { diff --git a/libnymea-app/jsonrpc/jsonrpcclient.cpp b/libnymea-app/jsonrpc/jsonrpcclient.cpp index b50efae8..9dcbf913 100644 --- a/libnymea-app/jsonrpc/jsonrpcclient.cpp +++ b/libnymea-app/jsonrpc/jsonrpcclient.cpp @@ -153,7 +153,7 @@ void JsonRpcClient::disconnectFromHost() m_connection->disconnectFromHost(); } -void JsonRpcClient::acceptCertificate(const QString &serverUuid, const QByteArray &pem) +void JsonRpcClient::acceptCertificate(const QUuid &serverUuid, const QByteArray &pem) { qDebug() << "Pinning new certificate for" << serverUuid << pem; storePem(serverUuid, pem); @@ -199,7 +199,7 @@ void JsonRpcClient::notificationReceived(const QVariantMap &data) m_token = data.value("params").toMap().value("token").toByteArray(); QSettings settings; settings.beginGroup("jsonTokens"); - settings.setValue(m_connection->currentHost()->uuid().toString(), m_token); + settings.setValue(m_serverUuid.toString(), m_token); settings.endGroup(); m_initialSetupRequired = false; @@ -305,7 +305,7 @@ QString JsonRpcClient::jsonRpcVersion() const return m_jsonRpcVersion.toString(); } -QString JsonRpcClient::serverUuid() const +QUuid JsonRpcClient::serverUuid() const { return m_connection && m_connection->currentHost() ? m_connection->currentHost()->uuid().toString() : ""; } @@ -394,7 +394,7 @@ void JsonRpcClient::processAuthenticate(int /*commandId*/, const QVariantMap &da emit permissionsChanged(); QSettings settings; settings.beginGroup("jsonTokens"); - settings.setValue(m_connection->currentHost()->uuid().toString(), m_token); + settings.setValue(m_serverUuid.toString(), m_token); settings.endGroup(); emit authenticationRequiredChanged(); @@ -481,8 +481,8 @@ void JsonRpcClient::sendRequest(const QVariantMap &request) bool JsonRpcClient::loadPem(const QUuid &serverUud, QByteArray &pem) { - QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/sslcerts/"); - QFile certFile(dir.absoluteFilePath(serverUud.toString().remove(QRegExp("[{}]")) + ".pem")); + QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/sslcerts/"); + QFile certFile(dir.absoluteFilePath(serverUud.toString().remove(QRegularExpression("[{}]")) + ".pem")); if (!certFile.open(QFile::ReadOnly)) { return false; } @@ -493,11 +493,11 @@ bool JsonRpcClient::loadPem(const QUuid &serverUud, QByteArray &pem) bool JsonRpcClient::storePem(const QUuid &serverUuid, const QByteArray &pem) { - QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/sslcerts/"); + QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/sslcerts/"); if (!dir.exists()) { - dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/sslcerts/"); + dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/sslcerts/"); } - QFile certFile(dir.absoluteFilePath(serverUuid.toString().remove(QRegExp("[{}]")) + ".pem")); + QFile certFile(dir.absoluteFilePath(serverUuid.toString().remove(QRegularExpression("[{}]")) + ".pem")); if (!certFile.open(QFile::WriteOnly | QFile::Truncate)) { return false; } @@ -600,7 +600,7 @@ void JsonRpcClient::dataReceived(const QByteArray &data) m_token.clear(); QSettings settings; settings.beginGroup("jsonTokens"); - settings.setValue(serverUuid(), m_token); + settings.setValue(m_serverUuid.toString(), m_token); settings.endGroup(); emit authenticationRequiredChanged(); m_authenticated = false; @@ -651,6 +651,7 @@ void JsonRpcClient::helloReply(int /*commandId*/, const QVariantMap ¶ms) m_pushButtonAuthAvailable = params.value("pushButtonAuthAvailable").toBool(); emit pushButtonAuthAvailableChanged(); + m_serverUuid = params.value("uuid").toUuid(); m_serverVersion = params.value("version").toString(); QUuid serverUuid = params.value("uuid").toUuid(); QString name = params.value("name").toString(); @@ -721,7 +722,7 @@ void JsonRpcClient::helloReply(int /*commandId*/, const QVariantMap ¶ms) // Reject the connection until the UI explicitly accepts this... m_connection->disconnectFromHost(); - emit verifyConnectionCertificate(serverUuid.toString(), issuerInfo, certificate.toPem()); + emit verifyConnectionCertificate(m_serverUuid.toString(), issuerInfo, certificate.toPem()); return; } qCInfo(dcJsonRpc()) << "This connections certificate is trusted."; @@ -769,7 +770,7 @@ void JsonRpcClient::helloReply(int /*commandId*/, const QVariantMap ¶ms) // Reload the token, now that we're certain about the server uuid. QSettings settings; settings.beginGroup("jsonTokens"); - m_token = settings.value(serverUuid.toString()).toByteArray(); + m_token = settings.value(m_serverUuid.toString()).toByteArray(); settings.endGroup(); emit authenticationRequiredChanged(); diff --git a/libnymea-app/jsonrpc/jsonrpcclient.h b/libnymea-app/jsonrpc/jsonrpcclient.h index 4b9fbf9e..9cd4cabd 100644 --- a/libnymea-app/jsonrpc/jsonrpcclient.h +++ b/libnymea-app/jsonrpc/jsonrpcclient.h @@ -51,7 +51,7 @@ class JsonRpcClient : public QObject Q_PROPERTY(bool authenticated READ authenticated NOTIFY authenticatedChanged) Q_PROPERTY(QString serverVersion READ serverVersion NOTIFY handshakeReceived) Q_PROPERTY(QString jsonRpcVersion READ jsonRpcVersion NOTIFY handshakeReceived) - Q_PROPERTY(QString serverUuid READ serverUuid NOTIFY handshakeReceived) + Q_PROPERTY(QUuid serverUuid READ serverUuid NOTIFY handshakeReceived) Q_PROPERTY(QString serverName READ serverName NOTIFY serverNameChanged) Q_PROPERTY(QString serverQtVersion READ serverQtVersion NOTIFY serverQtVersionChanged) Q_PROPERTY(QString serverQtBuildVersion READ serverQtBuildVersion NOTIFY serverQtVersionChanged) @@ -85,7 +85,7 @@ public: QString serverVersion() const; QString jsonRpcVersion() const; - QString serverUuid() const; + QUuid serverUuid() const; QString serverName() const; QString serverQtVersion(); QString serverQtBuildVersion(); @@ -94,7 +94,7 @@ public: // ui methods Q_INVOKABLE void connectToHost(NymeaHost *host, Connection *connection = nullptr); Q_INVOKABLE void disconnectFromHost(); - Q_INVOKABLE void acceptCertificate(const QString &serverUuid, const QByteArray &pem); + Q_INVOKABLE void acceptCertificate(const QUuid &serverUuid, const QByteArray &pem); Q_INVOKABLE bool tokenExists(const QString &serverUuid) const; Q_INVOKABLE void addToken(const QString &serverUuid, const QByteArray &token); @@ -154,6 +154,7 @@ private: bool m_pushButtonAuthAvailable = false; bool m_authenticated = false; int m_pendingPushButtonTransaction = -1; + QUuid m_serverUuid; QVersionNumber m_jsonRpcVersion; QString m_serverVersion; QString m_serverQtVersion; diff --git a/libnymea-app/libnymea-app-core.h b/libnymea-app/libnymea-app-core.h index 64761ecc..cbc0ae1f 100644 --- a/libnymea-app/libnymea-app-core.h +++ b/libnymea-app/libnymea-app-core.h @@ -28,6 +28,7 @@ #include "engine.h" #include "connection/nymeahosts.h" #include "connection/nymeahost.h" +#include "models/nymeahostsfiltermodel.h" #include "connection/discovery/nymeadiscovery.h" #include "vendorsproxy.h" #include "thingclassesproxy.h" diff --git a/libnymea-app/libnymea-app.pri b/libnymea-app/libnymea-app.pri index f293f761..72ff5352 100644 --- a/libnymea-app/libnymea-app.pri +++ b/libnymea-app/libnymea-app.pri @@ -30,6 +30,7 @@ SOURCES += \ $$PWD/models/boolseriesadapter.cpp \ $$PWD/models/newlogentry.cpp \ $$PWD/models/newlogsmodel.cpp \ + $$PWD/models/nymeahostsfiltermodel.cpp \ $$PWD/models/scriptsproxymodel.cpp \ $$PWD/pluginconfigmanager.cpp \ $$PWD/serverdebug/serverdebugmanager.cpp \ @@ -199,6 +200,7 @@ HEADERS += \ $$PWD/models/boolseriesadapter.h \ $$PWD/models/newlogentry.h \ $$PWD/models/newlogsmodel.h \ + $$PWD/models/nymeahostsfiltermodel.h \ $$PWD/models/scriptsproxymodel.h \ $$PWD/pluginconfigmanager.h \ $$PWD/serverdebug/serverdebugmanager.h \ diff --git a/libnymea-app/modbus/modbusrtumanager.cpp b/libnymea-app/modbus/modbusrtumanager.cpp index 0ba1246b..aed595ac 100644 --- a/libnymea-app/modbus/modbusrtumanager.cpp +++ b/libnymea-app/modbus/modbusrtumanager.cpp @@ -148,7 +148,7 @@ ModbusRtuMaster *ModbusRtuManager::unpackModbusRtuMaster(const QVariantMap &modb void ModbusRtuManager::notificationReceived(const QVariantMap ¬ification) { QString notificationString = notification.value("notification").toString(); - qDebug() << "Received notification" << notificationString << endl << notification; + qDebug() << "Received notification" << notificationString << Qt::endl << notification; if (notificationString == "ModbusRtu.SerialPortAdded") { QVariantMap serialPortMap = notification.value("params").toMap().value("serialPort").toMap(); m_serialPorts->addSerialPort(SerialPort::unpackSerialPort(serialPortMap, m_serialPorts)); diff --git a/libnymea-app/modbus/modbusrtumanager.h b/libnymea-app/modbus/modbusrtumanager.h index 637a98df..4e64e8d9 100644 --- a/libnymea-app/modbus/modbusrtumanager.h +++ b/libnymea-app/modbus/modbusrtumanager.h @@ -29,10 +29,10 @@ #include "types/serialports.h" -class Engine; -class JsonRpcClient; +#include "engine.h" +#include "modbusrtumasters.h" + class ModbusRtuMaster; -class ModbusRtuMasters; class ModbusRtuManager : public QObject { diff --git a/libnymea-app/models/barseriesadapter.cpp b/libnymea-app/models/barseriesadapter.cpp index d7a6e17d..801e7b78 100644 --- a/libnymea-app/models/barseriesadapter.cpp +++ b/libnymea-app/models/barseriesadapter.cpp @@ -46,12 +46,12 @@ void BarSeriesAdapter::setLogsModel(LogsModel *logsModel) } } -QtCharts::QAbstractBarSeries *BarSeriesAdapter::barSeries() const +QAbstractBarSeries *BarSeriesAdapter::barSeries() const { return m_barSeries; } -void BarSeriesAdapter::setBarSeries(QtCharts::QAbstractBarSeries *barSeries) +void BarSeriesAdapter::setBarSeries(QAbstractBarSeries *barSeries) { if (m_barSeries != barSeries) { m_barSeries = barSeries; @@ -78,7 +78,7 @@ void BarSeriesAdapter::update() if (!m_barSeries || !m_logsModel) { return; } - m_set = new QtCharts::QBarSet(m_barSeries->name()); + m_set = new QBarSet(m_barSeries->name()); m_barSeries->append(m_set); for (int i = 0; i < m_logsModel->rowCount(); i++) { diff --git a/libnymea-app/models/barseriesadapter.h b/libnymea-app/models/barseriesadapter.h index 18ee35bf..dd9027eb 100644 --- a/libnymea-app/models/barseriesadapter.h +++ b/libnymea-app/models/barseriesadapter.h @@ -31,11 +31,15 @@ #include #include +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +using namespace QtCharts; +#endif + class BarSeriesAdapter : public QObject { Q_OBJECT Q_PROPERTY(LogsModel* logsModel READ logsModel WRITE setLogsModel NOTIFY logsModelChanged) - Q_PROPERTY(QtCharts::QAbstractBarSeries* barSeries READ barSeries WRITE setBarSeries NOTIFY barSeriesChanged) + Q_PROPERTY(QAbstractBarSeries* barSeries READ barSeries WRITE setBarSeries NOTIFY barSeriesChanged) Q_PROPERTY(Interval interval READ interval WRITE setInterval NOTIFY intervalChanged) @@ -52,8 +56,8 @@ public: LogsModel *logsModel() const; void setLogsModel(LogsModel *logsModel); - QtCharts::QAbstractBarSeries *barSeries() const; - void setBarSeries(QtCharts::QAbstractBarSeries *barSeries); + QAbstractBarSeries *barSeries() const; + void setBarSeries(QAbstractBarSeries *barSeries); Interval interval() const; void setInterval(Interval interval); @@ -80,8 +84,8 @@ private: }; LogsModel *m_logsModel = nullptr; - QtCharts::QAbstractBarSeries *m_barSeries = nullptr; - QtCharts::QBarSet *m_set = nullptr; + QAbstractBarSeries *m_barSeries = nullptr; + QBarSet *m_set = nullptr; Interval m_interval = IntervalMinutes; QList m_timeslots; diff --git a/libnymea-app/models/interfacesproxy.h b/libnymea-app/models/interfacesproxy.h index 1ee4f3af..559d6474 100644 --- a/libnymea-app/models/interfacesproxy.h +++ b/libnymea-app/models/interfacesproxy.h @@ -27,8 +27,8 @@ #include -class Things; -class ThingsProxy; +#include "things.h" +#include "thingsproxy.h" class Interface; class Interfaces; diff --git a/libnymea-app/models/logsmodel.cpp b/libnymea-app/models/logsmodel.cpp index 26232259..5e017103 100644 --- a/libnymea-app/models/logsmodel.cpp +++ b/libnymea-app/models/logsmodel.cpp @@ -312,8 +312,8 @@ void LogsModel::logsReply(int /*commandId*/, const QVariantMap &data) foreach (const QVariant &logEntryVariant, logEntries) { QVariantMap entryMap = logEntryVariant.toMap(); QDateTime timeStamp = QDateTime::fromMSecsSinceEpoch(entryMap.value("timestamp").toLongLong()); - QString thingId = entryMap.value("thingId").toString(); - QString typeId = entryMap.value("typeId").toString(); + QUuid thingId = entryMap.value("thingId").toUuid(); + QUuid typeId = entryMap.value("typeId").toUuid(); QMetaEnum sourceEnum = QMetaEnum::fromType(); LogEntry::LoggingSource loggingSource = static_cast(sourceEnum.keyToValue(entryMap.value("source").toByteArray())); QMetaEnum loggingEventTypeEnum = QMetaEnum::fromType(); diff --git a/libnymea-app/models/logsmodel.h b/libnymea-app/models/logsmodel.h index 2f9495fa..d3180820 100644 --- a/libnymea-app/models/logsmodel.h +++ b/libnymea-app/models/logsmodel.h @@ -29,12 +29,11 @@ #include #include "types/logentry.h" +#include "engine.h" #include Q_DECLARE_LOGGING_CATEGORY(dcLogEngine) -class Engine; - class LogsModel : public QAbstractListModel, public QQmlParserStatus { Q_OBJECT diff --git a/libnymea-app/models/logsmodelng.cpp b/libnymea-app/models/logsmodelng.cpp index 6723bdec..419015f9 100644 --- a/libnymea-app/models/logsmodelng.cpp +++ b/libnymea-app/models/logsmodelng.cpp @@ -194,12 +194,12 @@ void LogsModelNg::setEndTime(const QDateTime &endTime) } } -QtCharts::QXYSeries *LogsModelNg::graphSeries() const +QXYSeries *LogsModelNg::graphSeries() const { return m_graphSeries; } -void LogsModelNg::setGraphSeries(QtCharts::QXYSeries *graphSeries) +void LogsModelNg::setGraphSeries(QXYSeries *graphSeries) { m_graphSeries = graphSeries; } @@ -315,8 +315,8 @@ void LogsModelNg::logsReply(int commandId, const QVariantMap &data) foreach (const QVariant &logEntryVariant, logEntries) { QVariantMap entryMap = logEntryVariant.toMap(); QDateTime timeStamp = QDateTime::fromMSecsSinceEpoch(entryMap.value("timestamp").toLongLong()); - QString thingId = entryMap.value("thingId").toString(); - QString typeId = entryMap.value("typeId").toString(); + QUuid thingId = entryMap.value("thingId").toUuid(); + QUuid typeId = entryMap.value("typeId").toUuid(); QMetaEnum sourceEnum = QMetaEnum::fromType(); LogEntry::LoggingSource loggingSource = static_cast(sourceEnum.keyToValue(entryMap.value("source").toByteArray())); QMetaEnum loggingEventTypeEnum = QMetaEnum::fromType(); @@ -382,10 +382,10 @@ void LogsModelNg::logsReply(int commandId, const QVariantMap &data) } // Adjust min/max - if (!newMin.isValid() || newMin > entry->value()) { + if (!newMin.isValid() || newMin.toDouble() > entry->value().toDouble()) { newMin = 0; } - if (!newMax.isValid() || newMax < entry->value()) { + if (!newMax.isValid() || newMax .toDouble() < entry->value().toDouble()) { newMax = 1; } @@ -401,10 +401,10 @@ void LogsModelNg::logsReply(int commandId, const QVariantMap &data) m_graphSeries->append(QPointF(entry->timestamp().toMSecsSinceEpoch(), value.toReal())); // Adjust min/max - if (!newMin.isValid() || newMin > value) { + if (!newMin.isValid() || newMin.toDouble() > value.toDouble()) { newMin = value.toReal(); } - if (!newMax.isValid() || newMax < value) { + if (!newMax.isValid() || newMax.toDouble() < value.toDouble()) { newMax = value.toReal(); } } @@ -566,11 +566,11 @@ void LogsModelNg::newLogEntryReceived(const QVariantMap &data) } - if (m_minValue > entry->value().toReal()) { + if (m_minValue.toReal() > entry->value().toReal()) { m_minValue = entry->value().toReal(); emit minValueChanged(); } - if (m_maxValue < entry->value().toReal()) { + if (m_maxValue.toReal() < entry->value().toReal()) { m_maxValue = entry->value().toReal(); emit maxValueChanged(); } diff --git a/libnymea-app/models/logsmodelng.h b/libnymea-app/models/logsmodelng.h index 453b63e3..45dcccf5 100644 --- a/libnymea-app/models/logsmodelng.h +++ b/libnymea-app/models/logsmodelng.h @@ -32,8 +32,13 @@ #include #include +#include "engine.h" + class LogEntry; -class Engine; + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +using namespace QtCharts; +#endif class LogsModelNg : public QAbstractListModel, public QQmlParserStatus { @@ -50,7 +55,7 @@ class LogsModelNg : public QAbstractListModel, public QQmlParserStatus Q_PROPERTY(QVariant minValue READ minValue NOTIFY minValueChanged) Q_PROPERTY(QVariant maxValue READ maxValue NOTIFY maxValueChanged) - Q_PROPERTY(QtCharts::QXYSeries *graphSeries READ graphSeries WRITE setGraphSeries NOTIFY graphSeriesChanged) + Q_PROPERTY(QXYSeries *graphSeries READ graphSeries WRITE setGraphSeries NOTIFY graphSeriesChanged) Q_PROPERTY(QDateTime viewStartTime READ viewStartTime WRITE setViewStartTime NOTIFY viewStartTimeChanged) public: @@ -91,8 +96,8 @@ public: QDateTime endTime() const; void setEndTime(const QDateTime &endTime); - QtCharts::QXYSeries *graphSeries() const; - void setGraphSeries(QtCharts::QXYSeries *lineSeries); + QXYSeries *graphSeries() const; + void setGraphSeries(QXYSeries *lineSeries); QDateTime viewStartTime() const; void setViewStartTime(const QDateTime &viewStartTime); @@ -142,7 +147,7 @@ private: QVariant m_maxValue; bool m_ready = false; - QtCharts::QXYSeries *m_graphSeries = nullptr; + QXYSeries *m_graphSeries = nullptr; QList > m_fetchedPeriods; }; diff --git a/libnymea-app/models/nymeahostsfiltermodel.cpp b/libnymea-app/models/nymeahostsfiltermodel.cpp new file mode 100644 index 00000000..a26dd6e8 --- /dev/null +++ b/libnymea-app/models/nymeahostsfiltermodel.cpp @@ -0,0 +1,138 @@ +#include "nymeahostsfiltermodel.h" + +#include "jsonrpc/jsonrpcclient.h" + +NymeaHostsFilterModel::NymeaHostsFilterModel(QObject *parent): + QSortFilterProxyModel(parent) +{ + +} + +NymeaDiscovery *NymeaHostsFilterModel::discovery() const +{ + return m_nymeaDiscovery; +} + +void NymeaHostsFilterModel::setDiscovery(NymeaDiscovery *discovery) +{ + if (m_nymeaDiscovery != discovery) { + m_nymeaDiscovery = discovery; + setSourceModel(discovery->nymeaHosts()); + emit discoveryChanged(); + + connect(discovery->nymeaHosts(), &NymeaHosts::hostChanged, this, [this](){ +// qDebug() << "Host Changed!"; + invalidateFilter(); + emit countChanged(); + }); + + emit countChanged(); + } +} + +JsonRpcClient *NymeaHostsFilterModel::jsonRpcClient() const +{ + return m_jsonRpcClient; +} + +void NymeaHostsFilterModel::setJsonRpcClient(JsonRpcClient *jsonRpcClient) +{ + if (m_jsonRpcClient != jsonRpcClient) { + m_jsonRpcClient = jsonRpcClient; + emit jsonRpcClientChanged(); + + connect(m_jsonRpcClient, &JsonRpcClient::availableBearerTypesChanged, this, [this](){ +// qDebug() << "Bearer Types Changed!"; + invalidateFilter(); + emit countChanged(); + }); + + invalidateFilter(); + emit countChanged(); + } +} + +bool NymeaHostsFilterModel::showUnreachableBearers() const +{ + return m_showUneachableBearers; +} + +void NymeaHostsFilterModel::setShowUnreachableBearers(bool showUnreachableBearers) +{ + if (m_showUneachableBearers != showUnreachableBearers) { + m_showUneachableBearers = showUnreachableBearers; + emit showUnreachableBearersChanged(); + invalidateFilter(); + emit countChanged(); + } +} + +bool NymeaHostsFilterModel::showUnreachableHosts() const +{ + return m_showUneachableHosts; +} + +void NymeaHostsFilterModel::setShowUnreachableHosts(bool showUnreachableHosts) +{ + if (m_showUneachableHosts != showUnreachableHosts) { + m_showUneachableHosts = showUnreachableHosts; + emit showUnreachableHostsChanged(); + invalidateFilter(); + emit countChanged(); + } +} + +NymeaHost *NymeaHostsFilterModel::get(int index) const +{ + return m_nymeaDiscovery->nymeaHosts()->get(mapToSource(this->index(index, 0)).row()); +} + +bool NymeaHostsFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +{ + Q_UNUSED(sourceParent) + NymeaHost *host = m_nymeaDiscovery->nymeaHosts()->get(sourceRow); + if (m_jsonRpcClient && !m_showUneachableBearers) { + bool hasReachableConnection = false; + for (int i = 0; i < host->connections()->rowCount(); i++) { +// qDebug() << "checking host for available bearer" << host->name() << host->connections()->get(i)->url() << "available bearer types:" << m_nymeaConnection->availableBearerTypes() << "hosts bearer types" << host->connections()->get(i)->bearerType(); + // Either enable a connection when the Bearer type is directly available + switch (host->connections()->get(i)->bearerType()) { + case Connection::BearerTypeLan: + hasReachableConnection |= m_jsonRpcClient->availableBearerTypes().testFlag(NymeaConnection::BearerTypeEthernet); + hasReachableConnection |= m_jsonRpcClient->availableBearerTypes().testFlag(NymeaConnection::BearerTypeWiFi); + break; + case Connection::BearerTypeWan: + case Connection::BearerTypeCloud: + hasReachableConnection |= m_jsonRpcClient->availableBearerTypes().testFlag(NymeaConnection::BearerTypeEthernet); + hasReachableConnection |= m_jsonRpcClient->availableBearerTypes().testFlag(NymeaConnection::BearerTypeWiFi); + hasReachableConnection |= m_jsonRpcClient->availableBearerTypes().testFlag(NymeaConnection::BearerTypeMobileData); + break; + case Connection::BearerTypeBluetooth: + hasReachableConnection |= m_jsonRpcClient->availableBearerTypes().testFlag(NymeaConnection::BearerTypeBluetooth); + break; + case Connection::BearerTypeUnknown: + case Connection::BearerTypeLoopback: + hasReachableConnection = true; + break; + case Connection::BearerTypeNone: + break; + } + } + if (!hasReachableConnection) { + return false; + } + } + if (!m_showUneachableHosts) { + bool isOnline = false; + for (int i = 0; i < host->connections()->rowCount(); i++) { + if (host->connections()->get(i)->online()) { + isOnline = true; + break; + } + } + if (!isOnline) { + return false; + } + } + return true; +} diff --git a/libnymea-app/models/nymeahostsfiltermodel.h b/libnymea-app/models/nymeahostsfiltermodel.h new file mode 100644 index 00000000..18f800b4 --- /dev/null +++ b/libnymea-app/models/nymeahostsfiltermodel.h @@ -0,0 +1,54 @@ +#ifndef NYMEAHOSTSFILTERMODEL_H +#define NYMEAHOSTSFILTERMODEL_H + +#include + +#include "connection/discovery/nymeadiscovery.h" +#include "jsonrpc/jsonrpcclient.h" + +class NymeaHostsFilterModel: public QSortFilterProxyModel +{ + Q_OBJECT + Q_PROPERTY(int count READ rowCount NOTIFY countChanged) + Q_PROPERTY(NymeaDiscovery* discovery READ discovery WRITE setDiscovery NOTIFY discoveryChanged) + Q_PROPERTY(JsonRpcClient* jsonRpcClient READ jsonRpcClient WRITE setJsonRpcClient NOTIFY jsonRpcClientChanged) + Q_PROPERTY(bool showUnreachableBearers READ showUnreachableBearers WRITE setShowUnreachableBearers NOTIFY showUnreachableBearersChanged) + Q_PROPERTY(bool showUnreachableHosts READ showUnreachableHosts WRITE setShowUnreachableHosts NOTIFY showUnreachableHostsChanged) + +public: + NymeaHostsFilterModel(QObject *parent = nullptr); + + NymeaDiscovery* discovery() const; + void setDiscovery(NymeaDiscovery *discovery); + + JsonRpcClient* jsonRpcClient() const; + void setJsonRpcClient(JsonRpcClient* jsonRpcClient); + + bool showUnreachableBearers() const; + void setShowUnreachableBearers(bool showUnreachableBearers); + + bool showUnreachableHosts() const; + void setShowUnreachableHosts(bool showUnreachableHosts); + + Q_INVOKABLE NymeaHost* get(int index) const; + +signals: + void countChanged(); + void discoveryChanged(); + void jsonRpcClientChanged(); + void showUnreachableBearersChanged(); + void showUnreachableHostsChanged(); + +protected: + bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; + +private: + NymeaDiscovery *m_nymeaDiscovery = nullptr; + JsonRpcClient *m_jsonRpcClient = nullptr; + + bool m_showUneachableBearers = false; + bool m_showUneachableHosts = false; + +}; + +#endif // NYMEAHOSTSFILTERMODEL_H diff --git a/libnymea-app/models/rulesfiltermodel.h b/libnymea-app/models/rulesfiltermodel.h index 60087851..bf38a248 100644 --- a/libnymea-app/models/rulesfiltermodel.h +++ b/libnymea-app/models/rulesfiltermodel.h @@ -28,8 +28,7 @@ #include #include -class Rules; -class Rule; +#include "types/rules.h" class RulesFilterModel : public QSortFilterProxyModel { diff --git a/libnymea-app/models/sortfilterproxymodel.cpp b/libnymea-app/models/sortfilterproxymodel.cpp index 0e8eba50..7d5fb7f6 100644 --- a/libnymea-app/models/sortfilterproxymodel.cpp +++ b/libnymea-app/models/sortfilterproxymodel.cpp @@ -117,5 +117,5 @@ bool SortFilterProxyModel::lessThan(const QModelIndex &source_left, const QModel QVariant left = sourceModel()->data(source_left, sortRole); QVariant right = sourceModel()->data(source_right, sortRole); - return left <= right; + return left.toString() <= right.toString(); } diff --git a/libnymea-app/models/taglistmodel.h b/libnymea-app/models/taglistmodel.h index 5b93aff2..fba85a21 100644 --- a/libnymea-app/models/taglistmodel.h +++ b/libnymea-app/models/taglistmodel.h @@ -28,7 +28,7 @@ #include #include -class TagsProxyModel; +#include "tagsproxymodel.h" class Tag; class TagListModel : public QAbstractListModel diff --git a/libnymea-app/models/tagsproxymodel.cpp b/libnymea-app/models/tagsproxymodel.cpp index 366d7329..a8d10ae9 100644 --- a/libnymea-app/models/tagsproxymodel.cpp +++ b/libnymea-app/models/tagsproxymodel.cpp @@ -144,8 +144,8 @@ bool TagsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_ qCDebug(dcTags) << "Filtering tag. ID:" << tag->tagId() << "Thing:" << tag->thingId() << "Value:" << tag->value(); qCDebug(dcTags) << "Filter: ID:" << m_filterTagId << "Thing:" << m_filterThingId << "value:" << m_filterValue; if (!m_filterTagId.isEmpty()) { - QRegExp exp(m_filterTagId); - if (!exp.exactMatch(tag->tagId())) { + QRegularExpression exp(m_filterTagId); + if (exp.match(tag->tagId()).hasMatch()) { return false; } } diff --git a/libnymea-app/models/tagsproxymodel.h b/libnymea-app/models/tagsproxymodel.h index a7476dfe..86c2d6b4 100644 --- a/libnymea-app/models/tagsproxymodel.h +++ b/libnymea-app/models/tagsproxymodel.h @@ -28,8 +28,7 @@ #include #include -class Tag; -class Tags; +#include "types/tags.h" class TagsProxyModel : public QSortFilterProxyModel { diff --git a/libnymea-app/models/wirelessaccesspointsproxy.h b/libnymea-app/models/wirelessaccesspointsproxy.h index 6c21ed74..b8eb4135 100644 --- a/libnymea-app/models/wirelessaccesspointsproxy.h +++ b/libnymea-app/models/wirelessaccesspointsproxy.h @@ -28,8 +28,7 @@ #include #include -class WirelessAccessPoint; -class WirelessAccessPoints; +#include "types/wirelessaccesspoints.h" class WirelessAccessPointsProxy : public QSortFilterProxyModel { diff --git a/libnymea-app/models/xyseriesadapter.cpp b/libnymea-app/models/xyseriesadapter.cpp index 864a1a15..65924925 100644 --- a/libnymea-app/models/xyseriesadapter.cpp +++ b/libnymea-app/models/xyseriesadapter.cpp @@ -49,12 +49,12 @@ void XYSeriesAdapter::setLogsModel(LogsModel *logsModel) } } -QtCharts::QXYSeries *XYSeriesAdapter::xySeries() const +QXYSeries *XYSeriesAdapter::xySeries() const { return m_series; } -void XYSeriesAdapter::setXySeries(QtCharts::QXYSeries *series) +void XYSeriesAdapter::setXySeries(QXYSeries *series) { if (m_series != series) { m_series = series; @@ -64,18 +64,18 @@ void XYSeriesAdapter::setXySeries(QtCharts::QXYSeries *series) } } -QtCharts::QXYSeries *XYSeriesAdapter::baseSeries() const +QXYSeries *XYSeriesAdapter::baseSeries() const { return m_baseSeries; } -void XYSeriesAdapter::setBaseSeries(QtCharts::QXYSeries *series) +void XYSeriesAdapter::setBaseSeries(QXYSeries *series) { if (m_baseSeries != series) { m_baseSeries = series; emit baseSeriesChanged(); - connect(m_baseSeries, &QtCharts::QXYSeries::pointAdded, this, [=](int index){ + connect(m_baseSeries, &QXYSeries::pointAdded, this, [=](int index){ if (m_series->count() > index) { qreal value = calculateSampleValue(index); m_series->replace(index, m_series->at(index).x(), value); @@ -91,7 +91,7 @@ void XYSeriesAdapter::setBaseSeries(QtCharts::QXYSeries *series) } } }); - connect(m_baseSeries, &QtCharts::QXYSeries::pointReplaced, this, [=](int index){ + connect(m_baseSeries, &QXYSeries::pointReplaced, this, [=](int index){ if (m_series->count() > index) { qreal value = calculateSampleValue(index); m_series->replace(index, m_series->at(index).x(), value); diff --git a/libnymea-app/models/xyseriesadapter.h b/libnymea-app/models/xyseriesadapter.h index bd14701e..0604c9d5 100644 --- a/libnymea-app/models/xyseriesadapter.h +++ b/libnymea-app/models/xyseriesadapter.h @@ -30,12 +30,16 @@ #include #include +#if QT_VERSION < QT_VERSION_CHECK(6, 0 ,0) +using namespace QtCharts; +#endif + class XYSeriesAdapter : public QObject { Q_OBJECT Q_PROPERTY(LogsModel* logsModel READ logsModel WRITE setLogsModel NOTIFY logsModelChanged) - Q_PROPERTY(QtCharts::QXYSeries* xySeries READ xySeries WRITE setXySeries NOTIFY xySeriesChanged) - Q_PROPERTY(QtCharts::QXYSeries* baseSeries READ baseSeries WRITE setBaseSeries NOTIFY baseSeriesChanged) + Q_PROPERTY(QXYSeries* xySeries READ xySeries WRITE setXySeries NOTIFY xySeriesChanged) + Q_PROPERTY(QXYSeries* baseSeries READ baseSeries WRITE setBaseSeries NOTIFY baseSeriesChanged) Q_PROPERTY(SampleRate sampleRate READ sampleRate WRITE setSampleRate NOTIFY sampleRateChanged) Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) @@ -59,11 +63,11 @@ public: LogsModel* logsModel() const; void setLogsModel(LogsModel *logsModel); - QtCharts::QXYSeries* xySeries() const; - void setXySeries(QtCharts::QXYSeries *series); + QXYSeries* xySeries() const; + void setXySeries(QXYSeries *series); - QtCharts::QXYSeries* baseSeries() const; - void setBaseSeries(QtCharts::QXYSeries *series); + QXYSeries* baseSeries() const; + void setBaseSeries(QXYSeries *series); SampleRate sampleRate() const; void setSampleRate(SampleRate sampleRate); @@ -103,8 +107,8 @@ private: LogEntry *startingPoint = nullptr; // the starting point for the sample. Normally the last entry of the previous sample }; LogsModel* m_model = nullptr; - QtCharts::QXYSeries* m_series = nullptr; - QtCharts::QXYSeries* m_baseSeries = nullptr; + QXYSeries* m_series = nullptr; + QXYSeries* m_baseSeries = nullptr; SampleRate m_sampleRate = SampleRateSecond; bool m_smooth = true; bool m_inverted = false; diff --git a/libnymea-app/rulemanager.cpp b/libnymea-app/rulemanager.cpp index bda1e116..52ff0285 100644 --- a/libnymea-app/rulemanager.cpp +++ b/libnymea-app/rulemanager.cpp @@ -253,13 +253,13 @@ void RuleManager::parseEventDescriptors(const QVariantList &eventDescriptorList, { foreach (const QVariant &eventDescriptorVariant, eventDescriptorList) { EventDescriptor *eventDescriptor = new EventDescriptor(rule); - eventDescriptor->setThingId(eventDescriptorVariant.toMap().value("thingId").toString()); - eventDescriptor->setEventTypeId(eventDescriptorVariant.toMap().value("eventTypeId").toString()); + eventDescriptor->setThingId(eventDescriptorVariant.toMap().value("thingId").toUuid()); + eventDescriptor->setEventTypeId(eventDescriptorVariant.toMap().value("eventTypeId").toUuid()); eventDescriptor->setInterfaceName(eventDescriptorVariant.toMap().value("interface").toString()); eventDescriptor->setInterfaceEvent(eventDescriptorVariant.toMap().value("interfaceEvent").toString()); foreach (const QVariant ¶mDescriptorVariant, eventDescriptorVariant.toMap().value("paramDescriptors").toList()) { ParamDescriptor *paramDescriptor = new ParamDescriptor(); - paramDescriptor->setParamTypeId(paramDescriptorVariant.toMap().value("paramTypeId").toString()); + paramDescriptor->setParamTypeId(paramDescriptorVariant.toMap().value("paramTypeId").toUuid()); paramDescriptor->setParamName(paramDescriptorVariant.toMap().value("paramName").toString()); paramDescriptor->setValue(paramDescriptorVariant.toMap().value("value")); QMetaEnum operatorEnum = QMetaEnum::fromType(); @@ -335,7 +335,7 @@ RuleAction *RuleManager::parseRuleAction(const QVariantMap &ruleAction) } foreach (const QVariant &ruleActionParamVariant, ruleAction.value("ruleActionParams").toList()) { RuleActionParam *param = new RuleActionParam(); - param->setParamTypeId(ruleActionParamVariant.toMap().value("paramTypeId").toString()); + param->setParamTypeId(ruleActionParamVariant.toMap().value("paramTypeId").toUuid()); param->setParamName(ruleActionParamVariant.toMap().value("paramName").toString()); param->setValue(ruleActionParamVariant.toMap().value("value")); param->setEventTypeId(ruleActionParamVariant.toMap().value("eventTypeId").toString()); diff --git a/libnymea-app/ruletemplates/ruleactiontemplate.h b/libnymea-app/ruletemplates/ruleactiontemplate.h index ecea5052..1c8d28b3 100644 --- a/libnymea-app/ruletemplates/ruleactiontemplate.h +++ b/libnymea-app/ruletemplates/ruleactiontemplate.h @@ -27,7 +27,8 @@ #include -class RuleActionParamTemplates; +#include "ruleactionparamtemplate.h" + class RuleActionTemplate : public QObject { diff --git a/libnymea-app/ruletemplates/ruletemplate.h b/libnymea-app/ruletemplates/ruletemplate.h index 0511e342..48cd28f5 100644 --- a/libnymea-app/ruletemplates/ruletemplate.h +++ b/libnymea-app/ruletemplates/ruletemplate.h @@ -27,10 +27,10 @@ #include -class EventDescriptorTemplates; -class RuleActionTemplates; -class StateEvaluatorTemplate; -class TimeDescriptorTemplate; +#include "eventdescriptortemplate.h" +#include "ruleactiontemplate.h" +#include "stateevaluatortemplate.h" +#include "timedescriptortemplate.h" class RuleTemplate : public QObject { diff --git a/libnymea-app/ruletemplates/ruletemplates.h b/libnymea-app/ruletemplates/ruletemplates.h index 6426d5c3..dc827263 100644 --- a/libnymea-app/ruletemplates/ruletemplates.h +++ b/libnymea-app/ruletemplates/ruletemplates.h @@ -26,12 +26,12 @@ #define RULETEMPLATES_H #include +#include "thingsproxy.h" class RuleTemplate; class StateEvaluatorTemplate; class TimeDescriptorTemplate; class RepeatingOption; -class ThingsProxy; class Thing; class RuleTemplates : public QAbstractListModel diff --git a/libnymea-app/ruletemplates/timedescriptortemplate.h b/libnymea-app/ruletemplates/timedescriptortemplate.h index 29aaa82e..84d4046c 100644 --- a/libnymea-app/ruletemplates/timedescriptortemplate.h +++ b/libnymea-app/ruletemplates/timedescriptortemplate.h @@ -27,8 +27,8 @@ #include -class CalendarItemTemplates; -class TimeEventItemTemplates; +#include "calendaritemtemplate.h" +#include "timeeventitemtemplate.h" class TimeDescriptorTemplate : public QObject { diff --git a/libnymea-app/scripting/codecompletion.cpp b/libnymea-app/scripting/codecompletion.cpp index 93065a88..08b1330d 100644 --- a/libnymea-app/scripting/codecompletion.cpp +++ b/libnymea-app/scripting/codecompletion.cpp @@ -191,21 +191,21 @@ void CodeCompletion::update() QList entries; - QRegExp thingIdExp(".*thingId: \"[a-zA-ZÀ-ž0-9- ]*"); - if (thingIdExp.exactMatch(blockText)) { + QRegularExpression thingIdExp(".*thingId: \"[a-zA-ZÀ-ž0-9- ]*"); + if (thingIdExp.match(blockText).hasMatch()) { for (int i = 0; i < m_engine->thingManager()->things()->rowCount(); i++) { Thing *thing = m_engine->thingManager()->things()->get(i); entries.append(CompletionModel::Entry(thing->id().toString() + "\" // " + thing->name(), thing->name(), "thing", thing->thingClass()->interfaces().join(","))); } - blockText.remove(QRegExp(".*thingId: \"")); + blockText.remove(QRegularExpression(".*thingId: \"")); m_model->update(entries); m_proxy->setFilter(blockText, false); emit hint(); return; } - QRegExp stateTypeIdExp(".*stateTypeId: \"[a-zA-Z0-9-]*"); - if (stateTypeIdExp.exactMatch(blockText)) { + QRegularExpression stateTypeIdExp(".*stateTypeId: \"[a-zA-Z0-9-]*"); + if (stateTypeIdExp.match(blockText).hasMatch()) { BlockInfo info = getBlockInfo(m_cursor.position()); QString thingId; if (!info.properties.contains("thingId")) { @@ -214,7 +214,7 @@ void CodeCompletion::update() thingId = info.properties.value("thingId"); qDebug() << "selected thingId" << thingId; - Thing *thing = m_engine->thingManager()->things()->getThing(thingId); + Thing *thing = m_engine->thingManager()->things()->getThing(QUuid(thingId)); if (!thing) { return; } @@ -223,16 +223,16 @@ void CodeCompletion::update() StateType *stateType = thing->thingClass()->stateTypes()->get(i); entries.append(CompletionModel::Entry(stateType->id().toString() + "\" // " + stateType->name(), stateType->name(), "stateType")); } - blockText.remove(QRegExp(".*stateTypeId: \"")); + blockText.remove(QRegularExpression(".*stateTypeId: \"")); m_model->update(entries); m_proxy->setFilter(blockText); emit hint(); return; } - QRegExp stateNameExp(".*stateName: \"[a-zA-Z0-9-]*"); + QRegularExpression stateNameExp(".*stateName: \"[a-zA-Z0-9-]*"); // qDebug() << "block text" << blockText << stateNameExp.exactMatch(blockText); - if (stateNameExp.exactMatch(blockText)) { + if (stateNameExp.match(blockText).hasMatch()) { BlockInfo info = getBlockInfo(m_cursor.position()); qDebug() << "stateName block info" << info.name << info.properties; QString thingId; @@ -258,20 +258,28 @@ void CodeCompletion::update() } else { return; } - for (int i = 0; i < stateTypes->rowCount(); i++) { - StateType *stateType = stateTypes->get(i); + thingId = info.properties.value("thingId"); + + qDebug() << "selected thingId" << thingId; + Thing *thing = m_engine->thingManager()->things()->getThing(QUuid(thingId)); + if (!thing) { + return; + } + qDebug() << "Thing is" << thing->name(); + + for (int i = 0; i < thing->thingClass()->stateTypes()->rowCount(); i++) { + StateType *stateType = thing->thingClass()->stateTypes()->get(i); entries.append(CompletionModel::Entry(stateType->name() + "\"", stateType->name(), "stateType")); } - - blockText.remove(QRegExp(".*stateName: \"")); + blockText.remove(QRegularExpression(".*stateName: \"")); m_model->update(entries); m_proxy->setFilter(blockText); emit hint(); return; } - QRegExp actionTypeIdExp(".*actionTypeId: \"[a-zA-Z0-9-]*"); - if (actionTypeIdExp.exactMatch(blockText)) { + QRegularExpression actionTypeIdExp(".*actionTypeId: \"[a-zA-Z0-9-]*"); + if (actionTypeIdExp.match(blockText).hasMatch()) { BlockInfo info = getBlockInfo(m_cursor.position()); QString thingId; if (!info.properties.contains("thingId")) { @@ -280,7 +288,7 @@ void CodeCompletion::update() thingId = info.properties.value("thingId"); qDebug() << "selected thingId" << thingId; - Thing *thing = m_engine->thingManager()->things()->getThing(thingId); + Thing *thing = m_engine->thingManager()->things()->getThing(QUuid(thingId)); if (!thing) { return; } @@ -289,15 +297,15 @@ void CodeCompletion::update() ActionType *actionType = thing->thingClass()->actionTypes()->get(i); entries.append(CompletionModel::Entry(actionType->id().toString() + "\" // " + actionType->name(), actionType->name(), "actionType")); } - blockText.remove(QRegExp(".*actionTypeId: \"")); + blockText.remove(QRegularExpression(".*actionTypeId: \"")); m_model->update(entries); m_proxy->setFilter(blockText); emit hint(); return; } - QRegExp actionNameExp(".*actionName: \"[a-zA-Z0-9-]*"); - if (actionNameExp.exactMatch(blockText)) { + QRegularExpression actionNameExp(".*actionName: \"[a-zA-Z0-9-]*"); + if (actionNameExp.match(blockText).hasMatch()) { BlockInfo info = getBlockInfo(m_cursor.position()); Interfaces ifaces; @@ -306,7 +314,7 @@ void CodeCompletion::update() if (info.properties.contains("thingId")) { QString thingId = info.properties.value("thingId"); qDebug() << "selected thingId" << thingId; - Thing *thing = m_engine->thingManager()->things()->getThing(thingId); + Thing *thing = m_engine->thingManager()->things()->getThing(QUuid(thingId)); if (!thing) { return; } @@ -327,15 +335,15 @@ void CodeCompletion::update() entries.append(CompletionModel::Entry(actionType->name() + "\"", actionType->name(), "actionType")); } - blockText.remove(QRegExp(".*actionName: \"")); + blockText.remove(QRegularExpression(".*actionName: \"")); m_model->update(entries); m_proxy->setFilter(blockText); emit hint(); return; } - QRegExp eventTypeIdExp(".*eventTypeId: \"[a-zA-Z0-9-]*"); - if (eventTypeIdExp.exactMatch(blockText)) { + QRegularExpression eventTypeIdExp(".*eventTypeId: \"[a-zA-Z0-9-]*"); + if (eventTypeIdExp.match(blockText).hasMatch()) { BlockInfo info = getBlockInfo(m_cursor.position()); QString thingId; if (!info.properties.contains("thingId")) { @@ -344,7 +352,7 @@ void CodeCompletion::update() thingId = info.properties.value("thingId"); qDebug() << "selected thingId" << thingId; - Thing *thing= m_engine->thingManager()->things()->getThing(thingId); + Thing *thing= m_engine->thingManager()->things()->getThing(QUuid(thingId)); if (!thing) { return; } @@ -353,21 +361,21 @@ void CodeCompletion::update() EventType *eventType = thing->thingClass()->eventTypes()->get(i); entries.append(CompletionModel::Entry(eventType->id().toString() + "\" // " + eventType->name(), eventType->name(), "eventType")); } - blockText.remove(QRegExp(".*eventTypeId: \"")); + blockText.remove(QRegularExpression(".*eventTypeId: \"")); m_model->update(entries); m_proxy->setFilter(blockText); emit hint(); return; } - QRegExp eventNameExp(".*eventName: \"[a-zA-Z0-9-]*"); - if (eventNameExp.exactMatch(blockText)) { + QRegularExpression eventNameExp(".*eventName: \"[a-zA-Z0-9-]*"); + if (eventNameExp.match(blockText).hasMatch()) { BlockInfo info = getBlockInfo(m_cursor.position()); Interfaces ifaces; EventTypes *eventTypes = nullptr; if (info.properties.contains("thingId")) { QString thingId = info.properties.value("thingId"); - Thing *thing = m_engine->thingManager()->things()->getThing(thingId); + Thing *thing = m_engine->thingManager()->things()->getThing(QUuid(thingId)); if (!thing) { return; } @@ -388,15 +396,15 @@ void CodeCompletion::update() EventType *eventType = eventTypes->get(i); entries.append(CompletionModel::Entry(eventType->name() + "\"", eventType->name(), "eventType")); } - blockText.remove(QRegExp(".*eventName: \"")); + blockText.remove(QRegularExpression(".*eventName: \"")); m_model->update(entries); m_proxy->setFilter(blockText); emit hint(); return; } - QRegExp interfaceNameExp(".*(interfaceName|filterInterface): \"[a-zA-Z]*"); - if (interfaceNameExp.exactMatch(blockText)) { + QRegularExpression interfaceNameExp(".*interfaceName: \"[a-zA-Z]*"); + if (interfaceNameExp.match(blockText).hasMatch()) { BlockInfo info = getBlockInfo(m_cursor.position()); Interfaces ifaces; @@ -405,22 +413,22 @@ void CodeCompletion::update() entries.append(CompletionModel::Entry(iface->name() + "\"", iface->name(), "interface", iface->name())); } m_model->update(entries); - blockText.remove(QRegExp(".*(interfaceName|filterInterface): \"")); + blockText.remove(QRegularExpression(".*interfaceName: \"")); m_proxy->setFilter(blockText); emit hint(); return; } - QRegExp importExp("imp(o|or)?"); - if (importExp.exactMatch(blockText)) { + QRegularExpression importExp("imp(o|or)?"); + if (importExp.match(blockText).hasMatch()) { entries.append(CompletionModel::Entry("import ", "import", "keyword", "")); m_model->update(entries); m_proxy->setFilter(blockText); return; } - QRegExp importExp2("import [a-zA-Z]*"); - if (importExp2.exactMatch(blockText)) { + QRegularExpression importExp2("import [a-zA-Z]*"); + if (importExp2.match(blockText).hasMatch()) { entries.append(CompletionModel::Entry("QtQuick 2.0")); entries.append(CompletionModel::Entry("nymea 1.0")); m_model->update(entries); @@ -429,8 +437,8 @@ void CodeCompletion::update() return; } - QRegExp rValueExp(" *[\\.a-zA-Z0-0]+[^id]:[ a-zA-Z0-0]*"); - if (rValueExp.exactMatch(blockText)) { + QRegularExpression rValueExp(" *[\\.a-zA-Z0-0]+[^id]:[ a-zA-Z0-0]*"); + if (rValueExp.match(blockText).hasMatch()) { QTextCursor tmp = m_cursor; tmp.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor); QString word = tmp.selectedText(); @@ -458,10 +466,10 @@ void CodeCompletion::update() return; } - QRegExp dotExp(".*[a-zA-Z0-9]+\\.[a-zA-Z0-9]*"); - if (dotExp.exactMatch(blockText)) { + QRegularExpression dotExp(".*[a-zA-Z0-9]+\\.[a-zA-Z0-9]*"); + if (dotExp.match(blockText).hasMatch()) { QString id = blockText; - id.remove(QRegExp(".* ")).remove(QRegExp("\\.[a-zA-Z0-9]*")); + id.remove(QRegularExpression(".* ")).remove(QRegularExpression("\\.[a-zA-Z0-9]*")); QString type = getIdTypes().value(id); int blockPosition = getBlockPosition(id); BlockInfo blockInfo = getBlockInfo(blockPosition); @@ -497,7 +505,7 @@ void CodeCompletion::update() if (d) { ActionType *at = nullptr; if (blockInfo.properties.contains("actionTypeId")) { - at = d->thingClass()->actionTypes()->getActionType(blockInfo.properties.value("actionTypeId")); + at = d->thingClass()->actionTypes()->getActionType(QUuid(blockInfo.properties.value("actionTypeId"))); } else if (blockInfo.properties.contains("actionName")) { at = d->thingClass()->actionTypes()->findByName(blockInfo.properties.value("actionName")); } @@ -542,7 +550,7 @@ void CodeCompletion::update() entries.append(CompletionModel::Entry(method + "(", method, "method", "", ")")); } m_model->update(entries); - m_proxy->setFilter(blockText.remove(QRegExp(".*\\."))); + m_proxy->setFilter(blockText.remove(QRegularExpression(".*\\."))); return; } @@ -564,8 +572,8 @@ void CodeCompletion::update() if (isImperative) { // qDebug() << "Is imperative!"; // Starting a new expression? - QRegExp newExpressionExp("(.*; [a-zA-Z0-9]*| *[a-zA-Z0-9]*)"); - if (newExpressionExp.exactMatch(blockText)) { + QRegularExpression newExpressionExp("(.*; [a-zA-Z0-9]*| *[a-zA-Z0-9]*)"); + if (newExpressionExp.match(blockText).hasMatch()) { // Add generic qml syntax foreach (const QString &s, m_genericJsSyntax.keys()) { entries.append(CompletionModel::Entry(m_genericJsSyntax.value(s), s, "keyword", "")); @@ -579,12 +587,12 @@ void CodeCompletion::update() } m_model->update(entries); - m_proxy->setFilter(blockText.remove(QRegExp(".* "))); + m_proxy->setFilter(blockText.remove(QRegularExpression(".* "))); return; } - QRegExp lValueStartExp(" *[a-zA-Z0-9]*"); - if (lValueStartExp.exactMatch(blockText)) { + QRegularExpression lValueStartExp(" *[a-zA-Z0-9]*"); + if (lValueStartExp.match(blockText).hasMatch()) { BlockInfo blockInfo = getBlockInfo(m_cursor.position()); // If we're inside a class, add properties @@ -617,7 +625,7 @@ void CodeCompletion::update() } m_model->update(entries); - blockText.remove(QRegExp(".* ")); + blockText.remove(QRegularExpression(".* ")); m_proxy->setFilter(blockText); // qDebug() << "Model has" << m_model->rowCount() << "Filtered:" << m_proxy->rowCount() << "filter:" << blockText; return; @@ -658,9 +666,9 @@ CodeCompletion::BlockInfo CodeCompletion::getBlockInfo(int position) const // qDebug() << "Block start:" << info.start << "end:" << info.end; info.name = blockStart.block().text(); - info.name.remove(QRegExp(" *\\{ *")); + info.name.remove(QRegularExpression(" *\\{ *")); while (info.name.contains(" ")) { - info.name.remove(QRegExp(".* ")); + info.name.remove(QRegularExpression(".* ")); } int childBlocks = 0; @@ -760,7 +768,7 @@ int CodeCompletion::openingBlocksBefore(int position) const QTextCursor tmp = m_cursor; tmp.setPosition(position); do { - tmp = m_document->textDocument()->find(QRegExp("[{}]"), tmp, QTextDocument::FindBackward); + tmp = m_document->textDocument()->find(QRegularExpression("[{}]"), tmp, QTextDocument::FindBackward); if (tmp.selectedText() == "{") opening++; if (tmp.selectedText() == "}") @@ -777,7 +785,7 @@ int CodeCompletion::closingBlocksAfter(int position) const QTextCursor tmp = m_cursor; tmp.setPosition(position); do { - tmp = m_document->textDocument()->find(QRegExp("[{}]"), tmp); + tmp = m_document->textDocument()->find(QRegularExpression("[{}]"), tmp); if (tmp.selectedText() == "{") opening++; if (tmp.selectedText() == "}") @@ -802,8 +810,8 @@ void CodeCompletion::complete(int index) QTextCursor tmp = m_cursor; tmp.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor); QString blockText = tmp.selectedText(); - QRegExp thingIdExp(".*thingId: \"[a-zA-ZÀ-ž0-9- ]*"); - if (thingIdExp.exactMatch(blockText)) { + QRegularExpression thingIdExp(".*thingId: \"[a-zA-ZÀ-ž0-9- ]*"); + if (thingIdExp.match(blockText).hasMatch()) { QTextCursor tmp = m_document->textDocument()->find("\"", m_cursor.position(), QTextDocument::FindBackward); m_cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor, m_cursor.position() - tmp.position()); m_cursor.removeSelectedText(); @@ -827,7 +835,7 @@ void CodeCompletion::newLine() } QString trimmedLine = line; - trimmedLine.remove(QRegExp("^[ ]+")); + trimmedLine.remove(QRegularExpression("^[ ]+")); int indent = line.length() - trimmedLine.length(); m_cursor.insertText(QString("\n").leftJustified(indent + 1, ' ')); @@ -926,7 +934,7 @@ void CodeCompletion::toggleComment(int from, int to) bool allLinesHaveComments = true; do { - QTextCursor nextComment = m_document->textDocument()->find(QRegExp("^[ ]*//"), tmp.position()); + QTextCursor nextComment = m_document->textDocument()->find(QRegularExpression("^[ ]*//"), tmp.position()); nextComment.movePosition(QTextCursor::StartOfLine); bool lineHasComment = tmp.position() == nextComment.position(); allLinesHaveComments &= lineHasComment; @@ -939,7 +947,7 @@ void CodeCompletion::toggleComment(int from, int to) tmp.movePosition(QTextCursor::StartOfLine); do { if (allLinesHaveComments) { - QTextCursor nextComment = m_document->textDocument()->find(QRegExp("//"), tmp.position()); + QTextCursor nextComment = m_document->textDocument()->find(QRegularExpression("//"), tmp.position()); nextComment.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, 2); nextComment.removeSelectedText(); nextComment.insertText(" "); @@ -970,7 +978,7 @@ void CodeCompletion::moveCursor(CodeCompletion::MoveOperation moveOperation, int return; case MoveOperationPreviousWord: { // We're not using the cursors next/previos word because we want camelCase word fragments - QTextCursor tmp = m_document->textDocument()->find(QRegExp("[A-Z\\.:\"'\\(\\)\\[\\]^ ]"), m_cursor.position() - 1, QTextDocument::FindBackward); + QTextCursor tmp = m_document->textDocument()->find(QRegularExpression("[A-Z\\.:\"'\\(\\)\\[\\]^ ]"), m_cursor.position() - 1, QTextDocument::FindBackward); qWarning() << "found at" << tmp.position() << "starting at" << m_cursor.position(); m_cursor.setPosition(tmp.position()); emit cursorPositionChanged(); @@ -978,7 +986,7 @@ void CodeCompletion::moveCursor(CodeCompletion::MoveOperation moveOperation, int } case MoveOperationNextWord: { // We're not using the cursors next/previos word because we want camelCase word fragments - QTextCursor tmp = m_document->textDocument()->find(QRegExp("[A-Z\\.:\"'\\(\\)\\[\\]$ ]"), m_cursor.position() + 1); + QTextCursor tmp = m_document->textDocument()->find(QRegularExpression("[A-Z\\.:\"'\\(\\)\\[\\]$ ]"), m_cursor.position() + 1); m_cursor.setPosition(tmp.position() - 1); emit cursorPositionChanged(); return; diff --git a/libnymea-app/scripting/codecompletion.h b/libnymea-app/scripting/codecompletion.h index 47da880b..3ca3da62 100644 --- a/libnymea-app/scripting/codecompletion.h +++ b/libnymea-app/scripting/codecompletion.h @@ -30,10 +30,9 @@ #include #include +#include "engine.h" #include "completionmodel.h" -class Engine; - class CodeCompletion: public QObject { Q_OBJECT diff --git a/libnymea-app/scripting/scriptautosaver.cpp b/libnymea-app/scripting/scriptautosaver.cpp index 095ab9ec..ef051e67 100644 --- a/libnymea-app/scripting/scriptautosaver.cpp +++ b/libnymea-app/scripting/scriptautosaver.cpp @@ -27,6 +27,7 @@ #include #include #include +#include ScriptAutoSaver::ScriptAutoSaver(QObject *parent) : QObject(parent) { @@ -80,7 +81,7 @@ void ScriptAutoSaver::setScriptId(const QUuid &scriptId) qWarning() << "Cannot create cache directory. Autosaving will not work..."; return; } - QString fileName = path + m_scriptId.toString().remove(QRegExp("[{}]")) + ".qml.autosave"; + QString fileName = path + m_scriptId.toString().remove(QRegularExpression("[{}]")) + ".qml.autosave"; m_cacheFile.setFileName(fileName); if (!m_cacheFile.open(QFile::ReadWrite)) { qWarning() << "Cannot open cache file. Autosaving will not work..."; diff --git a/libnymea-app/scriptmanager.h b/libnymea-app/scriptmanager.h index c951313d..73d4be6b 100644 --- a/libnymea-app/scriptmanager.h +++ b/libnymea-app/scriptmanager.h @@ -28,8 +28,7 @@ #include #include "jsonrpc/jsonrpcclient.h" - -class Scripts; +#include "types/scripts.h" class ScriptManager : public QObject { diff --git a/libnymea-app/system/systemcontroller.h b/libnymea-app/system/systemcontroller.h index 2c17247e..84a441a8 100644 --- a/libnymea-app/system/systemcontroller.h +++ b/libnymea-app/system/systemcontroller.h @@ -28,9 +28,8 @@ #include #include "jsonrpc/jsonrpcclient.h" - -class Repositories; -class Packages; +#include "types/packages.h" +#include "types/repositories.h" class SystemController : public QObject { diff --git a/libnymea-app/tagsmanager.cpp b/libnymea-app/tagsmanager.cpp index e5c5b9ca..00131d7d 100644 --- a/libnymea-app/tagsmanager.cpp +++ b/libnymea-app/tagsmanager.cpp @@ -177,15 +177,15 @@ void TagsManager::removeTagResponse(int commandId, const QVariantMap ¶ms) Tag* TagsManager::unpackTag(const QVariantMap &tagMap) { - QString thingId = tagMap.value("thingId").toString(); - QString ruleId = tagMap.value("ruleId").toString(); + QUuid thingId = tagMap.value("thingId").toUuid(); + QUuid ruleId = tagMap.value("ruleId").toUuid(); QString tagId = tagMap.value("tagId").toString(); QString value = tagMap.value("value").toString(); Tag *tag = nullptr; - if (!thingId.isEmpty()) { + if (!thingId.isNull()) { tag = new Tag(tagId, value); tag->setThingId(thingId); - } else if (!ruleId.isEmpty()) { + } else if (!ruleId.isNull()) { tag = new Tag(tagId, value); tag->setRuleId(ruleId); } else { diff --git a/libnymea-app/tagwatcher.h b/libnymea-app/tagwatcher.h index e88cd007..7b8f3371 100644 --- a/libnymea-app/tagwatcher.h +++ b/libnymea-app/tagwatcher.h @@ -28,6 +28,7 @@ #include #include +#include "types/tag.h" #include "types/tags.h" class TagWatcher : public QObject diff --git a/libnymea-app/thingdiscovery.cpp b/libnymea-app/thingdiscovery.cpp index df059e70..f71e5f6b 100644 --- a/libnymea-app/thingdiscovery.cpp +++ b/libnymea-app/thingdiscovery.cpp @@ -182,7 +182,7 @@ void ThingDiscovery::discoverThingsResponse(int commandId, const QVariantMap &pa beginInsertRows(QModelIndex(), m_foundThings.count(), m_foundThings.count()); ThingDescriptor *descriptor = new ThingDescriptor(descriptorVariant.toMap().value("id").toUuid(), descriptorVariant.toMap().value("thingClassId").toUuid(), // Note: This will only be provided as of nymea 0.28! - descriptorVariant.toMap().value("thingId").toString(), + descriptorVariant.toMap().value("thingId").toUuid(), descriptorVariant.toMap().value("title").toString(), descriptorVariant.toMap().value("description").toString(), this); // Work around a bug in nymea:core which didn't properly update deviceParams in the device->things transition @@ -194,7 +194,7 @@ void ThingDiscovery::discoverThingsResponse(int commandId, const QVariantMap &pa } foreach (const QVariant ¶mVariant, paramList) { qDebug() << "Adding param:" << paramVariant.toMap().value("paramTypeId").toString() << paramVariant.toMap().value("value"); - Param* p = new Param(paramVariant.toMap().value("paramTypeId").toString(), paramVariant.toMap().value("value")); + Param* p = new Param(paramVariant.toMap().value("paramTypeId").toUuid(), paramVariant.toMap().value("value")); descriptor->params()->addParam(p); } qCInfo(dcThingManager()) << "Found thing. Descriptor:" << descriptor->name() << descriptor->id(); diff --git a/libnymea-app/thingmanager.cpp b/libnymea-app/thingmanager.cpp index bdc225a5..3fff48c8 100644 --- a/libnymea-app/thingmanager.cpp +++ b/libnymea-app/thingmanager.cpp @@ -175,7 +175,7 @@ void ThingManager::notificationReceived(const QVariantMap &data) } } else if (notification == "Integrations.ThingSettingChanged") { QUuid thingId = data.value("params").toMap().value("thingId").toUuid(); - QString paramTypeId = data.value("params").toMap().value("paramTypeId").toString(); + QUuid paramTypeId = data.value("params").toMap().value("paramTypeId").toUuid(); QVariant value = data.value("params").toMap().value("value"); // qDebug() << "Thing settings changed notification for thing" << thingId << data.value("params").toMap().value("settings").toList(); Thing *thing = m_things->getThing(thingId); @@ -202,7 +202,7 @@ void ThingManager::notificationReceived(const QVariantMap &data) return; } qCDebug(dcThingManager) << "Event received" << thingId.toString() << eventTypeId.toString() << qUtf8Printable(QJsonDocument::fromVariant(event).toJson()); - thing->eventTriggered(eventTypeId.toString(), event.value("params").toList()); + thing->eventTriggered(eventTypeId, event.value("params").toList()); } else if (notification == "Integrations.IOConnectionAdded") { QVariantMap connectionMap = data.value("params").toMap().value("ioConnection").toMap(); QUuid id = connectionMap.value("id").toUuid(); @@ -280,7 +280,7 @@ void ThingManager::getThingsResponse(int /*commandId*/, const QVariantMap ¶m // set initial state values QVariantList stateVariantList = thingVariant.toMap().value("states").toList(); foreach (const QVariant &stateMap, stateVariantList) { - QString stateTypeId = stateMap.toMap().value("stateTypeId").toString(); + QUuid stateTypeId = stateMap.toMap().value("stateTypeId").toUuid(); StateType *st = thing->thingClass()->stateTypes()->getStateType(stateTypeId); if (!st) { qWarning() << "Can't find a statetype for this state"; @@ -725,7 +725,7 @@ void ThingManager::setEventLoggingResponse(int commandId, const QVariantMap &par Vendor *ThingManager::unpackVendor(const QVariantMap &vendorMap) { - Vendor *v = new Vendor(vendorMap.value("id").toString(), vendorMap.value("name").toString()); + Vendor *v = new Vendor(vendorMap.value("id").toUuid(), vendorMap.value("name").toString()); v->setDisplayName(vendorMap.value("displayName").toString()); return v; } @@ -817,14 +817,14 @@ ThingClass *ThingManager::unpackThingClass(const QVariantMap &thingClassMap) void ThingManager::unpackParam(const QVariantMap ¶mMap, Param *param) { - param->setParamTypeId(paramMap.value("paramTypeId").toString()); + param->setParamTypeId(paramMap.value("paramTypeId").toUuid()); param->setValue(paramMap.value("value")); } ParamType *ThingManager::unpackParamType(const QVariantMap ¶mTypeMap, QObject *parent) { ParamType *paramType = new ParamType(parent); - paramType->setId(paramTypeMap.value("id").toString()); + paramType->setId(paramTypeMap.value("id").toUuid()); paramType->setName(paramTypeMap.value("name").toString()); paramType->setDisplayName(paramTypeMap.value("displayName").toString()); paramType->setType(paramTypeMap.value("type").toString()); @@ -842,7 +842,7 @@ ParamType *ThingManager::unpackParamType(const QVariantMap ¶mTypeMap, QObjec StateType *ThingManager::unpackStateType(const QVariantMap &stateTypeMap, QObject *parent) { StateType *stateType = new StateType(parent); - stateType->setId(stateTypeMap.value("id").toString()); + stateType->setId(stateTypeMap.value("id").toUuid()); stateType->setName(stateTypeMap.value("name").toString()); stateType->setDisplayName(stateTypeMap.value("displayName").toString()); stateType->setIndex(stateTypeMap.value("index").toInt()); @@ -870,7 +870,7 @@ StateType *ThingManager::unpackStateType(const QVariantMap &stateTypeMap, QObjec EventType *ThingManager::unpackEventType(const QVariantMap &eventTypeMap, QObject *parent) { EventType *eventType = new EventType(parent); - eventType->setId(eventTypeMap.value("id").toString()); + eventType->setId(eventTypeMap.value("id").toUuid()); eventType->setName(eventTypeMap.value("name").toString()); eventType->setDisplayName(eventTypeMap.value("displayName").toString()); eventType->setIndex(eventTypeMap.value("index").toInt()); @@ -885,7 +885,7 @@ EventType *ThingManager::unpackEventType(const QVariantMap &eventTypeMap, QObjec ActionType *ThingManager::unpackActionType(const QVariantMap &actionTypeMap, QObject *parent) { ActionType *actionType = new ActionType(parent); - actionType->setId(actionTypeMap.value("id").toString()); + actionType->setId(actionTypeMap.value("id").toUuid()); actionType->setName(actionTypeMap.value("name").toString()); actionType->setDisplayName(actionTypeMap.value("displayName").toString()); actionType->setIndex(actionTypeMap.value("index").toInt()); @@ -937,7 +937,7 @@ Thing* ThingManager::unpackThing(ThingManager *thingManager, const QVariantMap & params = new Params(thing); } foreach (QVariant param, thingMap.value("params").toList()) { - Param *p = params->getParam(param.toMap().value("paramTypeId").toString()); + Param *p = params->getParam(param.toMap().value("paramTypeId").toUuid()); if (!p) { p = new Param(); params->addParam(p); @@ -951,7 +951,7 @@ Thing* ThingManager::unpackThing(ThingManager *thingManager, const QVariantMap & settings = new Params(thing); } foreach (QVariant setting, thingMap.value("settings").toList()) { - Param *p = settings->getParam(setting.toMap().value("paramTypeId").toString()); + Param *p = settings->getParam(setting.toMap().value("paramTypeId").toUuid()); if (!p) { p = new Param(); settings->addParam(p); diff --git a/libnymea-app/thingmanager.h b/libnymea-app/thingmanager.h index 328f96b9..41df07a9 100644 --- a/libnymea-app/thingmanager.h +++ b/libnymea-app/thingmanager.h @@ -30,16 +30,16 @@ #include "types/vendors.h" #include "things.h" #include "thingclasses.h" -#include "interfacesmodel.h" #include "types/plugins.h" #include "jsonrpc/jsonrpcclient.h" +#include "types/ioconnections.h" class BrowserItem; class BrowserItems; class ThingGroup; class Interface; -class IOConnections; class EventHandler; +class ThingsProxy; class ThingManager : public QObject { diff --git a/libnymea-app/thingsproxy.cpp b/libnymea-app/thingsproxy.cpp index 87230107..4599e467 100644 --- a/libnymea-app/thingsproxy.cpp +++ b/libnymea-app/thingsproxy.cpp @@ -253,7 +253,7 @@ void ThingsProxy::setHiddenThingClassIds(const QStringList &hiddenThingClassIds) { QList uuids; foreach (const QString &str, hiddenThingClassIds) { - uuids << str; + uuids.append(QUuid(str)); } if (m_hiddenThingClassIds != uuids) { m_hiddenThingClassIds = uuids; @@ -297,7 +297,7 @@ void ThingsProxy::setHiddenThingIds(const QStringList &hiddenThingIds) { QList uuids; foreach (const QString &str, hiddenThingIds) { - uuids << str; + uuids.append(QUuid(str)); } if (m_hiddenThingIds != uuids) { m_hiddenThingIds = uuids; @@ -610,7 +610,7 @@ bool ThingsProxy::lessThan(const QModelIndex &left, const QModelIndex &right) co State *rightState = rightThing->stateByName(m_sortStateName); QVariant leftStateValue = leftState ? leftState->value() : 0; QVariant rightStateValue = rightState ? rightState->value() : 0; - return leftStateValue < rightStateValue; + return leftStateValue.toString() < rightStateValue.toString(); } QString leftName = sourceModel()->data(left, sortRole()).toString(); @@ -631,7 +631,7 @@ bool ThingsProxy::filterAcceptsRow(int source_row, const QModelIndex &source_par { Thing *thing = getInternal(source_row); if (!m_filterTagId.isEmpty()) { - Tag *tag = m_engine->tagsManager()->tags()->findThingTag(thing->id().toString(), m_filterTagId); + Tag *tag = m_engine->tagsManager()->tags()->findThingTag(thing->id(), m_filterTagId); if (!tag) { return false; } @@ -640,7 +640,7 @@ bool ThingsProxy::filterAcceptsRow(int source_row, const QModelIndex &source_par } } if (!m_hideTagId.isEmpty()) { - Tag *tag = m_engine->tagsManager()->tags()->findThingTag(thing->id().toString(), m_hideTagId); + Tag *tag = m_engine->tagsManager()->tags()->findThingTag(thing->id(), m_hideTagId); if (tag && m_hideTagValue.isEmpty()) { return false; } diff --git a/libnymea-app/thingsproxy.h b/libnymea-app/thingsproxy.h index 2f4653a2..cc2e434f 100644 --- a/libnymea-app/thingsproxy.h +++ b/libnymea-app/thingsproxy.h @@ -29,10 +29,9 @@ #include #include +#include "engine.h" #include "things.h" -class Engine; - class ThingsProxy : public QSortFilterProxyModel { Q_OBJECT diff --git a/libnymea-app/types/calendaritem.h b/libnymea-app/types/calendaritem.h index 603cefa5..368c49c8 100644 --- a/libnymea-app/types/calendaritem.h +++ b/libnymea-app/types/calendaritem.h @@ -28,7 +28,7 @@ #include #include -class RepeatingOption; +#include "repeatingoption.h" class CalendarItem : public QObject { diff --git a/libnymea-app/types/interface.h b/libnymea-app/types/interface.h index 4f6d8650..9b456e2a 100644 --- a/libnymea-app/types/interface.h +++ b/libnymea-app/types/interface.h @@ -27,9 +27,10 @@ #include -class EventTypes; -class StateTypes; -class ActionTypes; +#include "eventtypes.h" +#include "statetypes.h" +#include "actiontypes.h" + class ThingClass; class Interface : public QObject diff --git a/libnymea-app/types/ioconnectionwatcher.h b/libnymea-app/types/ioconnectionwatcher.h index 2fb69c93..dd8b2612 100644 --- a/libnymea-app/types/ioconnectionwatcher.h +++ b/libnymea-app/types/ioconnectionwatcher.h @@ -28,8 +28,8 @@ #include #include -class IOConnection; -class IOConnections; +#include "ioconnection.h" +#include "ioconnections.h" class IOInputConnectionWatcher : public QObject { diff --git a/libnymea-app/types/networkdevice.h b/libnymea-app/types/networkdevice.h index b7ed2705..ae2f0636 100644 --- a/libnymea-app/types/networkdevice.h +++ b/libnymea-app/types/networkdevice.h @@ -27,8 +27,8 @@ #include -class WirelessAccessPoint; -class WirelessAccessPoints; +#include "wirelessaccesspoint.h" +#include "wirelessaccesspoints.h" class NetworkDevice : public QObject { diff --git a/libnymea-app/types/param.h b/libnymea-app/types/param.h index ddd3e5c6..626878d7 100644 --- a/libnymea-app/types/param.h +++ b/libnymea-app/types/param.h @@ -36,7 +36,7 @@ class Param : public QObject Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) public: - Param(const QUuid ¶mTypeId = QString(), const QVariant &value = QVariant(), QObject *parent = nullptr); + Param(const QUuid ¶mTypeId = QUuid(), const QVariant &value = QVariant(), QObject *parent = nullptr); Param(QObject *parent); QUuid paramTypeId() const; diff --git a/libnymea-app/types/paramdescriptors.cpp b/libnymea-app/types/paramdescriptors.cpp index c15f9c3b..b6791a3b 100644 --- a/libnymea-app/types/paramdescriptors.cpp +++ b/libnymea-app/types/paramdescriptors.cpp @@ -82,7 +82,7 @@ void ParamDescriptors::addParamDescriptor(ParamDescriptor *paramDescriptor) emit countChanged(); } -void ParamDescriptors::setParamDescriptor(const QString ¶mTypeId, const QVariant &value, ValueOperator operatorType) +void ParamDescriptors::setParamDescriptor(const QUuid ¶mTypeId, const QVariant &value, ValueOperator operatorType) { foreach (ParamDescriptor* paramDescriptor, m_list) { if (paramDescriptor->paramTypeId() == paramTypeId) { @@ -125,7 +125,7 @@ void ParamDescriptors::clear() emit countChanged(); } -ParamDescriptor *ParamDescriptors::getParamDescriptor(const QString ¶mTypeId) const +ParamDescriptor *ParamDescriptors::getParamDescriptor(const QUuid ¶mTypeId) const { qDebug() << "getParamDescriptor" << paramTypeId; for (int i = 0; i < m_list.count(); i++) { diff --git a/libnymea-app/types/paramdescriptors.h b/libnymea-app/types/paramdescriptors.h index a03cd0ef..01d128c6 100644 --- a/libnymea-app/types/paramdescriptors.h +++ b/libnymea-app/types/paramdescriptors.h @@ -62,11 +62,11 @@ public: ParamDescriptor* createNewParamDescriptor() const; void addParamDescriptor(ParamDescriptor* paramDescriptor); - Q_INVOKABLE void setParamDescriptor(const QString ¶mTypeId, const QVariant &value, ValueOperator operatorType); + Q_INVOKABLE void setParamDescriptor(const QUuid ¶mTypeId, const QVariant &value, ValueOperator operatorType); Q_INVOKABLE void setParamDescriptorByName(const QString ¶mName, const QVariant &value, ValueOperator operatorType); Q_INVOKABLE void clear(); - Q_INVOKABLE ParamDescriptor *getParamDescriptor(const QString ¶mTypeId) const; + Q_INVOKABLE ParamDescriptor *getParamDescriptor(const QUuid ¶mTypeId) const; Q_INVOKABLE ParamDescriptor *getParamDescriptorByName(const QString ¶mName) const; bool operator==(ParamDescriptors *other) const; diff --git a/libnymea-app/types/rule.cpp b/libnymea-app/types/rule.cpp index 58891ca8..56fcf75d 100644 --- a/libnymea-app/types/rule.cpp +++ b/libnymea-app/types/rule.cpp @@ -207,17 +207,17 @@ bool Rule::operator==(Rule *other) const QDebug operator <<(QDebug &dbg, Rule *rule) { - dbg << rule->name() << " (Enabled:" << rule->enabled() << "Active:" << rule->active() << ")" << endl; + dbg << rule->name() << " (Enabled:" << rule->enabled() << "Active:" << rule->active() << ")" << Qt::endl; if (rule->eventDescriptors()->rowCount() > 0) { - dbg << "Event descriptors:" << endl; + dbg << "Event descriptors:" << Qt::endl; } for (int i = 0; i < rule->eventDescriptors()->rowCount(); i++) { EventDescriptor *ed = rule->eventDescriptors()->get(i); dbg << " " << i << ":"; if (!ed->thingId().isNull() && !ed->eventTypeId().isNull()) { - dbg << "Thing ID:" << ed->thingId() << "Event Type ID:" << ed->eventTypeId() << endl; + dbg << "Thing ID:" << ed->thingId() << "Event Type ID:" << ed->eventTypeId() << Qt::endl; } else { - dbg << "Interface Name:" << ed->interfaceName() << "Event Name:" << ed->interfaceEvent() << endl; + dbg << "Interface Name:" << ed->interfaceName() << "Event Name:" << ed->interfaceEvent() << Qt::endl; } for (int j = 0; j < ed->paramDescriptors()->rowCount(); j++) { ParamDescriptor *epd = ed->paramDescriptors()->get(j); @@ -242,52 +242,52 @@ QDebug operator <<(QDebug &dbg, Rule *rule) operatorString = ">="; break; } - dbg << " Param" << j << ": ID:" << epd->paramTypeId() << operatorString << " Value:" << epd->value() << endl; + dbg << " Param" << j << ": ID:" << epd->paramTypeId() << operatorString << " Value:" << epd->value() << Qt::endl; } } if (rule->stateEvaluator()) { - dbg << "State Evaluator:" << endl; + dbg << "State Evaluator:" << Qt::endl; printStateEvaluator(dbg, rule->stateEvaluator()); } if (rule->actions()->rowCount() > 0) { - dbg << "Actions:" << endl; + dbg << "Actions:" << Qt::endl; } for (int i = 0; i < rule->actions()->rowCount(); i++) { RuleAction *ra = rule->actions()->get(i); dbg << " " << i << ":"; if (!ra->thingId().isNull() && !ra->actionTypeId().isNull()) { - dbg << "Thing ID:" << ra->thingId() << "Action Type ID:" << ra->actionTypeId() << endl; + dbg << "Thing ID:" << ra->thingId() << "Action Type ID:" << ra->actionTypeId() << Qt::endl; } else { - dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << endl; + dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << Qt::endl; } for (int j = 0; j < ra->ruleActionParams()->rowCount(); j++) { RuleActionParam *rap = ra->ruleActionParams()->get(j); if (rap->eventTypeId().isNull()) { - dbg << " Param" << j << ": ID:" << rap->paramTypeId() << " Value:" << rap->value() << endl; + dbg << " Param" << j << ": ID:" << rap->paramTypeId() << " Value:" << rap->value() << Qt::endl; } else { - dbg << " Param" << j << ": ID:" << rap->paramTypeId() << " Source Event Type ID:" << rap->eventTypeId() << "Source Event Param ID:" << rap->eventParamTypeId() << endl; + dbg << " Param" << j << ": ID:" << rap->paramTypeId() << " Source Event Type ID:" << rap->eventTypeId() << "Source Event Param ID:" << rap->eventParamTypeId() << Qt::endl; } } } if (rule->exitActions()->rowCount() > 0) { - dbg << "Exit Actions:" << endl; + dbg << "Exit Actions:" << Qt::endl; } for (int i = 0; i < rule->exitActions()->rowCount(); i++) { RuleAction *ra = rule->exitActions()->get(i); dbg << " " << i << ":"; if (!ra->thingId().isNull() && !ra->actionTypeId().isNull()) { - dbg << "Thing ID:" << ra->thingId() << "Action Type ID:" << ra->actionTypeId() << endl;; + dbg << "Thing ID:" << ra->thingId() << "Action Type ID:" << ra->actionTypeId() << Qt::endl;; } else { - dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << endl;; + dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << Qt::endl;; } for (int j = 0; j < ra->ruleActionParams()->rowCount(); j++) { RuleActionParam *rap = ra->ruleActionParams()->get(j); if (rap->eventTypeId().isNull()) { - dbg << " Param" << j << ": ID:" << rap->paramTypeId() << " Value:" << rap->value() << endl; + dbg << " Param" << j << ": ID:" << rap->paramTypeId() << " Value:" << rap->value() << Qt::endl; } else { - dbg << " Param" << j << ": ID:" << rap->paramTypeId() << " Source Event Type ID:" << rap->eventTypeId() << "Source Event Param ID:" << rap->eventParamTypeId() << endl; + dbg << " Param" << j << ": ID:" << rap->paramTypeId() << " Source Event Type ID:" << rap->eventTypeId() << "Source Event Param ID:" << rap->eventParamTypeId() << Qt::endl; } } } @@ -324,11 +324,11 @@ QDebug printStateEvaluator(QDebug &dbg, StateEvaluator *stateEvaluator, int inde dbg << ">="; break; } - dbg << stateEvaluator->stateDescriptor()->value() << '/' << stateEvaluator->stateDescriptor()->valueThingId() << stateEvaluator->stateDescriptor()->valueStateTypeId() << endl; + dbg << stateEvaluator->stateDescriptor()->value() << '/' << stateEvaluator->stateDescriptor()->valueThingId() << stateEvaluator->stateDescriptor()->valueStateTypeId() << Qt::endl; } if (stateEvaluator->childEvaluators()->rowCount() > 0) { for (int i = 0; i < indentLevel; i++) { dbg << " "; } - dbg << (stateEvaluator->stateOperator() == StateEvaluator::StateOperatorAnd ? "AND" : "OR") << endl; + dbg << (stateEvaluator->stateOperator() == StateEvaluator::StateOperatorAnd ? "AND" : "OR") << Qt::endl; } for (int i = 0; i < stateEvaluator->childEvaluators()->rowCount(); i++) { printStateEvaluator(dbg, stateEvaluator->childEvaluators()->get(i), indentLevel+1); diff --git a/libnymea-app/types/rule.h b/libnymea-app/types/rule.h index 5e9bcbef..ef185172 100644 --- a/libnymea-app/types/rule.h +++ b/libnymea-app/types/rule.h @@ -28,10 +28,10 @@ #include #include -class EventDescriptors; -class RuleActions; -class StateEvaluator; -class TimeDescriptor; +#include "eventdescriptors.h" +#include "ruleactions.h" +#include "stateevaluator.h" +#include "timedescriptor.h" class Rule : public QObject { diff --git a/libnymea-app/types/ruleaction.h b/libnymea-app/types/ruleaction.h index a6e910a3..458b031d 100644 --- a/libnymea-app/types/ruleaction.h +++ b/libnymea-app/types/ruleaction.h @@ -28,7 +28,7 @@ #include #include -class RuleActionParams; +#include "ruleactionparams.h" class RuleAction : public QObject { diff --git a/libnymea-app/types/ruleactionparams.cpp b/libnymea-app/types/ruleactionparams.cpp index 58ad9d3d..9d68e48e 100644 --- a/libnymea-app/types/ruleactionparams.cpp +++ b/libnymea-app/types/ruleactionparams.cpp @@ -103,7 +103,7 @@ void RuleActionParams::setRuleActionParamByName(const QString ¶mName, const addRuleActionParam(rap); } -void RuleActionParams::setRuleActionParamEvent(const QString ¶mTypeId, const QString &eventTypeId, const QString &eventParamTypeId) +void RuleActionParams::setRuleActionParamEvent(const QUuid ¶mTypeId, const QString &eventTypeId, const QString &eventParamTypeId) { foreach (RuleActionParam *rap, m_list) { if (rap->paramTypeId() == paramTypeId) { @@ -135,7 +135,7 @@ void RuleActionParams::setRuleActionParamEventByName(const QString ¶mName, c addRuleActionParam(rap); } -void RuleActionParams::setRuleActionParamState(const QString ¶mTypeId, const QString &stateThingId, const QString &stateTypeId) +void RuleActionParams::setRuleActionParamState(const QUuid ¶mTypeId, const QString &stateThingId, const QString &stateTypeId) { foreach (RuleActionParam *rap, m_list) { if (rap->paramTypeId() == paramTypeId) { @@ -185,7 +185,7 @@ RuleActionParam *RuleActionParams::getParam(const QUuid ¶mTypeId) return nullptr; } -bool RuleActionParams::hasRuleActionParam(const QString ¶mTypeId) const +bool RuleActionParams::hasRuleActionParam(const QUuid ¶mTypeId) const { for (int i = 0; i < m_list.count(); i++) { if (m_list.at(i)->paramTypeId() == paramTypeId) { diff --git a/libnymea-app/types/ruleactionparams.h b/libnymea-app/types/ruleactionparams.h index 802803be..1dd6e5f6 100644 --- a/libnymea-app/types/ruleactionparams.h +++ b/libnymea-app/types/ruleactionparams.h @@ -52,15 +52,15 @@ public: Q_INVOKABLE void setRuleActionParam(const QUuid ¶mTypeId, const QVariant &value); Q_INVOKABLE void setRuleActionParamByName(const QString ¶mName, const QVariant &value); - Q_INVOKABLE void setRuleActionParamEvent(const QString ¶mTypeId, const QString &eventTypeId, const QString &eventParamTypeId); + Q_INVOKABLE void setRuleActionParamEvent(const QUuid ¶mTypeId, const QString &eventTypeId, const QString &eventParamTypeId); Q_INVOKABLE void setRuleActionParamEventByName(const QString ¶mName, const QString &eventTypeId, const QString &eventParamTypeId); - Q_INVOKABLE void setRuleActionParamState(const QString ¶mTypeId, const QString &stateThingId, const QString &stateTypeId); + Q_INVOKABLE void setRuleActionParamState(const QUuid ¶mTypeId, const QString &stateThingId, const QString &stateTypeId); Q_INVOKABLE void setRuleActionParamStateByName(const QString ¶mName, const QString &stateThingId, const QString &stateTypeId); Q_INVOKABLE RuleActionParam* get(int index) const; Q_INVOKABLE RuleActionParam* getParam(const QUuid ¶mTypeId); - Q_INVOKABLE bool hasRuleActionParam(const QString ¶mTypeId) const; + Q_INVOKABLE bool hasRuleActionParam(const QUuid ¶mTypeId) const; Q_INVOKABLE void clear(); diff --git a/libnymea-app/types/stateevaluator.h b/libnymea-app/types/stateevaluator.h index 6ed61000..78d66f55 100644 --- a/libnymea-app/types/stateevaluator.h +++ b/libnymea-app/types/stateevaluator.h @@ -27,8 +27,8 @@ #include -class StateEvaluators; -class StateDescriptor; +#include "stateevaluators.h" +#include "statedescriptor.h" class StateEvaluator : public QObject { diff --git a/libnymea-app/types/tags.cpp b/libnymea-app/types/tags.cpp index 314c9ea0..bc7dc169 100644 --- a/libnymea-app/types/tags.cpp +++ b/libnymea-app/types/tags.cpp @@ -125,7 +125,7 @@ Tag *Tags::findThingTag(const QUuid &thingId, const QString &tagId) const return nullptr; } -Tag *Tags::findRuleTag(const QString &ruleId, const QString &tagId) const +Tag *Tags::findRuleTag(const QUuid &ruleId, const QString &tagId) const { foreach (Tag *tag, m_list) { if (tag->ruleId() == ruleId && tag->tagId() == tagId) { diff --git a/libnymea-app/types/tags.h b/libnymea-app/types/tags.h index c210e840..7f7cf002 100644 --- a/libnymea-app/types/tags.h +++ b/libnymea-app/types/tags.h @@ -55,7 +55,7 @@ public: Q_INVOKABLE Tag* get(int index) const; Q_INVOKABLE Tag* findThingTag(const QUuid &thingId, const QString &tagId) const; - Q_INVOKABLE Tag* findRuleTag(const QString &ruleId, const QString &tagId) const; + Q_INVOKABLE Tag* findRuleTag(const QUuid &ruleId, const QString &tagId) const; void clear(); diff --git a/libnymea-app/types/thing.cpp b/libnymea-app/types/thing.cpp index e2152cf1..6b8d351e 100644 --- a/libnymea-app/types/thing.cpp +++ b/libnymea-app/types/thing.cpp @@ -279,29 +279,29 @@ int Thing::executeAction(const QString &actionName, const QVariantList ¶ms) QDebug operator<<(QDebug &dbg, Thing *thing) { - dbg.nospace() << "Thing: " << thing->name() << " (" << thing->id().toString() << ") Class:" << thing->thingClass()->name() << " (" << thing->thingClassId().toString() << ")" << endl; + dbg.nospace() << "Thing: " << thing->name() << " (" << thing->id().toString() << ") Class:" << thing->thingClass()->name() << " (" << thing->thingClassId().toString() << ")" << Qt::endl; for (int i = 0; i < thing->thingClass()->paramTypes()->rowCount(); i++) { ParamType *pt = thing->thingClass()->paramTypes()->get(i); - Param *p = thing->params()->getParam(pt->id().toString()); + Param *p = thing->params()->getParam(pt->id()); if (p) { - dbg << " Param " << i << ": " << pt->id().toString() << ": " << pt->name() << " = " << p->value() << endl; + dbg << " Param " << i << ": " << pt->id().toString() << ": " << pt->name() << " = " << p->value() << Qt::endl; } else { - dbg << " Param " << i << ": " << pt->id().toString() << ": " << pt->name() << " = " << "*** Unknown value ***" << endl; + dbg << " Param " << i << ": " << pt->id().toString() << ": " << pt->name() << " = " << "*** Unknown value ***" << Qt::endl; } } for (int i = 0; i < thing->thingClass()->settingsTypes()->rowCount(); i++) { ParamType *pt = thing->thingClass()->settingsTypes()->get(i); - Param *p = thing->settings()->getParam(pt->id().toString()); + Param *p = thing->settings()->getParam(pt->id()); if (p) { - dbg << " Setting " << i << ": " << pt->id().toString() << ": " << pt->name() << " = " << p->value() << endl; + dbg << " Setting " << i << ": " << pt->id().toString() << ": " << pt->name() << " = " << p->value() << Qt::endl; } else { - dbg << " Setting " << i << ": " << pt->id().toString() << ": " << pt->name() << " = " << "*** Unknown value ***" << endl; + dbg << " Setting " << i << ": " << pt->id().toString() << ": " << pt->name() << " = " << "*** Unknown value ***" << Qt::endl; } } for (int i = 0; i < thing->thingClass()->stateTypes()->rowCount(); i++) { StateType *st = thing->thingClass()->stateTypes()->get(i); State *s = thing->states()->getState(st->id()); - dbg << " State " << i << ": " << st->id() << ": " << st->name() << " = " << s->value() << endl; + dbg << " State " << i << ": " << st->id() << ": " << st->name() << " = " << s->value() << Qt::endl; } return dbg; } diff --git a/libnymea-app/types/thing.h b/libnymea-app/types/thing.h index 2a731138..c3979537 100644 --- a/libnymea-app/types/thing.h +++ b/libnymea-app/types/thing.h @@ -31,8 +31,7 @@ #include "params.h" #include "states.h" #include "statesproxy.h" - -class ThingClass; +#include "thingclass.h" class ThingManager; class Thing : public QObject diff --git a/libnymea-app/types/thingclass.cpp b/libnymea-app/types/thingclass.cpp index 0ba7f5b5..a9358286 100644 --- a/libnymea-app/types/thingclass.cpp +++ b/libnymea-app/types/thingclass.cpp @@ -321,7 +321,7 @@ void ThingClass::setBrowserItemActionTypes(ActionTypes *browserActionTypes) emit browserItemActionTypesChanged(); } -bool ThingClass::hasActionType(const QString &actionTypeId) +bool ThingClass::hasActionType(const QUuid &actionTypeId) { foreach (ActionType *actionType, m_actionTypes->actionTypes()) { if (actionType->id() == actionTypeId) { diff --git a/libnymea-app/types/thingclass.h b/libnymea-app/types/thingclass.h index 943d4dff..ae4c905d 100644 --- a/libnymea-app/types/thingclass.h +++ b/libnymea-app/types/thingclass.h @@ -133,7 +133,7 @@ public: ActionTypes *browserItemActionTypes() const; void setBrowserItemActionTypes(ActionTypes *browserActionTypes); - Q_INVOKABLE bool hasActionType(const QString &actionTypeId); + Q_INVOKABLE bool hasActionType(const QUuid &actionTypeId); signals: void paramTypesChanged(); diff --git a/libnymea-app/types/timedescriptor.h b/libnymea-app/types/timedescriptor.h index 68c8e08f..06f7c95b 100644 --- a/libnymea-app/types/timedescriptor.h +++ b/libnymea-app/types/timedescriptor.h @@ -29,8 +29,8 @@ #include -class TimeEventItems; -class CalendarItems; +#include "timeeventitems.h" +#include "calendaritems.h" class TimeDescriptor : public QObject { diff --git a/libnymea-app/types/timeeventitem.h b/libnymea-app/types/timeeventitem.h index fbf375a9..dab564d8 100644 --- a/libnymea-app/types/timeeventitem.h +++ b/libnymea-app/types/timeeventitem.h @@ -29,7 +29,7 @@ #include #include -class RepeatingOption; +#include "repeatingoption.h" class TimeEventItem : public QObject { diff --git a/libnymea-app/usermanager.cpp b/libnymea-app/usermanager.cpp index ebc1daf0..1f56581b 100644 --- a/libnymea-app/usermanager.cpp +++ b/libnymea-app/usermanager.cpp @@ -219,7 +219,7 @@ void UserManager::getTokensResponse(int /*commandId*/, const QVariantMap &data) foreach (const QVariant &tokenVariant, data.value("tokenInfoList").toList()) { // qDebug() << "Token received" << tokenVariant.toMap(); QVariantMap token = tokenVariant.toMap(); - QUuid id = token.value("id").toString(); + QUuid id = token.value("id").toUuid(); QString username = token.value("username").toString(); QString deviceName = token.value("deviceName").toString(); QDateTime creationTime = QDateTime::fromSecsSinceEpoch(token.value("creationTime").toInt()); diff --git a/libnymea-app/wifisetup/bluetoothdeviceinfos.cpp b/libnymea-app/wifisetup/bluetoothdeviceinfos.cpp index ef6f3c94..021df6a0 100644 --- a/libnymea-app/wifisetup/bluetoothdeviceinfos.cpp +++ b/libnymea-app/wifisetup/bluetoothdeviceinfos.cpp @@ -176,8 +176,8 @@ QString BluetoothDeviceInfosProxy::filterForServiceUUID() const void BluetoothDeviceInfosProxy::setFilterForServiceUUID(const QString &filterForServiceUUID) { - if (m_filterForServiceUUID != filterForServiceUUID) { - m_filterForServiceUUID = filterForServiceUUID; + if (m_filterForServiceUUID != QBluetoothUuid(filterForServiceUUID)) { + m_filterForServiceUUID = QBluetoothUuid(filterForServiceUUID); emit filterForServiceUUIDChanged(); invalidateFilter(); emit countChanged(); diff --git a/libnymea-app/wifisetup/bluetoothdeviceinfos.h b/libnymea-app/wifisetup/bluetoothdeviceinfos.h index e5f2f60b..cba21deb 100644 --- a/libnymea-app/wifisetup/bluetoothdeviceinfos.h +++ b/libnymea-app/wifisetup/bluetoothdeviceinfos.h @@ -29,6 +29,7 @@ #include #include #include +#include #include "bluetoothdeviceinfo.h" @@ -115,7 +116,7 @@ private: BluetoothDeviceInfos *m_model = nullptr; QStringList m_nameWhitelist; bool m_filterForLowEnergy = false; - QUuid m_filterForServiceUUID; + QBluetoothUuid m_filterForServiceUUID; QString m_filterForName; }; diff --git a/libnymea-app/wifisetup/btwifisetup.cpp b/libnymea-app/wifisetup/btwifisetup.cpp index 64f4fb61..ad153b65 100644 --- a/libnymea-app/wifisetup/btwifisetup.cpp +++ b/libnymea-app/wifisetup/btwifisetup.cpp @@ -99,8 +99,12 @@ void BtWiFiSetup::connectToDevice(const BluetoothDeviceInfo *device) m_accessPoints->clearModel(); }, Qt::QueuedConnection); +#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0) typedef void (QLowEnergyController::*errorsSignal)(QLowEnergyController::Error); connect(m_btController, static_cast(&QLowEnergyController::error), this, [this](QLowEnergyController::Error error){ +#else + connect(m_btController, &QLowEnergyController::errorOccurred, this, [this](QLowEnergyController::Error error){ +#endif qCWarning(dcBtWiFiSetup()) << "Bluetooth error:" << error; emit this->bluetoothConnectionError(); }, Qt::QueuedConnection); @@ -255,7 +259,7 @@ WirelessAccessPoint *BtWiFiSetup::currentConnection() const void BtWiFiSetup::setupServices() { qCDebug(dcBtWiFiSetup()) << "Setting up Bluetooth services"; - m_deviceInformationService = m_btController->createServiceObject(QBluetoothUuid::DeviceInformation, m_btController); + m_deviceInformationService = m_btController->createServiceObject(QBluetoothUuid::ServiceClassUuid::DeviceInformation, m_btController); m_networkService = m_btController->createServiceObject(networkServiceUuid, m_btController); m_wifiService = m_btController->createServiceObject(wifiServiceUuid, m_btController); m_systemService = m_btController->createServiceObject(systemServiceUuid, m_btController); @@ -277,15 +281,15 @@ void BtWiFiSetup::setupServices() if (state != QLowEnergyService::ServiceDiscovered) return; qCDebug(dcBtWiFiSetup()) << "Device info service discovered"; - m_manufacturer = QString::fromUtf8(m_deviceInformationService->characteristic(QBluetoothUuid::ManufacturerNameString).value()); + m_manufacturer = QString::fromUtf8(m_deviceInformationService->characteristic(QBluetoothUuid::CharacteristicType::ManufacturerNameString).value()); emit manufacturerChanged(); - m_modelNumber = QString::fromUtf8(m_deviceInformationService->characteristic(QBluetoothUuid::ModelNumberString).value()); + m_modelNumber = QString::fromUtf8(m_deviceInformationService->characteristic(QBluetoothUuid::CharacteristicType::ModelNumberString).value()); emit modelNumberChanged(); - m_softwareRevision = QString::fromUtf8(m_deviceInformationService->characteristic(QBluetoothUuid::SoftwareRevisionString).value()); + m_softwareRevision = QString::fromUtf8(m_deviceInformationService->characteristic(QBluetoothUuid::CharacteristicType::SoftwareRevisionString).value()); emit softwareRevisionChanged(); - m_firmwareRevision = QString::fromUtf8(m_deviceInformationService->characteristic(QBluetoothUuid::FirmwareRevisionString).value()); + m_firmwareRevision = QString::fromUtf8(m_deviceInformationService->characteristic(QBluetoothUuid::CharacteristicType::FirmwareRevisionString).value()); emit firmwareRevisionChanged(); - m_hardwareRevision = QString::fromUtf8(m_deviceInformationService->characteristic(QBluetoothUuid::HardwareRevisionString).value()); + m_hardwareRevision = QString::fromUtf8(m_deviceInformationService->characteristic(QBluetoothUuid::CharacteristicType::HardwareRevisionString).value()); emit hardwareRevisionChanged(); }); m_deviceInformationService->discoverDetails(); @@ -305,9 +309,9 @@ void BtWiFiSetup::setupServices() return; } // Enable notifications - m_networkService->writeDescriptor(networkCharacteristic.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); - m_networkService->writeDescriptor(networkingEnabledCharacteristic.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); - m_networkService->writeDescriptor(wirelessEnabledCharacteristic.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); + m_networkService->writeDescriptor(networkCharacteristic.descriptor(QBluetoothUuid::DescriptorType::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); + m_networkService->writeDescriptor(networkingEnabledCharacteristic.descriptor(QBluetoothUuid::DescriptorType::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); + m_networkService->writeDescriptor(wirelessEnabledCharacteristic.descriptor(QBluetoothUuid::DescriptorType::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); m_networkStatus = static_cast(networkCharacteristic.value().toHex().toUInt(nullptr, 16)); emit networkStatusChanged(); @@ -330,8 +334,8 @@ void BtWiFiSetup::setupServices() m_wifiService->readCharacteristic(m_wifiService->characteristic(wifiServiceVersionCharacteristicUuid)); // Enable notifations - m_wifiService->writeDescriptor(m_wifiService->characteristic(wifiResponseCharacteristicUuid).descriptor(QBluetoothUuid::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); - m_wifiService->writeDescriptor(m_wifiService->characteristic(wifiStatusCharacteristicUuid).descriptor(QBluetoothUuid::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); + m_wifiService->writeDescriptor(m_wifiService->characteristic(wifiResponseCharacteristicUuid).descriptor(QBluetoothUuid::DescriptorType::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); + m_wifiService->writeDescriptor(m_wifiService->characteristic(wifiStatusCharacteristicUuid).descriptor(QBluetoothUuid::DescriptorType::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); qCDebug(dcBtWiFiSetup()) << "Fetching networks after init"; loadNetworks(); @@ -347,7 +351,7 @@ void BtWiFiSetup::setupServices() if (state != QLowEnergyService::ServiceDiscovered) return; qCDebug(dcBtWiFiSetup()) << "System service discovered"; - m_systemService->writeDescriptor(m_systemService->characteristic(systemResponseCharacteristicUuid).descriptor(QBluetoothUuid::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); + m_systemService->writeDescriptor(m_systemService->characteristic(systemResponseCharacteristicUuid).descriptor(QBluetoothUuid::DescriptorType::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); }); m_systemService->discoverDetails(); } diff --git a/libnymea-app/wifisetup/btwifisetup.h b/libnymea-app/wifisetup/btwifisetup.h index 22d5f8bc..854496c6 100644 --- a/libnymea-app/wifisetup/btwifisetup.h +++ b/libnymea-app/wifisetup/btwifisetup.h @@ -28,10 +28,9 @@ #include #include #include - -class BluetoothDeviceInfo; -class WirelessAccessPoints; -class WirelessAccessPoint; +#include "types/wirelessaccesspoint.h" +#include "types/wirelessaccesspoints.h" +#include "bluetoothdeviceinfo.h" class BtWiFiSetup : public QObject { diff --git a/libnymea-app/zigbee/zigbeeadaptersproxy.h b/libnymea-app/zigbee/zigbeeadaptersproxy.h index b065a3ba..afd7afaf 100644 --- a/libnymea-app/zigbee/zigbeeadaptersproxy.h +++ b/libnymea-app/zigbee/zigbeeadaptersproxy.h @@ -28,8 +28,9 @@ #include #include +#include "zigbeemanager.h" + class ZigbeeAdapter; -class ZigbeeManager; class ZigbeeAdaptersProxy : public QSortFilterProxyModel { diff --git a/libnymea-app/zigbee/zigbeemanager.h b/libnymea-app/zigbee/zigbeemanager.h index 8613e4d0..268150c9 100644 --- a/libnymea-app/zigbee/zigbeemanager.h +++ b/libnymea-app/zigbee/zigbeemanager.h @@ -26,13 +26,11 @@ #define ZIGBEEMANAGER_H #include -#include "zigbeeadapter.h" +#include "zigbeeadapters.h" +#include "zigbeenetworks.h" +#include "engine.h" -class Engine; class JsonRpcClient; -class ZigbeeAdapters; -class ZigbeeNetwork; -class ZigbeeNetworks; class ZigbeeNode; class ZigbeeNodes; class ZigbeeNodeBinding; diff --git a/libnymea-app/zigbee/zigbeenodes.h b/libnymea-app/zigbee/zigbeenodes.h index 42657aa4..bfd69e8c 100644 --- a/libnymea-app/zigbee/zigbeenodes.h +++ b/libnymea-app/zigbee/zigbeenodes.h @@ -78,4 +78,6 @@ protected: }; +Q_DECLARE_METATYPE(ZigbeeNodes*) + #endif // ZIGBEENODES_H diff --git a/libnymea-app/zigbee/zigbeenodesproxy.h b/libnymea-app/zigbee/zigbeenodesproxy.h index cf4929e2..e63eacb3 100644 --- a/libnymea-app/zigbee/zigbeenodesproxy.h +++ b/libnymea-app/zigbee/zigbeenodesproxy.h @@ -29,7 +29,7 @@ #include #include "zigbeenode.h" -class ZigbeeNodes; +#include "zigbeenodes.h" class ZigbeeNodesProxy : public QSortFilterProxyModel { diff --git a/nymea-app/dashboard/dashboarditem.h b/nymea-app/dashboard/dashboarditem.h index 4f14a6d9..79025521 100644 --- a/nymea-app/dashboard/dashboarditem.h +++ b/nymea-app/dashboard/dashboarditem.h @@ -28,8 +28,8 @@ #include #include #include +#include "dashboardmodel.h" -class DashboardModel; class DashboardItem : public QObject { diff --git a/nymea-app/main.cpp b/nymea-app/main.cpp index 0e8a6d7a..6fc679c7 100644 --- a/nymea-app/main.cpp +++ b/nymea-app/main.cpp @@ -32,6 +32,12 @@ #include #include #include "utils/qhashqml.h" +#include +#include +#include +#include +#include +#include #include "libnymea-app-core.h" #include "libnymea-app-airconditioning.h" @@ -139,8 +145,10 @@ int main(int argc, char *argv[]) QString defaultStyle; if (parser.isSet(defaultStyleOption)) { defaultStyle = parser.value(defaultStyleOption); +#ifndef DISABLE_DARK_MODE } else if (PlatformHelper::instance()->darkModeEnabled()) { defaultStyle = "dark"; +#endif } else { defaultStyle = "light"; } diff --git a/nymea-app/nfchelper.cpp b/nymea-app/nfchelper.cpp index c36c48bb..6e07bc6b 100644 --- a/nymea-app/nfchelper.cpp +++ b/nymea-app/nfchelper.cpp @@ -48,5 +48,9 @@ QObject *NfcHelper::nfcHelperProvider(QQmlEngine */*engine*/, QJSEngine */*scrip bool NfcHelper::isAvailable() const { QNearFieldManager manager; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) return manager.isAvailable(); +#else + return manager.isEnabled(); +#endif } diff --git a/nymea-app/nfcthingactionwriter.cpp b/nymea-app/nfcthingactionwriter.cpp index 4a13cebd..6634965e 100644 --- a/nymea-app/nfcthingactionwriter.cpp +++ b/nymea-app/nfcthingactionwriter.cpp @@ -46,7 +46,11 @@ NfcThingActionWriter::NfcThingActionWriter(QObject *parent): connect(m_actions, &RuleActions::countChanged, this, &NfcThingActionWriter::updateContent); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) m_manager->startTargetDetection(); +#else + m_manager->startTargetDetection(QNearFieldTarget::AnyAccess); +#endif } @@ -57,7 +61,11 @@ NfcThingActionWriter::~NfcThingActionWriter() bool NfcThingActionWriter::isAvailable() const { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) return m_manager->isAvailable(); +#else + return m_manager->isEnabled(); +#endif } Engine *NfcThingActionWriter::engine() const @@ -126,11 +134,11 @@ void NfcThingActionWriter::updateContent() if (!m_engine || !m_thing) { return; } - url.setHost(m_engine->jsonRpcClient()->currentHost()->uuid().toString().remove(QRegExp("[{}]"))); + url.setHost(m_engine->jsonRpcClient()->currentHost()->uuid().toString().remove(QRegularExpression("[{}]"))); QUrlQuery query; - query.addQueryItem("t", m_thing->id().toString().remove(QRegExp("[{}]"))); + query.addQueryItem("t", m_thing->id().toString().remove(QRegularExpression("[{}]"))); for (int i = 0; i < m_actions->rowCount(); i++) { RuleAction *action = m_actions->get(i); @@ -172,17 +180,6 @@ void NfcThingActionWriter::targetDetected(QNearFieldTarget *target) { QDateTime startTime = QDateTime::currentDateTime(); qDebug() << "target detected"; - connect(target, &QNearFieldTarget::error, this, [=](QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id){ - Q_UNUSED(id) - qDebug() << "Tag error:" << error; - m_status = TagStatusFailed; - emit statusChanged(); - }); - connect(target, &QNearFieldTarget::ndefMessagesWritten, this, [=](){ - qDebug() << "Tag written in" << startTime.msecsTo(QDateTime::currentDateTime()); - m_status = TagStatusWritten; - emit statusChanged(); - }); QNearFieldTarget::RequestId m_request = target->writeNdefMessages(QList() << m_currentMessage); if (!m_request.isValid()) { @@ -191,6 +188,20 @@ void NfcThingActionWriter::targetDetected(QNearFieldTarget *target) emit statusChanged(); } + connect(target, &QNearFieldTarget::error, this, [=](QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id){ + Q_UNUSED(id) + qDebug() << "Tag error:" << error; + m_status = TagStatusFailed; + emit statusChanged(); + }); + connect(target, &QNearFieldTarget::requestCompleted, this, [=](const QNearFieldTarget::RequestId &id){ + if (id == m_request) { + qDebug() << "Tag written in" << startTime.msecsTo(QDateTime::currentDateTime()); + m_status = TagStatusWritten; + emit statusChanged(); + } + }); + m_status = TagStatusWriting; emit statusChanged(); } diff --git a/nymea-app/resources.qrc b/nymea-app/resources.qrc index 0271f7d5..5030b43d 100644 --- a/nymea-app/resources.qrc +++ b/nymea-app/resources.qrc @@ -322,5 +322,6 @@ ui/system/ServerLoggingCategoriesPage.qml ui/components/BackgroundFocusHandler.qml ui/components/LicenseInformationItem.qml + ui/shaders/coloricon.frag.qsb diff --git a/nymea-app/ui/MainPage.qml b/nymea-app/ui/MainPage.qml index 3e81459f..38303ebb 100644 --- a/nymea-app/ui/MainPage.qml +++ b/nymea-app/ui/MainPage.qml @@ -29,7 +29,7 @@ import QtQuick.Layouts 1.2 import QtQuick.Window 2.3 import Qt.labs.settings 1.0 import Qt.labs.folderlistmodel 2.2 -import QtGraphicalEffects 1.0 +import Qt5Compat.GraphicalEffects import Nymea 1.0 import "components" import "delegates" diff --git a/nymea-app/ui/components/ColorIcon.qml b/nymea-app/ui/components/ColorIcon.qml index 3fbd1674..ad60559c 100644 --- a/nymea-app/ui/components/ColorIcon.qml +++ b/nymea-app/ui/components/ColorIcon.qml @@ -23,7 +23,6 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ import QtQuick 2.4 -import QtGraphicalEffects 1.0 import Nymea 1.0 Item { @@ -72,16 +71,6 @@ Item { property color inColor: "#808080" property real threshold: 0.1 - fragmentShader: " - varying highp vec2 qt_TexCoord0; - uniform sampler2D source; - uniform highp vec4 outColor; - uniform highp vec4 inColor; - uniform lowp float threshold; - uniform lowp float qt_Opacity; - void main() { - lowp vec4 sourceColor = texture2D(source, qt_TexCoord0); - gl_FragColor = mix(vec4(outColor.rgb, 1.0) * sourceColor.a, sourceColor, step(threshold, distance(sourceColor.rgb / sourceColor.a, inColor.rgb))) * qt_Opacity; - }" + fragmentShader: "/ui/shaders/coloricon.frag.qsb" } } diff --git a/nymea-app/ui/components/MainPageTile.qml b/nymea-app/ui/components/MainPageTile.qml index 8a74179a..ecfe5d13 100644 --- a/nymea-app/ui/components/MainPageTile.qml +++ b/nymea-app/ui/components/MainPageTile.qml @@ -27,7 +27,7 @@ import QtQuick.Controls 2.2 import QtQuick.Controls.Material 2.2 import QtQuick.Layouts 1.3 import Nymea 1.0 -import QtGraphicalEffects 1.0 +import Qt5Compat.GraphicalEffects Item { id: root diff --git a/nymea-app/ui/components/MediaPlayer.qml b/nymea-app/ui/components/MediaPlayer.qml index c455f42b..ec8078ed 100644 --- a/nymea-app/ui/components/MediaPlayer.qml +++ b/nymea-app/ui/components/MediaPlayer.qml @@ -29,6 +29,7 @@ import QtQuick.Layouts 1.2 import Nymea 1.0 import NymeaApp.Utils 1.0 import QtGraphicalEffects 1.0 +import Qt5Compat.GraphicalEffects import "../delegates" import "../utils" diff --git a/nymea-app/ui/components/NymeaToolTip.qml b/nymea-app/ui/components/NymeaToolTip.qml index f9376b0b..34d31aa6 100644 --- a/nymea-app/ui/components/NymeaToolTip.qml +++ b/nymea-app/ui/components/NymeaToolTip.qml @@ -23,7 +23,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ import QtQuick 2.3 -import QtGraphicalEffects 1.0 +import Qt5Compat.GraphicalEffects import Nymea 1.0 Item { diff --git a/nymea-app/ui/mainviews/EnergyView.qml b/nymea-app/ui/mainviews/EnergyView.qml index 8b3f758d..327fb800 100644 --- a/nymea-app/ui/mainviews/EnergyView.qml +++ b/nymea-app/ui/mainviews/EnergyView.qml @@ -26,7 +26,7 @@ import QtQuick 2.8 import QtQuick.Controls 2.1 import QtQuick.Controls.Material 2.1 import QtQuick.Layouts 1.2 -import QtGraphicalEffects 1.0 +import Qt5Compat.GraphicalEffects import QtCharts 2.2 import Nymea 1.0 import "../components" diff --git a/nymea-app/ui/mainviews/energy/ConsumersBarChart.qml b/nymea-app/ui/mainviews/energy/ConsumersBarChart.qml new file mode 100644 index 00000000..02a73b17 --- /dev/null +++ b/nymea-app/ui/mainviews/energy/ConsumersBarChart.qml @@ -0,0 +1,165 @@ +import QtQuick 2.0 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 2.3 +import Nymea 1.0 +import "qrc:/ui/components" + +Item { + id: root + + property EnergyManager energyManager: null + + property ThingsProxy consumers: ThingsProxy { + engine: _engine + shownInterfaces: ["smartmeterconsumer"] + } + + property var colors: null + + property int tickCount: 5 + + property int labelsWidth: 40 + + + QtObject { + id: d + property int topMargin: Style.margins + property int bottomMargin: Style.margins + property int leftMargin: Style.margins + property int rightMargin: Style.margins + } + + ColumnLayout { + anchors.fill: parent + anchors.margins: Style.smallMargins + Label { + text: qsTr("Consumers") + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + + Item { + id: valueAxis + Layout.fillWidth: true + Layout.fillHeight: true + + property double max: Math.ceil(root.energyManager.currentPowerConsumption / 100) * 100 + Repeater { + model: root.tickCount + delegate: RowLayout { + width: parent.width - d.leftMargin - d.rightMargin + y: index * ((parent.height - d.topMargin - d.bottomMargin - Style.iconSize - Style.margins) / (root.tickCount - 1)) - height / 2 + d.topMargin + x: d.leftMargin + Label { + property double value: (valueAxis.max - index * (valueAxis.max / (root.tickCount - 1))) + text: (value >= 1000 ? (value / 1000).toFixed(2) : value.toFixed(1)) + (value >= 1000 ? "kW" : "W") + font: Style.extraSmallFont + Layout.preferredWidth: root.labelsWidth + } + Rectangle { + Layout.preferredHeight: 1 + Layout.fillWidth: true + color: Style.tileOverlayColor + } + } + } + + RowLayout { + anchors.fill: parent + anchors.topMargin: d.topMargin + anchors.leftMargin: root.labelsWidth + d.leftMargin + anchors.bottomMargin: d.bottomMargin + anchors.rightMargin: d.rightMargin + + Repeater { + model: consumers.count + 1 + + delegate: ColumnLayout { + id: consumerDelegate + Layout.fillHeight: true + Layout.preferredWidth: root.width / consumers.count + spacing: Style.margins + property Thing thing: consumers.get(index) + property State currentPowerState: thing ? thing.stateByName("currentPower") : null + + property double consumption: { + var consumption = 0 + if (thing) { + consumption = currentPowerState.value + } else { + consumption = energyManager.currentPowerConsumption + for (var i = 0; i < consumers.count; i++) { + consumption -= consumers.get(i).stateByName("currentPower").value + } + } + return consumption; + } + + Item { + Layout.fillHeight: true + Layout.fillWidth: true + + Rectangle { + id: bar + anchors { + bottom: parent.bottom + horizontalCenter: parent.horizontalCenter + top: parent.top + } + gradient: Gradient { + GradientStop { position: 1; color: Style.green } + GradientStop { position: 0.5; color: Style.orange } + GradientStop { position: 0; color: Style.red } + } + width: 20 + visible: false + } + + Item { + id: barMask + anchors.fill: bar + Rectangle { + anchors { + bottom: parent.bottom + horizontalCenter: parent.horizontalCenter + } + width: 20 + Behavior on height { NumberAnimation { duration: Style.slowAnimationDuration; easing.type: Easing.InOutQuad } } + height: Math.max(1, parent.height * consumerDelegate.consumption / valueAxis.max) + // visible: false + } + } + + + OpacityMask { + anchors.fill: bar + source: bar + maskSource: barMask + } + + Label { + anchors.bottom: bar.bottom + anchors.left: bar.left + text: consumerDelegate.thing ? consumerDelegate.thing.name : qsTr("Unknown") + transform: Rotation { + angle: -90 + } + } + + } + Item { + Layout.fillWidth: true + Layout.preferredHeight: Style.iconSize + + ColorIcon { + anchors.centerIn: parent + name: consumerDelegate.thing ? app.interfacesToIcon(consumerDelegate.thing.thingClass.interfaces) : "energy" + color: root.colors[index % root.colors.length] + } + } + } + } + } + } + } +} diff --git a/nymea-app/ui/mainviews/energy/ConsumersPieChart.qml b/nymea-app/ui/mainviews/energy/ConsumersPieChart.qml index 84fc85bf..a184af1c 100644 --- a/nymea-app/ui/mainviews/energy/ConsumersPieChart.qml +++ b/nymea-app/ui/mainviews/energy/ConsumersPieChart.qml @@ -26,7 +26,6 @@ import QtQuick 2.8 import QtQuick.Controls 2.1 import QtQuick.Controls.Material 2.1 import QtQuick.Layouts 1.2 -import QtGraphicalEffects 1.0 import QtCharts 2.2 import Nymea 1.0 import NymeaApp.Utils 1.0 diff --git a/nymea-app/ui/mainviews/energy/CurrentConsumptionBalancePieChart.qml b/nymea-app/ui/mainviews/energy/CurrentConsumptionBalancePieChart.qml index 532f356c..1029f685 100644 --- a/nymea-app/ui/mainviews/energy/CurrentConsumptionBalancePieChart.qml +++ b/nymea-app/ui/mainviews/energy/CurrentConsumptionBalancePieChart.qml @@ -26,7 +26,6 @@ import QtQuick 2.8 import QtQuick.Controls 2.1 import QtQuick.Controls.Material 2.1 import QtQuick.Layouts 1.2 -import QtGraphicalEffects 1.0 import QtCharts 2.2 import Nymea 1.0 import NymeaApp.Utils 1.0 diff --git a/nymea-app/ui/mainviews/energy/CurrentProductionBalancePieChart.qml b/nymea-app/ui/mainviews/energy/CurrentProductionBalancePieChart.qml index a13c149a..b7117836 100644 --- a/nymea-app/ui/mainviews/energy/CurrentProductionBalancePieChart.qml +++ b/nymea-app/ui/mainviews/energy/CurrentProductionBalancePieChart.qml @@ -26,7 +26,6 @@ import QtQuick 2.8 import QtQuick.Controls 2.1 import QtQuick.Controls.Material 2.1 import QtQuick.Layouts 1.2 -import QtGraphicalEffects 1.0 import QtCharts 2.2 import Nymea 1.0 import NymeaApp.Utils 1.0 diff --git a/nymea-app/ui/mainviews/energy/PowerConsumptionBalanceHistory.qml b/nymea-app/ui/mainviews/energy/PowerConsumptionBalanceHistory.qml index 784d1f64..b567052b 100644 --- a/nymea-app/ui/mainviews/energy/PowerConsumptionBalanceHistory.qml +++ b/nymea-app/ui/mainviews/energy/PowerConsumptionBalanceHistory.qml @@ -25,7 +25,7 @@ import QtQuick 2.0 import QtCharts 2.2 import QtQuick.Layouts 1.2 -import QtQuick.Controls 2.2 +import QtQuick.Controls 2.3 import Nymea 1.0 import "qrc:/ui/components" diff --git a/nymea-app/ui/shaders/coloricon.frag b/nymea-app/ui/shaders/coloricon.frag new file mode 100644 index 00000000..bdae5db2 --- /dev/null +++ b/nymea-app/ui/shaders/coloricon.frag @@ -0,0 +1,19 @@ +#version 440 + +layout(location = 0) in vec2 qt_TexCoord0; +layout(location = 0) out vec4 fragColor; + +layout(binding = 1) uniform sampler2D source; + +layout(std140, binding = 0) uniform buf { + mat4 qt_Matrix; + float qt_Opacity; + vec4 inColor; + vec4 outColor; + float threshold; +} ubuf; + +void main() { + lowp vec4 sourceColor = texture(source, qt_TexCoord0); + fragColor = mix(vec4(ubuf.outColor.rgb, 1.0) * sourceColor.a, sourceColor, step(ubuf.threshold, distance(sourceColor.rgb / sourceColor.a, ubuf.inColor.rgb))) * ubuf.qt_Opacity; +} diff --git a/nymea-app/ui/shaders/coloricon.frag.qsb b/nymea-app/ui/shaders/coloricon.frag.qsb new file mode 100644 index 00000000..a3d95cb2 Binary files /dev/null and b/nymea-app/ui/shaders/coloricon.frag.qsb differ