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 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();

View File

@@ -28,15 +28,9 @@
#include <extensionsystem/iplugin.h>
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

View File

@@ -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;

View File

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