From fab360d83d4c9e0ca77ecfb44fccc974f279399c Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Fri, 18 Oct 2019 16:05:43 +0200 Subject: [PATCH] QmlDesigner: Start and end transaction for spin box dragging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using the spin box focus is not safe enough, but using transactions on the dragging works nicely. Change-Id: Iffc15b4ca44cb473b257f58e548ff86ebd56bbf2 Reviewed-by: Henning Gründl Reviewed-by: Thomas Hartmann --- .../imports/HelperWidgets/SpinBox.qml | 28 +++++++++++++++---- .../propertyeditortransaction.cpp | 7 ++++- .../propertyeditortransaction.h | 2 ++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/SpinBox.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/SpinBox.qml index 11c358af2af..bf42b964152 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/SpinBox.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/SpinBox.qml @@ -46,11 +46,30 @@ Item { width: 96 implicitHeight: spinBox.height + onFocusChanged: transaction.end(); + StudioControls.RealSpinBox { id: spinBox - onDragStarted: hideCursor(); - onDragEnded: restoreCursor(); + onDragStarted: { + hideCursor(); + transaction.start(); + } + + onDragEnded: { + restoreCursor(); + transaction.end(); + } + + onRealValueModified: { + if (transaction.active()) + commitValue(); + } + + function commitValue() { + if (spinBox.backendValue.value !== spinBox.realValue) + spinBox.backendValue.value = spinBox.realValue; + } property variant backendValue property bool hasSlider: wrapper.sliderIndicatorVisible @@ -77,9 +96,6 @@ Item { labelColor: spinBox.edit ? StudioTheme.Values.themeTextColor : colorLogic.textColor - onCompressedRealValueModified: { - if (spinBox.backendValue.value !== spinBox.realValue) - spinBox.backendValue.value = spinBox.realValue; - } + onCompressedRealValueModified: commitValue() } } diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditortransaction.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditortransaction.cpp index 3e4a20a1b3e..feafd9b1df5 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditortransaction.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditortransaction.cpp @@ -41,7 +41,7 @@ void PropertyEditorTransaction::start() if (m_rewriterTransaction.isValid()) m_rewriterTransaction.commit(); m_rewriterTransaction = m_propertyEditor->beginRewriterTransaction(QByteArrayLiteral("PropertyEditorTransaction::start")); - m_timerId = startTimer(4000); + m_timerId = startTimer(10000); } void PropertyEditorTransaction::end() @@ -52,6 +52,11 @@ void PropertyEditorTransaction::end() } } +bool PropertyEditorTransaction::active() const +{ + return m_rewriterTransaction.isValid(); +} + void PropertyEditorTransaction::timerEvent(QTimerEvent *timerEvent) { if (timerEvent->timerId() != m_timerId) diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditortransaction.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditortransaction.h index f3f87e47211..02590bf62e0 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditortransaction.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditortransaction.h @@ -38,6 +38,8 @@ public: Q_INVOKABLE void start(); Q_INVOKABLE void end(); + Q_INVOKABLE bool active() const; + protected: void timerEvent(QTimerEvent *event) override;