Add a simple wxGrid::AssignTable() wrapper for SetTable()

In many case SetTable() is called with its takeOwnership parameter set
to true, as shown by the grid sample in which all 3 of the calls to
SetTable() set it to true, but calling it in this case is awkward, as
bare "true" in the caller is unreadable and almost invariably requires
an explanatory comment.

Improve the API by adding AssignTable(), which is the same to SetTable()
as the existing AssignImageList() to SetImageLabel(), which always takes
ownership of the table pointer.
This commit is contained in:
Vadim Zeitlin
2020-03-30 02:24:20 +02:00
parent 3674240146
commit 15b5a1865c
4 changed files with 49 additions and 12 deletions

View File

@@ -1075,12 +1075,13 @@ public:
virtual ~wxGrid();
// however to initialize grid data either CreateGrid() or SetTable() must
// however to initialize grid data either CreateGrid() (to use a simple
// default table class) or {Set,Assign}Table() (to use a custom table) must
// be also called
// this is basically equivalent to
//
// SetTable(new wxGridStringTable(numRows, numCols), true, selmode)
// AssignTable(new wxGridStringTable(numRows, numCols), selmode)
//
bool CreateGrid( int numRows, int numCols,
wxGridSelectionModes selmode = wxGridSelectCells );
@@ -1089,6 +1090,9 @@ public:
bool takeOwnership = false,
wxGridSelectionModes selmode = wxGridSelectCells );
void AssignTable( wxGridTableBase *table,
wxGridSelectionModes selmode = wxGridSelectCells );
bool ProcessTableMessage(wxGridTableMessage&);
wxGridTableBase *GetTable() const { return m_table; }