X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2746bccf233379382f2017ef35d2dfcc114b70cb..f155075229d771430f0793700f5048ad4be00e9d:/samples/dataview/mymodels.cpp?ds=inline diff --git a/samples/dataview/mymodels.cpp b/samples/dataview/mymodels.cpp index c3bf1ff87a..a3cb111198 100644 --- a/samples/dataview/mymodels.cpp +++ b/samples/dataview/mymodels.cpp @@ -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: @@ -249,6 +244,17 @@ bool MyMusicTreeModel::SetValue( const wxVariant &variant, return false; } +bool MyMusicTreeModel::IsEnabled( const wxDataViewItem &item, + unsigned int col ) const +{ + wxASSERT(item.IsOk()); + + MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) item.GetID(); + + // disable Beethoven's ratings, his pieces can only be good + return !(col == 3 && node->m_artist.EndsWith("Beethoven")); +} + wxDataViewItem MyMusicTreeModel::GetParent( const wxDataViewItem &item ) const { // the invisible root node has no parent @@ -322,13 +328,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 +359,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,8 +402,7 @@ 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, @@ -436,6 +440,10 @@ void MyListModel::GetValueByRow( wxVariant &variant, } break; + case Col_Custom: + variant = wxString::Format("%d", row % 100); + break; + case Col_Max: wxFAIL_MSG( "invalid column" ); } @@ -456,7 +464,8 @@ bool MyListModel::GetAttrByRow( unsigned int row, unsigned int col, break; case Col_TextWithAttr: - // do what the labels defined above hint at + case Col_Custom: + // do what the labels defined in GetValueByRow() hint at switch ( row % 5 ) { case 0: @@ -517,6 +526,7 @@ bool MyListModel::SetValueByRow( const wxVariant &variant, return true; case Col_TextWithAttr: + case Col_Custom: wxLogError("Cannot edit the column %d", col); break; @@ -526,3 +536,14 @@ bool MyListModel::SetValueByRow( const wxVariant &variant, return false; } + + +// ---------------------------------------------------------------------------- +// MyListStoreDerivedModel +// ---------------------------------------------------------------------------- + +bool MyListStoreDerivedModel::IsEnabledByRow(unsigned int row, unsigned int col) const +{ + // disabled the last two checkboxes + return !(col == 0 && 8 <= row && row <= 9); +}