HomeHome

ClassesAnnotated - TreeFunctionsHomeStructure

QListViewItemIterator Class Reference


The QListViewItemIterator class provides an iterator for collections of QListViewItems More...

#include <qlistview.h>

List of all member functions.

Public Members


Detailed Description

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 listview. This means ++it makes always the first child of the current item the new current one. If there is no child, the next sibling gets the new current item, and if there is no next sibling, the next sibling of the parent is set to current.

Example:

Often you want to get all items, which were selected by a user. Here is an example which does this and stores the pointers to all selected items in a QList.

  // Somewhere a listview is generated like this
  QListView *lv = new QListView(this);
  // Enable multiselection
  lv->setMultiSelection( TRUE );

  // Insert the items here

  // ...

  // This function is called to get a list of the selected items of a listview
  QList<QListViewItem> * getSelectedItems( QListView *lv ) {
    if ( !lv )
      return 0;

    // Create the list
    QList<QListViewItem> *lst = new QList<QListViewItem>;
    lst->setAutoDelete( FALSE );

    // Create an iterator and give the listview as argument
    QListViewItemIterator it( lv );
    // iterate through all items of the listview
    for ( ; it.current(); ++it ) {
      if ( it.current()->isSelected() )
        lst->append( it.current() );
    }

    return lst;
  }

Using a QListViewItemIterator is a convenient way to traverse the tree of QListViewItems of a QListView. It makes especially operating on a hierarchical QListView easy.

Also, multiple QListViewItemIterators can operate on the tree of QListViewItems. A QListView knows about all iterators which are operating on its QListViewItems. So when a QListViewItem gets removed, all iterators that point to this item get updated and point to the new current item after that.

See also QListView and QListViewItem.


Member Function Documentation

QListViewItemIterator::QListViewItemIterator ()

Constructs an empty iterator.

QListViewItemIterator::QListViewItemIterator ( QListView * lv )

Constructs an iterator for the QListView lv. The current iterator item is set to point on the first child ( QListViewItem ) of lv.

QListViewItemIterator::QListViewItemIterator ( QListViewItem * item )

Constructs an iterator for the QListView of the item. The current iterator item is set to point on the item.

QListViewItemIterator::QListViewItemIterator ( const QListViewItemIterator & it )

Constructs an iterator for the same QListView as it. The current iterator item is set to point on the current item of it.

QListViewItemIterator::~QListViewItemIterator ()

Destroys the iterator.

QListViewItem * QListViewItemIterator::current () const

Returns a pointer to the current item of the iterator.

QListViewItemIterator & QListViewItemIterator::operator++ ()

Prefix ++ makes the next item in the QListViewItem tree of the QListView of the iterator the current item and returns it. If the current item was the last item in the QListView or null, null is returned.

const QListViewItemIterator QListViewItemIterator::operator++ ( int )

Postfix ++ makes the next item in the QListViewItem tree of the QListView of the iterator the current item and returns the item, which was the current one before.

QListViewItemIterator & QListViewItemIterator::operator+= ( int j )

Sets the current item to the item j positions after the current item in the QListViewItem hierarchy. If this item is beyond the last item, the current item is set to null.

The new current item (or null, if the new current item is null) is returned.

QListViewItemIterator & QListViewItemIterator::operator-- ()

Prefix -- makes the previous item in the QListViewItem tree of the QListView of the iterator the current item and returns it. If the current item was the last first in the QListView or null, null is returned.

const QListViewItemIterator QListViewItemIterator::operator-- ( int )

Postfix -- makes the previous item in the QListViewItem tree of the QListView of the iterator the current item and returns the item, which was the current one before.

QListViewItemIterator & QListViewItemIterator::operator-= ( int j )

Sets the current item to the item j positions before the current item in the QListViewItem hierarchy. If this item is above the first item, the current item is set to null. The new current item (or null, if the new current item is null) is returned.

QListViewItemIterator & QListViewItemIterator::operator= ( const QListViewItemIterator & it )

Assignment. Makes a copy of it and returns a reference to its iterator.


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.


Copyright © 2000 TrolltechTrademarks
Qt version 2.2.1