- 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)
|
||||
: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);
|
||||
|
|
|
@ -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<QStringList> readFilters();
|
||||
void writeFilters(QList<QStringList> 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;
|
||||
|
||||
|
|
|
@ -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<AppSettings>("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;
|
||||
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue