QmlDesigner: remove a texture from content library user tab

Fixes: QDS-12542
Change-Id: Iee3ea0bd8a3ce6cb41c27a645801eef608cd8da8
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Mahmoud Badri
2024-04-24 19:15:59 +03:00
parent 99e04056f1
commit cc187e1ce6
4 changed files with 27 additions and 2 deletions

View File

@@ -12,6 +12,7 @@ StudioControls.Menu {
property var targetTexture: null property var targetTexture: null
property bool hasSceneEnv: false 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 property bool canUse3D: targetTexture && ContentLibraryBackend.rootView.hasQuick3DImport && ContentLibraryBackend.rootView.hasMaterialLibrary
@@ -32,13 +33,20 @@ StudioControls.Menu {
StudioControls.MenuItem { StudioControls.MenuItem {
text: qsTr("Add texture") text: qsTr("Add texture")
enabled: canUse3D enabled: root.canUse3D
onTriggered: ContentLibraryBackend.rootView.addTexture(root.targetTexture) onTriggered: ContentLibraryBackend.rootView.addTexture(root.targetTexture)
} }
StudioControls.MenuItem { StudioControls.MenuItem {
text: qsTr("Add light probe") text: qsTr("Add light probe")
enabled: root.hasSceneEnv && canUse3D enabled: root.hasSceneEnv && root.canUse3D
onTriggered: ContentLibraryBackend.rootView.addLightProbe(root.targetTexture) 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)
}
} }

View File

@@ -61,6 +61,7 @@ HelperWidgets.ScrollView {
ContentLibraryTextureContextMenu { ContentLibraryTextureContextMenu {
id: ctxMenuTexture id: ctxMenuTexture
enableRemove: true
hasSceneEnv: ContentLibraryBackend.texturesModel.hasSceneEnv hasSceneEnv: ContentLibraryBackend.texturesModel.hasSceneEnv
} }

View File

@@ -121,6 +121,21 @@ void ContentLibraryUserModel::addTextures(const QStringList &paths)
emit dataChanged(index(texSectionIdx), index(texSectionIdx)); 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 // returns unique library material's name and qml component
QPair<QString, QString> ContentLibraryUserModel::getUniqueLibMaterialNameAndQml(const QString &matName) const QPair<QString, QString> ContentLibraryUserModel::getUniqueLibMaterialNameAndQml(const QString &matName) const
{ {

View File

@@ -72,6 +72,7 @@ public:
Q_INVOKABLE void applyToSelected(QmlDesigner::ContentLibraryMaterial *mat, bool add = false); Q_INVOKABLE void applyToSelected(QmlDesigner::ContentLibraryMaterial *mat, bool add = false);
Q_INVOKABLE void addToProject(QmlDesigner::ContentLibraryMaterial *mat); Q_INVOKABLE void addToProject(QmlDesigner::ContentLibraryMaterial *mat);
Q_INVOKABLE void removeFromProject(QmlDesigner::ContentLibraryMaterial *mat); Q_INVOKABLE void removeFromProject(QmlDesigner::ContentLibraryMaterial *mat);
Q_INVOKABLE void removeTexture(QmlDesigner::ContentLibraryTexture *tex);
signals: signals:
void isEmptyChanged(); void isEmptyChanged();