Core: Let callers specify which part of an options page to pre-select

... and use it for the "Manage kits" functionality.
We will make use of this in other contexts as well.

Task-number: QTCREATORBUG-25077
Change-Id: I79c622075b9385b060aed73534d39acc23fd765e
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2024-01-18 17:43:33 +01:00
parent b9cce1a0ba
commit 3fc1b5f57b
8 changed files with 41 additions and 18 deletions

View File

@@ -13,6 +13,7 @@
#include <QCheckBox>
#include <QGroupBox>
#include <QHash>
#include <QLabel>
#include <QPushButton>
#include <QRegularExpression>
@@ -309,4 +310,16 @@ const QList<IOptionsPageProvider *> IOptionsPageProvider::allOptionsPagesProvide
return g_optionsPagesProviders;
}
static QHash<Id, Id> g_preselectedOptionPageItems;
void setPreselectedOptionsPageItem(Id page, Id item)
{
g_preselectedOptionPageItems.insert(page, item);
}
Id preselectedOptionsPageItem(Id page)
{
return g_preselectedOptionPageItems.value(page);
}
} // Core

View File

@@ -119,4 +119,9 @@ protected:
Utils::FilePath m_categoryIconPath;
};
// Which part of the settings page to pre-select, if applicable. In practice, this will
// usually be an item in some sort of (list) view.
void CORE_EXPORT setPreselectedOptionsPageItem(Utils::Id page, Utils::Id item);
Utils::Id CORE_EXPORT preselectedOptionsPageItem(Utils::Id page);
} // namespace Core

View File

@@ -477,6 +477,24 @@ bool ICore::showOptionsDialog(const Id page, QWidget *parent)
return executeSettingsDialog(parent ? parent : dialogParent(), page);
}
/*!
Opens the options dialog on the specified \a page. The dialog's \a parent
defaults to dialogParent(). If the dialog is already shown when this method
is called, it is just switched to the specified \a page.
Pre-selects some part of the dialog specified by \a item which the dialog
knows how to interpret.
Returns whether the user accepted the dialog.
\sa msgShowOptionsDialog()
\sa msgShowOptionsDialogToolTip()
*/
bool ICore::showOptionsDialog(const Utils::Id page, Utils::Id item, QWidget *parent)
{
setPreselectedOptionsPageItem(page, item);
return showOptionsDialog(page, parent);
}
/*!
Returns the text to use on buttons that open the options dialog.

View File

@@ -55,6 +55,7 @@ public:
const QVariantMap &extraVariables = {});
static bool showOptionsDialog(const Utils::Id page, QWidget *parent = nullptr);
static bool showOptionsDialog(const Utils::Id page, Utils::Id item, QWidget *parent = nullptr);
static QString msgShowOptionsDialog();
static QString msgShowOptionsDialogToolTip();

View File

@@ -50,15 +50,6 @@ bool KitSettingsSortModel::lessThan(const QModelIndex &source_left,
namespace Internal {
// Page pre-selection
static Id selectedKitId;
void setSelectectKitId(const Id &kitId)
{
selectedKitId = kitId;
}
class KitManagerConfigWidget;
class KitNode : public TreeItem
@@ -595,7 +586,8 @@ KitOptionsPageWidget::KitOptionsPageWidget()
void KitOptionsPageWidget::scrollToSelectedKit()
{
QModelIndex index = m_sortModel->mapFromSource(m_model->indexOf(selectedKitId));
QModelIndex index = m_sortModel->mapFromSource(
m_model->indexOf(Core::preselectedOptionsPageItem(Constants::KITS_SETTINGS_PAGE_ID)));
m_selectionModel->select(index,
QItemSelectionModel::Clear
| QItemSelectionModel::SelectCurrent

View File

@@ -24,9 +24,4 @@ private:
QStringList m_sortedCategories;
};
namespace Internal {
void setSelectectKitId(const Utils::Id &kitId);
} // Internal
} // ProjectExplorer

View File

@@ -914,7 +914,7 @@ public:
while (treeItem) {
const Id kitId = Id::fromSetting(treeItem->data(0, KitIdRole));
if (kitId.isValid()) {
setSelectectKitId(kitId);
Core::setPreselectedOptionsPageItem(Constants::KITS_SETTINGS_PAGE_ID, kitId);
break;
}
treeItem = treeItem->parent();

View File

@@ -182,8 +182,7 @@ void TargetSetupWidget::manageKit()
if (!m_kit)
return;
setSelectectKitId(m_kit->id());
Core::ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, parentWidget());
Core::ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, m_kit->id(), parentWidget());
}
void TargetSetupWidget::setProjectPath(const FilePath &projectPath)