From 6cf67334c506d2606d299821c30564eac1b33b2a Mon Sep 17 00:00:00 2001 From: dorian Date: Sat, 16 Mar 2019 19:57:03 +0100 Subject: [PATCH] - cleanup - fixed bug in AppSettings class --- DasSchmalterApp/Qt-Code/appsettings.cpp | 12 +- DasSchmalterApp/Qt-Code/appsettings.h | 10 +- DasSchmalterApp/Qt-Code/main.cpp | 7 +- DasSchmalterApp/Qt-Code/main.qml | 147 +++++++++++++----------- 4 files changed, 88 insertions(+), 88 deletions(-) diff --git a/DasSchmalterApp/Qt-Code/appsettings.cpp b/DasSchmalterApp/Qt-Code/appsettings.cpp index dda6ee3..509fe4c 100644 --- a/DasSchmalterApp/Qt-Code/appsettings.cpp +++ b/DasSchmalterApp/Qt-Code/appsettings.cpp @@ -5,19 +5,17 @@ AppSettings * pGlobalAppSettings = nullptr; AppSettings::AppSettings(QObject* parent) :QObject(parent) { - qDebug() << "+----- AppSettings konstruktor -----+"; + qDebug() << "+ --- AppSettings konstruktor --- +"; pGlobalAppSettings = this; QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); - qDebug() << "+----- Settings Path:" << path << " -----+"; + qDebug() << "+ --- Settings Path:" << path << " --- +"; - this->settingsManager = new QSettings(path+"/fannyapp/settings.ini", QSettings::IniFormat); - - this->filtersFile = new QFile(path + "/fannyapp/filters.json"); + this->settingsManager = new QSettings(path+"/settings.ini", QSettings::IniFormat); } -QString AppSettings::loadSetting(const QString &key) +QString AppSettings::read(QString key) { this->settingsManager->beginGroup("AppSettings"); QString value = this->settingsManager->value(key , false).toString(); @@ -25,7 +23,7 @@ QString AppSettings::loadSetting(const QString &key) return(value); } -void AppSettings::writeSetting(const QString &key, const QVariant &variant) +void AppSettings::write(QString key, QVariant variant) { this->settingsManager->beginGroup("AppSettings"); this->settingsManager->setValue(key , variant); diff --git a/DasSchmalterApp/Qt-Code/appsettings.h b/DasSchmalterApp/Qt-Code/appsettings.h index 5c37d3d..4a6ecb6 100644 --- a/DasSchmalterApp/Qt-Code/appsettings.h +++ b/DasSchmalterApp/Qt-Code/appsettings.h @@ -16,18 +16,14 @@ public: explicit AppSettings(QObject *parent = nullptr); ~AppSettings(); - Q_INVOKABLE QString loadSetting(const QString &key); - Q_INVOKABLE void writeSetting(const QString &key, const QVariant &variant); - - QList readFilters(); - void writeFilters(QList list); - +private: QSettings *settingsManager; - QFile * filtersFile; signals: public slots: + Q_INVOKABLE QString read(QString key); + Q_INVOKABLE void write(QString key, QVariant variant); }; extern AppSettings * pGlobalAppSettings; diff --git a/DasSchmalterApp/Qt-Code/main.cpp b/DasSchmalterApp/Qt-Code/main.cpp index 764e366..ac1103f 100644 --- a/DasSchmalterApp/Qt-Code/main.cpp +++ b/DasSchmalterApp/Qt-Code/main.cpp @@ -18,20 +18,17 @@ int main(int argc, char *argv[]) { - AppSettings * pAppSettings = new AppSettings(); - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQuickStyle::setStyle("Material"); + qmlRegisterType("com.itsblue.dasschmalter", 1, 0, "AppSettings"); + QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); - QQmlContext *context = engine.rootContext(); - context->setContextProperty("_cppAppSettings", pAppSettings); - if (engine.rootObjects().isEmpty()) return -1; diff --git a/DasSchmalterApp/Qt-Code/main.qml b/DasSchmalterApp/Qt-Code/main.qml index 7ed20d5..9b869d6 100644 --- a/DasSchmalterApp/Qt-Code/main.qml +++ b/DasSchmalterApp/Qt-Code/main.qml @@ -1,6 +1,7 @@ import QtQuick 2.9 import QtQuick.Window 2.2 import QtQuick.Controls 2.4 +import com.itsblue.dasschmalter 1.0 Window { visible: true @@ -13,7 +14,11 @@ Window { state: "CONNECTING" anchors.fill: parent - property string ipAdress: _cppAppSettings.loadSetting("ip-adress") + property string ipAdress: settings.read("ip-adress") + + AppSettings { + id: settings + } Label { id: currentStateLa @@ -220,10 +225,10 @@ Window { } TextField { id: settingsIpAdressTf - text: _cppAppSettings.loadSetting("ip-adress") + text: settings.read("ip-adress") anchors.verticalCenter: settingsIpAdressLa.verticalCenter onTextChanged: { - _cppAppSettings.writeSetting("ip-adress", text) + settings.write("ip-adress", text) app.ipAdress = text } } @@ -232,6 +237,76 @@ Window { } + Timer { + id: refreshTimer + running: true + repeat: false + interval: 100 + onTriggered: { + // sync state + app.getState(); + } + } + + states: [ + State { + name: "ON" + PropertyChanges { target: onOffBt; opacity: 1; enabled: true; } + + PropertyChanges { target: lampOn0; opacity: 1; } + PropertyChanges { target: lampOn1; scale: 1; } + PropertyChanges { target: lampOn2; scale: 1; } + PropertyChanges { target: lampOn3; scale: 1; } + PropertyChanges { target: lampOn4; scale: 1; } + PropertyChanges { target: lampOn5; scale: 1; } + + PropertyChanges { target: lampCrossLineRa; opacity: 0; } + }, + State { + name: "OFF" + PropertyChanges { target: onOffBt; opacity: 1; enabled: true; } + + PropertyChanges { target: lampOn0; opacity: 0; } + PropertyChanges { target: lampOn1; scale: 0; } + PropertyChanges { target: lampOn2; scale: 0; } + PropertyChanges { target: lampOn3; scale: 0; } + PropertyChanges { target: lampOn4; scale: 0; } + PropertyChanges { target: lampOn5; scale: 0; } + + PropertyChanges { target: lampCrossLineRa; opacity: 0; } + }, + State { + name: "ERROR" + PropertyChanges { target: onOffBt; opacity: 0.5; enabled: false; } + + PropertyChanges { target: lampOn0; opacity: 0; } + PropertyChanges { target: lampOn1; scale: 0; } + PropertyChanges { target: lampOn2; scale: 0; } + PropertyChanges { target: lampOn3; scale: 0; } + PropertyChanges { target: lampOn4; scale: 0; } + PropertyChanges { target: lampOn5; scale: 0; } + + PropertyChanges { target: lampCrossLineRa; opacity: 1; } + }, + State { + name: "CONNECTING" + PropertyChanges { target: onOffBt; opacity: 0.5; enabled: false; } + + PropertyChanges { target: lampOn0; opacity: 0; } + PropertyChanges { target: lampOn1; scale: 0; } + PropertyChanges { target: lampOn2; scale: 0; } + PropertyChanges { target: lampOn3; scale: 0; } + PropertyChanges { target: lampOn4; scale: 0; } + PropertyChanges { target: lampOn5; scale: 0; } + + PropertyChanges { target: lampCrossLineRa; opacity: 0; } + } + ] + + // ----------------- + // --- functions --- + // ----------------- + function getState(){ // function to sync the state of the app with the state of the schmalter sendRequest("http://"+app.ipAdress+"/api/state") @@ -314,71 +389,5 @@ Window { function landscape(){ return(app.width > app.height) } - - Timer { - id: refreshTimer - running: true - repeat: false - interval: 100 - onTriggered: { - // sync state - app.getState(); - } - } - - states: [ - State { - name: "ON" - PropertyChanges { target: onOffBt; opacity: 1; enabled: true; } - - PropertyChanges { target: lampOn0; opacity: 1; } - PropertyChanges { target: lampOn1; scale: 1; } - PropertyChanges { target: lampOn2; scale: 1; } - PropertyChanges { target: lampOn3; scale: 1; } - PropertyChanges { target: lampOn4; scale: 1; } - PropertyChanges { target: lampOn5; scale: 1; } - - PropertyChanges { target: lampCrossLineRa; opacity: 0; } - }, - State { - name: "OFF" - PropertyChanges { target: onOffBt; opacity: 1; enabled: true; } - - PropertyChanges { target: lampOn0; opacity: 0; } - PropertyChanges { target: lampOn1; scale: 0; } - PropertyChanges { target: lampOn2; scale: 0; } - PropertyChanges { target: lampOn3; scale: 0; } - PropertyChanges { target: lampOn4; scale: 0; } - PropertyChanges { target: lampOn5; scale: 0; } - - PropertyChanges { target: lampCrossLineRa; opacity: 0; } - }, - State { - name: "ERROR" - PropertyChanges { target: onOffBt; opacity: 0.5; enabled: false; } - - PropertyChanges { target: lampOn0; opacity: 0; } - PropertyChanges { target: lampOn1; scale: 0; } - PropertyChanges { target: lampOn2; scale: 0; } - PropertyChanges { target: lampOn3; scale: 0; } - PropertyChanges { target: lampOn4; scale: 0; } - PropertyChanges { target: lampOn5; scale: 0; } - - PropertyChanges { target: lampCrossLineRa; opacity: 1; } - }, - State { - name: "CONNECTING" - PropertyChanges { target: onOffBt; opacity: 0.5; enabled: false; } - - PropertyChanges { target: lampOn0; opacity: 0; } - PropertyChanges { target: lampOn1; scale: 0; } - PropertyChanges { target: lampOn2; scale: 0; } - PropertyChanges { target: lampOn3; scale: 0; } - PropertyChanges { target: lampOn4; scale: 0; } - PropertyChanges { target: lampOn5; scale: 0; } - - PropertyChanges { target: lampCrossLineRa; opacity: 0; } - } - ] } }