forked from qt-creator/qt-creator
ProjectExplorer: Fix comparing priorities
Makes test_modelmanager_extraeditorsupport_uiFiles pass again. Before, a "CMake Wizard" dialog blocked the auto test due to the wrong comparisons. The std::max_element function takes a less predicate. Thus the right way to find e.g. highest int in a vector is: std::max_element(..., std::less<>) or std::min_element(..., std::greater<>) Both variants are confussing to read. Instead of provinding Utils::maxElementOr provide a bestElementOr which leads to this code: bestElementOr(..., std::greater<>). Change-Id: Ic30f0d742c03170b28227f60d3a5ae00e40fdf5a Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -79,12 +79,12 @@ typename T::value_type findOr(const T &container, typename T::value_type other,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename F>
|
template<typename T, typename F>
|
||||||
typename T::value_type maxElementOr(const T &container, typename T::value_type other, F function)
|
typename T::value_type bestElementOr(const T &container, typename T::value_type other, F function)
|
||||||
{
|
{
|
||||||
typename T::const_iterator end = container.end();
|
typename T::const_iterator end = container.end();
|
||||||
typename T::const_iterator begin = container.begin();
|
typename T::const_iterator begin = container.begin();
|
||||||
|
|
||||||
typename T::const_iterator it = std::max_element(begin, end, function);
|
typename T::const_iterator it = std::min_element(begin, end, function);
|
||||||
if (it == end)
|
if (it == end)
|
||||||
return other;
|
return other;
|
||||||
return *it;
|
return *it;
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ IBuildConfigurationFactory *IBuildConfigurationFactory::find(Kit *k, const QStri
|
|||||||
QList<IBuildConfigurationFactory *> factories
|
QList<IBuildConfigurationFactory *> factories
|
||||||
= ExtensionSystem::PluginManager::instance()->getObjects<IBuildConfigurationFactory>();
|
= ExtensionSystem::PluginManager::instance()->getObjects<IBuildConfigurationFactory>();
|
||||||
|
|
||||||
return Utils::maxElementOr(factories, 0,
|
return Utils::bestElementOr(factories, 0,
|
||||||
[&k, &projectPath](IBuildConfigurationFactory *a, IBuildConfigurationFactory *b) {
|
[&k, &projectPath](IBuildConfigurationFactory *a, IBuildConfigurationFactory *b) {
|
||||||
return a->priority(k, projectPath) > b->priority(k, projectPath);
|
return a->priority(k, projectPath) > b->priority(k, projectPath);
|
||||||
});
|
});
|
||||||
@@ -357,7 +357,7 @@ IBuildConfigurationFactory * IBuildConfigurationFactory::find(Target *parent)
|
|||||||
QList<IBuildConfigurationFactory *> factories
|
QList<IBuildConfigurationFactory *> factories
|
||||||
= ExtensionSystem::PluginManager::getObjects<IBuildConfigurationFactory>();
|
= ExtensionSystem::PluginManager::getObjects<IBuildConfigurationFactory>();
|
||||||
|
|
||||||
return Utils::maxElementOr(factories, 0,
|
return Utils::bestElementOr(factories, 0,
|
||||||
[&parent](IBuildConfigurationFactory *a, IBuildConfigurationFactory *b) {
|
[&parent](IBuildConfigurationFactory *a, IBuildConfigurationFactory *b) {
|
||||||
return a->priority(parent) > b->priority(parent);
|
return a->priority(parent) > b->priority(parent);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user