diff options
Diffstat (limited to 'src/gui/text/qtexthtmlparser_p.h')
-rw-r--r-- | src/gui/text/qtexthtmlparser_p.h | 91 |
1 files changed, 35 insertions, 56 deletions
diff --git a/src/gui/text/qtexthtmlparser_p.h b/src/gui/text/qtexthtmlparser_p.h index 31f558709f..dd52baa23e 100644 --- a/src/gui/text/qtexthtmlparser_p.h +++ b/src/gui/text/qtexthtmlparser_p.h @@ -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 #ifndef QTEXTHTMLPARSER_P_H #define QTEXTHTMLPARSER_P_H @@ -52,15 +16,19 @@ // #include <QtGui/private/qtguiglobal_p.h> -#include "QtCore/qvector.h" #include "QtGui/qbrush.h" #include "QtGui/qcolor.h" #include "QtGui/qfont.h" #include "QtGui/qtextdocument.h" #include "QtGui/qtextcursor.h" + +#include "QtCore/qlist.h" + #include "private/qtextformat_p.h" #include "private/qtextdocument_p.h" +#if QT_CONFIG(cssparser) #include "private/qcssparser_p.h" +#endif #ifndef QT_NO_TEXTHTMLPARSER @@ -167,7 +135,7 @@ struct QTextHtmlParserNode { QString text; QStringList attributes; int parent; - QVector<int> children; + QList<int> children; QTextHTMLElements id; QTextCharFormat charFormat; QTextBlockFormat blockFormat; @@ -182,6 +150,7 @@ struct QTextHtmlParserNode { uint displayMode : 3; // QTextHtmlElement::DisplayMode uint hasHref : 1; QTextListFormat::Style listStyle; + int listStart = 1; QString textListNumberPrefix; QString textListNumberSuffix; QString imageName; @@ -251,10 +220,11 @@ struct QTextHtmlParserNode { void parseStyleAttribute(const QString &value, const QTextDocument *resourceProvider); #if QT_CONFIG(cssparser) - void applyCssDeclarations(const QVector<QCss::Declaration> &declarations, const QTextDocument *resourceProvider); + void applyCssDeclarations(const QList<QCss::Declaration> &declarations, + const QTextDocument *resourceProvider); - void setListStyle(const QVector<QCss::Value> &cssValues); -#endif + void setListStyle(const QList<QCss::Value> &cssValues); +# endif void applyForegroundImage(qint64 cacheKey, const QTextDocument *resourceProvider); void applyBackgroundImage(const QString &url, const QTextDocument *resourceProvider); @@ -266,7 +236,7 @@ struct QTextHtmlParserNode { friend class QTextHtmlParser; }; -Q_DECLARE_TYPEINFO(QTextHtmlParserNode, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO(QTextHtmlParserNode, Q_RELOCATABLE_TYPE); class QTextHtmlParser @@ -278,11 +248,15 @@ public: MarginBottom, MarginLeft }; + ~QTextHtmlParser() + { + qDeleteAll(nodes); + } - inline const QTextHtmlParserNode &at(int i) const { return nodes.at(i); } - inline QTextHtmlParserNode &operator[](int i) { return nodes[i]; } - inline int count() const { return nodes.count(); } - inline int last() const { return nodes.count()-1; } + inline const QTextHtmlParserNode &at(int i) const { return *nodes.at(i); } + inline QTextHtmlParserNode &operator[](int i) { return *nodes[i]; } + inline int count() const { return nodes.size(); } + inline int last() const { return nodes.size()-1; } int depth(int i) const; int topMargin(int i) const; int bottomMargin(int i) const; @@ -302,10 +276,13 @@ public: void parse(const QString &text, const QTextDocument *resourceProvider); - static int lookupElement(const QString &element); + static int lookupElement(QStringView element); + + Q_GUI_EXPORT static QString parseEntity(QStringView entity); + protected: QTextHtmlParserNode *newNode(int parent); - QVector<QTextHtmlParserNode> nodes; + QList<QTextHtmlParserNode *> nodes; QString txt; int pos, len; @@ -323,14 +300,16 @@ protected: void applyAttributes(const QStringList &attributes); void eatSpace(); inline bool hasPrefix(QChar c, int lookahead = 0) const - {return pos + lookahead < len && txt.at(pos) == c; } + { + return pos + lookahead < len && txt.at(pos + lookahead) == c; + } int margin(int i, int mar) const; bool nodeIsChildOf(int i, QTextHTMLElements id) const; #if QT_CONFIG(cssparser) - QVector<QCss::Declaration> declarationsForNode(int node) const; + QList<QCss::Declaration> declarationsForNode(int node) const; void resolveStyleSheetImports(const QCss::StyleSheet &sheet); void importStyleSheet(const QString &href); @@ -343,14 +322,14 @@ protected: QCss::StyleSheet sheet; }; friend class QTypeInfo<ExternalStyleSheet>; - QVector<ExternalStyleSheet> externalStyleSheets; - QVector<QCss::StyleSheet> inlineStyleSheets; -#endif + QList<ExternalStyleSheet> externalStyleSheets; + QList<QCss::StyleSheet> inlineStyleSheets; +# endif const QTextDocument *resourceProvider; }; #if QT_CONFIG(cssparser) -Q_DECLARE_TYPEINFO(QTextHtmlParser::ExternalStyleSheet, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO(QTextHtmlParser::ExternalStyleSheet, Q_RELOCATABLE_TYPE); #endif QT_END_NAMESPACE |