Added logic, API and docs for wxDataViewModel::HasDefaultCompare indicating a compare function usable without and column (header)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48345 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2007-08-22 21:18:06 +00:00
parent 04e7692af1
commit 0bd2681966
5 changed files with 57 additions and 12 deletions

View File

@ -128,9 +128,14 @@ a little arrow.
\func{void}{SetSortable}{\param{bool }{sortable}}
Indicate that the column is sortable. This is only to provide a
visual hint in the column (such as a sort order indicator). It
will not actually sort the data.
Indicate that the column is sortable. This does
not show any sorting indicate yet, but it does
make the column header clickable. Call
\helpref{SetSortOrder}{wxdataviewcolumnsetsortorder}
afterwards to actually make the sort indicator appear.
If {\it sortable} is false, the column header is
no longer clickable and the sort indicator (little
arrow) will disappear.
\membersection{wxDataViewColumn::SetTitle}\label{wxdataviewcolumnsettitle}

View File

@ -38,7 +38,9 @@ Note that wxDataViewModel does not define the position or
index of any item in the control since several control might
display the data differently, but wxDataViewModel does
provide a \helpref{Compare}{wxdataviewmodelcompare} method
which the wxDataViewCtrl may use to sort the data.
which the wxDataViewCtrl may use to sort the data either
in conjunction with a column header or without (see
\helpref{HasDefaultCompare}{wxdataviewmodelhasdefaultcompare}.
This class maintains a list of
\helpref{wxDataViewModelNotifier}{wxdataviewmodelnotifier}
@ -107,6 +109,8 @@ The compare function to be used by control. The default compare function
sorts by container and other items separately and in ascending order.
Override this for a different sorting behaviour.
See also \helpref{HasDefaultCompare}{wxdataviewmodelhasdefaultcompare}.
\membersection{wxDataViewModel::GetColumnCount}\label{wxdataviewmodelgetcolumncount}
\constfunc{unsigned int}{GetColumnCount}{\void}
@ -147,6 +151,18 @@ of {\it item} or an invalid wxDataViewItem if {\it item} is the root item.
Override this to indicate the value of {\it item}
A \helpref{wxVariant}{wxvariant} is used to store the data.
\membersection{wxDataViewModel::HasDefaultCompare}\label{wxdataviewmodelhasdefaultcompare}
\func{bool}{HasDefaultCompare}{\void}
Override this to indicate that the model provides a default compare
function that the control should use if no wxDataViewColumn has been
chosen for sorting. Usually, the user clicks on a column header for
sorting, the data will be sorted alphanumerically. If any other
order (e.g. by index or order of appearance) is required, then this
should be used. See also \helpref{wxDataViewIndexListModel}{wxdataviewindexlistmodel}
for a model which makes use of this.
\membersection{wxDataViewModel::IsContainer}\label{wxdataviewmodeliscontainer}
\constfunc{bool}{IsContainer}{\param{const wxDataViewItem\& }{item}}

View File

@ -156,6 +156,7 @@ public:
// default compare function
virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
unsigned int column, bool ascending );
virtual bool HasDefaultCompare() { return false; }
protected:
// the user should not delete this class directly: he should use DecRef() instead!
@ -198,6 +199,7 @@ public:
virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
unsigned int column, bool ascending );
virtual bool HasDefaultCompare() { return true; }
// implement base methods

View File

@ -221,7 +221,16 @@ public:
case 0: variant = node->m_title; break;
case 1: variant = node->m_artist; break;
case 2: variant = node->m_year; break;
default: wxLogError( "MyMusicModel::GetValue: wrong column" );
default:
{
wxLogError( "MyMusicModel::GetValue: wrong column" );
wxMouseState state = wxGetMouseState();
if (state.ShiftDown())
{
char *crash = 0;
*crash = 0;
}
}
}
}
@ -558,8 +567,14 @@ MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
m_music_model = new MyMusicModel;
m_musicCtrl->AssociateModel( m_music_model.get() );
m_musicCtrl->AppendTextColumn( "Title", 0, wxDATAVIEW_CELL_INERT, 200,
wxDataViewColumn *col = m_musicCtrl->AppendTextColumn( "Title", 0, wxDATAVIEW_CELL_INERT, 200,
DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE );
#if 0
// Call this and sorting is enabled
// immediatly upon start up.
col->SetSortOrder( true );
#endif
m_musicCtrl->AppendTextColumn( "Artist", 1, wxDATAVIEW_CELL_EDITABLE, 200,
DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE );
m_musicCtrl->AppendTextColumn( "Year", 2, wxDATAVIEW_CELL_INERT, 50,

View File

@ -157,28 +157,28 @@ public:
void *id = child->GetItem().GetID();
m_children.Add( id );
#if 0
if (m_internal->IsSorted())
if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare())
{
g_internal = m_internal;
m_children.Sort( &wxGtkTreeModelChildCmp );
return m_children.Index( id );
}
#endif
return m_children.GetCount()-1;
}
unsigned int AddLeave( void* id )
{
m_children.Add( id );
#if 0
if (m_internal->IsSorted())
if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare())
{
g_internal = m_internal;
m_children.Sort( &wxGtkTreeModelChildCmp );
return m_children.Index( id );
}
#endif
return m_children.GetCount()-1;
}
@ -2097,9 +2097,14 @@ void wxDataViewColumn::SetSortable( bool sortable )
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
if (sortable)
{
gtk_tree_view_column_set_sort_column_id( column, GetModelColumn() );
}
else
{
gtk_tree_view_column_set_sort_column_id( column, -1 );
gtk_tree_view_column_set_sort_indicator( column, FALSE );
}
}
bool wxDataViewColumn::IsSortable() const
@ -2128,6 +2133,8 @@ void wxDataViewColumn::SetSortOrder( bool ascending )
gtk_tree_view_column_set_sort_order( column, GTK_SORT_ASCENDING );
else
gtk_tree_view_column_set_sort_order( column, GTK_SORT_DESCENDING );
gtk_tree_view_column_set_sort_indicator( column, TRUE );
}
bool wxDataViewColumn::IsSortOrderAscending() const