Re: Editable toggle when multiple model cols in view col
- From: Edd Dawson <edd nunswithguns net>
- To: gtkmm-list gnome org
- Subject: Re: Editable toggle when multiple model cols in view col
- Date: Mon, 18 Sep 2006 20:50:23 +0100
Murray Cumming wrote:
> Yes, I recommend that you try to reduce this to a simple test case. By
doing that you should see what you are doing wrong. It sounds like you
are doing the right thing but I can't guess any more what you might be
doing wrong. It does work.
Here it is. The 3 lines marked *** are where I believe my code is faulty. Two
tree-views are created using identical models. The upper view has a combined
bool/string column whereas the lower one has separate bool/string columns. I
believe that I have connected signals to the toggled slots as analogously as
possible between the two cases but only the signals corresponding to the top
view get fired when I click on the check-boxes.
I've also put the code here:
http://www.nunswithguns.net/guff/test.cpp
// g++ test.cpp -o test -W -Wall -ansi -pedantic `pkg-config --libs --cflags
gtkmm-2.4`
#include <cassert>
#include <string>
#include <gtkmm.h>
struct RecordDef : Gtk::TreeModel::ColumnRecord
{
RecordDef() { add(enabled); add(description); }
Gtk::TreeModelColumn<bool> enabled;
Gtk::TreeModelColumn<std::string> description;
};
class TestWindow : public Gtk::Window
{
public:
TestWindow();
private:
void add_dummy_rows(Glib::RefPtr<Gtk::ListStore> model);
void on_upper_bool_toggled(const Glib::ustring &);
void on_lower_bool_toggled(const Glib::ustring &);
private:
RecordDef record_def_;
Gtk::VBox layout_;
Glib::RefPtr<Gtk::ListStore> upper_model_;
Glib::RefPtr<Gtk::ListStore> lower_model_;
Gtk::TreeView upper_view_;
Gtk::TreeView lower_view_;
};
TestWindow::TestWindow() :
record_def_(),
layout_(),
upper_model_(Gtk::ListStore::create(record_def_)),
lower_model_(Gtk::ListStore::create(record_def_)),
upper_view_(upper_model_),
lower_view_(lower_model_)
{
// Create a single column that contains a check-box and some text.
//Add it to the upper view
Gtk::TreeView::Column* joint_column =
Gtk::manage(new Gtk::TreeView::Column("Joint column"));
joint_column->pack_start(record_def_.enabled, false);
joint_column->pack_start(record_def_.description);
upper_view_.append_column(*joint_column);
// Make the bool/check-box part of the upper view's column editable and
//connect a slot to catch any edits
Gtk::TreeViewColumn *col = upper_view_.get_column(0);
Gtk::CellRendererToggle *rend = dynamic_cast<Gtk::CellRendererToggle *>(
col->get_first_cell_renderer()
);
assert(rend);
rend->property_mode() = Gtk::CELL_RENDERER_MODE_EDITABLE; // ***
rend->property_activatable() = true; // ***
rend->signal_toggled().connect(
sigc::mem_fun(*this, &TestWindow::on_upper_bool_toggled)
); // ***
// Add individual bool/check-box and string columns to the lower view.
// The bool column is to be editable. Connect a slot to catch any edits
lower_view_.append_column_editable("Enabled", record_def_.enabled);
lower_view_.append_column("Description", record_def_.description);
rend = dynamic_cast<Gtk::CellRendererToggle *>(
lower_view_.get_column_cell_renderer(0)
);
assert(rend);
rend->signal_toggled().connect(
sigc::mem_fun(*this, &TestWindow::on_lower_bool_toggled)
);
// Add some dummy data to the models
add_dummy_rows(upper_model_);
add_dummy_rows(lower_model_);
// Add the tree view widgets to the window
layout_.pack_start(upper_view_);
layout_.pack_start(lower_view_);
add(layout_);
show_all_children();
}
void TestWindow::add_dummy_rows(Glib::RefPtr<Gtk::ListStore> model)
{
Gtk::TreeModel::Row row = *model->append();
row[record_def_.enabled] = true;
row[record_def_.description] = "blah blah blah";
row = *model->append();
row[record_def_.enabled] = false;
row[record_def_.description] = "yadda yadda yadda";
}
void TestWindow::on_upper_bool_toggled(const Glib::ustring &)
{
Gtk::MessageDialog("on_upper_bool_toggled!").run();
}
void TestWindow::on_lower_bool_toggled(const Glib::ustring &)
{
Gtk::MessageDialog("on_lower_bool_toggled!").run();
}
int main(int argc, char **argv)
{
Gtk::Main kit(argc, argv);
TestWindow test_window;
Gtk::Main::run(test_window);
return 0;
}
//---
Anyone?
Kind regards,
Edd
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]