Support for pmodules in profiles

This commit is contained in:
GPayne
2020-09-11 12:45:40 -06:00
parent 66aa8bc4be
commit ef61d0cb81
5 changed files with 660 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ set(HEADER_FILES
include/launcherwindow.h
include/marknodes.h
include/meta.h
include/osmodules.h
include/profileedit.h
include/ui_addedscripts.h
include/ui_assets.h
@@ -41,6 +42,7 @@ set(HEADER_FILES
include/ui_launcherwindow.h
include/ui_marknodes.h
include/ui_meta.h
include/ui_osmodules.h
include/ui_profileedit.h
)
@@ -56,6 +58,7 @@ set(SOURCE_FILES
src/launcherwindow.cpp
src/marknodes.cpp
src/meta.cpp
src/osmodules.cpp
src/profileedit.cpp
)

View File

@@ -0,0 +1,53 @@
#ifndef OSMODULES_H
#define OSMODULES_H
#include <QDialog>
#include <QWidget>
#include <QListWidgetItem>
QT_BEGIN_NAMESPACE
namespace Ui {
class osmodules;
}
QT_END_NAMESPACE
struct Module {
std::string name;
std::string loadedInstruction;
std::string notLoadedInstruction;
};
class osmodules : public QDialog
{
Q_OBJECT
public slots:
void listItemSelected();
void listItemAdded();
void listItemRemove();
void listItemSave();
void listItemCancelSave();
void transitionToEditMode();
void parseSelections();
public:
explicit osmodules(std::vector<Module>& imported, QWidget *parent = nullptr);
~osmodules();
protected:
//void resizeEvent(QResizeEvent* event);
private:
QString createOneLineSummary(Module m);
void transitionFromEditMode();
void editBoxDisabled(bool disabled);
Ui::osmodules *ui;
QWidget* _parent;
std::vector<Module>& _imported;
std::vector<Module> _data;
std::vector<QListWidgetItem*> _modulesListItems;
bool _editModeNewItem = false;
};
#endif // OSMODULES_H

View File

@@ -0,0 +1,160 @@
/********************************************************************************
** Form generated from reading UI file 'osmodules.ui'
**
** Created by: Qt User Interface Compiler version 5.15.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_OSMODULES_H
#define UI_OSMODULES_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDialog>
#include <QtWidgets/QDialogButtonBox>
#include <QtWidgets/QFrame>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QListWidget>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QTextEdit>
QT_BEGIN_NAMESPACE
class Ui_osmodules
{
public:
QDialogButtonBox *buttonBox;
QListWidget *list;
QPushButton *button_add;
QPushButton *button_remove;
QFrame *frame;
QLabel *label_module;
QLabel *label_loaded;
QLabel *label_notLoaded;
QLineEdit *line_module;
QPushButton *button_cancel;
QPushButton *button_save;
QTextEdit *line_loaded;
QTextEdit *line_notLoaded;
void setupUi(QDialog *osmodules)
{
if (osmodules->objectName().isEmpty())
osmodules->setObjectName(QString::fromUtf8("osmodules"));
osmodules->resize(591, 559);
buttonBox = new QDialogButtonBox(osmodules);
buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
buttonBox->setGeometry(QRect(240, 520, 341, 32));
buttonBox->setOrientation(Qt::Horizontal);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
list = new QListWidget(osmodules);
list->setObjectName(QString::fromUtf8("list"));
list->setGeometry(QRect(10, 10, 571, 120));
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(list->sizePolicy().hasHeightForWidth());
list->setSizePolicy(sizePolicy);
list->setMinimumSize(QSize(0, 50));
list->setMaximumSize(QSize(16777215, 120));
QFont font;
font.setFamily(QString::fromUtf8("Arial"));
list->setFont(font);
list->setAlternatingRowColors(true);
list->setMovement(QListView::Free);
list->setResizeMode(QListView::Adjust);
button_add = new QPushButton(osmodules);
button_add->setObjectName(QString::fromUtf8("button_add"));
button_add->setGeometry(QRect(10, 140, 111, 25));
button_remove = new QPushButton(osmodules);
button_remove->setObjectName(QString::fromUtf8("button_remove"));
button_remove->setGeometry(QRect(160, 140, 111, 25));
frame = new QFrame(osmodules);
frame->setObjectName(QString::fromUtf8("frame"));
frame->setGeometry(QRect(10, 190, 571, 311));
frame->setFrameShape(QFrame::StyledPanel);
frame->setFrameShadow(QFrame::Raised);
label_module = new QLabel(frame);
label_module->setObjectName(QString::fromUtf8("label_module"));
label_module->setGeometry(QRect(10, 10, 357, 20));
QFont font1;
font1.setFamily(QString::fromUtf8("Arial"));
font1.setPointSize(12);
label_module->setFont(font1);
label_loaded = new QLabel(frame);
label_loaded->setObjectName(QString::fromUtf8("label_loaded"));
label_loaded->setGeometry(QRect(10, 70, 357, 20));
label_loaded->setFont(font1);
label_notLoaded = new QLabel(frame);
label_notLoaded->setObjectName(QString::fromUtf8("label_notLoaded"));
label_notLoaded->setGeometry(QRect(10, 170, 357, 20));
label_notLoaded->setFont(font1);
line_module = new QLineEdit(frame);
line_module->setObjectName(QString::fromUtf8("line_module"));
line_module->setGeometry(QRect(10, 30, 357, 25));
button_cancel = new QPushButton(frame);
button_cancel->setObjectName(QString::fromUtf8("button_cancel"));
button_cancel->setGeometry(QRect(410, 270, 71, 25));
button_save = new QPushButton(frame);
button_save->setObjectName(QString::fromUtf8("button_save"));
button_save->setGeometry(QRect(490, 270, 71, 25));
line_loaded = new QTextEdit(frame);
line_loaded->setObjectName(QString::fromUtf8("line_loaded"));
line_loaded->setGeometry(QRect(10, 90, 511, 71));
line_notLoaded = new QTextEdit(frame);
line_notLoaded->setObjectName(QString::fromUtf8("line_notLoaded"));
line_notLoaded->setGeometry(QRect(10, 190, 511, 71));
label_module->raise();
label_loaded->raise();
label_notLoaded->raise();
button_save->raise();
button_cancel->raise();
line_module->raise();
line_loaded->raise();
line_notLoaded->raise();
retranslateUi(osmodules);
//QObject::connect(buttonBox, SIGNAL(accepted()), osmodules, SLOT(accept()));
QObject::connect(buttonBox, SIGNAL(rejected()), osmodules, SLOT(reject()));
QMetaObject::connectSlotsByName(osmodules);
} // setupUi
void retranslateUi(QDialog *osmodules)
{
osmodules->setWindowTitle(QCoreApplication::translate("osmodules", "Modules", nullptr));
button_add->setText(QCoreApplication::translate("osmodules", "Add New", nullptr));
button_remove->setText(QCoreApplication::translate("osmodules", "Remove", nullptr));
label_module->setText(QCoreApplication::translate("osmodules", "Module", nullptr));
label_loaded->setText(QCoreApplication::translate("osmodules", "Command if Module is Loaded", nullptr));
label_notLoaded->setText(QCoreApplication::translate("osmodules", "Command if Module is NOT Loaded", nullptr));
#if QT_CONFIG(tooltip)
line_module->setToolTip(QCoreApplication::translate("osmodules", "<html><head/><body><p>Name of OpenSpace module related to this profile</p></body></html>", nullptr));
#endif // QT_CONFIG(tooltip)
#if QT_CONFIG(tooltip)
button_cancel->setToolTip(QCoreApplication::translate("osmodules", "<html><head/><body><p>Cancel adding this module to the above list</p></body></html>", nullptr));
#endif // QT_CONFIG(tooltip)
button_cancel->setText(QCoreApplication::translate("osmodules", "Cancel", nullptr));
#if QT_CONFIG(tooltip)
button_save->setToolTip(QCoreApplication::translate("osmodules", "<html><head/><body><p>Save module changes to the above list</p></body></html>", nullptr));
#endif // QT_CONFIG(tooltip)
button_save->setText(QCoreApplication::translate("osmodules", "Save", nullptr));
#if QT_CONFIG(tooltip)
line_loaded->setToolTip(QCoreApplication::translate("osmodules", "<html><head/><body><p>[OPTIONAL] Lua command(s) to execute if the module is present in the OpenSpace application</p></body></html>", nullptr));
#endif // QT_CONFIG(tooltip)
#if QT_CONFIG(tooltip)
line_notLoaded->setToolTip(QCoreApplication::translate("osmodules", "<html><head/><body><p>[OPTIONAL] Lua command(s) to execute if the module is <span style=\" font-style:italic;\">not </span>present in the OpenSpace application (for example steps to account for a missing module)</p></body></html>", nullptr));
#endif // QT_CONFIG(tooltip)
} // retranslateUi
};
namespace Ui {
class osmodules: public Ui_osmodules {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_OSMODULES_H

View File

@@ -0,0 +1,156 @@
#include "osmodules.h"
#include "./ui_osmodules.h"
#include <qevent.h>
osmodules::osmodules(std::vector<Module>& imported, QWidget *parent)
: QDialog(parent)
, ui(new Ui::osmodules)
, _imported(imported)
, _data(imported)
{
ui->setupUi(this);
for (size_t i = 0; i < _data.size(); ++i) {
_modulesListItems.push_back(new QListWidgetItem(createOneLineSummary(_data[i])));
ui->list->addItem(_modulesListItems[i]);
}
connect(ui->list, SIGNAL(itemSelectionChanged()), this, SLOT(listItemSelected()));
connect(ui->button_add, SIGNAL(clicked()), this, SLOT(listItemAdded()));
connect(ui->button_save, SIGNAL(clicked()), this, SLOT(listItemSave()));
connect(ui->button_cancel, SIGNAL(clicked()), this, SLOT(listItemCancelSave()));
connect(ui->button_remove, SIGNAL(clicked()), this, SLOT(listItemRemove()));
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(parseSelections()));
transitionFromEditMode();
}
QString osmodules::createOneLineSummary(Module m) {
QString summary = QString(m.name.c_str());
bool hasCommandForLoaded = (m.loadedInstruction.length() > 0);
bool hasCommandForNotLoaded = (m.notLoadedInstruction.length() > 0);
if (hasCommandForLoaded && hasCommandForNotLoaded) {
summary += " (commands set for both loaded & not-loaded conditions)";
}
else if (hasCommandForLoaded) {
summary += " (command set only for loaded condition)";
}
else if (hasCommandForNotLoaded) {
summary += " (command set only for NOT loaded condition)";
}
else {
summary += " (no commands set)";
}
return summary;
}
void osmodules::listItemSelected(void) {
QListWidgetItem *item = ui->list->currentItem();
int index = ui->list->row(item);
Module& m = _data[index];
ui->line_module->setText(QString(m.name.c_str()));
ui->line_loaded->setText(QString(m.loadedInstruction.c_str()));
ui->line_notLoaded->setText(QString(m.notLoadedInstruction.c_str()));
transitionToEditMode();
}
void osmodules::listItemAdded(void) {
//Add new line at bottom of props list
_data.push_back({"", "", ""});
_modulesListItems.push_back(new QListWidgetItem(" (Enter details below and click 'Save')"));
ui->list->addItem(_modulesListItems.back());
//Scroll down to that blank line highlighted
ui->list->setCurrentItem(_modulesListItems.back());
//Blank-out the 2 text fields, set combo box to index 0
ui->line_module->setText(QString(_data.back().name.c_str()));
ui->line_loaded->setText(QString(_data.back().loadedInstruction.c_str()));
ui->line_notLoaded->setText(QString(_data.back().notLoadedInstruction.c_str()));
_editModeNewItem = true;
}
void osmodules::listItemSave(void) {
if (ui->line_module->text().length() == 0) {
ui->label_module->setText("<font color='red'>Module</font>");
return;
}
QListWidgetItem *item = ui->list->currentItem();
int index = ui->list->row(item);
_data[index].name = ui->line_module->text().toUtf8().constData();
_data[index].loadedInstruction = ui->line_loaded->toPlainText().toUtf8().constData();
_data[index].notLoadedInstruction = ui->line_notLoaded->toPlainText().toUtf8().constData();
_modulesListItems.at(index)->setText(createOneLineSummary(_data[index]));
transitionFromEditMode();
_editModeNewItem = false;
}
void osmodules::listItemCancelSave(void) {
listItemSelected();
transitionFromEditMode();
if (_editModeNewItem) {
if(_data.back().name.length() == 0) {
listItemRemove();
}
}
_editModeNewItem = false;
}
void osmodules::listItemRemove(void) {
QListWidgetItem *item = ui->list->currentItem();
int index = ui->list->row(item);
ui->list->takeItem(index);
_data.erase(_data.begin() + index);
_modulesListItems.erase(_modulesListItems.begin() + index);
transitionFromEditMode();
}
void osmodules::transitionToEditMode(void) {
ui->list->setDisabled(true);
ui->button_add->setDisabled(true);
ui->button_remove->setDisabled(true);
editBoxDisabled(false);
}
void osmodules::transitionFromEditMode(void) {
ui->list->setDisabled(false);
ui->button_add->setDisabled(false);
ui->button_remove->setDisabled(false);
editBoxDisabled(true);
ui->label_module->setText("<font color='black'>Module</font>");
}
void osmodules::editBoxDisabled(bool disabled) {
ui->label_module->setDisabled(disabled);
ui->line_module->setDisabled(disabled);
ui->label_loaded->setDisabled(disabled);
ui->line_loaded->setDisabled(disabled);
ui->label_notLoaded->setDisabled(disabled);
ui->line_notLoaded->setDisabled(disabled);
ui->button_cancel->setDisabled(disabled);
ui->button_save->setDisabled(disabled);
}
//osmodules::save() {
//
//}
void osmodules::parseSelections() {
_imported = _data;
accept();
}
osmodules::~osmodules() {
for (auto p : _modulesListItems) {
delete p;
}
delete ui;
}

View File

@@ -0,0 +1,288 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>osmodules</class>
<widget class="QDialog" name="osmodules">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>591</width>
<height>559</height>
</rect>
</property>
<property name="windowTitle">
<string>Modules</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>240</x>
<y>520</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QListWidget" name="list">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>571</width>
<height>120</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>120</height>
</size>
</property>
<property name="font">
<font>
<family>Arial</family>
</font>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="movement">
<enum>QListView::Free</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
</widget>
<widget class="QPushButton" name="button_add">
<property name="geometry">
<rect>
<x>10</x>
<y>140</y>
<width>111</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>Add New</string>
</property>
</widget>
<widget class="QPushButton" name="button_remove">
<property name="geometry">
<rect>
<x>160</x>
<y>140</y>
<width>111</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>Remove</string>
</property>
</widget>
<widget class="QFrame" name="frame">
<property name="geometry">
<rect>
<x>10</x>
<y>190</y>
<width>571</width>
<height>311</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QLabel" name="label_module">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>357</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<family>Arial</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Module</string>
</property>
</widget>
<widget class="QLabel" name="label_loaded">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>357</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<family>Arial</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Command if Module is Loaded</string>
</property>
</widget>
<widget class="QLabel" name="label_notLoaded">
<property name="geometry">
<rect>
<x>10</x>
<y>170</y>
<width>357</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<family>Arial</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Command if Module is NOT Loaded</string>
</property>
</widget>
<widget class="QLineEdit" name="line_module">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>357</width>
<height>25</height>
</rect>
</property>
<property name="toolTip">
<string extracomment="Module name is required">&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Name of OpenSpace module related to this profile&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QPushButton" name="button_cancel">
<property name="geometry">
<rect>
<x>410</x>
<y>270</y>
<width>71</width>
<height>25</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Cancel adding this module to the above list&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
<widget class="QPushButton" name="button_save">
<property name="geometry">
<rect>
<x>490</x>
<y>270</y>
<width>71</width>
<height>25</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save module changes to the above list&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Save</string>
</property>
</widget>
<widget class="QTextEdit" name="line_loaded">
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>511</width>
<height>71</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;[OPTIONAL] Lua command(s) to execute if the module is present in the OpenSpace application&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QTextEdit" name="line_notLoaded">
<property name="geometry">
<rect>
<x>10</x>
<y>190</y>
<width>511</width>
<height>71</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;[OPTIONAL] Lua command(s) to execute if the module is &lt;span style=&quot; font-style:italic;&quot;&gt;not &lt;/span&gt;present in the OpenSpace application (for example steps to account for a missing module)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<zorder>label_module</zorder>
<zorder>label_loaded</zorder>
<zorder>label_notLoaded</zorder>
<zorder>button_save</zorder>
<zorder>button_cancel</zorder>
<zorder>line_module</zorder>
<zorder>line_loaded</zorder>
<zorder>line_notLoaded</zorder>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>osmodules</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>osmodules</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>