Skip to content

Commit a8b0954

Browse files
shiboken6/Documentation: Nest inner classes' pages into outer classes
Referencing inner classes like QByteArray::FromBase64Result did not properly work due to the inner classes being generated to separate documentation pages. Change this such that inner classes are nested into the documentation of the outer class. The problem though is that this causes excessively long pages for Qt modules with namespaces like Qt3D/QtDataVisualization (all deprecated). For them, a type system attribute is added to keep the old behavior. Pick-to: 6.8 Task-number: PYSIDE-1106 Change-Id: I51330afa739027c28930af3902b83b1e762b92ef Reviewed-by: Cristian Maureira-Fredes <[email protected]>
1 parent 19926ab commit a8b0954

13 files changed

+98
-11
lines changed

sources/pyside6/PySide6/Qt3DCore/typesystem_3dcore.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
55
-->
66

7-
<typesystem package="PySide6.Qt3DCore" doc-package="PySide6.Qt3D"
7+
<typesystem package="PySide6.Qt3DCore" doc-package="PySide6.Qt3D" doc-mode="flat"
88
namespace-begin="QT_BEGIN_NAMESPACE" namespace-end="QT_END_NAMESPACE">
99
<load-typesystem name="QtGui/typesystem_gui.xml" generate="no"/>
1010
<smart-pointer-type name="QSharedPointer" type="shared" getter="data"

sources/pyside6/PySide6/Qt3DExtras/typesystem_3dextras.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
55
-->
66

7-
<typesystem package="PySide6.Qt3DExtras" doc-package="PySide6.Qt3D"
7+
<typesystem package="PySide6.Qt3DExtras" doc-package="PySide6.Qt3D" doc-mode="flat"
88
namespace-begin="QT_BEGIN_NAMESPACE" namespace-end="QT_END_NAMESPACE">
99
<load-typesystem name="Qt3DRender/typesystem_3drender.xml" generate="no"/>
1010
<namespace-type name="Qt3DExtras">

sources/pyside6/PySide6/Qt3DInput/typesystem_3dinput.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
55
-->
66

7-
<typesystem package="PySide6.Qt3DInput" doc-package="PySide6.Qt3D"
7+
<typesystem package="PySide6.Qt3DInput" doc-package="PySide6.Qt3D" doc-mode="flat"
88
namespace-begin="QT_BEGIN_NAMESPACE" namespace-end="QT_END_NAMESPACE">
99
<load-typesystem name="Qt3DCore/typesystem_3dcore.xml" generate="no"/>
1010
<namespace-type name="Qt3DInput">

sources/pyside6/PySide6/Qt3DLogic/typesystem_3dlogic.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
55
-->
66

7-
<typesystem package="PySide6.Qt3DLogic" doc-package="PySide6.Qt3D"
7+
<typesystem package="PySide6.Qt3DLogic" doc-package="PySide6.Qt3D" doc-mode="flat"
88
namespace-begin="QT_BEGIN_NAMESPACE" namespace-end="QT_END_NAMESPACE">
99
<load-typesystem name="Qt3DCore/typesystem_3dcore.xml" generate="no"/>
1010
<namespace-type name="Qt3DLogic">

sources/pyside6/PySide6/Qt3DRender/typesystem_3drender.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
55
-->
66

7-
<typesystem package="PySide6.Qt3DRender" doc-package="PySide6.Qt3D"
7+
<typesystem package="PySide6.Qt3DRender" doc-package="PySide6.Qt3D" doc-mode="flat"
88
namespace-begin="QT_BEGIN_NAMESPACE" namespace-end="QT_END_NAMESPACE">
99
<load-typesystem name="Qt3DCore/typesystem_3dcore.xml" generate="no"/>
1010
<load-typesystem name="QtGui/typesystem_gui.xml" generate="no"/>

sources/pyside6/PySide6/QtDataVisualization/typesystem_datavisualization.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright (C) 2017 The Qt Company Ltd.
44
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
55
-->
6-
<typesystem package="PySide6.QtDataVisualization"
6+
<typesystem package="PySide6.QtDataVisualization" doc-mode="flat"
77
namespace-begin="QT_BEGIN_NAMESPACE" namespace-end="QT_END_NAMESPACE">
88

99
<extra-includes>

sources/shiboken6/ApiExtractor/typesystem.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ class TypeSystemTypeEntryPrivate : public TypeEntryPrivate
670670
QString m_namespaceBegin;
671671
QString m_namespaceEnd;
672672
QString m_docTargetLangPackage;
673+
TypeSystem::DocMode m_docMode = TypeSystem::DocMode::Nested;
673674
};
674675

