summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2018-02-07 14:51:15 +0100
committerhjk <hjk@qt.io>2018-02-09 11:52:30 +0000
commit4e4111a92d635fd744c75f706502a2f37bbb3657 (patch)
tree9090bcf820b0e250de57321414d6144956b30711
parentacd63756dc96e153dce4ceadfdf5243b754a8a1e (diff)
downloadqt-creator-4e4111a92d635fd744c75f706502a2f37bbb3657.tar.gz
CppEditorPlugin: Partially pimpl and avoid use of global object pool
Change-Id: I1e55848a9947ff0b4bffcdca717419db8f6f2fa5 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
-rw-r--r--src/plugins/cppeditor/cppeditorplugin.cpp105
-rw-r--r--src/plugins/cppeditor/cppeditorplugin.h33
-rw-r--r--src/plugins/cppeditor/cppquickfixassistant.h2
3 files changed, 63 insertions, 77 deletions
diff --git a/src/plugins/cppeditor/cppeditorplugin.cpp b/src/plugins/cppeditor/cppeditorplugin.cpp
index 5e9285fed5..0f88851d2f 100644
--- a/src/plugins/cppeditor/cppeditorplugin.cpp
+++ b/src/plugins/cppeditor/cppeditorplugin.cpp
@@ -39,6 +39,7 @@
#include "resourcepreviewhoverhandler.h"
#include <coreplugin/editormanager/editormanager.h>
+#include <coreplugin/editormanager/ieditorfactory.h>
#ifdef WITH_TESTS
# include "cppdoxygen_test.h"
@@ -105,24 +106,39 @@ public:
| TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::UnCollapseAll
| TextEditorActionHandler::FollowSymbolUnderCursor);
-
- addHoverHandler(CppModelManager::instance()->createHoverHandler());
- addHoverHandler(new ColorPreviewHoverHandler);
- addHoverHandler(new ResourcePreviewHoverHandler);
}
};
///////////////////////////////// CppEditorPlugin //////////////////////////////////
-CppEditorPlugin *CppEditorPlugin::m_instance = 0;
+class CppEditorPluginPrivate : public QObject
+{
+public:
+ void onTaskStarted(Core::Id type);
+ void onAllTasksFinished(Core::Id type);
+ void inspectCppCodeModel();
+
+ QAction *m_renameSymbolUnderCursorAction = nullptr;
+ QAction *m_findUsagesAction = nullptr;
+ QAction *m_reparseExternallyChangedFiles = nullptr;
+ QAction *m_openTypeHierarchyAction = nullptr;
+ QAction *m_openIncludeHierarchyAction = nullptr;
+
+ CppQuickFixAssistProvider m_quickFixProvider;
+
+ QPointer<CppCodeModelInspectorDialog> m_cppCodeModelInspectorDialog;
+
+ QPointer<TextEditor::BaseTextEditor> m_currentEditor;
-CppEditorPlugin::CppEditorPlugin() :
- m_renameSymbolUnderCursorAction(0),
- m_findUsagesAction(0),
- m_reparseExternallyChangedFiles(0),
- m_openTypeHierarchyAction(0),
- m_openIncludeHierarchyAction(0),
- m_quickFixProvider(0)
+ CppOutlineWidgetFactory m_cppOutlineWidgetFactory;
+ CppTypeHierarchyFactory m_cppTypeHierarchyFactory;
+ CppIncludeHierarchyFactory m_cppIncludeHierarchyFactory;
+ CppEditorFactory m_cppEditorFactory;
+};
+
+static CppEditorPlugin *m_instance = nullptr;
+
+CppEditorPlugin::CppEditorPlugin()
{
m_instance = this;
}
@@ -130,7 +146,9 @@ CppEditorPlugin::CppEditorPlugin() :
CppEditorPlugin::~CppEditorPlugin()
{
destroyCppQuickFixes();
- m_instance = 0;
+ delete d;
+ d = nullptr;
+ m_instance = nullptr;
}
CppEditorPlugin *CppEditorPlugin::instance()
@@ -140,20 +158,18 @@ CppEditorPlugin *CppEditorPlugin::instance()
CppQuickFixAssistProvider *CppEditorPlugin::quickFixProvider() const
{
- return m_quickFixProvider;
+ return &d->m_quickFixProvider;
}
bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
{
Q_UNUSED(errorMessage)
- addAutoReleasedObject(new CppOutlineWidgetFactory);
- addAutoReleasedObject(new CppTypeHierarchyFactory);
- addAutoReleasedObject(new CppIncludeHierarchyFactory);
+ d = new CppEditorPluginPrivate;
+
SnippetProvider::registerGroup(Constants::CPP_SNIPPETS_GROUP_ID, tr("C++", "SnippetProvider"),
&CppEditor::decorateEditor);
- m_quickFixProvider = new CppQuickFixAssistProvider(this);
createCppQuickFixes();
Context context(Constants::CPPEDITOR_ID);
@@ -200,24 +216,24 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
this, &CppEditorPlugin::openDeclarationDefinitionInNextSplit);
cppToolsMenu->addAction(cmd);
- m_findUsagesAction = new QAction(tr("Find Usages"), this);
- cmd = ActionManager::registerAction(m_findUsagesAction, Constants::FIND_USAGES, context);
+ d->m_findUsagesAction = new QAction(tr("Find Usages"), this);
+ cmd = ActionManager::registerAction(d->m_findUsagesAction, Constants::FIND_USAGES, context);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U")));
- connect(m_findUsagesAction, &QAction::triggered, this, &CppEditorPlugin::findUsages);
+ connect(d->m_findUsagesAction, &QAction::triggered, this, &CppEditorPlugin::findUsages);
contextMenu->addAction(cmd);
cppToolsMenu->addAction(cmd);
- m_openTypeHierarchyAction = new QAction(tr("Open Type Hierarchy"), this);
- cmd = ActionManager::registerAction(m_openTypeHierarchyAction, Constants::OPEN_TYPE_HIERARCHY, context);
+ d->m_openTypeHierarchyAction = new QAction(tr("Open Type Hierarchy"), this);
+ cmd = ActionManager::registerAction(d->m_openTypeHierarchyAction, Constants::OPEN_TYPE_HIERARCHY, context);
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Meta+Shift+T") : tr("Ctrl+Shift+T")));
- connect(m_openTypeHierarchyAction, &QAction::triggered, this, &CppEditorPlugin::openTypeHierarchy);
+ connect(d->m_openTypeHierarchyAction, &QAction::triggered, this, &CppEditorPlugin::openTypeHierarchy);
contextMenu->addAction(cmd);
cppToolsMenu->addAction(cmd);
- m_openIncludeHierarchyAction = new QAction(tr("Open Include Hierarchy"), this);
- cmd = ActionManager::registerAction(m_openIncludeHierarchyAction, Constants::OPEN_INCLUDE_HIERARCHY, context);
+ d->m_openIncludeHierarchyAction = new QAction(tr("Open Include Hierarchy"), this);
+ cmd = ActionManager::registerAction(d->m_openIncludeHierarchyAction, Constants::OPEN_INCLUDE_HIERARCHY, context);
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Meta+Shift+I") : tr("Ctrl+Shift+I")));
- connect(m_openIncludeHierarchyAction, &QAction::triggered, this, &CppEditorPlugin::openIncludeHierarchy);
+ connect(d->m_openIncludeHierarchyAction, &QAction::triggered, this, &CppEditorPlugin::openIncludeHierarchy);
contextMenu->addAction(cmd);
cppToolsMenu->addAction(cmd);
@@ -226,29 +242,29 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
sep->action()->setObjectName(QLatin1String(Constants::M_REFACTORING_MENU_INSERTION_POINT));
contextMenu->addSeparator();
- m_renameSymbolUnderCursorAction = new QAction(tr("Rename Symbol Under Cursor"),
+ d->m_renameSymbolUnderCursorAction = new QAction(tr("Rename Symbol Under Cursor"),
this);
- cmd = ActionManager::registerAction(m_renameSymbolUnderCursorAction,
+ cmd = ActionManager::registerAction(d->m_renameSymbolUnderCursorAction,
Constants::RENAME_SYMBOL_UNDER_CURSOR,
context);
cmd->setDefaultKeySequence(QKeySequence(tr("CTRL+SHIFT+R")));
- connect(m_renameSymbolUnderCursorAction, &QAction::triggered,
+ connect(d->m_renameSymbolUnderCursorAction, &QAction::triggered,
this, &CppEditorPlugin::renameSymbolUnderCursor);
cppToolsMenu->addAction(cmd);
// Update context in global context
cppToolsMenu->addSeparator();
- m_reparseExternallyChangedFiles = new QAction(tr("Reparse Externally Changed Files"), this);
- cmd = ActionManager::registerAction(m_reparseExternallyChangedFiles, Constants::UPDATE_CODEMODEL);
+ d->m_reparseExternallyChangedFiles = new QAction(tr("Reparse Externally Changed Files"), this);
+ cmd = ActionManager::registerAction(d->m_reparseExternallyChangedFiles, Constants::UPDATE_CODEMODEL);
CppTools::CppModelManager *cppModelManager = CppTools::CppModelManager::instance();
- connect(m_reparseExternallyChangedFiles, &QAction::triggered, cppModelManager, &CppTools::CppModelManager::updateModifiedSourceFiles);
+ connect(d->m_reparseExternallyChangedFiles, &QAction::triggered, cppModelManager, &CppTools::CppModelManager::updateModifiedSourceFiles);
cppToolsMenu->addAction(cmd);
cppToolsMenu->addSeparator();
QAction *inspectCppCodeModel = new QAction(tr("Inspect C++ Code Model..."), this);
cmd = ActionManager::registerAction(inspectCppCodeModel, Constants::INSPECT_CPP_CODEMODEL);
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Meta+Shift+F12") : tr("Ctrl+Shift+F12")));
- connect(inspectCppCodeModel, &QAction::triggered, this, &CppEditorPlugin::inspectCppCodeModel);
+ connect(inspectCppCodeModel, &QAction::triggered, d, &CppEditorPluginPrivate::inspectCppCodeModel);
cppToolsMenu->addAction(cmd);
contextMenu->addSeparator(context);
@@ -260,18 +276,20 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
contextMenu->addAction(cmd);
connect(ProgressManager::instance(), &ProgressManager::taskStarted,
- this, &CppEditorPlugin::onTaskStarted);
+ d, &CppEditorPluginPrivate::onTaskStarted);
connect(ProgressManager::instance(), &ProgressManager::allTasksFinished,
- this, &CppEditorPlugin::onAllTasksFinished);
+ d, &CppEditorPluginPrivate::onAllTasksFinished);
return true;
}
void CppEditorPlugin::extensionsInitialized()
{
- // Add the editor factory here instead of in initialize()
+ // Add the hover handler factories here instead of in initialize()
// so that the Clang Code Model has a chance to hook in.
- addAutoReleasedObject(new CppEditorFactory);
+ d->m_cppEditorFactory.addHoverHandler(CppModelManager::instance()->createHoverHandler());
+ d->m_cppEditorFactory.addHoverHandler(new ColorPreviewHoverHandler);
+ d->m_cppEditorFactory.addHoverHandler(new ResourcePreviewHoverHandler);
if (!HostOsInfo::isMacHost() && !HostOsInfo::isWindowsHost()) {
FileIconProvider::registerIconOverlayForMimeType(
@@ -286,11 +304,6 @@ void CppEditorPlugin::extensionsInitialized()
}
}
-ExtensionSystem::IPlugin::ShutdownFlag CppEditorPlugin::aboutToShutdown()
-{
- return SynchronousShutdown;
-}
-
static CppEditorWidget *currentCppEditorWidget()
{
if (IEditor *currentEditor = EditorManager::currentEditor())
@@ -328,7 +341,7 @@ void CppEditorPlugin::showPreProcessorDialog()
editorWidget->showPreProcessorWidget();
}
-void CppEditorPlugin::onTaskStarted(Id type)
+void CppEditorPluginPrivate::onTaskStarted(Id type)
{
if (type == CppTools::Constants::TASK_INDEX) {
m_renameSymbolUnderCursorAction->setEnabled(false);
@@ -339,7 +352,7 @@ void CppEditorPlugin::onTaskStarted(Id type)
}
}
-void CppEditorPlugin::onAllTasksFinished(Id type)
+void CppEditorPluginPrivate::onAllTasksFinished(Id type)
{
if (type == CppTools::Constants::TASK_INDEX) {
m_renameSymbolUnderCursorAction->setEnabled(true);
@@ -350,7 +363,7 @@ void CppEditorPlugin::onAllTasksFinished(Id type)
}
}
-void CppEditorPlugin::inspectCppCodeModel()
+void CppEditorPluginPrivate::inspectCppCodeModel()
{
if (m_cppCodeModelInspectorDialog) {
ICore::raiseWindow(m_cppCodeModelInspectorDialog);
diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h
index c1d86a6159..c4fb3b720b 100644
--- a/src/plugins/cppeditor/cppeditorplugin.h
+++ b/src/plugins/cppeditor/cppeditorplugin.h
@@ -25,19 +25,12 @@
#pragma once
-#include <coreplugin/editormanager/ieditorfactory.h>
-
#include <extensionsystem/iplugin.h>
-#include <QtPlugin>
-#include <QAction>
-
-namespace TextEditor { class BaseTextEditor; }
-
namespace CppEditor {
namespace Internal {
-class CppCodeModelInspectorDialog;
+class CppEditorPluginPrivate;
class CppQuickFixAssistProvider;
class CppEditorPlugin : public ExtensionSystem::IPlugin
@@ -51,9 +44,8 @@ public:
static CppEditorPlugin *instance();
- bool initialize(const QStringList &arguments, QString *errorMessage = 0) override;
+ bool initialize(const QStringList &arguments, QString *errorMessage) override;
void extensionsInitialized() override;
- ShutdownFlag aboutToShutdown() override;
CppQuickFixAssistProvider *quickFixProvider() const;
@@ -71,11 +63,6 @@ public:
void renameSymbolUnderCursor();
void switchDeclarationDefinition();
-private:
- void onTaskStarted(Core::Id type);
- void onAllTasksFinished(Core::Id type);
- void inspectCppCodeModel();
-
#ifdef WITH_TESTS
private:
QList<QObject *> createTestObjects() const override;
@@ -252,21 +239,7 @@ private slots:
#endif // WITH_TESTS
private:
- Core::IEditor *createEditor(QWidget *parent);
-
- static CppEditorPlugin *m_instance;
-
- QAction *m_renameSymbolUnderCursorAction;
- QAction *m_findUsagesAction;
- QAction *m_reparseExternallyChangedFiles;
- QAction *m_openTypeHierarchyAction;
- QAction *m_openIncludeHierarchyAction;
-
- CppQuickFixAssistProvider *m_quickFixProvider;
-
- QPointer<CppCodeModelInspectorDialog> m_cppCodeModelInspectorDialog;
-
- QPointer<TextEditor::BaseTextEditor> m_currentEditor;
+ CppEditorPluginPrivate *d = nullptr;
};
} // namespace Internal
diff --git a/src/plugins/cppeditor/cppquickfixassistant.h b/src/plugins/cppeditor/cppquickfixassistant.h
index 127515f0fd..89aa798aa4 100644
--- a/src/plugins/cppeditor/cppquickfixassistant.h
+++ b/src/plugins/cppeditor/cppquickfixassistant.h
@@ -71,7 +71,7 @@ private:
class CppQuickFixAssistProvider : public TextEditor::IAssistProvider
{
public:
- CppQuickFixAssistProvider(QObject *parent = nullptr) : TextEditor::IAssistProvider(parent) {}
+ CppQuickFixAssistProvider() = default;
IAssistProvider::RunType runType() const override;
TextEditor::IAssistProcessor *createProcessor() const override;
};