ProjectExplorer: Create project panels centrally

Change-Id: I4b6fb52edb4b7d6df4e1184c432d239b77b30aac
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2025-06-13 12:29:53 +02:00
parent 0c13aecc70
commit f2112161ca
8 changed files with 109 additions and 173 deletions

View File

@@ -114,7 +114,6 @@ add_qtc_plugin(ProjectExplorer
msvcparser.cpp msvcparser.h
msvctoolchain.cpp msvctoolchain.h
osparser.cpp osparser.h
panelswidget.cpp panelswidget.h
parseissuesdialog.cpp parseissuesdialog.h
processparameters.cpp processparameters.h
processstep.cpp processstep.h

View File

@@ -6,7 +6,6 @@
#include "buildconfiguration.h"
#include "buildinfo.h"
#include "buildmanager.h"
#include "panelswidget.h"
#include "project.h"
#include "projectconfigurationmodel.h"
#include "projectexplorertr.h"
@@ -358,9 +357,7 @@ void BuildSettingsWidget::deleteConfiguration(BuildConfiguration *deleteConfigur
QWidget *createBuildSettingsWidget(Target *target)
{
auto panel = new PanelsWidget(true);
panel->addWidget(new BuildSettingsWidget(target));
return panel;
return new BuildSettingsWidget(target);
}
} // ProjectExplorer::Internal

View File

@@ -1,113 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "panelswidget.h"
#include <coreplugin/icore.h>
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
#include <utils/stylehelper.h>
#include <utils/theme/theme.h>
#include <QCheckBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QScrollArea>
#include <QVBoxLayout>
using namespace Utils;
namespace ProjectExplorer::Internal {
const int ABOVE_HEADING_MARGIN = 10;
const int CONTENTS_MARGIN = 5;
const int BELOW_CONTENTS_MARGIN = 16;
PanelsWidget::PanelsWidget(bool addStretch)
{
m_root = new QWidget(nullptr);
m_root->setFocusPolicy(Qt::NoFocus);
m_root->setContentsMargins(0, 0, 0, 0);
const auto scroller = new QScrollArea(this);
scroller->setWidget(m_root);
scroller->setFrameStyle(QFrame::NoFrame);
scroller->setWidgetResizable(true);
scroller->setFocusPolicy(Qt::NoFocus);
// The layout holding the individual panels:
auto topLayout = new QVBoxLayout(m_root);
topLayout->setContentsMargins(PanelVMargin, 0, PanelVMargin, 0);
topLayout->setSpacing(0);
m_layout = new QVBoxLayout;
m_layout->setSpacing(0);
topLayout->addLayout(m_layout);
if (addStretch)
topLayout->addStretch(1);
auto layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(scroller);
//layout->addWidget(new FindToolBarPlaceHolder(this));
}
PanelsWidget::~PanelsWidget() = default;
void PanelsWidget::addWidget(QWidget *widget)
{
setWindowTitle(widget->windowTitle());
widget->setContentsMargins(0, CONTENTS_MARGIN, 0, BELOW_CONTENTS_MARGIN);
widget->setParent(m_root);
m_layout->addWidget(widget);
}
void PanelsWidget::addGlobalSettingsProperties(ProjectSettingsWidget *widget)
{
if (!widget->isUseGlobalSettingsCheckBoxVisible() && !widget->isUseGlobalSettingsLabelVisible())
return;
m_layout->setContentsMargins(0, 0, 0, 0);
const auto useGlobalSettingsCheckBox = new QCheckBox;
useGlobalSettingsCheckBox->setChecked(widget->useGlobalSettings());
useGlobalSettingsCheckBox->setEnabled(widget->isUseGlobalSettingsCheckBoxEnabled());
const QString labelText = widget->isUseGlobalSettingsCheckBoxVisible()
? QStringLiteral("Use <a href=\"dummy\">global settings</a>")
: QStringLiteral("<a href=\"dummy\">Global settings</a>");
const auto settingsLabel = new QLabel(labelText);
settingsLabel->setEnabled(widget->isUseGlobalSettingsCheckBoxEnabled());
const auto horizontalLayout = new QHBoxLayout;
horizontalLayout->setContentsMargins(0, CONTENTS_MARGIN, 0, CONTENTS_MARGIN);
horizontalLayout->setSpacing(CONTENTS_MARGIN);
if (widget->isUseGlobalSettingsCheckBoxVisible()) {
horizontalLayout->addWidget(useGlobalSettingsCheckBox);
connect(widget, &ProjectSettingsWidget::useGlobalSettingsCheckBoxEnabledChanged,
this, [useGlobalSettingsCheckBox, settingsLabel](bool enabled) {
useGlobalSettingsCheckBox->setEnabled(enabled);
settingsLabel->setEnabled(enabled);
});
connect(useGlobalSettingsCheckBox, &QCheckBox::stateChanged,
widget, &ProjectSettingsWidget::setUseGlobalSettings);
connect(widget, &ProjectSettingsWidget::useGlobalSettingsChanged,
useGlobalSettingsCheckBox, &QCheckBox::setChecked);
}
if (widget->isUseGlobalSettingsLabelVisible()) {
horizontalLayout->addWidget(settingsLabel);
connect(settingsLabel, &QLabel::linkActivated, this, [widget] {
Core::ICore::showOptionsDialog(widget->globalSettingsId());
});
}
horizontalLayout->addStretch(1);
m_layout->addLayout(horizontalLayout);
m_layout->addWidget(Layouting::createHr());
}
} // ProjectExplorer::Internal

View File

@@ -1,30 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "projectsettingswidget.h"
QT_BEGIN_NAMESPACE
class QVBoxLayout;
QT_END_NAMESPACE
namespace ProjectExplorer::Internal {
class PanelsWidget final : public QWidget
{
public:
explicit PanelsWidget(bool addStretch);
~PanelsWidget() final;
static int constexpr PanelVMargin = 14;
void addGlobalSettingsProperties(ProjectSettingsWidget *widget);
void addWidget(QWidget *widget);
private:
QVBoxLayout *m_layout;
QWidget *m_root;
};
} // ProjectExplorer::Internal

View File

@@ -88,7 +88,6 @@ QtcPlugin {
"msvcparser.cpp", "msvcparser.h",
"msvctoolchain.cpp", "msvctoolchain.h",
"osparser.cpp", "osparser.h",
"panelswidget.cpp", "panelswidget.h",
"parseissuesdialog.cpp", "parseissuesdialog.h",
"processparameters.cpp", "processparameters.h",
"processstep.cpp", "processstep.h",

View File

@@ -5,7 +5,6 @@
#include "project.h"
#include "projectsettingswidget.h"
#include "projectwindow.h"
#include <utils/layoutbuilder.h>

View File

@@ -10,7 +10,6 @@
#include "kit.h"
#include "kitmanager.h"
#include "kitoptionspage.h"
#include "panelswidget.h"
#include "project.h"
#include "projectexplorer.h"
#include "projectexplorerconstants.h"
@@ -56,6 +55,7 @@
#include <utils/utilsicons.h>
#include <QApplication>
#include <QCheckBox>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QDockWidget>
@@ -81,6 +81,105 @@ const char kRegExpActionId[] = "OutputFilter.RegularExpressions.BuildSystemOutpu
const char kCaseSensitiveActionId[] = "OutputFilter.CaseSensitive.BuildSystemOutput";
const char kInvertActionId[] = "OutputFilter.Invert.BuildSystemOutput";
const int CONTENTS_MARGIN = 5;
const int BELOW_CONTENTS_MARGIN = 16;
const int PanelVMargin = 14;
class ProjectPanel final : public QWidget
{
public:
explicit ProjectPanel(QWidget *inner, bool addGlobalSettings, bool addStretch)
{
setWindowTitle(inner->windowTitle());
auto root = new QWidget(nullptr);
root->setFocusPolicy(Qt::NoFocus);
root->setContentsMargins(0, 0, 0, 0);
const auto scroller = new QScrollArea(this);
scroller->setWidget(root);
scroller->setFrameStyle(QFrame::NoFrame);
scroller->setWidgetResizable(true);
scroller->setFocusPolicy(Qt::NoFocus);
// The layout holding the individual panels:
auto topLayout = new QVBoxLayout(root);
topLayout->setContentsMargins(PanelVMargin, 0, PanelVMargin, 0);
topLayout->setSpacing(0);
m_layout = new QVBoxLayout;
m_layout->setSpacing(0);
topLayout->addLayout(m_layout);
if (addStretch)
topLayout->addStretch(1);
auto layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(scroller);
//layout->addWidget(new FindToolBarPlaceHolder(this));
if (addGlobalSettings) {
auto widget = dynamic_cast<ProjectSettingsWidget *>(inner);
if (QTC_GUARD(widget)) {
if (widget->isUseGlobalSettingsCheckBoxVisible() || widget->isUseGlobalSettingsLabelVisible()) {
m_layout->setContentsMargins(0, 0, 0, 0);
const auto useGlobalSettingsCheckBox = new QCheckBox;
useGlobalSettingsCheckBox->setChecked(widget->useGlobalSettings());
useGlobalSettingsCheckBox->setEnabled(widget->isUseGlobalSettingsCheckBoxEnabled());
const QString labelText = widget->isUseGlobalSettingsCheckBoxVisible()
? QStringLiteral("Use <a href=\"dummy\">global settings</a>")
: QStringLiteral("<a href=\"dummy\">Global settings</a>");
const auto settingsLabel = new QLabel(labelText);
settingsLabel->setEnabled(widget->isUseGlobalSettingsCheckBoxEnabled());
const auto horizontalLayout = new QHBoxLayout;
horizontalLayout->setContentsMargins(0, CONTENTS_MARGIN, 0, CONTENTS_MARGIN);
horizontalLayout->setSpacing(CONTENTS_MARGIN);
if (widget->isUseGlobalSettingsCheckBoxVisible()) {
horizontalLayout->addWidget(useGlobalSettingsCheckBox);
connect(widget, &ProjectSettingsWidget::useGlobalSettingsCheckBoxEnabledChanged,
this, [useGlobalSettingsCheckBox, settingsLabel](bool enabled) {
useGlobalSettingsCheckBox->setEnabled(enabled);
settingsLabel->setEnabled(enabled);
});
connect(useGlobalSettingsCheckBox, &QCheckBox::stateChanged,
widget, &ProjectSettingsWidget::setUseGlobalSettings);
connect(widget, &ProjectSettingsWidget::useGlobalSettingsChanged,
useGlobalSettingsCheckBox, &QCheckBox::setChecked);
}
if (widget->isUseGlobalSettingsLabelVisible()) {
horizontalLayout->addWidget(settingsLabel);
connect(settingsLabel, &QLabel::linkActivated, this, [widget] {
Core::ICore::showOptionsDialog(widget->globalSettingsId());
});
}
horizontalLayout->addStretch(1);
m_layout->addLayout(horizontalLayout);
m_layout->addWidget(Layouting::createHr());
}
}
}
inner->setContentsMargins(0, CONTENTS_MARGIN, 0, BELOW_CONTENTS_MARGIN);
inner->setParent(root);
m_layout->addWidget(inner);
setFocusProxy(inner);
}
private:
QVBoxLayout *m_layout;
};
class BuildSystemOutputWindow : public OutputWindow
{
public:
@@ -502,13 +601,8 @@ QVariant MiscSettingsPanelItem::data(int column, int role) const
ProjectPanels MiscSettingsPanelItem::panelWidgets() const
{
if (!m_widget) {
ProjectSettingsWidget *inner = m_factory->createWidget(m_project);
auto panel = new PanelsWidget(true);
panel->addGlobalSettingsProperties(inner);
panel->addWidget(inner);
panel->setFocusProxy(inner);
panel->setWindowTitle(m_factory->displayName());
m_widget = panel;
m_widget = new ProjectPanel(m_factory->createWidget(m_project), true, false);
m_widget->setWindowTitle(m_factory->displayName());
}
return {m_widget.get()};
}
@@ -876,9 +970,9 @@ public:
ProjectPanels panelWidgets() const final
{
if (!m_buildSettingsWidget)
m_buildSettingsWidget = createBuildSettingsWidget(target());
m_buildSettingsWidget = new ProjectPanel(createBuildSettingsWidget(target()), false, true);
if (!m_runSettingsWidget)
m_runSettingsWidget = createRunSettingsWidget(target());
m_runSettingsWidget = new ProjectPanel(createRunSettingsWidget(target()), false, true);
return { m_buildSettingsWidget.get(), m_runSettingsWidget.get() };
}
@@ -1083,13 +1177,8 @@ ProjectItemBase *TargetGroupItem::activeItem()
ProjectPanels TargetGroupItem::panelWidgets() const
{
if (!m_targetSetupPage) {
auto inner = new TargetSetupPageWrapper(m_project);
auto panel = new PanelsWidget(false);
panel->addWidget(inner);
panel->setFocusProxy(inner);
m_targetSetupPage = panel;
}
if (!m_targetSetupPage)
m_targetSetupPage = new ProjectPanel(new TargetSetupPageWrapper(m_project), false, false);
return {m_targetSetupPage.get()};
}
@@ -1433,8 +1522,7 @@ public:
auto innerLayout = new QVBoxLayout;
innerLayout->setSpacing(10);
innerLayout->setContentsMargins(PanelsWidget::PanelVMargin, innerLayout->spacing(),
PanelsWidget::PanelVMargin, 0);
innerLayout->setContentsMargins(PanelVMargin, innerLayout->spacing(), PanelVMargin, 0);
#ifdef QT_NO_DEBUG
const QStringList list = ICore::settings()->value("HideOptionCategories").toStringList();
#else

View File

@@ -7,7 +7,6 @@
#include "buildmanager.h"
#include "buildstepspage.h"
#include "deployconfiguration.h"
#include "panelswidget.h"
#include "project.h"
#include "projectconfigurationmodel.h"
#include "projectexplorerconstants.h"
@@ -793,9 +792,7 @@ void RunSettingsWidget::updateEnabledState()
QWidget *createRunSettingsWidget(Target *target)
{
auto panel = new PanelsWidget(true);
panel->addWidget(new RunSettingsWidget(target));
return panel;
return new RunSettingsWidget(target);
}
} // ProjectExplorer::Internal