QMutableListIterator Class ReferenceThe QMutableListIterator class provides a Java-style non-const iterator for QList and QQueue. Далее... #include <QMutableListIterator>
Открытые функции
Подробное описаниеThe QMutableListIterator class provides a Java-style non-const iterator for QList and QQueue. QList has both Java-style iterators and STL-style iterators. Итераторы в стиле Java более высокоуровневые и простые в использовании, чем итераторы в стиле STL; с другой стороны, они несколько менее эффективны. Альтернативой использованию итераторов является использование индекса позиций. Most QList member functions take an index as their first parameter, making it possible to access, insert, and remove items without using iterators. QMutableListIterator<T> allows you to iterate over a QList<T> (or a QQueue<T>) and modify the list. If you don't want to modify the list (or have a const QList), use the slightly faster QListIterator<T> instead. The QMutableListIterator constructor takes a QList as argument. After construction, the iterator is located at the very beginning of the list (before the first item). Вот, как последовательно перебрать все элементы: QList<float> list; ... QMutableListIterator<float> i(list); while (i.hasNext()) qDebug() << i.next(); The next() function returns the next item in the list and advances the iterator. В отличие от итераторов в стиле STL, итераторы в стиле Java указывают между элементами, а не на сами элементы. Первый вызов next() перемещает итератор в позицию между первым и вторым элементами и возвращает первый элемент; второй вызов next() перемещает итератор в позицию между вторым и третьим элементами, возвращая второй элемент; и т.д. Вот, как последовательно перебрать все элементы в обратном порядке: QMutableListIterator<float> i(list); i.toBack(); while (i.hasPrevious()) qDebug() << i.previous(); Если вы хотите найти все вхождения определённого значения, используйте findNext() или findPrevious() в цикле. If you want to remove items as you iterate over the list, use remove(). If you want to modify the value of an item, use setValue(). If you want to insert a new item in the list, use insert(). Пример: QMutableListIterator<int> i(list); while (i.hasNext()) { int val = i.next(); if (val < 0) { i.setValue(-val); } else if (val == 0) { i.remove(); } } The example traverses a list, replacing negative numbers with their absolute values, and eliminating zeroes. Only one mutable iterator can be active on a given list at any time. Furthermore, no changes should be done directly to the list while the iterator is active (as opposed to through the iterator), since this could invalidate the iterator and lead to undefined behavior. See also QListIterator and QList::iterator. Описание функций-членов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). Смотрите также operator=(). QMutableListIterator::~QMutableListIterator ()Destroys the iterator. Смотрите также operator=(). bool QMutableListIterator::findNext ( const T & value )Ищет вперед значение value, начиная с текущей позиции итератора. Возвращает true, если value найдено; в противном случае возвращает false. После вызова, если значение value было найдено, итератор устанавливается сразу после соответствующего элемента; в противном случае итератор устанавливается позади контейнера. Смотрите также findPrevious(). bool QMutableListIterator::findPrevious ( const T & value )Ищет назад значение value, начиная с текущей позиции итератора. Возвращает true, если value найдено; в противном случае возвращает false. После вызова, если значение value было найдено, итератор устанавливается сразу перед соответствующим элементом; в противном случае итератор устанавливается перед контейнером. Смотрите также findNext(). bool QMutableListIterator::hasNext () constВозвращает true, если есть хотя бы один элемент впереди итератора, т.е. итератор не позади контейнера; в противном случае возвращает false. Смотрите также hasPrevious() и next(). bool QMutableListIterator::hasPrevious () constВозвращает true, если есть хотя бы один элемент позади итератора, т.е. итератор не впереди контейнера; в противном случае возвращает false. Смотрите также hasNext() и previous(). void QMutableListIterator::insert ( const T & value )Inserts value at the current iterator position. After the call, the iterator is located just after the inserted item. See also remove() and setValue(). T & QMutableListIterator::next ()Returns a reference to the next item, and advances the iterator by one position. Вызов этой функции на итераторе, расположенном позади контейнера, приводит к неопределённым результатам. Смотрите также hasNext(), peekNext() и previous(). T & QMutableListIterator::peekNext () constReturns a reference to the next item, without moving the iterator. Вызов этой функции на итераторе, расположенном позади контейнера, приводит к неопределённым результатам. Смотрите также hasNext(), next() и peekPrevious(). T & QMutableListIterator::peekPrevious () constReturns a reference to the previous item, without moving the iterator. Вызов этой функции на итераторе, расположенном перед контейнером, приводит к неопределённым результатам. Смотрите также hasPrevious(), previous() и peekNext(). T & QMutableListIterator::previous ()Returns a reference to the previous item and moves the iterator back by one position. Вызов этой функции на итераторе, расположенном перед контейнером, приводит к неопределённым результатам. Смотрите также hasPrevious(), peekPrevious() и next(). void QMutableListIterator::remove ()Removes the last item that was jumped over using one of the traversal functions (next(), previous(), findNext(), findPrevious()). Пример: QMutableListIterator<int> i(list); while (i.hasNext()) { int val = i.next(); if (val < -32768 || val > 32767) i.remove(); } See also insert() and setValue(). void QMutableListIterator::setValue ( const T & value ) constReplaces the value of the last item that was jumped over using one of the traversal functions with value. The traversal functions are next(), previous(), findNext(), and findPrevious(). Пример: QMutableListIterator<double> i(list); while (i.hasNext()) { double val = i.next(); i.setValue(sqrt(val)); } See also value(), remove(), and insert(). void QMutableListIterator::toBack ()Перемещает итератор позади контейнера (после последнего элемента). Смотрите также toFront() и previous(). void QMutableListIterator::toFront ()Перемещает итератор впереди контейнера (перед первым элементом). Смотрите также toBack() и next(). const T & QMutableListIterator::value () constReturns the value of the last item that was jumped over using one of the traversal functions (next(), previous(), findNext(), findPrevious()). After a call to next() or findNext(), value() is equivalent to peekPrevious(). After a call to previous() or findPrevious(), value() is equivalent to peekNext(). Смотрите также setValue(). T & QMutableListIterator::value ()Это перегруженная функция. Returns a non-const reference to the value of the last item that was jumped over using one of the traversal functions. QMutableListIterator & QMutableListIterator::operator= ( QList<T> & list )Makes the iterator operate on list. The iterator is set to be at the front of the list (before the first item). |
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |