QmlDesigner: Start and end transaction for spin box dragging

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 <henning.gruendl@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Thomas Hartmann
2019-10-18 16:05:43 +02:00
parent b64f5a3fe5
commit fab360d83d
3 changed files with 30 additions and 7 deletions

View File

@@ -46,11 +46,30 @@ Item {
width: 96 width: 96
implicitHeight: spinBox.height implicitHeight: spinBox.height
onFocusChanged: transaction.end();
StudioControls.RealSpinBox { StudioControls.RealSpinBox {
id: spinBox id: spinBox
onDragStarted: hideCursor(); onDragStarted: {
onDragEnded: restoreCursor(); 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 variant backendValue
property bool hasSlider: wrapper.sliderIndicatorVisible property bool hasSlider: wrapper.sliderIndicatorVisible
@@ -77,9 +96,6 @@ Item {
labelColor: spinBox.edit ? StudioTheme.Values.themeTextColor : colorLogic.textColor labelColor: spinBox.edit ? StudioTheme.Values.themeTextColor : colorLogic.textColor
onCompressedRealValueModified: { onCompressedRealValueModified: commitValue()
if (spinBox.backendValue.value !== spinBox.realValue)
spinBox.backendValue.value = spinBox.realValue;
}
} }
} }

View File

@@ -41,7 +41,7 @@ void PropertyEditorTransaction::start()
if (m_rewriterTransaction.isValid()) if (m_rewriterTransaction.isValid())
m_rewriterTransaction.commit(); m_rewriterTransaction.commit();
m_rewriterTransaction = m_propertyEditor->beginRewriterTransaction(QByteArrayLiteral("PropertyEditorTransaction::start")); m_rewriterTransaction = m_propertyEditor->beginRewriterTransaction(QByteArrayLiteral("PropertyEditorTransaction::start"));
m_timerId = startTimer(4000); m_timerId = startTimer(10000);
} }
void PropertyEditorTransaction::end() void PropertyEditorTransaction::end()
@@ -52,6 +52,11 @@ void PropertyEditorTransaction::end()
} }
} }
bool PropertyEditorTransaction::active() const
{
return m_rewriterTransaction.isValid();
}
void PropertyEditorTransaction::timerEvent(QTimerEvent *timerEvent) void PropertyEditorTransaction::timerEvent(QTimerEvent *timerEvent)
{ {
if (timerEvent->timerId() != m_timerId) if (timerEvent->timerId() != m_timerId)

View File

@@ -38,6 +38,8 @@ public:
Q_INVOKABLE void start(); Q_INVOKABLE void start();
Q_INVOKABLE void end(); Q_INVOKABLE void end();
Q_INVOKABLE bool active() const;
protected: protected:
void timerEvent(QTimerEvent *event) override; void timerEvent(QTimerEvent *event) override;