Commit 465cf130 authored by Tobias Hunger's avatar Tobias Hunger

KitManager: Enable sorting on the target setup page

Add a separate method to sort lists of kits and remove the sortedKits()
method again.

You should not use the sorted list whenever possible, so requireing a
two-step process to get that is not too hard. And it allows to sort
sub-sets of all kits, which is exactly what we might have on the
TargetSetupPage.

Task-number: QTCREATORBUG-13549
Change-Id: Iaa8443bcc8c321425daa13a1fb1e024d18939306
Reviewed-by: default avatarDaniel Teske <daniel.teske@theqtcompany.com>
parent cb350bfe
......@@ -97,7 +97,7 @@ QString KitChooser::kitToolTip(Kit *k) const
void KitChooser::populate()
{
m_chooser->clear();
foreach (Kit *kit, KitManager::sortedKits()) {
foreach (Kit *kit, KitManager::sortKits(KitManager::kits())) {
if (kitMatches(kit)) {
m_chooser->addItem(kitText(kit), qVariantFromValue(kit->id()));
m_chooser->setItemData(m_chooser->count() - 1, kitToolTip(kit), Qt::ToolTipRole);
......
......@@ -331,6 +331,23 @@ FeatureSet KitManager::availableFeatures(const QString &platform)
return features;
}
QList<Kit *> KitManager::sortKits(const QList<Kit *> kits)
{
// This method was added to delay the sorting of kits as long as possible.
// Since the displayName can contain variables it can be costly (e.g. involve
// calling executables to find version information, etc.) to call that
// method!
// Avoid lots of potentially expensive calls to Kit::displayName():
QList<QPair<QString, Kit *> > sortList
= Utils::transform(kits, [](Kit *k) { return qMakePair(k->displayName(), k); });
Utils::sort(sortList, [](const QPair<QString, Kit *> &a, const QPair<QString, Kit *> &b) -> bool {
if (a.first == b.first)
return a.second < b.second;
return a. first < b.first;
});
return Utils::transform(sortList, [](const QPair<QString, Kit *> &a) { return a.second; });
}
KitManager::KitList KitManager::restoreKits(const FileName &fileName)
{
KitList result;
......@@ -385,21 +402,6 @@ QList<Kit *> KitManager::kits()
return d->m_kitList;
}
QList<Kit *> KitManager::sortedKits()
{
// This method was added to delay the sorting of kits as long as possible.
// Since the displayName can contain variables it can be costly (e.g. involve
// calling executables to find version information, etc.) to call that
// method!
// Avoid lots of potentially expensive calls to Kit::displayName():
QList<QPair<QString, Kit *> > sortList
= Utils::transform(d->m_kitList, [](Kit *k) { return qMakePair(k->displayName(), k); });
Utils::sort(sortList, [](const QPair<QString, Kit *> &a, const QPair<QString, Kit *> &b) {
return a.first < b.first;
});
return Utils::transform(sortList, [](const QPair<QString, Kit *> &a) { return a.second; });
}
QList<Kit *> KitManager::matchingKits(const KitMatcher &matcher)
{
QList<Kit *> result;
......
......@@ -134,7 +134,6 @@ public:
~KitManager();
static QList<Kit *> kits();
static QList<Kit *> sortedKits(); // Use kits() whenever possible as that is cheaper!
static QList<Kit *> matchingKits(const KitMatcher &matcher);
static Kit *find(Core::Id id);
static Kit *find(const KitMatcher &matcher);
......@@ -157,6 +156,8 @@ public:
static QString displayNameForPlatform(const QString &platform);
static Core::FeatureSet availableFeatures(const QString &platform);
static QList<Kit *> sortKits(const QList<Kit *> kits); // Avoid sorting whenever possible!
public slots:
void saveKits();
......
......@@ -118,7 +118,7 @@ KitModel::KitModel(QBoxLayout *parentLayout, QObject *parent) :
rootItem()->appendChild(m_autoRoot);
rootItem()->appendChild(m_manualRoot);
foreach (Kit *k, KitManager::sortedKits())
foreach (Kit *k, KitManager::sortKits(KitManager::kits()))
addKit(k);
changeDefaultKit();
......
......@@ -611,7 +611,7 @@ void TargetSettingsPanelWidget::updateTargetButtons()
this, SLOT(duplicateActionTriggered(QAction*)));
connect(removeAction, SIGNAL(triggered()), this, SLOT(removeTarget()));
foreach (Kit *k, KitManager::sortedKits()) {
foreach (Kit *k, KitManager::sortKits(KitManager::kits())) {
if (m_project->target(k))
continue;
createAction(k, m_addMenu);
......
......@@ -265,6 +265,7 @@ void TargetSetupPage::setupWidgets()
else
kitList = KitManager::kits();
kitList = KitManager::sortKits(kitList);
foreach (Kit *k, kitList)
addWidget(k);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment