ProjectExplorer: Start with selected kit

If there's one; when clicking "Manage Kits..." in project mode.

Change-Id: I06a92d8e286f7b2b54844b7f41029d7c64684398
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2023-08-18 17:02:13 +02:00
parent 70aad61e97
commit c18de1ecb6
7 changed files with 68 additions and 55 deletions

View File

@@ -188,6 +188,12 @@ KitNode *KitModel::kitNode(const QModelIndex &index)
return (n && n->level() == 2) ? static_cast<KitNode *>(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);

View File

@@ -5,6 +5,7 @@
#include "projectexplorer_export.h"
#include <utils/id.h>
#include <utils/treemodel.h>
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;

View File

@@ -11,6 +11,8 @@
#include "kitmanagerconfigwidget.h"
#include "kitmanager.h"
#include <coreplugin/dialogs/ioptionspage.h>
#include <utils/qtcassert.h>
#include <QHBoxLayout>
@@ -20,15 +22,21 @@
#include <QTreeView>
#include <QVBoxLayout>
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> 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
{
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

View File

@@ -3,20 +3,10 @@
#pragma once
#include "projectexplorer_export.h"
namespace Utils { class Id; }
#include <coreplugin/dialogs/ioptionspage.h>
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

View File

@@ -636,7 +636,6 @@ public:
DesktopDeviceFactory m_desktopDeviceFactory;
ToolChainOptionsPage m_toolChainOptionsPage;
KitOptionsPage m_kitOptionsPage;
TaskHub m_taskHub;

View File

@@ -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);
}

View File

@@ -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());
}