X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/14f73cf1da50ab12a151570b7a1731aa0fd383c6..81c3f0fce3cde0149d583f4d970532460e20e94a:/samples/dataview/mymodels.h diff --git a/samples/dataview/mymodels.h b/samples/dataview/mymodels.h index 2591c86e71..c55e8b2184 100644 --- a/samples/dataview/mymodels.h +++ b/samples/dataview/mymodels.h @@ -11,80 +11,92 @@ // ---------------------------------------------------------------------------- -// MyMusicTreeModel +// MyMusicTreeModelNode: a node inside MyMusicTreeModel // ---------------------------------------------------------------------------- -/* -Implement this data model - Title Artist Year Judgement --------------------------------------------------------------------------- -1: My Music: - 2: Pop music - 3: You are not alone Michael Jackson 1995 good - 4: Take a bow Madonna 1994 good - 5: Classical music - 6: Ninth Symphony Ludwig v. Beethoven 1824 good - 7: German Requiem Johannes Brahms 1868 good -*/ - class MyMusicTreeModelNode; -WX_DEFINE_ARRAY_PTR( MyMusicTreeModelNode*, MyMusicTreeModelNodes ); +WX_DEFINE_ARRAY_PTR( MyMusicTreeModelNode*, MyMusicTreeModelNodePtrArray ); class MyMusicTreeModelNode { public: MyMusicTreeModelNode( MyMusicTreeModelNode* parent, - const wxString &title, const wxString &artist, int year ) + const wxString &title, const wxString &artist, + unsigned int year ) { m_parent = parent; + m_title = title; m_artist = artist; m_year = year; m_quality = "good"; - m_isContainer = false; } MyMusicTreeModelNode( MyMusicTreeModelNode* parent, - const wxString &branch ) + const wxString &branch ) { m_parent = parent; + m_title = branch; m_year = -1; - m_isContainer = true; } ~MyMusicTreeModelNode() { + // free all our children nodes size_t count = m_children.GetCount(); - size_t i; - for (i = 0; i < count; i++) + for (size_t i = 0; i < count; i++) { MyMusicTreeModelNode *child = m_children[i]; delete child; } } - bool IsContainer() { return m_isContainer; } - - MyMusicTreeModelNode* GetParent() { return m_parent; } - MyMusicTreeModelNodes &GetChildren() { return m_children; } - MyMusicTreeModelNode* GetNthChild( unsigned int n ) { return m_children.Item( n ); } - void Insert( MyMusicTreeModelNode* child, unsigned int n) { m_children.Insert( child, n); } - void Append( MyMusicTreeModelNode* child ) { m_children.Add( child ); } - unsigned int GetChildCount() { return m_children.GetCount(); } - -public: - wxString m_title; - wxString m_artist; - int m_year; - wxString m_quality; + bool IsContainer() const + { return m_children.GetCount()>0; } + + MyMusicTreeModelNode* GetParent() + { return m_parent; } + MyMusicTreeModelNodePtrArray& GetChildren() + { return m_children; } + MyMusicTreeModelNode* GetNthChild( unsigned int n ) + { return m_children.Item( n ); } + void Insert( MyMusicTreeModelNode* child, unsigned int n) + { m_children.Insert( child, n); } + void Append( MyMusicTreeModelNode* child ) + { m_children.Add( child ); } + unsigned int GetChildCount() const + { return m_children.GetCount(); } + +public: // public to avoid getters/setters + wxString m_title; + wxString m_artist; + int m_year; + wxString m_quality; private: - MyMusicTreeModelNode *m_parent; - MyMusicTreeModelNodes m_children; - bool m_isContainer; + MyMusicTreeModelNode *m_parent; + MyMusicTreeModelNodePtrArray m_children; }; + +// ---------------------------------------------------------------------------- +// MyMusicTreeModel +// ---------------------------------------------------------------------------- + +/* +Implement this data model + Title Artist Year Judgement +-------------------------------------------------------------------------- +1: My Music: + 2: Pop music + 3: You are not alone Michael Jackson 1995 good + 4: Take a bow Madonna 1994 good + 5: Classical music + 6: Ninth Symphony Ludwig v. Beethoven 1824 good + 7: German Requiem Johannes Brahms 1868 good +*/ + class MyMusicTreeModel: public wxDataViewModel { public: @@ -101,9 +113,15 @@ public: // helper methods to change the model - void AddToClassical( const wxString &title, const wxString &artist, int year ); + void AddToClassical( const wxString &title, const wxString &artist, + unsigned int year ); void Delete( const wxDataViewItem &item ); + wxDataViewItem GetNinthItem() const + { + return wxDataViewItem( m_ninth ); + } + // override sorting to always sort branches ascendingly int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, @@ -134,16 +152,15 @@ public: virtual unsigned int GetChildren( const wxDataViewItem &parent, wxDataViewItemArray &array ) const; - wxDataViewItem GetNinthItem() const - { - return wxDataViewItem( m_ninth ); - } - private: MyMusicTreeModelNode* m_root; + + // pointers to some "special" nodes of the tree: MyMusicTreeModelNode* m_pop; MyMusicTreeModelNode* m_classical; MyMusicTreeModelNode* m_ninth; + + // ?? bool m_classicalMusicIsKnownToControl; }; @@ -193,7 +210,7 @@ public: private: wxArrayString m_array; - wxIcon m_icon; + wxIcon m_icon[2]; int m_virtualItems; };