From b13687b839579d9d743042a098d6e44ccbfb1510 Mon Sep 17 00:00:00 2001 From: Marcus Weber Date: Wed, 26 Jul 2023 16:43:04 +0200 Subject: [PATCH] Updated Release v1.10.0 --- EditorApp/mainwindow.cpp | 3 +- .../common_widgets/MeshAssetImportDialog.h | 2 +- .../src/MeshAssetImportDialog.cpp | 4 +- .../include/object_tree_view/ObjectTreeView.h | 1 - .../ObjectTreeViewDefaultModel.h | 4 +- .../src/object_tree_view/ObjectTreeView.cpp | 6 -- .../ObjectTreeViewDefaultModel.cpp | 72 +++++++++++-------- .../src/PropertyBrowserItem.cpp | 7 +- 8 files changed, 56 insertions(+), 43 deletions(-) diff --git a/EditorApp/mainwindow.cpp b/EditorApp/mainwindow.cpp index e1994247..67b18ff5 100644 --- a/EditorApp/mainwindow.cpp +++ b/EditorApp/mainwindow.cpp @@ -269,9 +269,10 @@ ads::CDockAreaWidget* createAndAddSceneGraphTree(MainWindow* mainWindow, const c Skin::typeDescription.typeName}; auto* model = new raco::object_tree::model::ObjectTreeViewDefaultModel(racoApplication->activeRaCoProject().commandInterface(), racoApplication->dataChangeDispatcher(), racoApplication->externalProjects(), allowedCreateableUserTypes); - model->setAcceptableFileExtensions(QStringList{"lua"}); + model->setAcceptableFileExtensions(QStringList{"lua", "gltf", "glb"}); model->setAcceptLuaScripts(true); model->setAcceptLuaInterfaces(true); + model->setDropGltfOpensAssetImportDialog(true); return createAndAddObjectTree(MainWindow::DockWidgetTypes::SCENE_GRAPH, dockObjName, model, new raco::object_tree::model::ObjectTreeViewDefaultSortFilterProxyModel(mainWindow, false), ads::LeftDockWidgetArea, mainWindow, dockManager, treeDockManager, nullptr); } diff --git a/gui/libCommonWidgets/include/common_widgets/MeshAssetImportDialog.h b/gui/libCommonWidgets/include/common_widgets/MeshAssetImportDialog.h index debd189f..8629bac2 100644 --- a/gui/libCommonWidgets/include/common_widgets/MeshAssetImportDialog.h +++ b/gui/libCommonWidgets/include/common_widgets/MeshAssetImportDialog.h @@ -25,7 +25,7 @@ namespace raco::common_widgets { class MeshAssetImportDialog final : public QDialog { public: - explicit MeshAssetImportDialog(raco::core::MeshScenegraph& sceneGraph, int projectFeatureLevel, QWidget* parent = nullptr); + explicit MeshAssetImportDialog(raco::core::MeshScenegraph& sceneGraph, int projectFeatureLevel, QString fileName, QWidget* parent = nullptr); QGridLayout* layout_; QTreeWidget* widget_; diff --git a/gui/libCommonWidgets/src/MeshAssetImportDialog.cpp b/gui/libCommonWidgets/src/MeshAssetImportDialog.cpp index d111cbad..7e3a01ea 100644 --- a/gui/libCommonWidgets/src/MeshAssetImportDialog.cpp +++ b/gui/libCommonWidgets/src/MeshAssetImportDialog.cpp @@ -22,12 +22,12 @@ namespace raco::common_widgets { -MeshAssetImportDialog::MeshAssetImportDialog(raco::core::MeshScenegraph& sceneGraph, int projectFeatureLevel, QWidget* parent) +MeshAssetImportDialog::MeshAssetImportDialog(raco::core::MeshScenegraph& sceneGraph, int projectFeatureLevel, QString fileName, QWidget* parent) : sceneGraph_{sceneGraph}, nodeTreeList_{sceneGraph_.nodes.size()}, meshTreeList_{sceneGraph_.meshes.size()}, animTreeList_{sceneGraph_.animations.size()} { - setWindowTitle("Import External Assets"); + setWindowTitle("Import External Assets from '" + fileName + "'"); widget_ = new QTreeWidget(this); widget_->setHeaderItem(new QTreeWidgetItem({"Name", "Type"})); diff --git a/gui/libObjectTree/include/object_tree_view/ObjectTreeView.h b/gui/libObjectTree/include/object_tree_view/ObjectTreeView.h index d3e56340..1f7766b8 100644 --- a/gui/libObjectTree/include/object_tree_view/ObjectTreeView.h +++ b/gui/libObjectTree/include/object_tree_view/ObjectTreeView.h @@ -82,7 +82,6 @@ public Q_SLOTS: virtual QMenu* createCustomContextMenu(const QPoint &p); - void dropEvent(QDropEvent *event) override; void dragMoveEvent(QDragMoveEvent *event) override; void mousePressEvent(QMouseEvent *event) override; diff --git a/gui/libObjectTree/include/object_tree_view_model/ObjectTreeViewDefaultModel.h b/gui/libObjectTree/include/object_tree_view_model/ObjectTreeViewDefaultModel.h index 77de5a17..f4e2355f 100644 --- a/gui/libObjectTree/include/object_tree_view_model/ObjectTreeViewDefaultModel.h +++ b/gui/libObjectTree/include/object_tree_view_model/ObjectTreeViewDefaultModel.h @@ -90,6 +90,7 @@ class ObjectTreeViewDefaultModel : public QAbstractItemModel { void setAcceptLuaModules(bool accept); void setAcceptLuaScripts(bool accept); void setAcceptLuaInterfaces(bool accept); + void setDropGltfOpensAssetImportDialog(bool flag); virtual Qt::TextElideMode textElideMode() const; @@ -118,7 +119,7 @@ class ObjectTreeViewDefaultModel : public QAbstractItemModel { public Q_SLOTS: core::SEditorObject createNewObject(const std::string& typeName, const std::string& nodeName = "", const QModelIndex& parent = QModelIndex()); - core::SEditorObject createNewObjectFromFile(const QFileInfo& fileInfo); + void dropFile(const QFileInfo& fileInfo, const QModelIndex& parent); virtual size_t deleteObjectsAtIndices(const QModelIndexList& indices); virtual void copyObjectsAtIndices(const QModelIndexList& indices, bool deepCopy); virtual void cutObjectsAtIndices(const QModelIndexList& indices, bool deepCut); @@ -198,6 +199,7 @@ public Q_SLOTS: bool acceptLuaModules_ = false; bool acceptLuaScripts_ = false; bool acceptLuaInterfaces_ = false; + bool gltfDropOpensAssetImportDialog_ = false; std::string getOriginPathFromMimeData(const QMimeData* data) const; QMimeData* generateMimeData(const QModelIndexList& indexes, const std::string& originPath) const; diff --git a/gui/libObjectTree/src/object_tree_view/ObjectTreeView.cpp b/gui/libObjectTree/src/object_tree_view/ObjectTreeView.cpp index eea1f784..f14d3bb8 100644 --- a/gui/libObjectTree/src/object_tree_view/ObjectTreeView.cpp +++ b/gui/libObjectTree/src/object_tree_view/ObjectTreeView.cpp @@ -488,12 +488,6 @@ QMenu* ObjectTreeView::createCustomContextMenu(const QPoint &p) { return treeViewMenu; } -void ObjectTreeView::dropEvent(QDropEvent *event) { - for (const auto& fileInfo : treeModel_->getAcceptableFilesInfo(event->mimeData())) { - treeModel_->createNewObjectFromFile(fileInfo); - } -} - void ObjectTreeView::dragMoveEvent(QDragMoveEvent *event) { setDropIndicatorShown(true); QTreeView::dragMoveEvent(event); diff --git a/gui/libObjectTree/src/object_tree_view_model/ObjectTreeViewDefaultModel.cpp b/gui/libObjectTree/src/object_tree_view_model/ObjectTreeViewDefaultModel.cpp index f022ade4..4171ad03 100644 --- a/gui/libObjectTree/src/object_tree_view_model/ObjectTreeViewDefaultModel.cpp +++ b/gui/libObjectTree/src/object_tree_view_model/ObjectTreeViewDefaultModel.cpp @@ -373,39 +373,43 @@ bool ObjectTreeViewDefaultModel::dropMimeData(const QMimeData* data, Qt::DropAct return true; } - if (!data->hasFormat(OBJECT_EDITOR_ID_MIME_TYPE)) { - return false; - } - - auto originPath = getOriginPathFromMimeData(data); - auto mimeDataContainsLocalInstances = originPath == project()->currentPath(); - auto movedItemIDs = decodeMimeData(data); + if (data->hasFormat(OBJECT_EDITOR_ID_MIME_TYPE)) { + auto originPath = getOriginPathFromMimeData(data); + auto mimeDataContainsLocalInstances = originPath == project()->currentPath(); + auto movedItemIDs = decodeMimeData(data); - if (mimeDataContainsLocalInstances) { - std::vector objs; - for (const auto& movedItemID : movedItemIDs) { - if (auto childObj = project()->getInstanceByID(movedItemID.toStdString())) { - objs.emplace_back(childObj); + if (mimeDataContainsLocalInstances) { + std::vector objs; + for (const auto& movedItemID : movedItemIDs) { + if (auto childObj = project()->getInstanceByID(movedItemID.toStdString())) { + objs.emplace_back(childObj); + } } - } - moveScenegraphChildren(objs, indexToSEditorObject(parent), row); - } else { - auto originCommandInterface = externalProjectStore_->getExternalProjectCommandInterface(originPath); - std::vector objs; - for (const auto& movedItemID : movedItemIDs) { - if (auto externalProjectObj = originCommandInterface->project()->getInstanceByID(movedItemID.toStdString())) { - objs.emplace_back(externalProjectObj); + moveScenegraphChildren(objs, indexToSEditorObject(parent), row); + } else { + auto originCommandInterface = externalProjectStore_->getExternalProjectCommandInterface(originPath); + std::vector objs; + for (const auto& movedItemID : movedItemIDs) { + if (auto externalProjectObj = originCommandInterface->project()->getInstanceByID(movedItemID.toStdString())) { + objs.emplace_back(externalProjectObj); + } } + auto serializedObjects = originCommandInterface->copyObjects(objs, true); + + auto pressedKeys = QGuiApplication::queryKeyboardModifiers(); + auto pasteAsExtRef = pressedKeys.testFlag(Qt::KeyboardModifier::AltModifier) || indexToTreeNode(parent)->getType() == ObjectTreeNodeType::ExtRefGroup; + pasteObjectAtIndex(parent, pasteAsExtRef, nullptr, serializedObjects); + return true; } - auto serializedObjects = originCommandInterface->copyObjects(objs, true); - auto pressedKeys = QGuiApplication::queryKeyboardModifiers(); - auto pasteAsExtRef = pressedKeys.testFlag(Qt::KeyboardModifier::AltModifier) || indexToTreeNode(parent)->getType() == ObjectTreeNodeType::ExtRefGroup; - pasteObjectAtIndex(parent, pasteAsExtRef, nullptr, serializedObjects); + } else if (!acceptableFileExtensions_.empty() && !getAcceptableFilesInfo(data).empty()) { + for (const auto& fileInfo : getAcceptableFilesInfo(data)) { + dropFile(fileInfo, parent); + } + return true; } - - return true; + return false; } Qt::ItemFlags ObjectTreeViewDefaultModel::flags(const QModelIndex& index) const { @@ -530,9 +534,13 @@ SEditorObject ObjectTreeViewDefaultModel::createNewObject(const std::string& typ return newObj; } -SEditorObject ObjectTreeViewDefaultModel::createNewObjectFromFile(const QFileInfo& fileInfo) { - object_creator::ObjectCreator objCreator(commandInterface_, acceptLuaModules_, acceptLuaInterfaces_, acceptLuaScripts_); - return objCreator.createNewObjectFromFile(fileInfo); +void ObjectTreeViewDefaultModel::dropFile(const QFileInfo& fileInfo, const QModelIndex& parent) { + if (gltfDropOpensAssetImportDialog_ && (fileInfo.suffix().toLower() == "glb" || fileInfo.suffix().toLower() == "gltf")) { + importMeshScenegraph(fileInfo.absoluteFilePath(), parent); + } else { + object_creator::ObjectCreator objCreator(commandInterface_, acceptLuaModules_, acceptLuaInterfaces_, acceptLuaScripts_); + objCreator.createNewObjectFromFile(fileInfo); + } } bool ObjectTreeViewDefaultModel::canCopyAtIndices(const QModelIndexList& indices) const { @@ -685,7 +693,7 @@ void ObjectTreeViewDefaultModel::importMeshScenegraph(const QString& filePath, c auto dummyCacheEntry = commandInterface_->meshCache()->registerFileChangedHandler(absPath, {nullptr, nullptr}); if (auto sceneGraphPtr = commandInterface_->meshCache()->getMeshScenegraph(absPath)) { MeshScenegraph sceneGraph{*sceneGraphPtr}; - auto importStatus = raco::common_widgets::MeshAssetImportDialog(sceneGraph, project()->featureLevel(), nullptr).exec(); + auto importStatus = raco::common_widgets::MeshAssetImportDialog(sceneGraph, project()->featureLevel(), QFileInfo(filePath).fileName(), nullptr).exec(); if (importStatus == QDialog::Accepted) { commandInterface_->insertAssetScenegraph(sceneGraph, absPath, selectedObject); } @@ -823,6 +831,10 @@ void ObjectTreeViewDefaultModel::setAcceptLuaInterfaces(bool accept) { acceptLuaInterfaces_ = accept; } +void ObjectTreeViewDefaultModel::setDropGltfOpensAssetImportDialog(bool flag) { + gltfDropOpensAssetImportDialog_ = flag; +} + bool ObjectTreeViewDefaultModel::setData(const QModelIndex& index, const QVariant& value, int role) { bool success{false}; diff --git a/gui/libPropertyBrowser/src/PropertyBrowserItem.cpp b/gui/libPropertyBrowser/src/PropertyBrowserItem.cpp index a92cdf52..af03db58 100644 --- a/gui/libPropertyBrowser/src/PropertyBrowserItem.cpp +++ b/gui/libPropertyBrowser/src/PropertyBrowserItem.cpp @@ -457,7 +457,12 @@ std::string PropertyBrowserItem::errorMessage() const { if (messages.size() == 1) { return *messages.begin(); } else if (messages.size() > 1) { - return "Multiple Errors"; + std::map levelDesc = { + {core::ErrorLevel::NONE, ""}, + {core::ErrorLevel::INFORMATION, "Information Items"}, + {core::ErrorLevel::WARNING, "Warnings"}, + {core::ErrorLevel::ERROR, "Errors"}}; + return "Multiple " + levelDesc[maxErrorLevel()]; } return {}; }