ProjectExplorer: Filter out unusable kits

As side-effect, fix missing expansion of subitems in some cases.

Task-number: QTCREATORBUG-17110
Change-Id: Ib0c74e968d6d814f9dadbb37b323c8ac68cda310
Reviewed-by: Robert Loehning <robert.loehning@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
hjk
2016-10-13 11:25:31 +02:00
parent 35f6a0b954
commit d78e87329f
3 changed files with 29 additions and 10 deletions

View File

@@ -234,6 +234,11 @@ public:
{
Q_UNUSED(column)
if (role == ItemUpdatedFromBelowRole) {
announceChange();
return true;
}
if (role == ItemDeactivatedFromBelowRole) {
announceChange();
return true;
@@ -375,16 +380,13 @@ public:
this, &SelectorModel::openContextMenu);
}
void announceChange()
{
m_changeListener(m_projectsModel.rootItem()->childAt(0)->data(0, PanelWidgetRole).value<QWidget *>());
}
void updatePanel()
{
announceChange();
ProjectItem *projectItem = m_projectsModel.rootItem()->childAt(0);
m_changeListener(projectItem->data(0, PanelWidgetRole).value<QWidget *>());
QModelIndex activeIndex = m_projectsModel.rootItem()->childAt(0)->activeIndex();
QModelIndex activeIndex = projectItem->activeIndex();
m_selectorTree->expandAll();
m_selectorTree->selectionModel()->clear();
m_selectorTree->selectionModel()->select(activeIndex, QItemSelectionModel::Select);
}

View File

@@ -42,6 +42,7 @@ enum {
ItemActivatedFromBelowRole, // A subitem gots activated and gives us the opportunity to adjust
ItemActivatedFromAboveRole, // A parent item gots activated and makes us its active child.
ItemDeactivatedFromBelowRole, // A subitem got deactivated and gives us the opportunity to adjust
ItemUpdatedFromBelowRole, // A subitem got updated, re-expansion is necessary.
ActiveItemRole, // The index of the currently selected item in the tree view
PanelWidgetRole // This item's widget to be shown as central widget.
};

View File

@@ -212,6 +212,7 @@ public:
void handleRemovedKit(Kit *kit);
void handleAddedKit(Kit *kit);
void handleUpdatedKit(Kit *kit);
void handleTargetAdded(Target *target);
void handleTargetRemoved(Target *target);
@@ -755,6 +756,8 @@ TargetGroupItemPrivate::TargetGroupItemPrivate(TargetGroupItem *q, Project *proj
this, &TargetGroupItemPrivate::handleAddedKit);
connect(KitManager::instance(), &KitManager::kitRemoved,
this, &TargetGroupItemPrivate::handleRemovedKit);
connect(KitManager::instance(), &KitManager::kitUpdated,
this, &TargetGroupItemPrivate::handleUpdatedKit);
rebuildContents();
}
@@ -789,7 +792,7 @@ QVariant TargetGroupItem::data(int column, int role) const
bool TargetGroupItem::setData(int column, const QVariant &data, int role)
{
Q_UNUSED(data)
if (role == ItemActivatedFromBelowRole) {
if (role == ItemActivatedFromBelowRole || role == ItemUpdatedFromBelowRole) {
// Bubble up to trigger setting the active project.
parent()->setData(column, QVariant::fromValue(static_cast<TreeItem *>(this)), role);
return true;
@@ -823,9 +826,16 @@ void TargetGroupItemPrivate::handleRemovedKit(Kit *kit)
rebuildContents();
}
void TargetGroupItemPrivate::handleUpdatedKit(Kit *kit)
{
Q_UNUSED(kit);
rebuildContents();
}
void TargetGroupItemPrivate::handleAddedKit(Kit *kit)
{
q->appendChild(new TargetItem(m_project, kit->id()));
if (m_project->supportsKit(kit))
q->appendChild(new TargetItem(m_project, kit->id()));
}
void TargetItem::updateSubItems()
@@ -843,8 +853,14 @@ void TargetGroupItemPrivate::rebuildContents()
{
q->removeChildren();
foreach (Kit *kit, KitManager::sortKits(KitManager::kits()))
KitMatcher matcher([this](const Kit *kit) { return m_project->supportsKit(const_cast<Kit *>(kit)); });
const QList<Kit *> kits = KitManager::sortKits(KitManager::matchingKits(matcher));
for (Kit *kit : kits)
q->appendChild(new TargetItem(m_project, kit->id()));
if (q->parent())
q->parent()->setData(0, QVariant::fromValue(static_cast<TreeItem *>(q)),
ItemUpdatedFromBelowRole);
}
void TargetGroupItemPrivate::handleTargetAdded(Target *target)