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

View File

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

View File

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

View File

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

View File

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

View File

@@ -53,6 +53,7 @@
#include <QAction>
#include <QHash>
#include <QLabel>
#include <QPushButton>
#include <QSettings>
#include <QStyle>
@@ -760,6 +761,15 @@ void KitAspectWidget::addMutableAction(QWidget *child)
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()
{
return tr("Manage...");

View File

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

View File

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