Tris

The standard tree models (TreeStore and ListStore) derive from TreeSortable, so they offer sorting functionality. For instance, call set_sort_column(), to sort the model by the specified column. Or supply a callback function to set_sort_func() to implement a more complicated sorting algorithm.

TreeSortable Reference

X.V.I. Tri en cliquant sur l'en-tête de colonne

So that a user can click on a TreeView's column header to sort the TreeView's contents, call Gtk::TreeView::Column::set_sort_column(), supplying the model column on which model should be sorted when the header is clicked. For instance:

auto pColumn = treeview.get_column(0);
if(pColumn)
  pColumn->set_sort_column(m_columns.m_col_id);

X.V.II. Vues d'un même modèle triées de manière indépendante

The TreeView already allows you to show the same TreeModel in two TreeView widgets. If you need one of these TreeViews to sort the model differently than the other then you should use a TreeModelSort instead of just, for instance, Gtk::TreeViewColumn::set_sort_column(). TreeModelSort is a model that contains another model, presenting a sorted version of that model. For instance, you might add a sorted version of a model to a TreeView like so:

auto sorted_model = Gtk::TreeModelSort::create(model);
sorted_model->set_sort_column(columns.m_col_name, Gtk::SORT_ASCENDING);
treeview.set_model(sorted_model);

Notez, toutefois, que la vue arborescente fournit des itérateurs sur le modèle trié. Vous devez les convertir en itérateurs du modèle enfant sous-jacent pour effectuer des opérations sur ce modèle. Par exemple :

void ExampleWindow::on_button_delete()
{
  auto refTreeSelection = m_treeview.get_selection();
  if(refTreeSelection)
  {
    auto sorted_iter = m_refTreeSelection->get_selected();
    if(sorted_iter)
    {
      auto iter = m_refModelSort->convert_iter_to_child_iter(sorted_iter);
      m_refModel->erase(iter);
    }
  }
}

TreeModelSort Reference