1/*
2 * Copyright(C) 1998-2002 The gtkmm Development Team
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or(at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19#include <gtkmm/treeiter.h>
20#include <gtkmm/treemodel.h>
21// We couldn't include it in treemodel.h, but doing it here makes it easier for people.
22#include <gtkmm/treepath.h>
23
24_DEFS(gtkmm,gtk)
25_PINCLUDE(glibmm/private/object_p.h)
26
27namespace Gtk
28{
29
30/**
31 * @ingroup TreeView
32 *
33 */
34class TreeModelFilter :
35  public Glib::Object,
36  public TreeModel
37{
38  _CLASS_GOBJECT(TreeModelFilter, GtkTreeModelFilter, GTK_TREE_MODEL_FILTER, Glib::Object, GObject)
39  _IMPLEMENTS_INTERFACE(TreeModel)
40
41protected:
42
43  explicit TreeModelFilter(const Glib::RefPtr<TreeModel>& child_model);
44  explicit TreeModelFilter(const Glib::RefPtr<TreeModel>& child_model, const TreeModel::Path& virtual_root);
45  dnl // Don't _IGNORE(gtk_tree_model_filter_new). It's listed in gtk_methods.defs as
46  dnl // a method of GtkTreeModel. Ignoring it would make gmmproc think that this
47  dnl // file wraps GtkTreeModel, and it would list all GtkTreeModel methods as unwrapped.
48
49public:
50
51  /** This creates a TreeModelFilter with @a child_model as the child model.
52   * You can use set_visible_func(), set_visible_column() and/or set_modify_func() to change the mapping of child
53   * model to parent model.
54   */
55  _WRAP_CREATE(const Glib::RefPtr<TreeModel>& child_model)
56
57  /** This creates a TreeModelFilter with @a child_model as the child model, and @a root as the virtual root.
58   * You can use set_visible_func(), set_visible_column() and/or set_modify_func() to change the mapping of child
59   * model to parent model.
60   */
61  _WRAP_CREATE(const Glib::RefPtr<TreeModel>& child_model, const TreeModel::Path& virtual_root)
62
63
64  /** For instance,
65   * bool on_visible(const TreeModel::const_iterator& iter);
66   * This should return true if the given row should be visible and false otherwise.
67   */
68  typedef sigc::slot<bool, const TreeModel::const_iterator&> SlotVisible;
69
70  /** Sets the "visible" callback used when filtering the filter.
71   * The callback function should return true if the given row should be visible and false otherwise.
72   *
73   * @param slot A callback slot which determines whether the row should be visible.
74   */
75  void set_visible_func(const SlotVisible& slot);
76  _IGNORE(gtk_tree_model_filter_set_visible_func)
77
78  //TODO: It would be nicer to use "const TreeModelColumnBase& column" instead of "int column",
79  //but how can we get the TreeModelColumnBase from the int in the SignalProxy?
80  //Maybe we could pass the ColumnsRecord to set_modify_func() and store it in the proxy? murrayc.
81  /** For instance,
82   *   void on_modify(const Gtk::TreeModel::iterator& iter, Glib::ValueBase& value, int column);
83   *
84   * where iter is an iterator to a row in the child model,
85   * value is an output parameter in which you must store the value to be used in the parent model's row,
86   * column is the column in the parent row whose row value you must provide in the value output paramater.
87   */
88  typedef sigc::slot<void, const Gtk::TreeModel::iterator& /* iter */, Glib::ValueBase& /* value */, int /* column */> SlotModify;
89
90  /** Specify columns that will be provided by this model, and a callback that will provide data for these
91   * columns based on data in the columns of the child model.
92   * The modify function will get called for each data access.
93   *
94   * @param columns Column types for this model (which will be exposed to the parent model/view).
95   * @param slot A callback which will be called for each data access.
96   */
97  void set_modify_func(const TreeModelColumnRecord& columns, const SlotModify& slot);
98  _IGNORE(gtk_tree_model_filter_set_modify_func)
99
100  _WRAP_METHOD(void set_visible_column(const TreeModelColumnBase& column), gtk_tree_model_filter_set_visible_column)
101  _WRAP_METHOD(void set_visible_column(int column), gtk_tree_model_filter_set_visible_column)
102
103  _WRAP_METHOD(Glib::RefPtr<TreeModel> get_model(), gtk_tree_model_filter_get_model, refreturn)
104  _WRAP_METHOD(Glib::RefPtr<const TreeModel> get_model() const, gtk_tree_model_filter_get_model, refreturn, constversion)
105
106  /** Gets an iterator that points to the sorted row that corresponds to the child row pointed at by child_iter.
107   *
108   * @param child_iter A valid iterator pointing to a row on the child model.
109   * @result A valid iterator that points to the row in this sorted model.
110   */
111  iterator convert_child_iter_to_iter(const iterator& child_iter) const;
112  _IGNORE(gtk_tree_model_filter_convert_child_iter_to_iter)
113
114  /** Gets an iterator that points to the child row that corresponds to the sorted row pointed at by sorted_iter.
115   *
116   * @param filter_iter A valid iterator pointing to a row on the sorted model.
117   * @result A valid iterator that points to the row in the child model.
118   */
119  iterator convert_iter_to_child_iter(const iterator& filter_iter) const;
120  _IGNORE(gtk_tree_model_filter_convert_iter_to_child_iter)
121
122  _WRAP_METHOD(Path convert_child_path_to_path(const Path& child_path) const, gtk_tree_model_filter_convert_child_path_to_path)
123  _WRAP_METHOD(Path convert_path_to_child_path(const Path& filter_path) const, gtk_tree_model_filter_convert_path_to_child_path)
124
125  _WRAP_METHOD(void refilter(), gtk_tree_model_filter_refilter)
126  _WRAP_METHOD(void clear_cache(), gtk_tree_model_filter_clear_cache)
127
128  _WRAP_PROPERTY("child-model", Glib::RefPtr<TreeModel>)
129  _WRAP_PROPERTY("virtual-root", TreeModel::Path)
130
131protected:
132  void set_value_impl(const iterator& row, int column, const Glib::ValueBase& value) override;
133};
134
135} // namespace Gtk
136