\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}
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}
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}
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}}
// 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!
virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
unsigned int column, bool ascending );
+ virtual bool HasDefaultCompare() { return true; }
// implement base methods
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;
+ }
+ }
}
}
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,
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;
}
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
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