From 2122ff37f12705bf0964d444bf2e874cc3a5c6df Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 29 Jan 2024 16:34:48 +0200 Subject: [PATCH] EffectComposer: Consider effect changes to be part of current document This will allow saving effects when current document is saved for any reason, including at application shutdown. If effect is not yet saved once (i.e. it doesn't have a name yet), it will not be saved in response to global save triggers to avoid complications with requiring user input to provide the name. Fixes: QDS-11436 Fixes: QDS-11446 Change-Id: I412ee4893e926d527b4f03f5f6c0c9b4e923bc1e Reviewed-by: Mahmoud Badri --- .../effectcomposer/effectcomposerwidget.cpp | 19 +++++++++++++++++++ .../components/integration/designdocument.cpp | 6 ++++++ .../components/integration/designdocument.h | 2 ++ 3 files changed, 27 insertions(+) diff --git a/src/plugins/effectcomposer/effectcomposerwidget.cpp b/src/plugins/effectcomposer/effectcomposerwidget.cpp index ebd793a3ad7..3be9284f4df 100644 --- a/src/plugins/effectcomposer/effectcomposerwidget.cpp +++ b/src/plugins/effectcomposer/effectcomposerwidget.cpp @@ -16,6 +16,8 @@ #include "theme.h" #include +#include +#include #include #include @@ -108,6 +110,23 @@ EffectComposerWidget::EffectComposerWidget(EffectComposerView *view) m_importScan.timer->start(100); }); + + connect(m_effectComposerModel.data(), &EffectComposerModel::hasUnsavedChangesChanged, + this, [this]() { + if (m_effectComposerModel->hasUnsavedChanges() && !m_effectComposerModel->currentComposition().isEmpty()) { + if (auto doc = QmlDesigner::QmlDesignerPlugin::instance()->documentManager().currentDesignDocument()) + doc->setModified(); + } + }); + + connect(Core::EditorManager::instance(), &Core::EditorManager::aboutToSave, + this, [this](Core::IDocument *document) { + if (m_effectComposerModel->hasUnsavedChanges()) { + QString compName = m_effectComposerModel->currentComposition(); + if (!compName.isEmpty()) + m_effectComposerModel->saveComposition(compName); + } + }); } diff --git a/src/plugins/qmldesigner/components/integration/designdocument.cpp b/src/plugins/qmldesigner/components/integration/designdocument.cpp index 3ad09a8693c..96cfc80da8d 100644 --- a/src/plugins/qmldesigner/components/integration/designdocument.cpp +++ b/src/plugins/qmldesigner/components/integration/designdocument.cpp @@ -427,6 +427,12 @@ bool DesignDocument::hasProject() const return !DocumentManager::currentProjectDirPath().isEmpty(); } +void DesignDocument::setModified() +{ + if (!m_documentTextModifier.isNull()) + m_documentTextModifier->textDocument()->setModified(true); +} + void DesignDocument::changeToInFileComponentModel(ComponentTextModifier *textModifer) { m_inFileComponentTextModifier.reset(textModifer); diff --git a/src/plugins/qmldesigner/components/integration/designdocument.h b/src/plugins/qmldesigner/components/integration/designdocument.h index aa7ced784fc..0d75141205e 100644 --- a/src/plugins/qmldesigner/components/integration/designdocument.h +++ b/src/plugins/qmldesigner/components/integration/designdocument.h @@ -89,6 +89,8 @@ public: Utils::FilePath projectFolder() const; bool hasProject() const; + void setModified(); + signals: void displayNameChanged(const QString &newFileName); void dirtyStateChanged(bool newState);