Re: Using a treeview with a dynamic number of columns



On Wed, 2006-03-01 at 19:51, Thiago Guzella wrote:
Greetings everyone,
I guess my first question is whether or not your "dynamic" columns really
need to be removed from the TreeModel, or whether merely selectively hiding their visibility from the user will suffice. While I will be interested if someone has an answer to your actuall question, what I do in my application is add all the columns I'll ever need to the TreeModel when I create it, then choose which of those columns I want to display when I set the treeview for that model. For example, given an appropriate definition for class C_Columns:

void showTreeView(TreeView & treeview, const C_Columns & Columns, bool show_type){
    Glib::RefPtr<TreeModel> treemodel = treeview.get_model();
    treeview.remove_all_columns();
    treeview.set_model(treemodel);
    treeview.append_column("Path",Columns.m_display_name);
    if(show_type) treeview.append_column("Type",Columns.m_row_type_str);
    treeview.append_column("Owner",Columns.m_owner);
    treeview.append_column("Date",Columns.m_date);
    treeview.append_column("Size",Columns.m_size_str);
    treeview.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
    treeview.show();
}


I am writing a Gtkmm app that contains a treeview, composed of a given
number of columns that are always visible, followed by columns that
are dynamically handled. Depending on user actions, a "dynamic" column
in the treeview needs to be added or removed. I have been implementing
this pattern in the following way:

class TreeViewColumns : public Gtk::TreeModel::ColumnRecord {

   Gtk::TreeModelColumn<Glib::ustring> constant_column_1;
   Gtk::TreeModelColumn<Glib::ustring> constant_column_2;
   Gtk::TreeModelColumn<Glib::ustring> constant_column_3;

   vector< Gtk::TreeModelColumn<Glib::ustring> > dynamic_columns;

   ...

   TreeViewColumns() {

      // Add the constant columns
      add(constant_column_1);
      add(constant_column_1);
      add(constant_column_1);
   }

   void addDynamicColumn() {

      // Insert the column
      dynamic_columns.push_back(Gtk::TreeModelColumn<Glib::ustring> ());
      // Add the new, dynamic, column
      add(dynamic_columns.back());
   }

};

class MyTreeView : public Gtk::TreeView {

   TreeViewColumns m_cols;
   Glib::RefPtr<Gtk::ListStore> m_ref_tree_model;


   MyTreeView() /* m_cols initialized; constant columns added */ {

      // Create list store
      m_ref_tree_model = Gtk::ListStore::create(*m_cols);
      // Set the tree model
      set_model(m_ref_tree_model);
   }
};

But, after experimenting, I have come to the conclusion that I can't
just add a column (by calling TreeViewColumns::addDynamicColumn) and
using MyTreeView::append_column.

After reading a previous thread
(http://mail.gnome.org/archives/gtkmm-list/2002-July/msg00367.html), I
tried to, when adding a new column, clear the columns, add the dynamic
column, running Gtk::TreeModel::ColumnRecord::add for each column to
be displayed, recreating the list store and updating the tree model.
But that doesn't seem to work. So, I would like to ask, how should
this scheme be implemented?


--
Thiago dos Santos Guzella
Electrical Enginnering Student - UFMG (www.ufmg.br), Brazil
Linux User #354160
UIN: 13465286. Jabber: tguzella At jabber Dot org

"Faith: not wanting to know what is true."
Friedrich Nietzsche
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]