From a56cffc9740923fd5c36c48d2c0a9eb9d98de579 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 5 Jan 2014 12:56:48 +0000 Subject: [PATCH] Simplify and fix column determination code in wxGridStringTable. The number of columns in the table is now (since r60717) stored in m_numCols, so there is no need to get it from wxGrid any more. This is not only simpler and faster but also more correct as the first row might not have the full number of values yet. Closes #15809. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75551 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/grid.cpp | 46 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 31f9297c63..215b818c9b 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -1329,18 +1329,14 @@ void wxGridStringTable::Clear() bool wxGridStringTable::InsertRows( size_t pos, size_t numRows ) { - size_t curNumRows = m_data.GetCount(); - size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : - ( GetView() ? GetView()->GetNumberCols() : 0 ) ); - - if ( pos >= curNumRows ) + if ( pos >= m_data.size() ) { return AppendRows( numRows ); } wxArrayString sa; - sa.Alloc( curNumCols ); - sa.Add( wxEmptyString, curNumCols ); + sa.Alloc( m_numCols ); + sa.Add( wxEmptyString, m_numCols ); m_data.Insert( sa, pos, numRows ); if ( GetView() ) @@ -1358,16 +1354,11 @@ bool wxGridStringTable::InsertRows( size_t pos, size_t numRows ) bool wxGridStringTable::AppendRows( size_t numRows ) { - size_t curNumRows = m_data.GetCount(); - size_t curNumCols = ( curNumRows > 0 - ? m_data[0].GetCount() - : ( GetView() ? GetView()->GetNumberCols() : 0 ) ); - wxArrayString sa; - if ( curNumCols > 0 ) + if ( m_numCols > 0 ) { - sa.Alloc( curNumCols ); - sa.Add( wxEmptyString, curNumCols ); + sa.Alloc( m_numCols ); + sa.Add( wxEmptyString, m_numCols ); } m_data.Add( sa, numRows ); @@ -1430,14 +1421,7 @@ bool wxGridStringTable::DeleteRows( size_t pos, size_t numRows ) bool wxGridStringTable::InsertCols( size_t pos, size_t numCols ) { - size_t row, col; - - size_t curNumRows = m_data.GetCount(); - size_t curNumCols = ( curNumRows > 0 - ? m_data[0].GetCount() - : ( GetView() ? GetView()->GetNumberCols() : 0 ) ); - - if ( pos >= curNumCols ) + if ( pos >= static_cast(m_numCols) ) { return AppendCols( numCols ); } @@ -1446,14 +1430,13 @@ bool wxGridStringTable::InsertCols( size_t pos, size_t numCols ) { m_colLabels.Insert( wxEmptyString, pos, numCols ); - size_t i; - for ( i = pos; i < pos + numCols; i++ ) + for ( size_t i = pos; i < pos + numCols; i++ ) m_colLabels[i] = wxGridTableBase::GetColLabelValue( i ); } - for ( row = 0; row < curNumRows; row++ ) + for ( size_t row = 0; row < m_data.size(); row++ ) { - for ( col = pos; col < pos + numCols; col++ ) + for ( size_t col = pos; col < pos + numCols; col++ ) { m_data[row].Insert( wxEmptyString, col ); } @@ -1476,11 +1459,7 @@ bool wxGridStringTable::InsertCols( size_t pos, size_t numCols ) bool wxGridStringTable::AppendCols( size_t numCols ) { - size_t row; - - size_t curNumRows = m_data.GetCount(); - - for ( row = 0; row < curNumRows; row++ ) + for ( size_t row = 0; row < m_data.size(); row++ ) { m_data[row].Add( wxEmptyString, numCols ); } @@ -1504,8 +1483,7 @@ bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols ) size_t row; size_t curNumRows = m_data.GetCount(); - size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : - ( GetView() ? GetView()->GetNumberCols() : 0 ) ); + size_t curNumCols = m_numCols; if ( pos >= curNumCols ) {