From 81a753cfa17e23c678f7f4584e3e1fc333eb71a3 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 3 Nov 2017 15:45:44 +0000 Subject: [PATCH] Delete and modify Remote-canvas configs --- utils/fgqcanvas/applicationcontroller.cpp | 29 ++++++++++++- utils/fgqcanvas/applicationcontroller.h | 4 ++ utils/fgqcanvas/qml/LoadSavePanel.qml | 50 ++++++++++++----------- 3 files changed, 58 insertions(+), 25 deletions(-) diff --git a/utils/fgqcanvas/applicationcontroller.cpp b/utils/fgqcanvas/applicationcontroller.cpp index 38c836cab..a899c961e 100644 --- a/utils/fgqcanvas/applicationcontroller.cpp +++ b/utils/fgqcanvas/applicationcontroller.cpp @@ -59,13 +59,11 @@ void ApplicationController::save(QString configName) { QDir d(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); if (!d.exists()) { - qWarning() << "creating" << d; d.mkpath("."); } // convert spaces to underscores QString filesystemCleanName = configName.replace(QRegularExpression("[\\s-\\\"/]"), "_"); - qDebug() << Q_FUNC_INFO << "FS clean name is " << filesystemCleanName; QFile f(d.filePath(configName + ".json")); if (f.exists()) { @@ -162,6 +160,33 @@ void ApplicationController::restoreConfig(int index) restoreState(f.readAll()); } +void ApplicationController::deleteConfig(int index) +{ + QString path = m_configs.at(index).toMap().value("path").toString(); + QFile f(path); + if (!f.remove()) { + qWarning() << "failed to remove file"; + return; + } + + m_configs.removeAt(index); + emit configListChanged(m_configs); +} + +void ApplicationController::saveConfigChanges(int index) +{ + QString path = m_configs.at(index).toMap().value("path").toString(); + QString name = m_configs.at(index).toMap().value("name").toString(); + doSaveToFile(path, name); +} + +void ApplicationController::doSaveToFile(QString path, QString configName) +{ + QFile f(path); + f.open(QIODevice::WriteOnly | QIODevice::Truncate); + f.write(saveState(configName)); +} + void ApplicationController::openCanvas(QString path) { CanvasConnection* cc = new CanvasConnection(this); diff --git a/utils/fgqcanvas/applicationcontroller.h b/utils/fgqcanvas/applicationcontroller.h index 4c846893e..45ec8db6f 100644 --- a/utils/fgqcanvas/applicationcontroller.h +++ b/utils/fgqcanvas/applicationcontroller.h @@ -53,6 +53,8 @@ public: Q_INVOKABLE void clearQuery(); Q_INVOKABLE void restoreConfig(int index); + Q_INVOKABLE void deleteConfig(int index); + Q_INVOKABLE void saveConfigChanges(int index); Q_INVOKABLE void openCanvas(QString path); @@ -111,6 +113,8 @@ private: void rebuildConfigData(); void clearConnections(); + void doSaveToFile(QString path, QString configName); + QByteArray saveState(QString name) const; void restoreState(QByteArray bytes); diff --git a/utils/fgqcanvas/qml/LoadSavePanel.qml b/utils/fgqcanvas/qml/LoadSavePanel.qml index a232b0237..402f0e2ef 100644 --- a/utils/fgqcanvas/qml/LoadSavePanel.qml +++ b/utils/fgqcanvas/qml/LoadSavePanel.qml @@ -18,39 +18,43 @@ Item { border.width: 1 color: "#5f5f5f" opacity: 0.8 + layer.enabled: true - Column { - spacing: 8 + InputLine { + id: saveTitleInput + width: parent.width + label: "Title" + anchors { + top: parent.top + topMargin: 8 + left: parent.left + leftMargin: 8 + right: saveButton.left + rightMargin: 8 + } - id: savePanelContent - width: parent.width - 30 + } + + Button { + id: saveButton + label: "Save" + enabled: (saveTitleInput.text != "") + anchors.right: parent.right + anchors.rightMargin: 8 anchors.top: parent.top anchors.topMargin: 8 - anchors.horizontalCenter: parent.horizontalCenter - InputLine { - id: saveTitleInput - width: parent.width - label: "Title" - - } - - Button { - id: saveButton - label: "Save" - enabled: (saveTitleInput.text != "") - - onClicked: { - _application.save(saveTitleInput.text); - } + onClicked: { + _application.save(saveTitleInput.text); } } + ListView { id: savedList model: _application.configs width: parent.width - 30 - anchors.top: savePanelContent.bottom + anchors.top: saveTitleInput.bottom anchors.topMargin: 8 anchors.bottom: parent.bottom anchors.bottomMargin: 8 @@ -74,7 +78,7 @@ Item { anchors.rightMargin: 8 label: "Delete" onClicked: { - + _application.deleteConfig(model.index) } } @@ -84,7 +88,7 @@ Item { anchors.rightMargin: 8 label: "Save" onClicked: { - + _application.saveConfigChanges(model.index) } } }