From 8856715d2d0f4e630de50e81fda4b8bd355060c1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Dec 2018 14:39:38 +0100 Subject: [PATCH] Use wxVector instead of wxList for wxDataViewCtrl columns storage As wxDataViewColumnList was never public, it should be fine to not define it any more and use a vector instead. This makes the code more clear and also marginally more efficient. --- include/wx/generic/dataview.h | 8 +++----- src/generic/datavgen.cpp | 34 ++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index bef6ab1f97..6742e048ba 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -12,7 +12,6 @@ #include "wx/defs.h" #include "wx/object.h" -#include "wx/list.h" #include "wx/control.h" #include "wx/scrolwin.h" #include "wx/icon.h" @@ -179,9 +178,6 @@ private: // wxDataViewCtrl // --------------------------------------------------------- -WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList, - class WXDLLIMPEXP_CORE); - class WXDLLIMPEXP_CORE wxDataViewCtrl : public wxDataViewCtrlBase, public wxScrollHelper { @@ -366,7 +362,9 @@ private: void InvalidateColBestWidth(int idx); void UpdateColWidths(); - wxDataViewColumnList m_cols; + void DoClearColumns(); + + wxVector m_cols; // cached column best widths information, values are for // respective columns from m_cols and the arrays have same size struct CachedColWidthInfo diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 80c7c7aa2c..2ea515ae00 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -5054,8 +5054,6 @@ void wxDataViewMainWindow::UpdateColumnSizes() // wxDataViewCtrl //----------------------------------------------------------------------------- -WX_DEFINE_LIST(wxDataViewColumnList) - wxIMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase); wxBEGIN_EVENT_TABLE(wxDataViewCtrl, wxDataViewCtrlBase) EVT_SIZE(wxDataViewCtrl::OnSize) @@ -5066,8 +5064,7 @@ wxDataViewCtrl::~wxDataViewCtrl() if (m_notifier) GetModel()->RemoveNotifier( m_notifier ); - m_cols.Clear(); - m_colsBestWidths.clear(); + DoClearColumns(); #if wxUSE_ACCESSIBILITY SetAccessible(NULL); @@ -5077,7 +5074,6 @@ wxDataViewCtrl::~wxDataViewCtrl() void wxDataViewCtrl::Init() { - m_cols.DeleteContents(true); m_notifier = NULL; m_headerArea = NULL; @@ -5329,7 +5325,7 @@ bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col ) if (!wxDataViewCtrlBase::AppendColumn(col)) return false; - m_cols.Append( col ); + m_cols.push_back( col ); m_colsBestWidths.push_back(CachedColWidthInfo()); OnColumnsCountChanged(); return true; @@ -5340,7 +5336,7 @@ bool wxDataViewCtrl::PrependColumn( wxDataViewColumn *col ) if (!wxDataViewCtrlBase::PrependColumn(col)) return false; - m_cols.Insert( col ); + m_cols.insert(m_cols.begin(), col); m_colsBestWidths.insert(m_colsBestWidths.begin(), CachedColWidthInfo()); OnColumnsCountChanged(); return true; @@ -5351,7 +5347,7 @@ bool wxDataViewCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col ) if (!wxDataViewCtrlBase::InsertColumn(pos,col)) return false; - m_cols.Insert( pos, col ); + m_cols.insert(m_cols.begin() + pos, col); m_colsBestWidths.insert(m_colsBestWidths.begin() + pos, CachedColWidthInfo()); OnColumnsCountChanged(); return true; @@ -5400,7 +5396,7 @@ void wxDataViewCtrl::DoSetIndent() unsigned int wxDataViewCtrl::GetColumnCount() const { - return m_cols.GetCount(); + return m_cols.size(); } bool wxDataViewCtrl::SetRowHeight( int lineHeight ) @@ -5552,12 +5548,12 @@ void wxDataViewCtrl::ColumnMoved(wxDataViewColumn *col, unsigned int new_pos) bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column ) { - wxDataViewColumnList::compatibility_iterator ret = m_cols.Find( column ); - if (!ret) + const int idx = GetColumnIndex(column); + if ( idx == wxNOT_FOUND ) return false; - m_colsBestWidths.erase(m_colsBestWidths.begin() + GetColumnIndex(column)); - m_cols.Erase(ret); + m_colsBestWidths.erase(m_colsBestWidths.begin() + idx); + m_cols.erase(m_cols.begin() + idx); if ( m_clientArea->GetCurrentColumn() == column ) m_clientArea->ClearCurrentColumn(); @@ -5567,10 +5563,20 @@ bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column ) return true; } +void wxDataViewCtrl::DoClearColumns() +{ + typedef wxVector::const_iterator citer; + for ( citer it = m_cols.begin(); it != m_cols.end(); ++it ) + delete *it; +} + bool wxDataViewCtrl::ClearColumns() { SetExpanderColumn(NULL); - m_cols.Clear(); + + DoClearColumns(); + + m_cols.clear(); m_sortingColumnIdxs.clear(); m_colsBestWidths.clear();