QmlDesigner: Automatically determine if CreateTexture needs import

Avoid having to pass to CreateTexture whether the asset needs importing
or not. Instead check if the asset is already inside the porject or
not. Also small relevant tweaks.

Change-Id: I6a449d76a6b70ab34fe81762fc9e3eacf9b64d04
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Mahmoud Badri
2023-03-09 18:13:43 +02:00
parent dc254b9a36
commit 27e2823591
7 changed files with 42 additions and 61 deletions

View File

@@ -5,25 +5,20 @@
#include "bindingproperty.h"
#include "createtexture.h"
#include "designmodecontext.h"
#include "materialbrowsermodel.h"
#include "materialbrowsertexturesmodel.h"
#include "materialbrowserwidget.h"
#include "nodeabstractproperty.h"
#include "nodeinstanceview.h"
#include "nodemetainfo.h"
#include "qmldesignerconstants.h"
#include "qmlobjectnode.h"
#include "variantproperty.h"
#include <designmodecontext.h>
#include <nodeinstanceview.h>
#include <nodelistproperty.h>
#include <qmldesignerconstants.h>
#include <coreplugin/icore.h>
#include <coreplugin/messagebox.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projecttree.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
@@ -31,7 +26,6 @@
#include <QQmlEngine>
#include <QQuickItem>
#include <QQuickView>
#include <QRegularExpression>
#include <QTimer>
namespace QmlDesigner {
@@ -648,16 +642,7 @@ void MaterialBrowserView::applyTextureToProperty(const QString &matId, const QSt
{
executeInTransaction(__FUNCTION__, [&] {
if (m_appliedTextureId.isEmpty() && !m_appliedTexturePath.isEmpty()) {
bool import = true;
using namespace ProjectExplorer;
if (Project *proj = ProjectTree::currentProject()) {
Utils::FilePath projDir = proj->projectFilePath().parentDir().pathAppended("content");
if (m_appliedTexturePath.startsWith(projDir.toString()))
import = false;
}
auto texCreator = new CreateTexture(this, import);
auto texCreator = new CreateTexture(this);
ModelNode tex = texCreator->execute(m_appliedTexturePath, AddTextureMode::Texture);
m_appliedTextureId = tex.id();
m_appliedTexturePath.clear();