Todo: Spread use of Utils::FilePath a bit

Change-Id: I0c6caacad76740dfc23e7a0be40ead776e1d5253
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2019-06-17 09:22:04 +02:00
parent 622117a6ce
commit 12b6242f43
2 changed files with 14 additions and 18 deletions

View File

@@ -45,6 +45,7 @@
#include <QTimer>
using namespace ProjectExplorer;
using namespace Utils;
namespace Todo {
namespace Internal {
@@ -90,7 +91,7 @@ void TodoItemsProvider::updateList()
// Show only items of the current file if any
if (m_settings.scanningScope == ScanningScopeCurrentFile) {
if (m_currentEditor)
m_itemsList = m_itemsHash.value(m_currentEditor->document()->filePath().toString());
m_itemsList = m_itemsHash.value(m_currentEditor->document()->filePath());
// Show only items of the current sub-project
} else if (m_settings.scanningScope == ScanningScopeSubProject) {
if (m_startupProject)
@@ -121,21 +122,19 @@ void TodoItemsProvider::createScanners()
void TodoItemsProvider::setItemsListWithinStartupProject()
{
QHashIterator<QString, QList<TodoItem> > it(m_itemsHash);
const QSet<QString> fileNames
= QSet<QString>::fromList(Utils::transform(m_startupProject->files(Project::SourceFiles),
&Utils::FilePath::toString));
QHashIterator<FilePath, QList<TodoItem> > it(m_itemsHash);
const auto filePaths = QSet<FilePath>::fromList(m_startupProject->files(Project::SourceFiles));
QVariantMap settings = m_startupProject->namedSettings(Constants::SETTINGS_NAME_KEY).toMap();
while (it.hasNext()) {
it.next();
QString fileName = it.key();
if (fileNames.contains(fileName)) {
const FilePath filePath = it.key();
if (filePaths.contains(filePath)) {
bool skip = false;
for (const QVariant &pattern : settings[Constants::EXCLUDES_LIST_KEY].toList()) {
QRegExp re(pattern.toString());
if (re.indexIn(fileName) != -1) {
if (re.indexIn(filePath.toString()) != -1) {
skip = true;
break;
}
@@ -154,31 +153,28 @@ void TodoItemsProvider::setItemsListWithinSubproject()
ProjectNode *projectNode = node->parentProjectNode();
if (projectNode) {
// FIXME: The name doesn't match the implementation that lists all files.
QSet<Utils::FilePath> subprojectFileNames;
QSet<FilePath> subprojectFileNames;
projectNode->forEachGenericNode([&](Node *node) {
subprojectFileNames.insert(node->filePath());
});
// files must be both in the current subproject and the startup-project.
const QSet<QString> fileNames
= QSet<QString>::fromList(Utils::transform(m_startupProject->files(Project::SourceFiles),
&Utils::FilePath::toString));
QHashIterator<QString, QList<TodoItem> > it(m_itemsHash);
const auto fileNames
= QSet<FilePath>::fromList(m_startupProject->files(Project::SourceFiles));
QHashIterator<FilePath, QList<TodoItem> > it(m_itemsHash);
while (it.hasNext()) {
it.next();
if (subprojectFileNames.contains(Utils::FilePath::fromString(it.key()))
&& fileNames.contains(it.key())) {
if (subprojectFileNames.contains(it.key()) && fileNames.contains(it.key()))
m_itemsList << it.value();
}
}
}
}
}
void TodoItemsProvider::itemsFetched(const QString &fileName, const QList<TodoItem> &items)
{
// Replace old items with new ones
m_itemsHash.insert(fileName, items);
m_itemsHash.insert(FilePath::fromString(fileName), items);
m_shouldUpdateList = true;
}

View File

@@ -60,7 +60,7 @@ private:
TodoItemsModel *m_itemsModel;
// All to-do items are stored here regardless current scanning scope
QHash<QString, QList<TodoItem> > m_itemsHash;
QHash<Utils::FilePath, QList<TodoItem> > m_itemsHash;
// This list contains only those to-do items that are within current scanning scope
QList<TodoItem> m_itemsList;