Commit 3dea3ef5 authored by Alexander Bock's avatar Alexander Bock
Browse files

Add ability to select profile properties from a ScriptLog (closes #1780)

parent 94d9a5a6
Showing with 100 additions and 0 deletions
+100 -0
......@@ -65,6 +65,8 @@ private slots:
void transitionToEditMode();
void parseSelections();
void selectLineFromScriptLog();
private:
void createWidgets();
......@@ -81,6 +83,8 @@ private:
QListWidget* _list = nullptr;
QPushButton* _addButton = nullptr;
QPushButton* _removeButton = nullptr;
QPushButton* _fillFromScriptLog = nullptr;
QLabel* _commandLabel = nullptr;
QComboBox* _commandCombo = nullptr;
QLabel* _propertyLabel = nullptr;
......
......@@ -25,6 +25,7 @@
#include "profile/propertiesdialog.h"
#include "profile/line.h"
#include <ghoul/filesystem/filesystem.h>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QEvent>
......@@ -33,6 +34,7 @@
#include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QTextStream>
#include <QVBoxLayout>
#include <iostream>
......@@ -93,6 +95,13 @@ void PropertiesDialog::createWidgets() {
}
layout->addWidget(new Line);
{
_fillFromScriptLog = new QPushButton("Fill from ScriptLog");
connect(
_fillFromScriptLog, &QPushButton::clicked,
this, &PropertiesDialog::selectLineFromScriptLog
);
layout->addWidget(_fillFromScriptLog);
_commandLabel = new QLabel("Property Set Command");
layout->addWidget(_commandLabel);
......@@ -333,6 +342,7 @@ void PropertiesDialog::transitionFromEditMode() {
}
void PropertiesDialog::editBoxDisabled(bool disabled) {
_fillFromScriptLog->setDisabled(disabled);
_commandLabel->setDisabled(disabled);
_commandCombo->setDisabled(disabled);
_propertyLabel->setDisabled(disabled);
......@@ -368,3 +378,89 @@ void PropertiesDialog::keyPressEvent(QKeyEvent* evt) {
QDialog::keyPressEvent(evt);
}
void PropertiesDialog::selectLineFromScriptLog() {
QComboBox* comboBox = new QComboBox;
QFile file(QString::fromStdString(absPath("${LOGS}/scriptLog.txt").string()));
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
// removing return from a few statments
// these are usually generated by gui panels
line.remove(QRegularExpression("^return "));
if (line.isEmpty()) {
continue;
}
if (!line.startsWith("openspace.setPropertyValue")) {
continue;
}
comboBox->addItem(line);
}
}
QDialog dialog;
connect(&dialog, &QDialog::finished, [this, comboBox](int result) {
if (result == QDialog::Rejected) {
return;
}
QString text = comboBox->currentText();
if (!text.startsWith("openspace.setPropertyValue")) {
return;
}
// We have a string that is of the form:
// openspace.setPropertyValue('prop', value);
if (text.startsWith("openspace.setPropertyValueSingle")) {
using namespace std::string_view_literals;
_commandCombo->setCurrentIndex(0);
text = text.mid("openspace.setPropertyValueSingle"sv.size() + 1); // +1 for (
}
else {
// command == "openspace.setPropertyValue"
using namespace std::string_view_literals;
_commandCombo->setCurrentIndex(1);
text = text.mid("openspace.setPropertyValue"sv.size() + 1); // +1 for (
}
// Remove everything past the closing brace
text = text.left(text.indexOf(")"));
QStringList textList = text.split(",");
if (textList.size() < 2) {
return;
}
// Remove the string markers around the property
QString property = textList[0].mid(1, textList[0].size() - 2);
textList.removeFirst();
QString value = textList.join(",");
_propertyEdit->setText(property.trimmed());
_valueEdit->setText(value.trimmed());
});
QLayout* layout = new QVBoxLayout;
QLabel* label = new QLabel("Select a line from the Script Log to add");
layout->addWidget(label);
layout->addWidget(comboBox);
QDialogButtonBox* bb = new QDialogButtonBox(
QDialogButtonBox::Ok | QDialogButtonBox::Cancel
);
connect(bb, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
connect(bb, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
layout->addWidget(bb);
dialog.setLayout(layout);
dialog.exec();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment