Coco: Slim down project panel creation interface

Change-Id: I7ac8c3551e906fdf2f19d2fbcee0db586fb94aae
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2024-12-10 14:08:10 +01:00
parent 8d02ee45bf
commit e4d23646f3
3 changed files with 47 additions and 50 deletions

View File

@@ -104,7 +104,6 @@ public:
}
void initialize() final;
void addEntryToProjectSettings();
private:
CocoLanguageClient *m_client = nullptr;
@@ -121,27 +120,12 @@ void CocoPlugin::initialize()
GlobalSettings::read();
GlobalSettingsPage::instance().widget();
addEntryToProjectSettings();
setupCocoProjectPanel();
initLanguageServer();
}
void CocoPlugin::addEntryToProjectSettings()
{
auto panelFactory = new ProjectPanelFactory;
panelFactory->setPriority(50);
panelFactory->setDisplayName(tr("Coco Code Coverage"));
panelFactory->setSupportsFunction([](Project *project) {
if (Target *target = project->activeTarget()) {
if (BuildConfiguration *abc = target->activeBuildConfiguration())
return BuildSettings::supportsBuildConfig(*abc);
}
return false;
});
panelFactory->setCreateWidgetFunction(
[](Project *project) { return new CocoProjectSettingsWidget(project); });
}
} // namespace Coco
#include "cocoplugin.moc"

View File

@@ -5,36 +5,67 @@
#include "cocopluginconstants.h"
#include "cocoprojectwidget.h"
#include "cocotr.h"
#include <cmakeprojectmanager/cmakeprojectconstants.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectpanelfactory.h>
#include <projectexplorer/projectsettingswidget.h>
#include <projectexplorer/target.h>
#include <qmakeprojectmanager/qmakeprojectmanagerconstants.h>
#include <QVBoxLayout>
#include <QDebug>
using namespace ProjectExplorer;
namespace Coco::Internal {
CocoProjectSettingsWidget::CocoProjectSettingsWidget(ProjectExplorer::Project *project)
: m_layout{new QVBoxLayout}
class CocoProjectSettingsWidget final : public ProjectSettingsWidget
{
public:
explicit CocoProjectSettingsWidget(Project *project)
{
setUseGlobalSettingsCheckBoxVisible(false);
setGlobalSettingsId(Constants::COCO_SETTINGS_PAGE_ID);
auto layout = new QVBoxLayout;
if (auto *target = project->activeTarget()) {
auto abc = target->activeBuildConfiguration();
if (abc->id() == QmakeProjectManager::Constants::QMAKE_BC_ID
|| abc->id() == CMakeProjectManager::Constants::CMAKE_BUILDCONFIGURATION_ID)
m_layout->addWidget(new CocoProjectWidget(project, abc));
layout->addWidget(new CocoProjectWidget(project, abc));
}
setLayout(m_layout);
setLayout(layout);
}
};
CocoProjectSettingsWidget::~CocoProjectSettingsWidget()
class CocoProjectPanelFactory final : public ProjectPanelFactory
{
delete m_layout;
public:
CocoProjectPanelFactory()
{
setPriority(50);
setDisplayName(Tr::tr("Coco Code Coverage"));
setSupportsFunction([](Project *project) {
if (Target *target = project->activeTarget()) {
if (BuildConfiguration *abc = target->activeBuildConfiguration())
return BuildSettings::supportsBuildConfig(*abc);
}
return false;
});
setCreateWidgetFunction(
[](Project *project) { return new CocoProjectSettingsWidget(project); });
}
};
void setupCocoProjectPanel()
{
static CocoProjectPanelFactory theCocoProjectPanelFactory;
}
} // namespace Coco::Internal

View File

@@ -3,26 +3,8 @@
#pragma once
#include <projectexplorer/projectsettingswidget.h>
#include <QVBoxLayout>
namespace ProjectExplorer {
class Project;
}
namespace Coco::Internal {
class CocoProjectSettingsWidget : public ProjectExplorer::ProjectSettingsWidget
{
Q_OBJECT
public:
explicit CocoProjectSettingsWidget(ProjectExplorer::Project *project);
~CocoProjectSettingsWidget();
private:
QVBoxLayout *m_layout;
};
void setupCocoProjectPanel();
} // namespace Coco::Internal