TreeModel with Gtk::Builder



I have build a TreeView in Glade 3 for Gtk::Builder.  I have been able
to setup the TreeView in Glade 3 with columns and data, and when I
load the xml file with Gtk::Builder it displays everything
beautifully.  That is all thanks to this tutorial:
http://tadeboro.blogspot.com/2009/04/creatin-gtktreeview-with-glade-3.html

But now I want to add my own data to the ListStore.  This is how I did
it and it works, but I feel like defining the TreeModel in the code is
redundant.

class TestModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:

       TestModelColumns()
       { add(mText); add(mValue); add(mDesc); }

       Gtk::TreeModelColumn<Glib::ustring> mText;
       Gtk::TreeModelColumn<int> mValue;
       Gtk::TreeModelColumn<Glib::ustring> mDesc;
};

TestModelColumns testMColumns;

Glib::RefPtr<Gtk::Builder> refXml;
Glib::RefPtr<Gtk::ListStore> liststore;

refXml = Gtk::Builder::create_from_file("test.xml");

Glib::RefPtr<Glib::Object> obj = refXml->get_object("liststore");

liststore = Glib::RefPtr<Gtk::ListStore>::cast_static(obj);

Gtk::TreeModel::Row row;
row = *(refTestList->append());

row[testMColumns.mText] = "Some Text String";
row[testMColumns.mValue] = 34;
row[testMColumns.mDesc] = "Random Description";

Is there a way to pull the TreeModel from the XML file and not have to
defined my TreeModel two times?

Thanks,
Dustin Moore


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