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:
Shrief Gabr
2024-09-19 15:12:55 +03:00
parent d25d40a198
commit 0bc8421616
3 changed files with 38 additions and 9 deletions

View File

@@ -226,11 +226,10 @@ void NameItemDelegate::paint(QPainter *painter,
};
bool validDrop = false;
if (dragType == Constants::MIME_TYPE_BUNDLE_TEXTURE) {
validDrop = metaInfo.isQtQuick3DModel();
} else if (dragType == Constants::MIME_TYPE_ASSET_TEXTURE3D) {
if (dragType == Constants::MIME_TYPE_ASSET_TEXTURE3D) {
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();
validDrop = isValid3dTextureTarget() || metaInfo.isBasedOn(model->qtQuickImageMetaInfo(),
model->qtQuickBorderImageMetaInfo());

View File

@@ -2,12 +2,14 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "navigatortreemodel.h"
#include "assetslibrarywidget.h"
#include "choosefrompropertylistdialog.h"
#include "createtexture.h"
#include "navigatorview.h"
#include "navigatorwidget.h"
#include "choosefrompropertylistdialog.h"
#include "qmldesignerconstants.h"
#include "qmldesignerplugin.h"
#include "assetslibrarywidget.h"
#include <abstractview.h>
#include <bindingproperty.h>
@@ -176,6 +178,7 @@ static void reparentModelNodeToNodeProperty(NodeAbstractProperty &parentProperty
}
NavigatorTreeModel::NavigatorTreeModel(QObject *parent) : QAbstractItemModel(parent)
, m_createTextures(Utils::makeUniqueObjectPtr<CreateTextures>(m_view))
{
m_actionManager = &QmlDesignerPlugin::instance()->viewManager().designerActionManager();
}
@@ -569,6 +572,30 @@ bool NavigatorTreeModel::dropMimeData(const QMimeData *mimeData,
if (targetNode.metaInfo().isQtQuick3DModel()) {
QmlDesignerPlugin::instance()->mainWidget()->showDockWidget("MaterialBrowser");
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)) {
if (targetNode.isValid())

View File

@@ -7,6 +7,7 @@
#include <modelnode.h>
#include <nodemetainfo.h>
#include <utils/uniqueobjectptr.h>
#include <QAbstractItemModel>
#include <QPointer>
@@ -16,10 +17,11 @@ QT_FORWARD_DECLARE_CLASS(QPixmap)
namespace QmlDesigner {
class Model;
class NavigatorView;
class ModelNode;
class CreateTextures;
class DesignerActionManager;
class Model;
class ModelNode;
class NavigatorView;
class NavigatorTreeModel : public QAbstractItemModel, public NavigatorModelInterface
{
@@ -103,6 +105,7 @@ private:
bool moveNodeToParent(const NodeAbstractProperty &targetProperty, const ModelNode &newModelNode);
QPointer<NavigatorView> m_view;
Utils::UniqueObjectPtr<CreateTextures> m_createTextures;
mutable QHash<ModelNode, QModelIndex> m_nodeIndexHash;
mutable QHash<ModelNode, QList<ModelNode> > m_rowCache;
bool m_showOnlyVisibleItems = true;