CMake: Pimpl CMakeProjectPlugin and avoid use of global object pool

Follows the recent pattern.

Change-Id: Ib91fb8e6ab343b5e595b9ed470daa3e55999f37c
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
hjk
2018-02-09 15:35:02 +01:00
parent 08e73d1a93
commit 9a3dff8934
2 changed files with 46 additions and 33 deletions

View File

@@ -51,13 +51,38 @@
#include <utils/parameteraction.h>
using namespace CMakeProjectManager::Internal;
using namespace Core;
using namespace ProjectExplorer;
namespace CMakeProjectManager {
namespace Internal {
class CMakeProjectPluginPrivate
{
public:
Utils::ParameterAction *m_buildTargetContextAction = nullptr;
QMetaObject::Connection m_actionConnect;
CMakeSettingsPage settingsPage;
CMakeManager manager;
CMakeBuildStepFactory buildStepFactory;
CMakeRunConfigurationFactory runConfigFactory;
CMakeBuildConfigurationFactory buildConfigFactory;
CMakeEditorFactory editorFactor;
CMakeLocatorFilter locatorFiler;
};
CMakeProjectPlugin::~CMakeProjectPlugin()
{
delete d;
}
bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
{
Q_UNUSED(errorMessage)
d = new CMakeProjectPluginPrivate;
const Context projectContext(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
Core::FileIconProvider::registerIconOverlayForSuffix(Constants::FILEOVERLAY_CMAKE, "cmake");
@@ -65,17 +90,8 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
TextEditor::SnippetProvider::registerGroup(Constants::CMAKE_SNIPPETS_GROUP_ID,
tr("CMake", "SnippetProvider"));
addAutoReleasedObject(new CMakeSettingsPage);
addAutoReleasedObject(new CMakeManager);
ProjectManager::registerProjectType<CMakeProject>(Constants::CMAKEPROJECTMIMETYPE);
addAutoReleasedObject(new CMakeBuildStepFactory);
addAutoReleasedObject(new CMakeRunConfigurationFactory);
addAutoReleasedObject(new CMakeBuildConfigurationFactory);
addAutoReleasedObject(new CMakeEditorFactory);
addAutoReleasedObject(new CMakeLocatorFilter);
new CMakeToolManager(this);
KitManager::registerKitInformation(new CMakeKitInformation);
@@ -89,13 +105,13 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
//register actions
Command *command = nullptr;
m_buildTargetContextAction = new Utils::ParameterAction(tr("Build"), tr("Build \"%1\""),
Utils::ParameterAction::AlwaysEnabled/*handled manually*/,
this);
command = ActionManager::registerAction(m_buildTargetContextAction, Constants::BUILD_TARGET_CONTEXTMENU, projectContext);
d->m_buildTargetContextAction = new Utils::ParameterAction(tr("Build"), tr("Build \"%1\""),
Utils::ParameterAction::AlwaysEnabled/*handled manually*/,
this);
command = ActionManager::registerAction(d->m_buildTargetContextAction, Constants::BUILD_TARGET_CONTEXTMENU, projectContext);
command->setAttribute(Command::CA_Hide);
command->setAttribute(Command::CA_UpdateText);
command->setDescription(m_buildTargetContextAction->text());
command->setDescription(d->m_buildTargetContextAction->text());
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
// Wire up context menu updates:
@@ -121,12 +137,16 @@ void CMakeProjectPlugin::updateContextActions()
CMakeProject *cmProject = dynamic_cast<CMakeProject *>(project);
// Build Target:
disconnect(m_actionConnect);
m_buildTargetContextAction->setParameter(targetDisplayName);
m_buildTargetContextAction->setEnabled(targetNode);
m_buildTargetContextAction->setVisible(targetNode);
disconnect(d->m_actionConnect);
d->m_buildTargetContextAction->setParameter(targetDisplayName);
d->m_buildTargetContextAction->setEnabled(targetNode);
d->m_buildTargetContextAction->setVisible(targetNode);
if (cmProject && targetNode) {
m_actionConnect = connect(m_buildTargetContextAction, &Utils::ParameterAction::triggered,
d->m_actionConnect = connect(d->m_buildTargetContextAction, &Utils::ParameterAction::triggered,
cmProject, [cmProject, targetDisplayName]() { cmProject->buildCMakeTarget(targetDisplayName); });
}
}
} // Internal
} // CMakeProjectManager

View File

@@ -27,14 +27,7 @@
#include <extensionsystem/iplugin.h>
#include <QObject>
namespace Utils { class ParameterAction; }
namespace CMakeProjectManager {
class CMakeProject;
namespace Internal {
class CMakeProjectPlugin : public ExtensionSystem::IPlugin
@@ -43,9 +36,7 @@ class CMakeProjectPlugin : public ExtensionSystem::IPlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CMakeProjectManager.json")
public:
bool initialize(const QStringList &arguments, QString *errorMessage) override;
void extensionsInitialized() override;
~CMakeProjectPlugin() override;
#ifdef WITH_TESTS
private slots:
@@ -66,11 +57,13 @@ private slots:
#endif
private:
bool initialize(const QStringList &arguments, QString *errorMessage) override;
void extensionsInitialized() override;
void updateContextActions();
Utils::ParameterAction *m_buildTargetContextAction = nullptr;
QMetaObject::Connection m_actionConnect;
class CMakeProjectPluginPrivate *d = nullptr;
};
} // namespace Internal
} // namespace CMakeProject
} // namespace CMakeProjectManager