forked from qt-creator/qt-creator
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:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "navigatortreemodel.h"
|
||||
#include "navigatorview.h"
|
||||
#include "qmldesignerplugin.h"
|
||||
|
||||
#include <bindingproperty.h>
|
||||
#include <designersettings.h>
|
||||
@@ -49,6 +50,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QApplication>
|
||||
#include <QPointF>
|
||||
#include <QDir>
|
||||
|
||||
#include <coreplugin/messagebox.h>
|
||||
|
||||
@@ -555,7 +557,8 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
|
||||
ModelNode targetNode(modelNodeForIndex(rowModelIndex));
|
||||
|
||||
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;
|
||||
|
||||
if (targetNode.isSubclassOf("QtQuick3D.DefaultMaterial")) {
|
||||
@@ -569,7 +572,7 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
|
||||
// set texture source
|
||||
PropertyName prop = "source";
|
||||
QString type = "QUrl";
|
||||
QVariant val = imageFileName;
|
||||
QVariant val = imagePath;
|
||||
itemLibraryEntry.addProperty(prop, type, val);
|
||||
|
||||
// create a texture
|
||||
@@ -581,8 +584,9 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
|
||||
});
|
||||
} else if (targetNode.isSubclassOf("QtQuick3D.Texture")) {
|
||||
// if dropping an image on a texture, set the texture source
|
||||
targetNode.variantProperty("source").setValue(imageFileName);
|
||||
targetNode.variantProperty("source").setValue(imagePath);
|
||||
} else {
|
||||
|
||||
// create an image
|
||||
newModelNode = QmlItemNode::createQmlItemNodeFromImage(m_view, imageSource , QPointF(), targetProperty);
|
||||
}
|
||||
|
Reference in New Issue
Block a user