Add filter box to kit selection in target setup dialog

The kit list gets quite long when having multiple qt versions installed.
To prevent having to search through the whole list when wanting to
select kits, a filter option based on kit names has been introduced.

Change-Id: Id533eb62680de69e956396fc4624b61a8c2de909
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Daniel Engelke
2017-10-17 16:32:25 +02:00
parent bd65ae1def
commit c27d0bb1cb
2 changed files with 55 additions and 8 deletions

View File

@@ -42,6 +42,7 @@
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <utils/wizard.h> #include <utils/wizard.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/fancylineedit.h>
#include <QFileInfo> #include <QFileInfo>
#include <QLabel> #include <QLabel>
@@ -52,6 +53,15 @@
namespace ProjectExplorer { namespace ProjectExplorer {
namespace Internal { namespace Internal {
static Utils::FileName importDirectory(const QString &projectPath)
{
// Setup import widget:
auto path = Utils::FileName::fromString(projectPath);
path = path.parentDir(); // base dir
path = path.parentDir(); // parent dir
return path;
}
class TargetSetupPageUi class TargetSetupPageUi
{ {
@@ -64,6 +74,7 @@ public:
QLabel *noValidKitLabel; QLabel *noValidKitLabel;
QLabel *optionHintLabel; QLabel *optionHintLabel;
QCheckBox *allKitsCheckBox; QCheckBox *allKitsCheckBox;
Utils::FancyLineEdit *kitFilterLineEdit;
void setupUi(TargetSetupPage *q) void setupUi(TargetSetupPage *q)
{ {
@@ -93,6 +104,10 @@ public:
allKitsCheckBox->setTristate(true); allKitsCheckBox->setTristate(true);
allKitsCheckBox->setText(TargetSetupPage::tr("Select all kits")); allKitsCheckBox->setText(TargetSetupPage::tr("Select all kits"));
kitFilterLineEdit = new Utils::FancyLineEdit(setupTargetPage);
kitFilterLineEdit->setFiltering(true);
kitFilterLineEdit->setPlaceholderText(TargetSetupPage::tr("Type to filter kits by name..."));
centralWidget = new QWidget(setupTargetPage); centralWidget = new QWidget(setupTargetPage);
QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Fixed); QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Fixed);
policy.setHorizontalStretch(0); policy.setHorizontalStretch(0);
@@ -115,8 +130,9 @@ public:
auto verticalLayout_2 = new QVBoxLayout(setupTargetPage); auto verticalLayout_2 = new QVBoxLayout(setupTargetPage);
verticalLayout_2->addWidget(headerLabel); verticalLayout_2->addWidget(headerLabel);
verticalLayout_2->addWidget(noValidKitLabel);
verticalLayout_2->addWidget(descriptionLabel); verticalLayout_2->addWidget(descriptionLabel);
verticalLayout_2->addWidget(kitFilterLineEdit);
verticalLayout_2->addWidget(noValidKitLabel);
verticalLayout_2->addWidget(optionHintLabel); verticalLayout_2->addWidget(optionHintLabel);
verticalLayout_2->addWidget(allKitsCheckBox); verticalLayout_2->addWidget(allKitsCheckBox);
verticalLayout_2->addWidget(centralWidget); verticalLayout_2->addWidget(centralWidget);
@@ -131,6 +147,9 @@ public:
QObject::connect(allKitsCheckBox, &QAbstractButton::clicked, QObject::connect(allKitsCheckBox, &QAbstractButton::clicked,
q, &TargetSetupPage::changeAllKitsSelections); q, &TargetSetupPage::changeAllKitsSelections);
QObject::connect(kitFilterLineEdit, &Utils::FancyLineEdit::filterChanged,
q, &TargetSetupPage::kitFilterChanged);
} }
}; };
@@ -246,20 +265,16 @@ bool TargetSetupPage::isComplete() const
void TargetSetupPage::setupWidgets() void TargetSetupPage::setupWidgets()
{ {
// Known profiles: // Known profiles:
QList<Kit *> kitList; auto kitList = sortedKitList(m_requiredPredicate);
kitList = KitManager::kits(m_requiredPredicate);
kitList = KitManager::sortKits(kitList);
foreach (Kit *k, kitList) foreach (Kit *k, kitList)
addWidget(k); addWidget(k);
// Setup import widget: // Setup import widget:
Utils::FileName path = Utils::FileName::fromString(m_projectPath); m_importWidget->setCurrentDirectory(Internal::importDirectory(m_projectPath));
path = path.parentDir(); // base dir
path = path.parentDir(); // parent dir
m_importWidget->setCurrentDirectory(path);
updateVisibility(); updateVisibility();
selectAtLeastOneKit();
} }
void TargetSetupPage::reset() void TargetSetupPage::reset()
@@ -434,6 +449,35 @@ void TargetSetupPage::kitSelectionChanged()
m_ui->allKitsCheckBox->setCheckState(Qt::Unchecked); m_ui->allKitsCheckBox->setCheckState(Qt::Unchecked);
} }
QList<Kit *> TargetSetupPage::sortedKitList(const Kit::Predicate &predicate)
{
const auto kitList = KitManager::kits(predicate);
return KitManager::sortKits(kitList);
}
void TargetSetupPage::kitFilterChanged(const QString &filterText)
{
// Reset current shown kits
reset();
if (filterText.isEmpty()) {
setupWidgets();
} else {
const auto kitList = sortedKitList(m_requiredPredicate);
foreach (Kit *kit, kitList) {
if (kit->displayName().contains(filterText, Qt::CaseInsensitive))
addWidget(kit);
}
m_importWidget->setCurrentDirectory(Internal::importDirectory(m_projectPath));
updateVisibility();
selectAtLeastOneKit();
}
}
void TargetSetupPage::changeAllKitsSelections() void TargetSetupPage::changeAllKitsSelections()
{ {
if (m_ui->allKitsCheckBox->checkState() == Qt::PartiallyChecked) if (m_ui->allKitsCheckBox->checkState() == Qt::PartiallyChecked)

View File

@@ -89,6 +89,8 @@ public:
void openOptions(); void openOptions();
void changeAllKitsSelections(); void changeAllKitsSelections();
void kitFilterChanged(const QString &filterText);
private: private:
void handleKitAddition(ProjectExplorer::Kit *k); void handleKitAddition(ProjectExplorer::Kit *k);
void handleKitRemoval(ProjectExplorer::Kit *k); void handleKitRemoval(ProjectExplorer::Kit *k);
@@ -96,6 +98,7 @@ private:
void updateVisibility(); void updateVisibility();
void kitSelectionChanged(); void kitSelectionChanged();
static QList<Kit *> sortedKitList(const Kit::Predicate &predicate);
bool isUpdating() const; bool isUpdating() const;
void selectAtLeastOneKit(); void selectAtLeastOneKit();