Version: 3.0.3
wxGridTableBase Class Referenceabstract

#include <wx/grid.h>

+ Inheritance diagram for wxGridTableBase:

Detailed Description

The almost abstract base class for grid tables.

A grid table is responsible for storing the grid data and, indirectly, grid cell attributes. The data can be stored in the way most convenient for the application but has to be provided in string form to wxGrid. It is also possible to provide cells values in other formats if appropriate, e.g. as numbers.

This base class is not quite abstract as it implements a trivial strategy for storing the attributes by forwarding it to wxGridCellAttrProvider and also provides stubs for some other functions. However it does have a number of pure virtual methods which must be implemented in the derived classes.

See also
wxGridStringTable

Library:  wxAdvanced
Category:  Grid Related Classes

Public Member Functions

 wxGridTableBase ()
 Default constructor. More...
 
virtual ~wxGridTableBase ()
 Destructor frees the attribute provider if it was created. More...
 
virtual int GetNumberRows ()=0
 Must be overridden to return the number of rows in the table. More...
 
virtual int GetNumberCols ()=0
 Must be overridden to return the number of columns in the table. More...
 
int GetRowsCount () const
 Return the number of rows in the table. More...
 
int GetColsCount () const
 Return the number of columns in the table. More...
 
virtual void SetView (wxGrid *grid)
 Called by the grid when the table is associated with it. More...
 
virtual wxGridGetView () const
 Returns the last grid passed to SetView(). More...
 
virtual bool CanHaveAttributes ()
 Returns true if this table supports attributes or false otherwise. More...
 
Table Cell Accessors
virtual bool IsEmptyCell (int row, int col)
 May be overridden to implement testing for empty cells. More...
 
bool IsEmpty (const wxGridCellCoords &coords)
 Same as IsEmptyCell() but taking wxGridCellCoords. More...
 
virtual wxString GetValue (int row, int col)=0
 Must be overridden to implement accessing the table values as text. More...
 
virtual void SetValue (int row, int col, const wxString &value)=0
 Must be overridden to implement setting the table values as text. More...
 
virtual wxString GetTypeName (int row, int col)
 Returns the type of the value in the given cell. More...
 
virtual bool CanGetValueAs (int row, int col, const wxString &typeName)
 Returns true if the value of the given cell can be accessed as if it were of the specified type. More...
 
virtual bool CanSetValueAs (int row, int col, const wxString &typeName)
 Returns true if the value of the given cell can be set as if it were of the specified type. More...
 
virtual long GetValueAsLong (int row, int col)
 Returns the value of the given cell as a long. More...
 
virtual double GetValueAsDouble (int row, int col)
 Returns the value of the given cell as a double. More...
 
virtual bool GetValueAsBool (int row, int col)
 Returns the value of the given cell as a boolean. More...
 
virtual void * GetValueAsCustom (int row, int col, const wxString &typeName)
 Returns the value of the given cell as a user-defined type. More...
 
virtual void SetValueAsLong (int row, int col, long value)
 Sets the value of the given cell as a long. More...
 
virtual void SetValueAsDouble (int row, int col, double value)
 Sets the value of the given cell as a double. More...
 
virtual void SetValueAsBool (int row, int col, bool value)
 Sets the value of the given cell as a boolean. More...
 
virtual void SetValueAsCustom (int row, int col, const wxString &typeName, void *value)
 Sets the value of the given cell as a user-defined type. More...
 
Table Structure Modifiers

Note that none of these functions are pure virtual as they don't have to be implemented if the table structure is never modified after creation, i.e. neither rows nor columns are ever added or deleted.

Also note that you do need to implement them if they are called, i.e. if your code either calls them directly or uses the matching wxGrid methods, as by default they simply do nothing which is definitely inappropriate.

virtual void Clear ()
 Clear the table contents. More...
 
virtual bool InsertRows (size_t pos=0, size_t numRows=1)
 Insert additional rows into the table. More...
 
virtual bool AppendRows (size_t numRows=1)
 Append additional rows at the end of the table. More...
 
virtual bool DeleteRows (size_t pos=0, size_t numRows=1)
 Delete rows from the table. More...
 
virtual bool InsertCols (size_t pos=0, size_t numCols=1)
 Exactly the same as InsertRows() but for columns. More...
 
