]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/dataviewmodel.tex
wxDataViewCtrl DnD stubs, some reformating
[wxWidgets.git] / docs / latex / wx / dataviewmodel.tex
... / ...
CommitLineData
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}.
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},
11\helpref{GetChildren}{wxdataviewmodelgetchildren},
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
17usually also allow the wxDataViewCtrl to change your data
18through its graphical interface, you will also have to override
19\helpref{SetValue}{wxdataviewmodelsetvalue} which the
20wxDataViewCtrl will call when a change to some data has been
21commited.
22
23wxDataViewModel (as indeed the entire wxDataViewCtrl
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
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},
36\helpref{Cleared}{wxdataviewmodelcleared}. There are
37plural forms for notification of addition, change
38or removal of several item at once. See
39\helpref{ItemsAdded}{wxdataviewmodelitemsadded},
40\helpref{ItemsDeleted}{wxdataviewmodelitemsdeleted},
41\helpref{ItemsChanged}{wxdataviewmodelitemschanged}.
42
43Note that wxDataViewModel does not define the position or
44index of any item in the control because different controls
45might display the same data differently. wxDataViewModel does
46provide a \helpref{Compare}{wxdataviewmodelcompare} method
47which the wxDataViewCtrl may use to sort the data either
48in conjunction with a column header or without (see
49\helpref{HasDefaultCompare}{wxdataviewmodelhasdefaultcompare}).
50
51This class maintains a list of
52\helpref{wxDataViewModelNotifier}{wxdataviewmodelnotifier}
53which link this class to the specific implementations on the
54supported platforms so that e.g. calling
55\helpref{ValueChanged}{wxdataviewmodelvaluechanged}
56on this model will just call
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:
64\helpref{wxDataViewIndexListModel}{wxdataviewindexlistmodel},
65\helpref{wxDataViewTreeStore}{wxdataviewtreestore}.
66
67Note that wxDataViewModel is reference counted, derives from
68\helpref{wxObjectRefData}{wxobjectrefdata} and cannot be deleted
69directly as it can be shared by several wxDataViewCtrls. 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 );
76 wxDataViewModel *musicModel = new MyMusicModel;
77 m_musicCtrl->AssociateModel( musicModel );
78 musicModel->DecRef(); // avoid memory leak !!
79 // add columns now
80\end{verbatim}
81}%
82
83\wxheading{Derived from}
84
85\helpref{wxObjectRefData}{wxobjectrefdata}
86
87\wxheading{Include files}
88
89<wx/dataview.h>
90
91\wxheading{Library}
92
93\helpref{wxAdv}{librarieslist}
94
95
96
97\latexignore{\rtfignore{\wxheading{Members}}}
98
99
100\membersection{wxDataViewModel::wxDataViewModel}\label{wxdataviewmodelwxdataviewmodel}
101
102\func{}{wxDataViewModel}{\void}
103
104Constructor.
105
106
107\membersection{wxDataViewModel::\destruct{wxDataViewModel}}\label{wxdataviewmodeldtor}
108
109\func{}{\destruct{wxDataViewModel}}{\void}
110
111Destructor. This should not be called directly. Use DecRef() instead.
112
113
114
115\membersection{wxDataViewModel::AddNotifier}\label{wxdataviewmodeladdnotifier}
116
117\func{void}{AddNotifier}{\param{wxDataViewModelNotifier* }{notifier}}
118
119Adds a \helpref{wxDataViewModelNotifier}{wxdataviewmodelnotifier}
120to the model.
121
122
123\membersection{wxDataViewModel::Cleared}\label{wxdataviewmodelcleared}
124
125\func{virtual bool}{Cleared}{\void}
126
127Called to inform the model that all data has been cleared. The
128control will reread the data from the model again.
129
130
131\membersection{wxDataViewModel::Compare}\label{wxdataviewmodelcompare}
132
133\func{virtual int}{Compare}{\param{const wxDataViewItem\& }{item1}, \param{const wxDataViewItem\& }{item2}, \param{unsigned int }{column}, \param{bool }{ascending}}
134
135The compare function to be used by control. The default compare function
136sorts by container and other items separately and in ascending order.
137Override this for a different sorting behaviour.
138
139See also \helpref{HasDefaultCompare}{wxdataviewmodelhasdefaultcompare}.
140
141
142\membersection{wxDataViewModel::GetAttr}\label{wxdataviewmodelgetattr}
143
144\func{bool}{GetAttr}{\param{const wxDataViewItem\& }{item}, \param{unsigned int }{col}, \param{wxDataViewItemAttr\& }{attr}}
145
146Oberride this to indicate that the item has special font attributes.
147This only affects the
148\helpref{wxDataViewTextRendererText}{wxdataviewtextrendererattr} renderer.
149
150See also \helpref{wxDataViewItemAttr}{wxdataviewitemattr}.
151
152\membersection{wxDataViewModel::GetColumnCount}\label{wxdataviewmodelgetcolumncount}
153
154\constfunc{virtual unsigned int}{GetColumnCount}{\void}
155
156Override this to indicate the number of columns in the model.
157
158
159\membersection{wxDataViewModel::GetColumnType}\label{wxdataviewmodelgetcolumntype}
160
161\constfunc{virtual wxString}{GetColumnType}{\param{unsigned int }{col}}
162
163Override this to indicate what type of data is stored in the
164column specified by {\it col}. This should return a string
165indicating the type of data as reported by \helpref{wxVariant}{wxvariant}.
166
167
168\membersection{wxDataViewModel::GetChildren}\label{wxdataviewmodelgetchildren}
169
170\constfunc{virtual unsigned int}{GetChildren}{\param{const wxDataViewItem\& }{item}, \param{wxDataViewItemArray\& }{children} }
171
172Override this so the control can query the child items of
173an item. Returns the number of items.
174
175
176\membersection{wxDataViewModel::GetParent}\label{wxdataviewmodelgetparent}
177
178\constfunc{virtual wxDataViewItem}{GetParent}{\param{const wxDataViewItem\& }{item}}
179
180Override this to indicate which wxDataViewItem representing the parent
181of {\it item} or an invalid wxDataViewItem if the the root item is
182the parent item.
183
184
185\membersection{wxDataViewModel::GetValue}\label{wxdataviewmodelgetvalue}
186
187\constfunc{virtual void}{GetValue}{\param{wxVariant\& }{variant}, \param{const wxDataViewItem\& }{item}, \param{unsigned int }{col}}
188
189Override this to indicate the value of {\it item}
190A \helpref{wxVariant}{wxvariant} is used to store the data.
191
192
193
194\membersection{wxDataViewModel::HasContainerColumns}\label{wxdataviewmodelhascontainercolumns}
195
196\constfunc{virtual bool}{HasContainerColumns}{\param{const wxDataViewItem\& }{item}}
197
198Override this method to indicate if a container item merely
199acts as a headline (or for categorisation) or if it also
200acts a normal item with entries for futher columns. By
201default returns {\it false}.
202
203
204\membersection{wxDataViewModel::HasDefaultCompare}\label{wxdataviewmodelhasdefaultcompare}
205
206\constfunc{virtual bool}{HasDefaultCompare}{\void}
207
208Override this to indicate that the model provides a default compare
209function that the control should use if no wxDataViewColumn has been
210chosen for sorting. Usually, the user clicks on a column header for
211sorting, the data will be sorted alphanumerically. If any other
212order (e.g. by index or order of appearance) is required, then this
213should be used. See also \helpref{wxDataViewIndexListModel}{wxdataviewindexlistmodel}
214for a model which makes use of this.
215
216
217\membersection{wxDataViewModel::IsContainer}\label{wxdataviewmodeliscontainer}
218
219\constfunc{virtual bool}{IsContainer}{\param{const wxDataViewItem\& }{item}}
220
221Override this to indicate of {\it item} is a container, i.e. if
222it can have child items.
223
224
225\membersection{wxDataViewModel::ItemAdded}\label{wxdataviewmodelitemadded}
226
227\func{virtual bool}{ItemAdded}{\param{const wxDataViewItem\& }{parent}, \param{const wxDataViewItem\& }{item}}
228
229Call this to inform the model that an item has been added
230to the data.
231
232
233\membersection{wxDataViewModel::ItemChanged}\label{wxdataviewmodelitemchanged}
234
235\func{virtual bool}{ItemChanged}{\param{const wxDataViewItem\& }{item}}
236
237Call this to inform the model that an item has changed.
238
239This will eventually emit a wxEVT\_DATAVIEW\_ITEM\_VALUE\_CHANGED
240event (in which the column fields will not be set) to the user.
241
242
243\membersection{wxDataViewModel::ItemDeleted}\label{wxdataviewmodelitemdeleted}
244
245\func{virtual bool}{ItemDeleted}{\param{const wxDataViewItem\& }{parent}, \param{const wxDataViewItem\& }{item}}
246
247Call this to inform the model that an item has been deleted from the data.
248
249
250\membersection{wxDataViewModel::ItemsAdded}\label{wxdataviewmodelitemsadded}
251
252\func{virtual bool}{ItemsAdded}{\param{const wxDataViewItem\& }{parent}, \param{const wxDataViewItemArray\& }{items}}
253
254Call this to inform the model that several items have been added
255to the data.
256
257
258\membersection{wxDataViewModel::ItemsChanged}\label{wxdataviewmodelitemschanged}
259
260\func{virtual bool}{ItemsChanged}{\param{const wxDataViewItemArray\& }{items}}
261
262Call this to inform the model that several items have changed.
263
264This will eventually emit wxEVT\_DATAVIEW\_ITEM\_VALUE\_CHANGED
265events (in which the column fields will not be set) to the user.
266
267
268\membersection{wxDataViewModel::ItemsDeleted}\label{wxdataviewmodelitemsdeleted}
269
270\func{virtual bool}{ItemsDeleted}{\param{const wxDataViewItem\& }{parent}, \param{const wxDataViewItemArray\& }{items}}
271
272Call this to inform the model that several items have been deleted.
273
274
275\membersection{wxDataViewModel::RemoveNotifier}\label{wxdataviewmodelremovenotifier}
276
277\func{void}{RemoveNotifier}{\param{wxDataViewModelNotifier* }{notifier}}
278
279Remove the {\it notifier} from the list of notifiers.
280
281
282\membersection{wxDataViewModel::Resort}\label{wxdataviewmodelresort}
283
284\func{virtual void}{Resort}{\void}
285
286Call this to initiate a resort after the sort function has
287been changed.
288
289
290\membersection{wxDataViewModel::SetValue}\label{wxdataviewmodelsetvalue}
291
292\func{virtual bool}{SetValue}{\param{const wxVariant\& }{variant}, \param{const wxDataViewItem\& }{item}, \param{unsigned int }{col}}
293
294This gets called in order to set a value in the data model.
295The most common scenario is that the wxDataViewCtrl calls
296this method after the user changed some data in the view.
297Afterwards \helpref{ValueChanged}{wxdataviewmodelvaluechanged}
298has to be called!
299
300
301\membersection{wxDataViewModel::ValueChanged}\label{wxdataviewmodelvaluechanged}
302
303\func{virtual bool}{ValueChanged}{\param{const wxDataViewItem\& }{item}, \param{unsigned int }{col}}
304
305Call this to inform this model that a value in the model has
306been changed. This is also called from wxDataViewCtrl's
307internal editing code, e.g. when editing a text field
308in the control.
309
310This will eventually emit a wxEVT\_DATAVIEW\_ITEM\_VALUE\_CHANGED
311event to the user.
312