Re: Displaying simple rows/columns of text (using TreeView now, used CList in version 1)
- From: "Marco Scholten" <mscholtn xs4all nl>
- To: toralf procaptura com
- Cc: "gtkmm-list gnome org" <gtkmm-list gnome org>
- Subject: Re: Displaying simple rows/columns of text (using TreeView now, used CList in version 1)
- Date: Sat, 26 Feb 2005 11:10:06 +0100
From: "Toralf Lund" <toralf procaptura com>
To: "GTK-- Mailing List" <gtkmm-list gnome org>
Subject: Displaying simple rows/columns of text (using TreeView now, used
CList in version 1)
Date: Thu, 24 Feb 2005 13:24:10 +0100
Just trying to display some simple text organised in rows and columns
for the first time with gtkmm 2... With version 1, I would use CList for
this purpose, but that type is gone, so what is the simplest way of
doing this in the current version?
Actually, I've successfully set up what I want via Gtk::TreeView and
friends, but I can't help feeling that it all got way too complex. I
mean, this approach requires at least 10 lines of code to replace the
simple "new Gtk::CList(...)", and assignment to existing values is extra
work, too. Differently put, it seems like I pay a too high price for
flexibility that I don't need. So is there an alternative? Or perhaps
I've missed some shortcuts available when setting up a TreeView? One
thing I didn't quite understand when doing that, by the way, was why I
had to set up the columns via the "store" object *and* methods to the
view itself.
I agree that a treeview is to complex if you just want a simple list.
To make this a little simpler i made this class:
class TextList: public Gtk::TreeView
{
public:
TextList(int nr_of_columns = 1);
~TextList(){;}
virtual void add_row(Glib::ustring s, int row = -1);
virtual bool set_text(unsigned int row,Glib::ustring s); //separate
column values by \t to set complete row at once
virtual bool set_text(unsigned int row, unsigned int col ,Glib::ustring
s);
virtual Glib::ustring get_text(unsigned int row); //returns complete row
column values separated by \t
virtual Glib::ustring get_text(unsigned int row, unsigned int col);
virtual bool remove_row(int row);
virtual void clear();
virtual unsigned int get_n_rows() const;
virtual unsigned int get_n_columns() const;
virtual int get_active_row();
virtual void set_active_row(unsigned int row);
virtual sigc::signal<void> signal_selection_changed();
protected:
void CreateColumns(int nr_of_columns);
sigc::signal<void> selection_changed;
void on_selection_changed();
private:
TextList(const TextList&);
TextList& operator=(const TextList&);
vector<Gtk::TreeModelColumn<Glib::ustring> > m_Columns;
Gtk::TreeModel::ColumnRecord m_ModelColumns;
Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
};
And when i need some extra data associated with each row i use:
template <class T>
class TextListWithRowData: public TextList
{
public:
TextListWithRowData(int nr_of_columns = 1);
~TextListWithRowData();
virtual void add_row(T rowdata, Glib::ustring s, int row = -1);
virtual bool remove_row(int row);
virtual void clear();
virtual T get_row_data(const unsigned int row);
virtual void set_row_data(const unsigned int row, const T data);
private:
vector<T> m_RowData;
};
using this is as easy as:
tl = TextList(3);
tl->add_row("row 0 col 0\trow 0 col 1\trow 0 col 2");
tl->add_row("row 1 col 0\trow 1 col 1\trow 1 col 2");
tl->add_row("row 2 col 0\trow 2 col 1\trow 2 col 2");
I think it would be nice if gtkmm had something like this, kinda like the
how ComboBoxText makes the ComboBox a little simpler.
--
Marco
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]