From e43190ea796ac3c1d15c18a88bcf7f3f745bd4bc Mon Sep 17 00:00:00 2001 From: Artur Wieczorek <7330332+a-wi@users.noreply.github.com> Date: Fri, 6 Jan 2023 17:52:05 +0200 Subject: [PATCH] Code cleanup: wxPGProperty helper classes Move declarations and implementations of wxPGProperty-related helper classes to the files containing wxPGProperty (and derived classes) code. --- include/wx/propgrid/property.h | 24 ++--------- include/wx/propgrid/props.h | 2 +- src/propgrid/property.cpp | 78 ++++++++++++++++++++++++++++++++++ src/propgrid/propgrid.cpp | 55 ------------------------ 4 files changed, 82 insertions(+), 77 deletions(-) diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index 858911603a..c7d42b4079 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -615,33 +615,15 @@ class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry : public wxPGCell { public: wxPGChoiceEntry(); - wxPGChoiceEntry(const wxPGChoiceEntry& other) - : wxPGCell(other) - , m_value(other.m_value) - { - } - wxPGChoiceEntry( const wxString& label, - int value = wxPG_INVALID_VALUE ) - : wxPGCell() - , m_value(value) - { - SetText(label); - } + wxPGChoiceEntry(const wxPGChoiceEntry& other); + wxPGChoiceEntry(const wxString& label, int value = wxPG_INVALID_VALUE); virtual ~wxPGChoiceEntry() = default; void SetValue( int value ) { m_value = value; } int GetValue() const { return m_value; } - wxPGChoiceEntry& operator=( const wxPGChoiceEntry& other ) - { - if ( this != &other ) - { - Ref(other); - } - m_value = other.m_value; - return *this; - } + wxPGChoiceEntry& operator=(const wxPGChoiceEntry& other); protected: int m_value; diff --git a/include/wx/propgrid/props.h b/include/wx/propgrid/props.h index 517b33770f..4267cee406 100644 --- a/include/wx/propgrid/props.h +++ b/include/wx/propgrid/props.h @@ -65,8 +65,8 @@ class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator { public: wxPGInDialogValidator() + : m_textCtrl(nullptr) { - m_textCtrl = nullptr; } ~wxPGInDialogValidator() diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 139d45aa4c..11e91bc908 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -441,6 +441,84 @@ void wxPGCell::SetEmptyData() AllocExclusive(); } +// ----------------------------------------------------------------------- +// wxPGChoiceEntry +// ----------------------------------------------------------------------- + +wxPGChoiceEntry::wxPGChoiceEntry() + : wxPGCell() + , m_value(wxPG_INVALID_VALUE) +{ +} + +wxPGChoiceEntry::wxPGChoiceEntry(const wxPGChoiceEntry& other) + : wxPGCell(other) + , m_value(other.m_value) +{ +} + +wxPGChoiceEntry::wxPGChoiceEntry(const wxString& label, int value) + : wxPGCell() + , m_value(value) +{ + SetText(label); +} + +wxPGChoiceEntry& wxPGChoiceEntry::operator=(const wxPGChoiceEntry& other) +{ + if ( this != &other ) + { + Ref(other); + } + m_value = other.m_value; + return *this; +} + +// ----------------------------------------------------------------------- +// wxPGChoicesData +// ----------------------------------------------------------------------- + +wxPGChoicesData::~wxPGChoicesData() +{ + Clear(); +} + +void wxPGChoicesData::Clear() +{ + m_items.clear(); +} + +void wxPGChoicesData::CopyDataFrom(wxPGChoicesData* data) +{ + wxASSERT(m_items.empty()); + + m_items = data->m_items; +} + +wxPGChoiceEntry& wxPGChoicesData::Insert(int index, + const wxPGChoiceEntry& item) +{ + wxVector::iterator it; + if ( index == -1 ) + { + it = m_items.end(); + index = (int)m_items.size(); + } + else + { + it = m_items.begin() + index; + } + + m_items.insert(it, item); + + wxPGChoiceEntry& ownEntry = m_items[index]; + + // Need to fix value? + if ( ownEntry.GetValue() == wxPG_INVALID_VALUE ) + ownEntry.SetValue(index); + + return ownEntry; +} // ----------------------------------------------------------------------- // wxPGProperty diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 9edb95b13f..b0beeefa53 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -6188,61 +6188,6 @@ wxString wxPGStringTokenizer::GetNextToken() return m_readyToken; } -// ----------------------------------------------------------------------- -// wxPGChoiceEntry -// ----------------------------------------------------------------------- - -wxPGChoiceEntry::wxPGChoiceEntry() - : wxPGCell(), m_value(wxPG_INVALID_VALUE) -{ -} - -// ----------------------------------------------------------------------- -// wxPGChoicesData -// ----------------------------------------------------------------------- - -wxPGChoicesData::~wxPGChoicesData() -{ - Clear(); -} - -void wxPGChoicesData::Clear() -{ - m_items.clear(); -} - -void wxPGChoicesData::CopyDataFrom( wxPGChoicesData* data ) -{ - wxASSERT( m_items.empty() ); - - m_items = data->m_items; -} - -wxPGChoiceEntry& wxPGChoicesData::Insert( int index, - const wxPGChoiceEntry& item ) -{ - wxVector::iterator it; - if ( index == -1 ) - { - it = m_items.end(); - index = (int) m_items.size(); - } - else - { - it = m_items.begin() + index; - } - - m_items.insert(it, item); - - wxPGChoiceEntry& ownEntry = m_items[index]; - - // Need to fix value? - if ( ownEntry.GetValue() == wxPG_INVALID_VALUE ) - ownEntry.SetValue(index); - - return ownEntry; -} - // ----------------------------------------------------------------------- // wxPropertyGridEvent // -----------------------------------------------------------------------