diff options
Diffstat (limited to 'src/gui/text/qtextdocument_p.cpp')
-rw-r--r-- | src/gui/text/qtextdocument_p.cpp | 87 |
1 files changed, 33 insertions, 54 deletions
diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index 1f2e8d2da2..3c1fc04d4b 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include <private/qtools_p.h> #include <qdebug.h> @@ -52,7 +16,6 @@ #include "qtextdocumentlayout_p.h" #include "qtexttable.h" #include "qtextengine_p.h" -#include "qurlresourceprovider.h" #include <stdlib.h> @@ -60,7 +23,7 @@ QT_BEGIN_NAMESPACE #define PMDEBUG if(0) qDebug -// The VxWorks DIAB compiler crashes when initializing the anonymouse union with { a7 } +// The VxWorks DIAB compiler crashes when initializing the anonymous union with { a7 } #if !defined(Q_CC_DIAB) # define QT_INIT_TEXTUNDOCOMMAND(c, a1, a2, a3, a4, a5, a6, a7, a8) \ QTextUndoCommand c = { a1, a2, 0, 0, quint8(a3), a4, quint32(a5), quint32(a6), { int(a7) }, quint32(a8) } @@ -188,7 +151,8 @@ QTextDocumentPrivate::QTextDocumentPrivate() framesDirty(true), rtFrame(nullptr), initialBlockCharFormatIndex(-1), // set correctly later in init() - resourceProvider(nullptr) + resourceProvider(nullptr), + cssMedia(QStringLiteral("screen")) { editBlock = 0; editBlockCursorPosition = -1; @@ -238,7 +202,7 @@ void QTextDocumentPrivate::clear() { Q_Q(QTextDocument); - for (QTextCursorPrivate *curs : qAsConst(cursors)) { + for (QTextCursorPrivate *curs : std::as_const(cursors)) { curs->setPosition(0); curs->currentCharFormat = -1; curs->anchor = 0; @@ -291,7 +255,7 @@ void QTextDocumentPrivate::clear() QTextDocumentPrivate::~QTextDocumentPrivate() { - for (QTextCursorPrivate *curs : qAsConst(cursors)) + for (QTextCursorPrivate *curs : std::as_const(cursors)) curs->priv = nullptr; cursors.clear(); undoState = 0; @@ -383,8 +347,13 @@ int QTextDocumentPrivate::insert_block(int pos, uint strPos, int format, int blo Q_ASSERT(blocks.length() == fragments.length()); QTextBlockGroup *group = qobject_cast<QTextBlockGroup *>(objectForFormat(blockFormat)); - if (group) + if (group) { group->blockInserted(QTextBlock(this, b)); + if (command != QTextUndoCommand::BlockDeleted) { + docChangeOldLength--; + docChangeLength--; + } + } QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(formats.format(format))); if (frame) { @@ -406,7 +375,7 @@ int QTextDocumentPrivate::insertBlock(QChar blockSeparator, beginEditBlock(); - int strPos = text.length(); + int strPos = text.size(); text.append(blockSeparator); int ob = blocks.findNode(pos); @@ -476,16 +445,16 @@ void QTextDocumentPrivate::insert(int pos, int strPos, int strLength, int format finishEdit(); } -void QTextDocumentPrivate::insert(int pos, const QString &str, int format) +void QTextDocumentPrivate::insert(int pos, QStringView str, int format) { if (str.size() == 0) return; Q_ASSERT(noBlockInString(str)); - int strPos = text.length(); + int strPos = text.size(); text.append(str); - insert(pos, strPos, str.length(), format); + insert(pos, strPos, str.size(), format); } int QTextDocumentPrivate::remove_string(int pos, uint length, QTextUndoCommand::Operation op) @@ -679,7 +648,7 @@ void QTextDocumentPrivate::remove(int pos, int length, QTextUndoCommand::Operati blockCursorAdjustment = true; move(pos, -1, length, op); blockCursorAdjustment = false; - for (QTextCursorPrivate *curs : qAsConst(cursors)) { + for (QTextCursorPrivate *curs : std::as_const(cursors)) { if (curs->adjustPosition(pos, -length, op) == QTextCursorPrivate::CursorMoved) { curs->changed = true; } @@ -1237,13 +1206,13 @@ void QTextDocumentPrivate::finishEdit() } QList<QTextCursor> changedCursors; - for (QTextCursorPrivate *curs : qAsConst(cursors)) { + for (QTextCursorPrivate *curs : std::as_const(cursors)) { if (curs->changed) { curs->changed = false; changedCursors.append(QTextCursor(curs)); } } - for (const QTextCursor &cursor : qAsConst(changedCursors)) + for (const QTextCursor &cursor : std::as_const(changedCursors)) emit q->cursorPositionChanged(cursor); contentsChanged(); @@ -1289,7 +1258,7 @@ void QTextDocumentPrivate::adjustDocumentChangesAndCursors(int from, int addedOr if (blockCursorAdjustment) { ; // postpone, will be called again from QTextDocumentPrivate::remove() } else { - for (QTextCursorPrivate *curs : qAsConst(cursors)) { + for (QTextCursorPrivate *curs : std::as_const(cursors)) { if (curs->adjustPosition(from, addedOrRemoved, op) == QTextCursorPrivate::CursorMoved) { curs->changed = true; } @@ -1452,6 +1421,16 @@ QTextFrame *QTextDocumentPrivate::rootFrame() const return rtFrame; } +void QTextDocumentPrivate::addCursor(QTextCursorPrivate *c) +{ + cursors.insert(c); +} + +void QTextDocumentPrivate::removeCursor(QTextCursorPrivate *c) +{ + cursors.remove(c); +} + QTextFrame *QTextDocumentPrivate::frameAt(int pos) const { QTextFrame *f = rootFrame(); @@ -1466,7 +1445,7 @@ QTextFrame *QTextDocumentPrivate::frameAt(int pos) const void QTextDocumentPrivate::clearFrame(QTextFrame *f) { - for (int i = 0; i < f->d_func()->childFrames.count(); ++i) + for (int i = 0; i < f->d_func()->childFrames.size(); ++i) clearFrame(f->d_func()->childFrames.at(i)); f->d_func()->childFrames.clear(); f->d_func()->parentFrame = nullptr; @@ -1736,7 +1715,7 @@ bool QTextDocumentPrivate::ensureMaximumBlockCount() void QTextDocumentPrivate::aboutToRemoveCell(int from, int to) { Q_ASSERT(from <= to); - for (QTextCursorPrivate *curs : qAsConst(cursors)) + for (QTextCursorPrivate *curs : std::as_const(cursors)) curs->aboutToRemoveCell(from, to); } |