diff options
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r-- | src/plugins/texteditor/refactoringchanges.cpp | 4 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditor.cpp | 45 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditor.h | 4 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditoractionhandler.cpp | 4 |
4 files changed, 35 insertions, 22 deletions
diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp index 01c61f10f8..9e91463349 100644 --- a/src/plugins/texteditor/refactoringchanges.cpp +++ b/src/plugins/texteditor/refactoringchanges.cpp @@ -132,7 +132,7 @@ TextEditorWidget *RefactoringChanges::openEditor(const QString &fileName, bool a IEditor *editor = EditorManager::openEditorAt(fileName, line, column, Id(), flags); if (editor) - return qobject_cast<TextEditorWidget *>(editor->widget()); + return TextEditorWidget::fromEditor(editor); else return nullptr; } @@ -163,7 +163,7 @@ RefactoringFile::RefactoringFile(const QString &fileName, const QSharedPointer<R { QList<IEditor *> editors = DocumentModel::editorsForFilePath(fileName); if (!editors.isEmpty()) { - auto editorWidget = qobject_cast<TextEditorWidget *>(editors.first()->widget()); + auto editorWidget = TextEditorWidget::fromEditor(editors.first()); if (editorWidget && !editorWidget->isReadOnly()) m_editor = editorWidget; } diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 7e92bc24eb..635acd6e66 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -1461,8 +1461,14 @@ TextDocumentPtr TextEditorWidget::textDocumentPtr() const TextEditorWidget *TextEditorWidget::currentTextEditorWidget() { - auto editor = qobject_cast<BaseTextEditor *>(EditorManager::currentEditor()); - return editor ? editor->editorWidget() : nullptr; + return fromEditor(EditorManager::currentEditor()); +} + +TextEditorWidget *TextEditorWidget::fromEditor(const IEditor *editor) +{ + if (editor) + return Aggregation::query<TextEditorWidget>(editor->widget()); + return nullptr; } void TextEditorWidgetPrivate::editorContentsChange(int position, int charsRemoved, int charsAdded) @@ -8370,8 +8376,9 @@ QVector<BaseTextEditor *> BaseTextEditor::textEditorsForDocument(TextDocument *t TextEditorWidget *BaseTextEditor::editorWidget() const { - QTC_ASSERT(qobject_cast<TextEditorWidget *>(m_widget.data()), return nullptr); - return static_cast<TextEditorWidget *>(m_widget.data()); + auto textEditorWidget = TextEditorWidget::fromEditor(this); + QTC_CHECK(textEditorWidget); + return textEditorWidget; } void BaseTextEditor::setTextCursor(const QTextCursor &cursor) @@ -8649,10 +8656,12 @@ void TextEditorFactory::setParenthesesMatchingEnabled(bool on) BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentPtr &document) { - TextEditorWidget *widget = m_widgetCreator(); - widget->setMarksVisible(m_marksVisible); - widget->setParenthesesMatchingEnabled(m_paranthesesMatchinEnabled); - widget->setCodeFoldingSupported(m_codeFoldingSupported); + QWidget *widget = m_widgetCreator(); + TextEditorWidget *textEditorWidget = Aggregation::query<TextEditorWidget>(widget); + QTC_ASSERT(textEditorWidget, return nullptr); + textEditorWidget->setMarksVisible(m_marksVisible); + textEditorWidget->setParenthesesMatchingEnabled(m_paranthesesMatchinEnabled); + textEditorWidget->setCodeFoldingSupported(m_codeFoldingSupported); BaseTextEditor *editor = m_editorCreator(); editor->setDuplicateSupported(m_duplicatedSupported); @@ -8663,25 +8672,25 @@ BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentP // Needs to go before setTextDocument as this copies the current settings. if (m_autoCompleterCreator) - widget->setAutoCompleter(m_autoCompleterCreator()); + textEditorWidget->setAutoCompleter(m_autoCompleterCreator()); - widget->setTextDocument(document); - widget->autoCompleter()->setTabSettings(document->tabSettings()); - widget->d->m_hoverHandlers = m_hoverHandlers; + textEditorWidget->setTextDocument(document); + textEditorWidget->autoCompleter()->setTabSettings(document->tabSettings()); + textEditorWidget->d->m_hoverHandlers = m_hoverHandlers; - widget->d->m_codeAssistant.configure(widget); - widget->d->m_commentDefinition = m_commentDefinition; + textEditorWidget->d->m_codeAssistant.configure(textEditorWidget); + textEditorWidget->d->m_commentDefinition = m_commentDefinition; - QObject::connect(widget, + QObject::connect(textEditorWidget, &TextEditorWidget::activateEditor, - widget, + textEditorWidget, [editor](EditorManager::OpenEditorFlags flags) { EditorManager::activateEditor(editor, flags); }); if (m_useGenericHighlighter) - widget->setupGenericHighlighter(); - widget->finalizeInitialization(); + textEditorWidget->setupGenericHighlighter(); + textEditorWidget->finalizeInitialization(); editor->finalizeInitialization(); return editor; } diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index a2512384da..403d2f2b6f 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -556,6 +556,7 @@ public: void setContextHelpItem(const Core::HelpItem &item); static TextEditorWidget *currentTextEditorWidget(); + static TextEditorWidget *fromEditor(const Core::IEditor *editor); protected: /*! @@ -641,7 +642,8 @@ public: using EditorCreator = std::function<BaseTextEditor *()>; using DocumentCreator = std::function<TextDocument *()>; - using EditorWidgetCreator = std::function<TextEditorWidget *()>; + // editor widget must be castable (qobject_cast or Aggregate::query) to TextEditorWidget + using EditorWidgetCreator = std::function<QWidget *()>; using SyntaxHighLighterCreator = std::function<SyntaxHighlighter *()>; using IndenterCreator = std::function<Indenter *(QTextDocument *)>; using AutoCompleterCreator = std::function<AutoCompleter *()>; diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index 4cae664cb4..67d5898509 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -31,6 +31,8 @@ #include "texteditorconstants.h" #include "texteditorplugin.h" +#include <aggregation/aggregate.h> + #include <coreplugin/locator/locatormanager.h> #include <coreplugin/icore.h> #include <coreplugin/editormanager/editormanager.h> @@ -592,7 +594,7 @@ TextEditorActionHandler::TextEditorActionHandler(Core::Id editorId, if (resolver) d->m_findTextWidget = resolver; else - d->m_findTextWidget = [](Core::IEditor *editor) { return qobject_cast<TextEditorWidget *>(editor->widget()); }; + d->m_findTextWidget = TextEditorWidget::fromEditor; } TextEditorActionHandler::~TextEditorActionHandler() |