![]() |
| ||
Classes - Annotated - Tree - Functions - Home - Structure |
The QListViewItemIterator class provides an iterator for collections of QListViewItems. More...
#include <qlistview.h>
The QListViewItemIterator class provides an iterator for collections of QListViewItems.
Construct an instance of a QListViewItemIterator, with either a QListView* or a QListViewItem* as argument, to operate on the tree of QListViewItems.
A QListViewItemIterator iterates over all items of a list view. This means that it always makes the first child of the current item the new current item. If there is no child, the next sibling becomes the new current item; and if there is no next sibling, the next sibling of the parent becomes current.
The following example function gets a list of all the items that have been selected by the user, storing pointers to the items in a QPtrList:
QPtrList<QListViewItem> * getSelectedItems( QListView *lv ) { if ( !lv ) return 0; // Create the list QPtrList<QListViewItem> *lst = new QPtrList<QListViewItem>; lst->setAutoDelete( FALSE ); // Create an iterator and give the list view as argument QListViewItemIterator it( lv ); // iterate through all items of the list view for ( ; it.current(); ++it ) { if ( it.current()->isSelected() ) lst->append( it.current() ); } return lst; }
A QListViewItemIterator provides a convenient and easy way to traverse a hierarchical QListView.
Multiple QListViewItemIterators can operate on the tree of QListViewItems. A QListView knows about all iterators operating on its QListViewItems. So when a QListViewItem gets removed all iterators that point to this item are updated and point to the following item.
See also QListView and QListViewItem.
Examples: addressbook/centralwidget.cpp, checklists/checklists.cpp, dirview/dirview.cpp and network/ftpclient/ftpview.cpp.
Postfix ++ makes the next item in the QListViewItem tree of the QListView of the iterator the current item and returns the item which was previously current.
The new current item (or null, if the new current item is null) is returned.
Postfix -- makes the previous item in the QListViewItem tree of the QListView of the iterator the current item and returns the item.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.
Copyright © 2001 Trolltech | Trademarks | Qt version 3.0.0-beta2
|