| Version: 3.3.1

Public Member Functions | List of all members
wxGridTableBase Class Referenceabstract
Class List by Category » Grid Related Classes

`#include <wx/grid.h>`

Inheritance diagram for wxGridTableBase:
[legend]

## 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: wxCore
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 wxGrid * | GetView () const
| Returns the last grid passed to SetView(). More...
virtual bool | CanHaveAttributes ()
| Returns true if this table supports attributes or false otherwise. More...
virtual bool | CanMeasureColUsingSameAttr (int col) const
| Override to return true if the same attribute can be used for measuring all cells in the given column. 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, Column and Corner Labels
By default the numbers are used for labelling rows and Latin letters for labelling 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, ... A cell in the top-left corner of a grid can also have a label. It is empty by default. Use wxGrid::SetCornerLabelValue() to set it and wxGrid::GetCornerLabelValue() to get its' current value. See also wxGridTableBase::GetCornerLabelValue, wxGridTableBase::SetCornerLabelValue
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 wxString | GetCornerLabelValue () const
| Return the label of the grid's corner. 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...
virtual void | SetCornerLabelValue (const wxString &)
| Set the given label for the grid's corner. 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...
wxGridCellAttrProvider * | GetAttrProvider () const
| Returns the attribute provider currently being used. More...
virtual wxGridCellAttr * | GetAttr (int row, int col, wxGridCellAttr::wxAttrKind kind)
| Return the attribute for the given cell. More...
wxGridCellAttrPtr | GetAttrPtr (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 nullptr the internal reference data. More...
| wxObject (const wxObject &other)
| Copy ctor. More...
virtual | ~wxObject ()
| Destructor. More...
virtual wxClassInfo * | GetClassInfo () const
| This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
wxObjectRefData * | GetRefData () 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=nullptr, 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 wxObjectRefData * | CreateRefData () const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
virtual wxObjectRefData * | CloneRefData (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
wxObjectRefData * | m_refData
| Pointer to an object which is the object's reference-counted data. More...

## Constructor & Destructor Documentation

## ◆ wxGridTableBase()

wxGridTableBase::wxGridTableBase | ( |  | ) |

Default constructor.

## ◆ ~wxGridTableBase()

virtual wxGridTableBase::~wxGridTableBase | ( |  | ) |
| virtual

Destructor frees the attribute provider if it was created.

## Member Function Documentation

## ◆ AppendCols()

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

Exactly the same as AppendRows() but for columns.

Reimplemented in wxGridStringTable.

## ◆ AppendRows()

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

  numRows | The number of rows to add.

Reimplemented in wxGridStringTable.

## ◆ CanGetValueAs()

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.

## ◆ CanHaveAttributes()

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.

## ◆ CanMeasureColUsingSameAttr()

virtual bool wxGridTableBase::CanMeasureColUsingSameAttr | ( | int | col | ) | const
| virtual

Override to return true if the same attribute can be used for measuring all cells in the given column.

This function is provided for optimization purposes: it returns false by default, but can be overridden to return true when all the cells in the same grid column use sensibly the same attribute, i.e. they use the same renderer (either explicitly, or implicitly, due to their type as returned by GetTypeName()) and the font of the same size.

Returning true from this function allows AutoSizeColumns() to skip looking up the attribute and the renderer for each individual cell, which results in very noticeable performance improvements for the grids with many rows.

Since
  3.1.4

## ◆ CanSetValueAs()

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()

## ◆ Clear()

virtual void wxGridTableBase::Clear | ( |  | ) |
| virtual

Clear the table contents.

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

Reimplemented in wxGridStringTable.

## ◆ DeleteCols()

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

Exactly the same as DeleteRows() but for columns.

Reimplemented in wxGridStringTable.

## ◆ DeleteRows()

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

Delete rows from the table.

Parameters

  pos | The first row to delete.
  numRows | The number of rows to delete.

Reimplemented in wxGridStringTable.

## ◆ GetAttr()

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.

Prefer to use GetAttrPtr() to avoid the need to call DecRef() on the returned pointer manually.

## ◆ GetAttrProvider()

wxGridCellAttrProvider* wxGridTableBase::GetAttrProvider | ( |  | ) | const

Returns the attribute provider currently being used.

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

## ◆ GetAttrPtr()

wxGridCellAttrPtr wxGridTableBase::GetAttrPtr | ( | int | row,
|  | int | col,
|  | wxGridCellAttr::wxAttrKind | kind
| ) |  |

Return the attribute for the given cell.

This method is identical to GetAttr(), but returns a smart pointer, which frees the caller from the need to call DecRef() manually.

Since
  3.1.4

## ◆ GetColLabelValue()

virtual wxString wxGridTableBase::GetColLabelValue | ( | int | col | ) |
| virtual

Return the label of the specified column.

Reimplemented in wxGridStringTable.

## ◆ GetColsCount()

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.

## ◆ GetCornerLabelValue()

virtual wxString wxGridTableBase::GetCornerLabelValue | ( |  | ) | const
| virtual

Return the label of the grid's corner.

Since
  3.1.2

Reimplemented in wxGridStringTable.

## ◆ GetNumberCols()

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.

## ◆ GetNumberRows()

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.

## ◆ GetRowLabelValue()

virtual wxString wxGridTableBase::GetRowLabelValue | ( | int | row | ) |
| virtual

Return the label of the specified row.

Reimplemented in wxGridStringTable.

## ◆ GetRowsCount()

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.

## ◆ GetTypeName()

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`.

## ◆ GetValue()

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

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

Implemented in wxGridStringTable.

## ◆ GetValueAsBool()

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.

## ◆ GetValueAsCustom()

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 nullptr.

Note that if the pointer is not null, it will be deleted by the caller, so it must be allocated on the heap by any class overriding this method. In practice, it means that the value stored internally must be cloned on every call.

## ◆ GetValueAsDouble()

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.

## ◆ GetValueAsLong()

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.

## ◆ GetView()

virtual wxGrid* wxGridTableBase::GetView | ( |  | ) | const
| virtual

Returns the last grid passed to SetView().

## ◆ InsertCols()

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

Exactly the same as InsertRows() but for columns.

Reimplemented in wxGridStringTable.

## ◆ InsertRows()

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

Insert additional rows into the table.

Parameters

  pos | The position of the first new row.
  numRows | The number of rows to insert.

Reimplemented in wxGridStringTable.

## ◆ IsEmpty()

bool wxGridTableBase::IsEmpty | ( | const wxGridCellCoords & | coords | ) |

Same as IsEmptyCell() but taking wxGridCellCoords.

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

## ◆ IsEmptyCell()

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.

## ◆ SetAttr()

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.

## ◆ SetAttrProvider()

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 nullptr, 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.

## ◆ SetColAttr()

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.

## ◆ SetColLabelValue()

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

Exactly the same as SetRowLabelValue() but for columns.

Reimplemented in wxGridStringTable.

## ◆ SetCornerLabelValue()

virtual void wxGridTableBase::SetCornerLabelValue | ( | const wxString & |  | ) |
| virtual

Set the given label for the grid's corner.

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::GetCornerLabelValue() to work.

Since
  3.1.2

Reimplemented in wxGridStringTable.

## ◆ SetRowAttr()

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.

## ◆ SetRowLabelValue()

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.

## ◆ SetValue()

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.

## ◆ SetValueAsBool()

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.

## ◆ SetValueAsCustom()

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.

## ◆ SetValueAsDouble()

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.

## ◆ SetValueAsLong()

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.

## ◆ SetView()

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.