* Fetch next index. */
| 97 | * Fetch next index. |
| 98 | */ |
| 99 | void FileProxyModelIterator::fetchNext() |
| 100 | { |
| 101 | int count = 0; |
| 102 | while (!m_aborted) { |
| 103 | if (m_nodes.isEmpty()) { |
| 104 | if (m_rootIndexes.isEmpty()) { |
| 105 | break; |
| 106 | } |
| 107 | m_nodes.push(m_rootIndexes.takeFirst()); |
| 108 | } |
| 109 | m_nextIdx = m_nodes.top(); |
| 110 | if (m_nextIdx.isValid()) { |
| 111 | if (m_model->isDir(m_nextIdx) && m_model->canFetchMore(m_nextIdx)) { |
| 112 | connect(m_model, &FileProxyModel::sortingFinished, |
| 113 | this, &FileProxyModelIterator::onDirectoryLoaded); |
| 114 | m_model->fetchMore(m_nextIdx); |
| 115 | return; |
| 116 | } |
| 117 | if (++count >= 10) { |
| 118 | // Avoid spinning too long to keep the GUI responsive. |
| 119 | QTimer::singleShot(0, this, &FileProxyModelIterator::fetchNext); |
| 120 | return; |
| 121 | } |
| 122 | m_nodes.pop(); |
| 123 | ++m_numDone; |
| 124 | const int numRows = m_model->rowCount(m_nextIdx); |
| 125 | QStack<QPersistentModelIndex> childNodes; |
| 126 | childNodes.reserve(numRows); |
| 127 | for (int row = numRows - 1; row >= 0; --row) { |
| 128 | childNodes.push(m_model->index(row, 0, m_nextIdx)); |
| 129 | } |
| 130 | std::stable_sort(childNodes.begin(), childNodes.end(), |
| 131 | [](const QPersistentModelIndex& lhs, |
| 132 | const QPersistentModelIndex& rhs) { |
| 133 | return lhs.data().toString().compare(rhs.data().toString()) > 0; |
| 134 | }); |
| 135 | m_nodes += childNodes; |
| 136 | emit nextReady(m_nextIdx); |
| 137 | } else { |
| 138 | m_nodes.pop(); |
| 139 | } |
| 140 | } |
| 141 | m_nodes.clear(); |
| 142 | m_rootIndexes.clear(); |
| 143 | m_nextIdx = QPersistentModelIndex(); |
| 144 | emit nextReady(m_nextIdx); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Called when the gatherer thread has finished to load. |
nothing calls this directly
no test coverage detected