From: Robert Roebling Date: Mon, 13 Sep 2010 20:02:01 +0000 (+0000) Subject: Further work on wxDataViewListModel::Reset() X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/d8090b5e2c5d980b243674c7d99b4b4200af39d4 Further work on wxDataViewListModel::Reset() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65538 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dataview.h b/include/wx/dataview.h index b0c7fde7af..0daadfc7ed 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -126,8 +126,8 @@ public: virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0; virtual bool Cleared() = 0; - // this is needed for the virtual list model under GTK+ - virtual bool BeforeReset( size_t WXUNUSED(old_size), size_t WXUNUSED(new_size) ) { return true; } + // some platforms, such as GTK+, may need a two step procedure for ::Reset() + virtual bool BeforeReset() { return true; } virtual bool AfterReset() { return Cleared(); } virtual void Resort() = 0; @@ -249,8 +249,8 @@ public: bool ValueChanged( const wxDataViewItem &item, unsigned int col ); bool Cleared(); - // this is needed for the virtual list model under GTK+ - bool BeforeReset( size_t old_size, size_t new_size ); + // some platforms, such as GTK+, may need a two step procedure for ::Reset() + bool BeforeReset(); bool AfterReset(); diff --git a/samples/dataview/mymodels.cpp b/samples/dataview/mymodels.cpp index ec5be5516e..8ea635899a 100644 --- a/samples/dataview/mymodels.cpp +++ b/samples/dataview/mymodels.cpp @@ -317,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; @@ -350,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; @@ -392,8 +391,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, diff --git a/samples/dataview/mymodels.h b/samples/dataview/mymodels.h index 0655a674e6..bb9ca8f653 100644 --- a/samples/dataview/mymodels.h +++ b/samples/dataview/mymodels.h @@ -222,11 +222,6 @@ public: return wxT("string"); } - virtual unsigned int GetRowCount() - { - return m_textColValues.GetCount(); - } - virtual void GetValueByRow( wxVariant &variant, unsigned int row, unsigned int col ) const; virtual bool GetAttrByRow( unsigned int row, unsigned int col, @@ -238,6 +233,5 @@ private: wxArrayString m_textColValues; wxArrayString m_iconColValues; wxIcon m_icon[2]; - int m_virtualItems; }; diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index a66701b634..6c9423bc38 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -235,7 +235,7 @@ bool wxDataViewModel::Cleared() return ret; } -bool wxDataViewModel::BeforeReset( size_t old_size, size_t new_size ) +bool wxDataViewModel::BeforeReset() { bool ret = true; @@ -243,7 +243,7 @@ bool wxDataViewModel::BeforeReset( size_t old_size, size_t new_size ) for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) { wxDataViewModelNotifier* notifier = *iter; - if (!notifier->BeforeReset(old_size,new_size)) + if (!notifier->BeforeReset()) ret = false; } @@ -375,6 +375,8 @@ wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size ) void wxDataViewIndexListModel::Reset( unsigned int new_size ) { + /* wxDataViewModel:: */ BeforeReset(); + m_hash.Clear(); // IDs are ordered until an item gets deleted or inserted @@ -387,7 +389,7 @@ void wxDataViewIndexListModel::Reset( unsigned int new_size ) m_nextFreeID = new_size + 1; - /* wxDataViewModel:: */ Cleared(); + /* wxDataViewModel:: */ AfterReset(); } void wxDataViewIndexListModel::RowPrepended() @@ -529,7 +531,7 @@ wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_siz void wxDataViewVirtualListModel::Reset( unsigned int new_size ) { - /* wxDataViewModel:: */ BeforeReset( m_size, new_size ); + /* wxDataViewModel:: */ BeforeReset(); m_size = new_size; diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index a52da38744..0ef9a32f22 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -233,7 +233,7 @@ public: bool ItemChanged( const wxDataViewItem &item ); bool ValueChanged( const wxDataViewItem &item, unsigned int col ); bool Cleared(); - bool BeforeReset(size_t old_Size,size_t new_size); + bool BeforeReset(); bool AfterReset(); void Resort(); @@ -258,8 +258,12 @@ public: // item can be deleted already in the model int GetIndexOf( const wxDataViewItem &parent, const wxDataViewItem &item ); + virtual void OnInternalIdle(); + protected: void InitTree(); + void ScheduleRefresh(); + wxGtkTreeModelNode *FindNode( const wxDataViewItem &item ); wxGtkTreeModelNode *FindNode( GtkTreeIter *iter ); wxGtkTreeModelNode *FindParentNode( const wxDataViewItem &item ); @@ -284,6 +288,8 @@ private: wxDataObject *m_dropDataObject; wxGtkDataViewModelNotifier *m_notifier; + + bool m_dirty; }; @@ -1487,7 +1493,7 @@ public: virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ); virtual bool Cleared(); virtual void Resort(); - virtual bool BeforeReset(size_t old_size,size_t new_size); + virtual bool BeforeReset(); virtual bool AfterReset(); void UpdateLastCount(); @@ -1627,23 +1633,23 @@ bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem &item, unsig return false; } -bool wxGtkDataViewModelNotifier::BeforeReset(size_t WXUNUSED(old_size), size_t WXUNUSED(new_size)) +bool wxGtkDataViewModelNotifier::BeforeReset() { GtkWidget *treeview = m_internal->GetOwner()->GtkGetTreeView(); gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), NULL ); - + return true; } bool wxGtkDataViewModelNotifier::AfterReset() { - GtkWxTreeModel *wxgtk_model = m_internal->GetGtkModel(); GtkWidget *treeview = m_internal->GetOwner()->GtkGetTreeView(); + GtkWxTreeModel *wxgtk_model = m_internal->GetGtkModel(); - gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(wxgtk_model) ); - m_internal->Cleared(); + gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(wxgtk_model) ); + return true; } @@ -3390,6 +3396,8 @@ wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner, wxDataVie m_dragDataObject = NULL; m_dropDataObject = NULL; + m_dirty = false; + m_gtk_model = wxgtk_tree_model_new(); m_gtk_model->internal = this; @@ -3418,6 +3426,21 @@ wxDataViewCtrlInternal::~wxDataViewCtrlInternal() delete m_dropDataObject; } +void wxDataViewCtrlInternal::ScheduleRefresh() +{ + m_dirty = true; +} + +void wxDataViewCtrlInternal::OnInternalIdle() +{ + if (m_dirty) + { + GtkWidget *widget = m_owner->GtkGetTreeView(); + gtk_widget_queue_draw( widget ); + m_dirty = false; + } +} + void wxDataViewCtrlInternal::InitTree() { wxDataViewItem item; @@ -3605,6 +3628,8 @@ bool wxDataViewCtrlInternal::Cleared() InitTree(); + ScheduleRefresh(); + return true; } @@ -3612,6 +3637,8 @@ void wxDataViewCtrlInternal::Resort() { if (!m_wx_model->IsVirtualListModel()) m_root->Resort(); + + ScheduleRefresh(); } bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) @@ -3628,6 +3655,8 @@ bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDa parent_node->AddLeave( item.GetID() ); } + ScheduleRefresh(); + return true; } @@ -3642,6 +3671,8 @@ bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wx parent_node->DeleteChild( item.GetID() ); } + ScheduleRefresh(); + return true; } @@ -4507,6 +4538,8 @@ wxDataViewItem wxDataViewCtrl::GTKPathToItem(GtkTreePath *path) const void wxDataViewCtrl::OnInternalIdle() { wxWindow::OnInternalIdle(); + + m_internal->OnInternalIdle(); unsigned int cols = GetColumnCount(); unsigned int i;