1
0
Fork 0

Delete and modify Remote-canvas configs

This commit is contained in:
James Turner 2017-11-03 15:45:44 +00:00
parent 623305965b
commit 81a753cfa1
3 changed files with 58 additions and 25 deletions

View file

@ -59,13 +59,11 @@ void ApplicationController::save(QString configName)
{ {
QDir d(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); QDir d(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
if (!d.exists()) { if (!d.exists()) {
qWarning() << "creating" << d;
d.mkpath("."); d.mkpath(".");
} }
// convert spaces to underscores // convert spaces to underscores
QString filesystemCleanName = configName.replace(QRegularExpression("[\\s-\\\"/]"), "_"); QString filesystemCleanName = configName.replace(QRegularExpression("[\\s-\\\"/]"), "_");
qDebug() << Q_FUNC_INFO << "FS clean name is " << filesystemCleanName;
QFile f(d.filePath(configName + ".json")); QFile f(d.filePath(configName + ".json"));
if (f.exists()) { if (f.exists()) {
@ -162,6 +160,33 @@ void ApplicationController::restoreConfig(int index)
restoreState(f.readAll()); 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) void ApplicationController::openCanvas(QString path)
{ {
CanvasConnection* cc = new CanvasConnection(this); CanvasConnection* cc = new CanvasConnection(this);

View file

@ -53,6 +53,8 @@ public:
Q_INVOKABLE void clearQuery(); Q_INVOKABLE void clearQuery();
Q_INVOKABLE void restoreConfig(int index); Q_INVOKABLE void restoreConfig(int index);
Q_INVOKABLE void deleteConfig(int index);
Q_INVOKABLE void saveConfigChanges(int index);
Q_INVOKABLE void openCanvas(QString path); Q_INVOKABLE void openCanvas(QString path);
@ -111,6 +113,8 @@ private:
void rebuildConfigData(); void rebuildConfigData();
void clearConnections(); void clearConnections();
void doSaveToFile(QString path, QString configName);
QByteArray saveState(QString name) const; QByteArray saveState(QString name) const;
void restoreState(QByteArray bytes); void restoreState(QByteArray bytes);

View file

@ -18,39 +18,43 @@ Item {
border.width: 1 border.width: 1
color: "#5f5f5f" color: "#5f5f5f"
opacity: 0.8 opacity: 0.8
layer.enabled: true
Column { InputLine {
spacing: 8 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.top: parent.top
anchors.topMargin: 8 anchors.topMargin: 8
anchors.horizontalCenter: parent.horizontalCenter
InputLine { onClicked: {
id: saveTitleInput _application.save(saveTitleInput.text);
width: parent.width
label: "Title"
}
Button {
id: saveButton
label: "Save"
enabled: (saveTitleInput.text != "")
onClicked: {
_application.save(saveTitleInput.text);
}
} }
} }
ListView { ListView {
id: savedList id: savedList
model: _application.configs model: _application.configs
width: parent.width - 30 width: parent.width - 30
anchors.top: savePanelContent.bottom anchors.top: saveTitleInput.bottom
anchors.topMargin: 8 anchors.topMargin: 8
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.bottomMargin: 8 anchors.bottomMargin: 8
@ -74,7 +78,7 @@ Item {
anchors.rightMargin: 8 anchors.rightMargin: 8
label: "Delete" label: "Delete"
onClicked: { onClicked: {
_application.deleteConfig(model.index)
} }
} }
@ -84,7 +88,7 @@ Item {
anchors.rightMargin: 8 anchors.rightMargin: 8
label: "Save" label: "Save"
onClicked: { onClicked: {
_application.saveConfigChanges(model.index)
} }
} }
} }