Debian Codegraph @

gtk/gtkmm/treemodelcolumn.h

raw symbols SCIP
1 #ifndef _GTKMM_TREEMODELCOLUMN_H
2 #define _GTKMM_TREEMODELCOLUMN_H
3
4 /* Copyright (C) 2002 The gtkmm Development Team
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or(at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include <gtkmmconfig.h>
21 #include <glibmm/value.h>
22 #include <glib-object.h>
23 #include <vector>
24
25 namespace Gtk
26 {
27
28 class GTKMM_API TreeModelColumnBase;
29
30
31 /** Typedefed as TreeModel::ColumnRecord.
32 * Keeps a record of @link TreeModelColumn TreeModelColumns@endlink.
33 * @ingroup TreeView
34 * ColumnRecord objects are used to setup a new instance of a TreeModel
35 * (or rather, a new instance of an implementation of the model, such as Gtk::ListStore
36 * or Gtk::TreeStore). It is convenient to do that by deriving from
37 * TreeModel::ColumnRecord:
38 * @code
39 * class MyModelColumns : public Gtk::TreeModel::ColumnRecord
40 * {
41 * public:
42 * Gtk::TreeModelColumn<Glib::ustring> filename;
43 * Gtk::TreeModelColumn<Glib::ustring> description;
44 * Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > thumbnail;
45 *
46 * MyModelColumns() { add(filename); add(description); add(thumbnail); }
47 * };
48 * @endcode
49 *
50 * Whether or not you derive your own ColumnRecord, you need to add the
51 * @link TreeModelColumn TreeModelColumns@endlink to the ColumnRecord with the
52 * add() method.
53 *
54 * A ColumnRecord instance, such as an instance of @c MyModelColumns should then
55 * be passed to ListStore::create() or TreeStore::create().
56 * The @link TreeModelColumn TreeModelColumns@endlink, such as the members
57 * @c filename, @c description and @c thumbnail can then be used with Gtk::TreeRow::operator[]()
58 * to specify the column you're interested in.
59 *
60 * Neither TreeModel::ColumnRecord nor the
61 * @link TreeModelColumn TreeModelColumns@endlink contain any real data --
62 * they merely describe what C++ type is stored in which column
63 * of a TreeModel, and save you from having to repeat that type information in several places.
64 *
65 * Thus TreeModel::ColumnRecord can be made a singleton (as long as you make
66 * sure it's instantiated after Gtk::Main), even when creating multiple models
67 * from it.
68 */
69 class TreeModelColumnRecord
70 {
71 public:
72 GTKMM_API TreeModelColumnRecord();
73 GTKMM_API virtual ~TreeModelColumnRecord() noexcept;
74
75 /** Adds a TreeModelColumn to this record.
76 * add() not only registers the @a column, but also assigns a column
77 * index to it. Once registered, the TreeModelColumn is final, and
78 * you're free to pass it around by value.
79 */
80 GTKMM_API void add(TreeModelColumnBase& column);
81
82 GTKMM_API unsigned int size() const;
83 GTKMM_API const GType* types() const;
84
85 private:
86 std::vector<GType> column_types_;
87
88 // noncopyable
89 GTKMM_API TreeModelColumnRecord(const TreeModelColumnRecord&);
90 GTKMM_API TreeModelColumnRecord& operator=(const TreeModelColumnRecord&);
91 };
92
93
94 /** Base class of TreeModelColumn templates.
95 * @ingroup TreeView
96 */
97 class GTKMM_API TreeModelColumnBase
98 {
99 public:
100 GType type() const { return type_; }
101 int index() const { return index_; }
102
103 protected:
104 explicit TreeModelColumnBase(GType g_type);
105
106 private:
107 GType type_;
108 int index_;
109
110 friend class Gtk::TreeModelColumnRecord;
111 };
112
113 /** @relates Gtk::TreeModelColumnBase */
114 inline bool operator==(const TreeModelColumnBase& lhs, const TreeModelColumnBase& rhs)
115 { return (lhs.index() == rhs.index()); }
116
117 /** @relates Gtk::TreeModelColumnBase */
118 inline bool operator!=(const TreeModelColumnBase& lhs, const TreeModelColumnBase& rhs)
119 { return (lhs.index() != rhs.index()); }
120
121
122 /** A Gtk::TreeModelColumn describes the C++ type of the data in a model column, and identifies that column in the model.
123 * See @link TreeModelColumnRecord Gtk::TreeModel::Columns@endlink for a usage example.
124 * @ingroup TreeView
125 */
126 template <class T>
127 class TreeModelColumn : public TreeModelColumnBase
128 {
129 public:
130 typedef T ElementType;
131 typedef Glib::Value<T> ValueType;
132
133 TreeModelColumn() : TreeModelColumnBase(ValueType::value_type()) {}
134 };
135
136 } // namespace Gtk
137
138 #endif /* _GTKMM_TREEMODELCOLUMN_H */