6.0.0-rc4Source

QMutableListIterator Class

template <typename T> class QMutableListIterator

The QMutableListIterator class provides a Java-style non-const iterator for QList. More…

Header#include <QMutableListIterator>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Functions

QMutableListIterator(QList<T> &list)
QMutableListIterator &operator=(QList<T> &list)
voidtoFront()
voidtoBack()
boolhasNext() const
boolhasPrevious() const
T &next()
T &previous()
T &peekNext() const
T &peekPrevious() const
T &value() const
voidsetValue(const T &v)
voidremove()
voidinsert(const T &v)
boolfindNext(const T &v)
boolfindPrevious(const T &v)

Detailed Description

QMutableListIterator<T> iterates over a list and can modify it. Like QListIterator it points between items; in addition, value(), setValue() and remove() act on the item that was last jumped over by next() or previous(), and insert() adds an item at the iterator position.

QList<int> list = {1, 2, 3, 4};
QMutableListIterator<int> it(list);
while (it.hasNext()) {
    if (it.next() % 2 == 0)
        it.remove();
}

The iterator is index-based, so inserting or removing items through it keeps it valid. Modifying the list by other means while an iterator is in use is not supported. QMutableVectorIterator is an alias of this class.

See also QListIterator and QAssocMutableIterator.

Differences from Qt

The container type is always QList<T>.

Member Function Documentation

[explicit] QMutableListIterator::QMutableListIterator(QList<T> &list)

Constructs an iterator for traversing list. The iterator is set to be at the front of the list, before the first item.

See also toFront().

bool QMutableListIterator::findNext(const T &v)

Searches for v forward from the iterator position. Returns true if an item equal to v is found, leaving the iterator just after it; otherwise returns false and leaves the iterator at the back of the list.

See also findPrevious().

bool QMutableListIterator::findPrevious(const T &v)

Searches for v backward from the iterator position. Returns true if an item equal to v is found, leaving the iterator just before it; otherwise returns false and leaves the iterator at the front of the list.

See also findNext().

bool QMutableListIterator::hasNext() const

Returns true if there is at least one item ahead of the iterator; otherwise returns false.

See also hasPrevious() and next().

bool QMutableListIterator::hasPrevious() const

Returns true if there is at least one item behind the iterator; otherwise returns false.

See also hasNext() and previous().

void QMutableListIterator::insert(const T &v)

Inserts v at the iterator position and advances the iterator past it, so the next call to next() returns the item that followed the insertion point.

See also remove() and setValue().

T & QMutableListIterator::next()

Returns a reference to the next item and advances the iterator by one position. Calling this function when the iterator is at the back of the list is undefined.

See also hasNext(), peekNext() and previous().

QMutableListIterator & QMutableListIterator::operator=(QList<T> &list)

Makes the iterator operate on list and moves it to the front of the list. Returns a reference to this iterator.

T & QMutableListIterator::peekNext() const

Returns a reference to the next item without moving the iterator. Calling this function when the iterator is at the back of the list is undefined.

See also hasNext(), next() and peekPrevious().

T & QMutableListIterator::peekPrevious() const

Returns a reference to the previous item without moving the iterator. Calling this function when the iterator is at the front of the list is undefined.

See also hasPrevious(), previous() and peekNext().

T & QMutableListIterator::previous()

Returns a reference to the previous item and moves the iterator back by one position. Calling this function when the iterator is at the front of the list is undefined.

See also hasPrevious(), peekPrevious() and next().

void QMutableListIterator::remove()

Removes the item that was last jumped over by next() or previous(). Does nothing if there is no such item, or if it has already been removed.

See also setValue() and insert().

void QMutableListIterator::setValue(const T &v)

Replaces the item that was last jumped over by next(), previous() or insert() with v. Does nothing if there is no such item.

See also value() and remove().

void QMutableListIterator::toBack()

Moves the iterator to the back of the list, after the last item.

See also toFront() and previous().

void QMutableListIterator::toFront()

Moves the iterator to the front of the list, before the first item.

See also toBack() and next().

T & QMutableListIterator::value() const

Returns a reference to the item that was last jumped over by next(), previous() or insert(). The iterator must have jumped over an item, and the item must not have been removed.

See also setValue() and remove().