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/trunk@75552 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -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<size_t>(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 )
|
||||
{
|
||||
|
Reference in New Issue
Block a user