virtual bool AppendCols (size_t numCols=1)
 Exactly the same as AppendRows() but for columns. More...
 
virtual bool DeleteCols (size_t pos=0, size_t numCols=1)
 Exactly the same as DeleteRows() but for columns. More...
 
Table Row and Column Labels

By default the numbers are used for labeling rows and Latin letters for labeling columns. If the table has more than 26 columns, the pairs of letters are used starting from the 27-th one and so on, i.e. the sequence of labels is A, B, ..., Z, AA, AB, ..., AZ, BA, ..., ..., ZZ, AAA, ...

virtual wxString GetRowLabelValue (int row)
 Return the label of the specified row. More...
 
virtual wxString GetColLabelValue (int col)
 Return the label of the specified column. More...
 
virtual void SetRowLabelValue (int row, const wxString &label)
 Set the given label for the specified row. More...
 
virtual void SetColLabelValue (int col, const wxString &label)
 Exactly the same as SetRowLabelValue() but for columns. More...
 
Attributes Management

By default the attributes management is delegated to wxGridCellAttrProvider class.

You may override the methods in this section to handle the attributes directly if, for example, they can be computed from the cell values.

void SetAttrProvider (wxGridCellAttrProvider *attrProvider)
 Associate this attributes provider with the table. More...
 
wxGridCellAttrProviderGetAttrProvider () const
 Returns the attribute provider currently being used. More...
 
virtual wxGridCellAttrGetAttr (int row, int col, wxGridCellAttr::wxAttrKind kind)
 Return the attribute for the given cell. More...
 
virtual void SetAttr (wxGridCellAttr *attr, int row, int col)
 Set attribute of the specified cell. More...
 
virtual void SetRowAttr (wxGridCellAttr *attr, int row)
 Set attribute of the specified row. More...
 
virtual void SetColAttr (wxGridCellAttr *attr, int col)
 Set attribute of the specified column. More...
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data. More...
 
 wxObject (const wxObject &other)
 Copy ctor. More...
 
virtual ~wxObject ()
 Destructor. More...
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class. More...
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj. More...
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone. More...
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer. More...
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public. More...
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 

Additional Inherited Members

- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object. More...
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
 
- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data. More...
 

Constructor & Destructor Documentation

wxGridTableBase::wxGridTableBase ( )

Default constructor.

virtual wxGridTableBase::~wxGridTableBase ( )
virtual

Destructor frees the attribute provider if it was created.

Member Function Documentation

virtual bool wxGridTableBase::AppendCols ( size_t  numCols = 1)
virtual

Exactly the same as AppendRows() but for columns.

Reimplemented in wxGridStringTable.

virtual bool wxGridTableBase::AppendRows ( size_t  numRows = 1)
virtual

Append additional rows at the end of the table.

This method is provided in addition to InsertRows() as some data models may only support appending rows to them but not inserting them at arbitrary locations. In such case you may implement this method only and leave InsertRows() unimplemented.

Parameters
numRowsThe number of rows to add.

Reimplemented in wxGridStringTable.

virtual bool wxGridTableBase::CanGetValueAs ( int  row,
int  col,
const wxString typeName 
)
virtual

Returns true if the value of the given cell can be accessed as if it were of the specified type.

By default the cells can only be accessed as strings. Note that a cell could be accessible in different ways, e.g. a numeric cell may return true for wxGRID_VALUE_NUMBER but also for wxGRID_VALUE_STRING indicating that the value can be coerced to a string form.

virtual bool wxGridTableBase::CanHaveAttributes ( )
virtual

Returns true if this table supports attributes or false otherwise.

By default, the table automatically creates a wxGridCellAttrProvider when this function is called if it had no attribute provider before and returns true.

virtual bool wxGridTableBase::CanSetValueAs ( int  row,
int  col,
const wxString typeName 
)
virtual

Returns true if the value of the given cell can be set as if it were of the specified type.

See also
CanGetValueAs()
virtual void wxGridTableBase::Clear ( )
virtual

Clear the table contents.

This method is used by wxGrid::ClearGrid().

Reimplemented in wxGridStringTable.

