From 87bf3dbfcc1912c85e6be382106d967634234bf7 Mon Sep 17 00:00:00 2001 From: parax0 Date: Mon, 21 Mar 2016 16:51:35 -0600 Subject: [PATCH] Fixed draggable spinboxes updating while the user is typing into them --- src/Editor/PropertyEdit/CPropertyDelegate.cpp | 6 +++ src/Editor/PropertyEdit/CPropertyDelegate.h | 1 + src/Editor/Widgets/WVectorEditor.cpp | 39 ++++++++++++++----- src/Editor/Widgets/WVectorEditor.h | 3 +- src/Editor/WorldEditor/CWorldEditor.cpp | 8 ++-- src/Editor/WorldEditor/CWorldEditor.ui | 3 ++ 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/Editor/PropertyEdit/CPropertyDelegate.cpp b/src/Editor/PropertyEdit/CPropertyDelegate.cpp index 2013c766..9fd5860f 100644 --- a/src/Editor/PropertyEdit/CPropertyDelegate.cpp +++ b/src/Editor/PropertyEdit/CPropertyDelegate.cpp @@ -30,6 +30,7 @@ CPropertyDelegate::CPropertyDelegate(QObject *pParent /*= 0*/) , mInRelayWidgetEdit(false) , mEditInProgress(false) , mRelaysBlocked(false) + , mUpdatingModel(false) { } @@ -196,6 +197,8 @@ QWidget* CPropertyDelegate::createEditor(QWidget *pParent, const QStyleOptionVie void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkIndex) const { + if (mUpdatingModel) return; + BlockRelays(true); mEditInProgress = false; // fixes case where user does undo mid-edit @@ -351,6 +354,7 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo { if (!mpModel) return; if (!pEditor) return; + mUpdatingModel = true; IProperty *pProp = mpModel->PropertyForIndex(rkIndex, false); IPropertyValue *pOldValue = nullptr; @@ -531,6 +535,8 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo else delete pOldValue; } + + mUpdatingModel = false; } bool CPropertyDelegate::eventFilter(QObject *pObject, QEvent *pEvent) diff --git a/src/Editor/PropertyEdit/CPropertyDelegate.h b/src/Editor/PropertyEdit/CPropertyDelegate.h index 867b8517..e0dc9e45 100644 --- a/src/Editor/PropertyEdit/CPropertyDelegate.h +++ b/src/Editor/PropertyEdit/CPropertyDelegate.h @@ -14,6 +14,7 @@ class CPropertyDelegate : public QStyledItemDelegate bool mInRelayWidgetEdit; mutable bool mEditInProgress; mutable bool mRelaysBlocked; + mutable bool mUpdatingModel; public: CPropertyDelegate(QObject *pParent = 0); diff --git a/src/Editor/Widgets/WVectorEditor.cpp b/src/Editor/Widgets/WVectorEditor.cpp index 021d2575..7b7c51f2 100644 --- a/src/Editor/Widgets/WVectorEditor.cpp +++ b/src/Editor/Widgets/WVectorEditor.cpp @@ -7,6 +7,7 @@ WVectorEditor::WVectorEditor(QWidget *pParent) : QWidget(pParent) mpSpinBoxX->setValue(0.0); mpSpinBoxY->setValue(0.0); mpSpinBoxZ->setValue(0.0); + mEditing = false; } WVectorEditor::WVectorEditor(const CVector3f& value, QWidget *pParent) : QWidget(pParent) @@ -16,6 +17,7 @@ WVectorEditor::WVectorEditor(const CVector3f& value, QWidget *pParent) : QWidget mpSpinBoxX->setValue((double) value.x); mpSpinBoxY->setValue((double) value.y); mpSpinBoxZ->setValue((double) value.z); + mEditing = false; } WVectorEditor::~WVectorEditor() @@ -94,19 +96,27 @@ void WVectorEditor::SetLabelsHidden(bool hidden) } } -bool WVectorEditor::IsBeingDragged() +bool WVectorEditor::IsBeingDragged() const { return (mpSpinBoxX->IsBeingDragged() || mpSpinBoxY->IsBeingDragged() || mpSpinBoxZ->IsBeingDragged()); } +bool WVectorEditor::IsBeingEdited() const +{ + return IsBeingDragged() || mEditing; +} + // ************ PUBLIC SLOTS ************ void WVectorEditor::SetX(double x) { mValue.x = (float) x; - mpSpinBoxX->blockSignals(true); - mpSpinBoxX->setValue((double) x); - mpSpinBoxX->blockSignals(false); + if (sender() != mpSpinBoxX) + { + mpSpinBoxX->blockSignals(true); + mpSpinBoxX->setValue((double) x); + mpSpinBoxX->blockSignals(false); + } mEditing = true; emit ValueChanged(mValue); @@ -116,9 +126,12 @@ void WVectorEditor::SetY(double y) { mValue.y = (float) y; - mpSpinBoxY->blockSignals(true); - mpSpinBoxY->setValue((double) y); - mpSpinBoxY->blockSignals(false); + if (sender() != mpSpinBoxY) + { + mpSpinBoxY->blockSignals(true); + mpSpinBoxY->setValue((double) y); + mpSpinBoxY->blockSignals(false); + } mEditing = true; emit ValueChanged(mValue); @@ -128,9 +141,12 @@ void WVectorEditor::SetZ(double z) { mValue.z = (float) z; - mpSpinBoxZ->blockSignals(true); - mpSpinBoxZ->setValue((double) z); - mpSpinBoxZ->blockSignals(false); + if (sender() != mpSpinBoxZ) + { + mpSpinBoxZ->blockSignals(true); + mpSpinBoxZ->setValue((double) z); + mpSpinBoxZ->blockSignals(false); + } mEditing = true; emit ValueChanged(mValue); @@ -176,6 +192,9 @@ void WVectorEditor::SetupUI() mpZLayout->addWidget(mpSpinBoxZ, 1); mpZLayout->setSpacing(5); + setTabOrder(mpSpinBoxX, mpSpinBoxY); + setTabOrder(mpSpinBoxY, mpSpinBoxZ); + // Create and initialize widget layout mpLayout = nullptr; SetOrientation(Qt::Vertical); diff --git a/src/Editor/Widgets/WVectorEditor.h b/src/Editor/Widgets/WVectorEditor.h index 150b5671..b4260c06 100644 --- a/src/Editor/Widgets/WVectorEditor.h +++ b/src/Editor/Widgets/WVectorEditor.h @@ -39,7 +39,8 @@ public: void SetDefaultValue(double value); void SetSingleStep(double step); void SetLabelsHidden(bool hidden); - bool IsBeingDragged(); + bool IsBeingDragged() const; + bool IsBeingEdited() const; public slots: void SetX(double x); diff --git a/src/Editor/WorldEditor/CWorldEditor.cpp b/src/Editor/WorldEditor/CWorldEditor.cpp index e6e18a66..4bfb2b27 100644 --- a/src/Editor/WorldEditor/CWorldEditor.cpp +++ b/src/Editor/WorldEditor/CWorldEditor.cpp @@ -529,7 +529,7 @@ void CWorldEditor::UpdateStatusBar() void CWorldEditor::UpdateGizmoUI() { // Update transform XYZ spin boxes - if (!ui->TransformSpinBox->IsBeingDragged()) + if (!ui->TransformSpinBox->IsBeingEdited()) { CVector3f spinBoxValue = CVector3f::skZero; @@ -695,6 +695,8 @@ void CWorldEditor::OnClipboardDataModified() void CWorldEditor::OnSelectionModified() { + ui->TransformSpinBox->setEnabled(!mpSelection->IsEmpty()); + bool HasScriptNode = HasAnyScriptNodesSelected(); ui->ActionCut->setEnabled(HasScriptNode); ui->ActionCopy->setEnabled(HasScriptNode); @@ -933,10 +935,6 @@ void CWorldEditor::OnTransformSpinBoxModified(CVector3f value) void CWorldEditor::OnTransformSpinBoxEdited(CVector3f) { - // bit of a hack - the vector editor emits a second "editing done" signal when it loses focus - ui->TransformSpinBox->blockSignals(true); - ui->MainViewport->setFocus(); - ui->TransformSpinBox->blockSignals(false); if (mpSelection->IsEmpty()) return; if (mGizmo.Mode() == CGizmo::eTranslate) mUndoStack.push(CTranslateNodeCommand::End()); diff --git a/src/Editor/WorldEditor/CWorldEditor.ui b/src/Editor/WorldEditor/CWorldEditor.ui index 684e9f79..7498258c 100644 --- a/src/Editor/WorldEditor/CWorldEditor.ui +++ b/src/Editor/WorldEditor/CWorldEditor.ui @@ -119,6 +119,9 @@ + + false + 0