Many more corrections and clarifications to virtual index list model use
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61078 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -274,11 +274,11 @@ public:
|
|||||||
|
|
||||||
// internal
|
// internal
|
||||||
virtual bool IsVirtualListModel() const { return false; }
|
virtual bool IsVirtualListModel() const { return false; }
|
||||||
unsigned int GetLastIndex() const { return m_lastIndex; }
|
unsigned int GetCount() const { return m_hash.GetCount(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxDataViewItemArray m_hash;
|
wxDataViewItemArray m_hash;
|
||||||
unsigned int m_lastIndex;
|
unsigned int m_nextFreeID;
|
||||||
bool m_ordered;
|
bool m_ordered;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -339,11 +339,10 @@ public:
|
|||||||
|
|
||||||
// internal
|
// internal
|
||||||
virtual bool IsVirtualListModel() const { return true; }
|
virtual bool IsVirtualListModel() const { return true; }
|
||||||
unsigned int GetLastIndex() const { return m_lastIndex; }
|
unsigned int GetCount() const { return m_size; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxDataViewItemArray m_hash;
|
unsigned int m_size;
|
||||||
unsigned int m_lastIndex;
|
|
||||||
bool m_ordered;
|
bool m_ordered;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@@ -309,7 +309,7 @@ wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
for (i = 1; i < initial_size+1; i++)
|
for (i = 1; i < initial_size+1; i++)
|
||||||
m_hash.Add( wxUIntToPtr(i) );
|
m_hash.Add( wxUIntToPtr(i) );
|
||||||
m_lastIndex = initial_size + 1;
|
m_nextFreeID = initial_size + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataViewIndexListModel::~wxDataViewIndexListModel()
|
wxDataViewIndexListModel::~wxDataViewIndexListModel()
|
||||||
@@ -327,7 +327,8 @@ void wxDataViewIndexListModel::Reset( unsigned int new_size )
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
for (i = 1; i < new_size+1; i++)
|
for (i = 1; i < new_size+1; i++)
|
||||||
m_hash.Add( wxUIntToPtr(i) );
|
m_hash.Add( wxUIntToPtr(i) );
|
||||||
m_lastIndex = new_size + 1;
|
|
||||||
|
m_nextFreeID = new_size + 1;
|
||||||
|
|
||||||
wxDataViewModel::Cleared();
|
wxDataViewModel::Cleared();
|
||||||
}
|
}
|
||||||
@@ -336,17 +337,22 @@ void wxDataViewIndexListModel::RowPrepended()
|
|||||||
{
|
{
|
||||||
m_ordered = false;
|
m_ordered = false;
|
||||||
|
|
||||||
unsigned int id = m_lastIndex++;
|
unsigned int id = m_nextFreeID;
|
||||||
|
m_nextFreeID++;
|
||||||
|
|
||||||
m_hash.Insert( wxUIntToPtr(id), 0 );
|
m_hash.Insert( wxUIntToPtr(id), 0 );
|
||||||
wxDataViewItem item( wxUIntToPtr(id) );
|
wxDataViewItem item( wxUIntToPtr(id) );
|
||||||
ItemAdded( wxDataViewItem(0), item );
|
ItemAdded( wxDataViewItem(0), item );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewIndexListModel::RowInserted( unsigned int before )
|
void wxDataViewIndexListModel::RowInserted( unsigned int before )
|
||||||
{
|
{
|
||||||
m_ordered = false;
|
m_ordered = false;
|
||||||
|
|
||||||
unsigned int id = m_lastIndex++;
|
unsigned int id = m_nextFreeID;
|
||||||
|
m_nextFreeID++;
|
||||||
|
|
||||||
m_hash.Insert( wxUIntToPtr(id), before );
|
m_hash.Insert( wxUIntToPtr(id), before );
|
||||||
wxDataViewItem item( wxUIntToPtr(id) );
|
wxDataViewItem item( wxUIntToPtr(id) );
|
||||||
ItemAdded( wxDataViewItem(0), item );
|
ItemAdded( wxDataViewItem(0), item );
|
||||||
@@ -354,7 +360,9 @@ void wxDataViewIndexListModel::RowInserted( unsigned int before )
|
|||||||
|
|
||||||
void wxDataViewIndexListModel::RowAppended()
|
void wxDataViewIndexListModel::RowAppended()
|
||||||
{
|
{
|
||||||
unsigned int id = m_lastIndex++;
|
unsigned int id = m_nextFreeID;
|
||||||
|
m_nextFreeID++;
|
||||||
|
|
||||||
m_hash.Add( wxUIntToPtr(id) );
|
m_hash.Add( wxUIntToPtr(id) );
|
||||||
wxDataViewItem item( wxUIntToPtr(id) );
|
wxDataViewItem item( wxUIntToPtr(id) );
|
||||||
ItemAdded( wxDataViewItem(0), item );
|
ItemAdded( wxDataViewItem(0), item );
|
||||||
@@ -402,10 +410,7 @@ void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int c
|
|||||||
unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const
|
unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const
|
||||||
{
|
{
|
||||||
if (m_ordered)
|
if (m_ordered)
|
||||||
{
|
return wxPtrToUInt(item.GetID())-1;
|
||||||
unsigned int pos = wxPtrToUInt( item.GetID() );
|
|
||||||
return pos-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// assert for not found
|
// assert for not found
|
||||||
return (unsigned int) m_hash.Index( item.GetID() );
|
return (unsigned int) m_hash.Index( item.GetID() );
|
||||||
@@ -429,8 +434,8 @@ int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
|
|||||||
{
|
{
|
||||||
if (m_ordered)
|
if (m_ordered)
|
||||||
{
|
{
|
||||||
unsigned int pos1 = wxPtrToUInt(item1.GetID());
|
unsigned int pos1 = wxPtrToUInt(item1.GetID()); // -1 not needed here
|
||||||
unsigned int pos2 = wxPtrToUInt(item2.GetID());
|
unsigned int pos2 = wxPtrToUInt(item2.GetID()); // -1 not needed here
|
||||||
|
|
||||||
if (ascending)
|
if (ascending)
|
||||||
return pos1 - pos2;
|
return pos1 - pos2;
|
||||||
@@ -493,7 +498,7 @@ unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item,
|
|||||||
|
|
||||||
wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size )
|
wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size )
|
||||||
{
|
{
|
||||||
m_lastIndex = initial_size-1;
|
m_size = initial_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
|
wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
|
||||||
@@ -502,29 +507,29 @@ wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
|
|||||||
|
|
||||||
void wxDataViewVirtualListModel::Reset( unsigned int new_size )
|
void wxDataViewVirtualListModel::Reset( unsigned int new_size )
|
||||||
{
|
{
|
||||||
m_lastIndex = new_size-1;
|
m_size = new_size;
|
||||||
|
|
||||||
wxDataViewModel::Cleared();
|
wxDataViewModel::Cleared();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewVirtualListModel::RowPrepended()
|
void wxDataViewVirtualListModel::RowPrepended()
|
||||||
{
|
{
|
||||||
m_lastIndex++;
|
m_size++;
|
||||||
wxDataViewItem item( wxUIntToPtr(1) );
|
wxDataViewItem item( wxUIntToPtr(1) );
|
||||||
ItemAdded( wxDataViewItem(0), item );
|
ItemAdded( wxDataViewItem(0), item );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewVirtualListModel::RowInserted( unsigned int before )
|
void wxDataViewVirtualListModel::RowInserted( unsigned int before )
|
||||||
{
|
{
|
||||||
m_lastIndex++;
|
m_size++;
|
||||||
wxDataViewItem item( wxUIntToPtr(before+1) );
|
wxDataViewItem item( wxUIntToPtr(before+1) );
|
||||||
ItemAdded( wxDataViewItem(0), item );
|
ItemAdded( wxDataViewItem(0), item );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewVirtualListModel::RowAppended()
|
void wxDataViewVirtualListModel::RowAppended()
|
||||||
{
|
{
|
||||||
m_lastIndex++;
|
m_size++;
|
||||||
wxDataViewItem item( wxUIntToPtr(m_lastIndex+1) );
|
wxDataViewItem item( wxUIntToPtr(m_size) );
|
||||||
ItemAdded( wxDataViewItem(0), item );
|
ItemAdded( wxDataViewItem(0), item );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,7 +537,7 @@ void wxDataViewVirtualListModel::RowDeleted( unsigned int row )
|
|||||||
{
|
{
|
||||||
wxDataViewItem item( wxUIntToPtr(row+1) );
|
wxDataViewItem item( wxUIntToPtr(row+1) );
|
||||||
wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
|
wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
|
||||||
m_lastIndex++;
|
m_size--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows )
|
void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows )
|
||||||
@@ -549,7 +554,7 @@ void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows )
|
|||||||
}
|
}
|
||||||
wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
|
wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
|
||||||
|
|
||||||
m_lastIndex -= rows.GetCount();
|
m_size -= rows.GetCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewVirtualListModel::RowChanged( unsigned int row )
|
void wxDataViewVirtualListModel::RowChanged( unsigned int row )
|
||||||
@@ -582,8 +587,8 @@ int wxDataViewVirtualListModel::Compare(const wxDataViewItem& item1,
|
|||||||
unsigned int WXUNUSED(column),
|
unsigned int WXUNUSED(column),
|
||||||
bool ascending) const
|
bool ascending) const
|
||||||
{
|
{
|
||||||
unsigned int pos1 = wxPtrToUInt(item1.GetID())-1;
|
unsigned int pos1 = wxPtrToUInt(item1.GetID()); // -1 not needed here
|
||||||
unsigned int pos2 = wxPtrToUInt(item2.GetID())-1;
|
unsigned int pos2 = wxPtrToUInt(item2.GetID()); // -1 not needed here
|
||||||
|
|
||||||
if (ascending)
|
if (ascending)
|
||||||
return pos1 - pos2;
|
return pos1 - pos2;
|
||||||
|
@@ -3204,13 +3204,9 @@ int wxDataViewMainWindow::RecalculateCount()
|
|||||||
{
|
{
|
||||||
if (IsVirtualList())
|
if (IsVirtualList())
|
||||||
{
|
{
|
||||||
wxDataViewIndexListModel *list_model =
|
wxDataViewVirtualListModel *list_model =
|
||||||
(wxDataViewIndexListModel*) GetOwner()->GetModel();
|
(wxDataViewVirtualListModel*) GetOwner()->GetModel();
|
||||||
#ifndef __WXMAC__
|
return list_model->GetCount();
|
||||||
return list_model->GetLastIndex() + 1;
|
|
||||||
#else
|
|
||||||
return list_model->GetLastIndex() - 1;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -3407,13 +3407,14 @@ GtkTreeModelFlags wxDataViewCtrlInternal::get_flags()
|
|||||||
|
|
||||||
gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )
|
gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )
|
||||||
{
|
{
|
||||||
|
|
||||||
if (m_wx_model->IsVirtualListModel())
|
if (m_wx_model->IsVirtualListModel())
|
||||||
{
|
{
|
||||||
wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
|
wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
|
||||||
|
|
||||||
unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0];
|
unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0];
|
||||||
|
|
||||||
if (i >= wx_model->GetLastIndex() + 1)
|
if (i >= wx_model->GetCount())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
iter->stamp = m_gtk_model->stamp;
|
iter->stamp = m_gtk_model->stamp;
|
||||||
@@ -3496,7 +3497,7 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
|
|||||||
{
|
{
|
||||||
if (m_wx_model->IsVirtualListModel())
|
if (m_wx_model->IsVirtualListModel())
|
||||||
{
|
{
|
||||||
wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
|
wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
|
||||||
|
|
||||||
// user_data is just the index +1
|
// user_data is just the index +1
|
||||||
int n = ( (wxUIntPtr) iter->user_data ) -1;
|
int n = ( (wxUIntPtr) iter->user_data ) -1;
|
||||||
@@ -3504,7 +3505,7 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
|
|||||||
if (n == -1)
|
if (n == -1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (n >= (int) wx_model->GetLastIndex())
|
if (n >= (int) wx_model->GetCount())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// user_data is just the index +1 (+2 because we need the next)
|
// user_data is just the index +1 (+2 because we need the next)
|
||||||
@@ -3537,7 +3538,7 @@ gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
iter->stamp = m_gtk_model->stamp;
|
iter->stamp = m_gtk_model->stamp;
|
||||||
iter->user_data = (gpointer) 0;
|
iter->user_data = (gpointer) 1;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -3568,6 +3569,11 @@ gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
|
|||||||
{
|
{
|
||||||
if (m_wx_model->IsVirtualListModel())
|
if (m_wx_model->IsVirtualListModel())
|
||||||
{
|
{
|
||||||
|
wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
|
||||||
|
|
||||||
|
if (iter == NULL)
|
||||||
|
return (gint) wx_model->GetCount();
|
||||||
|
|
||||||
// this is a list, nodes have no children
|
// this is a list, nodes have no children
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -3594,10 +3600,10 @@ gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
|
|||||||
{
|
{
|
||||||
if (m_wx_model->IsVirtualListModel())
|
if (m_wx_model->IsVirtualListModel())
|
||||||
{
|
{
|
||||||
wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
|
wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
|
||||||
|
|
||||||
if (iter == NULL)
|
if (iter == NULL)
|
||||||
return (gint) wx_model->GetLastIndex() + 1;
|
return (gint) wx_model->GetCount();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -3627,7 +3633,7 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter
|
|||||||
{
|
{
|
||||||
if (m_wx_model->IsVirtualListModel())
|
if (m_wx_model->IsVirtualListModel())
|
||||||
{
|
{
|
||||||
wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
|
wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
|
||||||
|
|
||||||
if (parent)
|
if (parent)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -3635,12 +3641,12 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter
|
|||||||
if (n < 0)
|
if (n < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (n >= (gint) wx_model->GetLastIndex() + 1)
|
if (n >= (gint) wx_model->GetCount())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
iter->stamp = m_gtk_model->stamp;
|
iter->stamp = m_gtk_model->stamp;
|
||||||
// user_data is just the index +1
|
// user_data is just the index +1
|
||||||
iter->user_data = (gpointer) (n-1);
|
iter->user_data = (gpointer) (n+1);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user