Further work on wxDataViewListModel::Reset()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65538 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2010-09-13 20:02:01 +00:00
parent b95d405138
commit d8090b5e2c
5 changed files with 53 additions and 26 deletions

View File

@@ -126,8 +126,8 @@ public:
virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0; virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0;
virtual bool Cleared() = 0; virtual bool Cleared() = 0;
// this is needed for the virtual list model under GTK+ // some platforms, such as GTK+, may need a two step procedure for ::Reset()
virtual bool BeforeReset( size_t WXUNUSED(old_size), size_t WXUNUSED(new_size) ) { return true; } virtual bool BeforeReset() { return true; }
virtual bool AfterReset() { return Cleared(); } virtual bool AfterReset() { return Cleared(); }
virtual void Resort() = 0; virtual void Resort() = 0;
@@ -249,8 +249,8 @@ public:
bool ValueChanged( const wxDataViewItem &item, unsigned int col ); bool ValueChanged( const wxDataViewItem &item, unsigned int col );
bool Cleared(); bool Cleared();
// this is needed for the virtual list model under GTK+ // some platforms, such as GTK+, may need a two step procedure for ::Reset()
bool BeforeReset( size_t old_size, size_t new_size ); bool BeforeReset();
bool AfterReset(); bool AfterReset();

View File

