EffectMaker: confirm save changes before opening an composition

Change-Id: I05659e4cdeba5dc5f437d2fb99bc3768c6a1522d
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
Mahmoud Badri
2023-12-12 15:15:15 +02:00
parent 9d8aa76b4c
commit d9774e7faf
4 changed files with 35 additions and 11 deletions

View File

@@ -16,6 +16,16 @@ Item {
property int moveToIdx: 0 property int moveToIdx: 0
property bool previewAnimationRunning: false property bool previewAnimationRunning: false
// Invoked after save changes is done
property var onSaveChangesCallback: () => {}
// Invoked from C++ side when open composition is requested and there are unsaved changes
function promptToSaveBeforeOpen() {
root.onSaveChangesCallback = () => { EffectMakerBackend.rootView.doOpenComposition() }
saveChangesDialog.open()
}
SaveAsDialog { SaveAsDialog {
id: saveDialog id: saveDialog
anchors.centerIn: parent anchors.centerIn: parent
@@ -31,12 +41,12 @@ Item {
saveDialog.clearOnClose = true saveDialog.clearOnClose = true
saveDialog.open() saveDialog.open()
} else { } else {
EffectMakerBackend.effectMakerModel.clear() root.onSaveChangesCallback()
} }
} }
onDiscard: { onDiscard: {
EffectMakerBackend.effectMakerModel.clear() root.onSaveChangesCallback()
} }
} }
@@ -47,6 +57,8 @@ Item {
EffectMakerTopBar { EffectMakerTopBar {
onAddClicked: { onAddClicked: {
root.onSaveChangesCallback = () => { EffectMakerBackend.effectMakerModel.clear() }
if (EffectMakerBackend.effectMakerModel.hasUnsavedChanges) if (EffectMakerBackend.effectMakerModel.hasUnsavedChanges)
saveChangesDialog.open() saveChangesDialog.open()
else else

View File

@@ -7,17 +7,10 @@
#include "effectmakernodesmodel.h" #include "effectmakernodesmodel.h"
#include "effectmakerwidget.h" #include "effectmakerwidget.h"
#include "nodeinstanceview.h"
#include "qmldesignerconstants.h" #include "qmldesignerconstants.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickItem>
#include <QQuickView>
#include <QTimer>
namespace EffectMaker { namespace EffectMaker {
EffectMakerContext::EffectMakerContext(QWidget *widget) EffectMakerContext::EffectMakerContext(QWidget *widget)
@@ -66,7 +59,7 @@ void EffectMakerView::customNotification([[maybe_unused]] const AbstractView *vi
{ {
if (identifier == "open_effectmaker_composition" && data.count() > 0) { if (identifier == "open_effectmaker_composition" && data.count() > 0) {
const QString compositionPath = data[0].toString(); const QString compositionPath = data[0].toString();
m_widget->effectMakerModel()->openComposition(compositionPath); m_widget->openComposition(compositionPath);
} }
} }

View File

@@ -12,7 +12,6 @@
//#include "qmldesigner/designercore/imagecache/midsizeimagecacheprovider.h" //#include "qmldesigner/designercore/imagecache/midsizeimagecacheprovider.h"
#include "qmldesignerconstants.h" #include "qmldesignerconstants.h"
#include "qmldesignerplugin.h" #include "qmldesignerplugin.h"
#include "qqmlcontext.h"
#include "theme.h" #include "theme.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
@@ -30,7 +29,9 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QQmlContext>
#include <QQmlEngine> #include <QQmlEngine>
#include <QQuickItem>
#include <QTimer> #include <QTimer>
namespace EffectMaker { namespace EffectMaker {
@@ -193,6 +194,21 @@ void EffectMakerWidget::initView()
reloadQmlSource(); reloadQmlSource();
} }
void EffectMakerWidget::openComposition(const QString &path)
{
m_compositionPath = path;
if (effectMakerModel()->hasUnsavedChanges())
QMetaObject::invokeMethod(quickWidget()->rootObject(), "promptToSaveBeforeOpen");
else
doOpenComposition();
}
void EffectMakerWidget::doOpenComposition()
{
effectMakerModel()->openComposition(m_compositionPath);
}
void EffectMakerWidget::reloadQmlSource() void EffectMakerWidget::reloadQmlSource()
{ {
const QString effectMakerQmlPath = qmlSourcesPath() + "/EffectMaker.qml"; const QString effectMakerQmlPath = qmlSourcesPath() + "/EffectMaker.qml";

View File

@@ -39,6 +39,7 @@ public:
void delayedUpdateModel(); void delayedUpdateModel();
void updateModel(); void updateModel();
void initView(); void initView();
void openComposition(const QString &path);
StudioQuickWidget *quickWidget() const; StudioQuickWidget *quickWidget() const;
QPointer<EffectMakerModel> effectMakerModel() const; QPointer<EffectMakerModel> effectMakerModel() const;
@@ -46,6 +47,7 @@ public:
Q_INVOKABLE void addEffectNode(const QString &nodeQenPath); Q_INVOKABLE void addEffectNode(const QString &nodeQenPath);
Q_INVOKABLE void focusSection(int section); Q_INVOKABLE void focusSection(int section);
Q_INVOKABLE void doOpenComposition();
Q_INVOKABLE QRect screenRect() const; Q_INVOKABLE QRect screenRect() const;
Q_INVOKABLE QPoint globalPos(const QPoint &point) const; Q_INVOKABLE QPoint globalPos(const QPoint &point) const;
@@ -74,6 +76,7 @@ private:
}; };
ImportScanData m_importScan; ImportScanData m_importScan;
QString m_compositionPath;
}; };
} // namespace EffectMaker } // namespace EffectMaker