Added wxDataViewListIndexModel::Reset(), clarified and corrected wxDataViewModel::Cleared(), corrected sample
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -73,6 +73,16 @@ Returns the position of given {\it item}.
|
|||||||
|
|
||||||
Override this to allow getting values from the model.
|
Override this to allow getting values from the model.
|
||||||
|
|
||||||
|
|
||||||
|
\membersection{wxDataViewIndexListModel::Reset}\label{wxdataviewindexlistmodelreset}
|
||||||
|
|
||||||
|
\func{void}{Reset}{\param{unsigned int }{new\_size}}
|
||||||
|
|
||||||
|
Call this after if the data has to be read again from
|
||||||
|
the model. This is useful after major changes when
|
||||||
|
calling the methods below (possibly thousands of times)
|
||||||
|
doesn't make sense.
|
||||||
|
|
||||||
\membersection{wxDataViewIndexListModel::RowAppended}\label{wxdataviewindexlistmodelrowappended}
|
\membersection{wxDataViewIndexListModel::RowAppended}\label{wxdataviewindexlistmodelrowappended}
|
||||||
|
|
||||||
\func{void}{RowAppended}{\void}
|
\func{void}{RowAppended}{\void}
|
||||||
|
@@ -124,7 +124,8 @@ to the model.
|
|||||||
|
|
||||||
\func{virtual bool}{Cleared}{\void}
|
\func{virtual bool}{Cleared}{\void}
|
||||||
|
|
||||||
Called to inform the model that all data has been deleted.
|
Called to inform the model that all data has been cleared. The
|
||||||
|
control will reread the data from the model again.
|
||||||
|
|
||||||
|
|
||||||
\membersection{wxDataViewModel::Compare}\label{wxdataviewmodelcompare}
|
\membersection{wxDataViewModel::Compare}\label{wxdataviewmodelcompare}
|
||||||
|
@@ -248,6 +248,7 @@ public:
|
|||||||
void RowsDeleted( const wxArrayInt &rows );
|
void RowsDeleted( const wxArrayInt &rows );
|
||||||
void RowChanged( unsigned int row );
|
void RowChanged( unsigned int row );
|
||||||
void RowValueChanged( unsigned int row, unsigned int col );
|
void RowValueChanged( unsigned int row, unsigned int col );
|
||||||
|
void Reset( unsigned int new_size );
|
||||||
|
|
||||||
// convert to/from row/wxDataViewItem
|
// convert to/from row/wxDataViewItem
|
||||||
|
|
||||||
|
@@ -417,6 +417,8 @@ private:
|
|||||||
friend class wxDataViewCtrlDCImpl;
|
friend class wxDataViewCtrlDCImpl;
|
||||||
friend class wxDataViewColumn;
|
friend class wxDataViewColumn;
|
||||||
friend class wxGtkDataViewModelNotifier;
|
friend class wxGtkDataViewModelNotifier;
|
||||||
|
friend class wxDataViewCtrlInternal;
|
||||||
|
|
||||||
GtkWidget *m_treeview;
|
GtkWidget *m_treeview;
|
||||||
wxDataViewModelNotifier *m_notifier;
|
wxDataViewModelNotifier *m_notifier;
|
||||||
wxDataViewCtrlInternal *m_internal;
|
wxDataViewCtrlInternal *m_internal;
|
||||||
|
@@ -369,16 +369,22 @@ class MyListModel: public wxDataViewIndexListModel
|
|||||||
public:
|
public:
|
||||||
MyListModel() :
|
MyListModel() :
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
wxDataViewIndexListModel( 1000 )
|
wxDataViewIndexListModel( 1000 + 100 )
|
||||||
#else
|
#else
|
||||||
wxDataViewIndexListModel( 100000 )
|
wxDataViewIndexListModel( 100000 + 100 )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
#ifdef __WXMAC__
|
||||||
|
m_virtualItems = 1000;
|
||||||
|
#else
|
||||||
|
m_virtualItems = 100000;
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
for (i = 0; i < 100; i++)
|
for (i = 0; i < 100; i++)
|
||||||
{
|
{
|
||||||
wxString str;
|
wxString str;
|
||||||
str.Printf( "row number %d", i );
|
str.Printf( "Test %d", i );
|
||||||
m_array.Add( str );
|
m_array.Add( str );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,6 +402,9 @@ public:
|
|||||||
void DeleteItem( const wxDataViewItem &item )
|
void DeleteItem( const wxDataViewItem &item )
|
||||||
{
|
{
|
||||||
unsigned int row = GetRow( item );
|
unsigned int row = GetRow( item );
|
||||||
|
if (row >= m_array.GetCount())
|
||||||
|
return;
|
||||||
|
|
||||||
m_array.RemoveAt( row );
|
m_array.RemoveAt( row );
|
||||||
RowDeleted( row );
|
RowDeleted( row );
|
||||||
}
|
}
|
||||||
@@ -407,7 +416,8 @@ public:
|
|||||||
for (i = 0; i < items.GetCount(); i++)
|
for (i = 0; i < items.GetCount(); i++)
|
||||||
{
|
{
|
||||||
unsigned int row = GetRow( items[i] );
|
unsigned int row = GetRow( items[i] );
|
||||||
rows.Add( row );
|
if (row < m_array.GetCount())
|
||||||
|
rows.Add( row );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort in descending order so that the last
|
// Sort in descending order so that the last
|
||||||
@@ -426,6 +436,8 @@ public:
|
|||||||
|
|
||||||
void AddMany()
|
void AddMany()
|
||||||
{
|
{
|
||||||
|
m_virtualItems += 1000;
|
||||||
|
Reset( m_array.GetCount() + m_virtualItems );
|
||||||
}
|
}
|
||||||
|
|
||||||
// implementation of base class virtuals to define model
|
// implementation of base class virtuals to define model
|
||||||
@@ -443,11 +455,6 @@ public:
|
|||||||
return "string";
|
return "string";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual unsigned int GetRowCount()
|
|
||||||
{
|
|
||||||
return m_array.GetCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void GetValue( wxVariant &variant,
|
virtual void GetValue( wxVariant &variant,
|
||||||
unsigned int row, unsigned int col ) const
|
unsigned int row, unsigned int col ) const
|
||||||
{
|
{
|
||||||
@@ -456,7 +463,7 @@ public:
|
|||||||
if (row >= m_array.GetCount())
|
if (row >= m_array.GetCount())
|
||||||
{
|
{
|
||||||
wxString str;
|
wxString str;
|
||||||
str.Printf( "row %d", row );
|
str.Printf( "row %d", row - m_array.GetCount() );
|
||||||
variant = str;
|
variant = str;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -471,10 +478,10 @@ public:
|
|||||||
} else
|
} else
|
||||||
if (col==2)
|
if (col==2)
|
||||||
{
|
{
|
||||||
if ((row % 2) == 1)
|
if (row >= m_array.GetCount())
|
||||||
variant = "Blue";
|
variant = "plain";
|
||||||
else
|
else
|
||||||
variant = "Italic";
|
variant = "blue italic";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,10 +490,11 @@ public:
|
|||||||
if (col != 2)
|
if (col != 2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((row % 2) == 1)
|
if (row < m_array.GetCount())
|
||||||
|
{
|
||||||
attr.SetColour( *wxBLUE );
|
attr.SetColour( *wxBLUE );
|
||||||
else
|
|
||||||
attr.SetItalic( true );
|
attr.SetItalic( true );
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -508,6 +516,7 @@ public:
|
|||||||
|
|
||||||
wxArrayString m_array;
|
wxArrayString m_array;
|
||||||
wxIcon m_icon;
|
wxIcon m_icon;
|
||||||
|
int m_virtualItems;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
|
@@ -326,6 +326,29 @@ wxDataViewIndexListModel::~wxDataViewIndexListModel()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxDataViewIndexListModel::Reset( unsigned int new_size )
|
||||||
|
{
|
||||||
|
if (m_useHash)
|
||||||
|
{
|
||||||
|
m_hash.Clear();
|
||||||
|
|
||||||
|
// IDs are ordered until an item gets deleted or inserted
|
||||||
|
m_ordered = true;
|
||||||
|
|
||||||
|
// build initial index
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 1; i < new_size+1; i++)
|
||||||
|
m_hash.Add( (void*) i );
|
||||||
|
m_lastIndex = new_size + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_lastIndex = new_size-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDataViewModel::Cleared();
|
||||||
|
}
|
||||||
|
|
||||||
void wxDataViewIndexListModel::RowPrepended()
|
void wxDataViewIndexListModel::RowPrepended()
|
||||||
{
|
{
|
||||||
if (m_useHash)
|
if (m_useHash)
|
||||||
@@ -549,7 +572,7 @@ unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
children = m_hash;
|
children = m_hash;
|
||||||
|
|
||||||
return m_hash.GetCount();
|
return m_hash.GetCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2206,9 +2206,11 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
|
|||||||
|
|
||||||
bool wxDataViewMainWindow::Cleared()
|
bool wxDataViewMainWindow::Cleared()
|
||||||
{
|
{
|
||||||
SortPrepare();
|
|
||||||
|
|
||||||
DestroyTree();
|
DestroyTree();
|
||||||
|
|
||||||
|
SortPrepare();
|
||||||
|
BuildTree( GetOwner()->GetModel() );
|
||||||
|
|
||||||
UpdateDisplay();
|
UpdateDisplay();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -525,9 +525,13 @@ wxgtk_tree_model_iter_next (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
|
GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model;
|
||||||
|
|
||||||
|
if (wxtree_model->stamp != iter->stamp)
|
||||||
|
wxPrintf( "crash\n" );
|
||||||
|
|
||||||
g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
|
g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), FALSE);
|
||||||
g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE);
|
g_return_val_if_fail (wxtree_model->stamp == iter->stamp, FALSE);
|
||||||
|
|
||||||
return wxtree_model->internal->iter_next( iter );
|
return wxtree_model->internal->iter_next( iter );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1062,6 +1066,9 @@ public:
|
|||||||
virtual bool Cleared();
|
virtual bool Cleared();
|
||||||
virtual void Resort();
|
virtual void Resort();
|
||||||
|
|
||||||
|
void SetGtkModel( GtkWxTreeModel *model ) { m_wxgtk_model = model; }
|
||||||
|
|
||||||
|
private:
|
||||||
GtkWxTreeModel *m_wxgtk_model;
|
GtkWxTreeModel *m_wxgtk_model;
|
||||||
wxDataViewModel *m_wx_model;
|
wxDataViewModel *m_wx_model;
|
||||||
wxDataViewCtrl *m_owner;
|
wxDataViewCtrl *m_owner;
|
||||||
@@ -1184,10 +1191,15 @@ bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem &item, unsig
|
|||||||
|
|
||||||
bool wxGtkDataViewModelNotifier::Cleared()
|
bool wxGtkDataViewModelNotifier::Cleared()
|
||||||
{
|
{
|
||||||
// TODO: delete everything
|
gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->m_treeview), NULL );
|
||||||
|
|
||||||
|
// this will create a new GTK model
|
||||||
m_owner->GtkGetInternal()->Cleared();
|
m_owner->GtkGetInternal()->Cleared();
|
||||||
|
|
||||||
|
SetGtkModel( m_owner->GtkGetInternal()->GetGtkModel() );
|
||||||
|
|
||||||
|
gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->m_treeview), GTK_TREE_MODEL(m_wxgtk_model) );
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2610,6 +2622,22 @@ void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode *node )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxDataViewCtrlInternal::Cleared()
|
||||||
|
{
|
||||||
|
if (m_root)
|
||||||
|
{
|
||||||
|
delete m_root;
|
||||||
|
InitTree();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new GTK model
|
||||||
|
g_object_unref( m_gtk_model );
|
||||||
|
m_gtk_model = wxgtk_tree_model_new();
|
||||||
|
m_gtk_model->internal = this;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void wxDataViewCtrlInternal::Resort()
|
void wxDataViewCtrlInternal::Resort()
|
||||||
{
|
{
|
||||||
if (!m_wx_model->IsIndexListModel())
|
if (!m_wx_model->IsIndexListModel())
|
||||||
@@ -2665,11 +2693,6 @@ bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataViewCtrlInternal::Cleared()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
GtkTreeModelFlags wxDataViewCtrlInternal::get_flags()
|
GtkTreeModelFlags wxDataViewCtrlInternal::get_flags()
|
||||||
{
|
{
|
||||||
if (m_wx_model->IsIndexListModel())
|
if (m_wx_model->IsIndexListModel())
|
||||||
@@ -3332,6 +3355,7 @@ wxDataViewCtrl::~wxDataViewCtrl()
|
|||||||
void wxDataViewCtrl::Init()
|
void wxDataViewCtrl::Init()
|
||||||
{
|
{
|
||||||
m_notifier = NULL;
|
m_notifier = NULL;
|
||||||
|
m_internal = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
|
bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
|
||||||
@@ -3441,6 +3465,15 @@ void wxDataViewCtrl::OnInternalIdle()
|
|||||||
|
|
||||||
bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model )
|
bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model )
|
||||||
{
|
{
|
||||||
|
if (GetModel())
|
||||||
|
{
|
||||||
|
delete m_internal;
|
||||||
|
m_internal = NULL;
|
||||||
|
|
||||||
|
delete m_notifier;
|
||||||
|
m_notifier = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!wxDataViewCtrlBase::AssociateModel( model ))
|
if (!wxDataViewCtrlBase::AssociateModel( model ))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@@ -367,7 +367,12 @@ public:
|
|||||||
|
|
||||||
virtual bool Cleared(void)
|
virtual bool Cleared(void)
|
||||||
{
|
{
|
||||||
return (this->m_dataViewControlPtr->RemoveItems() == noErr);
|
bool noFailureFlag = (this->m_dataViewControlPtr->RemoveItems() == noErr);
|
||||||
|
wxDataViewItem item;
|
||||||
|
wxDataViewItemArray array;
|
||||||
|
GetOwner()->GetChildren( item, array );
|
||||||
|
ItemsAdded( item, array );
|
||||||
|
return noFailureFlag;
|
||||||
} /* Cleared(void) */
|
} /* Cleared(void) */
|
||||||
|
|
||||||
virtual void Resort(void)
|
virtual void Resort(void)
|
||||||
|
Reference in New Issue
Block a user