@@ -317,13 +317,11 @@ static int my_sort( int *v1, int *v2 )
return *v1-*v2; return *v1-*v2;
} }
#define INITIAL_NUMBER_OF_ITEMS 100000 #define INITIAL_NUMBER_OF_ITEMS 10000
MyListModel::MyListModel() : MyListModel::MyListModel() :
wxDataViewVirtualListModel( INITIAL_NUMBER_OF_ITEMS ) wxDataViewVirtualListModel( INITIAL_NUMBER_OF_ITEMS )
{ {
m_virtualItems = INITIAL_NUMBER_OF_ITEMS;
// the first 100 items are really stored in this model; // the first 100 items are really stored in this model;
// all the others are synthesized on request // all the others are synthesized on request
static const unsigned NUMBER_REAL_ITEMS = 100; static const unsigned NUMBER_REAL_ITEMS = 100;
@@ -350,6 +348,7 @@ void MyListModel::Prepend( const wxString &text )
void MyListModel::DeleteItem( const wxDataViewItem &item ) void MyListModel::DeleteItem( const wxDataViewItem &item )
{ {
unsigned int row = GetRow( item ); unsigned int row = GetRow( item );
if (row >= m_textColValues.GetCount()) if (row >= m_textColValues.GetCount())
return; return;
@@ -392,8 +391,7 @@ void MyListModel::DeleteItems( const wxDataViewItemArray &items )
void MyListModel::AddMany() void MyListModel::AddMany()
{ {
m_virtualItems += 1000; Reset( GetCount()+1000 );
Reset( m_textColValues.GetCount() + m_virtualItems );
} }
void MyListModel::GetValueByRow( wxVariant &variant, void MyListModel::GetValueByRow( wxVariant &variant,

View File

@@ -222,11 +222,6 @@ public:
return wxT("string"); return wxT("string");
} }
virtual unsigned int GetRowCount()
{
return m_textColValues.GetCount();
}
virtual void GetValueByRow( wxVariant &variant, virtual void GetValueByRow( wxVariant &variant,
unsigned int row, unsigned int col ) const; unsigned int row, unsigned int col ) const;
virtual bool GetAttrByRow( unsigned int row, unsigned int col, virtual bool GetAttrByRow( unsigned int row, unsigned int col,
@@ -238,6 +233,5 @@ private:
wxArrayString m_textColValues; wxArrayString m_textColValues;
wxArrayString m_iconColValues; wxArrayString m_iconColValues;
wxIcon m_icon[2]; wxIcon m_icon[2];
int m_virtualItems;
}; };

View File

@@ -235,7 +235,7 @@ bool wxDataViewModel::Cleared()
return ret; return ret;
} }
bool wxDataViewModel::BeforeReset( size_t old_size, size_t new_size ) bool wxDataViewModel::BeforeReset()
{ {
bool ret = true; 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) for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
{ {
wxDataViewModelNotifier* notifier = *iter; wxDataViewModelNotifier* notifier = *iter;
if (!notifier->BeforeReset(old_size,new_size)) if (!notifier->BeforeReset())
ret = false; ret = false;
} }
@@ -375,6 +375,8 @@ wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
void wxDataViewIndexListModel::Reset( unsigned int new_size ) void wxDataViewIndexListModel::Reset( unsigned int new_size )
{ {
/* wxDataViewModel:: */ BeforeReset();
m_hash.Clear(); m_hash.Clear();
// IDs are ordered until an item gets deleted or inserted // 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; m_nextFreeID = new_size + 1;
/* wxDataViewModel:: */ Cleared(); /* wxDataViewModel:: */ AfterReset();
} }
void wxDataViewIndexListModel::RowPrepended() void wxDataViewIndexListModel::RowPrepended()
@@ -529,7 +531,7 @@ wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_siz
void wxDataViewVirtualListModel::Reset( unsigned int new_size ) void wxDataViewVirtualListModel::Reset( unsigned int new_size )
{ {
/* wxDataViewModel:: */ BeforeReset( m_size, new_size ); /* wxDataViewModel:: */ BeforeReset();
m_size = new_size; m_size = new_size;

View File

@@ -233,7 +233,7 @@ public:
bool ItemChanged( const wxDataViewItem &item ); bool ItemChanged( const wxDataViewItem &item );
bool ValueChanged( const wxDataViewItem &item, unsigned int col ); bool ValueChanged( const wxDataViewItem &item, unsigned int col );
bool Cleared(); bool Cleared();
bool BeforeReset(size_t old_Size,size_t new_size); bool BeforeReset();
bool AfterReset(); bool AfterReset();
void Resort(); void Resort();
@@ -258,8 +258,12 @@ public:
// item can be deleted already in the model // item can be deleted already in the model
int GetIndexOf( const wxDataViewItem &parent, const wxDataViewItem &item ); int GetIndexOf( const wxDataViewItem &parent, const wxDataViewItem &item );
virtual void OnInternalIdle();
protected: protected:
void InitTree(); void InitTree();
void ScheduleRefresh();
wxGtkTreeModelNode *FindNode( const wxDataViewItem &item ); wxGtkTreeModelNode *FindNode( const wxDataViewItem &item );
wxGtkTreeModelNode *FindNode( GtkTreeIter *iter ); wxGtkTreeModelNode *FindNode( GtkTreeIter *iter );
wxGtkTreeModelNode *FindParentNode( const wxDataViewItem &item ); wxGtkTreeModelNode *FindParentNode( const wxDataViewItem &item );
@@ -284,6 +288,8 @@ private:
wxDataObject *m_dropDataObject; wxDataObject *m_dropDataObject;
wxGtkDataViewModelNotifier *m_notifier; wxGtkDataViewModelNotifier *m_notifier;
bool m_dirty;
}; };
@@ -1487,7 +1493,7 @@ public:
virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ); virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col );
virtual bool Cleared(); virtual bool Cleared();
virtual void Resort(); virtual void Resort();
virtual bool BeforeReset(size_t old_size,size_t new_size); virtual bool BeforeReset();
virtual bool AfterReset(); virtual bool AfterReset();
void UpdateLastCount(); void UpdateLastCount();
@@ -1627,22 +1633,22 @@ bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem &item, unsig
return false; return false;
} }
bool wxGtkDataViewModelNotifier::BeforeReset(size_t WXUNUSED(old_size), size_t WXUNUSED(new_size)) bool wxGtkDataViewModelNotifier::BeforeReset()
{ {
GtkWidget *treeview = m_internal->GetOwner()->GtkGetTreeView(); GtkWidget *treeview = m_internal->GetOwner()->GtkGetTreeView();
gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), NULL ); gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), NULL );
return true; return true;
} }
bool wxGtkDataViewModelNotifier::AfterReset() bool wxGtkDataViewModelNotifier::AfterReset()
{ {
GtkWxTreeModel *wxgtk_model = m_internal->GetGtkModel();
GtkWidget *treeview = m_internal->GetOwner()->GtkGetTreeView(); GtkWidget *treeview = m_internal->GetOwner()->GtkGetTreeView();
GtkWxTreeModel *wxgtk_model = m_internal->GetGtkModel();
m_internal->Cleared();
gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(wxgtk_model) ); gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(wxgtk_model) );
m_internal->Cleared();
return true; return true;
} }
@@ -3390,6 +3396,8 @@ wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner, wxDataVie
m_dragDataObject = NULL; m_dragDataObject = NULL;
m_dropDataObject = NULL; m_dropDataObject = NULL;
m_dirty = false;
m_gtk_model = wxgtk_tree_model_new(); m_gtk_model = wxgtk_tree_model_new();
m_gtk_model->internal = this; m_gtk_model->internal = this;
@@ -3418,6 +3426,21 @@ wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
delete m_dropDataObject; 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() void wxDataViewCtrlInternal::InitTree()
{ {
wxDataViewItem item; wxDataViewItem item;
@@ -3605,6 +3628,8 @@ bool wxDataViewCtrlInternal::Cleared()
InitTree(); InitTree();
ScheduleRefresh();
return true; return true;
} }
@@ -3612,6 +3637,8 @@ void wxDataViewCtrlInternal::Resort()
{ {
if (!m_wx_model->IsVirtualListModel()) if (!m_wx_model->IsVirtualListModel())
m_root->Resort(); m_root->Resort();
ScheduleRefresh();
} }
bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) 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() ); parent_node->AddLeave( item.GetID() );
} }
ScheduleRefresh();
return true; return true;
} }
@@ -3642,6 +3671,8 @@ bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wx
parent_node->DeleteChild( item.GetID() ); parent_node->DeleteChild( item.GetID() );
} }
ScheduleRefresh();
return true; return true;
} }
@@ -4507,6 +4538,8 @@ wxDataViewItem wxDataViewCtrl::GTKPathToItem(GtkTreePath *path) const
void wxDataViewCtrl::OnInternalIdle() void wxDataViewCtrl::OnInternalIdle()
{ {
wxWindow::OnInternalIdle(); wxWindow::OnInternalIdle();
m_internal->OnInternalIdle();
unsigned int cols = GetColumnCount(); unsigned int cols = GetColumnCount();
unsigned int i; unsigned int i;