ProjectExplorer: Introduce a KitAspect::createManageButton() function

Saves some repetition downstream.

Change-Id: Ied58586572d3e70669c9172c5076bbd12e211aa7
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2021-04-12 10:58:54 +02:00
parent 77481f25ce
commit 7eb9d8cb60
8 changed files with 30 additions and 68 deletions

View File

@@ -31,19 +31,20 @@
#include "cmaketool.h" #include "cmaketool.h"
#include "cmaketoolmanager.h" #include "cmaketoolmanager.h"
#include <coreplugin/icore.h> #include <app/app_version.h>
#include <ios/iosconstants.h> #include <ios/iosconstants.h>
#include <projectexplorer/kitinformation.h> #include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectexplorersettings.h> #include <projectexplorer/projectexplorersettings.h>
#include <projectexplorer/task.h> #include <projectexplorer/task.h>
#include <projectexplorer/toolchain.h> #include <projectexplorer/toolchain.h>
#include <qtsupport/baseqtversion.h> #include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h> #include <qtsupport/qtkitinformation.h>
#include <app/app_version.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/elidinglabel.h> #include <utils/elidinglabel.h>
#include <utils/environment.h> #include <utils/environment.h>
@@ -89,7 +90,7 @@ class CMakeKitAspectWidget final : public KitAspectWidget
public: public:
CMakeKitAspectWidget(Kit *kit, const KitAspect *ki) : KitAspectWidget(kit, ki), CMakeKitAspectWidget(Kit *kit, const KitAspect *ki) : KitAspectWidget(kit, ki),
m_comboBox(createSubWidget<QComboBox>()), m_comboBox(createSubWidget<QComboBox>()),
m_manageButton(createSubWidget<QPushButton>(KitAspectWidget::msgManage())) m_manageButton(createManageButton(Constants::CMAKE_SETTINGS_PAGE_ID))
{ {
m_comboBox->setSizePolicy(QSizePolicy::Ignored, m_comboBox->sizePolicy().verticalPolicy()); m_comboBox->setSizePolicy(QSizePolicy::Ignored, m_comboBox->sizePolicy().verticalPolicy());
m_comboBox->setEnabled(false); m_comboBox->setEnabled(false);
@@ -103,10 +104,6 @@ public:
connect(m_comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), connect(m_comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &CMakeKitAspectWidget::currentCMakeToolChanged); this, &CMakeKitAspectWidget::currentCMakeToolChanged);
m_manageButton->setContentsMargins(0, 0, 0, 0);
connect(m_manageButton, &QPushButton::clicked,
this, &CMakeKitAspectWidget::manageCMakeTools);
CMakeToolManager *cmakeMgr = CMakeToolManager::instance(); CMakeToolManager *cmakeMgr = CMakeToolManager::instance();
connect(cmakeMgr, &CMakeToolManager::cmakeAdded, connect(cmakeMgr, &CMakeToolManager::cmakeAdded,
this, &CMakeKitAspectWidget::cmakeToolAdded); this, &CMakeKitAspectWidget::cmakeToolAdded);
@@ -209,14 +206,9 @@ private:
CMakeKitAspect::setCMakeTool(m_kit, id); CMakeKitAspect::setCMakeTool(m_kit, id);
} }
void manageCMakeTools()
{
Core::ICore::showOptionsDialog(Constants::CMAKE_SETTINGS_PAGE_ID, m_manageButton);
}
bool m_removingItem = false; bool m_removingItem = false;
QComboBox *m_comboBox; QComboBox *m_comboBox;
QPushButton *m_manageButton; QWidget *m_manageButton;
}; };
CMakeKitAspect::CMakeKitAspect() CMakeKitAspect::CMakeKitAspect()

View File

