forked from qt-creator/qt-creator
QmlDesigner: Remove duplicates
Change-Id: I5b2d8433c0aca286ec530f237750ba660c409a48
Reviewed-by: Aleksei German <aleksei.german@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
(cherry picked from commit eafe43399d
)
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -51,8 +51,6 @@ void ModuleScanner::scan([[maybe_unused]] std::string_view modulePath)
|
|||||||
#ifdef QDS_HAS_QMLPRIVATE
|
#ifdef QDS_HAS_QMLPRIVATE
|
||||||
QDirIterator dirIterator{QString::fromUtf8(modulePath), QDir::Dirs, QDirIterator::Subdirectories};
|
QDirIterator dirIterator{QString::fromUtf8(modulePath), QDir::Dirs, QDirIterator::Subdirectories};
|
||||||
|
|
||||||
QMap<QString, bool> moduleNames;
|
|
||||||
|
|
||||||
while (dirIterator.hasNext()) {
|
while (dirIterator.hasNext()) {
|
||||||
auto directoryPath = dirIterator.next();
|
auto directoryPath = dirIterator.next();
|
||||||
QString qmldirPath = directoryPath + "/qmldir";
|
QString qmldirPath = directoryPath + "/qmldir";
|
||||||
@@ -72,14 +70,13 @@ void ModuleScanner::scan([[maybe_unused]] std::string_view modulePath)
|
|||||||
if (moduleName.isEmpty() || m_skip(moduleName))
|
if (moduleName.isEmpty() || m_skip(moduleName))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (moduleNames.contains(moduleName))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
moduleNames.insert(moduleName, true);
|
|
||||||
m_modules.push_back(
|
m_modules.push_back(
|
||||||
Import::createLibraryImport(moduleName, createVersion(parser.components())));
|
Import::createLibraryImport(moduleName, createVersion(parser.components())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::sort(m_modules.begin(), m_modules.end());
|
||||||
|
m_modules.erase(std::unique(m_modules.begin(), m_modules.end()), m_modules.end());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,6 +21,15 @@ auto VersionProperty(const Matcher &matcher)
|
|||||||
return Property(&QmlDesigner::Import::version, matcher);
|
return Property(&QmlDesigner::Import::version, matcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MATCHER(HasDuplicates, std::string(negation ? "hasn't duplicates" : "has dublicates"))
|
||||||
|
{
|
||||||
|
auto values = arg;
|
||||||
|
std::sort(values.begin(), values.begin());
|
||||||
|
auto found = std::adjacent_find(values.begin(), values.end());
|
||||||
|
|
||||||
|
return found != values.end();
|
||||||
|
}
|
||||||
|
|
||||||
class ModuleScanner : public testing::Test
|
class ModuleScanner : public testing::Test
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
@@ -70,4 +79,20 @@ TEST_F(ModuleScanner, Version)
|
|||||||
ASSERT_THAT(scanner.modules(), ElementsAre(AllOf(UrlProperty("Example"), VersionProperty("1.3"))));
|
ASSERT_THAT(scanner.modules(), ElementsAre(AllOf(UrlProperty("Example"), VersionProperty("1.3"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ModuleScanner, Duplicates)
|
||||||
|
{
|
||||||
|
scanner.scan(QStringList{QT6_INSTALL_PREFIX});
|
||||||
|
|
||||||
|
ASSERT_THAT(scanner.modules(), Not(HasDuplicates()));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ModuleScanner, DontAddModulesAgain)
|
||||||
|
{
|
||||||
|
scanner.scan(QStringList{QT6_INSTALL_PREFIX});
|
||||||
|
|
||||||
|
scanner.scan(QStringList{QT6_INSTALL_PREFIX});
|
||||||
|
|
||||||
|
ASSERT_THAT(scanner.modules(), Not(HasDuplicates()));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
Reference in New Issue
Block a user