QmlDesigner: Fix material texture not updating after image DnD

Image path from project root is used instead of image name to make it
work when the image is inside a folder.

Task-number: QDS-1956
Change-Id: Ia5e10d7bf893902eaea6551e3ec6daafd7977a83
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Mahmoud Badri
2020-04-20 15:37:36 +03:00
parent 98ad7f96bb
commit 2f99a87a3f

View File

@@ -25,6 +25,7 @@
#include "navigatortreemodel.h" #include "navigatortreemodel.h"
#include "navigatorview.h" #include "navigatorview.h"
#include "qmldesignerplugin.h"
#include <bindingproperty.h> #include <bindingproperty.h>
#include <designersettings.h> #include <designersettings.h>
@@ -49,6 +50,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QApplication> #include <QApplication>
#include <QPointF> #include <QPointF>
#include <QDir>
#include <coreplugin/messagebox.h> #include <coreplugin/messagebox.h>
@@ -555,7 +557,8 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
ModelNode targetNode(modelNodeForIndex(rowModelIndex)); ModelNode targetNode(modelNodeForIndex(rowModelIndex));
const QString imageSource = QString::fromUtf8(mimeData->data("application/vnd.bauhaus.libraryresource")); // absolute path const QString imageSource = QString::fromUtf8(mimeData->data("application/vnd.bauhaus.libraryresource")); // absolute path
const QString imageFileName = imageSource.mid(imageSource.lastIndexOf('/') + 1); const QString imagePath = QmlDesignerPlugin::instance()->documentManager().currentFilePath().toFileInfo().dir().relativeFilePath(imageSource); // relative to .ui.qml file
ModelNode newModelNode; ModelNode newModelNode;
if (targetNode.isSubclassOf("QtQuick3D.DefaultMaterial")) { if (targetNode.isSubclassOf("QtQuick3D.DefaultMaterial")) {
@@ -569,7 +572,7 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
// set texture source // set texture source
PropertyName prop = "source"; PropertyName prop = "source";
QString type = "QUrl"; QString type = "QUrl";
QVariant val = imageFileName; QVariant val = imagePath;
itemLibraryEntry.addProperty(prop, type, val); itemLibraryEntry.addProperty(prop, type, val);
// create a texture // create a texture
@@ -581,8 +584,9 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
}); });
} else if (targetNode.isSubclassOf("QtQuick3D.Texture")) { } else if (targetNode.isSubclassOf("QtQuick3D.Texture")) {
// if dropping an image on a texture, set the texture source // if dropping an image on a texture, set the texture source
targetNode.variantProperty("source").setValue(imageFileName); targetNode.variantProperty("source").setValue(imagePath);
} else { } else {
// create an image // create an image
newModelNode = QmlItemNode::createQmlItemNodeFromImage(m_view, imageSource , QPointF(), targetProperty); newModelNode = QmlItemNode::createQmlItemNodeFromImage(m_view, imageSource , QPointF(), targetProperty);
} }