Skip to content

Commit e4d2364

Browse files
committed
Coco: Slim down project panel creation interface
Change-Id: I7ac8c3551e906fdf2f19d2fbcee0db586fb94aae Reviewed-by: Christian Stenger <[email protected]>
1 parent 8d02ee4 commit e4d2364

File tree

3 files changed

+47
-50
lines changed

3 files changed

+47
-50
lines changed

src/plugins/coco/cocoplugin.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ class CocoPlugin final : public ExtensionSystem::IPlugin
104104
}
105105

106106
void initialize() final;
107-
void addEntryToProjectSettings();
108107

109108
private:
110109
CocoLanguageClient *m_client = nullptr;
@@ -121,25 +120,10 @@ void CocoPlugin::initialize()
121120

122121
GlobalSettings::read();
123122
GlobalSettingsPage::instance().widget();
124-
addEntryToProjectSettings();
125123

126-
initLanguageServer();
127-
}
124+
setupCocoProjectPanel();
128125

129-
void CocoPlugin::addEntryToProjectSettings()
130-
{
131-
auto panelFactory = new ProjectPanelFactory;
132-
panelFactory->setPriority(50);
133-
panelFactory->setDisplayName(tr("Coco Code Coverage"));
134-
panelFactory->setSupportsFunction([](Project *project) {
135-
if (Target *target = project->activeTarget()) {
136-
if (BuildConfiguration *abc = target->activeBuildConfiguration())
137-
return BuildSettings::supportsBuildConfig(*abc);
138-
}
139-
return false;
140-
});
141-
panelFactory->setCreateWidgetFunction(
142-
[](Project *project) { return new CocoProjectSettingsWidget(project); });
126+
initLanguageServer();
143127
}
144128

145129
} // namespace Coco

src/plugins/coco/cocoprojectsettingswidget.cpp

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,67 @@
55

66
#include "cocopluginconstants.h"
77
#include "cocoprojectwidget.h"
8+
#include "cocotr.h"
89

910
#include <cmakeprojectmanager/cmakeprojectconstants.h>
11+
1012
#include <projectexplorer/buildconfiguration.h>
1113
#include <projectexplorer/project.h>
14+
#include <projectexplorer/projectpanelfactory.h>
15+
#include <projectexplorer/projectsettingswidget.h>
1216
#include <projectexplorer/target.h>
17+
1318
#include <qmakeprojectmanager/qmakeprojectmanagerconstants.h>
1419

20+
#include <QVBoxLayout>
1521
#include <QDebug>
1622

23+
using namespace ProjectExplorer;
24+
1725
namespace Coco::Internal {
1826

19-
CocoProjectSettingsWidget::CocoProjectSettingsWidget(ProjectExplorer::Project *project)
20-
: m_layout{new QVBoxLayout}
27+
class CocoProjectSettingsWidget final : public ProjectSettingsWidget
2128
{
22-
setUseGlobalSettingsCheckBoxVisible(false);
23-
setGlobalSettingsId(Constants::COCO_SETTINGS_PAGE_ID);
29+
public:
30+
explicit CocoProjectSettingsWidget(Project *project)
31+
{
32+
setUseGlobalSettingsCheckBoxVisible(false);
33+
setGlobalSettingsId(Constants::COCO_SETTINGS_PAGE_ID);
2434

25-
if (auto *target = project->activeTarget()) {
26-
auto abc = target->activeBuildConfiguration();
35+
auto layout = new QVBoxLayout;
36+
if (auto *target = project->activeTarget()) {
37+
auto abc = target->activeBuildConfiguration();
2738

28-
if (abc->id() == QmakeProjectManager::Constants::QMAKE_BC_ID
29-
|| abc->id() == CMakeProjectManager::Constants::CMAKE_BUILDCONFIGURATION_ID)
30-
m_layout->addWidget(new CocoProjectWidget(project, abc));
39+
if (abc->id() == QmakeProjectManager::Constants::QMAKE_BC_ID
40+
|| abc->id() == CMakeProjectManager::Constants::CMAKE_BUILDCONFIGURATION_ID)
41+
layout->addWidget(new CocoProjectWidget(project, abc));
42+
}
43+
setLayout(layout);
3144
}
32-
setLayout(m_layout);
33-
}
45+
};
46+
47+
class CocoProjectPanelFactory final : public ProjectPanelFactory
48+
{
49+
public:
50+
CocoProjectPanelFactory()
51+
{
52+
setPriority(50);
53+
setDisplayName(Tr::tr("Coco Code Coverage"));
54+
setSupportsFunction([](Project *project) {
55+
if (Target *target = project->activeTarget()) {
56+
if (BuildConfiguration *abc = target->activeBuildConfiguration())
57+
return BuildSettings::supportsBuildConfig(*abc);
58+
}
59+
return false;
60+
});
61+
setCreateWidgetFunction(
62+
[](Project *project) { return new CocoProjectSettingsWidget(project); });
63+
}
64+
};
3465

35-
CocoProjectSettingsWidget::~CocoProjectSettingsWidget()
66+
void setupCocoProjectPanel()
3667
{
37-
delete m_layout;
68+
static CocoProjectPanelFactory theCocoProjectPanelFactory;
3869
}
3970

4071
} // namespace Coco::Internal

src/plugins/coco/cocoprojectsettingswidget.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,8 @@
33

44
#pragma once
55

6-
#include <projectexplorer/projectsettingswidget.h>
7-
8-
#include <QVBoxLayout>
9-
10-
namespace ProjectExplorer {
11-
class Project;
12-
}
13-
146
namespace Coco::Internal {
157

16-
class CocoProjectSettingsWidget : public ProjectExplorer::ProjectSettingsWidget
17-
{
18-
Q_OBJECT
19-
20-
public:
21-
explicit CocoProjectSettingsWidget(ProjectExplorer::Project *project);
22-
~CocoProjectSettingsWidget();
23-
24-
private:
25-
QVBoxLayout *m_layout;
26-
};
8+
void setupCocoProjectPanel();
279

2810
} // namespace Coco::Internal

0 commit comments

Comments
 (0)