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

TQListViewItemIterator Class Reference

The TQListViewItemIterator class provides an iterator for collections of TQListViewItems. More...

#include <tqlistview.h>

List of all member functions.

Public Members


Detailed Description

The TQListViewItemIterator class provides an iterator for collections of TQListViewItems.

Construct an instance of a TQListViewItemIterator, with either a TQListView* or a TQListViewItem* as argument, to operate on the tree of TQListViewItems, starting from the argument.

A TQListViewItemIterator 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 TQPtrList:

    TQPtrList<TQListViewItem> lst;
    TQListViewItemIterator it( myListView );
    while ( it.current() ) {
        if ( it.current()->isSelected() )
            lst.append( it.current() );
        ++it;
    }
    

An alternative approach is to use an IteratorFlag:

    TQPtrList<TQListViewItem> lst;
    TQListViewItemIterator it( myListView, TQListViewItemIterator::Selected );
    while ( it.current() ) {
        lst.append( it.current() );
        ++it;
    }
    

A TQListViewItemIterator provides a convenient and easy way to traverse a hierarchical TQListView.

Multiple TQListViewItemIterators can operate on the tree of TQListViewItems. A TQListView knows about all iterators operating on its TQListViewItems. So when a TQListViewItem 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 TQListView, TQListViewItem, and Advanced Widgets.


Member Type Documentation

TQListViewItemIterator::IteratorFlag

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


Member Function Documentation

TQListViewItemIterator::TQListViewItemIterator ()

Constructs an empty iterator.

TQListViewItemIterator::TQListViewItemIterator ( TQListViewItem * item )

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

TQListViewItemIterator::TQListViewItemIterator ( TQListViewItem * item, int iteratorFlags )

Constructs an iterator for the TQListView 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 TQListViewItemIterator::IteratorFlag.

TQListViewItemIterator::TQListViewItemIterator ( const TQListViewItemIterator & it )

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

TQListViewItemIterator::TQListViewItemIterator ( TQListView * lv )

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

TQListViewItemIterator::TQListViewItemIterator ( TQListView * lv, int iteratorFlags )

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

See also TQListViewItemIterator::IteratorFlag.

TQListViewItemIterator::~TQListViewItemIterator ()

Destroys the iterator.

TQListViewItem * TQListViewItemIterator::current () const

Returns iterator's current item.

Examples: addressbook/centralwidget.cpp, checklists/checklists.cpp, and dirview/dirview.cpp.

TQListViewItem * TQListViewItemIterator::operator* ()

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

TQListViewItemIterator & TQListViewItemIterator::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 TQListView is 0.

const TQListViewItemIterator TQListViewItemIterator::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.

TQListViewItemIterator & TQListViewItemIterator::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.

TQListViewItemIterator & TQListViewItemIterator::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 TQListView is 0.

const TQListViewItemIterator TQListViewItemIterator::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.

TQListViewItemIterator & TQListViewItemIterator::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.

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

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

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8