TextEditor: move TextSuggestion into own set of files

Since the plan is to extend the functionality of TextSuggestion, this
would add too much unrelated code to the text document layout
implementation file.

Change-Id: Ia5a7c12e75bf843a8741f325c81524d0c504286c
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
David Schulz
2024-08-30 14:41:34 +02:00
parent 4747d82c92
commit dd78b90b5c
6 changed files with 63 additions and 35 deletions

View File

@@ -100,14 +100,15 @@ add_qtc_plugin(TextEditor
texteditor.cpp texteditor.h
texteditor.qrc
texteditor_global.h
texteditortr.h
texteditorconstants.cpp texteditorconstants.h
texteditoroverlay.cpp texteditoroverlay.h
texteditorplugin.cpp
texteditorsettings.cpp texteditorsettings.h
texteditortr.h
textindenter.cpp textindenter.h
textmark.cpp textmark.h
textstyles.h
textsuggestion.h textsuggestion.cpp
typehierarchy.cpp typehierarchy.h
typingsettings.cpp typingsettings.h
)

View File

@@ -877,14 +877,6 @@ void insertSorted(Parentheses &list, const Parenthesis &elem)
list.insert(it, elem);
}
TextSuggestion::TextSuggestion()
{
m_replacementDocument.setDocumentLayout(new TextDocumentLayout(&m_replacementDocument));
m_replacementDocument.setDocumentMargin(0);
}
TextSuggestion::~TextSuggestion() = default;
} // TextEditor

View File

@@ -5,15 +5,16 @@
#include "texteditor_global.h"
#include "textmark.h"
#include "textdocument.h"
#include "textmark.h"
#include "textsuggestion.h"
#include <utils/id.h>
#include <KSyntaxHighlighting/State>
#include <QTextBlockUserData>
#include <QPlainTextDocumentLayout>
#include <QTextBlockUserData>
namespace TextEditor {
@@ -43,29 +44,6 @@ public:
virtual ~CodeFormatterData();
};
class TEXTEDITOR_EXPORT TextSuggestion
{
public:
TextSuggestion();
virtual ~TextSuggestion();
// Returns true if the suggestion was applied completely, false if it was only partially applied.
virtual bool apply() = 0;
// Returns true if the suggestion was applied completely, false if it was only partially applied.
virtual bool applyWord(TextEditorWidget *widget) = 0;
virtual bool applyLine(TextEditorWidget *widget) = 0;
virtual void reset() = 0;
virtual int position() = 0;
int currentPosition() const { return m_currentPosition; }
void setCurrentPosition(int position) { m_currentPosition = position; }
QTextDocument *document() { return &m_replacementDocument; }
private:
QTextDocument m_replacementDocument;
int m_currentPosition = -1;
};
class TEXTEDITOR_EXPORT TextBlockUserData : public QTextBlockUserData
{
public:

View File

@@ -136,7 +136,6 @@ QtcPlugin {
"texteditor.h",
"texteditor.qrc",
"texteditor_global.h",
"texteditortr.h",
"texteditorconstants.cpp",
"texteditorconstants.h",
"texteditoroverlay.cpp",
@@ -144,6 +143,9 @@ QtcPlugin {
"texteditorplugin.cpp",
"texteditorsettings.cpp",
"texteditorsettings.h",
"texteditortr.h",
"textesuggestion.cpp",
"textesuggestion.h",
"textindenter.cpp",
"textindenter.h",
"textmark.cpp",

View File

@@ -0,0 +1,18 @@
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "textsuggestion.h"
#include "textdocumentlayout.h"
namespace TextEditor {
TextSuggestion::TextSuggestion()
{
m_replacementDocument.setDocumentLayout(new TextDocumentLayout(&m_replacementDocument));
m_replacementDocument.setDocumentMargin(0);
}
TextSuggestion::~TextSuggestion() = default;
} // namespace TextEditor

View File

@@ -0,0 +1,37 @@
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "texteditor_global.h"
#include <QTextDocument>
namespace TextEditor {
class TextEditorWidget;
class TEXTEDITOR_EXPORT TextSuggestion
{
public:
TextSuggestion();
virtual ~TextSuggestion();
// Returns true if the suggestion was applied completely, false if it was only partially applied.
virtual bool apply() = 0;
// Returns true if the suggestion was applied completely, false if it was only partially applied.
virtual bool applyWord(TextEditorWidget *widget) = 0;
virtual bool applyLine(TextEditorWidget *widget) = 0;
virtual void reset() = 0;
virtual int position() = 0;
int currentPosition() const { return m_currentPosition; }
void setCurrentPosition(int position) { m_currentPosition = position; }
QTextDocument *document() { return &m_replacementDocument; }
private:
QTextDocument m_replacementDocument;
int m_currentPosition = -1;
};
} // namespace TextEditor