Strange Gtk::TreeStore behaviour



Hi,

I am encountering an unexpected behavior in Gtk::TreeStore. I am
connecting a handler to signal_row_expanded to refresh the row
contents. To do this, I am simply removing the old contents and adding
children again. But when I expand the row in GUI, it doesn't get
expanded at all to show the children!

The following is the change to the book's tree view code
(examples/book/treeview/tree directory)

examplewindow.h
class ExampleWindow
{
   ...
    // handler
    void on_row_expanded(const Gtk::TreeModel::iterator & iter, const
Gtk::TreeModel::Path & path);

protected:
   void add_children(const Gtk::TreeModel::Row & row);
   void remove_children(const Gtk::TreeModel::Row & row);
  ...
}

examplewindow.cc
void ExampleWindow::on_row_expanded(const Gtk::TreeModel::iterator &
iter, const Gtk::TreeModel::Path & path)
{
    remove_children(*iter);
    add_children(*iter);
}
void ExampleWindow::remove_children(const Gtk::TreeModel::Row & row)
{
    while(!row.children().empty())
        m_refTreeModel->erase(row.children().begin());
}

void ExampleWindow::add_children(const Gtk::TreeModel::Row & row)
{
    // add some children
    Gtk::TreeModel::Row crow;
    crow = *( m_refTreeModel->append(row.children()) );
    crow[m_Columns.m_col_name] = row[m_Columns.m_col_name] + " child1";
    crow = *( m_refTreeModel->append(row.children()) );
    crow[m_Columns.m_col_name] = row[m_Columns.m_col_name] + " child2";
    crow = *( m_refTreeModel->append(row.children()) );
    crow[m_Columns.m_col_name] = row[m_Columns.m_col_name] + " child3";
}

The end result should be when I expand a row, it should show only the
above three children. While the GUI doesn't expand the row, the
children do get removed and added. Also, add_children() and
remove_children() are working as expected in isolation.

Any idea whats going wrong here?

With thanks
Ram



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