From 516a2238e29844ca3dab1186d413dd66ae8b2d85 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 15 Sep 2023 16:06:14 +0300 Subject: [PATCH] QmlDesigner: Ensure we save the latest values on 3D snap dialog close Track value property of spin boxes changes directly instead of the extra valueModified signal, which is not emitted in all cases. Also removed duplicate applying of snap configuration. Fixes: QDS-10653 Change-Id: If0ce7bffa1dcfb5b01e80b6e962f356f91f44d51 Reviewed-by: Qt CI Patch Build Bot Reviewed-by: Mahmoud Badri --- .../SnapConfigurationDialog.qml | 6 ++--- .../components/edit3d/snapconfiguration.cpp | 24 +++++++++---------- .../components/edit3d/snapconfiguration.h | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/share/qtcreator/qmldesigner/edit3dQmlSource/SnapConfigurationDialog.qml b/share/qtcreator/qmldesigner/edit3dQmlSource/SnapConfigurationDialog.qml index 340570ff9b2..43460b7f719 100644 --- a/share/qtcreator/qmldesigner/edit3dQmlSource/SnapConfigurationDialog.qml +++ b/share/qtcreator/qmldesigner/edit3dQmlSource/SnapConfigurationDialog.qml @@ -132,7 +132,7 @@ Rectangle { ToolTip.text: qsTr("Snap interval for move gizmo.") ToolTip.delay: root.toolTipDelay - onValueModified: posInt = value + onValueChanged: posInt = value } StudioControls.CheckBox { @@ -167,7 +167,7 @@ Rectangle { ToolTip.text: qsTr("Snap interval in degrees for rotation gizmo.") ToolTip.delay: root.toolTipDelay - onValueModified: rotInt = value + onValueChanged: rotInt = value } StudioControls.CheckBox { @@ -202,7 +202,7 @@ Rectangle { ToolTip.text: qsTr("Snap interval for scale gizmo in percentage of original scale.") ToolTip.delay: root.toolTipDelay - onValueModified: scaleInt = value + onValueChanged: scaleInt = value } StudioControls.CheckBox { diff --git a/src/plugins/qmldesigner/components/edit3d/snapconfiguration.cpp b/src/plugins/qmldesigner/components/edit3d/snapconfiguration.cpp index 1412588f902..f1d8889364b 100644 --- a/src/plugins/qmldesigner/components/edit3d/snapconfiguration.cpp +++ b/src/plugins/qmldesigner/components/edit3d/snapconfiguration.cpp @@ -47,7 +47,8 @@ SnapConfiguration::SnapConfiguration(Edit3DView *view) SnapConfiguration::~SnapConfiguration() { - cleanup(); + delete m_configDialog; + restoreCursor(); } void SnapConfiguration::apply() @@ -67,12 +68,10 @@ void SnapConfiguration::apply() m_rotationInterval); Edit3DViewConfig::save(DesignerSettingsKey::EDIT3DVIEW_SNAP_SCALE_INTERVAL, m_scaleInterval); - m_view->syncSnapAuxPropsToSettings(); + if (!m_view.isNull()) + m_view->syncSnapAuxPropsToSettings(); } - - restoreCursor(); - - cancel(); + deleteLater(); } void SnapConfiguration::resetDefaults() @@ -234,9 +233,12 @@ void SnapConfiguration::setScaleInt(double value) } } -void SnapConfiguration::cleanup() +void SnapConfiguration::asyncClose() { - delete m_configDialog; + QTimer::singleShot(0, this, [this]() { + if (!m_configDialog.isNull() && m_configDialog->isVisible()) + m_configDialog->close(); + }); } void SnapConfiguration::cancel() @@ -249,15 +251,13 @@ void SnapConfiguration::cancel() bool SnapConfiguration::eventFilter(QObject *obj, QEvent *event) { - // Closing dialog always applies the changes - if (obj == m_configDialog) { if (event->type() == QEvent::FocusOut) { - apply(); + asyncClose(); } else if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast(event); if (keyEvent->key() == Qt::Key_Escape) - apply(); + asyncClose(); } else if (event->type() == QEvent::Close) { apply(); } diff --git a/src/plugins/qmldesigner/components/edit3d/snapconfiguration.h b/src/plugins/qmldesigner/components/edit3d/snapconfiguration.h index b744e63053f..729e6ce7d10 100644 --- a/src/plugins/qmldesigner/components/edit3d/snapconfiguration.h +++ b/src/plugins/qmldesigner/components/edit3d/snapconfiguration.h @@ -90,7 +90,7 @@ protected: bool eventFilter(QObject *obj, QEvent *event) override; private: - void cleanup(); + void asyncClose(); QPointer m_configDialog; QPointer m_view;