Tried to make wxDataViewModel docs clearer
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65110 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -20,17 +20,26 @@
|
|||||||
wxDataViewModel::GetValue in order to define the data model which acts as an
|
wxDataViewModel::GetValue in order to define the data model which acts as an
|
||||||
interface between your actual data and the wxDataViewCtrl.
|
interface between your actual data and the wxDataViewCtrl.
|
||||||
|
|
||||||
Since you will usually also allow the wxDataViewCtrl to change your data
|
Note that wxDataViewModel does not define the position or index of any item
|
||||||
|
in the control because different controls might display the same data differently.
|
||||||
|
wxDataViewModel does provide a wxDataViewModel::Compare method which the
|
||||||
|
wxDataViewCtrl may use to sort the data either in conjunction with a column
|
||||||
|
header or without (see wxDataViewModel::HasDefaultCompare).
|
||||||
|
|
||||||
|
wxDataViewModel (as indeed the entire wxDataViewCtrl code) is using wxVariant
|
||||||
|
to store data and its type in a generic way. wxVariant can be extended to contain
|
||||||
|
almost any data without changes to the original class. To a certain extent,
|
||||||
|
you can use (the somewhat more elegant) wxAny instead of wxVariant as there
|
||||||
|
is code to convert between the two, but it is unclear what impact this will
|
||||||
|
have on performance.
|
||||||
|
|
||||||
|
Since you will usually allow the wxDataViewCtrl to change your data
|
||||||
through its graphical interface, you will also have to override
|
through its graphical interface, you will also have to override
|
||||||
wxDataViewModel::SetValue which the wxDataViewCtrl will call when a change
|
wxDataViewModel::SetValue which the wxDataViewCtrl will call when a change
|
||||||
to some data has been committed.
|
to some data has been committed.
|
||||||
|
|
||||||
wxDataViewModel (as indeed the entire wxDataViewCtrl code) is using wxVariant
|
If the data represented by the model is changed by something else than its
|
||||||
to store data and its type in a generic way. wxVariant can be extended to contain
|
associated wxDataViewCtrl, the control has to be notified about the change.
|
||||||
almost any data without changes to the original class.
|
|
||||||
|
|
||||||
The data that is presented through this data model is expected to change at
|
|
||||||
run-time. You need to inform the data model when a change happened.
|
|
||||||
Depending on what happened you need to call one of the following methods:
|
Depending on what happened you need to call one of the following methods:
|
||||||
- wxDataViewModel::ValueChanged,
|
- wxDataViewModel::ValueChanged,
|
||||||
- wxDataViewModel::ItemAdded,
|
- wxDataViewModel::ItemAdded,
|
||||||
@@ -44,12 +53,6 @@
|
|||||||
- wxDataViewModel::ItemsDeleted,
|
- wxDataViewModel::ItemsDeleted,
|
||||||
- wxDataViewModel::ItemsChanged.
|
- wxDataViewModel::ItemsChanged.
|
||||||
|
|
||||||
Note that wxDataViewModel does not define the position or index of any item
|
|
||||||
in the control because different controls might display the same data differently.
|
|
||||||
wxDataViewModel does provide a wxDataViewModel::Compare method which the
|
|
||||||
wxDataViewCtrl may use to sort the data either in conjunction with a column
|
|
||||||
header or without (see wxDataViewModel::HasDefaultCompare).
|
|
||||||
|
|
||||||
This class maintains a list of wxDataViewModelNotifier which link this class
|
This class maintains a list of wxDataViewModelNotifier which link this class
|
||||||
to the specific implementations on the supported platforms so that e.g. calling
|
to the specific implementations on the supported platforms so that e.g. calling
|
||||||
wxDataViewModel::ValueChanged on this model will just call
|
wxDataViewModel::ValueChanged on this model will just call
|
||||||
@@ -75,6 +78,19 @@
|
|||||||
// add columns now
|
// add columns now
|
||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
|
A potentially better way to avoid memory leaks is to use wxObjectDataPtr
|
||||||
|
|
||||||
|
@code
|
||||||
|
wxObjectDataPtr<MyMusicModel> musicModel;
|
||||||
|
|
||||||
|
wxDataViewCtrl *musicCtrl = new wxDataViewCtrl( this, wxID_ANY );
|
||||||
|
musicModel = new MyMusicModel;
|
||||||
|
m_musicCtrl->AssociateModel( musicModel.get() );
|
||||||
|
|
||||||
|
// add columns now
|
||||||
|
@endcode
|
||||||
|
|
||||||
|
|
||||||
@library{wxadv}
|
@library{wxadv}
|
||||||
@category{dvc}
|
@category{dvc}
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user