Browse Source

Add ModelIndexIterator::restart

Girish Ramakrishnan 8 years ago
parent
commit
43eb010016
2 changed files with 10 additions and 3 deletions
  1. 9 3
      src/dataproviders/modelindexiterator.cpp
  2. 1 0
      src/dataproviders/modelindexiterator.h

+ 9 - 3
src/dataproviders/modelindexiterator.cpp

@@ -34,9 +34,7 @@ void ModelIndexIterator::setRootIndex(const QVariant &index)
     if (rootIndex == m_rootIndex)
         return;
     m_rootIndex = rootIndex;
-    m_state = NotStarted;
-    m_stack.clear();
-    m_stack.push(m_rootIndex);
+    restart();
     emit rootIndexChanged();
 }
 
@@ -45,6 +43,14 @@ QVariant ModelIndexIterator::rootIndex() const
     return QVariant::fromValue<QModelIndex>(m_rootIndex);
 }
 
+void ModelIndexIterator::restart()
+{
+    m_state = NotStarted;
+    m_stack.clear();
+    m_stack.push(m_rootIndex);
+    m_currentIndex = QModelIndex();
+}
+
 void ModelIndexIterator::setFilterRole(const QString &role)
 {
     if (m_filterRole == role)

+ 1 - 0
src/dataproviders/modelindexiterator.h

@@ -56,6 +56,7 @@ public:
     QVariant data() const;
 
     Q_INVOKABLE bool next();
+    Q_INVOKABLE void restart();
 
 signals:
     void rootIndexChanged();