forked from qt-creator/qt-creator
FileIteratorWrapper: simplify the code
Setting m_status to BaseIteratorEnd should only be done in hasNext(),
because the latter is always called first, before any other member
function.
Change-Id: Ie55518a850655730fb760226d58c4fb171a7f2e1
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
(cherry picked from commit 1ddc71fcda
)
This commit is contained in:
@@ -47,8 +47,6 @@ public:
|
|||||||
if (m_status == State::Ended)
|
if (m_status == State::Ended)
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
checkStatus();
|
|
||||||
|
|
||||||
if (m_status == State::BaseIteratorEnd) {
|
if (m_status == State::BaseIteratorEnd) {
|
||||||
m_status = State::Ended;
|
m_status = State::Ended;
|
||||||
return FilePath::specialRootName();
|
return FilePath::specialRootName();
|
||||||
@@ -62,27 +60,26 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
setPath();
|
setPath();
|
||||||
checkStatus();
|
|
||||||
|
|
||||||
if (m_status == State::BaseIteratorEnd)
|
const bool res = m_baseIterator->hasNext();
|
||||||
|
if (m_status == State::IteratingRoot && !res) {
|
||||||
|
// m_baseIterator finished, but we need to advance one last time, so that
|
||||||
|
// e.g. next() and currentFileName() return FilePath::specialRootPath().
|
||||||
|
m_status = State::BaseIteratorEnd;
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return m_baseIterator->hasNext();
|
return res;
|
||||||
}
|
}
|
||||||
QString currentFileName() const override
|
QString currentFileName() const override
|
||||||
{
|
{
|
||||||
if (m_status == State::Ended)
|
return m_status == State::Ended ? FilePath::specialRootPath()
|
||||||
return FilePath::specialRootPath();
|
: m_baseIterator->currentFileName();
|
||||||
|
|
||||||
checkStatus();
|
|
||||||
return m_baseIterator->currentFileName();
|
|
||||||
}
|
}
|
||||||
QFileInfo currentFileInfo() const override
|
QFileInfo currentFileInfo() const override
|
||||||
{
|
{
|
||||||
if (m_status == State::Ended)
|
return m_status == State::Ended ? QFileInfo(FilePath::specialRootPath())
|
||||||
return QFileInfo(FilePath::specialRootPath());
|
: m_baseIterator->currentFileInfo();
|
||||||
checkStatus();
|
|
||||||
return m_baseIterator->currentFileInfo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -106,15 +103,6 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkStatus() const
|
|
||||||
{
|
|
||||||
if (m_status == State::IteratingRoot) {
|
|
||||||
if (m_baseIterator->hasNext() == false) {
|
|
||||||
m_status = State::BaseIteratorEnd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<QAbstractFileEngineIterator> m_baseIterator;
|
std::unique_ptr<QAbstractFileEngineIterator> m_baseIterator;
|
||||||
mutable bool m_hasSetPath{false};
|
mutable bool m_hasSetPath{false};
|
||||||
|
Reference in New Issue
Block a user