virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
unsigned int column, bool ascending );
- virtual bool HasDefaultCompare() const { return true; }
+ virtual bool HasDefaultCompare() const;
// implement base methods
private:
wxDataViewItemArray m_hash;
unsigned int m_lastIndex;
+ bool m_ordered;
};
wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
{
+ m_ordered = true;
+
// build initial index
unsigned int i;
for (i = 1; i < initial_size+1; i++)
m_hash.Insert( (void*) id, 0 );
wxDataViewItem item( (void*) id );
ItemAdded( wxDataViewItem(0), item );
+
+ m_ordered = false;
}
void wxDataViewIndexListModel::RowInserted( unsigned int before )
m_hash.Insert( (void*) id, before );
wxDataViewItem item( (void*) id );
ItemAdded( wxDataViewItem(0), item );
+
+ m_ordered = false;
}
void wxDataViewIndexListModel::RowAppended()
unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const
{
+ if (m_ordered)
+ {
+ unsigned int pos = (unsigned int) item.GetID();
+ return pos-1;
+ }
+
// assert for not found
return (unsigned int) m_hash.Index( item.GetID() );
}
return wxDataViewItem( m_hash[row] );
}
+bool wxDataViewIndexListModel::HasDefaultCompare() const
+{
+ return !m_ordered;
+}
+
int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
const wxDataViewItem& item2,
unsigned int WXUNUSED(column),
bool ascending)
{
+ if (m_ordered)
+ {
+ unsigned int pos1 = (unsigned int) item1.GetID();
+ unsigned int pos2 = (unsigned int) item2.GetID();
+
+ if (ascending)
+ return pos1 - pos2;
+ else
+ return pos2 - pos1;
+ }
+
if (ascending)
return GetRow(item1) - GetRow(item2);