From 4285b38b7471b5d72c1dc6f5ae6c06e855a03728 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Thu, 24 Nov 2022 17:15:07 -0500 Subject: [PATCH] Properties: Handle units changes correctly Fixes https://gitlab.com/kicad/code/kicad/-/issues/12885 --- common/properties/pg_editors.cpp | 5 +++++ common/widgets/unit_binder.cpp | 19 ++++++++----------- include/widgets/unit_binder.h | 6 +++--- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/common/properties/pg_editors.cpp b/common/properties/pg_editors.cpp index a1fd9cfe2d..bcba17f0c9 100644 --- a/common/properties/pg_editors.cpp +++ b/common/properties/pg_editors.cpp @@ -17,6 +17,7 @@ * with this program. If not, see . */ +#include #include #include #include @@ -29,6 +30,7 @@ PG_UNIT_EDITOR::PG_UNIT_EDITOR( EDA_DRAW_FRAME* aFrame ) : m_frame( aFrame ) { m_unitBinder = std::make_unique( m_frame ); + m_unitBinder->SetUnits( m_frame->GetUserUnits() ); } @@ -62,6 +64,7 @@ bool PG_UNIT_EDITOR::GetValueFromControl( wxVariant& aVariant, wxPGProperty* aPr if( aProperty->UsesAutoUnspecified() && textVal.empty() ) { aVariant.MakeNull(); + m_unitBinder->SetControl( nullptr ); return true; } @@ -80,5 +83,7 @@ bool PG_UNIT_EDITOR::GetValueFromControl( wxVariant& aVariant, wxPGProperty* aPr if( !changed && aVariant.IsNull() ) changed = true; + m_unitBinder->SetControl( nullptr ); + return changed; } diff --git a/common/widgets/unit_binder.cpp b/common/widgets/unit_binder.cpp index 74e5ca883e..3cc583977d 100644 --- a/common/widgets/unit_binder.cpp +++ b/common/widgets/unit_binder.cpp @@ -47,9 +47,9 @@ UNIT_BINDER::UNIT_BINDER( EDA_DRAW_FRAME* aParent, wxStaticText* aLabel, wxWindo UNIT_BINDER::UNIT_BINDER( EDA_BASE_FRAME* aParent, const EDA_IU_SCALE& aIUScale, wxStaticText* aLabel, wxWindow* aValueCtrl, - wxStaticText* aUnitLabel, bool allowEval, bool aBindFrameEvents ) : + wxStaticText* aUnitLabel, bool allowEval, bool aBindFocusEvent ) : m_frame( aParent ), - m_bindFrameEvents( aBindFrameEvents ), + m_bindFocusEvent( aBindFocusEvent ), m_label( aLabel ), m_valueCtrl( aValueCtrl ), m_unitLabel( aUnitLabel ), @@ -87,24 +87,21 @@ UNIT_BINDER::UNIT_BINDER( EDA_BASE_FRAME* aParent, const EDA_IU_SCALE& aIUScale, this ); } - if( m_bindFrameEvents ) + if( m_bindFocusEvent ) { Connect( DELAY_FOCUS, wxCommandEventHandler( UNIT_BINDER::delayedFocusHandler ), nullptr, this ); - - m_frame->Connect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ), - nullptr, this ); } + + m_frame->Connect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ), + nullptr, this ); } UNIT_BINDER::~UNIT_BINDER() { - if( m_bindFrameEvents ) - { - m_frame->Disconnect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ), - nullptr, this ); - } + m_frame->Disconnect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ), + nullptr, this ); } diff --git a/include/widgets/unit_binder.h b/include/widgets/unit_binder.h index 6a084c6073..9b952cffd3 100644 --- a/include/widgets/unit_binder.h +++ b/include/widgets/unit_binder.h @@ -54,11 +54,11 @@ public: */ UNIT_BINDER( EDA_DRAW_FRAME* aParent, wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel, - bool aAllowEval = true, bool aBindFrameEvents = true ); + bool aAllowEval = true, bool aBindFocusEvent = true ); UNIT_BINDER( EDA_BASE_FRAME* aParent, const EDA_IU_SCALE& aIUScale, wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel, bool aAllowEval = true, - bool aBindFrameEvents = true ); + bool aBindFocusEvent = true ); virtual ~UNIT_BINDER() override; @@ -221,7 +221,7 @@ protected: double setPrecision( double aValue, bool aValueUsesUserUnits ); EDA_BASE_FRAME* m_frame; - bool m_bindFrameEvents; + bool m_bindFocusEvent; ///< The bound widgets wxStaticText* m_label;