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