Added wxDataViewSortedListModel, which doesn't work

yet, but you get the idea..


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37760 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2006-02-28 10:47:28 +00:00
parent 30bbf68d3a
commit 8981608c69
2 changed files with 232 additions and 11 deletions

View File

@ -89,21 +89,21 @@ public:
virtual bool SetValue( wxVariant &variant, size_t col, size_t row ) = 0;
// delegated notifiers
bool RowAppended();
bool RowPrepended();
bool RowInserted( size_t before );
bool RowDeleted( size_t row );
bool RowChanged( size_t row );
bool ValueChanged( size_t col, size_t row );
bool Cleared();
virtual bool RowAppended();
virtual bool RowPrepended();
virtual bool RowInserted( size_t before );
virtual bool RowDeleted( size_t row );
virtual bool RowChanged( size_t row );
virtual bool ValueChanged( size_t col, size_t row );
virtual bool Cleared();
// Used internally
void AddViewingColumn( wxDataViewColumn *view_column, size_t model_column );
void RemoveViewingColumn( wxDataViewColumn *column );
virtual void AddViewingColumn( wxDataViewColumn *view_column, size_t model_column );
virtual void RemoveViewingColumn( wxDataViewColumn *column );
// Used internally
void SetNotifier( wxDataViewListModelNotifier *notifier );
wxDataViewListModelNotifier* GetNotifier();
virtual void SetNotifier( wxDataViewListModelNotifier *notifier );
virtual wxDataViewListModelNotifier* GetNotifier();
private:
wxDataViewListModelNotifier *m_notifier;
@ -113,6 +113,51 @@ protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewListModel)
};
// ---------------------------------------------------------
// wxDataViewSortedListModel
// ---------------------------------------------------------
typedef int (wxCALLBACK *wxDataViewListModelCompare)
(size_t row1, size_t row2, size_t col, wxDataViewListModel* model );
WX_DEFINE_SORTED_EXPORTED_ARRAY_SIZE_T(size_t, wxDataViewSortedIndexArray );
class wxDataViewSortedListModel: public wxDataViewListModel
{
public:
wxDataViewSortedListModel( wxDataViewListModel *child );
virtual ~wxDataViewSortedListModel();
virtual size_t GetNumberOfRows();
virtual size_t GetNumberOfCols();
// return type as reported by wxVariant
virtual wxString GetColType( size_t col );
// get value into a wxVariant
virtual wxVariant GetValue( size_t col, size_t row );
// set value, call ValueChanged() afterwards!
virtual bool SetValue( wxVariant &variant, size_t col, size_t row );
// delegated notifiers
virtual bool RowAppended();
virtual bool RowPrepended();
virtual bool RowInserted( size_t before );
virtual bool RowDeleted( size_t row );
virtual bool RowChanged( size_t row );
virtual bool ValueChanged( size_t col, size_t row );
virtual bool Cleared();
// Used internally
void SetNotifier( wxDataViewListModelNotifier *notifier );
wxDataViewListModelNotifier* GetNotifier();
private:
wxDataViewListModel *m_child;
wxDataViewSortedIndexArray m_array;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewSortedListModel)
};
// ---------------------------------------------------------
// wxDataViewCellBase
// ---------------------------------------------------------

View File