@@ -28,8 +28,6 @@
#include "debuggeritemmanager.h" #include "debuggeritemmanager.h"
#include "debuggeritem.h" #include "debuggeritem.h"
#include <coreplugin/icore.h>
#include <projectexplorer/toolchain.h> #include <projectexplorer/toolchain.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runcontrol.h> #include <projectexplorer/runcontrol.h>
@@ -42,7 +40,7 @@
#include <QComboBox> #include <QComboBox>
#include <QFileInfo> #include <QFileInfo>
#include <QPushButton>
#include <utility> #include <utility>
using namespace ProjectExplorer; using namespace ProjectExplorer;
@@ -73,10 +71,7 @@ public:
connect(m_comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), connect(m_comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &DebuggerKitAspectWidget::currentDebuggerChanged); this, &DebuggerKitAspectWidget::currentDebuggerChanged);
m_manageButton = createSubWidget<QPushButton>(KitAspectWidget::msgManage()); m_manageButton = createManageButton(ProjectExplorer::Constants::DEBUGGER_SETTINGS_PAGE_ID);
m_manageButton->setContentsMargins(0, 0, 0, 0);
connect(m_manageButton, &QAbstractButton::clicked,
this, &DebuggerKitAspectWidget::manageDebuggers);
} }
~DebuggerKitAspectWidget() override ~DebuggerKitAspectWidget() override
@@ -112,12 +107,6 @@ private:
m_ignoreChanges = false; m_ignoreChanges = false;
} }
void manageDebuggers()
{
Core::ICore::showOptionsDialog(ProjectExplorer::Constants::DEBUGGER_SETTINGS_PAGE_ID,
m_manageButton);
}
void currentDebuggerChanged(int idx) void currentDebuggerChanged(int idx)
{ {
Q_UNUSED(idx) Q_UNUSED(idx)
@@ -144,7 +133,7 @@ private:
bool m_ignoreChanges = false; bool m_ignoreChanges = false;
QComboBox *m_comboBox; QComboBox *m_comboBox;
QPushButton *m_manageButton; QWidget *m_manageButton;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -29,7 +29,6 @@
#include "mesontoolkitaspect.h" #include "mesontoolkitaspect.h"
#include "ninjatoolkitaspect.h" #include "ninjatoolkitaspect.h"
#include <coreplugin/icore.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
namespace MesonProjectManager { namespace MesonProjectManager {
@@ -40,7 +39,7 @@ ToolKitAspectWidget::ToolKitAspectWidget(ProjectExplorer::Kit *kit,
ToolType type) ToolType type)
: ProjectExplorer::KitAspectWidget(kit, ki) : ProjectExplorer::KitAspectWidget(kit, ki)
, m_toolsComboBox(createSubWidget<QComboBox>()) , m_toolsComboBox(createSubWidget<QComboBox>())
, m_manageButton(createSubWidget<QPushButton>(KitAspectWidget::msgManage())) , m_manageButton(createManageButton(Constants::SettingsPage::TOOLS_ID))
, m_type{type} , m_type{type}
{ {
m_toolsComboBox->setSizePolicy(QSizePolicy::Ignored, m_toolsComboBox->setSizePolicy(QSizePolicy::Ignored,
@@ -49,11 +48,6 @@ ToolKitAspectWidget::ToolKitAspectWidget(ProjectExplorer::Kit *kit,
m_toolsComboBox->setToolTip(ki->description()); m_toolsComboBox->setToolTip(ki->description());
loadTools(); loadTools();
m_manageButton->setContentsMargins(0, 0, 0, 0);
connect(m_manageButton, &QPushButton::clicked, this, [this]() {
Core::ICore::showOptionsDialog(Constants::SettingsPage::TOOLS_ID, m_manageButton);
});
connect(MesonTools::instance(), connect(MesonTools::instance(),
&MesonTools::toolAdded, &MesonTools::toolAdded,
this, this,

View File

@@ -34,7 +34,6 @@
#include <QComboBox> #include <QComboBox>
#include <QCoreApplication> #include <QCoreApplication>
#include <QPushButton>
namespace MesonProjectManager { namespace MesonProjectManager {
namespace Internal { namespace Internal {
@@ -83,7 +82,7 @@ private:
} }
QComboBox *m_toolsComboBox; QComboBox *m_toolsComboBox;
QPushButton *m_manageButton; QWidget *m_manageButton;
ToolType m_type; ToolType m_type;
}; };

View File

@@ -35,8 +35,8 @@
#include "toolchain.h" #include "toolchain.h"
#include "toolchainmanager.h" #include "toolchainmanager.h"
#include <coreplugin/icore.h>
#include <ssh/sshconnection.h> #include <ssh/sshconnection.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/elidinglabel.h> #include <utils/elidinglabel.h>
#include <utils/environment.h> #include <utils/environment.h>
@@ -249,10 +249,7 @@ public:
refresh(); refresh();
m_manageButton = createSubWidget<QPushButton>(KitAspectWidget::msgManage()); m_manageButton = createManageButton(Constants::TOOLCHAIN_SETTINGS_PAGE_ID);
m_manageButton->setContentsMargins(0, 0, 0, 0);
connect(m_manageButton, &QAbstractButton::clicked,
this, &ToolChainKitAspectWidget::manageToolChains);
} }
~ToolChainKitAspectWidget() override ~ToolChainKitAspectWidget() override
@@ -298,11 +295,6 @@ private:
} }
} }
void manageToolChains()
{
Core::ICore::showOptionsDialog(Constants::TOOLCHAIN_SETTINGS_PAGE_ID, m_manageButton);
}
void currentToolChainChanged(Utils::Id language, int idx) void currentToolChainChanged(Utils::Id language, int idx)
{ {
if (m_ignoreChanges || idx < 0) if (m_ignoreChanges || idx < 0)
@@ -328,7 +320,7 @@ private:
} }
QWidget *m_mainWidget = nullptr; QWidget *m_mainWidget = nullptr;
QPushButton *m_manageButton = nullptr; QWidget *m_manageButton = nullptr;
QHash<Utils::Id, QComboBox *> m_languageComboboxMap; QHash<Utils::Id, QComboBox *> m_languageComboboxMap;
bool m_ignoreChanges = false; bool m_ignoreChanges = false;
bool m_isReadOnly = false; bool m_isReadOnly = false;
@@ -839,7 +831,7 @@ public:
{ {
m_comboBox->setSizePolicy(QSizePolicy::Ignored, m_comboBox->sizePolicy().verticalPolicy()); m_comboBox->setSizePolicy(QSizePolicy::Ignored, m_comboBox->sizePolicy().verticalPolicy());
m_comboBox->setModel(m_model); m_comboBox->setModel(m_model);
m_manageButton = createSubWidget<QPushButton>(KitAspectWidget::msgManage()); m_manageButton = createManageButton(Constants::DEVICE_SETTINGS_PAGE_ID);
refresh(); refresh();
m_comboBox->setToolTip(ki->description()); m_comboBox->setToolTip(ki->description());
@@ -849,8 +841,6 @@ public:
this, &DeviceKitAspectWidget::modelReset); this, &DeviceKitAspectWidget::modelReset);
connect(m_comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), connect(m_comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &DeviceKitAspectWidget::currentDeviceChanged); this, &DeviceKitAspectWidget::currentDeviceChanged);
connect(m_manageButton, &QAbstractButton::clicked,
this, &DeviceKitAspectWidget::manageDevices);
} }
~DeviceKitAspectWidget() override ~DeviceKitAspectWidget() override
@@ -876,11 +866,6 @@ private:
m_comboBox->setCurrentIndex(m_model->indexOf(DeviceKitAspect::device(m_kit))); m_comboBox->setCurrentIndex(m_model->indexOf(DeviceKitAspect::device(m_kit)));
} }
void manageDevices()
{
Core::ICore::showOptionsDialog(Constants::DEVICE_SETTINGS_PAGE_ID, m_manageButton);
}
void modelAboutToReset() void modelAboutToReset()
{ {
m_selectedId = m_model->deviceId(m_comboBox->currentIndex()); m_selectedId = m_model->deviceId(m_comboBox->currentIndex());
@@ -902,7 +887,7 @@ private:
bool m_ignoreChange = false; bool m_ignoreChange = false;
QComboBox *m_comboBox; QComboBox *m_comboBox;
QPushButton *m_manageButton; QWidget *m_manageButton;
DeviceManagerModel *m_model; DeviceManagerModel *m_model;
Utils::Id m_selectedId; Utils::Id m_selectedId;
}; };

