]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/dataviewmodel.tex
remove C++ comment
[wxWidgets.git] / docs / latex / wx / dataviewmodel.tex
CommitLineData
b6b9d556
RR
1
2\section{\class{wxDataViewModel}}\label{wxdataviewmodel}
3
4wxDataViewModel is the base class for all data model to be
5displayed by a \helpref{wxDataViewCtrl}{wxdataviewctrl}.
1ab4aff2
RR
6All other models derive from it and must implement its
7pure virtual functions in order to define a complete
8data model. In detail, you need to override
9\helpref{IsContainer}{wxdataviewmodeliscontainer},
10\helpref{GetParent}{wxdataviewmodelgetparent},
74fe973b 11\helpref{GetChildren}{wxdataviewmodelgetchildren},
1ab4aff2
RR
12\helpref{GetColumnCount}{wxdataviewmodelgetcolumncount},
13\helpref{GetColumnType}{wxdataviewmodelgetcolumntype} and
14\helpref{GetValue}{wxdataviewmodelgetvalue} in order to
15define the data model which acts as an interface between
16your actual data and the wxDataViewCtrl. Since you will
aa0576fe
RR
17usually also allow the wxDataViewCtrl to change your data
18through its graphical interface, you will also have to override
61cec318 19\helpref{SetValue}{wxdataviewmodelsetvalue} which the
aa0576fe
RR
20wxDataViewCtrl will call when a change to some data has been
21commited.
22
1ab4aff2 23wxDataViewModel (as indeed the entire wxDataViewCtrl
b19add95
RR
24code) is using \helpref{wxVariant}{wxvariant} to store data and
25its type in a generic way. wxVariant can be extended to contain
26almost any data without changes to the original class.
27
1ab4aff2
RR
28The data that is presented through this data model is expected
29to change at run-time. You need to inform the data model when
30a change happened. Depending on what happened you need to call
31one of the following methods:
32\helpref{ValueChanged}{wxdataviewmodelvaluechanged},
33\helpref{ItemAdded}{wxdataviewmodelitemadded},
34\helpref{ItemDeleted}{wxdataviewmodelitemdeleted},
35\helpref{ItemChanged}{wxdataviewmodelitemchanged},
2a4f365c
RR
36\helpref{Cleared}{wxdataviewmodelcleared}. There are
37plural forms for notification of addition, change
38or removal of several item at once. See
39\helpref{ItemsAdded}{wxdataviewmodelitesmadded},
40\helpref{ItemsDeleted}{wxdataviewmodelitemsdeleted},
41\helpref{ItemsChanged}{wxdataviewmodelitemschanged},
1ab4aff2
RR
42
43Note that wxDataViewModel does not define the position or
2a4f365c
RR
44index of any item in the control because different controls
45might display the same data differently. wxDataViewModel does
1ab4aff2 46provide a \helpref{Compare}{wxdataviewmodelcompare} method
0bd26819
RR
47which the wxDataViewCtrl may use to sort the data either
48in conjunction with a column header or without (see
2a4f365c 49\helpref{HasDefaultCompare}{wxdataviewmodelhasdefaultcompare}).
1ab4aff2 50
b6b9d556 51This class maintains a list of
1ab4aff2 52\helpref{wxDataViewModelNotifier}{wxdataviewmodelnotifier}
b6b9d556 53which link this class to the specific implementations on the
b19add95 54supported platforms so that e.g. calling
1ab4aff2 55\helpref{ValueChanged}{wxdataviewmodelvaluechanged}
b6b9d556 56on this model will just call
1ab4aff2
RR
57\helpref{wxDataViewModelNotifier::ValueChanged}{wxdataviewmodelnotifiervaluechanged}
58for each notifier that has been added. You can also add
59your own notifier in order to get informed about any changes
60to the data in the list model.
61
62Currently wxWidgets provides the following models apart
63from the base model:
716a15b7
RR
64\helpref{wxDataViewIndexListModel}{wxdataviewindexlistmodel},
65\helpref{wxDataViewTreeStore}{wxdataviewtreestore}.
b6b9d556 66
2a4f365c
RR
67Note that wxDataViewModel is reference counted, derives from
68\helpref{wxObjectRefData}{wxobjectrefdata} and cannot be deleted
69directly as it can be shares by several wxDataViewCtrl. This
70implies that you need to decrease the reference count after
71associating the model with a control like this:
72
73{\small%
74\begin{verbatim}
75 wxDataViewCtrl *musicCtrl = new wxDataViewCtrl( this, ID_MUSIC_CTRL, wxDefaultPosition,
76 wxDefaultSize, wxDV_MULTIPLE );
77 wxDataViewModel *musicModel = new MyMusicModel;
78 m_musicCtrl->AssociateModel( musicModel );
79 musicModel->DecRef(); // avoid memory leak !!
80
81 // add columns now
82\end{verbatim}
83}%
84
b6b9d556
RR
85\wxheading{Derived from}
86
7376079d 87\helpref{wxObjectRefData}{wxobjectrefdata}
b6b9d556
RR
88
89\wxheading{Include files}
90
91<wx/dataview.h>
92
1ab4aff2 93\wxheading{Library}
b6b9d556 94
1ab4aff2 95\helpref{wxAdv}{librarieslist}
1be9182d 96
809e21b5
FM
97
98
99\latexignore{\rtfignore{\wxheading{Members}}}
100
1ab4aff2 101\membersection{wxDataViewModel::wxDataViewModel}\label{wxdataviewmodelwxdataviewmodel}
1be9182d 102
1ab4aff2 103\func{}{wxDataViewModel}{\void}
b6b9d556 104
1ab4aff2 105Constructor.
b6b9d556 106
1ab4aff2 107\membersection{wxDataViewModel::\destruct{wxDataViewModel}}\label{wxdataviewmodeldtor}
b6b9d556 108
1ab4aff2 109\func{}{\destruct{wxDataViewModel}}{\void}
b6b9d556 110
1ab4aff2 111Destructor. This should not be called directly. Use DecRef() instead.
b6b9d556 112
b6b9d556 113
1ab4aff2 114\membersection{wxDataViewModel::AddNotifier}\label{wxdataviewmodeladdnotifier}
b6b9d556 115
1ab4aff2 116\func{void}{AddNotifier}{\param{wxDataViewModelNotifier* }{notifier}}
b6b9d556 117
61cec318 118Adds a \helpref{wxDataViewModelNotifier}{wxdataviewmodelnotifier}
1ab4aff2 119to the model.
b6b9d556 120
1ab4aff2 121\membersection{wxDataViewModel::Cleared}\label{wxdataviewmodelcleared}
b6b9d556 122
09711964 123\func{virtual bool}{Cleared}{\void}
b6b9d556 124
1ab4aff2 125Called to inform the model that all data has been deleted.
b6b9d556 126
1ab4aff2 127\membersection{wxDataViewModel::Compare}\label{wxdataviewmodelcompare}
b6b9d556 128
09711964 129\func{virtual int}{Compare}{\param{const wxDataViewItem\& }{item1}, \param{const wxDataViewItem\& }{item2}, \param{unsigned int }{column}, \param{bool }{ascending}}
b6b9d556 130
1ab4aff2
RR
131The compare function to be used by control. The default compare function
132sorts by container and other items separately and in ascending order.
133Override this for a different sorting behaviour.
b6b9d556 134
0bd26819
RR
135See also \helpref{HasDefaultCompare}{wxdataviewmodelhasdefaultcompare}.
136
1ab4aff2 137\membersection{wxDataViewModel::GetColumnCount}\label{wxdataviewmodelgetcolumncount}
b6b9d556 138
09711964 139\constfunc{virtual unsigned int}{GetColumnCount}{\void}
b6b9d556 140
1ab4aff2 141Override this to indicate the number of columns in the model.
b6b9d556 142
1ab4aff2 143\membersection{wxDataViewModel::GetColumnType}\label{wxdataviewmodelgetcolumntype}
b6b9d556 144
09711964 145\constfunc{virtual wxString}{GetColumnType}{\param{unsigned int }{col}}
b6b9d556 146
1ab4aff2
RR
147Override this to indicate what type of data is stored in the
148column specified by {\it col}. This should return a string
149indicating the type of data as reported by \helpref{wxVariant}{wxvariant}.
b6b9d556 150
a9768412 151\membersection{wxDataViewModel::GetChildren}\label{wxdataviewmodelgetchildren}
b6b9d556 152
09711964 153\constfunc{virtual unsigned int}{GetChildren}{\param{const wxDataViewItem\& }{item}, \param{wxDataViewItemArray\& }{children} }
b6b9d556 154
74fe973b
RR
155Override this so the control can query the child items of
156an item. Returns the number of items.
b6b9d556 157
1ab4aff2 158\membersection{wxDataViewModel::GetParent}\label{wxdataviewmodelgetparent}
b6b9d556 159
09711964 160\constfunc{virtual wxDataViewItem}{GetParent}{\param{const wxDataViewItem\& }{item}}
b6b9d556 161
1ab4aff2 162Override this to indicate which wxDataViewItem representing the parent
2a4f365c
RR
163of {\it item} or an invalid wxDataViewItem if the the root item is
164the parent item.
b6b9d556 165
1ab4aff2 166\membersection{wxDataViewModel::GetValue}\label{wxdataviewmodelgetvalue}
b6b9d556 167
09711964 168\constfunc{virtual void}{GetValue}{\param{wxVariant\& }{variant}, \param{const wxDataViewItem\& }{item}, \param{unsigned int }{col}}
b6b9d556 169
1ab4aff2
RR
170Override this to indicate the value of {\it item}
171A \helpref{wxVariant}{wxvariant} is used to store the data.
b6b9d556 172
1e40f667
RR
173
174\membersection{wxDataViewModel::HasContainerColumns}\label{wxdataviewmodelhascontainercolumns}
175
176\constfunc{virtual bool}{HasContainerColumns}{\param{const wxDataViewItem\& }{item}}
177
178Override this method to indicate if a container item merely
179acts as a headline (or for categorisation) or if it also
180acts a normal item with entries for futher columns. By
181default returns {\it false}.
182
0bd26819
RR
183\membersection{wxDataViewModel::HasDefaultCompare}\label{wxdataviewmodelhasdefaultcompare}
184
09711964 185\constfunc{virtual bool}{HasDefaultCompare}{\void}
0bd26819
RR
186
187Override this to indicate that the model provides a default compare
188function that the control should use if no wxDataViewColumn has been
189chosen for sorting. Usually, the user clicks on a column header for
190sorting, the data will be sorted alphanumerically. If any other
191order (e.g. by index or order of appearance) is required, then this
192should be used. See also \helpref{wxDataViewIndexListModel}{wxdataviewindexlistmodel}
193for a model which makes use of this.
194
1ab4aff2 195\membersection{wxDataViewModel::IsContainer}\label{wxdataviewmodeliscontainer}
b6b9d556 196
09711964 197\constfunc{virtual bool}{IsContainer}{\param{const wxDataViewItem\& }{item}}
b6b9d556 198
1ab4aff2
RR
199Override this to indicate of {\it item} is a container, i.e. if
200it can have child items.
b6b9d556 201
1ab4aff2 202\membersection{wxDataViewModel::ItemAdded}\label{wxdataviewmodelitemadded}
b6b9d556 203
09711964 204\func{virtual bool}{ItemAdded}{\param{const wxDataViewItem\& }{parent}, \param{const wxDataViewItem\& }{item}}
b6b9d556 205
1ab4aff2
RR
206Call this to inform the model that an item has been added
207to the data.
b6b9d556 208
1ab4aff2 209\membersection{wxDataViewModel::ItemChanged}\label{wxdataviewmodelitemchanged}
b6b9d556 210
09711964 211\func{virtual bool}{ItemChanged}{\param{const wxDataViewItem\& }{item}}
b6b9d556 212
1ab4aff2 213Call this to inform the model that an item has changed.
b6b9d556 214
6608fdab
RR
215This will eventually emit a wxEVT\_DATAVIEW\_ITEM\_VALUE\_CHANGED
216event (in which the column fields will not be set) to the user.
217
854cdb09 218\membersection{wxDataViewModel::ItemsAdded}\label{wxdataviewmodelitemsadded}
b6b9d556 219
854cdb09 220\func{virtual bool}{ItemsAdded}{\param{const wxDataViewItem\& }{parent}, \param{const wxDataViewItemArray\& }{items}}
b6b9d556 221
854cdb09
RR
222Call this to inform the model that several items have been added
223to the data.
224
225\membersection{wxDataViewModel::ItemsChanged}\label{wxdataviewmodelitemschanged}
226
227\func{virtual bool}{ItemsChanged}{\param{const wxDataViewItemArray\& }{items}}
228
229Call this to inform the model that several items have changed.
230
6608fdab
RR
231This will eventually emit wxEVT\_DATAVIEW\_ITEM\_VALUE\_CHANGED
232events (in which the column fields will not be set) to the user.
233
854cdb09
RR
234\membersection{wxDataViewModel::ItemsDeleted}\label{wxdataviewmodelitemsdeleted}
235
236\func{virtual bool}{ItemsDeleted}{\param{const wxDataViewItem\& }{parent}, \param{const wxDataViewItemArray\& }{items}}
237
238Call this to inform the model that several items have been deleted.
b6b9d556 239
1ab4aff2 240\membersection{wxDataViewModel::RemoveNotifier}\label{wxdataviewmodelremovenotifier}
b6b9d556 241
1ab4aff2 242\func{void}{RemoveNotifier}{\param{wxDataViewModelNotifier* }{notifier}}
b6b9d556 243
1ab4aff2 244Remove the {\it notifier} from the list of notifiers.
b6b9d556 245
1ab4aff2 246\membersection{wxDataViewModel::Resort}\label{wxdataviewmodelresort}
b6b9d556 247
09711964 248\func{virtual void}{Resort}{\void}
b6b9d556 249
1ab4aff2
RR
250Call this to initiate a resort after the sort function has
251been changed.
b6b9d556 252
1ab4aff2 253\membersection{wxDataViewModel::SetValue}\label{wxdataviewmodelsetvalue}
b6b9d556 254
09711964 255\func{virtual bool}{SetValue}{\param{const wxVariant\& }{variant}, \param{const wxDataViewItem\& }{item}, \param{unsigned int }{col}}
b6b9d556 256
1ab4aff2
RR
257This gets called in order to set a value in the data model.
258The most common scenario is that the wxDataViewCtrl calls
259this method after the user changed some data in the view.
260Afterwards \helpref{ValueChanged}{wxdataviewmodelvaluechanged}
261has to be called!
b6b9d556 262
1ab4aff2 263\membersection{wxDataViewModel::ValueChanged}\label{wxdataviewmodelvaluechanged}
b6b9d556 264
09711964 265\func{virtual bool}{ValueChanged}{\param{const wxDataViewItem\& }{item}, \param{unsigned int }{col}}
b6b9d556 266
6608fdab
RR
267Call this to inform this model that a value in the model has
268been changed. This is also called from wxDataViewCtrl's
269internal editing code, e.g. when editing a text field
270in the control.
271
272This will eventually emit a wxEVT\_DATAVIEW\_ITEM\_VALUE\_CHANGED
273event to the user.
b6b9d556 274