diff --git a/include/property.h b/include/property.h index b6f37fd7ca..a1a843f8c3 100644 --- a/include/property.h +++ b/include/property.h @@ -50,9 +50,10 @@ class ENUM_MAP; enum PROPERTY_DISPLAY { DEFAULT, ///< Default property for a given type - DISTANCE, ///< Display value expressed in distance units (mm/inch) - DEGREE, ///< Display value expressed in degrees - DECIDEGREE ///< Convert decidegrees to degrees for display + SIZE, ///< Size expressed in distance units (mm/inch) + COORD, ///< Coordinate expressed in distance units (mm/inch) + DEGREE, ///< Angle expressed in degrees + DECIDEGREE ///< Angle expressed in decidegrees }; ///< Macro to generate unique identifier for a type @@ -176,8 +177,9 @@ private: public: PROPERTY_BASE( const wxString& aName, PROPERTY_DISPLAY aDisplay = DEFAULT ) : + m_id( nextId ), m_name( aName ), - m_display( aDisplay ), + m_type( aType ), m_availFunc( [](INSPECTABLE*)->bool { return true; } ) { } @@ -251,9 +253,9 @@ public: virtual bool IsReadOnly() const = 0; - PROPERTY_DISPLAY GetDisplay() const + PROPERTY_TYPE Type() const { - return m_display; + return m_type; } protected: @@ -279,8 +281,9 @@ protected: virtual wxAny getter( void* aObject ) const = 0; private: - const wxString m_name; - const PROPERTY_DISPLAY m_display; + const size_t m_id; + const wxString m_name; + const PROPERTY_DISPLAY m_display; std::function m_availFunc; ///< Eval to determine if prop is available @@ -298,18 +301,18 @@ public: template PROPERTY( const wxString& aName, void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )(), - PROPERTY_DISPLAY aDisplay = DEFAULT ) + PROPERTY_TYPE aType = DEFAULT ) : PROPERTY( aName, METHOD::Wrap( aSetter ), - METHOD::Wrap( aGetter ), aDisplay ) + METHOD::Wrap( aGetter ), aType ) { } template PROPERTY( const wxString& aName, void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )() const, - PROPERTY_DISPLAY aDisplay = DEFAULT ) + PROPERTY_TYPE aType = DEFAULT ) : PROPERTY( aName, METHOD::Wrap( aSetter ), - METHOD::Wrap( aGetter ), aDisplay ) + METHOD::Wrap( aGetter ), aType ) { } @@ -335,8 +338,8 @@ public: protected: PROPERTY( const wxString& aName, SETTER_BASE* s, GETTER_BASE* g, - PROPERTY_DISPLAY aDisplay ) - : PROPERTY_BASE( aName, aDisplay ), m_setter( s ), m_getter( g ), + PROPERTY_TYPE aType ) + : PROPERTY_BASE( aName, aType ), m_setter( s ), m_getter( g ), m_ownerHash( TYPE_HASH( Owner ) ), m_baseHash( TYPE_HASH( Base ) ), m_typeHash( TYPE_HASH( BASE_TYPE ) ) { @@ -387,9 +390,9 @@ public: template PROPERTY_ENUM( const wxString& aName, void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )(), - PROPERTY_DISPLAY aDisplay = PROPERTY_DISPLAY::DEFAULT ) + PROPERTY_TYPE aType = PROPERTY_TYPE::DEFAULT ) : PROPERTY( aName, METHOD::Wrap( aSetter ), - METHOD::Wrap( aGetter ), aDisplay ) + METHOD::Wrap( aGetter ), aType ) { if ( std::is_enum::value ) { @@ -401,9 +404,9 @@ public: template PROPERTY_ENUM( const wxString& aName, void ( Base::*aSetter )( SetType ), GetType( Base::*aGetter )() const, - PROPERTY_DISPLAY aDisplay = PROPERTY_DISPLAY::DEFAULT ) + PROPERTY_TYPE aType = PROPERTY_TYPE::DEFAULT ) : PROPERTY( aName, METHOD::Wrap( aSetter ), - METHOD::Wrap( aGetter ), aDisplay ) + METHOD::Wrap( aGetter ), aType ) { if ( std::is_enum::value ) { @@ -442,7 +445,7 @@ public: const wxPGChoices& Choices() const override { - return m_choices; + return m_choices.GetCount() > 0 ? m_choices : ENUM_MAP::Instance().Choices(); } void SetChoices( const wxPGChoices& aChoices ) override @@ -452,7 +455,7 @@ public: bool HasChoices() const override { - return m_choices.GetCount() > 0; + return Choices().GetCount() > 0; } protected: diff --git a/pcbnew/board_item.cpp b/pcbnew/board_item.cpp index 1f4b6fc284..2ab0739e39 100644 --- a/pcbnew/board_item.cpp +++ b/pcbnew/board_item.cpp @@ -256,9 +256,9 @@ static struct BOARD_ITEM_DESC propMgr.InheritsAfter( TYPE_HASH( BOARD_ITEM ), TYPE_HASH( EDA_ITEM ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Position X" ), - &BOARD_ITEM::SetX, &BOARD_ITEM::GetX, PROPERTY_DISPLAY::DISTANCE ) ); + &BOARD_ITEM::SetX, &BOARD_ITEM::GetX, PROPERTY_TYPE::COORD ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Position Y" ), - &BOARD_ITEM::SetY, &BOARD_ITEM::GetY, PROPERTY_DISPLAY::DISTANCE ) ); + &BOARD_ITEM::SetY, &BOARD_ITEM::GetY, PROPERTY_TYPE::COORD ) ); propMgr.AddProperty( new PROPERTY_ENUM( _HKI( "Layer" ), &BOARD_ITEM::SetLayer, &BOARD_ITEM::GetLayer ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Locked" ), diff --git a/pcbnew/pcb_target.cpp b/pcbnew/pcb_target.cpp index a20f667ebb..afa77abfe8 100644 --- a/pcbnew/pcb_target.cpp +++ b/pcbnew/pcb_target.cpp @@ -200,9 +200,9 @@ static struct PCB_TARGET_DESC REGISTER_TYPE( PCB_TARGET ); propMgr.InheritsAfter( TYPE_HASH( PCB_TARGET ), TYPE_HASH( BOARD_ITEM ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Size" ), - &PCB_TARGET::SetSize, &PCB_TARGET::GetSize, PROPERTY_DISPLAY::DISTANCE ) ); + &PCB_TARGET::SetSize, &PCB_TARGET::GetSize, PROPERTY_TYPE::SIZE ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Width" ), - &PCB_TARGET::SetWidth, &PCB_TARGET::GetWidth, PROPERTY_DISPLAY::DISTANCE ) ); + &PCB_TARGET::SetWidth, &PCB_TARGET::GetWidth, PROPERTY_TYPE::SIZE ) ); auto shape = new PROPERTY( _HKI( "Shape" ), &PCB_TARGET::SetShape, &PCB_TARGET::GetShape ); diff --git a/qa/unittests/common/test_property.cpp b/qa/unittests/common/test_property.cpp index 3a36a79dbb..af2db0e661 100644 --- a/qa/unittests/common/test_property.cpp +++ b/qa/unittests/common/test_property.cpp @@ -259,7 +259,7 @@ BOOST_AUTO_TEST_CASE( NotexistingProperties ) { ptr = &d; BOOST_CHECK_EQUAL( ptr->Set( "does not exist", 5 ), false ); - //BOOST_CHECK_EQUAL( ptr->Get( "neither" ).has_value(), false ); + BOOST_CHECK_EQUAL( static_cast( ptr->Get( "neither" ) ), false ); } // Request data using incorrect type @@ -298,12 +298,12 @@ BOOST_AUTO_TEST_CASE( EnumGlob ) BOOST_CHECK_EQUAL( v.GetCount(), values.GetCount() ); BOOST_CHECK_EQUAL( v.GetCount(), labels.GetCount() ); - for (int i = 0; i < values.GetCount(); ++i ) + for (unsigned int i = 0; i < values.GetCount(); ++i ) { BOOST_CHECK_EQUAL( v.GetValue( i ), values[i] ); } - for (int i = 0; i < labels.GetCount(); ++i ) + for (unsigned int i = 0; i < labels.GetCount(); ++i ) { BOOST_CHECK_EQUAL( v.GetLabel( i ), labels[i] ); } @@ -338,12 +338,12 @@ BOOST_AUTO_TEST_CASE( EnumClass ) BOOST_CHECK_EQUAL( v.GetCount(), values.GetCount() ); BOOST_CHECK_EQUAL( v.GetCount(), labels.GetCount() ); - for (int i = 0; i < values.GetCount(); ++i ) + for (unsigned int i = 0; i < values.GetCount(); ++i ) { BOOST_CHECK_EQUAL( v.GetValue( i ), values[i] ); } - for (int i = 0; i < labels.GetCount(); ++i ) + for (unsigned int i = 0; i < labels.GetCount(); ++i ) { BOOST_CHECK_EQUAL( v.GetLabel( i ), labels[i] ); } @@ -406,12 +406,12 @@ BOOST_AUTO_TEST_CASE( AlternativeEnum ) BOOST_CHECK_EQUAL( v.GetCount(), values.GetCount() ); BOOST_CHECK_EQUAL( v.GetCount(), labels.GetCount() ); - for (int i = 0; i < values.GetCount(); ++i ) + for (unsigned int i = 0; i < values.GetCount(); ++i ) { BOOST_CHECK_EQUAL( v.GetValue( i ), values[i] ); } - for (int i = 0; i < labels.GetCount(); ++i ) + for (unsigned int i = 0; i < labels.GetCount(); ++i ) { BOOST_CHECK_EQUAL( v.GetLabel( i ), labels[i] ); }