View File

@@ -53,6 +53,7 @@
#include <QAction> #include <QAction>
#include <QHash> #include <QHash>
#include <QLabel> #include <QLabel>
#include <QPushButton>
#include <QSettings> #include <QSettings>
#include <QStyle> #include <QStyle>
@@ -760,6 +761,15 @@ void KitAspectWidget::addMutableAction(QWidget *child)
child->setContextMenuPolicy(Qt::ActionsContextMenu); child->setContextMenuPolicy(Qt::ActionsContextMenu);
} }
QWidget *KitAspectWidget::createManageButton(Id pageId)
{
auto button = createSubWidget<QPushButton>(msgManage());
connect(button, &QPushButton::clicked, this, [pageId] {
Core::ICore::showOptionsDialog(pageId);
});
return button;
}
QString KitAspectWidget::msgManage() QString KitAspectWidget::msgManage()
{ {
return tr("Manage..."); return tr("Manage...");

View File

@@ -146,6 +146,7 @@ public:
const KitAspect *kitInformation() const { return m_kitInformation; } const KitAspect *kitInformation() const { return m_kitInformation; }
QAction *mutableAction() const { return m_mutableAction; } QAction *mutableAction() const { return m_mutableAction; }
void addMutableAction(QWidget *child); void addMutableAction(QWidget *child);
QWidget *createManageButton(Utils::Id pageId);
protected: protected:
Kit *m_kit; Kit *m_kit;

View File

@@ -30,11 +30,11 @@
#include "qtparser.h" #include "qtparser.h"
#include "qttestparser.h" #include "qttestparser.h"
#include <coreplugin/icore.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/task.h> #include <projectexplorer/task.h>
#include <projectexplorer/toolchain.h> #include <projectexplorer/toolchain.h>
#include <projectexplorer/toolchainmanager.h> #include <projectexplorer/toolchainmanager.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/buildablehelperlibrary.h> #include <utils/buildablehelperlibrary.h>
#include <utils/layoutbuilder.h> #include <utils/layoutbuilder.h>
@@ -42,7 +42,6 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QComboBox> #include <QComboBox>
#include <QPushButton>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
@@ -63,7 +62,7 @@ public:
QList<int> versionIds = Utils::transform(QtVersionManager::versions(), &BaseQtVersion::uniqueId); QList<int> versionIds = Utils::transform(QtVersionManager::versions(), &BaseQtVersion::uniqueId);
versionsChanged(versionIds, QList<int>(), QList<int>()); versionsChanged(versionIds, QList<int>(), QList<int>());
m_manageButton = createSubWidget<QPushButton>(KitAspectWidget::msgManage()); m_manageButton = createManageButton(Constants::QTVERSION_SETTINGS_PAGE_ID);
refresh(); refresh();
m_combo->setToolTip(ki->description()); m_combo->setToolTip(ki->description());
@@ -73,8 +72,6 @@ public:
connect(QtVersionManager::instance(), &QtVersionManager::qtVersionsChanged, connect(QtVersionManager::instance(), &QtVersionManager::qtVersionsChanged,
this, &QtKitAspectWidget::versionsChanged); this, &QtKitAspectWidget::versionsChanged);
connect(m_manageButton, &QAbstractButton::clicked, this, &QtKitAspectWidget::manageQtVersions);
} }
~QtKitAspectWidget() final ~QtKitAspectWidget() final
@@ -129,11 +126,6 @@ private:
} }
} }
void manageQtVersions()
{
Core::ICore::showOptionsDialog(Constants::QTVERSION_SETTINGS_PAGE_ID, m_manageButton);
}
void currentWasChanged(int idx) void currentWasChanged(int idx)
{ {
QtKitAspect::setQtVersionId(m_kit, m_combo->itemData(idx).toInt()); QtKitAspect::setQtVersionId(m_kit, m_combo->itemData(idx).toInt());
@@ -149,7 +141,7 @@ private:
} }
QComboBox *m_combo; QComboBox *m_combo;
QPushButton *m_manageButton; QWidget *m_manageButton;
}; };
} // namespace Internal } // namespace Internal