return the correct number of columns from wxGridStringTable, even when we don't have any rows (closes #10818)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60717 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-05-22 19:53:32 +00:00
parent 3e603cb713
commit 5c3313a968
2 changed files with 27 additions and 20 deletions

View File

@@ -729,10 +729,10 @@ public:
// these are pure virtual in wxGridTableBase // these are pure virtual in wxGridTableBase
// //
int GetNumberRows(); virtual int GetNumberRows() { return m_data.size(); }
int GetNumberCols(); virtual int GetNumberCols() { return m_numCols; }
wxString GetValue( int row, int col ); virtual wxString GetValue( int row, int col );
void SetValue( int row, int col, const wxString& s ); virtual void SetValue( int row, int col, const wxString& s );
// overridden functions from wxGridTableBase // overridden functions from wxGridTableBase
// //
@@ -752,6 +752,12 @@ public:
private: private:
wxGridStringArray m_data; wxGridStringArray m_data;
// notice that while we don't need to store the number of our rows as it's
// always equal to the size of m_data array, we do need to store the number
// of our columns as we can't retrieve it from m_data when the number of
// rows is 0 (see #10818)
int m_numCols;
// These only get used if you set your own labels, otherwise the // These only get used if you set your own labels, otherwise the
// GetRow/ColLabelValue functions return wxGridTableBase defaults // GetRow/ColLabelValue functions return wxGridTableBase defaults
// //

View File

@@ -1127,11 +1127,14 @@ IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable, wxGridTableBase )
wxGridStringTable::wxGridStringTable() wxGridStringTable::wxGridStringTable()
: wxGridTableBase() : wxGridTableBase()
{ {
m_numCols = 0;
} }
wxGridStringTable::wxGridStringTable( int numRows, int numCols ) wxGridStringTable::wxGridStringTable( int numRows, int numCols )
: wxGridTableBase() : wxGridTableBase()
{ {
m_numCols = numCols;
m_data.Alloc( numRows ); m_data.Alloc( numRows );
wxArrayString sa; wxArrayString sa;
@@ -1145,19 +1148,6 @@ wxGridStringTable::~wxGridStringTable()
{ {
} }
int wxGridStringTable::GetNumberRows()
{
return m_data.GetCount();
}
int wxGridStringTable::GetNumberCols()
{
if ( m_data.GetCount() > 0 )
return m_data[0].GetCount();
else
return 0;
}
wxString wxGridStringTable::GetValue( int row, int col ) wxString wxGridStringTable::GetValue( int row, int col )
{ {
wxCHECK_MSG( (row < GetNumberRows()) && (col < GetNumberCols()), wxCHECK_MSG( (row < GetNumberRows()) && (col < GetNumberCols()),
@@ -1327,6 +1317,8 @@ bool wxGridStringTable::InsertCols( size_t pos, size_t numCols )
} }
} }
m_numCols += numCols;
if ( GetView() ) if ( GetView() )
{ {
wxGridTableMessage msg( this, wxGridTableMessage msg( this,
@@ -1351,6 +1343,8 @@ bool wxGridStringTable::AppendCols( size_t numCols )
m_data[row].Add( wxEmptyString, numCols ); m_data[row].Add( wxEmptyString, numCols );
} }
m_numCols += numCols;
if ( GetView() ) if ( GetView() )
{ {
wxGridTableMessage msg( this, wxGridTableMessage msg( this,
@@ -1404,16 +1398,23 @@ bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols )
m_colLabels.RemoveAt( colID, nToRm ); m_colLabels.RemoveAt( colID, nToRm );
} }
for ( row = 0; row < curNumRows; row++ ) if ( numCols >= curNumCols )
{ {
if ( numCols >= curNumCols ) for ( row = 0; row < curNumRows; row++ )
{ {
m_data[row].Clear(); m_data[row].Clear();
} }
else
m_numCols = 0;
}
else // something will be left
{
for ( row = 0; row < curNumRows; row++ )
{ {
m_data[row].RemoveAt( colID, numCols ); m_data[row].RemoveAt( colID, numCols );
} }
m_numCols -= numCols;
} }
if ( GetView() ) if ( GetView() )