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 243e0d96622..f41bd676053 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp @@ -97,6 +97,21 @@ void ContentLibraryUserModel::addMaterial(const QString &name, const QString &qm emit dataChanged(index(matSectionIdx, 0), index(matSectionIdx, 0)); } +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 26edbf5ec33..92f66b9201c 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h @@ -71,6 +71,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();