Delete and modify Remote-canvas configs
This commit is contained in:
parent
623305965b
commit
81a753cfa1
3 changed files with 58 additions and 25 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue