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