45
45
46
46
#include < algorithm>
47
47
#include < limits>
48
+ #include < unordered_set>
48
49
49
50
using namespace Qt ::StringLiterals;
50
51
@@ -53,9 +54,21 @@ static inline QString classScope(const AbstractMetaClassCPtr &metaClass)
53
54
return metaClass->fullName ();
54
55
}
55
56
57
+ struct DocClassEntry
58
+ {
59
+ QString name;
60
+ QString fullName;
61
+ QString file;
62
+ };
63
+
64
+ static bool classEntryLessThan (const DocClassEntry &e1 , const DocClassEntry &e2 )
65
+ {
66
+ return e1 .name < e2 .name ;
67
+ }
68
+
56
69
struct DocPackage
57
70
{
58
- QStringList classPages;
71
+ QList<DocClassEntry> classPages;
59
72
QStringList decoratorPages;
60
73
AbstractMetaFunctionCList globalFunctions;
61
74
AbstractMetaEnumList globalEnums;
@@ -220,7 +233,8 @@ static void readExtraDoc(const QFileInfo &fi,
220
233
DocPackage *docPackage, QStringList *extraTocEntries)
221
234
{
222
235
// Strip to "Property.rst" in output directory
223
- const QString newFileName = fi.fileName ().mid (moduleName.size () + 1 );
236
+ const QString newFileName = fi.fileName ().sliced (moduleName.size () + 1 );
237
+ const QString fullClassName = fi.completeBaseName ().sliced (moduleName.size () + 1 );
224
238
QFile sourceFile (fi.absoluteFilePath ());
225
239
if (!sourceFile.open (QIODevice::ReadOnly|QIODevice::Text)) {
226
240
qCWarning (lcShibokenDoc, " %s" , qPrintable (msgCannotOpenForReading (sourceFile)));
@@ -234,10 +248,15 @@ static void readExtraDoc(const QFileInfo &fi,
234
248
return ;
235
249
}
236
250
targetFile.write (contents);
237
- if (contents.contains (" decorator::" ))
251
+ if (contents.contains (" decorator::" )) {
238
252
docPackage->decoratorPages .append (newFileName);
239
- else
240
- docPackage->classPages .append (newFileName);
253
+ } else {
254
+ QString name = fullClassName;
255
+ auto dot = name.lastIndexOf (u' .' );
256
+ if (dot != -1 )
257
+ name.remove (0 , dot + 1 );
258
+ docPackage->classPages .append ({name, fullClassName, newFileName});
259
+ }
241
260
extraTocEntries->append (fileNameToTocEntry (newFileName));
242
261
}
243
262
@@ -447,7 +466,8 @@ void QtDocGenerator::generateClassRecursion(TextStream &s, const QString &target
447
466
448
467
qCDebug (lcShibokenDoc, " Generating Documentation for %s" , qPrintable (metaClass->fullName ()));
449
468
450
- m_packages[metaClass->package ()].classPages << fileNameForContext (classContext);
469
+ m_packages[metaClass->package ()].classPages .append ({metaClass->name (), metaClass->fullName (),
470
+ fileNameForContext (classContext)});
451
471
452
472
doGenerateClass (s, targetDir, metaClass);
453
473
@@ -1017,34 +1037,7 @@ void QtDocGenerator::writeFunctionDocumentation(TextStream &s, const AbstractMet
1017
1037
func, scope, images);
1018
1038
}
1019
1039
1020
- static QStringList fileListToToc (const QStringList &items)
1021
- {
1022
- QStringList result;
1023
- result.reserve (items.size ());
1024
- std::transform (items.cbegin (), items.cend (), std::back_inserter (result),
1025
- fileNameToTocEntry);
1026
- return result;
1027
- }
1028
-
1029
- static QStringList functionListToToc (const AbstractMetaFunctionCList &functions)
1030
- {
1031
- QStringList result;
1032
- result.reserve (functions.size ());
1033
- for (const auto &f : functions)
1034
- result.append (f->name ());
1035
- // Functions are sorted by the Metabuilder; erase overloads
1036
- result.erase (std::unique (result.begin (), result.end ()), result.end ());
1037
- return result;
1038
- }
1039
-
1040
- static QStringList enumListToToc (const AbstractMetaEnumList &enums)
1041
- {
1042
- QStringList result;
1043
- result.reserve (enums.size ());
1044
- for (const auto &e : enums)
1045
- result.append (e.name ());
1046
- return result;
1047
- }
1040
+ using TocMap = QMap<QChar, QStringList>;
1048
1041
1049
1042
// Sort entries for a TOC by first character, dropping the
1050
1043
// leading common Qt prefixes like 'Q'.
@@ -1065,19 +1058,57 @@ static QChar sortKey(const QString &key)
1065
1058
return idx < size ? key.at (idx).toUpper () : u' A' ;
1066
1059
}
1067
1060
1061
+ static TocMap classEntryListToToc (const QList<DocClassEntry> &entries,
1062
+ TypeSystem::DocMode docMode)
1063
+ {
1064
+ const bool fullyQualified = docMode == TypeSystem::DocMode::Nested;
1065
+ TocMap result;
1066
+ // Sort by name, use full href
1067
+ for (const auto &e : entries)
1068
+ result[sortKey (e.name )] << (fullyQualified ? e.fullName : e.name );
1069
+ return result;
1070
+ }
1071
+
1072
+ static TocMap fileListToToc (const QStringList &items)
1073
+ {
1074
+ TocMap result;
1075
+ for (const auto &item : items) {
1076
+ const QString entry = fileNameToTocEntry (item);
1077
+ result[sortKey (entry)] << entry;
1078
+ }
1079
+ return result;
1080
+ }
1081
+
1082
+ static TocMap functionListToToc (const AbstractMetaFunctionCList &functions)
1083
+ {
1084
+ TocMap result;
1085
+ // Functions are sorted by the Metabuilder; erase overloads
1086
+ std::unordered_set<QString> seenNames;
1087
+ for (const auto &f : functions) {
1088
+ const QString &name = f->name ();
1089
+ if (seenNames.find (name) == seenNames.end ()) {
1090
+ seenNames.insert (name);
1091
+ result[sortKey (name)] << name;
1092
+ }
1093
+ }
1094
+ return result;
1095
+ }
1096
+
1097
+ static TocMap enumListToToc (const AbstractMetaEnumList &enums)
1098
+ {
1099
+ TocMap result;
1100
+ for (const auto &e : enums)
1101
+ result[sortKey (e.name ())] << e.name ();
1102
+ return result;
1103
+ }
1104
+
1068
1105
static void writeFancyToc (TextStream& s, QAnyStringView title,
1069
- const QStringList& items ,
1106
+ const TocMap &tocMap ,
1070
1107
QLatin1StringView referenceType)
1071
1108
{
1072
- using TocMap = QMap<QChar, QStringList>;
1073
-
1074
- if (items.isEmpty ())
1109
+ if (tocMap.isEmpty ())
1075
1110
return ;
1076
1111
1077
- TocMap tocMap;
1078
- for (const QString &item : items)
1079
- tocMap[sortKey (item)] << item;
1080
-
1081
1112
qsizetype maxColumnCount = 0 ;
1082
1113
for (auto it = tocMap.cbegin (), end = tocMap.cend (); it != end; ++it) {
1083
1114
if (it.value ().size () > maxColumnCount)
@@ -1096,7 +1127,10 @@ static void writeFancyToc(TextStream& s, QAnyStringView title,
1096
1127
row.clear ();
1097
1128
row << QtXmlToSphinx::TableCell (QString{});
1098
1129
}
1099
- const QString entry = " * :" _L1 + referenceType + " :`" _L1 + item + u' `' ;
1130
+ QString entry = " * :" _L1 + referenceType + " :`" _L1;
1131
+ if (item.contains (u' .' ))
1132
+ entry += u' ~' ;
1133
+ entry += item + u' `' ;
1100
1134
row << QtXmlToSphinx::TableCell (entry);
1101
1135
}
1102
1136
if (row.size () > 1 ) {
@@ -1194,9 +1228,10 @@ static bool imagesFromRstDocs(const QByteArray &rstDoc, const QString &scope,
1194
1228
1195
1229
void QtDocGenerator::writeModuleDocumentation ()
1196
1230
{
1231
+ auto *typeDb = TypeDatabase::instance ();
1197
1232
for (auto it = m_packages.begin (), end = m_packages.end (); it != end; ++it) {
1198
1233
auto &docPackage = it.value ();
1199
- std::sort (docPackage.classPages .begin (), docPackage.classPages .end ());
1234
+ std::sort (docPackage.classPages .begin (), docPackage.classPages .end (), classEntryLessThan );
1200
1235
1201
1236
QString key = it.key ();
1202
1237
key.replace (u' .' , u' /' );
@@ -1244,8 +1279,8 @@ void QtDocGenerator::writeModuleDocumentation()
1244
1279
<< " :maxdepth: 1\n\n " ;
1245
1280
if (hasGlobals)
1246
1281
s << globalsPage << ' \n ' ;
1247
- for (const QString &className : std::as_const (docPackage.classPages ))
1248
- s << className << ' \n ' ;
1282
+ for (const auto &e : std::as_const (docPackage.classPages ))
1283
+ s << e. file << ' \n ' ;
1249
1284
s << " \n\n " << outdent << outdent << headline (" Detailed Description" );
1250
1285
1251
1286
// module doc is always wrong and C++istic, so go straight to the extra directory!
@@ -1279,7 +1314,10 @@ void QtDocGenerator::writeModuleDocumentation()
1279
1314
}
1280
1315
}
1281
1316
1282
- writeFancyToc (s, " List of Classes" , fileListToToc (docPackage.classPages ),
1317
+ TypeSystemTypeEntryCPtr typeSystemEntry = typeDb->findTypeSystemType (it.key ());
1318
+ Q_ASSERT (typeSystemEntry);
1319
+ writeFancyToc (s, " List of Classes" , classEntryListToToc (docPackage.classPages ,
1320
+ typeSystemEntry->docMode ()),
1283
1321
" class" _L1);
1284
1322
writeFancyToc (s, " List of Decorators" , fileListToToc (docPackage.decoratorPages ),
1285
1323
" deco" _L1);
0 commit comments