mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-08 12:39:49 -06:00
Allow the ScriptlogDialog to return multiple scripts; Make use of the Dialog in the Properties panel (closes #2253)
This commit is contained in:
@@ -58,7 +58,7 @@ private:
|
||||
void clearActionFields();
|
||||
void actionRejected();
|
||||
void chooseScripts();
|
||||
void appendScriptsToTextfield(std::string scripts);
|
||||
void appendScriptsToTextfield(std::vector<std::string> scripts);
|
||||
|
||||
openspace::Profile::Keybinding* selectedKeybinding();
|
||||
void keybindingAdd();
|
||||
|
||||
@@ -52,7 +52,7 @@ private:
|
||||
*
|
||||
* \param scripts #std::string scripts to be appended
|
||||
*/
|
||||
void appendScriptsToTextfield(std::string scripts);
|
||||
void appendScriptsToTextfield(std::vector<std::string> scripts);
|
||||
|
||||
std::vector<std::string>* _scripts = nullptr;
|
||||
std::vector<std::string> _scriptsData;
|
||||
|
||||
@@ -34,10 +34,10 @@ class QPushButton;
|
||||
class ScriptlogDialog final : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ScriptlogDialog(QWidget* parent);
|
||||
ScriptlogDialog(QWidget* parent, std::string filter = "");
|
||||
|
||||
signals:
|
||||
void scriptsSelected(std::string script);
|
||||
void scriptsSelected(std::vector<std::string> script);
|
||||
|
||||
private:
|
||||
void createWidgets();
|
||||
@@ -52,6 +52,8 @@ private:
|
||||
QPushButton* _reloadFile = nullptr;
|
||||
std::string _scriptLogFile;
|
||||
std::vector<std::string> _scripts;
|
||||
|
||||
std::string _fixedFilter;
|
||||
};
|
||||
|
||||
#endif // __OPENSPACE_UI_LAUNCHER___SCRIPTLOGDIALOG___H__
|
||||
|
||||
@@ -649,12 +649,17 @@ void ActionDialog::actionRejected() {
|
||||
|
||||
void ActionDialog::chooseScripts() {
|
||||
ScriptlogDialog d(this);
|
||||
connect(&d, &ScriptlogDialog::scriptsSelected, this, &ActionDialog::appendScriptsToTextfield);
|
||||
connect(
|
||||
&d, &ScriptlogDialog::scriptsSelected,
|
||||
this, &ActionDialog::appendScriptsToTextfield
|
||||
);
|
||||
d.exec();
|
||||
}
|
||||
|
||||
void ActionDialog::appendScriptsToTextfield(std::string scripts) {
|
||||
_actionWidgets.script->append(QString::fromStdString(std::move(scripts)));
|
||||
void ActionDialog::appendScriptsToTextfield(std::vector<std::string> scripts) {
|
||||
for (std::string script : scripts) {
|
||||
_actionWidgets.script->append(QString::fromStdString(std::move(script)));
|
||||
}
|
||||
}
|
||||
|
||||
Profile::Keybinding* ActionDialog::selectedKeybinding() {
|
||||
|
||||
@@ -109,6 +109,8 @@ void AdditionalScriptsDialog::chooseScripts() {
|
||||
d.exec();
|
||||
}
|
||||
|
||||
void AdditionalScriptsDialog::appendScriptsToTextfield(std::string scripts) {
|
||||
_textScripts->append(QString::fromStdString(std::move(scripts)));
|
||||
void AdditionalScriptsDialog::appendScriptsToTextfield(std::vector<std::string> scripts) {
|
||||
for (std::string script : scripts) {
|
||||
_textScripts->append(QString::fromStdString(std::move(script)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "profile/propertiesdialog.h"
|
||||
|
||||
#include "profile/line.h"
|
||||
#include "profile/scriptlogdialog.h"
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <QComboBox>
|
||||
#include <QDialogButtonBox>
|
||||
@@ -92,17 +93,17 @@ void PropertiesDialog::createWidgets() {
|
||||
|
||||
box->addStretch();
|
||||
|
||||
layout->addLayout(box);
|
||||
}
|
||||
layout->addWidget(new Line);
|
||||
{
|
||||
_fillFromScriptLog = new QPushButton("Fill from ScriptLog");
|
||||
connect(
|
||||
_fillFromScriptLog, &QPushButton::clicked,
|
||||
this, &PropertiesDialog::selectLineFromScriptLog
|
||||
);
|
||||
layout->addWidget(_fillFromScriptLog);
|
||||
box->addWidget(_fillFromScriptLog);
|
||||
|
||||
layout->addLayout(box);
|
||||
}
|
||||
layout->addWidget(new Line);
|
||||
{
|
||||
_commandLabel = new QLabel("Property Set Command");
|
||||
layout->addWidget(_commandLabel);
|
||||
|
||||
@@ -339,7 +340,6 @@ void PropertiesDialog::transitionFromEditMode() {
|
||||
}
|
||||
|
||||
void PropertiesDialog::editBoxDisabled(bool disabled) {
|
||||
_fillFromScriptLog->setDisabled(disabled);
|
||||
_commandLabel->setDisabled(disabled);
|
||||
_commandCombo->setDisabled(disabled);
|
||||
_propertyLabel->setDisabled(disabled);
|
||||
@@ -374,91 +374,52 @@ void PropertiesDialog::keyPressEvent(QKeyEvent* 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;
|
||||
|
||||
ScriptlogDialog d(this, "openspace.setPropertyValue");
|
||||
connect(
|
||||
&dialog, &QDialog::finished,
|
||||
[this, comboBox](int result) {
|
||||
if (result == QDialog::Rejected) {
|
||||
return;
|
||||
&d, &ScriptlogDialog::scriptsSelected,
|
||||
[this](std::vector<std::string> scripts) {
|
||||
for (const std::string& script : scripts) {
|
||||
listItemAdded();
|
||||
|
||||
QString text = QString::fromStdString(script);
|
||||
if (!text.startsWith("openspace.setPropertyValue")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We have a string that is of the form:
|
||||
// openspace.setPropertyValue('prop', value);
|
||||
if (text.startsWith("openspace.setPropertyValueSingle")) {
|
||||
_commandCombo->setCurrentIndex(0);
|
||||
std::string_view prefix = "openspace.setPropertyValueSingle";
|
||||
text = text.mid(static_cast<int>(prefix.size()) + 1); // +1 for (
|
||||
}
|
||||
else {
|
||||
// command == "openspace.setPropertyValue"
|
||||
_commandCombo->setCurrentIndex(1);
|
||||
std::string_view prefix = "openspace.setPropertyValue";
|
||||
text = text.mid(static_cast<int>(prefix.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());
|
||||
listItemSave();
|
||||
}
|
||||
|
||||
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")) {
|
||||
_commandCombo->setCurrentIndex(0);
|
||||
std::string_view prefix = "openspace.setPropertyValueSingle";
|
||||
text = text.mid(static_cast<int>(prefix.size()) + 1); // +1 for (
|
||||
}
|
||||
else {
|
||||
// command == "openspace.setPropertyValue"
|
||||
_commandCombo->setCurrentIndex(1);
|
||||
std::string_view prefix = "openspace.setPropertyValue";
|
||||
text = text.mid(static_cast<int>(prefix.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();
|
||||
d.exec();
|
||||
}
|
||||
|
||||
@@ -40,9 +40,10 @@
|
||||
#include <QPushButton>
|
||||
#include <QTextStream>
|
||||
|
||||
ScriptlogDialog::ScriptlogDialog(QWidget* parent)
|
||||
ScriptlogDialog::ScriptlogDialog(QWidget* parent, std::string filter)
|
||||
: QDialog(parent)
|
||||
, _scriptLogFile(openspace::global::configuration->scriptLog)
|
||||
, _fixedFilter(std::move(filter))
|
||||
{
|
||||
setWindowTitle("Scriptlog");
|
||||
createWidgets();
|
||||
@@ -151,7 +152,10 @@ void ScriptlogDialog::updateScriptList() {
|
||||
int index = -1;
|
||||
_scriptlogList->clear();
|
||||
for (const std::string& script : _scripts) {
|
||||
if (script.find(filter) != std::string::npos) {
|
||||
bool foundDynamic = script.find(filter) != std::string::npos;
|
||||
bool foundStatic =
|
||||
_fixedFilter.empty() ? true : script.find(_fixedFilter) != std::string::npos;
|
||||
if (foundDynamic && foundStatic) {
|
||||
if (script == selection && index == -1) {
|
||||
index = _scriptlogList->count();
|
||||
}
|
||||
@@ -161,15 +165,11 @@ void ScriptlogDialog::updateScriptList() {
|
||||
}
|
||||
|
||||
void ScriptlogDialog::saveChosenScripts() {
|
||||
std::string chosenScripts;
|
||||
std::vector<std::string> chosenScripts;
|
||||
QList<QListWidgetItem*> itemList = _scriptlogList->selectedItems();
|
||||
for (int i = 0; i < itemList.size(); ++i) {
|
||||
chosenScripts += itemList.at(i)->text().toStdString();
|
||||
if (i < itemList.size()) {
|
||||
chosenScripts += "\n";
|
||||
}
|
||||
for (QListWidgetItem* item : _scriptlogList->selectedItems()) {
|
||||
chosenScripts.push_back(item->text().toStdString());
|
||||
}
|
||||
emit scriptsSelected(chosenScripts);
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user