Make TextEditor setup more flexible

So far it was only possible to combine TextEditorFactory, BaseTextEditor
and TextEditorWidget directly.
That TextEditorWidget is also directly a QPlainTextEdit made it
impossible to "decorate" the text editor widget with something else
without a lot of effort.

Make it possible to create a text editor factory that returns an
arbitrary widget, as long as it can be "cast" to a TextEditorWidget with
either qobject_cast or Aggregation::query. That way the TextEditorWidget
instance can be attached to the editor widget via Aggregation.

Adapt other code that accesses TextEditorWidget from editors
accordingly. Introduce a common method how to do that.

Change-Id: I72b8721f3a8a8d8281c39af75253e9c80cbe1250
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2020-02-11 14:00:09 +01:00
parent 42f02fae03
commit d43f1662d0
14 changed files with 54 additions and 37 deletions

View File

@@ -1267,7 +1267,7 @@ void FakeVimPluginPrivate::userActionTriggered(int key)
void FakeVimPluginPrivate::createRelativeNumberWidget(IEditor *editor)
{
if (auto textEditor = qobject_cast<TextEditorWidget *>(editor->widget())) {
if (auto textEditor = TextEditorWidget::fromEditor(editor)) {
auto relativeNumbers = new RelativeNumbersColumn(textEditor);
connect(theFakeVimSetting(ConfigRelativeNumber), &SavedAction::valueChanged,
relativeNumbers, &QObject::deleteLater);
@@ -1532,10 +1532,14 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor)
return;
// we can only handle QTextEdit and QPlainTextEdit
if (!qobject_cast<QTextEdit *>(widget) && !qobject_cast<QPlainTextEdit *>(widget))
if (auto edit = Aggregation::query<QTextEdit>(widget))
widget = edit;
else if (auto edit = Aggregation::query<QPlainTextEdit>(widget))
widget = edit;
else
return;
auto tew = qobject_cast<TextEditorWidget *>(widget);
auto tew = TextEditorWidget::fromEditor(editor);
//qDebug() << "OPENING: " << editor << editor->widget()
// << "MODE: " << theFakeVimSetting(ConfigUseFakeVim)->value();