Re: TreeView path and iter
- From: "Paul Davis" <pjdavis engineering uiowa edu>
- To: johnmb <johnmblackburn googlemail com>
- Cc: gtkmm-list gnome org
- Subject: Re: TreeView path and iter
- Date: Tue, 19 Dec 2006 12:07:06 -0600
Johnmb,
You can use the TreeSelection to do this. In the attached example I
only bothered moving the position in a depth first traversal. I assume
you'll be able to figure out how to make traversing down the tree
based on a second button.
Paul
On 12/19/06, johnmb <johnmblackburn googlemail com> wrote:
John,
> Not exactly sure about the functions you listed, but this is a simple
> recursive function to find a given row.
> ..... code snip
> Its not the best, but it should get the idea acroos.
> Paul
Ah, perhaps I'd better explain more about what I'm trying to do then.
The thing is, I am developing a touch screen menu interface for a machine
and I am using a single gui button to move the treeview row highlight, down
the parent menu items. Hence, I have to use the button clicked signal to
move the row highlight down a single row at a time. At the same time, of
course I need to check that it has reached the last item and make it wrap
back to the first item. I use another button to expand the current row
into the list of children and move down that.
Hence, it is not JUST the model I am navigating but the treeview as well.
regards
John
--
View this message in context: http://www.nabble.com/TreeView-path-and-iter-tf2839301.html#a7943432
Sent from the Gtkmm mailing list archive at Nabble.com.
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Paul Davis pjdavis engineering uiowa edu
* Copyright: University of Iowa 2006
*
* Filename: tree_movement.cc
* Created: 2006-Dec-18 02:50:36 PM
* Modified: 2006-Dec-19 12:04:46 PM
*/
#include <gtkmm.h>
class Editor : public Gtk::Window
{
public:
Editor()
{
set_title( "TreeSelection Example" ) ;
set_size_request( 400, 400 ) ;
Gtk::VBox* vbox = Gtk::manage( new Gtk::VBox() ) ;
add( *vbox ) ;
mTreeView = Gtk::manage( new Gtk::TreeView() ) ;
vbox->add( *mTreeView ) ;
Gtk::Button* button = Gtk::manage( new Gtk::Button( "Move Down" ) ) ;
button->signal_clicked().connect( sigc::mem_fun( *this, &Editor::on_next_clicked ) ) ;
vbox->add( *button ) ;
mTreeModel = Gtk::TreeStore::create(mTreeColumns);
mTreeView->set_model(mTreeModel);
mTreeSelection = mTreeView->get_selection() ;
Gtk::TreeModel::Row root = *(mTreeModel->append());
root[mTreeColumns.mNodeName] = "Root";
Gtk::TreeModel::Row row = *(mTreeModel->append( root->children() ) ) ;
row[mTreeColumns.mNodeName] = "Child 1" ;
row = *( mTreeModel->append( root->children() ) ) ;
row[mTreeColumns.mNodeName] = "Child 2" ;
mTreeView->append_column("Nodes", mTreeColumns.mNodeName );
mTreeSelection->select( root ) ;
show_all_children() ;
}
private:
void on_next_clicked()
{
Gtk::TreeModel::iterator iter = mTreeSelection->get_selected() ;
if( !iter )
{
iter = mTreeModel->children().begin() ;
mTreeSelection->select( iter ) ;
return ;
}
Gtk::TreeModel::Row row = *iter ;
Gtk::TreeModel::Children children = row.children() ;
if( children.size() > 0 )
{
Gtk::TreePath path( iter ) ;
mTreeView->expand_row( path, false ) ;
iter = children.begin() ;
mTreeSelection->select( iter ) ;
return ;
}
Gtk::TreeModel::iterator next = iter ;
next++ ;
if( next )
{
mTreeSelection->select( next ) ;
return ;
}
Gtk::TreeModel::iterator parent = *(iter)->parent() ;
next = parent++ ;
if( next )
{
mTreeSelection->select( next ) ;
return ;
}
next = mTreeModel->children().begin() ;
mTreeSelection->select( next ) ;
return ;
}
class TreeColumns : public Gtk::TreeModel::ColumnRecord
{
public:
TreeColumns()
{
add(mNodeName);
}
Gtk::TreeModelColumn<Glib::ustring> mNodeName;
} ;
TreeColumns mTreeColumns;
Gtk::TreeView* mTreeView ;
Glib::RefPtr<Gtk::TreeStore> mTreeModel;
Glib::RefPtr<Gtk::TreeSelection> mTreeSelection ;
} ;
int
main(int argc, char* argv[])
{
Gtk::Main kit(argc, argv);
Editor e ;
Gtk::Main::run( e );
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]