aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor/qtdocparser.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-11-28 08:56:15 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-11-28 14:30:17 +0100
commit4e779d0e361ba455479f868f73b52b62e4b82be7 (patch)
tree48b6a44b4acc3ef8e4309aa6e2522005bd0be729 /sources/shiboken6/ApiExtractor/qtdocparser.cpp
parent05b3c28099c1eaff74bba8b06004cc8205b24f45 (diff)
shiboken6: Add a documentation file hint to complex type entries
Complements ad5eb64daaaa1b927bcbf9e568738f417fef845f. Add a doc-file attribute to complex type entries (object/value/namespaces) like it was done for enums and free functions by ad5eb64daaaa1b927bcbf9e568738f417fef845f. This is mainly intended for namespaces that can be extended by other modules. Change the functions to parse WebXML to accept lists of files. Improve the error message about not finding qdoc files. Pick-to: 6.8 Task-number: PYSIDE-2918 Task-number: PYSIDE-1106 Change-Id: I2811e0715b7f44a4461876019580295f5af4ea06 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.cpp44
1 files changed, 26 insertions, 18 deletions
diff --git a/sources/shiboken6/ApiExtractor/qtdocparser.cpp b/sources/shiboken6/ApiExtractor/qtdocparser.cpp
index 96d14ea93..216eccb05 100644
--- a/sources/shiboken6/ApiExtractor/qtdocparser.cpp
+++ b/sources/shiboken6/ApiExtractor/qtdocparser.cpp
@@ -28,6 +28,9 @@
#include <QtCore/QHash>
#include <QtCore/QUrl>
+#include <algorithm>
+#include <iterator>
+
using namespace Qt::StringLiterals;
enum { debugFunctionSearch = 0 };
@@ -86,13 +89,11 @@ QString QtDocParser::qdocModuleDir(const QString &pythonType)
return it.value();
}
-static QString xmlFileNameRoot(const AbstractMetaClassPtr &metaClass)
+static QString xmlFileBaseName(const AbstractMetaClassPtr &metaClass)
{
QString className = metaClass->qualifiedCppName().toLower();
className.replace("::"_L1, "-"_L1);
-
- return QtDocParser::qdocModuleDir(metaClass->typeEntry()->targetLangPackage())
- + u'/' + className;
+ return className;
}
static void formatPreQualifications(QTextStream &str, const AbstractMetaType &type)
@@ -324,7 +325,7 @@ void QtDocParser::fillGlobalFunctionDocumentation(const AbstractMetaFunctionPtr
return;
QString errorMessage;
- auto classDocumentationO = parseWebXml(sourceFileName, &errorMessage);
+ auto classDocumentationO = parseWebXml({sourceFileName}, &errorMessage);
if (!classDocumentationO.has_value()) {
qCWarning(lcShibokenDoc, "%s", qPrintable(errorMessage));
return;
@@ -347,7 +348,7 @@ void QtDocParser::fillGlobalEnumDocumentation(AbstractMetaEnum &e)
return;
QString errorMessage;
- auto classDocumentationO = parseWebXml(sourceFileName, &errorMessage);
+ auto classDocumentationO = parseWebXml({sourceFileName}, &errorMessage);
if (!classDocumentationO.has_value()) {
qCWarning(lcShibokenDoc, "%s", qPrintable(errorMessage));
return;
@@ -370,28 +371,35 @@ QString QtDocParser::fillDocumentation(const AbstractMetaClassPtr &metaClass)
context = context->enclosingClass();
}
- QString sourceFileRoot = documentationDataDirectory() + u'/' + xmlFileNameRoot(metaClass);
-
- QFileInfo sourceFile(sourceFileRoot + webxmlSuffix);
- if (!sourceFile.exists())
- sourceFile.setFile(sourceFileRoot + ".xml"_L1);
- if (!sourceFile.exists()) {
- qCWarning(lcShibokenDoc).noquote().nospace()
- << "Can't find qdoc file for class " << metaClass->name() << ", tried: "
- << QDir::toNativeSeparators(sourceFile.absoluteFilePath());
+ // Find qdoc files of a class.
+ QStringList allCandidates;
+ const auto typeEntry = metaClass->typeEntry();
+ const QString docDir = documentationDataDirectory() + u'/'
+ + QtDocParser::qdocModuleDir(typeEntry->targetLangPackage()) + u'/';
+ const QString baseName = xmlFileBaseName(metaClass);
+ allCandidates.append(docDir + baseName + webxmlSuffix);
+ const QString &docFile = typeEntry->docFile();
+ if (!docFile.isEmpty())
+ allCandidates.append(docDir + docFile + webxmlSuffix);
+ allCandidates.append(docDir + baseName + ".xml"_L1);
+ QStringList candidates;
+ std::copy_if(allCandidates.cbegin(), allCandidates.cend(), std::back_inserter(candidates),
+ qOverload<const QString &>(QFileInfo::exists));
+
+ if (candidates.isEmpty()) {
+ qCWarning(lcShibokenDoc, "%s", qPrintable(msgCannotFindQDocFile(metaClass, allCandidates)));
return {};
}
- const QString sourceFileName = sourceFile.absoluteFilePath();
QString errorMessage;
-
- const auto classDocumentationO = parseWebXml(sourceFileName, &errorMessage);
+ const auto classDocumentationO = parseWebXml(candidates, &errorMessage);
if (!classDocumentationO.has_value()) {
qCWarning(lcShibokenDoc, "%s", qPrintable(errorMessage));
return {};
}
const auto &classDocumentation = classDocumentationO.value();
+ const QString &sourceFileName = candidates.constFirst();
for (const auto &p : classDocumentation.properties) {
Documentation doc(p.description, p.brief, sourceFileName);
metaClass->setPropertyDocumentation(p.name, doc);