@ -166,6 +166,182 @@ wxDataViewListModelNotifier* wxDataViewListModel::GetNotifier()
return m_notifier;
}
// ---------------------------------------------------------
// wxDataViewSortedListModel
// ---------------------------------------------------------
int wxCALLBACK wxDataViewListModelSortedDefaultCompare
(size_t row1, size_t row2, size_t col, wxDataViewListModel* model )
{
wxVariant value1 = model->GetValue( col, row1 );
wxVariant value2 = model->GetValue( col, row2 );
if (value1.GetType() == wxT("string"))
{
wxString str1 = value1.GetString();
wxString str2 = value2.GetString();
return str1.Cmp( str2 );
}
if (value1.GetType() == wxT("long"))
{
long l1 = value1.GetLong();
long l2 = value2.GetLong();
return l1-l2;
}
if (value1.GetType() == wxT("double"))
{
double d1 = value1.GetDouble();
double d2 = value2.GetDouble();
if (d1 == d2) return 0;
if (d1 < d2) return 1;
return -1;
}
if (value1.GetType() == wxT("datetime"))
{
wxDateTime dt1 = value1.GetDateTime();
wxDateTime dt2 = value2.GetDateTime();
if (dt1.IsEqualTo(dt2)) return 0;
if (dt1.IsEarlierThan(dt2)) return 1;
return -1;
}
return 0;
}
static wxDataViewListModelCompare s_CmpFunc;
static wxDataViewListModel *s_CmpModel;
static size_t s_CmpCol;
int LINKAGEMODE wxDataViewIntermediateCmp( size_t row1, size_t row2 )
{
return s_CmpFunc( row1, row2, s_CmpCol, s_CmpModel );
}
IMPLEMENT_ABSTRACT_CLASS(wxDataViewSortedListModel, wxDataViewListModel)
wxDataViewSortedListModel::wxDataViewSortedListModel( wxDataViewListModel *child ) :
m_array( wxDataViewIntermediateCmp )
{
m_child = child;
s_CmpCol = 0;
s_CmpModel = child;
s_CmpFunc = wxDataViewListModelSortedDefaultCompare;
}
wxDataViewSortedListModel::~wxDataViewSortedListModel()
{
}
size_t wxDataViewSortedListModel::GetNumberOfRows()
{
return m_child->GetNumberOfRows();
}
size_t wxDataViewSortedListModel::GetNumberOfCols()
{
return m_child->GetNumberOfCols();
}
wxString wxDataViewSortedListModel::GetColType( size_t col )
{
return m_child->GetColType( col );
}
wxVariant wxDataViewSortedListModel::GetValue( size_t col, size_t row )
{
size_t child_row = m_array[row];
return m_child->GetValue( col, child_row );
}
bool wxDataViewSortedListModel::SetValue( wxVariant &variant, size_t col, size_t row )
{
size_t child_row = m_array[row];
bool ret = m_child->SetValue( variant, col, child_row );
// resort in ::ValueChanged()
return ret;
}
bool wxDataViewSortedListModel::RowAppended()
{
// you can only append
bool ret = m_child->RowAppended();
// report RowInsrted
return ret;
}
bool wxDataViewSortedListModel::RowPrepended()
{
// you can only append
bool ret = m_child->RowAppended();
// report RowInsrted
return ret;
}
bool wxDataViewSortedListModel::RowInserted( size_t before )
{
// you can only append
bool ret = m_child->RowAppended();
// report different RowInsrted
return ret;
}
bool wxDataViewSortedListModel::RowDeleted( size_t row )
{
size_t child_row = m_array[row];
bool ret = m_child->RowDeleted( child_row );
wxDataViewListModel::RowDeleted( row );
return ret;
}
bool wxDataViewSortedListModel::RowChanged( size_t row )
{
size_t child_row = m_array[row];
bool ret = m_child->RowChanged( child_row );
// report delete old pos, inserted new pos
return ret;
}
bool wxDataViewSortedListModel::ValueChanged( size_t col, size_t row )
{
size_t child_row = m_array[row];
bool ret = m_child->ValueChanged( col, child_row );
// Do nothing if not the sorted col..
// report delete old pos, inserted new pos
return ret;
}
bool wxDataViewSortedListModel::Cleared()
{
bool ret = m_child->Cleared();
wxDataViewListModel::Cleared();
return ret;
}
void wxDataViewSortedListModel::SetNotifier( wxDataViewListModelNotifier *notifier )
{
wxDataViewListModel::SetNotifier( notifier );
}
wxDataViewListModelNotifier* wxDataViewSortedListModel::GetNotifier()
{
return wxDataViewListModel::GetNotifier();
}
// ---------------------------------------------------------
// wxDataViewCellBase
// ---------------------------------------------------------