From cc187e1ce66d0b831b7da0eccce96cb1fc857955 Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Wed, 24 Apr 2024 19:15:59 +0300 Subject: [PATCH] QmlDesigner: remove a texture from content library user tab Fixes: QDS-12542 Change-Id: Iee3ea0bd8a3ce6cb41c27a645801eef608cd8da8 Reviewed-by: Miikka Heikkinen --- .../ContentLibraryTextureContextMenu.qml | 12 ++++++++++-- .../ContentLibraryUserView.qml | 1 + .../contentlibrary/contentlibraryusermodel.cpp | 15 +++++++++++++++ .../contentlibrary/contentlibraryusermodel.h | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTextureContextMenu.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTextureContextMenu.qml index f804f16d893..b1f690f10c9 100644 --- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTextureContextMenu.qml +++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTextureContextMenu.qml @@ -12,6 +12,7 @@ StudioControls.Menu { property var targetTexture: null property bool hasSceneEnv: false + property bool enableRemove: false // true: adds an option to remove targetTexture property bool canUse3D: targetTexture && ContentLibraryBackend.rootView.hasQuick3DImport && ContentLibraryBackend.rootView.hasMaterialLibrary @@ -32,13 +33,20 @@ StudioControls.Menu { StudioControls.MenuItem { text: qsTr("Add texture") - enabled: canUse3D + enabled: root.canUse3D onTriggered: ContentLibraryBackend.rootView.addTexture(root.targetTexture) } StudioControls.MenuItem { text: qsTr("Add light probe") - enabled: root.hasSceneEnv && canUse3D + enabled: root.hasSceneEnv && root.canUse3D onTriggered: ContentLibraryBackend.rootView.addLightProbe(root.targetTexture) } + + StudioControls.MenuItem { + text: qsTr("Remove from Content Library") + visible: root.targetTexture && root.enableRemove + height: visible ? implicitHeight : 0 + onTriggered: ContentLibraryBackend.userModel.removeTexture(root.targetTexture) + } } diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml index 1288e14c2a7..d711a0fc310 100644 --- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml +++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml @@ -61,6 +61,7 @@ HelperWidgets.ScrollView { ContentLibraryTextureContextMenu { id: ctxMenuTexture + enableRemove: true hasSceneEnv: ContentLibraryBackend.texturesModel.hasSceneEnv } diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp index ed9723a1512..793e3bbe7ad 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp @@ -121,6 +121,21 @@ void ContentLibraryUserModel::addTextures(const QStringList &paths) emit dataChanged(index(texSectionIdx), index(texSectionIdx)); } +void ContentLibraryUserModel::removeTexture(ContentLibraryTexture *tex) +{ + // remove resources + Utils::FilePath::fromString(tex->texturePath()).removeFile(); + Utils::FilePath::fromString(tex->iconPath()).removeFile(); + + // remove from model + m_userTextures.removeOne(tex); + tex->deleteLater(); + + // update model + int texSectionIdx = 1; + emit dataChanged(index(texSectionIdx), index(texSectionIdx)); +} + // returns unique library material's name and qml component QPair ContentLibraryUserModel::getUniqueLibMaterialNameAndQml(const QString &matName) const { diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h index 3e9a96fd9d7..affa9a89120 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h @@ -72,6 +72,7 @@ public: Q_INVOKABLE void applyToSelected(QmlDesigner::ContentLibraryMaterial *mat, bool add = false); Q_INVOKABLE void addToProject(QmlDesigner::ContentLibraryMaterial *mat); Q_INVOKABLE void removeFromProject(QmlDesigner::ContentLibraryMaterial *mat); + Q_INVOKABLE void removeTexture(QmlDesigner::ContentLibraryTexture *tex); signals: void isEmptyChanged();