]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/dataview/mymodels.cpp
Remove unnecessary tests for m_log from dataview sample.
[wxWidgets.git] / samples / dataview / mymodels.cpp
index 3c2f7f4f6451a4279282e765ee6dfdb47616d060..79fc7170bbef77c8741f8740862cc2c56ee33408 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     06/01/06
 // RCS-ID:      $Id$
 // Copyright:   (c) Robert Roebling
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 
@@ -203,18 +203,13 @@ void MyMusicTreeModel::GetValue( wxVariant &variant,
         variant = node->m_quality;
         break;
     case 4:
-        // wxMac doesn't conceal the popularity progress renderer, return 0 for containers
-        if (IsContainer(item))
-            variant = (long) 0;
-        else
-            variant = (long) 80;  // all music is very 80% popular
+        variant = 80L;  // all music is very 80% popular
         break;
     case 5:
-        // Make size of red square depend on year
         if (GetYear(item) < 1900)
-            variant = (long) 35;
+            variant = "old";
         else
-            variant = (long) 25;
+            variant = "new";
         break;
 
     default:
@@ -322,13 +317,11 @@ static int my_sort( int *v1, int *v2 )
    return *v1-*v2;
 }
 
-#define INITIAL_NUMBER_OF_ITEMS 100000
+#define INITIAL_NUMBER_OF_ITEMS 10000
 
 MyListModel::MyListModel() :
         wxDataViewVirtualListModel( INITIAL_NUMBER_OF_ITEMS )
 {
-    m_virtualItems = INITIAL_NUMBER_OF_ITEMS;
-
     // the first 100 items are really stored in this model;
     // all the others are synthesized on request
     static const unsigned NUMBER_REAL_ITEMS = 100;
@@ -355,6 +348,7 @@ void MyListModel::Prepend( const wxString &text )
 void MyListModel::DeleteItem( const wxDataViewItem &item )
 {
     unsigned int row = GetRow( item );
+
     if (row >= m_textColValues.GetCount())
         return;
 
@@ -397,38 +391,50 @@ void MyListModel::DeleteItems( const wxDataViewItemArray &items )
 
 void MyListModel::AddMany()
 {
-    m_virtualItems += 1000;
-    Reset( m_textColValues.GetCount() + m_virtualItems );
+    Reset( GetCount()+1000 );
 }
 
 void MyListModel::GetValueByRow( wxVariant &variant,
                                  unsigned int row, unsigned int col ) const
 {
-    if (col==0)
-    {
-        if (row >= m_textColValues.GetCount())
-            variant = wxString::Format( "virtual row %d", row );
-        else
-            variant = m_textColValues[ row ];
-    }
-    else if (col==1)
+    switch ( col )
     {
-        wxString text;
-        if ( row >= m_iconColValues.GetCount() )
-            text = "virtual icon";
-        else
-            text = m_iconColValues[row];
+        case Col_EditableText:
+            if (row >= m_textColValues.GetCount())
+                variant = wxString::Format( "virtual row %d", row );
+            else
+                variant = m_textColValues[ row ];
+            break;
 
-        variant << wxDataViewIconText(text, m_icon[row % 2]);
-    }
-    else if (col==2)
-    {
-        static const char *labels[5] =
-        {
-            "blue", "green", "red", "bold cyan", "default",
-        };
+        case Col_IconText:
+            {
+                wxString text;
+                if ( row >= m_iconColValues.GetCount() )
+                    text = "virtual icon";
+                else
+                    text = m_iconColValues[row];
 
-        variant = labels[row % 5];
+                variant << wxDataViewIconText(text, m_icon[row % 2]);
+            }
+            break;
+
+        case Col_TextWithAttr:
+            {
+                static const char *labels[5] =
+                {
+                    "blue", "green", "red", "bold cyan", "default",
+                };
+
+                variant = labels[row % 5];
+            }
+            break;
+
+        case Col_Custom:
+            variant = wxString::Format("%d", row % 100);
+            break;
+
+        case Col_Max:
+            wxFAIL_MSG( "invalid column" );
     }
 }
 
@@ -437,17 +443,18 @@ bool MyListModel::GetAttrByRow( unsigned int row, unsigned int col,
 {
     switch ( col )
     {
-        case 0:
+        case Col_EditableText:
             return false;
 
-        case 1:
+        case Col_IconText:
             if ( !(row % 2) )
                 return false;
             attr.SetColour(*wxLIGHT_GREY);
             break;
 
-        case 2:
-            // do what the labels defined above hint at
+        case Col_TextWithAttr:
+        case Col_Custom:
+            // do what the labels defined in GetValueByRow() hint at
             switch ( row % 5 )
             {
                 case 0:
@@ -471,6 +478,9 @@ bool MyListModel::GetAttrByRow( unsigned int row, unsigned int col,
                     return false;
             }
             break;
+
+        case Col_Max:
+            wxFAIL_MSG( "invalid column" );
     }
 
     return true;
@@ -481,8 +491,8 @@ bool MyListModel::SetValueByRow( const wxVariant &variant,
 {
     switch ( col )
     {
-        case 0:
-        case 1:
+        case Col_EditableText:
+        case Col_IconText:
             if (row >= m_textColValues.GetCount())
             {
                 // the item is not in the range of the items
@@ -492,22 +502,26 @@ bool MyListModel::SetValueByRow( const wxVariant &variant,
                 return false;
             }
 
-            if ( col == 0 )
+            if ( col == Col_EditableText )
             {
                 m_textColValues[row] = variant.GetString();
             }
-            else // col == 1
+            else // col == Col_IconText
             {
                 wxDataViewIconText iconText;
                 iconText << variant;
                 m_iconColValues[row] = iconText.GetText();
             }
-            break;
+            return true;
 
-        default:
+        case Col_TextWithAttr:
+        case Col_Custom:
             wxLogError("Cannot edit the column %d", col);
-            return false;
+            break;
+
+        case Col_Max:
+            wxFAIL_MSG( "invalid column" );
     }
 
-    return true;
+    return false;
 }