forked from qt-creator/qt-creator
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:
@@ -188,6 +188,12 @@ KitNode *KitModel::kitNode(const QModelIndex &index)
|
|||||||
return (n && n->level() == 2) ? static_cast<KitNode *>(n) : nullptr;
|
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
|
QModelIndex KitModel::indexOf(Kit *k) const
|
||||||
{
|
{
|
||||||
KitNode *n = findWorkingCopy(k);
|
KitNode *n = findWorkingCopy(k);
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "projectexplorer_export.h"
|
#include "projectexplorer_export.h"
|
||||||
|
|
||||||
|
#include <utils/id.h>
|
||||||
#include <utils/treemodel.h>
|
#include <utils/treemodel.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@@ -36,6 +37,7 @@ public:
|
|||||||
Kit *kit(const QModelIndex &);
|
Kit *kit(const QModelIndex &);
|
||||||
KitNode *kitNode(const QModelIndex &);
|
KitNode *kitNode(const QModelIndex &);
|
||||||
QModelIndex indexOf(Kit *k) const;
|
QModelIndex indexOf(Kit *k) const;
|
||||||
|
QModelIndex indexOf(Utils::Id kitId) const;
|
||||||
|
|
||||||
void setDefaultKit(const QModelIndex &index);
|
void setDefaultKit(const QModelIndex &index);
|
||||||
bool isDefaultKit(Kit *k) const;
|
bool isDefaultKit(Kit *k) const;
|
||||||
|
@@ -11,6 +11,8 @@
|
|||||||
#include "kitmanagerconfigwidget.h"
|
#include "kitmanagerconfigwidget.h"
|
||||||
#include "kitmanager.h"
|
#include "kitmanager.h"
|
||||||
|
|
||||||
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
@@ -20,15 +22,21 @@
|
|||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
using namespace Utils;
|
||||||
namespace Internal {
|
|
||||||
|
namespace ProjectExplorer::Internal {
|
||||||
|
|
||||||
|
// Page pre-selection
|
||||||
|
|
||||||
|
static Id selectedKitId;
|
||||||
|
|
||||||
|
void setSelectectKitId(const Utils::Id &kitId)
|
||||||
|
{
|
||||||
|
selectedKitId = kitId;
|
||||||
|
}
|
||||||
|
|
||||||
// KitOptionsPageWidget
|
// KitOptionsPageWidget
|
||||||
|
|
||||||
class KitOptionsPageWidget;
|
|
||||||
|
|
||||||
static QPointer<KitOptionsPageWidget> kitOptionsPageWidget;
|
|
||||||
|
|
||||||
class KitOptionsPageWidget : public Core::IOptionsPageWidget
|
class KitOptionsPageWidget : public Core::IOptionsPageWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -44,6 +52,8 @@ public:
|
|||||||
void makeDefaultKit();
|
void makeDefaultKit();
|
||||||
void updateState();
|
void updateState();
|
||||||
|
|
||||||
|
void scrollToSelectedKit();
|
||||||
|
|
||||||
void apply() final { m_model->apply(); }
|
void apply() final { m_model->apply(); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -62,7 +72,6 @@ public:
|
|||||||
|
|
||||||
KitOptionsPageWidget::KitOptionsPageWidget()
|
KitOptionsPageWidget::KitOptionsPageWidget()
|
||||||
{
|
{
|
||||||
kitOptionsPageWidget = this;
|
|
||||||
m_kitsView = new QTreeView(this);
|
m_kitsView = new QTreeView(this);
|
||||||
m_kitsView->setUniformRowHeights(true);
|
m_kitsView->setUniformRowHeights(true);
|
||||||
m_kitsView->header()->setStretchLastSection(true);
|
m_kitsView->header()->setStretchLastSection(true);
|
||||||
@@ -140,9 +149,22 @@ KitOptionsPageWidget::KitOptionsPageWidget()
|
|||||||
m_model->updateVisibility();
|
m_model->updateVisibility();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
scrollToSelectedKit();
|
||||||
|
|
||||||
updateState();
|
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()
|
void KitOptionsPageWidget::kitSelectionChanged()
|
||||||
{
|
{
|
||||||
QModelIndex current = currentIndex();
|
QModelIndex current = currentIndex();
|
||||||
@@ -238,37 +260,22 @@ QModelIndex KitOptionsPageWidget::currentIndex() const
|
|||||||
return idxs.at(0);
|
return idxs.at(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
// KitOptionsPage
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
class KitsSettingsPage : public Core::IOptionsPage
|
||||||
// KitOptionsPage:
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
KitOptionsPage::KitOptionsPage()
|
|
||||||
{
|
{
|
||||||
setId(Constants::KITS_SETTINGS_PAGE_ID);
|
public:
|
||||||
setDisplayName(Tr::tr("Kits"));
|
KitsSettingsPage()
|
||||||
setCategory(Constants::KITS_SETTINGS_CATEGORY);
|
{
|
||||||
setDisplayCategory(Tr::tr("Kits"));
|
setId(Constants::KITS_SETTINGS_PAGE_ID);
|
||||||
setCategoryIconPath(":/projectexplorer/images/settingscategory_kits.png");
|
setDisplayName(Tr::tr("Kits"));
|
||||||
setWidgetCreator([] { return new Internal::KitOptionsPageWidget; });
|
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)
|
const KitsSettingsPage theKitsSettingsPage;
|
||||||
{
|
|
||||||
if (!k)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Internal::KitOptionsPageWidget *widget = Internal::kitOptionsPageWidget;
|
} // ProjectExplorer::Internal
|
||||||
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
|
|
||||||
|
@@ -3,20 +3,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#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;
|
} // ProjectExplorer::Internal
|
||||||
|
|
||||||
class PROJECTEXPLORER_EXPORT KitOptionsPage : public Core::IOptionsPage
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
KitOptionsPage();
|
|
||||||
|
|
||||||
static void showKit(Kit *k);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
|
||||||
|
@@ -636,7 +636,6 @@ public:
|
|||||||
DesktopDeviceFactory m_desktopDeviceFactory;
|
DesktopDeviceFactory m_desktopDeviceFactory;
|
||||||
|
|
||||||
ToolChainOptionsPage m_toolChainOptionsPage;
|
ToolChainOptionsPage m_toolChainOptionsPage;
|
||||||
KitOptionsPage m_kitOptionsPage;
|
|
||||||
|
|
||||||
TaskHub m_taskHub;
|
TaskHub m_taskHub;
|
||||||
|
|
||||||
|
@@ -741,8 +741,17 @@ public:
|
|||||||
|
|
||||||
void handleManageKits()
|
void handleManageKits()
|
||||||
{
|
{
|
||||||
if (ProjectItem *projectItem = m_projectsModel.rootItem()->childAt(0)) {
|
const QModelIndexList selected = m_selectorTree->selectionModel()->selectedIndexes();
|
||||||
KitOptionsPage::showKit(KitManager::kit(Id::fromSetting(projectItem->data(0, KitIdRole))));
|
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);
|
ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID);
|
||||||
}
|
}
|
||||||
|
@@ -180,7 +180,7 @@ void TargetSetupWidget::manageKit()
|
|||||||
if (!m_kit)
|
if (!m_kit)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
KitOptionsPage::showKit(m_kit);
|
setSelectectKitId(m_kit->id());
|
||||||
Core::ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, parentWidget());
|
Core::ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, parentWidget());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user