diff options
Diffstat (limited to 'sources/shiboken6/generator/qtdoc/qtxmltosphinx.h')
-rw-r--r-- | sources/shiboken6/generator/qtdoc/qtxmltosphinx.h | 108 |
1 files changed, 58 insertions, 50 deletions
diff --git a/sources/shiboken6/generator/qtdoc/qtxmltosphinx.h b/sources/shiboken6/generator/qtdoc/qtxmltosphinx.h index 5c3a90be5..398c5bc97 100644 --- a/sources/shiboken6/generator/qtdoc/qtxmltosphinx.h +++ b/sources/shiboken6/generator/qtdoc/qtxmltosphinx.h @@ -1,48 +1,25 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** 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-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef QTXMLTOSPHINX_H #define QTXMLTOSPHINX_H #include <textstream.h> -#include <QtCore/QHash> #include <QtCore/QList> #include <QtCore/QScopedPointer> #include <QtCore/QStack> -#include <QtCore/QTextStream> + +#include <memory> QT_BEGIN_NAMESPACE +class QDebug; class QXmlStreamReader; QT_END_NAMESPACE class QtXmlToSphinxDocGeneratorInterface; struct QtXmlToSphinxParameters; +struct QtXmlToSphinxLink; enum class WebXmlTag; @@ -51,8 +28,6 @@ class QtXmlToSphinx public: Q_DISABLE_COPY_MOVE(QtXmlToSphinx) - struct LinkContext; - struct InlineImage { QString tag; @@ -66,7 +41,7 @@ public: QString data; TableCell(const QString& text = QString()) : data(text) {} - TableCell(const char* text) : data(QLatin1String(text)) {} + TableCell(const char* text) : data(QString::fromLatin1(text)) {} }; using TableRow = QList<TableCell>; @@ -95,20 +70,19 @@ public: return m_normalized; } - void clear() { - m_normalized = false; - m_rows.clear(); - } - void appendRow(const TableRow &row) { m_rows.append(row); } - const TableRow &constFirst() { return m_rows.constFirst(); } + const TableRow &constFirst() const { return m_rows.constFirst(); } TableRow &first() { return m_rows.first(); } TableRow &last() { return m_rows.last(); } void format(TextStream& s) const; + void formatDebug(QDebug &debug) const; private: + bool hasEmptyLeadingRow() const; + bool hasEmptyTrailingRow() const; + QList<TableRow> m_rows; bool m_hasHeader = false; bool m_normalized = false; @@ -127,11 +101,20 @@ public: static void stripPythonQualifiers(QString *s); + // For testing + static QString readSnippet(QIODevice &inputFile, const QString &identifier, + QString *errorMessage); + private: + using StringSharedPtr = std::shared_ptr<QString>; + QString transform(const QString& doc); void handleHeadingTag(QXmlStreamReader& reader); void handleParaTag(QXmlStreamReader& reader); + void handleParaTagStart(); + void handleParaTagText(QXmlStreamReader &reader); + void handleParaTagEnd(); void handleItalicTag(QXmlStreamReader& reader); void handleBoldTag(QXmlStreamReader& reader); void handleArgumentTag(QXmlStreamReader& reader); @@ -149,6 +132,7 @@ private: // table tagsvoid QtXmlToSphinx::handleValueTag(QXmlStreamReader& reader) void handleTableTag(QXmlStreamReader& reader); + void handleHeaderTag(QXmlStreamReader& reader); void handleRowTag(QXmlStreamReader& reader); void handleItemTag(QXmlStreamReader& reader); void handleRawTag(QXmlStreamReader& reader); @@ -162,9 +146,10 @@ private: void handleAnchorTag(QXmlStreamReader& reader); void handleRstPassTroughTag(QXmlStreamReader& reader); - LinkContext *handleLinkStart(const QString &type, QString ref) const; - static void handleLinkText(LinkContext *linkContext, const QString &linktext) ; - void handleLinkEnd(LinkContext *linkContext); + QtXmlToSphinxLink *handleLinkStart(const QString &type, QString ref) const; + static void handleLinkText(QtXmlToSphinxLink *linkContext, const QString &linktext) ; + void handleLinkEnd(QtXmlToSphinxLink *linkContext); + WebXmlTag parentTag() const; void warn(const QString &message) const; void debug(const QString &message) const; @@ -173,23 +158,42 @@ private: TextStream m_output; QString m_result; - QStack<QString*> m_buffers; + QStack<StringSharedPtr> m_buffers; // Maintain address stability since it used in TextStream - Table m_currentTable; - QScopedPointer<LinkContext> m_linkContext; // for <link> - QScopedPointer<LinkContext> m_seeAlsoContext; // for <see-also>foo()</see-also> - bool m_tableHasHeader; + QStack<Table> m_tables; // Stack of tables, used for <table><list> with nested <item> + QScopedPointer<QtXmlToSphinxLink> m_linkContext; // for <link> + QScopedPointer<QtXmlToSphinxLink> m_seeAlsoContext; // for <see-also>foo()</see-also> QString m_context; const QtXmlToSphinxDocGeneratorInterface *m_generator; const QtXmlToSphinxParameters &m_parameters; - bool m_insideBold; - bool m_insideItalic; + int m_formattingDepth = 0; + bool m_insideBold = false; + bool m_insideItalic = false; QString m_lastTagName; QString m_opened_anchor; QList<InlineImage> m_inlineImages; - QString readFromLocations(const QStringList &locations, const QString &path, - const QString &identifier, QString *errorMessage); + bool m_containsAutoTranslations = false; + + struct Snippet + { + enum Result { + Converted, // C++ converted to Python + Resolved, // Otherwise resolved in snippet paths + Fallback, // Fallback from XML + Error + }; + + QString code; + Result result; + }; + + void setAutoTranslatedNote(QString *str) const; + + Snippet readSnippetFromLocations(const QString &path, + const QString &identifier, + const QString &fallbackPath, + QString *errorMessage); static QString readFromLocation(const QString &location, const QString &identifier, QString *errorMessage); void pushOutputBuffer(); @@ -205,4 +209,8 @@ inline TextStream& operator<<(TextStream& s, const QtXmlToSphinx& xmlToSphinx) return s << xmlToSphinx.result(); } +QDebug operator<<(QDebug d, const QtXmlToSphinxLink &l); +QDebug operator<<(QDebug debug, const QtXmlToSphinx::Table &t); +QDebug operator<<(QDebug debug, const QtXmlToSphinx::TableCell &c); + #endif // QTXMLTOSPHINX_H |