forked from qt-creator/qt-creator
FileIteratorWrapper: refactor setPath()
Only call setPath() in hasNext(), the latter is called before any other member method, and setPath() is guarded by a bool to only run a single time. Split some code to a helper function, which will be reused when porting to new QAFEngine API. Change-Id: Ibda0ede18593a3a20729b31e03e994ad2de126de Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -47,7 +47,6 @@ public:
|
||||
if (m_status == State::Ended)
|
||||
return QString();
|
||||
|
||||
setPath();
|
||||
checkStatus();
|
||||
|
||||
if (m_status == State::BaseIteratorEnd) {
|
||||
@@ -75,7 +74,6 @@ public:
|
||||
if (m_status == State::Ended)
|
||||
return FilePath::specialRootPath();
|
||||
|
||||
setPath();
|
||||
checkStatus();
|
||||
return m_baseIterator->currentFileName();
|
||||
}
|
||||
@@ -83,22 +81,26 @@ public:
|
||||
{
|
||||
if (m_status == State::Ended)
|
||||
return QFileInfo(FilePath::specialRootPath());
|
||||
setPath();
|
||||
checkStatus();
|
||||
return m_baseIterator->currentFileInfo();
|
||||
}
|
||||
|
||||
private:
|
||||
QString setStatus() const
|
||||
{
|
||||
// path() can be "/somedir/.." so we need to clean it first.
|
||||
// We only need QDir::cleanPath here, as the path is always
|
||||
// a fs engine path and will not contain scheme:// etc.
|
||||
QString p = QDir::cleanPath(path());
|
||||
if (p.compare(HostOsInfo::root().path(), Qt::CaseInsensitive) == 0)
|
||||
m_status = State::IteratingRoot;
|
||||
return p;
|
||||
}
|
||||
|
||||
void setPath() const
|
||||
{
|
||||
if (!m_hasSetPath) {
|
||||
// path() can be "/somedir/.." so we need to clean it first.
|
||||
// We only need QDir::cleanPath here, as the path is always
|
||||
// a fs engine path and will not contain scheme:// etc.
|
||||
const QString p = QDir::cleanPath(path());
|
||||
if (p.compare(HostOsInfo::root().path(), Qt::CaseInsensitive) == 0)
|
||||
m_status = State::IteratingRoot;
|
||||
|
||||
const QString &p = setStatus();
|
||||
((*m_baseIterator).*get(QAFEITag()))(p);
|
||||
m_hasSetPath = true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user