Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

Q3ListViewItemIterator Class Reference

The Q3ListViewItemIterator class provides an iterator for collections of Q3ListViewItems. More...

#include <Q3ListViewItemIterator>

This class is part of the Qt 3 compatibility library. It is provided to keep old source code working. We strongly advise against using it in new code. See the Porting Guide for more information.

Public Types

Public Functions


Detailed Description

The Q3ListViewItemIterator class provides an iterator for collections of Q3ListViewItems.

Construct an instance of a Q3ListViewItemIterator, with either a Q3ListView* or a Q3ListViewItem* as argument, to operate on the tree of Q3ListViewItems, starting from the argument.

A Q3ListViewItemIterator iterates over all the items from its starting point. 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 creates a list of all the items that have been selected by the user, storing pointers to the items in a QList:

    QList<Q3ListViewItem *> lst;
    Q3ListViewItemIterator it(myListView);
    while (it.current()) {
        if (it.current()->isSelected())
            lst.append(it.current());
        ++it;
    }

An alternative approach is to use an IteratorFlag:

    QList<Q3ListViewItem *> lst;
    Q3ListViewItemIterator it(myListView, Selected);
    while (it.current()) {
        lst.append(it.current());
        ++it;
    }

A Q3ListViewItemIterator provides a convenient and easy way to traverse a hierarchical Q3ListView.

Multiple Q3ListViewItemIterators can operate on the tree of Q3ListViewItems. A Q3ListView knows about all iterators operating on its Q3ListViewItems. So when a Q3ListViewItem gets removed all iterators that point to this item are updated and point to the following item if possible, otherwise to a valid item before the current one or to 0. Note however that deleting the parent item of an item that an iterator points to is not safe.

See also Q3ListView and Q3ListViewItem.


Member Type Documentation

enum Q3ListViewItemIterator::IteratorFlag

These flags can be passed to a Q3ListViewItemIterator constructor (OR-ed together if more than one is used), so that the iterator will only iterate over items that match the given flags.

Q3ListViewItemIterator::Visible 
Q3ListViewItemIterator::Invisible 
Q3ListViewItemIterator::Selected 
Q3ListViewItemIterator::Unselected 
Q3ListViewItemIterator::Selectable 
Q3ListViewItemIterator::NotSelectable 
Q3ListViewItemIterator::DragEnabled 
Q3ListViewItemIterator::DragDisabled 
Q3ListViewItemIterator::DropEnabled 
Q3ListViewItemIterator::DropDisabled 
Q3ListViewItemIterator::Expandable 
Q3ListViewItemIterator::NotExpandable 
Q3ListViewItemIterator::Checked 
Q3ListViewItemIterator::NotChecked 

Member Function Documentation

Q3ListViewItemIterator::Q3ListViewItemIterator ()

Constructs an empty iterator.

Q3ListViewItemIterator::Q3ListViewItemIterator ( Q3ListViewItem * item )

Constructs an iterator for the Q3ListView that contains the item. The current iterator item is set to point to the item.

Q3ListViewItemIterator::Q3ListViewItemIterator ( Q3ListViewItem * item, int iteratorFlags )

Constructs an iterator for the Q3ListView that contains the item using the flags iteratorFlags. The current iterator item is set to point to item or the next matching item if item doesn't match the flags.

See also Q3ListViewItemIterator::IteratorFlag.

Q3ListViewItemIterator::Q3ListViewItemIterator ( const Q3ListViewItemIterator & it )

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

Q3ListViewItemIterator::Q3ListViewItemIterator ( Q3ListView * lv )

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

Q3ListViewItemIterator::Q3ListViewItemIterator ( Q3ListView * lv, int iteratorFlags )

Constructs an iterator for the Q3ListView lv with the flags iteratorFlags. The current iterator item is set to point on the first child (Q3ListViewItem) of lv that matches the flags.

See also Q3ListViewItemIterator::IteratorFlag.

Q3ListViewItemIterator::~Q3ListViewItemIterator ()

Destroys the iterator.

Q3ListViewItem * Q3ListViewItemIterator::current () const

Returns iterator's current item.

Q3ListViewItem * Q3ListViewItemIterator::operator* ()

Dereference operator. Returns a reference to the current item. The same as current().

Q3ListViewItemIterator & Q3ListViewItemIterator::operator++ ()

Prefix ++. Makes the next item the new current item and returns it. Returns 0 if the current item is the last item or the Q3ListView is 0.

const Q3ListViewItemIterator Q3ListViewItemIterator::operator++ ( int )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Postfix ++. Makes the next item the new current item and returns the item that was the current item.

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

Sets the current item to the item j positions after the current item. If that item is beyond the last item, the current item is set to 0. Returns the current item.

Q3ListViewItemIterator & Q3ListViewItemIterator::operator-- ()

Prefix --. Makes the previous item the new current item and returns it. Returns 0 if the current item is the first item or the Q3ListView is 0.

const Q3ListViewItemIterator Q3ListViewItemIterator::operator-- ( int )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Postfix --. Makes the previous item the new current item and returns the item that was the current item.

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

Sets the current item to the item j positions before the current item. If that item is before the first item, the current item is set to 0. Returns the current item.

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

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


Copyright © 2004 Trolltech Trademarks
Qt 4.0.0-b1