forked from qt-creator/qt-creator
QmlDesigner: Fix texture source path for newly created textures
Fixes: QDS-8448 Change-Id: Ibaf51444f2dff8d3de95edd4c8afbc7bc2cd2241 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
committed by
Tim Jenssen
parent
e1fce66f38
commit
6dfe325083
@@ -43,10 +43,8 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ToolTip {
|
ToolTip {
|
||||||
property bool hasSource: textureSource.slice(-1) !== "/"
|
|
||||||
|
|
||||||
visible: mouseArea.containsMouse
|
visible: mouseArea.containsMouse
|
||||||
text: hasSource ? textureSource : qsTr("Texture has no source image.")
|
text: textureSource ? textureSource : qsTr("Texture has no source image.")
|
||||||
delay: 1000
|
delay: 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1731,6 +1731,13 @@ bool validateEffect(const QString &effectPath)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils::FilePath getImagesDefaultDirectory()
|
||||||
|
{
|
||||||
|
return Utils::FilePath::fromString(
|
||||||
|
getAssetDefaultDirectory(
|
||||||
|
"images", QmlDesignerPlugin::instance()->documentManager().currentProjectDirPath().toString()));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ModelNodeOperations
|
} // namespace ModelNodeOperations
|
||||||
|
|
||||||
} //QmlDesigner
|
} //QmlDesigner
|
||||||
|
@@ -125,6 +125,8 @@ QString getEffectIcon(const QString &effectPath);
|
|||||||
bool useLayerEffect();
|
bool useLayerEffect();
|
||||||
bool validateEffect(const QString &effectPath);
|
bool validateEffect(const QString &effectPath);
|
||||||
|
|
||||||
|
Utils::FilePath getImagesDefaultDirectory();
|
||||||
|
|
||||||
// ModelNodePreviewImageOperations
|
// ModelNodePreviewImageOperations
|
||||||
QVariant previewImageDataForGenericNode(const ModelNode &modelNode);
|
QVariant previewImageDataForGenericNode(const ModelNode &modelNode);
|
||||||
QVariant previewImageDataForImageNode(const ModelNode &modelNode);
|
QVariant previewImageDataForImageNode(const ModelNode &modelNode);
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
#include "createtexture.h"
|
#include "createtexture.h"
|
||||||
|
|
||||||
#include "abstractview.h"
|
#include "abstractview.h"
|
||||||
|
#include "documentmanager.h"
|
||||||
#include "modelnodeoperations.h"
|
#include "modelnodeoperations.h"
|
||||||
#include "nodelistproperty.h"
|
#include "nodelistproperty.h"
|
||||||
#include "nodemetainfo.h"
|
#include "nodemetainfo.h"
|
||||||
@@ -41,7 +42,8 @@ void CreateTexture::execute(const QString &filePath, AddTextureMode mode, int sc
|
|||||||
|
|
||||||
bool CreateTexture::addFileToProject(const QString &filePath)
|
bool CreateTexture::addFileToProject(const QString &filePath)
|
||||||
{
|
{
|
||||||
AddFilesResult result = ModelNodeOperations::addImageToProject({filePath}, "images", false);
|
AddFilesResult result = ModelNodeOperations::addImageToProject(
|
||||||
|
{filePath}, ModelNodeOperations::getImagesDefaultDirectory().toString(), false);
|
||||||
|
|
||||||
if (result.status() == AddFilesResult::Failed) {
|
if (result.status() == AddFilesResult::Failed) {
|
||||||
Core::AsynchronousMessageBox::warning(QObject::tr("Failed to Add Texture"),
|
Core::AsynchronousMessageBox::warning(QObject::tr("Failed to Add Texture"),
|
||||||
@@ -63,12 +65,16 @@ ModelNode CreateTexture::createTextureFromImage(const QString &assetPath, AddTex
|
|||||||
|
|
||||||
NodeMetaInfo metaInfo = m_view->model()->qtQuick3DTextureMetaInfo();
|
NodeMetaInfo metaInfo = m_view->model()->qtQuick3DTextureMetaInfo();
|
||||||
|
|
||||||
QString sourceVal = QLatin1String("images/%1").arg(assetPath.split('/').last());
|
Utils::FilePath imagePath = ModelNodeOperations::getImagesDefaultDirectory()
|
||||||
|
.pathAppended(Utils::FilePath::fromString(assetPath).fileName());
|
||||||
|
QString sourceVal = imagePath.relativePathFrom(
|
||||||
|
QmlDesigner::DocumentManager::currentFilePath()).toString();
|
||||||
|
|
||||||
ModelNode newTexNode = m_view->getTextureDefaultInstance(sourceVal);
|
ModelNode newTexNode = m_view->getTextureDefaultInstance(sourceVal);
|
||||||
if (!newTexNode.isValid()) {
|
if (!newTexNode.isValid()) {
|
||||||
newTexNode = m_view->createModelNode("QtQuick3D.Texture",
|
newTexNode = m_view->createModelNode("QtQuick3D.Texture",
|
||||||
metaInfo.majorVersion(),
|
metaInfo.majorVersion(),
|
||||||
metaInfo.minorVersion());
|
metaInfo.minorVersion());
|
||||||
newTexNode.validId();
|
newTexNode.validId();
|
||||||
VariantProperty sourceProp = newTexNode.variantProperty("source");
|
VariantProperty sourceProp = newTexNode.variantProperty("source");
|
||||||
sourceProp.setValue(sourceVal);
|
sourceProp.setValue(sourceVal);
|
||||||
|
@@ -34,7 +34,12 @@ QVariant MaterialBrowserTexturesModel::data(const QModelIndex &index, int role)
|
|||||||
QByteArray roleName = roleNames().value(role);
|
QByteArray roleName = roleNames().value(role);
|
||||||
if (roleName == "textureSource") {
|
if (roleName == "textureSource") {
|
||||||
QString source = m_textureList.at(index.row()).variantProperty("source").value().toString();
|
QString source = m_textureList.at(index.row()).variantProperty("source").value().toString();
|
||||||
return QVariant(DocumentManager::currentResourcePath().path() + '/' + source);
|
if (source.isEmpty())
|
||||||
|
return {};
|
||||||
|
if (Utils::FilePath::fromString(source).isAbsolutePath())
|
||||||
|
return QVariant(source);
|
||||||
|
return QVariant(QmlDesignerPlugin::instance()->documentManager().currentDesignDocument()
|
||||||
|
->fileName().absolutePath().pathAppended(source).cleanPath().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (roleName == "textureVisible")
|
if (roleName == "textureVisible")
|
||||||
|
@@ -450,87 +450,9 @@ void MaterialBrowserView::customNotification(const AbstractView *view,
|
|||||||
applyTextureToModel3D(nodeList.at(0), nodeList.at(1));
|
applyTextureToModel3D(nodeList.at(0), nodeList.at(1));
|
||||||
} else if (identifier == "apply_texture_to_material") {
|
} else if (identifier == "apply_texture_to_material") {
|
||||||
applyTextureToMaterial({nodeList.at(0)}, nodeList.at(1));
|
applyTextureToMaterial({nodeList.at(0)}, nodeList.at(1));
|
||||||
} else if (identifier == "add_textures") {
|
|
||||||
if (data.size() != 4) {
|
|
||||||
qWarning() << "Wrong number of arguments passed to add_textures: " << data.size();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray identifier = data.at(0).toByteArray();
|
|
||||||
QStringList filePaths = data.at(1).toStringList();
|
|
||||||
AddTextureMode mode = data.at(2).value<AddTextureMode>();
|
|
||||||
bool addToProject = data.at(3).toBool();
|
|
||||||
|
|
||||||
executeInTransaction(identifier, [&] {
|
|
||||||
addTextures(filePaths, mode, addToProject);
|
|
||||||
});
|
|
||||||
} else if (identifier == "add_texture") {
|
|
||||||
if (data.size() != 4) {
|
|
||||||
qWarning() << "Wrong number of arguments passed to add_texture: " << data.size();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray identifier = data.at(0).toByteArray();
|
|
||||||
QString filePath = data.at(1).toString();
|
|
||||||
AddTextureMode mode = data.at(2).value<AddTextureMode>();
|
|
||||||
bool addToProject = data.at(3).toBool();
|
|
||||||
|
|
||||||
executeInTransaction(identifier, [&] {
|
|
||||||
addOneTexture(filePath, mode, addToProject);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialBrowserView::addOneTexture(const QString &texPath, AddTextureMode mode, bool addToProject)
|
|
||||||
{
|
|
||||||
if (addToProject) {
|
|
||||||
// copy image to project
|
|
||||||
AddFilesResult result = ModelNodeOperations::addImageToProject({texPath}, "images", false);
|
|
||||||
|
|
||||||
if (result.status() == AddFilesResult::Failed) {
|
|
||||||
Core::AsynchronousMessageBox::warning(tr("Failed to Add Texture"),
|
|
||||||
tr("Could not add %1 to project.").arg(texPath));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == AddTextureMode::Image)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// create a texture from the image
|
|
||||||
ModelNode matLib = materialLibraryNode();
|
|
||||||
if (!matLib.isValid())
|
|
||||||
return;
|
|
||||||
|
|
||||||
NodeMetaInfo metaInfo = model()->metaInfo("QtQuick3D.Texture");
|
|
||||||
|
|
||||||
QString sourceVal = QLatin1String("images/%1").arg(texPath.split('/').last());
|
|
||||||
ModelNode texNode = getTextureDefaultInstance(sourceVal);
|
|
||||||
if (!texNode.isValid()) {
|
|
||||||
texNode = createModelNode("QtQuick3D.Texture", metaInfo.majorVersion(),
|
|
||||||
metaInfo.minorVersion());
|
|
||||||
texNode.validId();
|
|
||||||
VariantProperty sourceProp = texNode.variantProperty("source");
|
|
||||||
sourceProp.setValue(sourceVal);
|
|
||||||
matLib.defaultNodeListProperty().reparentHere(texNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// assign the texture as scene environment's light probe
|
|
||||||
if (mode == AddTextureMode::LightProbe && m_sceneId != -1) {
|
|
||||||
QmlObjectNode sceneEnv = resolveSceneEnv();
|
|
||||||
if (sceneEnv.isValid()) {
|
|
||||||
sceneEnv.setBindingProperty("lightProbe", texNode.id());
|
|
||||||
sceneEnv.setVariantProperty("backgroundMode",
|
|
||||||
QVariant::fromValue(Enumeration("SceneEnvironment",
|
|
||||||
"SkyBox")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QTimer::singleShot(0, this, [this, texNode]() {
|
|
||||||
if (model() && texNode.isValid())
|
|
||||||
emitCustomNotification("selected_texture_changed", {texNode});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaterialBrowserView::active3DSceneChanged(qint32 sceneId)
|
void MaterialBrowserView::active3DSceneChanged(qint32 sceneId)
|
||||||
{
|
{
|
||||||
m_sceneId = sceneId;
|
m_sceneId = sceneId;
|
||||||
@@ -559,12 +481,6 @@ ModelNode MaterialBrowserView::resolveSceneEnv()
|
|||||||
return activeSceneEnv;
|
return activeSceneEnv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialBrowserView::addTextures(const QStringList &filePaths, AddTextureMode mode, bool addToProject)
|
|
||||||
{
|
|
||||||
for (const QString &texPath : filePaths)
|
|
||||||
addOneTexture(texPath, mode, addToProject);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaterialBrowserView::instancesCompleted(const QVector<ModelNode> &completedNodeList)
|
void MaterialBrowserView::instancesCompleted(const QVector<ModelNode> &completedNodeList)
|
||||||
{
|
{
|
||||||
for (const ModelNode &node : completedNodeList) {
|
for (const ModelNode &node : completedNodeList) {
|
||||||
|
@@ -69,9 +69,6 @@ private:
|
|||||||
void requestPreviews();
|
void requestPreviews();
|
||||||
ModelNode resolveSceneEnv();
|
ModelNode resolveSceneEnv();
|
||||||
|
|
||||||
void addOneTexture(const QString &filePath, AddTextureMode mode, bool addToProject);
|
|
||||||
void addTextures(const QStringList &texturePaths, AddTextureMode mode, bool addToProject);
|
|
||||||
|
|
||||||
AsynchronousImageCache &m_imageCache;
|
AsynchronousImageCache &m_imageCache;
|
||||||
QPointer<MaterialBrowserWidget> m_widget;
|
QPointer<MaterialBrowserWidget> m_widget;
|
||||||
QList<ModelNode> m_selectedModels; // selected 3D model nodes
|
QList<ModelNode> m_selectedModels; // selected 3D model nodes
|
||||||
|
Reference in New Issue
Block a user