forked from qt-creator/qt-creator
TextEditor: Modernize texteditor.{cpp,h}
Apply some clazy and modernize fixes from clang tidy: mostly use of nullptr and removal of type duplication. Change-Id: Ibd9ee8f9b8a836a40d6f9be0b95acc91513a1a01 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -156,8 +156,8 @@ namespace Internal {
|
|||||||
|
|
||||||
enum { NExtraSelectionKinds = 12 };
|
enum { NExtraSelectionKinds = 12 };
|
||||||
|
|
||||||
typedef QString (TransformationMethod)(const QString &);
|
using TransformationMethod = QString(const QString &);
|
||||||
typedef void (ListTransformationMethod)(QStringList &);
|
using ListTransformationMethod = void(QStringList &);
|
||||||
|
|
||||||
static QString QString_toUpper(const QString &str)
|
static QString QString_toUpper(const QString &str)
|
||||||
{
|
{
|
||||||
@@ -253,29 +253,28 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSize sizeHint() const {
|
QSize sizeHint() const override {
|
||||||
return QSize(textEdit->extraAreaWidth(), 0);
|
return {textEdit->extraAreaWidth(), 0};
|
||||||
}
|
}
|
||||||
void paintEvent(QPaintEvent *event) {
|
void paintEvent(QPaintEvent *event) override {
|
||||||
textEdit->extraAreaPaintEvent(event);
|
textEdit->extraAreaPaintEvent(event);
|
||||||
}
|
}
|
||||||
void mousePressEvent(QMouseEvent *event) {
|
void mousePressEvent(QMouseEvent *event) override {
|
||||||
textEdit->extraAreaMouseEvent(event);
|
textEdit->extraAreaMouseEvent(event);
|
||||||
}
|
}
|
||||||
void mouseMoveEvent(QMouseEvent *event) {
|
void mouseMoveEvent(QMouseEvent *event) override {
|
||||||
textEdit->extraAreaMouseEvent(event);
|
textEdit->extraAreaMouseEvent(event);
|
||||||
}
|
}
|
||||||
void mouseReleaseEvent(QMouseEvent *event) {
|
void mouseReleaseEvent(QMouseEvent *event) override {
|
||||||
textEdit->extraAreaMouseEvent(event);
|
textEdit->extraAreaMouseEvent(event);
|
||||||
}
|
}
|
||||||
void leaveEvent(QEvent *event) {
|
void leaveEvent(QEvent *event) override {
|
||||||
textEdit->extraAreaLeaveEvent(event);
|
textEdit->extraAreaLeaveEvent(event);
|
||||||
}
|
}
|
||||||
void contextMenuEvent(QContextMenuEvent *event) {
|
void contextMenuEvent(QContextMenuEvent *event) override {
|
||||||
textEdit->extraAreaContextMenuEvent(event);
|
textEdit->extraAreaContextMenuEvent(event);
|
||||||
}
|
}
|
||||||
|
void wheelEvent(QWheelEvent *event) override {
|
||||||
void wheelEvent(QWheelEvent *event) {
|
|
||||||
QCoreApplication::sendEvent(textEdit->viewport(), event);
|
QCoreApplication::sendEvent(textEdit->viewport(), event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +285,7 @@ private:
|
|||||||
class BaseTextEditorPrivate
|
class BaseTextEditorPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BaseTextEditorPrivate() {}
|
BaseTextEditorPrivate() = default;
|
||||||
|
|
||||||
TextEditorFactoryPrivate *m_origin = nullptr;
|
TextEditorFactoryPrivate *m_origin = nullptr;
|
||||||
};
|
};
|
||||||
@@ -451,7 +450,7 @@ struct PaintEventData
|
|||||||
QTextBlock visibleCollapsedBlock;
|
QTextBlock visibleCollapsedBlock;
|
||||||
QPointF visibleCollapsedBlockOffset;
|
QPointF visibleCollapsedBlockOffset;
|
||||||
QTextBlock block;
|
QTextBlock block;
|
||||||
QTextLayout *cursorLayout = 0;
|
QTextLayout *cursorLayout = nullptr;
|
||||||
QPointF cursorOffset;
|
QPointF cursorOffset;
|
||||||
int cursorPos = 0;
|
int cursorPos = 0;
|
||||||
QPen cursorPen;
|
QPen cursorPen;
|
||||||
@@ -475,7 +474,7 @@ class TextEditorWidgetPrivate : public QObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TextEditorWidgetPrivate(TextEditorWidget *parent);
|
TextEditorWidgetPrivate(TextEditorWidget *parent);
|
||||||
~TextEditorWidgetPrivate();
|
~TextEditorWidgetPrivate() override;
|
||||||
|
|
||||||
void setupDocumentSignals();
|
void setupDocumentSignals();
|
||||||
void updateLineSelectionColor();
|
void updateLineSelectionColor();
|
||||||
@@ -545,7 +544,7 @@ public:
|
|||||||
void toggleBlockVisible(const QTextBlock &block);
|
void toggleBlockVisible(const QTextBlock &block);
|
||||||
QRect foldBox();
|
QRect foldBox();
|
||||||
|
|
||||||
QTextBlock foldedBlockAt(const QPoint &pos, QRect *box = 0) const;
|
QTextBlock foldedBlockAt(const QPoint &pos, QRect *box = nullptr) const;
|
||||||
|
|
||||||
void requestUpdateLink(QMouseEvent *e, bool immediate = false);
|
void requestUpdateLink(QMouseEvent *e, bool immediate = false);
|
||||||
void updateLink();
|
void updateLink();
|
||||||
@@ -788,8 +787,8 @@ TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent)
|
|||||||
m_clipboardAssistProvider(new ClipboardAssistProvider),
|
m_clipboardAssistProvider(new ClipboardAssistProvider),
|
||||||
m_autoCompleter(new AutoCompleter)
|
m_autoCompleter(new AutoCompleter)
|
||||||
{
|
{
|
||||||
Aggregation::Aggregate *aggregate = new Aggregation::Aggregate;
|
auto aggregate = new Aggregation::Aggregate;
|
||||||
BaseTextFind *baseTextFind = new BaseTextFind(q);
|
auto baseTextFind = new BaseTextFind(q);
|
||||||
connect(baseTextFind, &BaseTextFind::highlightAllRequested,
|
connect(baseTextFind, &BaseTextFind::highlightAllRequested,
|
||||||
this, &TextEditorWidgetPrivate::highlightSearchResultsSlot);
|
this, &TextEditorWidgetPrivate::highlightSearchResultsSlot);
|
||||||
connect(baseTextFind, &BaseTextFind::findScopeChanged,
|
connect(baseTextFind, &BaseTextFind::findScopeChanged,
|
||||||
@@ -903,7 +902,7 @@ TextEditorWidget::TextEditorWidget(QWidget *parent)
|
|||||||
{
|
{
|
||||||
// "Needed", as the creation below triggers ChildEvents that are
|
// "Needed", as the creation below triggers ChildEvents that are
|
||||||
// passed to this object's event() which uses 'd'.
|
// passed to this object's event() which uses 'd'.
|
||||||
d = 0;
|
d = nullptr;
|
||||||
d = new TextEditorWidgetPrivate(this);
|
d = new TextEditorWidgetPrivate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -986,8 +985,8 @@ void TextEditorWidgetPrivate::ctor(const QSharedPointer<TextDocument> &doc)
|
|||||||
QObject::connect(&m_scrollBarUpdateTimer, &QTimer::timeout,
|
QObject::connect(&m_scrollBarUpdateTimer, &QTimer::timeout,
|
||||||
this, &TextEditorWidgetPrivate::highlightSearchResultsInScrollBar);
|
this, &TextEditorWidgetPrivate::highlightSearchResultsInScrollBar);
|
||||||
|
|
||||||
m_bracketsAnimator = 0;
|
m_bracketsAnimator = nullptr;
|
||||||
m_autocompleteAnimator = 0;
|
m_autocompleteAnimator = nullptr;
|
||||||
|
|
||||||
slotUpdateExtraAreaWidth();
|
slotUpdateExtraAreaWidth();
|
||||||
updateHighlights();
|
updateHighlights();
|
||||||
@@ -1015,14 +1014,14 @@ void TextEditorWidgetPrivate::ctor(const QSharedPointer<TextDocument> &doc)
|
|||||||
TextEditorWidget::~TextEditorWidget()
|
TextEditorWidget::~TextEditorWidget()
|
||||||
{
|
{
|
||||||
delete d;
|
delete d;
|
||||||
d = 0;
|
d = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorWidget::print(QPrinter *printer)
|
void TextEditorWidget::print(QPrinter *printer)
|
||||||
{
|
{
|
||||||
const bool oldFullPage = printer->fullPage();
|
const bool oldFullPage = printer->fullPage();
|
||||||
printer->setFullPage(true);
|
printer->setFullPage(true);
|
||||||
QPrintDialog *dlg = new QPrintDialog(printer, this);
|
auto dlg = new QPrintDialog(printer, this);
|
||||||
dlg->setWindowTitle(tr("Print Document"));
|
dlg->setWindowTitle(tr("Print Document"));
|
||||||
if (dlg->exec() == QDialog::Accepted)
|
if (dlg->exec() == QDialog::Accepted)
|
||||||
d->print(printer);
|
d->print(printer);
|
||||||
@@ -1233,7 +1232,7 @@ void TextEditorWidgetPrivate::updateAutoCompleteHighlight()
|
|||||||
= q->textDocument()->fontSettings().toTextCharFormat(C_AUTOCOMPLETE);
|
= q->textDocument()->fontSettings().toTextCharFormat(C_AUTOCOMPLETE);
|
||||||
|
|
||||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||||
for (QTextCursor cursor : Utils::asConst(m_autoCompleteHighlightPos)) {
|
for (const QTextCursor &cursor : Utils::asConst(m_autoCompleteHighlightPos)) {
|
||||||
QTextEdit::ExtraSelection sel;
|
QTextEdit::ExtraSelection sel;
|
||||||
sel.cursor = cursor;
|
sel.cursor = cursor;
|
||||||
sel.format.setBackground(matchFormat.background());
|
sel.format.setBackground(matchFormat.background());
|
||||||
@@ -1303,7 +1302,7 @@ void TextEditorWidgetPrivate::updateCannotDecodeInfo()
|
|||||||
return;
|
return;
|
||||||
InfoBarEntry info(selectEncodingId,
|
InfoBarEntry info(selectEncodingId,
|
||||||
TextEditorWidget::tr("<b>Error:</b> Could not decode \"%1\" with \"%2\"-encoding. Editing not possible.")
|
TextEditorWidget::tr("<b>Error:</b> Could not decode \"%1\" with \"%2\"-encoding. Editing not possible.")
|
||||||
.arg(m_document->displayName()).arg(QString::fromLatin1(m_document->codec()->name())));
|
.arg(m_document->displayName(), QString::fromLatin1(m_document->codec()->name())));
|
||||||
info.setCustomButtonInfo(TextEditorWidget::tr("Select Encoding"), [this]() { q->selectEncoding(); });
|
info.setCustomButtonInfo(TextEditorWidget::tr("Select Encoding"), [this]() { q->selectEncoding(); });
|
||||||
infoBar->addInfo(info);
|
infoBar->addInfo(info);
|
||||||
} else {
|
} else {
|
||||||
@@ -1334,7 +1333,7 @@ static QTextBlock skipShebang(const QTextBlock &block)
|
|||||||
void TextEditorWidgetPrivate::foldLicenseHeader()
|
void TextEditorWidgetPrivate::foldLicenseHeader()
|
||||||
{
|
{
|
||||||
QTextDocument *doc = q->document();
|
QTextDocument *doc = q->document();
|
||||||
TextDocumentLayout *documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
||||||
QTC_ASSERT(documentLayout, return);
|
QTC_ASSERT(documentLayout, return);
|
||||||
QTextBlock block = skipShebang(doc->firstBlock());
|
QTextBlock block = skipShebang(doc->firstBlock());
|
||||||
while (block.isValid() && block.isVisible()) {
|
while (block.isValid() && block.isVisible()) {
|
||||||
@@ -1380,8 +1379,8 @@ TextDocumentPtr TextEditorWidget::textDocumentPtr() const
|
|||||||
|
|
||||||
TextEditorWidget *TextEditorWidget::currentTextEditorWidget()
|
TextEditorWidget *TextEditorWidget::currentTextEditorWidget()
|
||||||
{
|
{
|
||||||
BaseTextEditor *editor = qobject_cast<BaseTextEditor *>(EditorManager::currentEditor());
|
auto editor = qobject_cast<BaseTextEditor *>(EditorManager::currentEditor());
|
||||||
return editor ? editor->editorWidget() : 0;
|
return editor ? editor->editorWidget() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorWidgetPrivate::editorContentsChange(int position, int charsRemoved, int charsAdded)
|
void TextEditorWidgetPrivate::editorContentsChange(int position, int charsRemoved, int charsAdded)
|
||||||
@@ -1391,7 +1390,7 @@ void TextEditorWidgetPrivate::editorContentsChange(int position, int charsRemove
|
|||||||
|
|
||||||
m_contentsChanged = true;
|
m_contentsChanged = true;
|
||||||
QTextDocument *doc = q->document();
|
QTextDocument *doc = q->document();
|
||||||
TextDocumentLayout *documentLayout = static_cast<TextDocumentLayout*>(doc->documentLayout());
|
auto documentLayout = static_cast<TextDocumentLayout*>(doc->documentLayout());
|
||||||
const QTextBlock posBlock = doc->findBlock(position);
|
const QTextBlock posBlock = doc->findBlock(position);
|
||||||
|
|
||||||
// Keep the line numbers and the block information for the text marks updated
|
// Keep the line numbers and the block information for the text marks updated
|
||||||
@@ -1973,11 +1972,11 @@ static QTextLine currentTextLine(const QTextCursor &cursor)
|
|||||||
{
|
{
|
||||||
const QTextBlock block = cursor.block();
|
const QTextBlock block = cursor.block();
|
||||||
if (!block.isValid())
|
if (!block.isValid())
|
||||||
return QTextLine();
|
return {};
|
||||||
|
|
||||||
const QTextLayout *layout = block.layout();
|
const QTextLayout *layout = block.layout();
|
||||||
if (!layout)
|
if (!layout)
|
||||||
return QTextLine();
|
return {};
|
||||||
|
|
||||||
const int relativePos = cursor.position() - block.position();
|
const int relativePos = cursor.position() - block.position();
|
||||||
return layout->lineForTextPosition(relativePos);
|
return layout->lineForTextPosition(relativePos);
|
||||||
@@ -3085,8 +3084,7 @@ bool TextEditorWidget::restoreState(const QByteArray &state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (layoutChanged) {
|
if (layoutChanged) {
|
||||||
TextDocumentLayout *documentLayout =
|
auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
||||||
qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
|
||||||
QTC_ASSERT(documentLayout, return false);
|
QTC_ASSERT(documentLayout, return false);
|
||||||
documentLayout->requestUpdate();
|
documentLayout->requestUpdate();
|
||||||
documentLayout->emitDocumentSizeChanged();
|
documentLayout->emitDocumentSizeChanged();
|
||||||
@@ -3306,7 +3304,7 @@ void TextEditorWidgetPrivate::setupDocumentSignals()
|
|||||||
q->QPlainTextEdit::setDocument(doc);
|
q->QPlainTextEdit::setDocument(doc);
|
||||||
q->setCursorWidth(2); // Applies to the document layout
|
q->setCursorWidth(2); // Applies to the document layout
|
||||||
|
|
||||||
TextDocumentLayout *documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
||||||
QTC_CHECK(documentLayout);
|
QTC_CHECK(documentLayout);
|
||||||
|
|
||||||
QObject::connect(documentLayout, &QPlainTextDocumentLayout::updateBlock,
|
QObject::connect(documentLayout, &QPlainTextDocumentLayout::updateBlock,
|
||||||
@@ -3561,13 +3559,13 @@ void TextEditorWidget::resizeEvent(QResizeEvent *e)
|
|||||||
QRect TextEditorWidgetPrivate::foldBox()
|
QRect TextEditorWidgetPrivate::foldBox()
|
||||||
{
|
{
|
||||||
if (m_highlightBlocksInfo.isEmpty() || extraAreaHighlightFoldedBlockNumber < 0)
|
if (m_highlightBlocksInfo.isEmpty() || extraAreaHighlightFoldedBlockNumber < 0)
|
||||||
return QRect();
|
return {};
|
||||||
|
|
||||||
QTextBlock begin = q->document()->findBlockByNumber(m_highlightBlocksInfo.open.last());
|
QTextBlock begin = q->document()->findBlockByNumber(m_highlightBlocksInfo.open.last());
|
||||||
|
|
||||||
QTextBlock end = q->document()->findBlockByNumber(m_highlightBlocksInfo.close.first());
|
QTextBlock end = q->document()->findBlockByNumber(m_highlightBlocksInfo.close.first());
|
||||||
if (!begin.isValid() || !end.isValid())
|
if (!begin.isValid() || !end.isValid())
|
||||||
return QRect();
|
return {};
|
||||||
QRectF br = q->blockBoundingGeometry(begin).translated(q->contentOffset());
|
QRectF br = q->blockBoundingGeometry(begin).translated(q->contentOffset());
|
||||||
QRectF er = q->blockBoundingGeometry(end).translated(q->contentOffset());
|
QRectF er = q->blockBoundingGeometry(end).translated(q->contentOffset());
|
||||||
|
|
||||||
@@ -4003,7 +4001,7 @@ QRectF TextEditorWidgetPrivate::getLastLineLineRect(const QTextBlock &block)
|
|||||||
const QTextLayout *layout = block.layout();
|
const QTextLayout *layout = block.layout();
|
||||||
const int lineCount = layout->lineCount();
|
const int lineCount = layout->lineCount();
|
||||||
if (lineCount < 1)
|
if (lineCount < 1)
|
||||||
return QRectF();
|
return {};
|
||||||
const QTextLine line = layout->lineAt(lineCount - 1);
|
const QTextLine line = layout->lineAt(lineCount - 1);
|
||||||
const QPointF contentOffset = q->contentOffset();
|
const QPointF contentOffset = q->contentOffset();
|
||||||
const qreal top = q->blockBoundingGeometry(block).translated(contentOffset).top();
|
const qreal top = q->blockBoundingGeometry(block).translated(contentOffset).top();
|
||||||
@@ -4322,7 +4320,7 @@ void TextEditorWidgetPrivate::paintFindScope(const PaintEventData &data, QPainte
|
|||||||
block = TextEditor::nextVisibleBlock(block, data.doc);
|
block = TextEditor::nextVisibleBlock(block, data.doc);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TextEditorOverlay *overlay = new TextEditorOverlay(q);
|
auto overlay = new TextEditorOverlay(q);
|
||||||
overlay->addOverlaySelection(m_findScopeStart.position(),
|
overlay->addOverlaySelection(m_findScopeStart.position(),
|
||||||
m_findScopeEnd.position(),
|
m_findScopeEnd.position(),
|
||||||
data.searchScopeFormat.foreground().color(),
|
data.searchScopeFormat.foreground().color(),
|
||||||
@@ -4903,7 +4901,7 @@ QWidget *TextEditorWidget::extraArea() const
|
|||||||
|
|
||||||
int TextEditorWidget::extraAreaWidth(int *markWidthPtr) const
|
int TextEditorWidget::extraAreaWidth(int *markWidthPtr) const
|
||||||
{
|
{
|
||||||
TextDocumentLayout *documentLayout = qobject_cast<TextDocumentLayout*>(document()->documentLayout());
|
auto documentLayout = qobject_cast<TextDocumentLayout*>(document()->documentLayout());
|
||||||
if (!documentLayout)
|
if (!documentLayout)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -5027,7 +5025,7 @@ void TextEditorWidgetPrivate::paintLineNumbers(QPainter &painter,
|
|||||||
void TextEditorWidgetPrivate::paintTextMarks(QPainter &painter, const ExtraAreaPaintEventData &data,
|
void TextEditorWidgetPrivate::paintTextMarks(QPainter &painter, const ExtraAreaPaintEventData &data,
|
||||||
const QRectF &blockBoundingRect) const
|
const QRectF &blockBoundingRect) const
|
||||||
{
|
{
|
||||||
TextBlockUserData *userData = static_cast<TextBlockUserData*>(data.block.userData());
|
auto userData = static_cast<TextBlockUserData*>(data.block.userData());
|
||||||
if (!userData || !m_marksVisible)
|
if (!userData || !m_marksVisible)
|
||||||
return;
|
return;
|
||||||
int xoffset = 0;
|
int xoffset = 0;
|
||||||
@@ -5173,7 +5171,7 @@ void TextEditorWidgetPrivate::drawFoldingMarker(QPainter *painter, const QPalett
|
|||||||
bool hovered) const
|
bool hovered) const
|
||||||
{
|
{
|
||||||
QStyle *s = q->style();
|
QStyle *s = q->style();
|
||||||
if (ManhattanStyle *ms = qobject_cast<ManhattanStyle*>(s))
|
if (auto ms = qobject_cast<ManhattanStyle*>(s))
|
||||||
s = ms->baseStyle();
|
s = ms->baseStyle();
|
||||||
|
|
||||||
QStyleOptionViewItem opt;
|
QStyleOptionViewItem opt;
|
||||||
@@ -5282,7 +5280,7 @@ void TextEditorWidgetPrivate::updateHighlights()
|
|||||||
if (m_parenthesesMatchingEnabled && q->hasFocus()) {
|
if (m_parenthesesMatchingEnabled && q->hasFocus()) {
|
||||||
// Delay update when no matching is displayed yet, to avoid flicker
|
// Delay update when no matching is displayed yet, to avoid flicker
|
||||||
if (q->extraSelections(TextEditorWidget::ParenthesesMatchingSelection).isEmpty()
|
if (q->extraSelections(TextEditorWidget::ParenthesesMatchingSelection).isEmpty()
|
||||||
&& m_bracketsAnimator == 0) {
|
&& m_bracketsAnimator == nullptr) {
|
||||||
m_parenthesesMatchingTimer.start(50);
|
m_parenthesesMatchingTimer.start(50);
|
||||||
} else {
|
} else {
|
||||||
// when we uncheck "highlight matching parentheses"
|
// when we uncheck "highlight matching parentheses"
|
||||||
@@ -5656,7 +5654,7 @@ void TextEditorWidget::extraAreaContextMenuEvent(QContextMenuEvent *e)
|
|||||||
{
|
{
|
||||||
if (d->m_marksVisible) {
|
if (d->m_marksVisible) {
|
||||||
QTextCursor cursor = cursorForPosition(QPoint(0, e->pos().y()));
|
QTextCursor cursor = cursorForPosition(QPoint(0, e->pos().y()));
|
||||||
QMenu * contextMenu = new QMenu(this);
|
auto contextMenu = new QMenu(this);
|
||||||
emit markContextMenuRequested(this, cursor.blockNumber() + 1, contextMenu);
|
emit markContextMenuRequested(this, cursor.blockNumber() + 1, contextMenu);
|
||||||
if (!contextMenu->isEmpty())
|
if (!contextMenu->isEmpty())
|
||||||
contextMenu->exec(e->globalPos());
|
contextMenu->exec(e->globalPos());
|
||||||
@@ -5767,7 +5765,7 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
|
|||||||
d->extraAreaToggleMarkBlockNumber = cursor.blockNumber();
|
d->extraAreaToggleMarkBlockNumber = cursor.blockNumber();
|
||||||
d->m_markDragging = false;
|
d->m_markDragging = false;
|
||||||
QTextBlock block = cursor.document()->findBlockByNumber(d->extraAreaToggleMarkBlockNumber);
|
QTextBlock block = cursor.document()->findBlockByNumber(d->extraAreaToggleMarkBlockNumber);
|
||||||
if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData())) {
|
if (auto data = static_cast<TextBlockUserData *>(block.userData())) {
|
||||||
TextMarks marks = data->marks();
|
TextMarks marks = data->marks();
|
||||||
for (int i = marks.size(); --i >= 0; ) {
|
for (int i = marks.size(); --i >= 0; ) {
|
||||||
TextMark *mark = marks.at(i);
|
TextMark *mark = marks.at(i);
|
||||||
@@ -5825,7 +5823,7 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
|
|||||||
return;
|
return;
|
||||||
} else if (sameLine) {
|
} else if (sameLine) {
|
||||||
QTextBlock block = cursor.document()->findBlockByNumber(n);
|
QTextBlock block = cursor.document()->findBlockByNumber(n);
|
||||||
if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData())) {
|
if (auto data = static_cast<TextBlockUserData *>(block.userData())) {
|
||||||
TextMarks marks = data->marks();
|
TextMarks marks = data->marks();
|
||||||
for (int i = marks.size(); --i >= 0; ) {
|
for (int i = marks.size(); --i >= 0; ) {
|
||||||
TextMark *mark = marks.at(i);
|
TextMark *mark = marks.at(i);
|
||||||
@@ -5857,7 +5855,7 @@ void TextEditorWidget::ensureCursorVisible()
|
|||||||
void TextEditorWidget::ensureBlockIsUnfolded(QTextBlock block)
|
void TextEditorWidget::ensureBlockIsUnfolded(QTextBlock block)
|
||||||
{
|
{
|
||||||
if (!block.isVisible()) {
|
if (!block.isVisible()) {
|
||||||
TextDocumentLayout *documentLayout = qobject_cast<TextDocumentLayout*>(document()->documentLayout());
|
auto documentLayout = qobject_cast<TextDocumentLayout*>(document()->documentLayout());
|
||||||
QTC_ASSERT(documentLayout, return);
|
QTC_ASSERT(documentLayout, return);
|
||||||
|
|
||||||
// Open all parent folds of current line.
|
// Open all parent folds of current line.
|
||||||
@@ -6255,7 +6253,7 @@ void TextEditorWidgetPrivate::searchResultsReady(int beginIndex, int endIndex)
|
|||||||
void TextEditorWidgetPrivate::searchFinished()
|
void TextEditorWidgetPrivate::searchFinished()
|
||||||
{
|
{
|
||||||
delete m_searchWatcher;
|
delete m_searchWatcher;
|
||||||
m_searchWatcher = 0;
|
m_searchWatcher = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorWidgetPrivate::adjustScrollBarRanges()
|
void TextEditorWidgetPrivate::adjustScrollBarRanges()
|
||||||
@@ -6282,7 +6280,7 @@ void TextEditorWidgetPrivate::highlightSearchResultsInScrollBar()
|
|||||||
m_searchWatcher->disconnect();
|
m_searchWatcher->disconnect();
|
||||||
m_searchWatcher->cancel();
|
m_searchWatcher->cancel();
|
||||||
m_searchWatcher->deleteLater();
|
m_searchWatcher->deleteLater();
|
||||||
m_searchWatcher = 0;
|
m_searchWatcher = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &txt = m_searchExpr.pattern();
|
const QString &txt = m_searchExpr.pattern();
|
||||||
@@ -6986,8 +6984,7 @@ QList<QTextEdit::ExtraSelection> TextEditorWidget::extraSelections(Id kind) cons
|
|||||||
QString TextEditorWidget::extraSelectionTooltip(int pos) const
|
QString TextEditorWidget::extraSelectionTooltip(int pos) const
|
||||||
{
|
{
|
||||||
foreach (const QList<QTextEdit::ExtraSelection> &sel, d->m_extraSelections) {
|
foreach (const QList<QTextEdit::ExtraSelection> &sel, d->m_extraSelections) {
|
||||||
for (int j = 0; j < sel.size(); ++j) {
|
for (const QTextEdit::ExtraSelection &s : sel) {
|
||||||
const QTextEdit::ExtraSelection &s = sel.at(j);
|
|
||||||
if (s.cursor.selectionStart() <= pos
|
if (s.cursor.selectionStart() <= pos
|
||||||
&& s.cursor.selectionEnd() >= pos
|
&& s.cursor.selectionEnd() >= pos
|
||||||
&& !s.format.toolTip().isEmpty())
|
&& !s.format.toolTip().isEmpty())
|
||||||
@@ -7001,7 +6998,7 @@ QString TextEditorWidget::extraSelectionTooltip(int pos) const
|
|||||||
void TextEditorWidget::setIfdefedOutBlocks(const QList<BlockRange> &blocks)
|
void TextEditorWidget::setIfdefedOutBlocks(const QList<BlockRange> &blocks)
|
||||||
{
|
{
|
||||||
QTextDocument *doc = document();
|
QTextDocument *doc = document();
|
||||||
TextDocumentLayout *documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
||||||
QTC_ASSERT(documentLayout, return);
|
QTC_ASSERT(documentLayout, return);
|
||||||
|
|
||||||
bool needUpdate = false;
|
bool needUpdate = false;
|
||||||
@@ -7082,11 +7079,9 @@ void TextEditorWidget::rewrapParagraph()
|
|||||||
// Find indent level of current block.
|
// Find indent level of current block.
|
||||||
|
|
||||||
int indentLevel = 0;
|
int indentLevel = 0;
|
||||||
QString text = cursor.block().text();
|
const QString text = cursor.block().text();
|
||||||
|
|
||||||
for (int i = 0; i < text.length(); i++) {
|
|
||||||
const QChar ch = text.at(i);
|
|
||||||
|
|
||||||
|
for (const QChar &ch : text) {
|
||||||
if (ch == QLatin1Char(' '))
|
if (ch == QLatin1Char(' '))
|
||||||
indentLevel++;
|
indentLevel++;
|
||||||
else if (ch == QLatin1Char('\t'))
|
else if (ch == QLatin1Char('\t'))
|
||||||
@@ -7151,8 +7146,7 @@ void TextEditorWidget::rewrapParagraph()
|
|||||||
// keep the same indentation level as first line in paragraph.
|
// keep the same indentation level as first line in paragraph.
|
||||||
QString currentWord;
|
QString currentWord;
|
||||||
|
|
||||||
for (int i = 0; i < selectedText.length(); ++i) {
|
for (const QChar &ch : Utils::asConst(selectedText)) {
|
||||||
QChar ch = selectedText.at(i);
|
|
||||||
if (ch.isSpace()) {
|
if (ch.isSpace()) {
|
||||||
if (!currentWord.isEmpty()) {
|
if (!currentWord.isEmpty()) {
|
||||||
currentLength += currentWord.length() + 1;
|
currentLength += currentWord.length() + 1;
|
||||||
@@ -7349,7 +7343,7 @@ void TextEditorWidget::setExtraEncodingSettings(const ExtraEncodingSettings &ext
|
|||||||
void TextEditorWidget::fold()
|
void TextEditorWidget::fold()
|
||||||
{
|
{
|
||||||
QTextDocument *doc = document();
|
QTextDocument *doc = document();
|
||||||
TextDocumentLayout *documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
||||||
QTC_ASSERT(documentLayout, return);
|
QTC_ASSERT(documentLayout, return);
|
||||||
QTextBlock block = textCursor().block();
|
QTextBlock block = textCursor().block();
|
||||||
if (!(TextDocumentLayout::canFold(block) && block.next().isVisible())) {
|
if (!(TextDocumentLayout::canFold(block) && block.next().isVisible())) {
|
||||||
@@ -7369,7 +7363,7 @@ void TextEditorWidget::fold()
|
|||||||
void TextEditorWidget::unfold()
|
void TextEditorWidget::unfold()
|
||||||
{
|
{
|
||||||
QTextDocument *doc = document();
|
QTextDocument *doc = document();
|
||||||
TextDocumentLayout *documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
||||||
QTC_ASSERT(documentLayout, return);
|
QTC_ASSERT(documentLayout, return);
|
||||||
QTextBlock block = textCursor().block();
|
QTextBlock block = textCursor().block();
|
||||||
while (block.isValid() && !block.isVisible())
|
while (block.isValid() && !block.isVisible())
|
||||||
@@ -7383,7 +7377,7 @@ void TextEditorWidget::unfold()
|
|||||||
void TextEditorWidget::unfoldAll()
|
void TextEditorWidget::unfoldAll()
|
||||||
{
|
{
|
||||||
QTextDocument *doc = document();
|
QTextDocument *doc = document();
|
||||||
TextDocumentLayout *documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
||||||
QTC_ASSERT(documentLayout, return);
|
QTC_ASSERT(documentLayout, return);
|
||||||
|
|
||||||
QTextBlock block = doc->firstBlock();
|
QTextBlock block = doc->firstBlock();
|
||||||
@@ -7491,12 +7485,12 @@ void TextEditorWidget::switchUtf8bom()
|
|||||||
QMimeData *TextEditorWidget::createMimeDataFromSelection() const
|
QMimeData *TextEditorWidget::createMimeDataFromSelection() const
|
||||||
{
|
{
|
||||||
if (d->m_inBlockSelectionMode) {
|
if (d->m_inBlockSelectionMode) {
|
||||||
QMimeData *mimeData = new QMimeData;
|
auto mimeData = new QMimeData;
|
||||||
mimeData->setText(d->copyBlockSelection());
|
mimeData->setText(d->copyBlockSelection());
|
||||||
return mimeData;
|
return mimeData;
|
||||||
} else if (textCursor().hasSelection()) {
|
} else if (textCursor().hasSelection()) {
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
QMimeData *mimeData = new QMimeData;
|
auto mimeData = new QMimeData;
|
||||||
|
|
||||||
QString text = plainTextFromSelection(cursor);
|
QString text = plainTextFromSelection(cursor);
|
||||||
mimeData->setText(text);
|
mimeData->setText(text);
|
||||||
@@ -7504,7 +7498,7 @@ QMimeData *TextEditorWidget::createMimeDataFromSelection() const
|
|||||||
// Copy the selected text as HTML
|
// Copy the selected text as HTML
|
||||||
{
|
{
|
||||||
// Create a new document from the selected text document fragment
|
// Create a new document from the selected text document fragment
|
||||||
QTextDocument *tempDocument = new QTextDocument;
|
auto tempDocument = new QTextDocument;
|
||||||
QTextCursor tempCursor(tempDocument);
|
QTextCursor tempCursor(tempDocument);
|
||||||
tempCursor.insertFragment(cursor.selection());
|
tempCursor.insertFragment(cursor.selection());
|
||||||
|
|
||||||
@@ -7578,7 +7572,7 @@ QMimeData *TextEditorWidget::createMimeDataFromSelection() const
|
|||||||
}
|
}
|
||||||
return mimeData;
|
return mimeData;
|
||||||
}
|
}
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextEditorWidget::canInsertFromMimeData(const QMimeData *source) const
|
bool TextEditorWidget::canInsertFromMimeData(const QMimeData *source) const
|
||||||
@@ -7671,7 +7665,7 @@ QMimeData *TextEditorWidget::duplicateMimeData(const QMimeData *source)
|
|||||||
{
|
{
|
||||||
Q_ASSERT(source);
|
Q_ASSERT(source);
|
||||||
|
|
||||||
QMimeData *mimeData = new QMimeData;
|
auto mimeData = new QMimeData;
|
||||||
mimeData->setText(source->text());
|
mimeData->setText(source->text());
|
||||||
mimeData->setHtml(source->html());
|
mimeData->setHtml(source->html());
|
||||||
if (source->hasFormat(QLatin1String(kTextBlockMimeType))) {
|
if (source->hasFormat(QLatin1String(kTextBlockMimeType))) {
|
||||||
@@ -7713,7 +7707,7 @@ bool TextEditorWidget::replacementVisible(int blockNumber) const
|
|||||||
QColor TextEditorWidget::replacementPenColor(int blockNumber) const
|
QColor TextEditorWidget::replacementPenColor(int blockNumber) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(blockNumber)
|
Q_UNUSED(blockNumber)
|
||||||
return QColor();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorWidget::setupFallBackEditor(Id id)
|
void TextEditorWidget::setupFallBackEditor(Id id)
|
||||||
@@ -7793,7 +7787,7 @@ QAction * TextEditorWidget::insertExtraToolBarWidget(TextEditorWidget::Side side
|
|||||||
if (widget->sizePolicy().horizontalPolicy() & QSizePolicy::ExpandFlag) {
|
if (widget->sizePolicy().horizontalPolicy() & QSizePolicy::ExpandFlag) {
|
||||||
if (d->m_stretchWidget)
|
if (d->m_stretchWidget)
|
||||||
d->m_stretchWidget->deleteLater();
|
d->m_stretchWidget->deleteLater();
|
||||||
d->m_stretchWidget = 0;
|
d->m_stretchWidget = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (side == Right)
|
if (side == Right)
|
||||||
@@ -8304,7 +8298,7 @@ BaseTextEditor *BaseTextEditor::currentTextEditor()
|
|||||||
|
|
||||||
TextEditorWidget *BaseTextEditor::editorWidget() const
|
TextEditorWidget *BaseTextEditor::editorWidget() const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(qobject_cast<TextEditorWidget *>(m_widget.data()), return 0);
|
QTC_ASSERT(qobject_cast<TextEditorWidget *>(m_widget.data()), return nullptr);
|
||||||
return static_cast<TextEditorWidget *>(m_widget.data());
|
return static_cast<TextEditorWidget *>(m_widget.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8340,7 +8334,7 @@ QString TextEditorWidget::textAt(int from, int to) const
|
|||||||
|
|
||||||
void TextEditorWidget::configureGenericHighlighter()
|
void TextEditorWidget::configureGenericHighlighter()
|
||||||
{
|
{
|
||||||
Highlighter *highlighter = new Highlighter();
|
auto highlighter = new Highlighter();
|
||||||
highlighter->setTabSettings(textDocument()->tabSettings());
|
highlighter->setTabSettings(textDocument()->tabSettings());
|
||||||
textDocument()->setSyntaxHighlighter(highlighter);
|
textDocument()->setSyntaxHighlighter(highlighter);
|
||||||
|
|
||||||
@@ -8656,6 +8650,7 @@ BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentP
|
|||||||
|
|
||||||
QObject::connect(widget,
|
QObject::connect(widget,
|
||||||
&TextEditorWidget::activateEditor,
|
&TextEditorWidget::activateEditor,
|
||||||
|
widget,
|
||||||
[editor](EditorManager::OpenEditorFlags flags) {
|
[editor](EditorManager::OpenEditorFlags flags) {
|
||||||
EditorManager::activateEditor(editor, flags);
|
EditorManager::activateEditor(editor, flags);
|
||||||
});
|
});
|
||||||
@@ -8675,7 +8670,7 @@ IEditor *BaseTextEditor::duplicate()
|
|||||||
|
|
||||||
// If neither is sufficient, you need to implement 'YourEditor::duplicate'.
|
// If neither is sufficient, you need to implement 'YourEditor::duplicate'.
|
||||||
QTC_CHECK(false);
|
QTC_CHECK(false);
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
@@ -65,7 +65,7 @@ class AssistInterface;
|
|||||||
class IAssistProvider;
|
class IAssistProvider;
|
||||||
class ICodeStylePreferences;
|
class ICodeStylePreferences;
|
||||||
class CompletionAssistProvider;
|
class CompletionAssistProvider;
|
||||||
typedef QList<RefactorMarker> RefactorMarkers;
|
using RefactorMarkers = QList<RefactorMarker>;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
class BaseTextEditorPrivate;
|
class BaseTextEditorPrivate;
|
||||||
@@ -103,7 +103,7 @@ class TEXTEDITOR_EXPORT BaseTextEditor : public Core::IEditor
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
BaseTextEditor();
|
BaseTextEditor();
|
||||||
~BaseTextEditor();
|
~BaseTextEditor() override;
|
||||||
|
|
||||||
virtual void finalizeInitialization() {}
|
virtual void finalizeInitialization() {}
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ class TEXTEDITOR_EXPORT TextEditorWidget : public QPlainTextEdit
|
|||||||
Q_PROPERTY(int verticalBlockSelectionLastColumn READ verticalBlockSelectionLastColumn)
|
Q_PROPERTY(int verticalBlockSelectionLastColumn READ verticalBlockSelectionLastColumn)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextEditorWidget(QWidget *parent = 0);
|
TextEditorWidget(QWidget *parent = nullptr);
|
||||||
~TextEditorWidget() override;
|
~TextEditorWidget() override;
|
||||||
|
|
||||||
void setTextDocument(const QSharedPointer<TextDocument> &doc);
|
void setTextDocument(const QSharedPointer<TextDocument> &doc);
|
||||||
@@ -273,7 +273,7 @@ public:
|
|||||||
|
|
||||||
QPoint toolTipPosition(const QTextCursor &c) const;
|
QPoint toolTipPosition(const QTextCursor &c) const;
|
||||||
|
|
||||||
void invokeAssist(AssistKind assistKind, IAssistProvider *provider = 0);
|
void invokeAssist(AssistKind assistKind, IAssistProvider *provider = nullptr);
|
||||||
|
|
||||||
virtual TextEditor::AssistInterface *createAssistInterface(AssistKind assistKind,
|
virtual TextEditor::AssistInterface *createAssistInterface(AssistKind assistKind,
|
||||||
AssistReason assistReason) const;
|
AssistReason assistReason) const;
|
||||||
@@ -284,7 +284,7 @@ public:
|
|||||||
void insertPlainText(const QString &text);
|
void insertPlainText(const QString &text);
|
||||||
|
|
||||||
QWidget *extraArea() const;
|
QWidget *extraArea() const;
|
||||||
virtual int extraAreaWidth(int *markWidthPtr = 0) const;
|
virtual int extraAreaWidth(int *markWidthPtr = nullptr) const;
|
||||||
virtual void extraAreaPaintEvent(QPaintEvent *);
|
virtual void extraAreaPaintEvent(QPaintEvent *);
|
||||||
virtual void extraAreaLeaveEvent(QEvent *);
|
virtual void extraAreaLeaveEvent(QEvent *);
|
||||||
virtual void extraAreaContextMenuEvent(QContextMenuEvent *);
|
virtual void extraAreaContextMenuEvent(QContextMenuEvent *);
|
||||||
@@ -573,7 +573,7 @@ signals:
|
|||||||
void tooltipOverrideRequested(TextEditor::TextEditorWidget *widget,
|
void tooltipOverrideRequested(TextEditor::TextEditorWidget *widget,
|
||||||
const QPoint &globalPos, int position, bool *handled);
|
const QPoint &globalPos, int position, bool *handled);
|
||||||
void tooltipRequested(const QPoint &globalPos, int position);
|
void tooltipRequested(const QPoint &globalPos, int position);
|
||||||
void activateEditor(Core::EditorManager::OpenEditorFlags flags = 0);
|
void activateEditor(Core::EditorManager::OpenEditorFlags flags = nullptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void slotCursorPositionChanged(); // Used in VcsBase
|
virtual void slotCursorPositionChanged(); // Used in VcsBase
|
||||||
@@ -595,15 +595,15 @@ private:
|
|||||||
class TEXTEDITOR_EXPORT TextEditorLinkLabel : public QLabel
|
class TEXTEDITOR_EXPORT TextEditorLinkLabel : public QLabel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TextEditorLinkLabel(QWidget *parent = 0);
|
TextEditorLinkLabel(QWidget *parent = nullptr);
|
||||||
|
|
||||||
void setLink(Utils::Link link);
|
void setLink(Utils::Link link);
|
||||||
Utils::Link link() const;
|
Utils::Link link() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
void mouseReleaseEvent(QMouseEvent *event);
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPoint m_dragStartPosition;
|
QPoint m_dragStartPosition;
|
||||||
@@ -615,15 +615,15 @@ class TEXTEDITOR_EXPORT TextEditorFactory : public Core::IEditorFactory
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextEditorFactory(QObject *parent = 0);
|
TextEditorFactory(QObject *parent = nullptr);
|
||||||
~TextEditorFactory();
|
~TextEditorFactory() override;
|
||||||
|
|
||||||
typedef std::function<BaseTextEditor *()> EditorCreator;
|
using EditorCreator = std::function<BaseTextEditor *()>;
|
||||||
typedef std::function<TextDocument *()> DocumentCreator;
|
using DocumentCreator = std::function<TextDocument *()>;
|
||||||
typedef std::function<TextEditorWidget *()> EditorWidgetCreator;
|
using EditorWidgetCreator = std::function<TextEditorWidget *()>;
|
||||||
typedef std::function<SyntaxHighlighter *()> SyntaxHighLighterCreator;
|
using SyntaxHighLighterCreator = std::function<SyntaxHighlighter *()>;
|
||||||
typedef std::function<Indenter *()> IndenterCreator;
|
using IndenterCreator = std::function<Indenter *()>;
|
||||||
typedef std::function<AutoCompleter *()> AutoCompleterCreator;
|
using AutoCompleterCreator = std::function<AutoCompleter *()>;
|
||||||
|
|
||||||
void setDocumentCreator(const DocumentCreator &creator);
|
void setDocumentCreator(const DocumentCreator &creator);
|
||||||
void setEditorWidgetCreator(const EditorWidgetCreator &creator);
|
void setEditorWidgetCreator(const EditorWidgetCreator &creator);
|
||||||
|
Reference in New Issue
Block a user