From 2ea6b555e5f0a805cc250dc2f9f0255d8e0deb5d Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 25 Oct 2024 14:32:24 +0300 Subject: [PATCH] EffectComposer: Fix custom preview issues - Custom preview saving and loading fixed when file is deleted - Custom preview not shown in combo when it's opened after file deletion - Fixed selected highlight on custom preview Fixes: QDS-13880 Change-Id: I8ef3fed5cfc220e3b37007b302f54fe3bf01899d Reviewed-by: Mahmoud Badri --- .../PreviewImagesComboBox.qml | 7 +++- .../effectcomposer/effectcomposermodel.cpp | 37 ++++++++++++++----- .../effectcomposer/effectcomposermodel.h | 1 + 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/share/qtcreator/qmldesigner/effectComposerQmlSources/PreviewImagesComboBox.qml b/share/qtcreator/qmldesigner/effectComposerQmlSources/PreviewImagesComboBox.qml index b75a04001e8..0fc5f26056b 100644 --- a/share/qtcreator/qmldesigner/effectComposerQmlSources/PreviewImagesComboBox.qml +++ b/share/qtcreator/qmldesigner/effectComposerQmlSources/PreviewImagesComboBox.qml @@ -69,6 +69,7 @@ StudioControls.ComboBox { target: root.popup function onAboutToShow() { + EffectComposerBackend.effectComposerModel.previewComboAboutToOpen() root.calculateWindowGeometry() window.show() @@ -170,8 +171,10 @@ StudioControls.ComboBox { required property var modelData color: "transparent" - border.color: root.selectedImage === modelData ? StudioTheme.Values.themeInteraction - : "transparent" + border.color: root.selectedImage === modelData + || index == 0 && root.selectedImage == EffectComposerBackend.effectComposerModel.customPreviewImage + ? StudioTheme.Values.themeInteraction + : "transparent" width: 200 height: 200 diff --git a/src/plugins/effectcomposer/effectcomposermodel.cpp b/src/plugins/effectcomposer/effectcomposermodel.cpp index 3063283bffc..4319c9afd4d 100644 --- a/src/plugins/effectcomposer/effectcomposermodel.cpp +++ b/src/plugins/effectcomposer/effectcomposermodel.cpp @@ -294,6 +294,17 @@ void EffectComposerModel::chooseCustomPreviewImage() }); } +void EffectComposerModel::previewComboAboutToOpen() +{ + if (!m_customPreviewImage.isEmpty() && !Utils::FilePath::fromUrl(m_customPreviewImage).exists()) { + if (m_currentPreviewImage == m_customPreviewImage) { + m_customPreviewImage.clear(); + emit customPreviewImageChanged(); + setCurrentPreviewImage({}); + } + } +} + QString EffectComposerModel::fragmentShader() const { return m_fragmentShader; @@ -1067,8 +1078,12 @@ void EffectComposerModel::saveComposition(const QString &name) json.insert("tool", "EffectComposer"); Utils::FilePath customPreviewPath = Utils::FilePath::fromUrl(m_customPreviewImage); - if (m_customPreviewImage.isLocalFile()) - customPreviewPath = customPreviewPath.relativePathFrom(compositionDir); + if (m_customPreviewImage.isLocalFile()) { + if (customPreviewPath.exists()) + customPreviewPath = customPreviewPath.relativePathFrom(compositionDir); + else + customPreviewPath = {}; + } json.insert("customPreviewImage", customPreviewPath.toUrl().toString()); QUrl previewUrl = m_currentPreviewImage; @@ -1259,14 +1274,16 @@ void EffectComposerModel::openComposition(const QString &path) m_customPreviewImage.clear(); if (json.contains("customPreviewImage")) { QUrl imageUrl{json["customPreviewImage"].toString()}; - Utils::FilePath imagePath = Utils::FilePath::fromUrl(imageUrl); - if (imagePath.isAbsolutePath()) { - if (imagePath.exists()) - m_customPreviewImage = imageUrl; - } else { - imagePath = effectPath.absolutePath().resolvePath(imagePath); - if (imagePath.exists()) - m_customPreviewImage = imagePath.toUrl(); + if (!imageUrl.isEmpty()) { + Utils::FilePath imagePath = Utils::FilePath::fromUrl(imageUrl); + if (imagePath.isAbsolutePath()) { + if (imagePath.exists()) + m_customPreviewImage = imageUrl; + } else { + imagePath = effectPath.absolutePath().resolvePath(imagePath); + if (imagePath.exists()) + m_customPreviewImage = imagePath.toUrl(); + } } } diff --git a/src/plugins/effectcomposer/effectcomposermodel.h b/src/plugins/effectcomposer/effectcomposermodel.h index 0fe4aeb84f9..a7ca05d124b 100644 --- a/src/plugins/effectcomposer/effectcomposermodel.h +++ b/src/plugins/effectcomposer/effectcomposermodel.h @@ -81,6 +81,7 @@ public: Q_INVOKABLE QString getUniqueEffectName() const; Q_INVOKABLE bool nameExists(const QString &name) const; Q_INVOKABLE void chooseCustomPreviewImage(); + Q_INVOKABLE void previewComboAboutToOpen(); bool shadersUpToDate() const; void setShadersUpToDate(bool newShadersUpToDate);