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/wizard.h>
#include <utils/algorithm.h>
#include <utils/fancylineedit.h>
#include <QFileInfo>
#include <QLabel>
@@ -52,6 +53,15 @@
namespace ProjectExplorer {
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
{
@@ -64,6 +74,7 @@ public:
QLabel *noValidKitLabel;
QLabel *optionHintLabel;
QCheckBox *allKitsCheckBox;
Utils::FancyLineEdit *kitFilterLineEdit;
void setupUi(TargetSetupPage *q)
{
@@ -93,6 +104,10 @@ public:
allKitsCheckBox->setTristate(true);
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);
QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Fixed);
policy.setHorizontalStretch(0);
@@ -115,8 +130,9 @@ public:
auto verticalLayout_2 = new QVBoxLayout(setupTargetPage);
verticalLayout_2->addWidget(headerLabel);
verticalLayout_2->addWidget(noValidKitLabel);
verticalLayout_2->addWidget(descriptionLabel);
verticalLayout_2->addWidget(kitFilterLineEdit);
verticalLayout_2->addWidget(noValidKitLabel);
verticalLayout_2->addWidget(optionHintLabel);
verticalLayout_2->addWidget(allKitsCheckBox);
verticalLayout_2->addWidget(centralWidget);
@@ -131,6 +147,9 @@ public:
QObject::connect(allKitsCheckBox, &QAbstractButton::clicked,
q, &TargetSetupPage::changeAllKitsSelections);
QObject::connect(kitFilterLineEdit, &Utils::FancyLineEdit::filterChanged,
q, &TargetSetupPage::kitFilterChanged);
}
};
@@ -246,20 +265,16 @@ bool TargetSetupPage::isComplete() const
void TargetSetupPage::setupWidgets()
{
// Known profiles:
QList<Kit *> kitList;
kitList = KitManager::kits(m_requiredPredicate);
kitList = KitManager::sortKits(kitList);
auto kitList = sortedKitList(m_requiredPredicate);
foreach (Kit *k, kitList)
addWidget(k);
// Setup import widget:
Utils::FileName path = Utils::FileName::fromString(m_projectPath);
path = path.parentDir(); // base dir
path = path.parentDir(); // parent dir
m_importWidget->setCurrentDirectory(path);
m_importWidget->setCurrentDirectory(Internal::importDirectory(m_projectPath));
updateVisibility();
selectAtLeastOneKit();
}
void TargetSetupPage::reset()
@@ -434,6 +449,35 @@ void TargetSetupPage::kitSelectionChanged()
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()
{
if (m_ui->allKitsCheckBox->checkState() == Qt::PartiallyChecked)

View File

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