- cleanup
- fixed bug in AppSettings class
This commit is contained in:
parent
c227748ff6
commit
6cf67334c5
4 changed files with 88 additions and 88 deletions
|
@ -5,19 +5,17 @@ AppSettings * pGlobalAppSettings = nullptr;
|
||||||
AppSettings::AppSettings(QObject* parent)
|
AppSettings::AppSettings(QObject* parent)
|
||||||
:QObject(parent)
|
:QObject(parent)
|
||||||
{
|
{
|
||||||
qDebug() << "+----- AppSettings konstruktor -----+";
|
qDebug() << "+ --- AppSettings konstruktor --- +";
|
||||||
|
|
||||||
pGlobalAppSettings = this;
|
pGlobalAppSettings = this;
|
||||||
|
|
||||||
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
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->settingsManager = new QSettings(path+"/settings.ini", QSettings::IniFormat);
|
||||||
|
|
||||||
this->filtersFile = new QFile(path + "/fannyapp/filters.json");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AppSettings::loadSetting(const QString &key)
|
QString AppSettings::read(QString key)
|
||||||
{
|
{
|
||||||
this->settingsManager->beginGroup("AppSettings");
|
this->settingsManager->beginGroup("AppSettings");
|
||||||
QString value = this->settingsManager->value(key , false).toString();
|
QString value = this->settingsManager->value(key , false).toString();
|
||||||
|
@ -25,7 +23,7 @@ QString AppSettings::loadSetting(const QString &key)
|
||||||
return(value);
|
return(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppSettings::writeSetting(const QString &key, const QVariant &variant)
|
void AppSettings::write(QString key, QVariant variant)
|
||||||
{
|
{
|
||||||
this->settingsManager->beginGroup("AppSettings");
|
this->settingsManager->beginGroup("AppSettings");
|
||||||
this->settingsManager->setValue(key , variant);
|
this->settingsManager->setValue(key , variant);
|
||||||
|
|
|
@ -16,18 +16,14 @@ public:
|
||||||
explicit AppSettings(QObject *parent = nullptr);
|
explicit AppSettings(QObject *parent = nullptr);
|
||||||
~AppSettings();
|
~AppSettings();
|
||||||
|
|
||||||
Q_INVOKABLE QString loadSetting(const QString &key);
|
private:
|
||||||
Q_INVOKABLE void writeSetting(const QString &key, const QVariant &variant);
|
|
||||||
|
|
||||||
QList<QStringList> readFilters();
|
|
||||||
void writeFilters(QList<QStringList> list);
|
|
||||||
|
|
||||||
QSettings *settingsManager;
|
QSettings *settingsManager;
|
||||||
QFile * filtersFile;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
Q_INVOKABLE QString read(QString key);
|
||||||
|
Q_INVOKABLE void write(QString key, QVariant variant);
|
||||||
};
|
};
|
||||||
extern AppSettings * pGlobalAppSettings;
|
extern AppSettings * pGlobalAppSettings;
|
||||||
|
|
||||||
|
|
|
@ -18,20 +18,17 @@
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
AppSettings * pAppSettings = new AppSettings();
|
|
||||||
|
|
||||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
QQuickStyle::setStyle("Material");
|
QQuickStyle::setStyle("Material");
|
||||||
|
|
||||||
|
qmlRegisterType<AppSettings>("com.itsblue.dasschmalter", 1, 0, "AppSettings");
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
||||||
|
|
||||||
QQmlContext *context = engine.rootContext();
|
|
||||||
context->setContextProperty("_cppAppSettings", pAppSettings);
|
|
||||||
|
|
||||||
if (engine.rootObjects().isEmpty())
|
if (engine.rootObjects().isEmpty())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import QtQuick 2.9
|
import QtQuick 2.9
|
||||||
import QtQuick.Window 2.2
|
import QtQuick.Window 2.2
|
||||||
import QtQuick.Controls 2.4
|
import QtQuick.Controls 2.4
|
||||||
|
import com.itsblue.dasschmalter 1.0
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
visible: true
|
visible: true
|
||||||
|
@ -13,7 +14,11 @@ Window {
|
||||||
state: "CONNECTING"
|
state: "CONNECTING"
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
property string ipAdress: _cppAppSettings.loadSetting("ip-adress")
|
property string ipAdress: settings.read("ip-adress")
|
||||||
|
|
||||||
|
AppSettings {
|
||||||
|
id: settings
|
||||||
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
id: currentStateLa
|
id: currentStateLa
|
||||||
|
@ -220,10 +225,10 @@ Window {
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
id: settingsIpAdressTf
|
id: settingsIpAdressTf
|
||||||
text: _cppAppSettings.loadSetting("ip-adress")
|
text: settings.read("ip-adress")
|
||||||
anchors.verticalCenter: settingsIpAdressLa.verticalCenter
|
anchors.verticalCenter: settingsIpAdressLa.verticalCenter
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
_cppAppSettings.writeSetting("ip-adress", text)
|
settings.write("ip-adress", text)
|
||||||
app.ipAdress = 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 getState(){
|
||||||
// function to sync the state of the app with the state of the schmalter
|
// function to sync the state of the app with the state of the schmalter
|
||||||
sendRequest("http://"+app.ipAdress+"/api/state")
|
sendRequest("http://"+app.ipAdress+"/api/state")
|
||||||
|
@ -314,71 +389,5 @@ Window {
|
||||||
function landscape(){
|
function landscape(){
|
||||||
return(app.width > app.height)
|
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; }
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue