Re: Displaying a "hierarchy" of classes in a TreeView
- From: José Alburquerque <jaalburquerque cox net>
- To: Aaron Geier <ageier catalystmicro com>
- Cc: gtkmm-list gnome org
- Subject: Re: Displaying a "hierarchy" of classes in a TreeView
- Date: Thu, 06 Sep 2007 16:33:19 -0400
Aaron Geier wrote:
Hello,
I'm not an expert on gtkmm, but I'll try to take a stab at this one.
>From what I understand of TreeView is that the TreeView is the display and the TreeModel is the data that can be displayed by a TreeView.
That being said, TreeView uses a class called CellRenderer[1] to display the view...
So what you're attempting to do is add something that is not a CellRenderer to the TreeView display, which, I believe, cannot be done.
You see, the TreeModel contains specific types of data (i.e. ustrings, integers, booleans, and doubles) and the TreeView has a way of displaying those types of data using CellRenderers. By default, if you use a column that is a ustring, it will choose a CellRenderText as the CellRenderer, unless you tell it to use a different CellRenderer.
Does that make any sense at all?
-Aaron Geier
Thanks Aaron for trying to answer my question. As I mentioned in my
original post, I have a series of "interconnected" classes (by
pointers). The connections are uni-directional which determines which
is the parent and which are "ancestors". Children, themselves can also
have children so the tree relationship is somewhat "intricate".
As I mentioned in my last post, I think I found a solution: What I've
done so far is to derive all the classes from a single base class
(though some have multiple inheritances) which I call "Element". I then
defined a class derived from Gtk::TreeModelColumnRecord class with a
single Gtk::TreeModelColumn<Element> member which looks like the following:
class Columns : public Gtk::TreeModelColumnRecord {
public:
Columns()
{ add(element); }
Gtk::TreeModelColumn<Element> element;
};
Columns columns;
I can now successfully create the TreeStore (the model) using something like
Gtk::RefPtr<Gtk::TreeStore> treeStoreRefPtr =
Gtk::TreeStore::create(columns);
I am also able to "treeStoreRefPtr->append()" rows, etc. within the tree
and set them by using code like the following:
Gtk::TreeStore::iterator rowIter = treeStoreRefPtr->append();
Gtk::TreeStore::Row row = (*rowIter);
row[columns.element] = <One of My classes>;
So so far, I seem to be able to build the model just fine.
What I was asking basically is: How can I have the TreeView "display"
these classes and as you mentioned, the TreeView uses CellRenderers. I
found this excerpt from Chap. 8 of programming guide:
Adding View Columns
You can use the |append_column()| method to tell the View that it
should display certain Model columns, in a certain order, with a
certain column title.
m_TreeView.append_column("Messages", m_Columns.m_col_text);
When using this simple |append_column()| override, the |TreeView|
will display the model data with an appropriate |CellRenderer|. For
instance, strings and numbers are shown in a simple |Gtk::Entry|
widget, and booleans are shown in a |Gtk::CheckButton|. This is
usually what you need. *For other column types you must either
connect a callback that converts your type into a string
representation, with |TreeViewColumn::set_cell_data_func()|, or
derive a custom |CellRenderer|.* Note that (unsigned) short is not
supported by default - You could use (unsigned) int or (unsigned)
long as the column type instead.
So I think I'll have to use the "set_cell_data_func()" in TreeViewColumn
or derive a custom CellRenderer as mentioned above. So far, I think
things are working. At first I didn't know where to start (it was a bit
overwhelming), but I think I should be able to figure things out now.
If you have any comments I'd appreciate them and I'll post again if I
get stuck. :-) Thanks again.
-Jose
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]