mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 03:29:44 -06:00
Work on asset classes
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include <openspace/scene/profile.h>
|
||||
namespace openspace { class Profile; }
|
||||
|
||||
class QTextEdit;
|
||||
|
||||
|
||||
@@ -26,27 +26,17 @@
|
||||
#define __OPENSPACE_UI_LAUNCHER___ASSETS___H__
|
||||
|
||||
#include <QDialog>
|
||||
#include <QWidget>
|
||||
#include <QListWidgetItem>
|
||||
|
||||
#include "assettreemodel.h"
|
||||
#include "filesystemaccess.h"
|
||||
#include <openspace/scene/profile.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class assets;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
namespace openspace { class Profile; }
|
||||
|
||||
class assets : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
void cancel();
|
||||
void parseSelections();
|
||||
void selected(const QModelIndex&);
|
||||
class QTextEdit;
|
||||
class QTreeView;
|
||||
|
||||
class Assets : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* Constructor for assets class
|
||||
@@ -56,15 +46,10 @@ public:
|
||||
* \param reportAssets A full summary of all assets and their respective paths in
|
||||
* a text format unique to this application (more details are
|
||||
* in class #assetTreeModel)
|
||||
* \param parent Pointer to parent Qt widget (optional)
|
||||
* \param parent Pointer to parent Qt widget
|
||||
*/
|
||||
explicit assets(openspace::Profile* imported, const std::string reportAssets,
|
||||
QWidget *parent = nullptr);
|
||||
|
||||
/**
|
||||
* Destructor for assets class
|
||||
*/
|
||||
~assets();
|
||||
explicit Assets(openspace::Profile* imported, const std::string reportAssets,
|
||||
QWidget* parent);
|
||||
|
||||
/**
|
||||
* Creates a text summary of all assets and their paths
|
||||
@@ -73,27 +58,15 @@ public:
|
||||
*/
|
||||
QString createTextSummary();
|
||||
|
||||
/**
|
||||
* Handles keypress while the Qt dialog window is open
|
||||
*
|
||||
* \param evt #QKeyEvent object for the key press event
|
||||
*/
|
||||
void keyPressEvent(QKeyEvent *evt);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
public slots:
|
||||
void parseSelections();
|
||||
void selected(const QModelIndex&);
|
||||
|
||||
private:
|
||||
void compareFilesystemWithProfileAssets();
|
||||
bool traverseToExpandSelectedItems(int nRows, QModelIndex parent);
|
||||
void findPathMatch(std::string& path);
|
||||
void traverseToFindFilesystemMatch(QModelIndex parent, int nRows,
|
||||
std::string dirname);
|
||||
Ui::assets *ui;
|
||||
QWidget* _parent;
|
||||
openspace::Profile* _imported;
|
||||
assetTreeModel _assetTreeModel;
|
||||
QModelIndex _selectedIdx;
|
||||
AssetTreeModel _assetTreeModel;
|
||||
QTreeView* _assetTree = nullptr;
|
||||
QTextEdit* _summary = nullptr;
|
||||
};
|
||||
|
||||
#endif // __OPENSPACE_UI_LAUNCHER___ASSETS___H__
|
||||
|
||||
@@ -25,12 +25,13 @@
|
||||
#ifndef __OPENSPACE_UI_LAUNCHER___ASSETTREEITEM___H__
|
||||
#define __OPENSPACE_UI_LAUNCHER___ASSETTREEITEM___H__
|
||||
|
||||
#include <QVector>
|
||||
#include <QVariant>
|
||||
#include <vector>
|
||||
|
||||
class assetTreeItem
|
||||
{
|
||||
class AssetTreeItem {
|
||||
public:
|
||||
static constexpr const int CheckboxColumn = 1;
|
||||
|
||||
/**
|
||||
* Constructor for assetTreeItem class
|
||||
*
|
||||
@@ -38,13 +39,13 @@ public:
|
||||
* \param parentItem The parent that contains this (and possibly other) children
|
||||
* in the tree structure (optional).
|
||||
*/
|
||||
explicit assetTreeItem(const QVector<QVariant>& data,
|
||||
assetTreeItem* parentItem = nullptr);
|
||||
explicit AssetTreeItem(const std::vector<QVariant>& data,
|
||||
AssetTreeItem* parentItem = nullptr);
|
||||
|
||||
/**
|
||||
* Destructor for assetTreeItem class
|
||||
*/
|
||||
~assetTreeItem();
|
||||
~AssetTreeItem();
|
||||
|
||||
/**
|
||||
* Returns pointer to this tree item's child at position \p row.
|
||||
@@ -54,7 +55,7 @@ public:
|
||||
* in the tree structure (optional).
|
||||
* \return pointer to the child #assetTreeItem
|
||||
*/
|
||||
assetTreeItem* child(int row);
|
||||
AssetTreeItem* child(int row);
|
||||
|
||||
/**
|
||||
* Returns the number of children this item has
|
||||
@@ -103,7 +104,7 @@ public:
|
||||
*
|
||||
* \return pointer to the \p assetTreeItem parent
|
||||
*/
|
||||
assetTreeItem* parent();
|
||||
AssetTreeItem* parent();
|
||||
|
||||
/**
|
||||
* Returns the row number / child number of this item's parent
|
||||
@@ -122,14 +123,6 @@ public:
|
||||
*/
|
||||
bool removeChildren(int position, int count);
|
||||
|
||||
/**
|
||||
* Returns the position number of the current item as a child of its parent,
|
||||
* relative to the parent's other children.
|
||||
*
|
||||
* \return The position number of the current item with respect to its siblings
|
||||
*/
|
||||
int childNumber() const;
|
||||
|
||||
/**
|
||||
* Set data at column \p column
|
||||
*
|
||||
@@ -145,14 +138,14 @@ public:
|
||||
*
|
||||
* \return true if this item is checked
|
||||
*/
|
||||
bool isChecked() const { return _checked; }
|
||||
bool isChecked() const;
|
||||
|
||||
/**
|
||||
* Sets the checked state of this item (whether or not it is selected for a profile)
|
||||
*
|
||||
* \param set bool for whether or not this is checked
|
||||
*/
|
||||
void setChecked( bool set ) { _checked = set; }
|
||||
void setChecked(bool set);
|
||||
|
||||
/**
|
||||
* Returns a bool for whether or not this is an asset. If it is a file
|
||||
@@ -193,21 +186,12 @@ public:
|
||||
*/
|
||||
QString name() const;
|
||||
|
||||
/**
|
||||
* Returns the asset's optional variable name
|
||||
*
|
||||
* \return The asset's variable name
|
||||
*/
|
||||
QString varName() const;
|
||||
|
||||
static const int checkboxColumn = 1;
|
||||
|
||||
private:
|
||||
QVector<assetTreeItem*> _childItems;
|
||||
QVector<QVariant> _itemData;
|
||||
assetTreeItem* _parentItem;
|
||||
bool _checked = false;
|
||||
bool _existsInFilesystem = true;
|
||||
std::vector<AssetTreeItem*> _childItems;
|
||||
std::vector<QVariant> _itemData;
|
||||
AssetTreeItem* _parentItem;
|
||||
bool _isChecked = false;
|
||||
bool _fileExists = true;
|
||||
};
|
||||
|
||||
#endif // __OPENSPACE_UI_LAUNCHER___ASSETTREEITEM___H__
|
||||
|
||||
@@ -26,27 +26,16 @@
|
||||
#define __OPENSPACE_UI_LAUNCHER___ASSETTREEMODEL___H__
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
#include "assettreeitem.h"
|
||||
#include "openspace/scene/profile.h"
|
||||
#include <memory>
|
||||
|
||||
struct importElement
|
||||
{
|
||||
importElement(std::string l, int lev, bool chk)
|
||||
: line(l), level(lev), checked(chk) {}
|
||||
std::string line;
|
||||
int level = -1;
|
||||
bool checked = false;
|
||||
bool existsInFilesystem = true;
|
||||
};
|
||||
|
||||
class assetTreeModel : public QAbstractItemModel
|
||||
{
|
||||
class AssetTreeModel : public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit assetTreeModel(QString header1, QString header2,
|
||||
QObject* parent = nullptr);
|
||||
~assetTreeModel();
|
||||
AssetTreeModel(QObject* parent = nullptr);
|
||||
|
||||
/**
|
||||
* Returns the data contained at an index
|
||||
@@ -56,7 +45,7 @@ public:
|
||||
* function (can be multiple times)
|
||||
* \return QVariant data object
|
||||
*/
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
|
||||
/**
|
||||
* Returns the header data of the tree view
|
||||
@@ -79,7 +68,7 @@ public:
|
||||
* \return #QModelIndex index of the item at specified position
|
||||
*/
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const override;
|
||||
const QModelIndex& parent = QModelIndex()) const override;
|
||||
|
||||
/**
|
||||
* Returns the index of the parent of the item specified by input param
|
||||
@@ -87,7 +76,7 @@ public:
|
||||
* \param index of item that is a child of the parent
|
||||
* \return #QModelIndex index of the parent
|
||||
*/
|
||||
QModelIndex parent(const QModelIndex &index) const override;
|
||||
QModelIndex parent(const QModelIndex& index) const override;
|
||||
|
||||
/**
|
||||
* Returns the index of the parent of the item specified by the input params
|
||||
@@ -106,7 +95,7 @@ public:
|
||||
* \param index of item that is a child of the parent
|
||||
* \return #assetTreeItem pointer to the item at the provided index
|
||||
*/
|
||||
assetTreeItem* assetItem(const QModelIndex &index);
|
||||
AssetTreeItem* assetItem(const QModelIndex& index);
|
||||
|
||||
/**
|
||||
* Returns number of children/rows of the parent
|
||||
@@ -114,7 +103,7 @@ public:
|
||||
* \param parent #QModelIndex of the parent item
|
||||
* \return number of children/rows of this parent
|
||||
*/
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
|
||||
/**
|
||||
* Returns the number of columns of data in each item of the tree
|
||||
@@ -122,7 +111,7 @@ public:
|
||||
* \param parent specified by the #QModelIndex index
|
||||
* \return the number of data columns
|
||||
*/
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
|
||||
/**
|
||||
* Return the Qt flags of the item specified by index, which can include
|
||||
@@ -131,7 +120,7 @@ public:
|
||||
* \param index specified by the #QModelIndex index
|
||||
* \return the Qt flags
|
||||
*/
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
|
||||
/**
|
||||
* Set data at index \p index
|
||||
@@ -141,7 +130,7 @@ public:
|
||||
* \param role Qt-specific role to define context of the call
|
||||
* \return true if the data set was successful
|
||||
*/
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
bool setData(const QModelIndex& index, const QVariant& value,
|
||||
int role = Qt::EditRole) override;
|
||||
|
||||
/**
|
||||
@@ -152,16 +141,8 @@ public:
|
||||
* \param outputItems vector of #assetTreeItem * objects,
|
||||
* each of which are selected
|
||||
*/
|
||||
void selectedAssets(std::vector<std::string>& outputPaths,
|
||||
std::vector<assetTreeItem*>& outputItems);
|
||||
|
||||
/**
|
||||
* Returns a vector of all assets selected in the tree view, but in the form of
|
||||
* #assetTreeItem pointers
|
||||
*
|
||||
* \return vector of #assetTreeItem * objects, each of which are selected
|
||||
*/
|
||||
std::vector<std::string> selectedAssetsDetailed();
|
||||
void getSelectedAssets(std::vector<std::string>& outputPaths,
|
||||
std::vector<AssetTreeItem*>& outputItems);
|
||||
|
||||
/**
|
||||
* Imports asset tree data for this model. The import text format is unique to
|
||||
@@ -180,7 +161,7 @@ public:
|
||||
*
|
||||
* \param contents asset recursive listing of directory in format described above
|
||||
*/
|
||||
void importModelData(const std::string contents);
|
||||
void importModelData(const std::string& contents);
|
||||
|
||||
/**
|
||||
* Returns bool for if item is checked/selected
|
||||
@@ -220,7 +201,7 @@ public:
|
||||
* \param row the child number of the current item
|
||||
* \return assetTreeItem pointer to the child
|
||||
*/
|
||||
assetTreeItem* child(int row) const;
|
||||
AssetTreeItem* child(int row) const;
|
||||
|
||||
/**
|
||||
* Returns the asset name of the specified item
|
||||
@@ -255,17 +236,9 @@ public:
|
||||
void setExistenceInFilesystem(QModelIndex& index, bool fileExists);
|
||||
|
||||
private:
|
||||
std::string headerTitle;
|
||||
assetTreeItem *getItem(const QModelIndex &index) const;
|
||||
assetTreeItem *rootItem;
|
||||
void parseChildrenForSelected(assetTreeItem* item,
|
||||
std::vector<std::string>& outputPaths,
|
||||
std::vector<assetTreeItem*>& outputItems, std::string pathPrefix);
|
||||
void importInsertItem(std::istringstream& iss, assetTreeItem* parent,
|
||||
importElement& elem, int level);
|
||||
bool importGetNextLine(importElement& elem, std::istringstream& iss);
|
||||
void trimWhitespaceFromLine(std::string& line);
|
||||
int getLevelFromLine(std::string line);
|
||||
AssetTreeItem* getItem(const QModelIndex& index) const;
|
||||
|
||||
std::unique_ptr<AssetTreeItem> _rootItem;
|
||||
};
|
||||
|
||||
#endif // __OPENSPACE_UI_LAUNCHER___ASSETTREEMODEL___H__
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include "keybindings.h"
|
||||
#include "assets.h"
|
||||
#include "ostime.h"
|
||||
#include "addedscripts.h"
|
||||
#include "additionalscripts.h"
|
||||
#include "deltatimes.h"
|
||||
#include "camera.h"
|
||||
#include "marknodes.h"
|
||||
@@ -136,7 +136,7 @@ private:
|
||||
properties* _properties;
|
||||
osmodules* _modules;
|
||||
keybindings* _keybindings;
|
||||
assets* _assets;
|
||||
Assets* _assets;
|
||||
ostime* _time;
|
||||
AdditionalScripts* _addedScripts;
|
||||
deltaTimes* _deltaTimes;
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2020 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_UI_LAUNCHER___UI_ASSETS___H__
|
||||
#define __OPENSPACE_UI_LAUNCHER___UI_ASSETS___H__
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <QtWidgets/QDialogButtonBox>
|
||||
#include <QtWidgets/QFrame>
|
||||
#include <QtWidgets/QLabel>
|
||||
#include <QtWidgets/QHeaderView>
|
||||
#include <QtWidgets/QTextEdit>
|
||||
#include <QtWidgets/QTreeView>
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class Ui_assets
|
||||
{
|
||||
public:
|
||||
QVBoxLayout *verticalLayout;
|
||||
QTreeView *treeView;
|
||||
QTextEdit *textEdit;
|
||||
QFrame *line;
|
||||
QDialogButtonBox *buttonBox;
|
||||
QLabel *label_selection;
|
||||
QLabel *label_summary;
|
||||
QHBoxLayout *hLay_bottom_buttonBox;
|
||||
QLabel *label_error;
|
||||
|
||||
void setupUi(QDialog *assets)
|
||||
{
|
||||
if (assets->objectName().isEmpty())
|
||||
assets->setObjectName(QString::fromUtf8("assets"));
|
||||
assets->resize(610, 479);
|
||||
assets->setMinimumSize(QSize(400, 400));
|
||||
assets->setMaximumSize(QSize(1600, 950));
|
||||
label_selection= new QLabel(assets);
|
||||
label_selection->setObjectName(QString::fromUtf8("label_selection"));
|
||||
label_summary = new QLabel(assets);
|
||||
label_summary->setObjectName(QString::fromUtf8("label_summary"));
|
||||
QFont font1;
|
||||
font1.setFamily(QString::fromUtf8("Arial"));
|
||||
font1.setPointSize(12);
|
||||
label_selection->setFont(font1);
|
||||
label_summary->setFont(font1);
|
||||
verticalLayout = new QVBoxLayout(assets);
|
||||
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
|
||||
treeView = new QTreeView(assets);
|
||||
treeView->setObjectName(QString::fromUtf8("treeView"));
|
||||
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);
|
||||
verticalLayout->addWidget(label_selection);
|
||||
verticalLayout->addWidget(treeView);
|
||||
|
||||
textEdit = new QTextEdit(assets);
|
||||
textEdit->setObjectName(QString::fromUtf8("textEdit"));
|
||||
|
||||
verticalLayout->addWidget(label_summary);
|
||||
verticalLayout->addWidget(textEdit);
|
||||
|
||||
line = new QFrame(assets);
|
||||
line->setObjectName(QString::fromUtf8("line"));
|
||||
line->setFrameShape(QFrame::HLine);
|
||||
line->setFrameShadow(QFrame::Sunken);
|
||||
|
||||
verticalLayout->addWidget(line);
|
||||
|
||||
hLay_bottom_buttonBox = new QHBoxLayout();
|
||||
hLay_bottom_buttonBox->setObjectName(QString::fromUtf8("hLay_bottom_buttonBox"));
|
||||
|
||||
QFont fontE;
|
||||
fontE.setFamily(QString::fromUtf8("Arial"));
|
||||
label_error = new QLabel(assets);
|
||||
label_error->setObjectName(QString::fromUtf8("label_error"));
|
||||
QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
sizePolicy1.setHorizontalStretch(0);
|
||||
sizePolicy1.setVerticalStretch(0);
|
||||
sizePolicy1.setHeightForWidth(label_error->sizePolicy().hasHeightForWidth());
|
||||
label_error->setSizePolicy(sizePolicy1);
|
||||
label_error->setMinimumSize(QSize(200, 40));
|
||||
label_error->setMaximumSize(QSize(800, 40));
|
||||
label_error->setFont(fontE);
|
||||
label_error->setWordWrap(true);
|
||||
hLay_bottom_buttonBox->addWidget(label_error);
|
||||
|
||||
buttonBox = new QDialogButtonBox(assets);
|
||||
buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
|
||||
buttonBox->setOrientation(Qt::Horizontal);
|
||||
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
|
||||
|
||||
hLay_bottom_buttonBox->addWidget(buttonBox);
|
||||
verticalLayout->addLayout(hLay_bottom_buttonBox);
|
||||
|
||||
retranslateUi(assets);
|
||||
//QObject::connect(buttonBox, SIGNAL(accepted()), assets, SLOT(accept()));
|
||||
QObject::connect(buttonBox, SIGNAL(rejected()), assets, SLOT(reject()));
|
||||
|
||||
QMetaObject::connectSlotsByName(assets);
|
||||
} // setupUi
|
||||
|
||||
void retranslateUi(QDialog *assets)
|
||||
{
|
||||
assets->setWindowTitle(QCoreApplication::translate("assets", "Dialog", nullptr));
|
||||
label_selection->setText(QCoreApplication::translate("assets", "Select Assets from /data/assets:", nullptr));
|
||||
label_summary->setText(QCoreApplication::translate("assets", "Selection summary:", nullptr));
|
||||
label_error->setText(QCoreApplication::translate("assets", "", nullptr));
|
||||
#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)
|
||||
} // retranslateUi
|
||||
|
||||
};
|
||||
|
||||
namespace Ui {
|
||||
class assets: public Ui_assets {};
|
||||
} // namespace Ui
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // __OPENSPACE_UI_LAUNCHER___UI_ASSETS___H__
|
||||
@@ -1,3 +1,13 @@
|
||||
AdditionalScripts QLabel#title {
|
||||
/*
|
||||
* General settings
|
||||
*/
|
||||
QLabel#heading {
|
||||
font-size: 12pt;
|
||||
}
|
||||
|
||||
/*
|
||||
* Assets
|
||||
*/
|
||||
Assets QTreeView {
|
||||
min-width: 40em;
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "additionalscripts.h"
|
||||
|
||||
#include <openspace/scene/profile.h>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
|
||||
@@ -23,145 +23,180 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include "assets.h"
|
||||
#include "./ui_assets.h"
|
||||
#include <qevent.h>
|
||||
#include <QFileSystemModel>
|
||||
#include <QScreen>
|
||||
#include <QKeyEvent>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <openspace/scene/profile.h>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTextEdit>
|
||||
#include <QTreeView>
|
||||
|
||||
assets::assets(openspace::Profile* imported, const std::string reportAssets,
|
||||
QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::assets)
|
||||
, _imported(imported)
|
||||
, _assetTreeModel(tr("Asset"), tr("Enabled"))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
namespace {
|
||||
bool traverseToExpandSelectedItems(QTreeView& tree, AssetTreeModel& model,
|
||||
int rows, QModelIndex parent)
|
||||
{
|
||||
bool isExpanded = false;
|
||||
|
||||
_assetTreeModel.importModelData(reportAssets);
|
||||
|
||||
ui->treeView->setModel(&_assetTreeModel);
|
||||
ui->treeView->setRootIndex(_assetTreeModel.index(-1, 0));
|
||||
//ui->treeView->setColumnWidth(0, ui->treeView->width() * 0.9);
|
||||
ui->treeView->setColumnWidth(1, 60);//ui->treeView->width() * 0.1);
|
||||
ui->treeView->setColumnWidth(0, ui->treeView->width() - 60);
|
||||
ui->treeView->setAnimated(true);
|
||||
ui->treeView->setSortingEnabled(false);
|
||||
ui->treeView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
ui->textEdit->setReadOnly(true);
|
||||
|
||||
compareFilesystemWithProfileAssets();
|
||||
|
||||
int nRows = _assetTreeModel.rowCount(_assetTreeModel.index(-1, 0));
|
||||
traverseToExpandSelectedItems(nRows, _assetTreeModel.index(-1, 0));
|
||||
ui->textEdit->setText(createTextSummary());
|
||||
|
||||
connect(ui->treeView,
|
||||
SIGNAL(clicked(const QModelIndex&)),
|
||||
this,
|
||||
SLOT(selected(const QModelIndex&))
|
||||
);
|
||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(parseSelections()));
|
||||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()));
|
||||
}
|
||||
|
||||
void assets::compareFilesystemWithProfileAssets() {
|
||||
for (std::string a : _imported->assets()) {
|
||||
findPathMatch(a);
|
||||
}
|
||||
}
|
||||
|
||||
void assets::findPathMatch(std::string& path) {
|
||||
QModelIndex parent = _assetTreeModel.index(-1, 0);
|
||||
int nRows = _assetTreeModel.rowCount(parent);
|
||||
traverseToFindFilesystemMatch(parent, nRows, path);
|
||||
}
|
||||
|
||||
void assets::traverseToFindFilesystemMatch(QModelIndex parent, int rows, std::string path)
|
||||
{
|
||||
size_t slash = path.find_first_of('/', 0);
|
||||
bool endOfPath = (slash == std::string::npos);
|
||||
std::string firstDir = endOfPath ? "" : path.substr(0, slash);
|
||||
|
||||
if (!endOfPath) {
|
||||
std::string nextPath = (slash == std::string::npos) ? path :
|
||||
path.substr(slash + 1);
|
||||
bool foundDirMatch = false;
|
||||
for (int r = 0; r < rows; r++) {
|
||||
QModelIndex idx = _assetTreeModel.index(r, 0, parent);
|
||||
std::string assetName = _assetTreeModel.name(idx).toUtf8().constData();
|
||||
if (!_assetTreeModel.isAsset(idx)) {
|
||||
if (firstDir.compare(assetName) == 0) {
|
||||
int nChildRows = _assetTreeModel.childCount(idx);
|
||||
foundDirMatch = true;
|
||||
traverseToFindFilesystemMatch(idx, nChildRows, nextPath);
|
||||
break;
|
||||
QModelIndex idx = model.index(r, 0, parent);
|
||||
|
||||
if (!model.isAsset(idx)) {
|
||||
int nChildRows = model.childCount(idx);
|
||||
if (traverseToExpandSelectedItems(tree, model, nChildRows, idx)) {
|
||||
tree.setExpanded(idx, true);
|
||||
isExpanded = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!foundDirMatch) {
|
||||
//Insert missing directory here with name and exists=false condition
|
||||
_assetTreeModel.assetItem(parent)->insertChildren(rows, 1, 3);
|
||||
QModelIndex idx = _assetTreeModel.index(rows, 0, parent);
|
||||
_assetTreeModel.setName(idx, QString(firstDir.c_str()));
|
||||
_assetTreeModel.setExistenceInFilesystem(idx, false);
|
||||
traverseToFindFilesystemMatch(idx, 0, nextPath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
bool foundFileMatch = false;
|
||||
for (int r = 0; r < rows; r++) {
|
||||
QModelIndex idx = _assetTreeModel.index(r, 0, parent);
|
||||
std::string assetName = _assetTreeModel.name(idx).toUtf8().constData();
|
||||
|
||||
if (path.compare(assetName) == 0) {
|
||||
foundFileMatch = true;
|
||||
_assetTreeModel.setChecked(idx, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundFileMatch) {
|
||||
//Insert missing file here with name and exists=false condition
|
||||
_assetTreeModel.assetItem(parent)->insertChildren(rows, 1, 3);
|
||||
QModelIndex idx = _assetTreeModel.index(rows, 0, parent);
|
||||
_assetTreeModel.setName(idx, QString(path.c_str()));
|
||||
_assetTreeModel.setChecked(idx, true);
|
||||
_assetTreeModel.setExistenceInFilesystem(idx, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool assets::traverseToExpandSelectedItems(int rows, QModelIndex parent) {
|
||||
bool isExpanded = false;
|
||||
|
||||
for (int r = 0; r < rows; r++) {
|
||||
QModelIndex idx = _assetTreeModel.index(r, 0, parent);
|
||||
|
||||
if (!_assetTreeModel.isAsset(idx)) {
|
||||
int nChildRows = _assetTreeModel.childCount(idx);
|
||||
if (traverseToExpandSelectedItems(nChildRows, idx)) {
|
||||
ui->treeView->setExpanded(idx, true);
|
||||
else if (model.isChecked(idx) || !model.inFilesystem(idx)) {
|
||||
isExpanded = true;
|
||||
}
|
||||
}
|
||||
else if (_assetTreeModel.isChecked(idx) || !_assetTreeModel.inFilesystem(idx)) {
|
||||
isExpanded = true;
|
||||
return isExpanded;
|
||||
}
|
||||
|
||||
void traverseToFindFilesystemMatch(AssetTreeModel& model, QModelIndex parent,
|
||||
int nRows, const std::string& path)
|
||||
{
|
||||
size_t slash = path.find_first_of('/', 0);
|
||||
bool endOfPath = (slash == std::string::npos);
|
||||
std::string firstDir = endOfPath ? "" : path.substr(0, slash);
|
||||
|
||||
if (!endOfPath) {
|
||||
std::string nextPath = (slash == std::string::npos) ?
|
||||
path :
|
||||
path.substr(slash + 1);
|
||||
bool foundDirMatch = false;
|
||||
for (int r = 0; r < nRows; r++) {
|
||||
QModelIndex idx = model.index(r, 0, parent);
|
||||
std::string assetName = model.name(idx).toUtf8().constData();
|
||||
if (!model.isAsset(idx)) {
|
||||
if (firstDir.compare(assetName) == 0) {
|
||||
int nChildRows = model.childCount(idx);
|
||||
foundDirMatch = true;
|
||||
traverseToFindFilesystemMatch(model, idx, nChildRows, nextPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!foundDirMatch) {
|
||||
//Insert missing directory here with name and exists=false condition
|
||||
model.assetItem(parent)->insertChildren(nRows, 1, 3);
|
||||
QModelIndex idx = model.index(nRows, 0, parent);
|
||||
model.setName(idx, QString(firstDir.c_str()));
|
||||
model.setExistenceInFilesystem(idx, false);
|
||||
traverseToFindFilesystemMatch(model, idx, 0, nextPath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
bool foundFileMatch = false;
|
||||
for (int r = 0; r < nRows; r++) {
|
||||
QModelIndex idx = model.index(r, 0, parent);
|
||||
std::string assetName = model.name(idx).toUtf8().constData();
|
||||
|
||||
if (path.compare(assetName) == 0) {
|
||||
foundFileMatch = true;
|
||||
model.setChecked(idx, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundFileMatch) {
|
||||
//Insert missing file here with name and exists=false condition
|
||||
model.assetItem(parent)->insertChildren(nRows, 1, 3);
|
||||
QModelIndex idx = model.index(nRows, 0, parent);
|
||||
model.setName(idx, QString(path.c_str()));
|
||||
model.setChecked(idx, true);
|
||||
model.setExistenceInFilesystem(idx, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return isExpanded;
|
||||
} // namespace
|
||||
|
||||
Assets::Assets(openspace::Profile* imported, const std::string reportAssets,
|
||||
QWidget* parent)
|
||||
: QDialog(parent)
|
||||
, _imported(imported)
|
||||
{
|
||||
setWindowTitle("Assets");
|
||||
|
||||
QBoxLayout* layout = new QVBoxLayout(this);
|
||||
{
|
||||
QLabel* heading = new QLabel("Select assets from /data/assets");
|
||||
heading->setObjectName("heading");
|
||||
layout->addWidget(heading);
|
||||
}
|
||||
{
|
||||
_assetTreeModel.importModelData(reportAssets);
|
||||
|
||||
_assetTree = new QTreeView;
|
||||
_assetTree->setToolTip(
|
||||
"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."
|
||||
);
|
||||
_assetTree->setAlternatingRowColors(true);
|
||||
_assetTree->setModel(&_assetTreeModel);
|
||||
_assetTree->setRootIndex(_assetTreeModel.index(-1, 0));
|
||||
_assetTree->setColumnWidth(1, 60);
|
||||
_assetTree->setColumnWidth(0, _assetTree->width() - 60);
|
||||
_assetTree->header()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
_assetTree->header()->setSectionResizeMode(1, QHeaderView::Fixed);
|
||||
_assetTree->header()->setStretchLastSection(false);
|
||||
_assetTree->setAnimated(true);
|
||||
_assetTree->setSortingEnabled(false);
|
||||
_assetTree->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
connect(_assetTree, &QTreeView::clicked, this, &Assets::selected);
|
||||
|
||||
|
||||
for (const std::string& a : _imported->assets()) {
|
||||
QModelIndex parent = _assetTreeModel.index(-1, 0);
|
||||
int nRows = _assetTreeModel.rowCount(parent);
|
||||
traverseToFindFilesystemMatch(_assetTreeModel, parent, nRows, a);
|
||||
}
|
||||
|
||||
int nRows = _assetTreeModel.rowCount(_assetTreeModel.index(-1, 0));
|
||||
traverseToExpandSelectedItems(
|
||||
*_assetTree,
|
||||
_assetTreeModel,
|
||||
nRows,
|
||||
_assetTreeModel.index(-1, 0)
|
||||
);
|
||||
layout->addWidget(_assetTree);
|
||||
}
|
||||
{
|
||||
QLabel* summaryHeading = new QLabel("Selection summary");
|
||||
summaryHeading->setObjectName("heading");
|
||||
layout->addWidget(summaryHeading);
|
||||
}
|
||||
{
|
||||
_summary = new QTextEdit;
|
||||
_summary->setReadOnly(true);
|
||||
_summary->setText(createTextSummary());
|
||||
layout->addWidget(_summary);
|
||||
}
|
||||
{
|
||||
QFrame* line = new QFrame;
|
||||
line->setFrameShape(QFrame::HLine);
|
||||
line->setFrameShadow(QFrame::Sunken);
|
||||
layout->addWidget(line);
|
||||
}
|
||||
|
||||
{
|
||||
QDialogButtonBox* buttons = new QDialogButtonBox;
|
||||
buttons->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
|
||||
connect(buttons, &QDialogButtonBox::accepted, this, &Assets::parseSelections);
|
||||
connect(buttons, &QDialogButtonBox::rejected, this, &Assets::reject);
|
||||
layout->addWidget(buttons);
|
||||
}
|
||||
}
|
||||
|
||||
QString assets::createTextSummary() {
|
||||
//compareFilesystemWithProfileAssets();
|
||||
QString Assets::createTextSummary() {
|
||||
std::vector<std::string> summaryPaths;
|
||||
std::vector<assetTreeItem*> summaryItems;
|
||||
_assetTreeModel.selectedAssets(summaryPaths, summaryItems);
|
||||
std::vector<AssetTreeItem*> summaryItems;
|
||||
_assetTreeModel.getSelectedAssets(summaryPaths, summaryItems);
|
||||
|
||||
if (summaryPaths.size() != summaryItems.size()) {
|
||||
return "";
|
||||
@@ -178,38 +213,18 @@ QString assets::createTextSummary() {
|
||||
return summary;
|
||||
}
|
||||
|
||||
void assets::parseSelections() {
|
||||
void Assets::parseSelections() {
|
||||
_imported->clearAssets();
|
||||
std::vector<std::string> summaryPaths;
|
||||
std::vector<assetTreeItem*> summaryItems;
|
||||
_assetTreeModel.selectedAssets(summaryPaths, summaryItems);
|
||||
std::vector<AssetTreeItem*> summaryItems;
|
||||
_assetTreeModel.getSelectedAssets(summaryPaths, summaryItems);
|
||||
|
||||
for (std::string sel : summaryPaths) {
|
||||
for (const std::string& sel : summaryPaths) {
|
||||
_imported->addAsset(sel);
|
||||
}
|
||||
accept();
|
||||
}
|
||||
|
||||
void assets::selected(const QModelIndex& sel) {
|
||||
ui->textEdit->setText(createTextSummary());
|
||||
}
|
||||
|
||||
assets::~assets() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void assets::cancel() {
|
||||
}
|
||||
|
||||
void assets::keyPressEvent(QKeyEvent *evt)
|
||||
{
|
||||
if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return)
|
||||
return;
|
||||
QDialog::keyPressEvent(evt);
|
||||
}
|
||||
|
||||
void assets::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
int assetColumnWidth = ui->treeView->width() - 90;
|
||||
ui->treeView->setColumnWidth(0, assetColumnWidth);
|
||||
void Assets::selected(const QModelIndex& sel) {
|
||||
_summary->setText(createTextSummary());
|
||||
}
|
||||
|
||||
@@ -24,127 +24,138 @@
|
||||
|
||||
#include "assettreeitem.h"
|
||||
|
||||
assetTreeItem::assetTreeItem(const QVector<QVariant> &data, assetTreeItem* parentItem)
|
||||
: _itemData(data), _parentItem(parentItem)
|
||||
{
|
||||
}
|
||||
AssetTreeItem::AssetTreeItem(const std::vector<QVariant>& data, AssetTreeItem* parentItem)
|
||||
: _itemData(data)
|
||||
, _parentItem(parentItem)
|
||||
{}
|
||||
|
||||
assetTreeItem::~assetTreeItem()
|
||||
{
|
||||
AssetTreeItem::~AssetTreeItem() {
|
||||
qDeleteAll(_childItems);
|
||||
}
|
||||
|
||||
assetTreeItem* assetTreeItem::child(int row)
|
||||
{
|
||||
if (row < 0 || row >= _childItems.size())
|
||||
AssetTreeItem* AssetTreeItem::child(int row) {
|
||||
if (row < 0 || row >= static_cast<int>(_childItems.size())) {
|
||||
return nullptr;
|
||||
return _childItems.at(row);
|
||||
}
|
||||
else {
|
||||
return _childItems.at(row);
|
||||
}
|
||||
}
|
||||
|
||||
int assetTreeItem::childCount() const
|
||||
{
|
||||
return _childItems.count();
|
||||
int AssetTreeItem::childCount() const {
|
||||
return static_cast<int>(_childItems.size());
|
||||
}
|
||||
|
||||
int assetTreeItem::row() const
|
||||
{
|
||||
if (_parentItem)
|
||||
return _parentItem->_childItems.indexOf(const_cast<assetTreeItem*>(this));
|
||||
|
||||
return 0;
|
||||
int AssetTreeItem::row() const {
|
||||
if (_parentItem) {
|
||||
auto it = std::find(
|
||||
_parentItem->_childItems.begin(),
|
||||
_parentItem->_childItems.end(),
|
||||
this
|
||||
);
|
||||
return std::distance(_parentItem->_childItems.begin(), it);
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int assetTreeItem::columnCount() const
|
||||
{
|
||||
return _itemData.count();
|
||||
int AssetTreeItem::columnCount() const {
|
||||
return _itemData.size();
|
||||
}
|
||||
|
||||
int assetTreeItem::childNumber() const
|
||||
{
|
||||
if (_parentItem)
|
||||
return _parentItem->_childItems.indexOf(const_cast<assetTreeItem*>(this));
|
||||
return 0;
|
||||
}
|
||||
|
||||
QVariant assetTreeItem::data(int column) const
|
||||
{
|
||||
if (column < 0 || column >= _itemData.size())
|
||||
QVariant AssetTreeItem::data(int column) const {
|
||||
if (column < 0 || column >= _itemData.size()) {
|
||||
return QVariant();
|
||||
return _itemData.at(column);
|
||||
}
|
||||
else {
|
||||
return _itemData.at(column);
|
||||
}
|
||||
}
|
||||
|
||||
bool assetTreeItem::setData(int column, const QVariant &value)
|
||||
{
|
||||
if (column < 0 || column >= _itemData.size())
|
||||
bool AssetTreeItem::setData(int column, const QVariant& value) {
|
||||
if (column < 0 || column >= _itemData.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_itemData[column] = value;
|
||||
if (column == checkboxColumn) {
|
||||
_checked = value.toBool();
|
||||
if (column == CheckboxColumn) {
|
||||
_isChecked = value.toBool();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool assetTreeItem::isAsset() const {
|
||||
bool AssetTreeItem::isChecked() const {
|
||||
return _isChecked;
|
||||
}
|
||||
|
||||
void AssetTreeItem::setChecked(bool set) {
|
||||
_isChecked = set;
|
||||
}
|
||||
|
||||
bool AssetTreeItem::isAsset() const {
|
||||
return (childCount() == 0);
|
||||
}
|
||||
|
||||
bool assetTreeItem::isCategory() const {
|
||||
bool AssetTreeItem::isCategory() const {
|
||||
return (childCount() > 0);
|
||||
}
|
||||
|
||||
void assetTreeItem::setExistsInFilesystem(bool fileExists) {
|
||||
_existsInFilesystem = fileExists;
|
||||
void AssetTreeItem::setExistsInFilesystem(bool fileExists) {
|
||||
_fileExists = fileExists;
|
||||
}
|
||||
|
||||
bool assetTreeItem::doesExistInFilesystem() const {
|
||||
return _existsInFilesystem;
|
||||
bool AssetTreeItem::doesExistInFilesystem() const {
|
||||
return _fileExists;
|
||||
}
|
||||
|
||||
QString assetTreeItem::name() const {
|
||||
QString AssetTreeItem::name() const {
|
||||
return QString(data(0).toString());
|
||||
}
|
||||
|
||||
bool assetTreeItem::insertChildren(int position, int count, int columns)
|
||||
{
|
||||
if (position < 0 || position > _childItems.size())
|
||||
bool AssetTreeItem::insertChildren(int position, int count, int columns) {
|
||||
if (position < 0 || position > _childItems.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int row = 0; row < count; ++row) {
|
||||
QVector<QVariant> data(columns);
|
||||
assetTreeItem *item = new assetTreeItem(data, this);
|
||||
_childItems.insert(position, item);
|
||||
std::vector<QVariant> data(columns);
|
||||
AssetTreeItem*item = new AssetTreeItem(data, this);
|
||||
_childItems.insert(_childItems.begin() + position, item);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool assetTreeItem::removeChildren(int position, int count)
|
||||
{
|
||||
if (position < 0 || position + count > _childItems.size())
|
||||
bool AssetTreeItem::removeChildren(int position, int count) {
|
||||
if (position < 0 || position + count > _childItems.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int row = 0; row < count; ++row)
|
||||
delete _childItems.takeAt(position);
|
||||
for (int row = 0; row < count; ++row) {
|
||||
delete _childItems[position];
|
||||
_childItems.erase(_childItems.begin() + position);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool assetTreeItem::insertColumns(int position, int columns)
|
||||
{
|
||||
if (position < 0 || position > _itemData.size())
|
||||
bool AssetTreeItem::insertColumns(int position, int columns) {
|
||||
if (position < 0 || position > _itemData.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int column = 0; column < columns; ++column)
|
||||
_itemData.insert(position, QVariant());
|
||||
for (int column = 0; column < columns; ++column) {
|
||||
_itemData.insert(_itemData.begin() + position, QVariant());
|
||||
}
|
||||
|
||||
for (assetTreeItem *child : qAsConst(_childItems))
|
||||
for (AssetTreeItem* child : qAsConst(_childItems)) {
|
||||
child->insertColumns(position, columns);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
assetTreeItem* assetTreeItem::parent()
|
||||
{
|
||||
AssetTreeItem* AssetTreeItem::parent() {
|
||||
return _parentItem;
|
||||
}
|
||||
|
||||
@@ -27,136 +27,178 @@
|
||||
#include <sstream>
|
||||
#include <QColor>
|
||||
|
||||
assetTreeModel::assetTreeModel(QString header1, QString header2, QObject* parent)
|
||||
: QAbstractItemModel(parent),
|
||||
headerTitle(header1.toUtf8().constData())
|
||||
{
|
||||
QVector<QVariant> rootData;
|
||||
rootItem = new assetTreeItem({header1, header2});
|
||||
}
|
||||
namespace {
|
||||
constexpr const char* Header1 = "Asset";
|
||||
constexpr const char* Header2 = "Enabled";
|
||||
|
||||
assetTreeModel::~assetTreeModel() {
|
||||
delete rootItem;
|
||||
}
|
||||
struct ImportElement {
|
||||
std::string line;
|
||||
int level = -1;
|
||||
bool checked = false;
|
||||
bool existsInFilesystem = true;
|
||||
};
|
||||
|
||||
void assetTreeModel::importModelData(const std::string contents) {
|
||||
std::istringstream iss(contents.c_str());
|
||||
importElement rootElem = {"", 0, false};
|
||||
|
||||
if (importGetNextLine(rootElem, iss)) {
|
||||
importInsertItem(iss, rootItem, rootElem, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void assetTreeModel::importInsertItem(std::istringstream& iss, assetTreeItem* parent,
|
||||
importElement& elem, int level)
|
||||
{
|
||||
int nChildInsert = -1;
|
||||
bool continueToNextLine = true;
|
||||
|
||||
while (continueToNextLine && elem.line.length() != 0) {
|
||||
int levelChange = elem.level - level;
|
||||
|
||||
if (levelChange == 0) {
|
||||
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)->setExistsInFilesystem(elem.existsInFilesystem);
|
||||
continueToNextLine = importGetNextLine(elem, iss);
|
||||
}
|
||||
else if (levelChange == 1) {
|
||||
importInsertItem(iss, parent->child(nChildInsert), elem, level + 1);
|
||||
}
|
||||
else if (levelChange < 0) {
|
||||
continueToNextLine = false;
|
||||
break;
|
||||
int getLevelFromLine(std::string line) {
|
||||
int level = 0;
|
||||
for (unsigned int i = 0; i < line.length(); ++i) {
|
||||
if (line.substr(i, 1) == " ") {
|
||||
level++;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return level;
|
||||
}
|
||||
}
|
||||
|
||||
bool assetTreeModel::importGetNextLine(importElement& elem, std::istringstream& iss) {
|
||||
bool ok = std::getline(iss, elem.line) ? true : false;
|
||||
if (!ok) {
|
||||
elem.line = "";
|
||||
elem.level = -1;
|
||||
void trimWhitespaceFromLine(std::string& line) {
|
||||
line.erase(0, line.find_first_not_of(" \t\n"));
|
||||
line.erase(line.find_last_not_of(" \t\n") + 1);
|
||||
}
|
||||
else {
|
||||
elem.checked = (elem.line.substr(0, 1).compare("0") == 0) ? false : true;
|
||||
elem.existsInFilesystem = (elem.line.substr(0, 1).compare("x") == 0) ?
|
||||
false : true;
|
||||
elem.line = elem.line.substr(1);
|
||||
elem.level = getLevelFromLine(elem.line);
|
||||
trimWhitespaceFromLine(elem.line);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
void assetTreeModel::trimWhitespaceFromLine(std::string& line) {
|
||||
line.erase(0, line.find_first_not_of(" \t\n"));
|
||||
line.erase(line.find_last_not_of(" \t\n") + 1);
|
||||
}
|
||||
|
||||
int assetTreeModel::getLevelFromLine(std::string line) {
|
||||
int level = 0;
|
||||
for (unsigned int i = 0; i < line.length(); ++i) {
|
||||
if (line.substr(i, 1).compare(" ") == 0) {
|
||||
level++;
|
||||
bool importGetNextLine(ImportElement& elem, std::istringstream& iss) {
|
||||
bool ok = std::getline(iss, elem.line) ? true : false;
|
||||
if (!ok) {
|
||||
elem.line = "";
|
||||
elem.level = -1;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
elem.checked = elem.line.substr(0, 1) != "0";
|
||||
elem.existsInFilesystem = elem.line.substr(0, 1) != "x";
|
||||
elem.line = elem.line.substr(1);
|
||||
elem.level = getLevelFromLine(elem.line);
|
||||
trimWhitespaceFromLine(elem.line);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
void importInsertItem(std::istringstream& iss, AssetTreeItem* parent,
|
||||
ImportElement& elem, int level)
|
||||
{
|
||||
int nChildInsert = -1;
|
||||
bool continueToNextLine = true;
|
||||
|
||||
while (continueToNextLine && elem.line.length() != 0) {
|
||||
int levelChange = elem.level - level;
|
||||
|
||||
if (levelChange == 0) {
|
||||
parent->insertChildren(++nChildInsert, 1, 3);
|
||||
parent->child(nChildInsert)->setData(0, QString::fromStdString(elem.line));
|
||||
bool shouldMakeElemChecked = (elem.checked || !elem.existsInFilesystem);
|
||||
Qt::CheckState check = (shouldMakeElemChecked) ? Qt::Checked : Qt::Unchecked;
|
||||
parent->child(nChildInsert)->setData(1, check);
|
||||
parent->child(nChildInsert)->setExistsInFilesystem(elem.existsInFilesystem);
|
||||
continueToNextLine = importGetNextLine(elem, iss);
|
||||
}
|
||||
else if (levelChange == 1) {
|
||||
importInsertItem(iss, parent->child(nChildInsert), elem, level + 1);
|
||||
}
|
||||
else if (levelChange < 0) {
|
||||
continueToNextLine = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return level;
|
||||
}
|
||||
|
||||
assetTreeItem* assetTreeModel::getItem(const QModelIndex &index) const {
|
||||
if (index.isValid()) {
|
||||
assetTreeItem* item = static_cast<assetTreeItem*>(index.internalPointer());
|
||||
if (item)
|
||||
return item;
|
||||
|
||||
void parseChildrenForSelected(AssetTreeItem* item,
|
||||
std::vector<std::string>& outputPaths,
|
||||
std::vector<AssetTreeItem*>& outputItems,
|
||||
std::string pathPrefix)
|
||||
{
|
||||
std::string itemName = item->data(0).toString().toStdString();
|
||||
bool isPathPrefix = ((pathPrefix.length()) == 0 && (itemName == Header1));
|
||||
|
||||
if (item->isAsset()) {
|
||||
if (item->isChecked()) {
|
||||
std::string path = pathPrefix + itemName;
|
||||
outputItems.push_back(item);
|
||||
outputPaths.push_back(path);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!isPathPrefix) {
|
||||
pathPrefix += itemName;
|
||||
pathPrefix += "/";
|
||||
}
|
||||
for (int i = 0; i < item->childCount(); ++i) {
|
||||
parseChildrenForSelected(
|
||||
item->child(i),
|
||||
outputPaths,
|
||||
outputItems,
|
||||
pathPrefix
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rootItem;
|
||||
} // namespace
|
||||
|
||||
AssetTreeModel::AssetTreeModel(QObject* parent)
|
||||
: QAbstractItemModel(parent)
|
||||
{
|
||||
_rootItem = std::make_unique<AssetTreeItem>(
|
||||
std::vector<QVariant>{
|
||||
QString::fromStdString(Header1), QString::fromStdString(Header2)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
bool assetTreeModel::isChecked(QModelIndex& index) const {
|
||||
assetTreeItem* item = getItem(index);
|
||||
void AssetTreeModel::importModelData(const std::string& contents) {
|
||||
std::istringstream iss(contents.c_str());
|
||||
ImportElement rootElem = { "", 0, false };
|
||||
|
||||
if (importGetNextLine(rootElem, iss)) {
|
||||
importInsertItem(iss, _rootItem.get(), rootElem, 0);
|
||||
}
|
||||
}
|
||||
|
||||
AssetTreeItem* AssetTreeModel::getItem(const QModelIndex& index) const {
|
||||
if (index.isValid()) {
|
||||
AssetTreeItem* item = static_cast<AssetTreeItem*>(index.internalPointer());
|
||||
if (item) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return _rootItem.get();
|
||||
}
|
||||
|
||||
bool AssetTreeModel::isChecked(QModelIndex& index) const {
|
||||
AssetTreeItem* item = getItem(index);
|
||||
int checked = item->data(1).toInt();
|
||||
return (checked == Qt::Checked) ? true : false;
|
||||
return checked == Qt::Checked;
|
||||
}
|
||||
|
||||
bool assetTreeModel::isAsset(QModelIndex& index) const {
|
||||
assetTreeItem* item = getItem(index);
|
||||
bool AssetTreeModel::isAsset(QModelIndex& index) const {
|
||||
AssetTreeItem* item = getItem(index);
|
||||
return item->isAsset();
|
||||
}
|
||||
|
||||
bool assetTreeModel::inFilesystem(QModelIndex& index) const {
|
||||
assetTreeItem* item = getItem(index);
|
||||
bool AssetTreeModel::inFilesystem(QModelIndex& index) const {
|
||||
AssetTreeItem* item = getItem(index);
|
||||
return item->doesExistInFilesystem();
|
||||
}
|
||||
|
||||
int assetTreeModel::childCount(QModelIndex& index) const {
|
||||
int AssetTreeModel::childCount(QModelIndex& index) const {
|
||||
return getItem(index)->childCount();
|
||||
}
|
||||
|
||||
QString assetTreeModel::name(QModelIndex& index) const {
|
||||
QString AssetTreeModel::name(QModelIndex& index) const {
|
||||
return getItem(index)->name();
|
||||
}
|
||||
|
||||
void assetTreeModel::setName(QModelIndex& index, QString name) {
|
||||
void AssetTreeModel::setName(QModelIndex& index, QString name) {
|
||||
getItem(index)->setData(0, name);
|
||||
}
|
||||
|
||||
void assetTreeModel::setChecked(QModelIndex& index, bool checked) {
|
||||
void AssetTreeModel::setChecked(QModelIndex& index, bool checked) {
|
||||
getItem(index)->setData(1, checked ? Qt::Checked : Qt::Unchecked);
|
||||
}
|
||||
|
||||
void assetTreeModel::setExistenceInFilesystem(QModelIndex& index, bool fileExists) {
|
||||
void AssetTreeModel::setExistenceInFilesystem(QModelIndex& index, bool fileExists) {
|
||||
getItem(index)->setExistsInFilesystem(fileExists);
|
||||
}
|
||||
|
||||
assetTreeItem* assetTreeModel::child(int row) const {
|
||||
AssetTreeItem* AssetTreeModel::child(int row) const {
|
||||
QModelIndex i = index(row, 0);
|
||||
int nKids = childCount(i);
|
||||
if (row < nKids) {
|
||||
@@ -165,66 +207,69 @@ 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)
|
||||
QModelIndex AssetTreeModel::index(int row, int column, const QModelIndex& parent) const {
|
||||
if (parent.isValid() && parent.column() != 0) {
|
||||
return QModelIndex();
|
||||
if (!hasIndex(row, column, parent))
|
||||
}
|
||||
if (!hasIndex(row, column, parent)) {
|
||||
return QModelIndex();
|
||||
assetTreeItem *parentItem = getItem(parent);
|
||||
if (!parentItem)
|
||||
return QModelIndex();
|
||||
|
||||
if (!parent.isValid())
|
||||
parentItem = rootItem;
|
||||
|
||||
assetTreeItem* childItem = parentItem->child(row);
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex assetTreeModel::parent(int row, int column, const QModelIndex& parent) const
|
||||
{
|
||||
QModelIndex idx = index(row, column, parent);
|
||||
return assetTreeModel::parent(idx);
|
||||
}
|
||||
|
||||
QModelIndex assetTreeModel::parent(const QModelIndex& index) const {
|
||||
if (!index.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
assetTreeItem* childItem = getItem(index);
|
||||
|
||||
assetTreeItem* parentItem = childItem ? childItem->parent() : nullptr;
|
||||
|
||||
if (parentItem == rootItem || !parentItem) {
|
||||
}
|
||||
AssetTreeItem* parentItem = getItem(parent);
|
||||
if (!parentItem) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
return createIndex(parentItem->childNumber(), 0, parentItem);
|
||||
if (!parent.isValid()) {
|
||||
parentItem = _rootItem.get();
|
||||
}
|
||||
|
||||
AssetTreeItem* childItem = parentItem->child(row);
|
||||
if (childItem) {
|
||||
return createIndex(row, column, childItem);
|
||||
}
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
assetTreeItem* assetTreeModel::assetItem(const QModelIndex &index) {
|
||||
QModelIndex AssetTreeModel::parent(int row, int column, const QModelIndex& parent) const {
|
||||
QModelIndex idx = index(row, column, parent);
|
||||
return AssetTreeModel::parent(idx);
|
||||
}
|
||||
|
||||
QModelIndex AssetTreeModel::parent(const QModelIndex& index) const {
|
||||
if (!index.isValid()) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
AssetTreeItem* childItem = getItem(index);
|
||||
AssetTreeItem* parentItem = childItem ? childItem->parent() : nullptr;
|
||||
if (parentItem == _rootItem.get() || !parentItem) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
}
|
||||
|
||||
AssetTreeItem* AssetTreeModel::assetItem(const QModelIndex& index) {
|
||||
return getItem(index);
|
||||
}
|
||||
|
||||
int assetTreeModel::rowCount(const QModelIndex& parent) const {
|
||||
const assetTreeItem* parentItem = getItem(parent);
|
||||
int AssetTreeModel::rowCount(const QModelIndex& parent) const {
|
||||
const AssetTreeItem* parentItem = getItem(parent);
|
||||
return parentItem ? parentItem->childCount() : 0;
|
||||
}
|
||||
|
||||
int assetTreeModel::columnCount(const QModelIndex& parent) const {
|
||||
Q_UNUSED(parent);
|
||||
return rootItem->columnCount();
|
||||
int AssetTreeModel::columnCount(const QModelIndex&) const {
|
||||
return _rootItem->columnCount();
|
||||
}
|
||||
|
||||
QVariant assetTreeModel::data(const QModelIndex& index, int role) const {
|
||||
if (!index.isValid())
|
||||
QVariant AssetTreeModel::data(const QModelIndex& index, int role) const {
|
||||
if (!index.isValid()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
assetTreeItem* item = static_cast<assetTreeItem*>(index.internalPointer());
|
||||
AssetTreeItem* item = static_cast<AssetTreeItem*>(index.internalPointer());
|
||||
|
||||
if (index.column() == assetTreeItem::checkboxColumn) {
|
||||
if (index.column() == AssetTreeItem::CheckboxColumn) {
|
||||
if (item->isAsset() && (role == Qt::CheckStateRole)) {
|
||||
return static_cast<int>(item->isChecked() ? Qt::Checked : Qt::Unchecked);
|
||||
}
|
||||
@@ -249,70 +294,48 @@ QVariant assetTreeModel::data(const QModelIndex& index, int role) const {
|
||||
}
|
||||
}
|
||||
|
||||
bool assetTreeModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||
{
|
||||
bool AssetTreeModel::setData(const QModelIndex& index, const QVariant& value, int role) {
|
||||
bool setSuccess = false;
|
||||
|
||||
if (!index.isValid())
|
||||
if (!index.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
assetTreeItem* item = static_cast<assetTreeItem*>(index.internalPointer());
|
||||
AssetTreeItem* item = static_cast<AssetTreeItem*>(index.internalPointer());
|
||||
|
||||
if (role == Qt::CheckStateRole && index.column() == assetTreeItem::checkboxColumn) {
|
||||
if (role == Qt::CheckStateRole && index.column() == AssetTreeItem::CheckboxColumn) {
|
||||
setSuccess = item->setData(index.column(), value);
|
||||
}
|
||||
return setSuccess;
|
||||
}
|
||||
|
||||
Qt::ItemFlags assetTreeModel::flags(const QModelIndex& index) const {
|
||||
if (!index.isValid())
|
||||
Qt::ItemFlags AssetTreeModel::flags(const QModelIndex& index) const {
|
||||
if (!index.isValid()) {
|
||||
return Qt::NoItemFlags;
|
||||
}
|
||||
|
||||
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
Qt::ItemFlags flags = Qt::ItemIsEnabled;
|
||||
|
||||
if ( index.column() == assetTreeItem::checkboxColumn )
|
||||
if (index.column() == AssetTreeItem::CheckboxColumn) {
|
||||
flags |= Qt::ItemIsUserCheckable;
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
QVariant assetTreeModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
QVariant AssetTreeModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||
return rootItem->data(section);
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void assetTreeModel::selectedAssets(std::vector<std::string>& outputPaths,
|
||||
std::vector<assetTreeItem*>& outputItems)
|
||||
{
|
||||
parseChildrenForSelected(rootItem, outputPaths, outputItems, "");
|
||||
}
|
||||
|
||||
void assetTreeModel::parseChildrenForSelected(assetTreeItem* item,
|
||||
std::vector<std::string>& outputPaths,
|
||||
std::vector<assetTreeItem*>& outputItems,
|
||||
std::string pathPrefix)
|
||||
{
|
||||
std::string itemName = item->data(0).toString().toUtf8().constData();
|
||||
bool isPathPrefix = ((pathPrefix.length()) == 0 && (itemName == headerTitle));
|
||||
|
||||
if (item->isAsset()) {
|
||||
if (item->isChecked()) {
|
||||
std::string path = pathPrefix + itemName;
|
||||
outputItems.push_back(item);
|
||||
outputPaths.push_back(path);
|
||||
}
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||
return _rootItem->data(section);
|
||||
}
|
||||
else {
|
||||
if (!isPathPrefix) {
|
||||
pathPrefix += itemName;
|
||||
pathPrefix += "/";
|
||||
}
|
||||
for (int i = 0; i < item->childCount(); ++i) {
|
||||
parseChildrenForSelected(item->child(i), outputPaths, outputItems, pathPrefix);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
void AssetTreeModel::getSelectedAssets(std::vector<std::string>& outputPaths,
|
||||
std::vector<AssetTreeItem*>& outputItems)
|
||||
{
|
||||
parseChildrenForSelected(_rootItem.get(), outputPaths, outputItems, "");
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ void ProfileEdit::openKeybindings() {
|
||||
void ProfileEdit::openAssets() {
|
||||
ui->label_error->setText("");
|
||||
if (_pData) {
|
||||
_assets = new assets(_pData, _reportedAssets);
|
||||
_assets = new Assets(_pData, _reportedAssets, this);
|
||||
_assets->exec();
|
||||
labelText(_pData, _pData->assets().size(), "Assets", ui->label_assets);
|
||||
ui->text_assets->setText(_assets->createTextSummary());
|
||||
|
||||
Reference in New Issue
Block a user