From d78e87329f9e637de7742cffd167810cc95565cb Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 13 Oct 2016 11:25:31 +0200 Subject: [PATCH] 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 Reviewed-by: Tobias Hunger --- src/plugins/projectexplorer/projectwindow.cpp | 16 ++++++++------ src/plugins/projectexplorer/projectwindow.h | 1 + .../projectexplorer/targetsettingspanel.cpp | 22 ++++++++++++++++--- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/plugins/projectexplorer/projectwindow.cpp b/src/plugins/projectexplorer/projectwindow.cpp index 14773cf608c..5267b25a52b 100644 --- a/src/plugins/projectexplorer/projectwindow.cpp +++ b/src/plugins/projectexplorer/projectwindow.cpp @@ -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()); - } - void updatePanel() { - announceChange(); + ProjectItem *projectItem = m_projectsModel.rootItem()->childAt(0); + m_changeListener(projectItem->data(0, PanelWidgetRole).value()); - 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); } diff --git a/src/plugins/projectexplorer/projectwindow.h b/src/plugins/projectexplorer/projectwindow.h index a9918a093be..50a6b8ff9af 100644 --- a/src/plugins/projectexplorer/projectwindow.h +++ b/src/plugins/projectexplorer/projectwindow.h @@ -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. }; diff --git a/src/plugins/projectexplorer/targetsettingspanel.cpp b/src/plugins/projectexplorer/targetsettingspanel.cpp index 8e380a37040..0700dbe4a76 100644 --- a/src/plugins/projectexplorer/targetsettingspanel.cpp +++ b/src/plugins/projectexplorer/targetsettingspanel.cpp @@ -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(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)); }); + const QList 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(q)), + ItemUpdatedFromBelowRole); } void TargetGroupItemPrivate::handleTargetAdded(Target *target)