1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
//!
//! \addtogroup linuxui Linux UI
//! @{
//!
#ifndef __TREEMODEL_WRAPPER_H__
#define __TREEMODEL_WRAPPER_H__
#include "listmodel_wrapper.h"
#include <set>
typedef std::set<std::string> ExpandedRowsStorage;
class TreeModelWrapper : public ListModelWrapper
{
private:
TreeModelWrapper(bec::TreeModel *tm, Gtk::TreeView *treeview, const std::string& name, const bec::NodeId &root_node, bool as_list)
: Glib::ObjectBase(typeid(TreeModelWrapper))
, ListModelWrapper(tm, treeview, ("tv_" + name))
, _root_node_path(root_node.toString())
, _root_node_path_dot(root_node.toString() + ".")
, _show_as_list(as_list)
, _expanded_rows(0)
, _children_count_enabled(true)
, _delay_expanding_nodes(false)
{
if (treeview)
{
_expand_signal = treeview->signal_row_expanded().connect(sigc::mem_fun(this, &TreeModelWrapper::tree_row_expanded));
_collapse_signal = treeview->signal_row_collapsed().connect(sigc::mem_fun(this, &TreeModelWrapper::tree_row_collapsed));
}
}
public:
static Glib::RefPtr<TreeModelWrapper> create(bec::TreeModel *tm, Gtk::TreeView *treeview, const std::string& name, const bec::NodeId &root_node= bec::NodeId(), bool as_list= false)
{
bec::NodeId root= root_node.is_valid() ? root_node : tm->get_root();
return Glib::RefPtr<TreeModelWrapper>(new TreeModelWrapper(tm, treeview, name, root, as_list));
}
void set_delay_expanding_nodes(bool flag) { _delay_expanding_nodes= flag; }
ExpandedRowsStorage* expanded_rows_storage() const { return _expanded_rows; }
void set_expanded_rows_storage(ExpandedRowsStorage* s) { _expanded_rows = s;}
void update_root_node(const bec::NodeId &root_node);
virtual Gtk::TreeModelFlags get_flags_vfunc() const;
virtual bec::NodeId get_node_for_path(const Gtk::TreeModel::Path &path) const;
virtual void get_icon_value(const iterator& iter, int column, const bec::NodeId &node, Glib::ValueBase& value) const;
virtual Gtk::TreeModel::Path get_path_vfunc(const iterator& iter) const;
/**
Sets @a iter to a valid iterator pointing to @a path
@param path An path to a node.
@param iter An iterator that will be set to refer to a node to the path, or will be set as invalid.
@result true if the operation was possible.
*/
virtual bool get_iter_vfunc(const Path& path, iterator& iter) const;
/**
Sets @a iter to refer to the first child of @a parent. If @a parent has no children,
false is returned and @a iter is set to be invalid.
@param parent An iterator.
@param iter An iterator that will be set to refer to the firt child node, or will be set as invalid.
@result true if the operation was possible.
*/
virtual bool iter_children_vfunc(const iterator& parent, iterator& iter) const;
/**
Sets @a iter to be the parent of @a child. If @a child is at the toplevel, and
doesn't have a parent, then @a iter is set to an invalid iterator and false
is returned.
@param child An iterator.
@param iter An iterator that will be set to refer to the parent node, or will be set as invalid.
@result true if the operation was possible.
*/
virtual bool iter_parent_vfunc(const iterator& child, iterator& iter) const;
/**
Sets @a iter to be the child of @a parent using the given index. The first
index is 0. If @a n is too big, or @a parent has no children, @a iter is set
to an invalid iterator and false is returned.
See also iter_nth_root_child_vfunc()
@param parent An iterator.
@param n The index of the child node to which @a iter should be set.
@param iter An iterator that will be set to refer to the nth node, or will be set as invalid.
@result true if the operation was possible.
*/
virtual bool iter_nth_child_vfunc(const iterator& parent, int n, iterator& iter) const;
/**
Sets @a iter to be the child of at the root level using the given index. The first
index is 0. If @a n is too big, or if there are no children, @a iter is set
to an invalid iterator and false is returned.
See also iter_nth_child_vfunc().
@param n The index of the child node to which @a iter should be set.
@param iter An iterator that will be set to refer to the nth node, or will be set as invalid.
@result true if the operation was possible.
*/
virtual bool iter_nth_root_child_vfunc(int n, iterator& iter) const;
/**
Returns true if @a iter has children, false otherwise.
@param iter The iterator to test for children.
@result true if @a iter has children.
*/
virtual bool iter_has_child_vfunc(const iterator& iter) const;
/**
Returns the number of children that @a iter has.
See also iter_n_root_children_vfunc().
@param iter The iterator to test for children.
@result The number of children of @a iter.
*/
virtual int iter_n_children_vfunc(const iterator& iter) const;
/**
Returns the number of toplevel nodes.
See also iter_n_children().
@result The number of children at the root level.
*/
virtual int iter_n_root_children_vfunc() const;
void tree_row_expanded(const iterator& iter, const Path &path);
void tree_row_collapsed(const iterator& iter, const Path &path);
void block_expand_collapse_signals();
void unblock_expand_collapse_signals();
bool children_count_enabled() { return _children_count_enabled; }
void children_count_enabled(bool value) { _children_count_enabled= value; }
//virtual bec::NodeId node_for_iter(const iterator &iter) const;
private:
//virtual bool init_gtktreeiter(GtkTreeIter* it, const bec::NodeId &uid = bec::NodeId()) const;
std::string _root_node_path;
std::string _root_node_path_dot;
bool _show_as_list;
//! As bec::TreeModel::is_expanded is not working atm and ValueTreeBE::is_expanded neither,
//! a workaround is used. Not every TreeModel needs to have ability to determine
//! if a node is expanded or collapsed the optional storage is provided via _expanded_rows.
//! _expanded_rows is a std::set of string representation of Gtk::TreeModel::Path.
//! tree_row_expanded and tree_row_collapsed check if _expanded_rows is not null and
//! insert/erase paths accordingly. TreeModelWrapper::set_expanded_rows_storage and
//! TreeModelWrapper::expanded_rows_storage are used to get/set the storage.
//! The storage is also used in expand_tree_nodes_as_in_be function, which expands
//! Gtk::TreeView rows after the storage. This is used when a refresh is done for
//! the TreeView/model.
ExpandedRowsStorage *_expanded_rows;
sigc::connection _expand_signal;
sigc::connection _collapse_signal;
bool _children_count_enabled;
bool _delay_expanding_nodes;
bec::TreeModel *tm() const { return static_cast<bec::TreeModel*>(get_be_model()); }
};
#endif
//!
//! @}
//!
|