mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-06 11:29:55 -05:00
Add a filter and reload method for te Script Log window (closes #2019)
This commit is contained in:
@@ -26,16 +26,14 @@
|
||||
#define __OPENSPACE_UI_LAUNCHER___SCRIPTLOG___H__
|
||||
|
||||
#include <QDialog>
|
||||
#include <QListWidget>
|
||||
|
||||
class QLineEdit;
|
||||
class QListWidget;
|
||||
class QPushButton;
|
||||
|
||||
class ScriptlogDialog final : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* Constructor for ScriptlogDialog class
|
||||
*
|
||||
* \param parent Pointer to parent Qt widget
|
||||
*/
|
||||
ScriptlogDialog(QWidget* parent);
|
||||
|
||||
signals:
|
||||
@@ -46,8 +44,13 @@ private slots:
|
||||
|
||||
private:
|
||||
void createWidgets();
|
||||
void loadScriptFile();
|
||||
void updateScriptList();
|
||||
|
||||
QListWidget* _scriptlogList = nullptr;
|
||||
QLineEdit* _filter = nullptr;
|
||||
QPushButton* _reloadFile = nullptr;
|
||||
std::vector<std::string> _scripts;
|
||||
};
|
||||
|
||||
#endif // __OPENSPACE_UI_LAUNCHER___SCRIPTLOG___H__
|
||||
|
||||
@@ -149,25 +149,32 @@ CameraDialog QLabel#error-message {
|
||||
min-width: 10em;
|
||||
}
|
||||
|
||||
/*
|
||||
* ScriptlogDialog
|
||||
*/
|
||||
ScriptlogDialog QListWidget {
|
||||
min-width: 60em;
|
||||
}
|
||||
|
||||
/*
|
||||
* Horizons dialog
|
||||
*/
|
||||
QPlainTextEdit#log {
|
||||
HorizonsDialog QPlainTextEdit#log {
|
||||
font-family: Courier;
|
||||
}
|
||||
|
||||
QComboBox#mono {
|
||||
HorizonsDialog QComboBox#mono {
|
||||
font-family: Courier;
|
||||
}
|
||||
|
||||
QLabel#thin {
|
||||
HorizonsDialog QLabel#thin {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
QLabel#error {
|
||||
HorizonsDialog QLabel#error {
|
||||
color: rgb(221, 17, 17);
|
||||
}
|
||||
|
||||
QLabel#normal {
|
||||
HorizonsDialog QLabel#normal {
|
||||
color: rgb(0, 0, 0);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,10 @@ void AdditionalScriptsDialog::parseScript() {
|
||||
|
||||
void AdditionalScriptsDialog::chooseScripts() {
|
||||
ScriptlogDialog d(this);
|
||||
connect(&d, &ScriptlogDialog::scriptsSelected, this, &AdditionalScriptsDialog::appendScriptsToTextfield);
|
||||
connect(
|
||||
&d, &ScriptlogDialog::scriptsSelected,
|
||||
this, &AdditionalScriptsDialog::appendScriptsToTextfield
|
||||
);
|
||||
d.exec();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,15 +23,21 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include "profile/scriptlogdialog.h"
|
||||
|
||||
#include "profile/line.h"
|
||||
#include <openspace/engine/configuration.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/scene/profile.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/fmt.h>
|
||||
#include <QGridLayout>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QListWidget>
|
||||
#include <QFile>
|
||||
#include <QPushButton>
|
||||
#include <QTextStream>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
ScriptlogDialog::ScriptlogDialog(QWidget* parent)
|
||||
: QDialog(parent)
|
||||
@@ -39,32 +45,52 @@ ScriptlogDialog::ScriptlogDialog(QWidget* parent)
|
||||
setWindowTitle("Scriptlog");
|
||||
createWidgets();
|
||||
|
||||
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()) {
|
||||
_scriptlogList->addItem(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
loadScriptFile();
|
||||
}
|
||||
|
||||
void ScriptlogDialog::createWidgets() {
|
||||
QBoxLayout* layout = new QVBoxLayout(this);
|
||||
// Column 0 Column 1
|
||||
// *-------------------------*------------*
|
||||
// | Title |
|
||||
// *--------------------------------------*
|
||||
// | Filter scripts * Reload |
|
||||
// *--------------------------------------*
|
||||
// | Script list |
|
||||
// *--------------------------------------*
|
||||
// * Save Cancel *
|
||||
// *-------------------------*------------*
|
||||
|
||||
QGridLayout* layout = new QGridLayout;
|
||||
{
|
||||
QLabel* heading = new QLabel("Choose commands from log/scriptLog.txt");
|
||||
QLabel* heading = new QLabel(QString::fromStdString(
|
||||
fmt::format(
|
||||
"Choose commands from \"{}\"",
|
||||
openspace::global::configuration->scriptLog
|
||||
)
|
||||
));
|
||||
heading->setObjectName("heading");
|
||||
layout->addWidget(heading);
|
||||
layout->addWidget(heading, 0, 0, 1, 2);
|
||||
}
|
||||
|
||||
_filter = new QLineEdit;
|
||||
_filter->setPlaceholderText("Filter the list of scripts");
|
||||
connect(
|
||||
_filter, &QLineEdit::textEdited,
|
||||
this, &ScriptlogDialog::updateScriptList
|
||||
);
|
||||
layout->addWidget(_filter, 1, 0);
|
||||
|
||||
_reloadFile = new QPushButton("Reload");
|
||||
_reloadFile->setToolTip("Reload the script log file");
|
||||
connect(
|
||||
_reloadFile, &QPushButton::clicked,
|
||||
this, &ScriptlogDialog::loadScriptFile
|
||||
);
|
||||
layout->addWidget(_reloadFile, 1, 1);
|
||||
|
||||
_scriptlogList = new QListWidget;
|
||||
_scriptlogList->setSelectionMode(QAbstractItemView::SelectionMode::MultiSelection);
|
||||
layout->addWidget(_scriptlogList);
|
||||
layout->addWidget(_scriptlogList, 2, 0, 1, 2);
|
||||
|
||||
layout->addWidget(new Line);
|
||||
{
|
||||
@@ -78,8 +104,48 @@ void ScriptlogDialog::createWidgets() {
|
||||
buttons, &QDialogButtonBox::rejected,
|
||||
this, &ScriptlogDialog::reject
|
||||
);
|
||||
layout->addWidget(buttons);
|
||||
layout->addWidget(buttons, 3, 0, 1, 2);
|
||||
}
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void ScriptlogDialog::loadScriptFile() {
|
||||
std::string log = absPath(openspace::global::configuration->scriptLog).string();
|
||||
QFile file(QString::fromStdString(log));
|
||||
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()) {
|
||||
_scripts.push_back(line.toStdString());
|
||||
}
|
||||
}
|
||||
}
|
||||
updateScriptList();
|
||||
}
|
||||
|
||||
void ScriptlogDialog::updateScriptList() {
|
||||
std::string filter = _filter->text().toStdString();
|
||||
QListWidgetItem* curr = _scriptlogList->currentItem();
|
||||
std::string selection;
|
||||
if (curr) {
|
||||
selection = curr->text().toStdString();
|
||||
}
|
||||
int index = -1;
|
||||
_scriptlogList->clear();
|
||||
for (const std::string& script : _scripts) {
|
||||
if (script.find(filter) != std::string::npos) {
|
||||
if (script == selection && index == -1) {
|
||||
index = _scriptlogList->count();
|
||||
}
|
||||
_scriptlogList->addItem(QString::fromStdString(script));
|
||||
}
|
||||
}
|
||||
_scriptlogList->setCurrentRow(index != -1 ? index : 0);
|
||||
}
|
||||
|
||||
void ScriptlogDialog::saveChosenScripts() {
|
||||
|
||||
Reference in New Issue
Block a user