diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-09-27 10:16:51 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-09-27 23:13:04 +0200 |
| commit | 2ae76e777d7cc8305b515099b24ce5627171b5b9 (patch) | |
| tree | 1c546a7efe73a6835956d68e78f2956a64a4c7a8 /sources/shiboken6/ApiExtractor/qtdocparser.cpp | |
| parent | a8717d612eb17c3dfaaede46c7bda34e5c20125e (diff) | |
shiboken6/Documentation: Introduce a doc-package typesystem attribute
Make it possible to specify an alternate doc-package for locating the
WebXML files generated by qdoc. For example the documentation of the
QtMultimediaWidgets module is generated into the QtMultimedia module.
This became a problem after the module split
qttools/c51980bb0d9658f2ade4de1900d07b08e88cb52d.
Task-number: QTBUG-77650
Task-number: PYSIDE-2620
Task-number: PYSIDE-1106
Change-Id: I09ab50f7e3b56c0a7d0f2e94e593a8d5e83b2001
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/qtdocparser.cpp')
| -rw-r--r-- | sources/shiboken6/ApiExtractor/qtdocparser.cpp | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/sources/shiboken6/ApiExtractor/qtdocparser.cpp b/sources/shiboken6/ApiExtractor/qtdocparser.cpp index b0de9041e..a1875f567 100644 --- a/sources/shiboken6/ApiExtractor/qtdocparser.cpp +++ b/sources/shiboken6/ApiExtractor/qtdocparser.cpp @@ -9,6 +9,7 @@ #include "abstractmetalang.h" #include "abstractmetatype.h" #include "documentation.h" +#include "exception.h" #include "modifications.h" #include "messages.h" #include "propertyspec.h" @@ -17,11 +18,14 @@ #include "complextypeentry.h" #include "functiontypeentry.h" #include "enumtypeentry.h" +#include "typesystemtypeentry.h" +#include "typedatabase.h" #include "qtcompat.h" #include <QtCore/QDir> #include <QtCore/QFile> +#include <QtCore/QHash> #include <QtCore/QUrl> using namespace Qt::StringLiterals; @@ -37,16 +41,49 @@ Documentation QtDocParser::retrieveModuleDocumentation() return retrieveModuleDocumentation(packageName()); } +// Return the package of a type "PySide6.QtGui.QPainter" -> "PySide6.QtGui" +static QStringView packageFromPythonType(QStringView pythonType) +{ + qsizetype pos = pythonType.startsWith(u"PySide6.") ? 8 : 0; + auto dot = pythonType.indexOf(u'.', pos); + return dot != -1 ? pythonType.sliced(0, dot) : pythonType; +} + // Return the qdoc dir "PySide6.QtGui.QPainter" -> "qtgui/webxml" (QTBUG-119500) +static QString qdocModuleDirFromPackage(QStringView package) +{ + if (package.startsWith(u"PySide6.")) + package = package.sliced(8); + return package.toString().toLower() + "/webxml"_L1; +} + +// Populate a cache of package to WebXML dir +static QHash<QString, QString> getPackageToModuleDir() +{ + QHash<QString, QString> result; + const auto &typeSystemEntries = TypeDatabase::instance()->typeSystemEntries(); + for (const auto &te : typeSystemEntries) { + const QString &package = te->name(); + const QString &docPackage = te->hasDocTargetLangPackage() + ? te->docTargetLangPackage() : package; + result.insert(package, qdocModuleDirFromPackage(docPackage)); + } + return result; +} + QString QtDocParser::qdocModuleDir(const QString &pythonType) { - QString package = pythonType; - if (package.startsWith("PySide6."_L1)) - package.remove(0, 8); - auto dot = package.indexOf(u'.'); - if (dot != -1) - package.truncate(dot); - return package.toLower() + "/webxml"_L1; + static const QHash<QString, QString> packageToModuleDir = getPackageToModuleDir(); + + const QStringView package = packageFromPythonType(pythonType); + const auto it = packageToModuleDir.constFind(package); + if (it == packageToModuleDir.cend()) { + const QString known = packageToModuleDir.keys().join(", "_L1); + qCWarning(lcShibokenDoc, "Type from unknown package: \"%s\" (known: %s).", + qPrintable(pythonType), qPrintable(known)); + return qdocModuleDirFromPackage(package); + } + return it.value(); } static QString xmlFileNameRoot(const AbstractMetaClassPtr &metaClass) |
