forked from qt-creator/qt-creator
QmlDesigner: Allow dropping content library textures in Navigator
Fixes: QDS-13575 Change-Id: Idefa22696a859919f6932854039c06a992ce4d46 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -226,11 +226,10 @@ void NameItemDelegate::paint(QPainter *painter,
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool validDrop = false;
|
bool validDrop = false;
|
||||||
if (dragType == Constants::MIME_TYPE_BUNDLE_TEXTURE) {
|
if (dragType == Constants::MIME_TYPE_ASSET_TEXTURE3D) {
|
||||||
validDrop = metaInfo.isQtQuick3DModel();
|
|
||||||
} else if (dragType == Constants::MIME_TYPE_ASSET_TEXTURE3D) {
|
|
||||||
validDrop = isValid3dTextureTarget();
|
validDrop = isValid3dTextureTarget();
|
||||||
} else if (dragType == Constants::MIME_TYPE_ASSET_IMAGE) {
|
} else if (dragType == Constants::MIME_TYPE_ASSET_IMAGE
|
||||||
|
|| dragType == Constants::MIME_TYPE_BUNDLE_TEXTURE) {
|
||||||
Model *model = node.model();
|
Model *model = node.model();
|
||||||
validDrop = isValid3dTextureTarget() || metaInfo.isBasedOn(model->qtQuickImageMetaInfo(),
|
validDrop = isValid3dTextureTarget() || metaInfo.isBasedOn(model->qtQuickImageMetaInfo(),
|
||||||
model->qtQuickBorderImageMetaInfo());
|
model->qtQuickBorderImageMetaInfo());
|
||||||
|
@@ -2,12 +2,14 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "navigatortreemodel.h"
|
#include "navigatortreemodel.h"
|
||||||
|
|
||||||
|
#include "assetslibrarywidget.h"
|
||||||
|
#include "choosefrompropertylistdialog.h"
|
||||||
|
#include "createtexture.h"
|
||||||
#include "navigatorview.h"
|
#include "navigatorview.h"
|
||||||
#include "navigatorwidget.h"
|
#include "navigatorwidget.h"
|
||||||
#include "choosefrompropertylistdialog.h"
|
|
||||||
#include "qmldesignerconstants.h"
|
#include "qmldesignerconstants.h"
|
||||||
#include "qmldesignerplugin.h"
|
#include "qmldesignerplugin.h"
|
||||||
#include "assetslibrarywidget.h"
|
|
||||||
|
|
||||||
#include <abstractview.h>
|
#include <abstractview.h>
|
||||||
#include <bindingproperty.h>
|
#include <bindingproperty.h>
|
||||||
@@ -176,6 +178,7 @@ static void reparentModelNodeToNodeProperty(NodeAbstractProperty &parentProperty
|
|||||||
}
|
}
|
||||||
|
|
||||||
NavigatorTreeModel::NavigatorTreeModel(QObject *parent) : QAbstractItemModel(parent)
|
NavigatorTreeModel::NavigatorTreeModel(QObject *parent) : QAbstractItemModel(parent)
|
||||||
|
, m_createTextures(Utils::makeUniqueObjectPtr<CreateTextures>(m_view))
|
||||||
{
|
{
|
||||||
m_actionManager = &QmlDesignerPlugin::instance()->viewManager().designerActionManager();
|
m_actionManager = &QmlDesignerPlugin::instance()->viewManager().designerActionManager();
|
||||||
}
|
}
|
||||||
@@ -569,6 +572,30 @@ bool NavigatorTreeModel::dropMimeData(const QMimeData *mimeData,
|
|||||||
if (targetNode.metaInfo().isQtQuick3DModel()) {
|
if (targetNode.metaInfo().isQtQuick3DModel()) {
|
||||||
QmlDesignerPlugin::instance()->mainWidget()->showDockWidget("MaterialBrowser");
|
QmlDesignerPlugin::instance()->mainWidget()->showDockWidget("MaterialBrowser");
|
||||||
m_view->emitCustomNotification("apply_asset_to_model3D", {targetNode}, {filePath}); // To MaterialBrowserView
|
m_view->emitCustomNotification("apply_asset_to_model3D", {targetNode}, {filePath}); // To MaterialBrowserView
|
||||||
|
} else {
|
||||||
|
QString texturePath = QString::fromUtf8(mimeData->data(Constants::MIME_TYPE_BUNDLE_TEXTURE));
|
||||||
|
NodeAbstractProperty targetProperty;
|
||||||
|
|
||||||
|
const QModelIndex rowModelIndex = dropModelIndex.sibling(dropModelIndex.row(), 0);
|
||||||
|
int targetRowNumber = rowNumber;
|
||||||
|
bool foundTarget = findTargetProperty(rowModelIndex, this, &targetProperty, &targetRowNumber);
|
||||||
|
if (foundTarget) {
|
||||||
|
bool moveNodesAfter = false;
|
||||||
|
|
||||||
|
m_view->executeInTransaction(__FUNCTION__, [&] {
|
||||||
|
m_createTextures->execute(QStringList{texturePath},
|
||||||
|
AddTextureMode::Image,
|
||||||
|
Utils3D::active3DSceneId(m_view->model()));
|
||||||
|
QString textureName = Utils::FilePath::fromString(texturePath).fileName();
|
||||||
|
QString textureAbsolutePath = DocumentManager::currentResourcePath()
|
||||||
|
.pathAppended("images/" + textureName).toString();
|
||||||
|
ModelNodeOperations::handleItemLibraryImageDrop(textureAbsolutePath,
|
||||||
|
targetProperty,
|
||||||
|
modelNodeForIndex(
|
||||||
|
rowModelIndex),
|
||||||
|
moveNodesAfter);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (mimeData->hasFormat(Constants::MIME_TYPE_BUNDLE_MATERIAL)) {
|
} else if (mimeData->hasFormat(Constants::MIME_TYPE_BUNDLE_MATERIAL)) {
|
||||||
if (targetNode.isValid())
|
if (targetNode.isValid())
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <modelnode.h>
|
#include <modelnode.h>
|
||||||
#include <nodemetainfo.h>
|
#include <nodemetainfo.h>
|
||||||
|
#include <utils/uniqueobjectptr.h>
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
@@ -16,10 +17,11 @@ QT_FORWARD_DECLARE_CLASS(QPixmap)
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
class Model;
|
class CreateTextures;
|
||||||
class NavigatorView;
|
|
||||||
class ModelNode;
|
|
||||||
class DesignerActionManager;
|
class DesignerActionManager;
|
||||||
|
class Model;
|
||||||
|
class ModelNode;
|
||||||
|
class NavigatorView;
|
||||||
|
|
||||||
class NavigatorTreeModel : public QAbstractItemModel, public NavigatorModelInterface
|
class NavigatorTreeModel : public QAbstractItemModel, public NavigatorModelInterface
|
||||||
{
|
{
|
||||||
@@ -103,6 +105,7 @@ private:
|
|||||||
bool moveNodeToParent(const NodeAbstractProperty &targetProperty, const ModelNode &newModelNode);
|
bool moveNodeToParent(const NodeAbstractProperty &targetProperty, const ModelNode &newModelNode);
|
||||||
|
|
||||||
QPointer<NavigatorView> m_view;
|
QPointer<NavigatorView> m_view;
|
||||||
|
Utils::UniqueObjectPtr<CreateTextures> m_createTextures;
|
||||||
mutable QHash<ModelNode, QModelIndex> m_nodeIndexHash;
|
mutable QHash<ModelNode, QModelIndex> m_nodeIndexHash;
|
||||||
mutable QHash<ModelNode, QList<ModelNode> > m_rowCache;
|
mutable QHash<ModelNode, QList<ModelNode> > m_rowCache;
|
||||||
bool m_showOnlyVisibleItems = true;
|
bool m_showOnlyVisibleItems = true;
|
||||||
|
Reference in New Issue
Block a user