diff --git a/src/plugins/projectexplorer/kitmodel.cpp b/src/plugins/projectexplorer/kitmodel.cpp index 4981a19d25b..38ce4a576b2 100644 --- a/src/plugins/projectexplorer/kitmodel.cpp +++ b/src/plugins/projectexplorer/kitmodel.cpp @@ -188,6 +188,12 @@ KitNode *KitModel::kitNode(const QModelIndex &index) return (n && n->level() == 2) ? static_cast(n) : nullptr; } +QModelIndex KitModel::indexOf(Id kitId) const +{ + KitNode *n = findItemAtLevel<2>([kitId](KitNode *n) { return n->kit()->id() == kitId; }); + return n ? indexForItem(n) : QModelIndex(); +} + QModelIndex KitModel::indexOf(Kit *k) const { KitNode *n = findWorkingCopy(k); diff --git a/src/plugins/projectexplorer/kitmodel.h b/src/plugins/projectexplorer/kitmodel.h index f402b265d40..249d485101e 100644 --- a/src/plugins/projectexplorer/kitmodel.h +++ b/src/plugins/projectexplorer/kitmodel.h @@ -5,6 +5,7 @@ #include "projectexplorer_export.h" +#include #include QT_BEGIN_NAMESPACE @@ -36,6 +37,7 @@ public: Kit *kit(const QModelIndex &); KitNode *kitNode(const QModelIndex &); QModelIndex indexOf(Kit *k) const; + QModelIndex indexOf(Utils::Id kitId) const; void setDefaultKit(const QModelIndex &index); bool isDefaultKit(Kit *k) const; diff --git a/src/plugins/projectexplorer/kitoptionspage.cpp b/src/plugins/projectexplorer/kitoptionspage.cpp index 24bafc0eeb0..bf702cab13a 100644 --- a/src/plugins/projectexplorer/kitoptionspage.cpp +++ b/src/plugins/projectexplorer/kitoptionspage.cpp @@ -11,6 +11,8 @@ #include "kitmanagerconfigwidget.h" #include "kitmanager.h" +#include + #include #include @@ -20,15 +22,21 @@ #include #include -namespace ProjectExplorer { -namespace Internal { +using namespace Utils; + +namespace ProjectExplorer::Internal { + +// Page pre-selection + +static Id selectedKitId; + +void setSelectectKitId(const Utils::Id &kitId) +{ + selectedKitId = kitId; +} // KitOptionsPageWidget -class KitOptionsPageWidget; - -static QPointer kitOptionsPageWidget; - class KitOptionsPageWidget : public Core::IOptionsPageWidget { public: @@ -44,6 +52,8 @@ public: void makeDefaultKit(); void updateState(); + void scrollToSelectedKit(); + void apply() final { m_model->apply(); } public: @@ -62,7 +72,6 @@ public: KitOptionsPageWidget::KitOptionsPageWidget() { - kitOptionsPageWidget = this; m_kitsView = new QTreeView(this); m_kitsView->setUniformRowHeights(true); m_kitsView->header()->setStretchLastSection(true); @@ -140,9 +149,22 @@ KitOptionsPageWidget::KitOptionsPageWidget() m_model->updateVisibility(); } }); + + scrollToSelectedKit(); + updateState(); } +void KitOptionsPageWidget::scrollToSelectedKit() +{ + QModelIndex index = m_model->indexOf(selectedKitId); + m_selectionModel->select(index, + QItemSelectionModel::Clear + | QItemSelectionModel::SelectCurrent + | QItemSelectionModel::Rows); + m_kitsView->scrollTo(index); +} + void KitOptionsPageWidget::kitSelectionChanged() { QModelIndex current = currentIndex(); @@ -238,37 +260,22 @@ QModelIndex KitOptionsPageWidget::currentIndex() const return idxs.at(0); } -} // namespace Internal +// KitOptionsPage -// -------------------------------------------------------------------------- -// KitOptionsPage: -// -------------------------------------------------------------------------- - -KitOptionsPage::KitOptionsPage() +class KitsSettingsPage : public Core::IOptionsPage { - setId(Constants::KITS_SETTINGS_PAGE_ID); - setDisplayName(Tr::tr("Kits")); - setCategory(Constants::KITS_SETTINGS_CATEGORY); - setDisplayCategory(Tr::tr("Kits")); - setCategoryIconPath(":/projectexplorer/images/settingscategory_kits.png"); - setWidgetCreator([] { return new Internal::KitOptionsPageWidget; }); -} +public: + KitsSettingsPage() + { + setId(Constants::KITS_SETTINGS_PAGE_ID); + setDisplayName(Tr::tr("Kits")); + setCategory(Constants::KITS_SETTINGS_CATEGORY); + setDisplayCategory(Tr::tr("Kits")); + setCategoryIconPath(":/projectexplorer/images/settingscategory_kits.png"); + setWidgetCreator([] { return new Internal::KitOptionsPageWidget; }); + } +}; -void KitOptionsPage::showKit(Kit *k) -{ - if (!k) - return; +const KitsSettingsPage theKitsSettingsPage; - Internal::KitOptionsPageWidget *widget = Internal::kitOptionsPageWidget; - if (!widget) - return; - - QModelIndex index = widget->m_model->indexOf(k); - widget->m_selectionModel->select(index, - QItemSelectionModel::Clear - | QItemSelectionModel::SelectCurrent - | QItemSelectionModel::Rows); - widget->m_kitsView->scrollTo(index); -} - -} // namespace ProjectExplorer +} // ProjectExplorer::Internal diff --git a/src/plugins/projectexplorer/kitoptionspage.h b/src/plugins/projectexplorer/kitoptionspage.h index a7a4ba29dbc..ae8d42e88dc 100644 --- a/src/plugins/projectexplorer/kitoptionspage.h +++ b/src/plugins/projectexplorer/kitoptionspage.h @@ -3,20 +3,10 @@ #pragma once -#include "projectexplorer_export.h" +namespace Utils { class Id; } -#include +namespace ProjectExplorer::Internal { -namespace ProjectExplorer { +void setSelectectKitId(const Utils::Id &kitId); -class Kit; - -class PROJECTEXPLORER_EXPORT KitOptionsPage : public Core::IOptionsPage -{ -public: - KitOptionsPage(); - - static void showKit(Kit *k); -}; - -} // namespace ProjectExplorer +} // ProjectExplorer::Internal diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 063196c65fd..55b4d28cc1a 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -636,7 +636,6 @@ public: DesktopDeviceFactory m_desktopDeviceFactory; ToolChainOptionsPage m_toolChainOptionsPage; - KitOptionsPage m_kitOptionsPage; TaskHub m_taskHub; diff --git a/src/plugins/projectexplorer/projectwindow.cpp b/src/plugins/projectexplorer/projectwindow.cpp index 1ad0b256a2a..e9f5d82adb3 100644 --- a/src/plugins/projectexplorer/projectwindow.cpp +++ b/src/plugins/projectexplorer/projectwindow.cpp @@ -741,8 +741,17 @@ public: void handleManageKits() { - if (ProjectItem *projectItem = m_projectsModel.rootItem()->childAt(0)) { - KitOptionsPage::showKit(KitManager::kit(Id::fromSetting(projectItem->data(0, KitIdRole)))); + const QModelIndexList selected = m_selectorTree->selectionModel()->selectedIndexes(); + if (!selected.isEmpty()) { + TreeItem *treeItem = m_projectsModel.itemForIndex(selected.front()); + while (treeItem) { + const Id kitId = Id::fromSetting(treeItem->data(0, KitIdRole)); + if (kitId.isValid()) { + setSelectectKitId(kitId); + break; + } + treeItem = treeItem->parent(); + } } ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID); } diff --git a/src/plugins/projectexplorer/targetsetupwidget.cpp b/src/plugins/projectexplorer/targetsetupwidget.cpp index 50e86ef02b8..ea49a54c75b 100644 --- a/src/plugins/projectexplorer/targetsetupwidget.cpp +++ b/src/plugins/projectexplorer/targetsetupwidget.cpp @@ -180,7 +180,7 @@ void TargetSetupWidget::manageKit() if (!m_kit) return; - KitOptionsPage::showKit(m_kit); + setSelectectKitId(m_kit->id()); Core::ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, parentWidget()); }