virtual bool wxGridTableBase::DeleteCols ( size_t  pos = 0,
size_t  numCols = 1 
)
virtual

Exactly the same as DeleteRows() but for columns.

Reimplemented in wxGridStringTable.

virtual bool wxGridTableBase::DeleteRows ( size_t  pos = 0,
size_t  numRows = 1 
)
virtual

Delete rows from the table.

Notice that currently deleting a row intersecting a multi-cell (see SetCellSize()) is not supported and will result in a crash.

Parameters
posThe first row to delete.
numRowsThe number of rows to delete.

Reimplemented in wxGridStringTable.

virtual wxGridCellAttr* wxGridTableBase::GetAttr ( int  row,
int  col,
wxGridCellAttr::wxAttrKind  kind 
)
virtual

Return the attribute for the given cell.

By default this function is simply forwarded to wxGridCellAttrProvider::GetAttr() but it may be overridden to handle attributes directly in the table.

wxGridCellAttrProvider* wxGridTableBase::GetAttrProvider ( ) const

Returns the attribute provider currently being used.

This function may return NULL if the attribute provider hasn't been neither associated with this table by SetAttrProvider() nor created on demand by any other methods.

virtual wxString wxGridTableBase::GetColLabelValue ( int  col)
virtual

Return the label of the specified column.

Reimplemented in wxGridStringTable.

int wxGridTableBase::GetColsCount ( ) const

Return the number of columns in the table.

This method is not virtual and is only provided as a convenience for the derived classes which can't call GetNumberCols() without a const_cast from their const methods.

virtual int wxGridTableBase::GetNumberCols ( )
pure virtual

Must be overridden to return the number of columns in the table.

For backwards compatibility reasons, this method is not const. Use GetColsCount() instead of it in const methods of derived table classes,

Implemented in wxGridStringTable.

virtual int wxGridTableBase::GetNumberRows ( )
pure virtual

Must be overridden to return the number of rows in the table.

For backwards compatibility reasons, this method is not const. Use GetRowsCount() instead of it in const methods of derived table classes.

Implemented in wxGridStringTable.

virtual wxString wxGridTableBase::GetRowLabelValue ( int  row)
virtual

Return the label of the specified row.

Reimplemented in wxGridStringTable.

int wxGridTableBase::GetRowsCount ( ) const

Return the number of rows in the table.

This method is not virtual and is only provided as a convenience for the derived classes which can't call GetNumberRows() without a const_cast from their const methods.

virtual wxString wxGridTableBase::GetTypeName ( int  row,
int  col 
)
virtual

Returns the type of the value in the given cell.

By default all cells are strings and this method returns wxGRID_VALUE_STRING.

virtual wxString wxGridTableBase::GetValue ( int  row,
int  col 
)
pure virtual

Must be overridden to implement accessing the table values as text.

Implemented in wxGridStringTable.

virtual bool wxGridTableBase::GetValueAsBool ( int  row,
int  col 
)
virtual

Returns the value of the given cell as a boolean.

This should only be called if CanGetValueAs() returns true when called with wxGRID_VALUE_BOOL argument. Default implementation always return false.

virtual void* wxGridTableBase::GetValueAsCustom ( int  row,
int  col,
const wxString typeName 
)
virtual

Returns the value of the given cell as a user-defined type.

This should only be called if CanGetValueAs() returns true when called with typeName. Default implementation always return NULL.

virtual double wxGridTableBase::GetValueAsDouble ( int  row,
int  col 
)
virtual

Returns the value of the given cell as a double.

This should only be called if CanGetValueAs() returns true when called with wxGRID_VALUE_FLOAT argument. Default implementation always return 0.0.

virtual long wxGridTableBase::GetValueAsLong ( int  row,
int  col 
)
virtual

Returns the value of the given cell as a long.

This should only be called if CanGetValueAs() returns true when called with wxGRID_VALUE_NUMBER argument. Default implementation always return 0.

virtual wxGrid* wxGridTableBase::GetView ( ) const
virtual

Returns the last grid passed to SetView().

virtual bool wxGridTableBase::InsertCols ( size_t  pos = 0,
size_t  numCols = 1 
)
virtual

Exactly the same as InsertRows() but for columns.

Reimplemented in wxGridStringTable.

