From 58a168db8250abb741dd1a47bc53444a33072fab Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 6 Feb 2018 14:00:12 +0100 Subject: [PATCH] TextEditorPlugin: Pimpl and remove uses of global object pool Change-Id: I17eb0e928788f02f6089fd2a2ed2393d7f577d11 Reviewed-by: David Schulz --- src/plugins/texteditor/texteditorplugin.cpp | 80 +++++++++++-------- src/plugins/texteditor/texteditorplugin.h | 23 +----- src/plugins/texteditor/texteditorsettings.cpp | 3 +- src/plugins/texteditor/texteditorsettings.h | 2 +- 4 files changed, 51 insertions(+), 57 deletions(-) diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index 9df31c910c6..6b11c4d3574 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -66,7 +66,27 @@ static const char kCurrentDocumentRowCount[] = "CurrentDocument:RowCount"; static const char kCurrentDocumentColumnCount[] = "CurrentDocument:ColumnCount"; static const char kCurrentDocumentFontSize[] = "CurrentDocument:FontSize"; -static TextEditorPlugin *m_instance = 0; +class TextEditorPluginPrivate : public QObject +{ +public: + void extensionsInitialized(); + void updateSearchResultsFont(const TextEditor::FontSettings &); + void updateSearchResultsTabWidth(const TextEditor::TabSettings &tabSettings); + void updateCurrentSelection(const QString &text); + + TextEditorSettings settings; + LineNumberFilter lineNumberFilter; // Goto line functionality for quick open + OutlineFactory outlineFactory; + + FindInFiles findInFilesFilter; + FindInCurrentFile findInCurrentFileFilter; + FindInOpenFiles findInOpenFilesFilter; + + PlainTextEditorFactory plainTextEditorFactory; +}; + +static TextEditorPlugin *m_instance = nullptr; +static TextEditorPluginPrivate *dd = nullptr; TextEditorPlugin::TextEditorPlugin() { @@ -76,7 +96,9 @@ TextEditorPlugin::TextEditorPlugin() TextEditorPlugin::~TextEditorPlugin() { - m_instance = 0; + delete dd; + dd = nullptr; + m_instance = nullptr; } TextEditorPlugin *TextEditorPlugin::instance() @@ -90,14 +112,7 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe Q_UNUSED(arguments) Q_UNUSED(errorMessage) - m_settings = new TextEditorSettings(this); - - // Add plain text editor factory - addAutoReleasedObject(new PlainTextEditorFactory); - - // Goto line functionality for quick open - m_lineNumberFilter = new LineNumberFilter; - addAutoReleasedObject(m_lineNumberFilter); + dd = new TextEditorPluginPrivate; Context context(TextEditor::Constants::C_TEXTEDITOR); @@ -135,27 +150,28 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe SnippetProvider::registerGroup(Constants::TEXT_SNIPPET_GROUP_ID, tr("Text", "SnippetProvider")); - m_outlineFactory = new OutlineFactory; - addAutoReleasedObject(m_outlineFactory); - - addAutoReleasedObject(new FindInFiles); - addAutoReleasedObject(new FindInCurrentFile); - addAutoReleasedObject(new FindInOpenFiles); - return true; } +void TextEditorPluginPrivate::extensionsInitialized() +{ + connect(&settings, &TextEditorSettings::fontSettingsChanged, + this, &TextEditorPluginPrivate::updateSearchResultsFont); + + updateSearchResultsFont(settings.fontSettings()); + + connect(settings.codeStyle(), &ICodeStylePreferences::currentTabSettingsChanged, + this, &TextEditorPluginPrivate::updateSearchResultsTabWidth); + + updateSearchResultsTabWidth(settings.codeStyle()->currentTabSettings()); + + connect(ExternalToolManager::instance(), &ExternalToolManager::replaceSelectionRequested, + this, &TextEditorPluginPrivate::updateCurrentSelection); +} + void TextEditorPlugin::extensionsInitialized() { - connect(m_settings, &TextEditorSettings::fontSettingsChanged, - this, &TextEditorPlugin::updateSearchResultsFont); - - updateSearchResultsFont(m_settings->fontSettings()); - - connect(m_settings->codeStyle(), &ICodeStylePreferences::currentTabSettingsChanged, - this, &TextEditorPlugin::updateSearchResultsTabWidth); - - updateSearchResultsTabWidth(m_settings->codeStyle()->currentTabSettings()); + dd->extensionsInitialized(); Utils::MacroExpander *expander = Utils::globalMacroExpander(); @@ -204,18 +220,14 @@ void TextEditorPlugin::extensionsInitialized() BaseTextEditor *editor = BaseTextEditor::currentTextEditor(); return editor ? editor->widget()->font().pointSize() : 0; }); - - - connect(ExternalToolManager::instance(), &ExternalToolManager::replaceSelectionRequested, - this, &TextEditorPlugin::updateCurrentSelection); } LineNumberFilter *TextEditorPlugin::lineNumberFilter() { - return m_instance->m_lineNumberFilter; + return &dd->lineNumberFilter; } -void TextEditorPlugin::updateSearchResultsFont(const FontSettings &settings) +void TextEditorPluginPrivate::updateSearchResultsFont(const FontSettings &settings) { if (auto window = SearchResultWindow::instance()) { window->setTextEditorFont(QFont(settings.family(), settings.fontSize() * settings.fontZoom() / 100), @@ -226,13 +238,13 @@ void TextEditorPlugin::updateSearchResultsFont(const FontSettings &settings) } } -void TextEditorPlugin::updateSearchResultsTabWidth(const TabSettings &tabSettings) +void TextEditorPluginPrivate::updateSearchResultsTabWidth(const TabSettings &tabSettings) { if (auto window = SearchResultWindow::instance()) window->setTabWidth(tabSettings.m_tabSize); } -void TextEditorPlugin::updateCurrentSelection(const QString &text) +void TextEditorPluginPrivate::updateCurrentSelection(const QString &text) { if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) { const int pos = editor->position(); diff --git a/src/plugins/texteditor/texteditorplugin.h b/src/plugins/texteditor/texteditorplugin.h index f3875afa40b..fcc938e010d 100644 --- a/src/plugins/texteditor/texteditorplugin.h +++ b/src/plugins/texteditor/texteditorplugin.h @@ -28,15 +28,9 @@ #include namespace TextEditor { - -class FontSettings; -class TabSettings; -class TextEditorSettings; - namespace Internal { class LineNumberFilter; -class OutlineFactory; class TextEditorPlugin : public ExtensionSystem::IPlugin { @@ -45,24 +39,14 @@ class TextEditorPlugin : public ExtensionSystem::IPlugin public: TextEditorPlugin(); - virtual ~TextEditorPlugin(); + ~TextEditorPlugin() final; static TextEditorPlugin *instance(); - - // ExtensionSystem::IPlugin - bool initialize(const QStringList &arguments, QString *errorMessage); - void extensionsInitialized(); - static LineNumberFilter *lineNumberFilter(); private: - void updateSearchResultsFont(const TextEditor::FontSettings &); - void updateSearchResultsTabWidth(const TextEditor::TabSettings &tabSettings); - void updateCurrentSelection(const QString &text); - - TextEditorSettings *m_settings = nullptr; - LineNumberFilter *m_lineNumberFilter = nullptr; - OutlineFactory *m_outlineFactory = nullptr; + bool initialize(const QStringList &arguments, QString *errorMessage) final; + void extensionsInitialized() final; #ifdef WITH_TESTS private slots: @@ -81,7 +65,6 @@ private slots: void testIndentationClean_data(); void testIndentationClean(); #endif - }; } // namespace Internal diff --git a/src/plugins/texteditor/texteditorsettings.cpp b/src/plugins/texteditor/texteditorsettings.cpp index 560d4dce536..9e4b9dc46dd 100644 --- a/src/plugins/texteditor/texteditorsettings.cpp +++ b/src/plugins/texteditor/texteditorsettings.cpp @@ -81,8 +81,7 @@ public: static TextEditorSettingsPrivate *d = 0; static TextEditorSettings *m_instance = 0; -TextEditorSettings::TextEditorSettings(QObject *parent) - : QObject(parent) +TextEditorSettings::TextEditorSettings() { QTC_ASSERT(!m_instance, return); m_instance = this; diff --git a/src/plugins/texteditor/texteditorsettings.h b/src/plugins/texteditor/texteditorsettings.h index 656d5856843..36a2d86e45c 100644 --- a/src/plugins/texteditor/texteditorsettings.h +++ b/src/plugins/texteditor/texteditorsettings.h @@ -62,7 +62,7 @@ class TEXTEDITOR_EXPORT TextEditorSettings : public QObject Q_OBJECT public: - explicit TextEditorSettings(QObject *parent); + TextEditorSettings(); ~TextEditorSettings(); static TextEditorSettings *instance();