]> git.saurik.com Git - wxWidgets.git/blame - samples/dataview/mymodels.h
Somehow, setting a tint color makes gauge work :/.
[wxWidgets.git] / samples / dataview / mymodels.h
CommitLineData
03dfc8f5
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: mymodels.h
3// Purpose: wxDataViewCtrl wxWidgets sample
4// Author: Robert Roebling
5// Modified by: Francesco Montorsi, Bo Yang
6// Created: 06/01/06
03dfc8f5 7// Copyright: (c) Robert Roebling
526954c5 8// Licence: wxWindows licence
03dfc8f5
VZ
9/////////////////////////////////////////////////////////////////////////////
10
11
12// ----------------------------------------------------------------------------
13// MyMusicTreeModelNode: a node inside MyMusicTreeModel
14// ----------------------------------------------------------------------------
15
16class MyMusicTreeModelNode;
17WX_DEFINE_ARRAY_PTR( MyMusicTreeModelNode*, MyMusicTreeModelNodePtrArray );
18
19class MyMusicTreeModelNode
20{
21public:
22 MyMusicTreeModelNode( MyMusicTreeModelNode* parent,
ecad59d8 23 const wxString &title, const wxString &artist,
03dfc8f5
VZ
24 unsigned int year )
25 {
26 m_parent = parent;
27
28 m_title = title;
29 m_artist = artist;
30 m_year = year;
31 m_quality = "good";
ecad59d8
FM
32
33 m_container = false;
03dfc8f5
VZ
34 }
35
36 MyMusicTreeModelNode( MyMusicTreeModelNode* parent,
37 const wxString &branch )
38 {
39 m_parent = parent;
40
41 m_title = branch;
42 m_year = -1;
ecad59d8
FM
43
44 m_container = true;
03dfc8f5
VZ
45 }
46
47 ~MyMusicTreeModelNode()
48 {
49 // free all our children nodes
50 size_t count = m_children.GetCount();
51 for (size_t i = 0; i < count; i++)
52 {
53 MyMusicTreeModelNode *child = m_children[i];
54 delete child;
55 }
56 }
57
58 bool IsContainer() const
ecad59d8 59 { return m_container; }
03dfc8f5
VZ
60
61 MyMusicTreeModelNode* GetParent()
62 { return m_parent; }
63 MyMusicTreeModelNodePtrArray& GetChildren()
64 { return m_children; }
65 MyMusicTreeModelNode* GetNthChild( unsigned int n )
66 { return m_children.Item( n ); }
67 void Insert( MyMusicTreeModelNode* child, unsigned int n)
68 { m_children.Insert( child, n); }
69 void Append( MyMusicTreeModelNode* child )
70 { m_children.Add( child ); }
71 unsigned int GetChildCount() const
72 { return m_children.GetCount(); }
73
74public: // public to avoid getters/setters
75 wxString m_title;
76 wxString m_artist;
77 int m_year;
78 wxString m_quality;
79
ecad59d8
FM
80 // TODO/FIXME:
81 // the GTK version of wxDVC (in particular wxDataViewCtrlInternal::ItemAdded)
82 // needs to know in advance if a node is or _will be_ a container.
83 // Thus implementing:
84 // bool IsContainer() const
85 // { return m_children.GetCount()>0; }
86 // doesn't work with wxGTK when MyMusicTreeModel::AddToClassical is called
87 // AND the classical node was removed (a new node temporary without children
88 // would be added to the control)
89 bool m_container;
90
03dfc8f5
VZ
91private:
92 MyMusicTreeModelNode *m_parent;
93 MyMusicTreeModelNodePtrArray m_children;
94};
95
96
97// ----------------------------------------------------------------------------
98// MyMusicTreeModel
99// ----------------------------------------------------------------------------
100
101/*
102Implement this data model
103 Title Artist Year Judgement
104--------------------------------------------------------------------------
1051: My Music:
106 2: Pop music
107 3: You are not alone Michael Jackson 1995 good
108 4: Take a bow Madonna 1994 good
109 5: Classical music
110 6: Ninth Symphony Ludwig v. Beethoven 1824 good
111 7: German Requiem Johannes Brahms 1868 good
112*/
113
114class MyMusicTreeModel: public wxDataViewModel
115{
116public:
117 MyMusicTreeModel();
118 ~MyMusicTreeModel()
119 {
120 delete m_root;
121 }
122
123 // helper method for wxLog
124
125 wxString GetTitle( const wxDataViewItem &item ) const;
ecc32226 126 wxString GetArtist( const wxDataViewItem &item ) const;
03dfc8f5
VZ
127 int GetYear( const wxDataViewItem &item ) const;
128
129 // helper methods to change the model
130
ecad59d8 131 void AddToClassical( const wxString &title, const wxString &artist,
03dfc8f5
VZ
132 unsigned int year );
133 void Delete( const wxDataViewItem &item );
134
135 wxDataViewItem GetNinthItem() const
136 {
137 return wxDataViewItem( m_ninth );
138 }
139
140 // override sorting to always sort branches ascendingly
141
142 int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
a82e28dd 143 unsigned int column, bool ascending ) const;
03dfc8f5
VZ
144
145 // implementation of base class virtuals to define model
146
147 virtual unsigned int GetColumnCount() const
148 {
149 return 6;
150 }
151
152 virtual wxString GetColumnType( unsigned int col ) const
153 {
154 if (col == 2)
155 return wxT("long");
156
157 return wxT("string");
158 }
159
160 virtual void GetValue( wxVariant &variant,
161 const wxDataViewItem &item, unsigned int col ) const;
162 virtual bool SetValue( const wxVariant &variant,
163 const wxDataViewItem &item, unsigned int col );
164
98f8e666
VZ
165 virtual bool IsEnabled( const wxDataViewItem &item,
166 unsigned int col ) const;
167
03dfc8f5
VZ
168 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
169 virtual bool IsContainer( const wxDataViewItem &item ) const;
ecad59d8 170 virtual unsigned int GetChildren( const wxDataViewItem &parent,
03dfc8f5
VZ
171 wxDataViewItemArray &array ) const;
172
173private:
174 MyMusicTreeModelNode* m_root;
175
176 // pointers to some "special" nodes of the tree:
177 MyMusicTreeModelNode* m_pop;
178 MyMusicTreeModelNode* m_classical;
179 MyMusicTreeModelNode* m_ninth;
180
181 // ??
182 bool m_classicalMusicIsKnownToControl;
183};
184
185
186// ----------------------------------------------------------------------------
187// MyListModel
188// ----------------------------------------------------------------------------
189
190class MyListModel: public wxDataViewVirtualListModel
191{
192public:
2746bccf
VZ
193 enum
194 {
195 Col_EditableText,
196 Col_IconText,
197 Col_TextWithAttr,
ef6833f9 198 Col_Custom,
2746bccf
VZ
199 Col_Max
200 };
201
03dfc8f5
VZ
202 MyListModel();
203
204 // helper methods to change the model
205
206 void Prepend( const wxString &text );
207 void DeleteItem( const wxDataViewItem &item );
208 void DeleteItems( const wxDataViewItemArray &items );
209 void AddMany();
210
211
212 // implementation of base class virtuals to define model
213
214 virtual unsigned int GetColumnCount() const
215 {
2746bccf 216 return Col_Max;
03dfc8f5
VZ
217 }
218
219 virtual wxString GetColumnType( unsigned int col ) const
220 {
2746bccf 221 if (col == Col_IconText)
03dfc8f5
VZ
222 return wxT("wxDataViewIconText");
223
224 return wxT("string");
225 }
226
03dfc8f5
VZ
227 virtual void GetValueByRow( wxVariant &variant,
228 unsigned int row, unsigned int col ) const;
7fadac88
VZ
229 virtual bool GetAttrByRow( unsigned int row, unsigned int col,
230 wxDataViewItemAttr &attr ) const;
03dfc8f5
VZ
231 virtual bool SetValueByRow( const wxVariant &variant,
232 unsigned int row, unsigned int col );
233
234private:
205bdf20
VZ
235 wxArrayString m_textColValues;
236 wxArrayString m_iconColValues;
03dfc8f5 237 wxIcon m_icon[2];
03dfc8f5
VZ
238};
239
98f8e666
VZ
240// ----------------------------------------------------------------------------
241// MyListStoreDerivedModel
242// ----------------------------------------------------------------------------
243
244class MyListStoreDerivedModel : public wxDataViewListStore
245{
246public:
247 virtual bool IsEnabledByRow(unsigned int row, unsigned int col) const;
248};