TextEditorPlugin: Pimpl and remove uses of global object pool

Change-Id: I17eb0e928788f02f6089fd2a2ed2393d7f577d11
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2018-02-06 14:00:12 +01:00
parent 0bbf224667
commit 58a168db82
4 changed files with 51 additions and 57 deletions

View File

@@ -66,7 +66,27 @@ static const char kCurrentDocumentRowCount[] = "CurrentDocument:RowCount";
static const char kCurrentDocumentColumnCount[] = "CurrentDocument:ColumnCount"; static const char kCurrentDocumentColumnCount[] = "CurrentDocument:ColumnCount";
static const char kCurrentDocumentFontSize[] = "CurrentDocument:FontSize"; 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() TextEditorPlugin::TextEditorPlugin()
{ {
@@ -76,7 +96,9 @@ TextEditorPlugin::TextEditorPlugin()
TextEditorPlugin::~TextEditorPlugin() TextEditorPlugin::~TextEditorPlugin()
{ {
m_instance = 0; delete dd;
dd = nullptr;
m_instance = nullptr;
} }
TextEditorPlugin *TextEditorPlugin::instance() TextEditorPlugin *TextEditorPlugin::instance()
@@ -90,14 +112,7 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
Q_UNUSED(arguments) Q_UNUSED(arguments)
Q_UNUSED(errorMessage) Q_UNUSED(errorMessage)
m_settings = new TextEditorSettings(this); dd = new TextEditorPluginPrivate;
// Add plain text editor factory
addAutoReleasedObject(new PlainTextEditorFactory);
// Goto line functionality for quick open
m_lineNumberFilter = new LineNumberFilter;
addAutoReleasedObject(m_lineNumberFilter);
Context context(TextEditor::Constants::C_TEXTEDITOR); 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, SnippetProvider::registerGroup(Constants::TEXT_SNIPPET_GROUP_ID,
tr("Text", "SnippetProvider")); tr("Text", "SnippetProvider"));
m_outlineFactory = new OutlineFactory;
addAutoReleasedObject(m_outlineFactory);
addAutoReleasedObject(new FindInFiles);
addAutoReleasedObject(new FindInCurrentFile);
addAutoReleasedObject(new FindInOpenFiles);
return true; 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() void TextEditorPlugin::extensionsInitialized()
{ {
connect(m_settings, &TextEditorSettings::fontSettingsChanged, dd->extensionsInitialized();
this, &TextEditorPlugin::updateSearchResultsFont);
updateSearchResultsFont(m_settings->fontSettings());
connect(m_settings->codeStyle(), &ICodeStylePreferences::currentTabSettingsChanged,
this, &TextEditorPlugin::updateSearchResultsTabWidth);
updateSearchResultsTabWidth(m_settings->codeStyle()->currentTabSettings());
Utils::MacroExpander *expander = Utils::globalMacroExpander(); Utils::MacroExpander *expander = Utils::globalMacroExpander();
@@ -204,18 +220,14 @@ void TextEditorPlugin::extensionsInitialized()
BaseTextEditor *editor = BaseTextEditor::currentTextEditor(); BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
return editor ? editor->widget()->font().pointSize() : 0; return editor ? editor->widget()->font().pointSize() : 0;
}); });
connect(ExternalToolManager::instance(), &ExternalToolManager::replaceSelectionRequested,
this, &TextEditorPlugin::updateCurrentSelection);
} }
LineNumberFilter *TextEditorPlugin::lineNumberFilter() 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()) { if (auto window = SearchResultWindow::instance()) {
window->setTextEditorFont(QFont(settings.family(), settings.fontSize() * settings.fontZoom() / 100), 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()) if (auto window = SearchResultWindow::instance())
window->setTabWidth(tabSettings.m_tabSize); window->setTabWidth(tabSettings.m_tabSize);
} }
void TextEditorPlugin::updateCurrentSelection(const QString &text) void TextEditorPluginPrivate::updateCurrentSelection(const QString &text)
{ {
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) { if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) {
const int pos = editor->position(); const int pos = editor->position();

View File

@@ -28,15 +28,9 @@
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
namespace TextEditor { namespace TextEditor {
class FontSettings;
class TabSettings;
class TextEditorSettings;
namespace Internal { namespace Internal {
class LineNumberFilter; class LineNumberFilter;
class OutlineFactory;
class TextEditorPlugin : public ExtensionSystem::IPlugin class TextEditorPlugin : public ExtensionSystem::IPlugin
{ {
@@ -45,24 +39,14 @@ class TextEditorPlugin : public ExtensionSystem::IPlugin
public: public:
TextEditorPlugin(); TextEditorPlugin();
virtual ~TextEditorPlugin(); ~TextEditorPlugin() final;
static TextEditorPlugin *instance(); static TextEditorPlugin *instance();
// ExtensionSystem::IPlugin
bool initialize(const QStringList &arguments, QString *errorMessage);
void extensionsInitialized();
static LineNumberFilter *lineNumberFilter(); static LineNumberFilter *lineNumberFilter();
private: private:
void updateSearchResultsFont(const TextEditor::FontSettings &); bool initialize(const QStringList &arguments, QString *errorMessage) final;
void updateSearchResultsTabWidth(const TextEditor::TabSettings &tabSettings); void extensionsInitialized() final;
void updateCurrentSelection(const QString &text);
TextEditorSettings *m_settings = nullptr;
LineNumberFilter *m_lineNumberFilter = nullptr;
OutlineFactory *m_outlineFactory = nullptr;
#ifdef WITH_TESTS #ifdef WITH_TESTS
private slots: private slots:
@@ -81,7 +65,6 @@ private slots:
void testIndentationClean_data(); void testIndentationClean_data();
void testIndentationClean(); void testIndentationClean();
#endif #endif
}; };
} // namespace Internal } // namespace Internal

View File

@@ -81,8 +81,7 @@ public:
static TextEditorSettingsPrivate *d = 0; static TextEditorSettingsPrivate *d = 0;
static TextEditorSettings *m_instance = 0; static TextEditorSettings *m_instance = 0;
TextEditorSettings::TextEditorSettings(QObject *parent) TextEditorSettings::TextEditorSettings()
: QObject(parent)
{ {
QTC_ASSERT(!m_instance, return); QTC_ASSERT(!m_instance, return);
m_instance = this; m_instance = this;

View File

@@ -62,7 +62,7 @@ class TEXTEDITOR_EXPORT TextEditorSettings : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit TextEditorSettings(QObject *parent); TextEditorSettings();
~TextEditorSettings(); ~TextEditorSettings();
static TextEditorSettings *instance(); static TextEditorSettings *instance();