675676
TypeSystemTypeEntry::TypeSystemTypeEntry(const QString &entryName, const QVersionNumber &vr,
@@ -737,6 +738,18 @@ void TypeSystemTypeEntry::setDocTargetLangPackage(const QString &p)
737738
d->m_docTargetLangPackage = p;
738739
}
739740

741+
TypeSystem::DocMode TypeSystemTypeEntry::docMode() const
742+
{
743+
S_D(const TypeSystemTypeEntry);
744+
return d->m_docMode;
745+
}
746+
747+
void TypeSystemTypeEntry::setDocMode(TypeSystem::DocMode m)
748+
{
749+
S_D(TypeSystemTypeEntry);
750+
d->m_docMode = m;
751+
}
752+
740753
const QString &TypeSystemTypeEntry::namespaceBegin() const
741754
{
742755
S_D(const TypeSystemTypeEntry);

sources/shiboken6/ApiExtractor/typesystem_enums.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ enum DocModificationMode {
4646
DocModificationXPathReplace
4747
};
4848

49+
enum class DocMode {
50+
Nested,
51+
Flat
52+
};
53+
4954
enum class ExceptionHandling {
5055
Unspecified,
5156
Off,

sources/shiboken6/ApiExtractor/typesystemparser.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ constexpr auto overloadNumberAttribute = "overload-number"_L1;
8989
constexpr auto ownershipAttribute = "owner"_L1;
9090
constexpr auto packageAttribute = "package"_L1;
9191
constexpr auto docPackageAttribute = "doc-package"_L1;
92+
constexpr auto docModeAttribute = "doc-mode"_L1;
9293
constexpr auto polymorphicBaseAttribute = "polymorphic-base"_L1;
9394
constexpr auto positionAttribute = "position"_L1;
9495
constexpr auto preferredConversionAttribute = "preferred-conversion"_L1;
@@ -259,6 +260,14 @@ ENUM_LOOKUP_BEGIN(TypeSystem::PythonEnumType, Qt::CaseSensitive,
259260
};
260261
ENUM_LOOKUP_LINEAR_SEARCH
261262

263+
ENUM_LOOKUP_BEGIN(TypeSystem::DocMode, Qt::CaseSensitive,
264+
docModeFromAttribute)
265+
{
266+
{u"nested", TypeSystem::DocMode::Nested},
267+
{u"flat", TypeSystem::DocMode::Flat},
268+
};
269+
ENUM_LOOKUP_LINEAR_SEARCH
270+
262271
ENUM_LOOKUP_BEGIN(TypeSystem::QtMetaTypeRegistration, Qt::CaseSensitive,
263272
qtMetaTypeFromAttribute)
264273
{
@@ -2096,13 +2105,21 @@ TypeSystemTypeEntryPtr TypeSystemParser::parseRootElement(const ConditionalStrea
20962105
QString namespaceBegin;
20972106
QString namespaceEnd;
20982107
QString docPackage;
2108+
std::optional<TypeSystem::DocMode> docModeOpt;
20992109

21002110
for (auto i = attributes->size() - 1; i >= 0; --i) {
21012111
const auto name = attributes->at(i).qualifiedName();
21022112
if (name == packageAttribute) {
21032113
m_defaultPackage = attributes->takeAt(i).value().toString();
21042114
} else if (name == docPackageAttribute) {
21052115
docPackage = attributes->takeAt(i).value().toString();
2116+
} else if (name == docModeAttribute) {
2117+
const auto attribute = attributes->takeAt(i);
2118+
docModeOpt = docModeFromAttribute(attribute.value());
2119+
if (!docModeOpt.has_value()) {
2120+
qCWarning(lcShiboken, "%s",
2121+
qPrintable(msgInvalidAttributeValue(attribute)));
2122+
}
21062123
} else if (name == defaultSuperclassAttribute) {
21072124
m_defaultSuperclass = attributes->takeAt(i).value().toString();
21082125
} else if (name == exceptionHandlingAttribute) {
@@ -2158,6 +2175,8 @@ TypeSystemTypeEntryPtr TypeSystemParser::parseRootElement(const ConditionalStrea
21582175
}
21592176
if (!docPackage.isEmpty())
21602177
moduleEntry->setDocTargetLangPackage(docPackage);
2178+
if (docModeOpt.has_value())
2179+
moduleEntry->setDocMode(docModeOpt.value());
21612180
moduleEntry->setCodeGeneration(m_generate);
21622181
moduleEntry->setSnakeCase(snakeCase);
21632182
if (!namespaceBegin.isEmpty())

sources/shiboken6/ApiExtractor/typesystemtypeentry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class TypeSystemTypeEntry : public TypeEntry
3030
bool hasDocTargetLangPackage() const;
3131
QString docTargetLangPackage() const;
3232
void setDocTargetLangPackage(const QString &p);
33+
TypeSystem::DocMode docMode() const;
34+
void setDocMode(TypeSystem::DocMode m);
3335

3436
const QString &namespaceBegin() const;
3537
void setNamespaceBegin(const QString &n);

sources/shiboken6/doc/typesystem_specifying_types.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ It can have a number of attributes, described below.
5050
snake-case="yes | no | both"
5151
namespace-begin="..."
5252
namespace-end="..."
53-
doc-package="..." >
53+
doc-package="..."
54+
doc-mode = "nested | flat" >
5455
</typesystem>
5556
5657
The **package** attribute is a string describing the package to be used,
@@ -93,6 +94,12 @@ files for the documentation generation. It is mainly relevant for Qt where for
9394
example the documentation of the ``QtMultimediaWidgets`` module is generated
9495
into the ``QtMultimedia`` module.
9596

97+
The *optional* attribute **doc-mode** determines whether to nest the
98+
documentation of inner classes into the outer classes' pages. Its default value
99+
is **nested**. It is possible to turn this off by specifying **flat** in case
100+
too many classes are cointained in a namespace, causing excessively long pages.
101+
However, the referencing may then not fully work.
102+
96103
.. _load-typesystem:
97104

98105
load-typesystem

sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <complextypeentry.h>
2929
#include <flagstypeentry.h>
3030
#include <primitivetypeentry.h>
31+
#include <typesystemtypeentry.h>
3132
#include <qtdocparser.h>
3233
#include <doxygenparser.h>
3334

@@ -430,13 +431,48 @@ void QtDocGenerator::generateClass(TextStream &s, const QString &targetDir,
430431
const GeneratorContext &classContext,
431432
QList<GeneratorContext> *contexts)
432433
{
433-
Q_UNUSED(targetDir)
434-
Q_UNUSED(contexts)
435-
AbstractMetaClassCPtr metaClass = classContext.metaClass();
436-
qCDebug(lcShibokenDoc).noquote().nospace() << "Generating Documentation for " << metaClass->fullName();
434+
generateClassRecursion(s, targetDir, classContext, contexts);
435+
}
436+
437+
static inline TypeSystem::DocMode classDocMode(const AbstractMetaClassCPtr &metaClass)
438+
{
439+
return typeSystemTypeEntry(metaClass->typeEntry())->docMode();
440+
}
441+
442+
void QtDocGenerator::generateClassRecursion(TextStream &s, const QString &targetDir,
443+
const GeneratorContext &classContext,
444+
QList<GeneratorContext> *contexts)
445+
{
446+
const AbstractMetaClassCPtr &metaClass = classContext.metaClass();
447+
448+
qCDebug(lcShibokenDoc, "Generating Documentation for %s", qPrintable(metaClass->fullName()));
437449

438450
m_packages[metaClass->package()].classPages << fileNameForContext(classContext);
439451

452+
doGenerateClass(s, targetDir, metaClass);
453+
454+
if (classDocMode(metaClass) == TypeSystem::DocMode::Nested) {
455+
QList<GeneratorContext> innerContexts;
456+
for (qsizetype i = 0; i < contexts->size(); ) {
457+
if (contexts->at(i).metaClass()->targetLangEnclosingClass() == metaClass)
458+
innerContexts.append(contexts->takeAt(i));
459+
else
460+
++i;
461+
}
462+
if (!innerContexts.isEmpty()) {
463+
s << indent;
464+
for (const auto &innerClassContext : std::as_const(innerContexts))
465+
generateClassRecursion(s, targetDir, innerClassContext, contexts);
466+
s << outdent;
467+
}
468+
}
469+
}
470+
471+
void QtDocGenerator::doGenerateClass(TextStream &s, const QString &targetDir,
472+
const AbstractMetaClassCPtr &metaClass)
473+
{
474+
qCDebug(lcShibokenDoc).noquote().nospace() << "Generating Documentation for " << metaClass->fullName();
475+
440476
m_docParser->setPackageName(metaClass->package());
441477
const QString sourceFile =
442478
m_docParser->fillDocumentation(std::const_pointer_cast<AbstractMetaClass>(metaClass));

sources/shiboken6/generator/qtdoc/qtdocgenerator.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ class QtDocGenerator : public Generator, public QtXmlToSphinxDocGeneratorInterfa
6464
bool finishGeneration() override;
6565

6666
private:
67+
void generateClassRecursion(TextStream &s, const QString &targetDir,
68+
const GeneratorContext &classContext,
69+
QList<GeneratorContext> *contexts);
70+
void doGenerateClass(TextStream &ts, const QString &targetDir,
71+
const AbstractMetaClassCPtr &metaClass);
6772
void writeEnums(TextStream &s, const AbstractMetaEnumList &enums,
6873
const QString &scope, QtXmlToSphinxImages *images) const;
6974

0 commit comments

Comments
 (0)