ProjectExplorer: Use function for comparison instead of global object

Cheaper.

Change-Id: Ibcaa68fd96b5ae0272a32033c5e3606e9a037bbe
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-07-30 10:11:54 +02:00
parent 4461efdfbb
commit 05ec31453c

View File

@@ -34,8 +34,6 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/stringutils.h> #include <utils/stringutils.h>
using namespace ProjectExplorer;
/*! /*!
\class ProjectExplorer::BuildConfigurationModel \class ProjectExplorer::BuildConfigurationModel
\brief The BuildConfigurationModel class is a model to represent the build \brief The BuildConfigurationModel class is a model to represent the build
@@ -48,14 +46,12 @@ using namespace ProjectExplorer;
TODO might it possible to share code without making the code a complete mess. TODO might it possible to share code without making the code a complete mess.
*/ */
namespace { namespace ProjectExplorer {
const auto ComparisonOperator = static bool isOrderedBefore(const ProjectConfiguration *a, const ProjectConfiguration *b)
[](const ProjectConfiguration *a, const ProjectConfiguration *b) { {
return Utils::caseFriendlyCompare(a->displayName(), b->displayName()) < 0; return Utils::caseFriendlyCompare(a->displayName(), b->displayName()) < 0;
}; }
} // namespace
ProjectConfigurationModel::ProjectConfigurationModel(Target *target) : ProjectConfigurationModel::ProjectConfigurationModel(Target *target) :
m_target(target) m_target(target)
@@ -83,10 +79,10 @@ void ProjectConfigurationModel::displayNameChanged()
if (oldPos < 0) if (oldPos < 0)
return; return;
if (oldPos >= 1 && ComparisonOperator(m_projectConfigurations.at(oldPos), m_projectConfigurations.at(oldPos - 1))) { if (oldPos >= 1 && isOrderedBefore(m_projectConfigurations.at(oldPos), m_projectConfigurations.at(oldPos - 1))) {
// We need to move up // We need to move up
int newPos = oldPos - 1; int newPos = oldPos - 1;
while (newPos >= 0 && ComparisonOperator(m_projectConfigurations.at(oldPos), m_projectConfigurations.at(newPos))) { while (newPos >= 0 && isOrderedBefore(m_projectConfigurations.at(oldPos), m_projectConfigurations.at(newPos))) {
--newPos; --newPos;
} }
++newPos; ++newPos;
@@ -98,11 +94,11 @@ void ProjectConfigurationModel::displayNameChanged()
// Not only did we move, we also changed... // Not only did we move, we also changed...
emit dataChanged(index(newPos, 0), index(newPos,0)); emit dataChanged(index(newPos, 0), index(newPos,0));
} else if (oldPos < m_projectConfigurations.size() - 1 } else if (oldPos < m_projectConfigurations.size() - 1
&& ComparisonOperator(m_projectConfigurations.at(oldPos + 1), m_projectConfigurations.at(oldPos))) { && isOrderedBefore(m_projectConfigurations.at(oldPos + 1), m_projectConfigurations.at(oldPos))) {
// We need to move down // We need to move down
int newPos = oldPos + 1; int newPos = oldPos + 1;
while (newPos < m_projectConfigurations.size() while (newPos < m_projectConfigurations.size()
&& ComparisonOperator(m_projectConfigurations.at(newPos), m_projectConfigurations.at(oldPos))) { && isOrderedBefore(m_projectConfigurations.at(newPos), m_projectConfigurations.at(oldPos))) {
++newPos; ++newPos;
} }
beginMoveRows(QModelIndex(), oldPos, oldPos, QModelIndex(), newPos); beginMoveRows(QModelIndex(), oldPos, oldPos, QModelIndex(), newPos);
@@ -145,7 +141,7 @@ void ProjectConfigurationModel::addProjectConfiguration(ProjectConfiguration *pc
// Find the right place to insert // Find the right place to insert
int i = 0; int i = 0;
for (; i < m_projectConfigurations.size(); ++i) { for (; i < m_projectConfigurations.size(); ++i) {
if (ComparisonOperator(pc, m_projectConfigurations.at(i))) if (isOrderedBefore(pc, m_projectConfigurations.at(i)))
break; break;
} }
@@ -166,3 +162,5 @@ void ProjectConfigurationModel::removeProjectConfiguration(ProjectConfiguration
m_projectConfigurations.removeAt(i); m_projectConfigurations.removeAt(i);
endRemoveRows(); endRemoveRows();
} }
} // ProjectExplorer