summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2019-07-23 18:30:00 +0200
committerhjk <hjk@qt.io>2019-07-24 07:18:17 +0000
commit2c0b69cdc5c77d9376b539ac8e36dc304d8ea27b (patch)
treeb413e4f3a1f28b2701bc8de59c8541c7455c5404
parent4216702d954976ee050aa05c48274a1023a5f121 (diff)
downloadqt-creator-2c0b69cdc5c77d9376b539ac8e36dc304d8ea27b.tar.gz
Core: Use more of Utils::FilePath in locator filters
Change-Id: Ie550691861317f2af6f38170b5dfc6413af5954f Reviewed-by: Eike Ziller <eike.ziller@qt.io>
-rw-r--r--src/plugins/coreplugin/locator/basefilefilter.cpp60
-rw-r--r--src/plugins/coreplugin/locator/basefilefilter.h22
-rw-r--r--src/plugins/coreplugin/locator/directoryfilter.cpp10
-rw-r--r--src/plugins/coreplugin/locator/directoryfilter.h2
-rw-r--r--src/plugins/coreplugin/locator/locator_test.cpp4
-rw-r--r--src/plugins/cpptools/cppincludesfilter.cpp32
-rw-r--r--src/plugins/projectexplorer/allprojectsfilter.cpp4
-rw-r--r--src/plugins/projectexplorer/currentprojectfilter.cpp4
8 files changed, 50 insertions, 88 deletions
diff --git a/src/plugins/coreplugin/locator/basefilefilter.cpp b/src/plugins/coreplugin/locator/basefilefilter.cpp
index 57c5018dd0..f10c2ead53 100644
--- a/src/plugins/coreplugin/locator/basefilefilter.cpp
+++ b/src/plugins/coreplugin/locator/basefilefilter.cpp
@@ -34,7 +34,6 @@
#include <QRegularExpression>
#include <QTimer>
-using namespace Core;
using namespace Utils;
namespace Core {
@@ -47,13 +46,11 @@ public:
{
iterator.clear();
previousResultPaths.clear();
- previousResultNames.clear();
previousEntry.clear();
}
QSharedPointer<BaseFileFilter::Iterator> iterator;
- QStringList previousResultPaths;
- QStringList previousResultNames;
+ FilePathList previousResultPaths;
bool forceNewSearchList;
QString previousEntry;
};
@@ -66,7 +63,6 @@ public:
};
} // Internal
-} // Core
BaseFileFilter::Iterator::~Iterator() = default;
@@ -74,7 +70,7 @@ BaseFileFilter::BaseFileFilter()
: d(new Internal::BaseFileFilterPrivate)
{
d->m_data.forceNewSearchList = true;
- setFileIterator(new ListIterator(QStringList()));
+ setFileIterator(new ListIterator({}));
}
BaseFileFilter::~BaseFileFilter()
@@ -87,7 +83,6 @@ void BaseFileFilter::prepareSearch(const QString &entry)
Q_UNUSED(entry)
d->m_current.iterator = d->m_data.iterator;
d->m_current.previousResultPaths = d->m_data.previousResultPaths;
- d->m_current.previousResultNames = d->m_data.previousResultNames;
d->m_current.forceNewSearchList = d->m_data.forceNewSearchList;
d->m_current.previousEntry = d->m_data.previousEntry;
d->m_data.forceNewSearchList = false;
@@ -132,12 +127,10 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil
const bool searchInPreviousResults = !d->m_current.forceNewSearchList && containsPreviousEntry
&& !pathSeparatorAdded;
if (searchInPreviousResults)
- d->m_current.iterator.reset(new ListIterator(d->m_current.previousResultPaths,
- d->m_current.previousResultNames));
+ d->m_current.iterator.reset(new ListIterator(d->m_current.previousResultPaths));
QTC_ASSERT(d->m_current.iterator.data(), return QList<LocatorFilterEntry>());
d->m_current.previousResultPaths.clear();
- d->m_current.previousResultNames.clear();
d->m_current.previousEntry = fp.filePath;
d->m_current.iterator->toFront();
bool canceled = false;
@@ -148,15 +141,14 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil
}
d->m_current.iterator->next();
- QString path = d->m_current.iterator->filePath();
- QString name = d->m_current.iterator->fileName();
- QString matchText = hasPathSeparator ? path : name;
+ FilePath path = d->m_current.iterator->filePath();
+ QString matchText = hasPathSeparator ? path.toString() : path.fileName();
QRegularExpressionMatch match = regexp.match(matchText);
if (match.hasMatch()) {
- QFileInfo fi(path);
- LocatorFilterEntry filterEntry(this, fi.fileName(), QString(path + fp.postfix));
- filterEntry.fileName = path;
+ QFileInfo fi(path.toString());
+ LocatorFilterEntry filterEntry(this, fi.fileName(), QString(path.toString() + fp.postfix));
+ filterEntry.fileName = path.toString();
filterEntry.extraInfo = FilePath::fromFileInfo(fi).shortNativePath();
const int matchLevel = matchLevelFor(match, matchText);
@@ -170,7 +162,6 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil
entries[matchLevel].append(filterEntry);
d->m_current.previousResultPaths.append(path);
- d->m_current.previousResultNames.append(name);
}
}
@@ -225,32 +216,18 @@ void BaseFileFilter::updatePreviousResultData()
return; // do not update with the new result list etc
d->m_data.previousEntry = d->m_current.previousEntry;
d->m_data.previousResultPaths = d->m_current.previousResultPaths;
- d->m_data.previousResultNames = d->m_current.previousResultNames;
// forceNewSearchList was already reset in prepareSearch
}
-BaseFileFilter::ListIterator::ListIterator(const QStringList &filePaths)
-{
- m_filePaths = filePaths;
- for (const QString &path : filePaths) {
- QFileInfo fi(path);
- m_fileNames.append(fi.fileName());
- }
- toFront();
-}
-
-BaseFileFilter::ListIterator::ListIterator(const QStringList &filePaths,
- const QStringList &fileNames)
+BaseFileFilter::ListIterator::ListIterator(const FilePathList &filePaths)
{
m_filePaths = filePaths;
- m_fileNames = fileNames;
toFront();
}
void BaseFileFilter::ListIterator::toFront()
{
m_pathPosition = m_filePaths.constBegin() - 1;
- m_namePosition = m_fileNames.constBegin() - 1;
}
bool BaseFileFilter::ListIterator::hasNext() const
@@ -259,25 +236,18 @@ bool BaseFileFilter::ListIterator::hasNext() const
return m_pathPosition + 1 != m_filePaths.constEnd();
}
-QString BaseFileFilter::ListIterator::next()
+FilePath BaseFileFilter::ListIterator::next()
{
- QTC_ASSERT(m_pathPosition != m_filePaths.constEnd(), return QString());
- QTC_ASSERT(m_namePosition != m_fileNames.constEnd(), return QString());
+ QTC_ASSERT(m_pathPosition != m_filePaths.constEnd(), return {});
++m_pathPosition;
- ++m_namePosition;
- QTC_ASSERT(m_pathPosition != m_filePaths.constEnd(), return QString());
- QTC_ASSERT(m_namePosition != m_fileNames.constEnd(), return QString());
+ QTC_ASSERT(m_pathPosition != m_filePaths.constEnd(), return {});
return *m_pathPosition;
}
-QString BaseFileFilter::ListIterator::filePath() const
+FilePath BaseFileFilter::ListIterator::filePath() const
{
- QTC_ASSERT(m_pathPosition != m_filePaths.constEnd(), return QString());
+ QTC_ASSERT(m_pathPosition != m_filePaths.constEnd(), return {});
return *m_pathPosition;
}
-QString BaseFileFilter::ListIterator::fileName() const
-{
- QTC_ASSERT(m_namePosition != m_fileNames.constEnd(), return QString());
- return *m_namePosition;
-}
+} // Core
diff --git a/src/plugins/coreplugin/locator/basefilefilter.h b/src/plugins/coreplugin/locator/basefilefilter.h
index 1f98cd4a5e..8371adad7c 100644
--- a/src/plugins/coreplugin/locator/basefilefilter.h
+++ b/src/plugins/coreplugin/locator/basefilefilter.h
@@ -27,8 +27,9 @@
#include "ilocatorfilter.h"
+#include <utils/fileutils.h>
+
#include <QSharedPointer>
-#include <QStringList>
namespace Core {
@@ -44,27 +45,22 @@ public:
virtual ~Iterator();
virtual void toFront() = 0;
virtual bool hasNext() const = 0;
- virtual QString next() = 0;
- virtual QString filePath() const = 0;
- virtual QString fileName() const = 0;
+ virtual Utils::FilePath next() = 0;
+ virtual Utils::FilePath filePath() const = 0;
};
class CORE_EXPORT ListIterator : public Iterator {
public:
- ListIterator(const QStringList &filePaths);
- ListIterator(const QStringList &filePaths, const QStringList &fileNames);
+ ListIterator(const Utils::FilePathList &filePaths);
void toFront() override;
bool hasNext() const override;
- QString next() override;
- QString filePath() const override;
- QString fileName() const override;
+ Utils::FilePath next() override;
+ Utils::FilePath filePath() const override;
private:
- QStringList m_filePaths;
- QStringList m_fileNames;
- QStringList::const_iterator m_pathPosition;
- QStringList::const_iterator m_namePosition;
+ Utils::FilePathList m_filePaths;
+ Utils::FilePathList::const_iterator m_pathPosition;
};
BaseFileFilter();
diff --git a/src/plugins/coreplugin/locator/directoryfilter.cpp b/src/plugins/coreplugin/locator/directoryfilter.cpp
index 02e7e59fe9..559d3de665 100644
--- a/src/plugins/coreplugin/locator/directoryfilter.cpp
+++ b/src/plugins/coreplugin/locator/directoryfilter.cpp
@@ -56,7 +56,7 @@ QByteArray DirectoryFilter::saveState() const
out << m_filters;
out << shortcutString();
out << isIncludedByDefault();
- out << m_files;
+ out << Utils::transform(m_files, &Utils::FilePath::toString);
out << m_exclusionFilters;
return value;
}
@@ -69,6 +69,7 @@ void DirectoryFilter::restoreState(const QByteArray &state)
QStringList directories;
QString shortcut;
bool defaultFilter;
+ QStringList files;
QDataStream in(state);
in >> name;
@@ -76,7 +77,8 @@ void DirectoryFilter::restoreState(const QByteArray &state)
in >> m_filters;
in >> shortcut;
in >> defaultFilter;
- in >> m_files;
+ in >> files;
+ m_files = Utils::transform(files, &Utils::FilePath::fromString);
if (!in.atEnd()) // Qt Creator 4.3 and later
in >> m_exclusionFilters;
else
@@ -231,12 +233,12 @@ void DirectoryFilter::refresh(QFutureInterface<void> &future)
}
Utils::SubDirFileIterator subDirIterator(directories, m_filters, m_exclusionFilters);
future.setProgressRange(0, subDirIterator.maxProgress());
- QStringList filesFound;
+ Utils::FilePathList filesFound;
auto end = subDirIterator.end();
for (auto it = subDirIterator.begin(); it != end; ++it) {
if (future.isCanceled())
break;
- filesFound << (*it).filePath;
+ filesFound << Utils::FilePath::fromString((*it).filePath);
if (future.isProgressUpdateNeeded()
|| future.progressValue() == 0 /*workaround for regression in Qt*/) {
future.setProgressValueAndText(subDirIterator.currentProgress(),
diff --git a/src/plugins/coreplugin/locator/directoryfilter.h b/src/plugins/coreplugin/locator/directoryfilter.h
index 803141afdb..b8a1871ce3 100644
--- a/src/plugins/coreplugin/locator/directoryfilter.h
+++ b/src/plugins/coreplugin/locator/directoryfilter.h
@@ -77,7 +77,7 @@ private:
QDialog *m_dialog = nullptr;
Internal::Ui::DirectoryFilterOptions *m_ui = nullptr;
mutable QMutex m_lock;
- QStringList m_files;
+ Utils::FilePathList m_files;
bool m_isCustomFilter = true;
};
diff --git a/src/plugins/coreplugin/locator/locator_test.cpp b/src/plugins/coreplugin/locator/locator_test.cpp
index c76a5633ea..a0881d273b 100644
--- a/src/plugins/coreplugin/locator/locator_test.cpp
+++ b/src/plugins/coreplugin/locator/locator_test.cpp
@@ -45,7 +45,7 @@ QTC_DECLARE_MYTESTDATADIR("../../../../tests/locators/")
class MyBaseFileFilter : public Core::BaseFileFilter
{
public:
- MyBaseFileFilter(const QStringList &theFiles)
+ MyBaseFileFilter(const Utils::FilePathList &theFiles)
{
setFileIterator(new BaseFileFilter::ListIterator(theFiles));
}
@@ -74,7 +74,7 @@ void Core::Internal::CorePlugin::test_basefilefilter()
QFETCH(QStringList, testFiles);
QFETCH(QList<ReferenceData>, referenceDataList);
- MyBaseFileFilter filter(testFiles);
+ MyBaseFileFilter filter(Utils::transform(testFiles, &Utils::FilePath::fromString));
BasicLocatorFilterTest test(&filter);
for (const ReferenceData &reference : qAsConst(referenceDataList)) {
diff --git a/src/plugins/cpptools/cppincludesfilter.cpp b/src/plugins/cpptools/cppincludesfilter.cpp
index 8a852fb7a5..db52f4e5ba 100644
--- a/src/plugins/cpptools/cppincludesfilter.cpp
+++ b/src/plugins/cpptools/cppincludesfilter.cpp
@@ -37,9 +37,9 @@
#include <QTimer>
using namespace Core;
-using namespace CppTools;
-using namespace CppTools::Internal;
using namespace ProjectExplorer;
+using namespace Utils;
+
namespace CppTools {
namespace Internal {
@@ -50,9 +50,8 @@ public:
void toFront() override;
bool hasNext() const override;
- QString next() override;
- QString filePath() const override;
- QString fileName() const override;
+ Utils::FilePath next() override;
+ Utils::FilePath filePath() const override;
private:
void fetchMore();
@@ -62,13 +61,9 @@ private:
QSet<QString> m_queuedPaths;
QSet<QString> m_allResultPaths;
QStringList m_resultQueue;
- QString m_currentPath;
+ FilePath m_currentPath;
};
-} // Internal
-} // CppTools
-
-
CppIncludesIterator::CppIncludesIterator(CPlusPlus::Snapshot snapshot,
const QSet<QString> &seedPaths)
: m_snapshot(snapshot),
@@ -90,26 +85,21 @@ bool CppIncludesIterator::hasNext() const
return !m_resultQueue.isEmpty();
}
-QString CppIncludesIterator::next()
+FilePath CppIncludesIterator::next()
{
if (m_resultQueue.isEmpty())
- return QString();
- m_currentPath = m_resultQueue.takeFirst();
+ return {};
+ m_currentPath = FilePath::fromString(m_resultQueue.takeFirst());
if (m_resultQueue.isEmpty())
fetchMore();
return m_currentPath;
}
-QString CppIncludesIterator::filePath() const
+FilePath CppIncludesIterator::filePath() const
{
return m_currentPath;
}
-QString CppIncludesIterator::fileName() const
-{
- return QFileInfo(m_currentPath).fileName();
-}
-
void CppIncludesIterator::fetchMore()
{
while (!m_queuedPaths.isEmpty() && m_resultQueue.isEmpty()) {
@@ -186,3 +176,7 @@ void CppIncludesFilter::markOutdated()
m_needsUpdate = true;
setFileIterator(nullptr); // clean up
}
+
+} // Internal
+} // CppTools
+
diff --git a/src/plugins/projectexplorer/allprojectsfilter.cpp b/src/plugins/projectexplorer/allprojectsfilter.cpp
index ab17127d73..9068c6bcce 100644
--- a/src/plugins/projectexplorer/allprojectsfilter.cpp
+++ b/src/plugins/projectexplorer/allprojectsfilter.cpp
@@ -57,9 +57,9 @@ void AllProjectsFilter::prepareSearch(const QString &entry)
{
Q_UNUSED(entry)
if (!fileIterator()) {
- QStringList paths;
+ Utils::FilePathList paths;
for (Project *project : SessionManager::projects())
- paths.append(Utils::transform(project->files(Project::AllFiles), &Utils::FilePath::toString));
+ paths.append(project->files(Project::AllFiles));
Utils::sort(paths);
setFileIterator(new BaseFileFilter::ListIterator(paths));
}
diff --git a/src/plugins/projectexplorer/currentprojectfilter.cpp b/src/plugins/projectexplorer/currentprojectfilter.cpp
index 0e924eeb2a..0ce954d1fd 100644
--- a/src/plugins/projectexplorer/currentprojectfilter.cpp
+++ b/src/plugins/projectexplorer/currentprojectfilter.cpp
@@ -56,9 +56,9 @@ void CurrentProjectFilter::prepareSearch(const QString &entry)
{
Q_UNUSED(entry)
if (!fileIterator()) {
- QStringList paths;
+ Utils::FilePathList paths;
if (m_project)
- paths = Utils::transform(m_project->files(Project::AllFiles), &Utils::FilePath::toString);
+ paths = m_project->files(Project::AllFiles);
setFileIterator(new BaseFileFilter::ListIterator(paths));
}
BaseFileFilter::prepareSearch(entry);