virtual bool wxGridTableBase::InsertRows ( size_t  pos = 0,
size_t  numRows = 1 
)
virtual

Insert additional rows into the table.

Parameters
posThe position of the first new row.
numRowsThe number of rows to insert.

Reimplemented in wxGridStringTable.

bool wxGridTableBase::IsEmpty ( const wxGridCellCoords coords)

Same as IsEmptyCell() but taking wxGridCellCoords.

Notice that this method is not virtual, only IsEmptyCell() should be overridden.

virtual bool wxGridTableBase::IsEmptyCell ( int  row,
int  col 
)
virtual

May be overridden to implement testing for empty cells.

This method is used by the grid to test if the given cell is not used and so whether a neighbouring cell may overflow into it. By default it only returns true if the value of the given cell, as returned by GetValue(), is empty.

virtual void wxGridTableBase::SetAttr ( wxGridCellAttr attr,
int  row,
int  col 
)
virtual

Set attribute of the specified cell.

By default this function is simply forwarded to wxGridCellAttrProvider::SetAttr().

The table takes ownership of attr, i.e. will call DecRef() on it.

void wxGridTableBase::SetAttrProvider ( wxGridCellAttrProvider attrProvider)

Associate this attributes provider with the table.

The table takes ownership of attrProvider pointer and will delete it when it doesn't need it any more. The pointer can be NULL, however this won't disable attributes management in the table but will just result in a default attributes being recreated the next time any of the other functions in this section is called. To completely disable the attributes support, should this be needed, you need to override CanHaveAttributes() to return false.

virtual void wxGridTableBase::SetColAttr ( wxGridCellAttr attr,
int  col 
)
virtual

Set attribute of the specified column.

By default this function is simply forwarded to wxGridCellAttrProvider::SetColAttr().

The table takes ownership of attr, i.e. will call DecRef() on it.

virtual void wxGridTableBase::SetColLabelValue ( int  col,
const wxString label 
)
virtual

Exactly the same as SetRowLabelValue() but for columns.

Reimplemented in wxGridStringTable.

virtual void wxGridTableBase::SetRowAttr ( wxGridCellAttr attr,
int  row 
)
virtual

Set attribute of the specified row.

By default this function is simply forwarded to wxGridCellAttrProvider::SetRowAttr().

The table takes ownership of attr, i.e. will call DecRef() on it.

virtual void wxGridTableBase::SetRowLabelValue ( int  row,
const wxString label 
)
virtual

Set the given label for the specified row.

The default version does nothing, i.e. the label is not stored. You must override this method in your derived class if you wish wxGrid::SetRowLabelValue() to work.

Reimplemented in wxGridStringTable.

virtual void wxGridTableBase::SetValue ( int  row,
int  col,
const wxString value 
)
pure virtual

Must be overridden to implement setting the table values as text.

Implemented in wxGridStringTable.

virtual void wxGridTableBase::SetValueAsBool ( int  row,
int  col,
bool  value 
)
virtual

Sets the value of the given cell as a boolean.

This should only be called if CanSetValueAs() returns true when called with wxGRID_VALUE_BOOL argument. Default implementation doesn't do anything.

virtual void wxGridTableBase::SetValueAsCustom ( int  row,
int  col,
const wxString typeName,
void *  value 
)
virtual

Sets the value of the given cell as a user-defined type.

This should only be called if CanSetValueAs() returns true when called with typeName. Default implementation doesn't do anything.

virtual void wxGridTableBase::SetValueAsDouble ( int  row,
int  col,
double  value 
)
virtual

Sets the value of the given cell as a double.

This should only be called if CanSetValueAs() returns true when called with wxGRID_VALUE_FLOAT argument. Default implementation doesn't do anything.

virtual void wxGridTableBase::SetValueAsLong ( int  row,
int  col,
long  value 
)
virtual

Sets the value of the given cell as a long.

This should only be called if CanSetValueAs() returns true when called with wxGRID_VALUE_NUMBER argument. Default implementation doesn't do anything.

virtual void wxGridTableBase::SetView ( wxGrid grid)
virtual

Called by the grid when the table is associated with it.

The default implementation stores the pointer and returns it from its GetView() and so only makes sense if the table cannot be associated with more than one grid at a time.