mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-07 03:49:43 -05:00
Fixed parse exceptions and improved assets with path and variable name
This commit is contained in:
@@ -21,6 +21,8 @@ class assets : public QDialog
|
||||
public slots:
|
||||
void cancel();
|
||||
void parseSelections();
|
||||
void selected(const QModelIndex&);
|
||||
void setVarName();
|
||||
|
||||
public:
|
||||
explicit assets(openspace::Profile* imported, const std::string reportAssets,
|
||||
@@ -34,13 +36,14 @@ protected:
|
||||
private:
|
||||
void compareFilesystemWithProfileAssets();
|
||||
bool traverseToExpandSelectedItems(int nRows, QModelIndex parent);
|
||||
void findPathMatch(std::string& path, std::string& filename);
|
||||
void findPathMatch(std::string& path, std::string& varName);
|
||||
void traverseToFindFilesystemMatch(QModelIndex parent, int nRows,
|
||||
std::string dirname, std::string filename);
|
||||
std::string dirname, std::string varName);
|
||||
Ui::assets *ui;
|
||||
QWidget* _parent;
|
||||
openspace::Profile* _imported;
|
||||
assetTreeModel _assetTreeModel;
|
||||
QModelIndex _selectedIdx;
|
||||
};
|
||||
|
||||
#endif // ASSETS_H
|
||||
|
||||
@@ -52,6 +52,7 @@ public:
|
||||
void setExistsInFilesystem(bool fileExists);
|
||||
bool doesExistInFilesystem() const;
|
||||
QString name() const;
|
||||
QString varName() const;
|
||||
static const int checkboxColumn = 1;
|
||||
|
||||
private:
|
||||
|
||||
@@ -27,15 +27,17 @@
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include "assettreeitem.h"
|
||||
#include "openspace/scene/profile.h"
|
||||
|
||||
struct importElement
|
||||
{
|
||||
importElement(std::string l, int lev, bool chk)
|
||||
: line(l), level(lev), checked(chk) {}
|
||||
importElement(std::string l, int lev, bool chk, std::string vname)
|
||||
: line(l), level(lev), checked(chk), varname(vname) {}
|
||||
std::string line;
|
||||
int level = -1;
|
||||
bool checked = false;
|
||||
bool existsInFilesystem = true;
|
||||
std::string varname;
|
||||
};
|
||||
|
||||
class assetTreeModel : public QAbstractItemModel
|
||||
@@ -43,7 +45,8 @@ class assetTreeModel : public QAbstractItemModel
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit assetTreeModel(QString header1, QString header2, QObject* parent = nullptr);
|
||||
explicit assetTreeModel(QString header1, QString header2, QString header3,
|
||||
QObject* parent = nullptr);
|
||||
~assetTreeModel();
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
@@ -60,7 +63,7 @@ public:
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole) override;
|
||||
std::vector<std::string> selectedAssets();
|
||||
std::vector<openspace::Profile::Asset> selectedAssets();
|
||||
void importModelData(const std::string contents);
|
||||
bool isChecked(QModelIndex& index) const;
|
||||
bool isAsset(QModelIndex& index) const;
|
||||
@@ -71,12 +74,14 @@ public:
|
||||
void setName(QModelIndex& index, QString name);
|
||||
void setChecked(QModelIndex& index, bool checked);
|
||||
void setExistenceInFilesystem(QModelIndex& index, bool fileExists);
|
||||
QString varName(const QModelIndex& index) const;
|
||||
void setVarName(QModelIndex& index, QString varName);
|
||||
|
||||
private:
|
||||
std::string headerTitle;
|
||||
assetTreeItem *getItem(const QModelIndex &index) const;
|
||||
assetTreeItem *rootItem;
|
||||
void parseChildrenForSelected(assetTreeItem* item, std::vector<std::string>& output,
|
||||
void parseChildrenForSelected(assetTreeItem* item, std::vector<openspace::Profile::Asset>& output,
|
||||
std::string pathPrefix);
|
||||
void importInsertItem(std::istringstream& iss, assetTreeItem* parent,
|
||||
importElement& elem, int level);
|
||||
|
||||
@@ -28,6 +28,8 @@ public:
|
||||
private:
|
||||
void populateProfilesList();
|
||||
void populateWindowConfigsList();
|
||||
bool loadProfileFromFile(openspace::Profile*& p, std::string filename);
|
||||
void displayProfileParseErrorDialogThenQuit(std::string msg);
|
||||
void clearData();
|
||||
void initialize_meta();
|
||||
void initialize_modules();
|
||||
@@ -42,9 +44,9 @@ private:
|
||||
|
||||
Ui::LauncherWindow *ui;
|
||||
ProfileEdit* myEditorWindow;
|
||||
errordialog* _myDialog;
|
||||
filesystemAccess _fileAccess_profiles;
|
||||
filesystemAccess _fileAccess_winConfigs;
|
||||
|
||||
openspace::Profile::Meta _metaData;
|
||||
std::vector<openspace::Profile::Module> _moduleData;
|
||||
std::vector<openspace::Profile::Asset> _assetData;
|
||||
|
||||
@@ -42,13 +42,11 @@ public slots:
|
||||
void approved();
|
||||
|
||||
public:
|
||||
explicit ProfileEdit(std::string filename, const std::string reportedAssets, QWidget *parent = nullptr);
|
||||
explicit ProfileEdit(openspace::Profile* profile, const std::string reportedAssets, QWidget *parent = nullptr);
|
||||
~ProfileEdit();
|
||||
void setProfileName(QString profileToSet);
|
||||
|
||||
private:
|
||||
bool loadProfileFromFile(std::string filename);
|
||||
void displayProfileParseErrorDialogThenQuit(std::string msg);
|
||||
void initSummaryTextForEachCategory();
|
||||
QString summarizeText_meta();
|
||||
QString summarizeText_modules();
|
||||
@@ -63,7 +61,6 @@ private:
|
||||
|
||||
Ui::ProfileEdit *ui;
|
||||
QWidget* _parent;
|
||||
errordialog* _myDialog;
|
||||
meta* _meta;
|
||||
properties* _properties;
|
||||
osmodules* _modules;
|
||||
@@ -74,10 +71,7 @@ private:
|
||||
deltaTimes* _deltaTimes;
|
||||
camera* _camera;
|
||||
markNodes* _markNodes;
|
||||
|
||||
//ProfileBlock _pData;
|
||||
openspace::Profile* _pData = nullptr;
|
||||
std::vector<std::string> _content;
|
||||
openspace::Profile* _pData;
|
||||
const std::string _reportedAssets;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <QtWidgets/QDialogButtonBox>
|
||||
#include <QtWidgets/QHeaderView>
|
||||
#include <QtWidgets/QLabel>
|
||||
#include <QtWidgets/QLineEdit>
|
||||
#include <QtWidgets/QPushButton>
|
||||
#include <QtWidgets/QTreeView>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@@ -23,26 +26,43 @@ class Ui_assets
|
||||
public:
|
||||
QDialogButtonBox *buttonBox;
|
||||
QTreeView *treeView;
|
||||
QPushButton *varName;
|
||||
QLineEdit *lineEdit;
|
||||
QLabel *label;
|
||||
|
||||
void setupUi(QDialog *assets)
|
||||
{
|
||||
if (assets->objectName().isEmpty())
|
||||
assets->setObjectName(QString::fromUtf8("assets"));
|
||||
assets->resize(470, 442);
|
||||
assets->resize(610, 479);
|
||||
buttonBox = new QDialogButtonBox(assets);
|
||||
buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
|
||||
buttonBox->setGeometry(QRect(110, 400, 341, 32));
|
||||
buttonBox->setGeometry(QRect(240, 430, 341, 32));
|
||||
buttonBox->setOrientation(Qt::Horizontal);
|
||||
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
|
||||
treeView = new QTreeView(assets);
|
||||
treeView->setObjectName(QString::fromUtf8("treeView"));
|
||||
treeView->setGeometry(QRect(20, 20, 431, 351));
|
||||
treeView->setGeometry(QRect(20, 20, 571, 351));
|
||||
QFont font;
|
||||
font.setFamily(QString::fromUtf8("Arial"));
|
||||
treeView->setFont(font);
|
||||
treeView->setStyleSheet(QString::fromUtf8("background-color: rgb(85, 87, 83);"));
|
||||
treeView->setAlternatingRowColors(false);
|
||||
treeView->setAnimated(false);
|
||||
varName = new QPushButton(assets);
|
||||
varName->setObjectName(QString::fromUtf8("varName"));
|
||||
varName->setGeometry(QRect(130, 430, 121, 25));
|
||||
lineEdit = new QLineEdit(assets);
|
||||
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
|
||||
lineEdit->setGeometry(QRect(130, 390, 261, 25));
|
||||
label = new QLabel(assets);
|
||||
label->setObjectName(QString::fromUtf8("label"));
|
||||
label->setGeometry(QRect(30, 390, 71, 61));
|
||||
QFont font1;
|
||||
font1.setFamily(QString::fromUtf8("Arial"));
|
||||
font1.setPointSize(12);
|
||||
label->setFont(font1);
|
||||
label->setWordWrap(true);
|
||||
|
||||
retranslateUi(assets);
|
||||
//QObject::connect(buttonBox, SIGNAL(accepted()), assets, SLOT(accept()));
|
||||
@@ -57,6 +77,8 @@ public:
|
||||
#if QT_CONFIG(tooltip)
|
||||
treeView->setToolTip(QCoreApplication::translate("assets", "<html><head/><body><p>Expand arrow entries to browse assets in this OpenSpace installation. Enable checkbox to include an asset. Those assets highlighted in red are present in the profile but do not exist in this OpenSpace installation.</p></body></html>", nullptr));
|
||||
#endif // QT_CONFIG(tooltip)
|
||||
varName->setText(QCoreApplication::translate("assets", "Modify Name", nullptr));
|
||||
label->setText(QCoreApplication::translate("assets", "Optional variable name", nullptr));
|
||||
} // retranslateUi
|
||||
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ assets::assets(openspace::Profile* imported, const std::string reportAssets, QWi
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::assets)
|
||||
, _imported(imported)
|
||||
, _assetTreeModel(tr("Asset"), tr("Enabled"))
|
||||
, _assetTreeModel(tr("Asset"), tr("Enabled"), tr("Var Name"))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@@ -19,15 +19,24 @@ assets::assets(openspace::Profile* imported, const std::string reportAssets, QWi
|
||||
|
||||
ui->treeView->setModel(&_assetTreeModel);
|
||||
ui->treeView->setRootIndex(_assetTreeModel.index(-1, 0));
|
||||
ui->treeView->setColumnWidth(0, ui->treeView->width() * 0.8);
|
||||
ui->treeView->setColumnWidth(0, ui->treeView->width() * 0.63);
|
||||
ui->treeView->setColumnWidth(1, ui->treeView->width() * 0.12);
|
||||
ui->treeView->setColumnWidth(2, ui->treeView->width() * 0.25);
|
||||
ui->treeView->setAnimated(true);
|
||||
ui->treeView->setSortingEnabled(false);
|
||||
ui->treeView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
compareFilesystemWithProfileAssets();
|
||||
|
||||
int nRows = _assetTreeModel.rowCount(_assetTreeModel.index(-1, 0));
|
||||
traverseToExpandSelectedItems(nRows, _assetTreeModel.index(-1, 0));
|
||||
|
||||
connect(ui->treeView,
|
||||
SIGNAL(clicked(const QModelIndex&)),
|
||||
this,
|
||||
SLOT(selected(const QModelIndex&))
|
||||
);
|
||||
connect(ui->varName, SIGNAL(clicked()), this, SLOT(setVarName()));
|
||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(parseSelections()));
|
||||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()));
|
||||
}
|
||||
@@ -38,21 +47,21 @@ void assets::compareFilesystemWithProfileAssets() {
|
||||
}
|
||||
}
|
||||
|
||||
void assets::findPathMatch(std::string& path, std::string& filename) {
|
||||
void assets::findPathMatch(std::string& path, std::string& varName) {
|
||||
QModelIndex parent = _assetTreeModel.index(-1, 0);
|
||||
int nRows = _assetTreeModel.rowCount(parent);
|
||||
traverseToFindFilesystemMatch(parent, nRows, path, filename);
|
||||
traverseToFindFilesystemMatch(parent, nRows, path, varName);
|
||||
}
|
||||
|
||||
void assets::traverseToFindFilesystemMatch(QModelIndex parent, int nRows,
|
||||
std::string path, std::string filename)
|
||||
std::string path, std::string varName)
|
||||
{
|
||||
bool endOfPath = (path.length() == 0);
|
||||
size_t slash = path.find_first_of('/', 0);
|
||||
std::string firstDir = endOfPath ? path : path.substr(0, slash);
|
||||
bool endOfPath = (slash == std::string::npos);
|
||||
std::string firstDir = endOfPath ? "" : path.substr(0, slash);
|
||||
|
||||
if (!endOfPath) {
|
||||
std::string nextPath = (slash == std::string::npos) ? "" :
|
||||
std::string nextPath = (slash == std::string::npos) ? path :
|
||||
path.substr(slash + 1);
|
||||
bool foundDirMatch = false;
|
||||
for (int r = 0; r < nRows; r++) {
|
||||
@@ -62,7 +71,7 @@ void assets::traverseToFindFilesystemMatch(QModelIndex parent, int nRows,
|
||||
if (firstDir.compare(assetName) == 0) {
|
||||
int nChildRows = _assetTreeModel.childCount(idx);
|
||||
foundDirMatch = true;
|
||||
traverseToFindFilesystemMatch(idx, nChildRows, nextPath, filename);
|
||||
traverseToFindFilesystemMatch(idx, nChildRows, nextPath, varName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -72,11 +81,11 @@ void assets::traverseToFindFilesystemMatch(QModelIndex parent, int nRows,
|
||||
}
|
||||
if (!foundDirMatch) {
|
||||
//Insert missing directory here with name and exists=false condition
|
||||
_assetTreeModel.assetItem(parent)->insertChildren(nRows, 1, 2);
|
||||
_assetTreeModel.assetItem(parent)->insertChildren(nRows, 1, 3);
|
||||
QModelIndex idx = _assetTreeModel.index(nRows, 0, parent);
|
||||
_assetTreeModel.setName(idx, QString(firstDir.c_str()));
|
||||
_assetTreeModel.setExistenceInFilesystem(idx, false);
|
||||
traverseToFindFilesystemMatch(idx, 0, nextPath, filename);
|
||||
traverseToFindFilesystemMatch(idx, 0, nextPath, varName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -85,18 +94,20 @@ void assets::traverseToFindFilesystemMatch(QModelIndex parent, int nRows,
|
||||
QModelIndex idx = _assetTreeModel.index(r, 0, parent);
|
||||
std::string assetName = _assetTreeModel.name(idx).toUtf8().constData();
|
||||
|
||||
if (filename.compare(assetName) == 0) {
|
||||
if (path.compare(assetName) == 0) {
|
||||
foundFileMatch = true;
|
||||
_assetTreeModel.setChecked(idx, true);
|
||||
_assetTreeModel.setVarName(idx, QString(varName.c_str()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundFileMatch) {
|
||||
//Insert missing file here with name and exists=false condition
|
||||
_assetTreeModel.assetItem(parent)->insertChildren(nRows, 1, 2);
|
||||
_assetTreeModel.assetItem(parent)->insertChildren(nRows, 1, 3);
|
||||
QModelIndex idx = _assetTreeModel.index(nRows, 0, parent);
|
||||
_assetTreeModel.setName(idx, QString(filename.c_str()));
|
||||
_assetTreeModel.setName(idx, QString(path.c_str()));
|
||||
_assetTreeModel.setChecked(idx, true);
|
||||
_assetTreeModel.setVarName(idx, QString(varName.c_str()));
|
||||
_assetTreeModel.setExistenceInFilesystem(idx, false);
|
||||
}
|
||||
}
|
||||
@@ -124,30 +135,33 @@ bool assets::traverseToExpandSelectedItems(int nRows, QModelIndex parent) {
|
||||
|
||||
std::string assets::createTextSummary() {
|
||||
std::string summary;
|
||||
for (std::string line : _assetTreeModel.selectedAssets()) {
|
||||
summary += line + "\n";
|
||||
for (openspace::Profile::Asset sel : _assetTreeModel.selectedAssets()) {
|
||||
summary += sel.path + " " + sel.name + "\n";
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
|
||||
void assets::parseSelections() {
|
||||
_imported->clearAssets();
|
||||
for (std::string selected : _assetTreeModel.selectedAssets()) {
|
||||
openspace::Profile::Asset a;
|
||||
size_t slash = selected.find_last_of('/');
|
||||
if (slash == std::string::npos) {
|
||||
a.path = "";
|
||||
a.name = selected;
|
||||
}
|
||||
else {
|
||||
a.path = selected.substr(0, slash);
|
||||
a.name = selected.substr(slash + 1);
|
||||
}
|
||||
_imported->addAsset(a.path + "/" + a.name);
|
||||
for (openspace::Profile::Asset sel : _assetTreeModel.selectedAssets()) {
|
||||
_imported->addAsset(sel.path, sel.name);
|
||||
}
|
||||
accept();
|
||||
}
|
||||
|
||||
void assets::selected(const QModelIndex& sel) {
|
||||
_selectedIdx = sel;
|
||||
QString existingVarName = _assetTreeModel.varName(_selectedIdx);
|
||||
ui->lineEdit->setText(existingVarName);
|
||||
}
|
||||
|
||||
void assets::setVarName() {
|
||||
_assetTreeModel.setVarName(_selectedIdx, ui->lineEdit->text());
|
||||
ui->treeView->reset();
|
||||
int nRows = _assetTreeModel.rowCount(_assetTreeModel.index(-1, 0));
|
||||
traverseToExpandSelectedItems(nRows, _assetTreeModel.index(-1, 0));
|
||||
}
|
||||
|
||||
assets::~assets() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>470</width>
|
||||
<height>442</height>
|
||||
<width>610</width>
|
||||
<height>479</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -16,8 +16,8 @@
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>400</y>
|
||||
<x>240</x>
|
||||
<y>430</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
@@ -34,7 +34,7 @@
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>431</width>
|
||||
<width>571</width>
|
||||
<height>351</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -56,6 +56,51 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="varName">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>130</x>
|
||||
<y>430</y>
|
||||
<width>121</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Modify Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="lineEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>130</x>
|
||||
<y>390</y>
|
||||
<width>261</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>390</y>
|
||||
<width>71</width>
|
||||
<height>61</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Optional variable name</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
||||
@@ -105,6 +105,10 @@ QString assetTreeItem::name() const {
|
||||
return QString(data(0).toString());
|
||||
}
|
||||
|
||||
QString assetTreeItem::varName() const {
|
||||
return QString(data(2).toString());
|
||||
}
|
||||
|
||||
bool assetTreeItem::insertChildren(int position, int count, int columns)
|
||||
{
|
||||
if (position < 0 || position > _childItems.size())
|
||||
|
||||
@@ -27,22 +27,22 @@
|
||||
#include <sstream>
|
||||
#include <QColor>
|
||||
|
||||
assetTreeModel::assetTreeModel(QString header1, QString header2, QObject* parent)
|
||||
assetTreeModel::assetTreeModel(QString header1, QString header2, QString header3,
|
||||
QObject* parent)
|
||||
: QAbstractItemModel(parent),
|
||||
headerTitle(header1.toUtf8().constData())
|
||||
{
|
||||
QVector<QVariant> rootData;
|
||||
rootItem = new assetTreeItem({header1, header2});
|
||||
rootItem = new assetTreeItem({header1, header2, header3});
|
||||
}
|
||||
|
||||
|
||||
assetTreeModel::~assetTreeModel() {
|
||||
delete rootItem;
|
||||
}
|
||||
|
||||
void assetTreeModel::importModelData(const std::string contents) {
|
||||
std::istringstream iss(contents.c_str());
|
||||
importElement rootElem = {"", 0, false};
|
||||
importElement rootElem = {"", 0, false, ""};
|
||||
|
||||
if (importGetNextLine(rootElem, iss)) {
|
||||
importInsertItem(iss, rootItem, rootElem, 0);
|
||||
@@ -59,11 +59,12 @@ void assetTreeModel::importInsertItem(std::istringstream& iss, assetTreeItem* pa
|
||||
int levelChange = elem.level - level;
|
||||
|
||||
if (levelChange == 0) {
|
||||
parent->insertChildren(++nChildInsert, 1, 2);
|
||||
parent->insertChildren(++nChildInsert, 1, 3);
|
||||
parent->child(nChildInsert)->setData(0, QString::fromUtf8(elem.line.c_str()));
|
||||
bool shouldMakeElemChecked = (elem.checked || !elem.existsInFilesystem);
|
||||
Qt::CheckState check = (shouldMakeElemChecked) ? Qt::Checked : Qt::Unchecked;
|
||||
parent->child(nChildInsert)->setData(1, check);
|
||||
parent->child(nChildInsert)->setData(2, "");
|
||||
parent->child(nChildInsert)->setExistsInFilesystem(elem.existsInFilesystem);
|
||||
continueToNextLine = importGetNextLine(elem, iss);
|
||||
}
|
||||
@@ -145,6 +146,14 @@ QString assetTreeModel::name(QModelIndex& index) const {
|
||||
return getItem(index)->name();
|
||||
}
|
||||
|
||||
QString assetTreeModel::varName(const QModelIndex& index) const {
|
||||
return getItem(index)->varName();
|
||||
}
|
||||
|
||||
void assetTreeModel::setVarName(QModelIndex& index, QString varName) {
|
||||
getItem(index)->setData(2, varName);
|
||||
}
|
||||
|
||||
void assetTreeModel::setName(QModelIndex& index, QString name) {
|
||||
getItem(index)->setData(0, name);
|
||||
}
|
||||
@@ -166,7 +175,6 @@ assetTreeItem* assetTreeModel::child(int row) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
QModelIndex assetTreeModel::index(int row, int column, const QModelIndex& parent) const {
|
||||
if (parent.isValid() && parent.column() != 0)
|
||||
return QModelIndex();
|
||||
@@ -287,22 +295,24 @@ QVariant assetTreeModel::headerData(int section, Qt::Orientation orientation,
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
std::vector<std::string> assetTreeModel::selectedAssets() {
|
||||
std::vector<std::string> output;
|
||||
std::vector<openspace::Profile::Asset> assetTreeModel::selectedAssets() {
|
||||
std::vector<openspace::Profile::Asset> output;
|
||||
parseChildrenForSelected(rootItem, output, "");
|
||||
return output;
|
||||
}
|
||||
|
||||
void assetTreeModel::parseChildrenForSelected(assetTreeItem* item,
|
||||
std::vector<std::string>& output,
|
||||
std::vector<openspace::Profile::Asset>& output,
|
||||
std::string pathPrefix)
|
||||
{
|
||||
std::string itemName = item->data(0).toString().toUtf8().constData();
|
||||
std::string varName = item->data(2).toString().toUtf8().constData();
|
||||
bool isPathPrefix = ((pathPrefix.length()) == 0 && (itemName == headerTitle));
|
||||
|
||||
if (item->isAsset()) {
|
||||
if (item->isChecked()) {
|
||||
output.push_back(pathPrefix + itemName);
|
||||
std::string path = pathPrefix + itemName;
|
||||
output.push_back(openspace::Profile::Asset({path, varName}));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -55,8 +55,12 @@ void LauncherWindow::populateWindowConfigsList() {
|
||||
|
||||
void LauncherWindow::openWindow_new() {
|
||||
clearData();
|
||||
myEditorWindow = new ProfileEdit("", _reportAssetsInFilesystem);
|
||||
myEditorWindow->exec();
|
||||
openspace::Profile* pData = new openspace::Profile();
|
||||
if (pData != nullptr) {
|
||||
myEditorWindow = new ProfileEdit(pData, _reportAssetsInFilesystem);
|
||||
myEditorWindow->exec();
|
||||
}
|
||||
delete pData;
|
||||
}
|
||||
|
||||
void LauncherWindow::openWindow_edit() {
|
||||
@@ -66,9 +70,71 @@ void LauncherWindow::openWindow_edit() {
|
||||
QString profileToSet = ui->comboBoxProfiles->itemText(selectedProfileIdx);
|
||||
editProfilePath += profileToSet.toUtf8().constData();
|
||||
editProfilePath += ".profile";
|
||||
myEditorWindow = new ProfileEdit(editProfilePath, _reportAssetsInFilesystem);
|
||||
myEditorWindow->setProfileName(profileToSet);
|
||||
myEditorWindow->exec();
|
||||
openspace::Profile* pData;
|
||||
loadProfileFromFile(pData, editProfilePath);
|
||||
if (pData != nullptr) {
|
||||
myEditorWindow = new ProfileEdit(pData, _reportAssetsInFilesystem);
|
||||
myEditorWindow->setProfileName(profileToSet);
|
||||
myEditorWindow->exec();
|
||||
}
|
||||
delete pData;
|
||||
}
|
||||
|
||||
bool LauncherWindow::loadProfileFromFile(openspace::Profile*& p, std::string filename) {
|
||||
std::vector<std::string> content;
|
||||
if (filename.length() > 0) {
|
||||
std::ifstream inFile;
|
||||
try {
|
||||
inFile.open(filename, std::ifstream::in);
|
||||
}
|
||||
catch (const std::ifstream::failure& e) {
|
||||
throw ghoul::RuntimeError(fmt::format(
|
||||
"Exception opening {} profile for read: ({})",
|
||||
filename,
|
||||
e.what()
|
||||
));
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(inFile, line)) {
|
||||
content.push_back(std::move(line));
|
||||
}
|
||||
}
|
||||
try {
|
||||
p = new openspace::Profile(content);
|
||||
}
|
||||
catch (const ghoul::MissingCaseException& e) {
|
||||
displayProfileParseErrorDialogThenQuit(fmt::format(
|
||||
"Missing case exception in {}: {}",
|
||||
filename,
|
||||
e.what()
|
||||
));
|
||||
return false;
|
||||
}
|
||||
catch (const openspace::Profile::ParsingError& e) {
|
||||
displayProfileParseErrorDialogThenQuit(fmt::format(
|
||||
"ParsingError exception in {}: {}, {}",
|
||||
filename,
|
||||
e.component,
|
||||
e.message
|
||||
));
|
||||
return false;
|
||||
}
|
||||
catch (const ghoul::RuntimeError& e) {
|
||||
displayProfileParseErrorDialogThenQuit(fmt::format(
|
||||
"RuntimeError exception in {}, component {}: {}",
|
||||
filename,
|
||||
e.component,
|
||||
e.message
|
||||
));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void LauncherWindow::displayProfileParseErrorDialogThenQuit(std::string msg) {
|
||||
//New instance of info dialog window
|
||||
_myDialog = new errordialog(QString(msg.c_str()));
|
||||
_myDialog->exec();
|
||||
}
|
||||
|
||||
void LauncherWindow::receiveAssets(std::vector<std::string> results) {
|
||||
|
||||
@@ -6,89 +6,32 @@
|
||||
template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
|
||||
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
|
||||
|
||||
ProfileEdit::ProfileEdit(std::string filename, const std::string reportedAssets, QWidget *parent)
|
||||
ProfileEdit::ProfileEdit(openspace::Profile* profile, const std::string reportedAssets, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::ProfileEdit)
|
||||
, _reportedAssets(reportedAssets)
|
||||
, _pData(profile)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
loadProfileFromFile(filename);
|
||||
|
||||
initSummaryTextForEachCategory();
|
||||
connect(ui->edit_meta, SIGNAL(clicked()), this, SLOT(openMeta()));
|
||||
connect(ui->edit_properties, SIGNAL(clicked()), this, SLOT(openProperties()));
|
||||
connect(ui->edit_modules, SIGNAL(clicked()), this, SLOT(openModules()));
|
||||
connect(ui->edit_keybindings, SIGNAL(clicked()), this, SLOT(openKeybindings()));
|
||||
connect(ui->edit_assets, SIGNAL(clicked()), this, SLOT(openAssets()));
|
||||
connect(ui->edit_time, SIGNAL(clicked()), this, SLOT(openTime()));
|
||||
connect(ui->edit_additionalscripts, SIGNAL(clicked()), this, SLOT(openAddedScripts()));
|
||||
connect(ui->edit_deltatimes, SIGNAL(clicked()), this, SLOT(openDeltaTimes()));
|
||||
connect(ui->edit_camera, SIGNAL(clicked()), this, SLOT(openCamera()));
|
||||
connect(ui->edit_marknodes, SIGNAL(clicked()), this, SLOT(openMarkNodes()));
|
||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(approved()));
|
||||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()));
|
||||
if (_pData != nullptr) {
|
||||
initSummaryTextForEachCategory();
|
||||
connect(ui->edit_meta, SIGNAL(clicked()), this, SLOT(openMeta()));
|
||||
connect(ui->edit_properties, SIGNAL(clicked()), this, SLOT(openProperties()));
|
||||
connect(ui->edit_modules, SIGNAL(clicked()), this, SLOT(openModules()));
|
||||
connect(ui->edit_keybindings, SIGNAL(clicked()), this, SLOT(openKeybindings()));
|
||||
connect(ui->edit_assets, SIGNAL(clicked()), this, SLOT(openAssets()));
|
||||
connect(ui->edit_time, SIGNAL(clicked()), this, SLOT(openTime()));
|
||||
connect(ui->edit_additionalscripts, SIGNAL(clicked()), this, SLOT(openAddedScripts()));
|
||||
connect(ui->edit_deltatimes, SIGNAL(clicked()), this, SLOT(openDeltaTimes()));
|
||||
connect(ui->edit_camera, SIGNAL(clicked()), this, SLOT(openCamera()));
|
||||
connect(ui->edit_marknodes, SIGNAL(clicked()), this, SLOT(openMarkNodes()));
|
||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(approved()));
|
||||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()));
|
||||
}
|
||||
}
|
||||
|
||||
ProfileEdit::~ProfileEdit() {
|
||||
delete ui;
|
||||
delete _pData;
|
||||
}
|
||||
|
||||
bool ProfileEdit::loadProfileFromFile(std::string filename) {
|
||||
if (filename.length() > 0) {
|
||||
std::ifstream inFile;
|
||||
try {
|
||||
inFile.open(filename, std::ifstream::in);
|
||||
}
|
||||
catch (const std::ifstream::failure& e) {
|
||||
throw ghoul::RuntimeError(fmt::format(
|
||||
"Exception opening {} profile for read: ({})",
|
||||
filename,
|
||||
e.what()
|
||||
));
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(inFile, line)) {
|
||||
_content.push_back(std::move(line));
|
||||
}
|
||||
}
|
||||
try {
|
||||
_pData = new openspace::Profile(_content);
|
||||
}
|
||||
catch (const ghoul::MissingCaseException& e) {
|
||||
displayProfileParseErrorDialogThenQuit(fmt::format(
|
||||
"Missing case exception in {}: {}",
|
||||
filename,
|
||||
e.what()
|
||||
));
|
||||
return false;
|
||||
}
|
||||
catch (const openspace::Profile::ParsingError& e) {
|
||||
displayProfileParseErrorDialogThenQuit(fmt::format(
|
||||
"ParsingError exception in {}: {}, {}",
|
||||
filename,
|
||||
e.component,
|
||||
e.message
|
||||
));
|
||||
return false;
|
||||
}
|
||||
catch (const ghoul::RuntimeError& e) {
|
||||
displayProfileParseErrorDialogThenQuit(fmt::format(
|
||||
"RuntimeError exception in {}, component {}: {}",
|
||||
filename,
|
||||
e.component,
|
||||
e.message
|
||||
));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProfileEdit::displayProfileParseErrorDialogThenQuit(std::string msg) {
|
||||
//New instance of info dialog window
|
||||
_myDialog = new errordialog(QString(msg.c_str()));
|
||||
_myDialog->exec();
|
||||
cancel();
|
||||
}
|
||||
|
||||
void ProfileEdit::initSummaryTextForEachCategory() {
|
||||
@@ -281,7 +224,7 @@ QString ProfileEdit::summarizeText_assets() {
|
||||
}
|
||||
QString results = QString("<Configured with %1 assets>\n").arg(_pData->assets().size());
|
||||
for (openspace::Profile::Asset a : _pData->assets()) {
|
||||
results += " " + QString(a.path.c_str()) + "/";
|
||||
results += " " + QString(a.path.c_str()) + " ";
|
||||
results += QString(a.name.c_str()) + "\n";
|
||||
}
|
||||
return results;
|
||||
@@ -384,7 +327,6 @@ QString ProfileEdit::summarizeText_markNodes() {
|
||||
|
||||
void ProfileEdit::cancel() {
|
||||
reject();
|
||||
rejected();
|
||||
}
|
||||
|
||||
void ProfileEdit::approved() {
|
||||
|
||||
@@ -24,7 +24,7 @@ SHIFT+i Undo Insight landing layers setup Unset Insight layers /Missions/Insight
|
||||
absolute 2018 NOV 26 19:39:03.68
|
||||
|
||||
#Camera
|
||||
setNavigationState insightAsset.Insight.Identifier "Root" 8.430115E0, -1.791710E1, 2.813660E0 0.494659E0,0.357162E0,0.792306E0
|
||||
setNavigationState insightAsset.Insight.Identifier "Root" 8.430115E0, -1.791710E1, 2.813660E0 0.494659E0, 0.357162E0, 0.792306E0
|
||||
|
||||
#MarkNodes
|
||||
Insight
|
||||
|
||||
@@ -31,7 +31,7 @@ p Enables or disables the image projection on 67P. Toggle 67P projection /Missio
|
||||
absolute 2014-08-01T03:05:00.000
|
||||
|
||||
#Camera
|
||||
setNavigationState Comet67PAsset.Comet67P.Identifier "Root" -7.294781E5 , -6.657894E5, 2.509047E6 0.146529E0, 0.944727E0, 0.293290E0
|
||||
setNavigationState Comet67PAsset.Comet67P.Identifier "Root" -7.294781E5, -6.657894E5, 2.509047E6 0.146529E0, 0.944727E0, 0.293290E0
|
||||
|
||||
#MarkNodes
|
||||
67P
|
||||
|
||||
@@ -18,7 +18,7 @@ setPropertyValueSingle Scene.PlutoBarycenterTrail.Renderable.Enabled false
|
||||
relative -1d
|
||||
|
||||
#Camera
|
||||
setNavigationState earthAsset.Earth.Identifier 58.5877,16.1924,20000000
|
||||
setNavigationState earthAsset.Earth.Identifier 58.5877, 16.1924, 20000000
|
||||
|
||||
#MarkNodes
|
||||
Earth
|
||||
|
||||
@@ -141,7 +141,7 @@ public:
|
||||
void setIgnoreUpdates(bool ignoreUpdates);
|
||||
|
||||
/// Adds a new asset and checks for duplicates
|
||||
void addAsset(const std::string& path);
|
||||
void addAsset(const std::string& path, const std::string& varName = "");
|
||||
|
||||
/// Removes an asset
|
||||
void removeAsset(const std::string& path);
|
||||
|
||||
+19
-9
@@ -364,15 +364,24 @@ namespace {
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<std::string> up = ghoul::tokenizeString(fields[5], ' ');
|
||||
std::vector<std::string> up = ghoul::tokenizeString(fields[5], ',');
|
||||
if (up.size() != 0 && up.size() != 3) {
|
||||
throw Profile::ParsingError(
|
||||
lineNumber,
|
||||
fmt::format(
|
||||
"Expected 0 or 3 fields for the camera's up vector, got {}",
|
||||
up.size()
|
||||
)
|
||||
);
|
||||
//Fix for tokenizeString returns incorrect up.size() with blank entry
|
||||
bool emptyFields = true;
|
||||
for (auto u : up) {
|
||||
if (u.length() > 0) {
|
||||
emptyFields = false;
|
||||
}
|
||||
}
|
||||
if (!emptyFields) {
|
||||
throw Profile::ParsingError(
|
||||
lineNumber,
|
||||
fmt::format(
|
||||
"Expected 0 or 3 fields for camera up vector, got {}",
|
||||
up.size()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (up.size() == 3) {
|
||||
try {
|
||||
@@ -503,7 +512,7 @@ void Profile::setIgnoreUpdates(bool ignoreUpdates) {
|
||||
_ignoreUpdates = ignoreUpdates;
|
||||
}
|
||||
|
||||
void Profile::addAsset(const std::string& path) {
|
||||
void Profile::addAsset(const std::string& path, const std::string& varName) {
|
||||
ZoneScoped
|
||||
|
||||
if (_ignoreUpdates) {
|
||||
@@ -523,6 +532,7 @@ void Profile::addAsset(const std::string& path) {
|
||||
|
||||
Asset a;
|
||||
a.path = path;
|
||||
a.name = varName;
|
||||
_assets.push_back(std::move(a));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user