Commit 96be6ae1 authored by hjk's avatar hjk

TextEditor: Shuffle some convenience functions

Remove rarely used ones, add a currentTextEditorWidget()

Change-Id: I27b97c17927c71e07dc3b489785b7f2f76eb801e
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 577fcd97
......@@ -63,18 +63,18 @@ static void moveCursorToEndOfName(QTextCursor *tc)
// We cannot depend on this since CppEditor plugin code is internal and requires building the implementation files ourselves
CPlusPlus::Symbol *AnalyzerUtils::findSymbolUnderCursor()
{
TextEditor::BaseTextEditor *editor = TextEditor::BaseTextEditor::currentTextEditor();
if (!editor)
TextEditor::TextEditorWidget *widget = TextEditor::TextEditorWidget::currentTextEditorWidget();
if (!widget)
return 0;
QTextCursor tc = editor->textCursor();
QTextCursor tc = widget->textCursor();
int line = 0;
int column = 0;
const int pos = tc.position();
editor->convertPosition(pos, &line, &column);
widget->convertPosition(pos, &line, &column);
const CPlusPlus::Snapshot &snapshot = CppTools::CppModelManager::instance()->snapshot();
CPlusPlus::Document::Ptr doc = snapshot.document(editor->document()->filePath());
CPlusPlus::Document::Ptr doc = snapshot.document(widget->textDocument()->filePath());
QTC_ASSERT(doc, return 0);
// fetch the expression's code
......
......@@ -220,25 +220,22 @@ QString BeautifierPlugin::format(const QString &text, const Command &command,
void BeautifierPlugin::formatCurrentFile(const Command &command)
{
QPlainTextEdit *textEditor = 0;
QString filePath;
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) {
textEditor = editor->editorWidget();
filePath = editor->document()->filePath();
}
if (!textEditor)
TextEditorWidget *widget = TextEditorWidget::currentTextEditorWidget();
if (!widget)
return;
const QString sourceData = textEditor->toPlainText();
const QString sourceData = widget->toPlainText();
if (sourceData.isEmpty())
return;
QFutureWatcher<FormatTask> *watcher = new QFutureWatcher<FormatTask>;
connect(textEditor->document(), SIGNAL(contentsChanged()), watcher, SLOT(cancel()));
connect(widget->textDocument(), &TextDocument::contentsChanged,
watcher, &QFutureWatcher<FormatTask>::cancel);
connect(watcher, SIGNAL(finished()), m_asyncFormatMapper, SLOT(map()));
m_asyncFormatMapper->setMapping(watcher, watcher);
const QString filePath = widget->textDocument()->filePath();
watcher->setFuture(QtConcurrent::run(&BeautifierPlugin::formatAsync, this,
FormatTask(textEditor, filePath, sourceData, command)));
FormatTask(widget, filePath, sourceData, command)));
}
void BeautifierPlugin::formatAsync(QFutureInterface<FormatTask> &future, FormatTask task)
......
......@@ -114,11 +114,11 @@ void ClangFormat::formatFile()
void ClangFormat::formatSelectedText()
{
TextEditor::BaseTextEditor *editor = TextEditor::BaseTextEditor::currentTextEditor();
if (!editor)
TextEditor::TextEditorWidget *widget = TextEditor::TextEditorWidget::currentTextEditorWidget();
if (!widget)
return;
QTextCursor tc = editor->textCursor();
QTextCursor tc = widget->textCursor();
if (tc.hasSelection()) {
const int offset = tc.selectionStart();
const int length = tc.selectionEnd() - offset;
......
......@@ -114,7 +114,7 @@ public:
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, cursorPosition);
editor->setTextCursor(cursor);
QTextDocument *qtextDocument = editor->qdocument();
QTextDocument *qtextDocument = editor->textDocument()->document();
CppRefactoringFilePtr cppRefactoringFile
= CppRefactoringChanges::file(editor->editorWidget(), document);
......
......@@ -44,12 +44,12 @@
#include <QDebug>
#include <QFileInfo>
#include <QTextBlock>
#include <limits.h>
using namespace Core;
using namespace TextEditor;
namespace Debugger {
namespace Internal {
......@@ -61,9 +61,9 @@ public:
~SourceAgentPrivate();
public:
QPointer<TextEditor::BaseTextEditor> editor;
QPointer<BaseTextEditor> editor;
QPointer<DebuggerEngine> engine;
TextEditor::TextMark *locationMark;
TextMark *locationMark;
QString path;
QString producer;
};
......@@ -73,7 +73,6 @@ SourceAgentPrivate::SourceAgentPrivate()
, locationMark(0)
, producer(QLatin1String("remote"))
{
}
SourceAgentPrivate::~SourceAgentPrivate()
......@@ -104,9 +103,6 @@ void SourceAgent::setSourceProducerName(const QString &name)
void SourceAgent::setContent(const QString &filePath, const QString &content)
{
QTC_ASSERT(d, return);
using namespace Core;
using namespace TextEditor;
d->path = filePath;
if (!d->editor) {
......@@ -143,9 +139,11 @@ void SourceAgent::updateLocationMarker()
d->locationMark = 0;
if (d->engine->stackHandler()->currentFrame().file == d->path) {
int lineNumber = d->engine->stackHandler()->currentFrame().line;
d->locationMark = new TextEditor::TextMark(QString(), lineNumber);
d->locationMark->setIcon(Internal::locationMarkIcon());
d->locationMark->setPriority(TextEditor::TextMark::HighPriority);
d->locationMark = new TextMark(QString(), lineNumber);
d->locationMark->setIcon(locationMarkIcon());
d->locationMark->setPriority(TextMark::HighPriority);
d->editor->textDocument()->addMark(d->locationMark);
QTextCursor tc = d->editor->textCursor();
QTextBlock block = tc.document()->findBlockByNumber(lineNumber - 1);
......
......@@ -1018,6 +1018,12 @@ TextDocumentPtr TextEditorWidget::textDocumentPtr() const
return d->m_document;
}
TextEditorWidget *TextEditorWidget::currentTextEditorWidget()
{
BaseTextEditor *editor = qobject_cast<BaseTextEditor *>(EditorManager::currentEditor());
return editor ? editor->editorWidget() : 0;
}
void TextEditorWidgetPrivate::editorContentsChange(int position, int charsRemoved, int charsAdded)
{
if (m_animator)
......@@ -6702,11 +6708,6 @@ void BaseTextEditor::convertPosition(int pos, int *line, int *column) const
editorWidget()->convertPosition(pos, line, column);
}
QRect BaseTextEditor::cursorRect(int pos) const
{
return editorWidget()->cursorRect(pos);
}
QString BaseTextEditor::selectedText() const
{
return editorWidget()->selectedText();
......@@ -7124,11 +7125,6 @@ TextEditorWidget *BaseTextEditor::editorWidget() const
return static_cast<TextEditorWidget *>(m_widget.data());
}
QTextDocument *BaseTextEditor::qdocument() const
{
return textDocument()->document();
}
void BaseTextEditor::setTextCursor(const QTextCursor &cursor)
{
editorWidget()->setTextCursor(cursor);
......
......@@ -147,7 +147,6 @@ public:
TextDocument *textDocument() const;
// Some convenience text access
QTextDocument *qdocument() const;
void setTextCursor(const QTextCursor &cursor);
QTextCursor textCursor() const;
QChar characterAt(int pos) const;
......@@ -184,9 +183,6 @@ public:
/*! Converts the \a pos in characters from beginning of document to \a line and \a column */
virtual void convertPosition(int pos, int *line, int *column) const;
/*! Returns the cursor rectangle in pixels at \a pos, or current position if \a pos = -1 */
virtual QRect cursorRect(int pos = -1) const;
virtual QString selectedText() const;
/*! Removes \a length characters to the right of the cursor. */
......@@ -574,6 +570,8 @@ public:
QString contextHelpId();
void setContextHelpId(const QString &id);
static TextEditorWidget *currentTextEditorWidget();
protected:
/*!
Reimplement this function to enable code navigation.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment