ProjectExplorer: (Ab-)Use window title for panel tab display name

Moves the specification of the name closer to the widget itself and
simplifies the overall structure, at the price of some (bearable) obscurity.

Change-Id: I8c8f15175e64f8d406cbd742d158e681f67ec316
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2025-06-13 10:18:19 +02:00
parent e65e8e25d7
commit 0c13aecc70
6 changed files with 20 additions and 32 deletions

View File

@@ -74,6 +74,8 @@ private:
BuildSettingsWidget::BuildSettingsWidget(Target *target)
: m_target(target)
{
setWindowTitle(Tr::tr("Build Settings"));
auto vbox = new QVBoxLayout(this);
vbox->setContentsMargins(0, 0, 0, 0);

View File

@@ -60,6 +60,7 @@ 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);

View File

@@ -99,6 +99,7 @@ public:
: m_settings(project)
{
setGlobalSettingsId(TextEditor::Constants::TEXT_EDITOR_COMMENTS_SETTINGS);
const auto layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(&m_widget);

View File

@@ -32,8 +32,9 @@ public:
// interface for users of ProjectPanelFactory
bool supports(Project *project);
using WidgetCreator = std::function<ProjectSettingsWidget *(Project *)>;
// Widgets created by this function should use setWindowTitle() to specify
// their tab title.
ProjectSettingsWidget *createWidget(Project *project) const;
// interface for "implementations" of ProjectPanelFactory
// by default all projects are supported, only set a custom supports function
@@ -45,8 +46,8 @@ public:
Utils::TreeItem *createPanelItem(Project *project);
using WidgetCreator = std::function<ProjectSettingsWidget *(Project *)>;
void setCreateWidgetFunction(const WidgetCreator &createWidgetFunction);
ProjectSettingsWidget *createWidget(Project *project) const;
private:
Utils::Id m_id;

View File

@@ -219,19 +219,7 @@ void BuildSystemOutputWindow::updateFilter()
0 /* after context */);
}
class ProjectPanel
{
public:
ProjectPanel() = default;
ProjectPanel(const QString &displayName, QWidget *widget)
: displayName(displayName), widget(widget)
{}
QString displayName;
QWidget *widget = nullptr;
};
using ProjectPanels = QList<ProjectPanel>;
using ProjectPanels = QList<QWidget *>;
// Overall structure:
//
@@ -519,12 +507,10 @@ ProjectPanels MiscSettingsPanelItem::panelWidgets() const
panel->addGlobalSettingsProperties(inner);
panel->addWidget(inner);
panel->setFocusProxy(inner);
panel->setWindowTitle(m_factory->displayName());
m_widget = panel;
}
ProjectPanel panel;
panel.displayName = m_factory->displayName();
panel.widget = m_widget;
return QList{panel};
return {m_widget.get()};
}
ProjectItemBase *MiscSettingsPanelItem::activeItem()
@@ -756,6 +742,8 @@ private:
TargetSetupPageWrapper::TargetSetupPageWrapper(Project *project)
: m_project(project)
{
setWindowTitle(Tr::tr("Configure Project"));
auto box = new QDialogButtonBox(this);
m_configureButton = new QPushButton(this);
@@ -892,10 +880,7 @@ public:
if (!m_runSettingsWidget)
m_runSettingsWidget = createRunSettingsWidget(target());
return {
ProjectPanel(Tr::tr("Build Settings"), m_buildSettingsWidget),
ProjectPanel(Tr::tr("Run Settings"), m_runSettingsWidget)
};
return { m_buildSettingsWidget.get(), m_runSettingsWidget.get() };
}
void addToMenu(QMenu *menu) const final
@@ -1106,11 +1091,7 @@ ProjectPanels TargetGroupItem::panelWidgets() const
m_targetSetupPage = panel;
}
ProjectPanel panel;
panel.displayName = Tr::tr("Configure Project");
panel.widget = m_targetSetupPage;
return {panel};
return {m_targetSetupPage.get()};
}
void TargetGroupItem::itemActivatedFromBelow(const ProjectItemBase *)
@@ -1290,9 +1271,9 @@ public:
m_tabWidget->removeTab(pos);
}
for (const ProjectPanel &panel : panels) {
QTC_ASSERT(panel.widget, continue);
m_tabWidget->addTab(panel.widget, panel.displayName);
for (QWidget *panel : panels) {
QTC_ASSERT(panel, continue);
m_tabWidget->addTab(panel, panel->windowTitle());
}
m_tabWidget->setCurrentIndex(oldIndex);

View File

@@ -245,6 +245,8 @@ private:
RunSettingsWidget::RunSettingsWidget(Target *target)
: m_target(target)
{
setWindowTitle(Tr::tr("Run Settings"));
m_deployConfigurationCombo = new QComboBox(this);
setWheelScrollingWithoutFocusBlocked(m_deployConfigurationCombo);
m_addDeployToolButton = new QPushButton(Tr::tr("Add"), this);