diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-03-05 07:54:21 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-03-06 11:47:11 +0100 |
commit | e72af74d4cd458a10a707ad6aa248fbcb661de0a (patch) | |
tree | 983d7956fdaa6dc75e42d285352b94134ced016b | |
parent | 233f49d49af9c86a28be0d1a1d2f827c4505a28b (diff) |
Documentation: Improve TOC sorting
When creating the TOC tables sorting by first character, consider
more common Qt prefixes for functions (QT_, Q_, as well as _).
Change-Id: I12f96bb7d0ea7b8c8270cc0ad8d5a46088f70a3a
Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
(cherry picked from commit fe62a95fe11cf2b4904fa09c57996089505a9438)
-rw-r--r-- | sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp index bba60fa9a..252b576eb 100644 --- a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp @@ -874,23 +874,29 @@ void QtDocGenerator::writeFunction(TextStream &s, const AbstractMetaClassCPtr &c } } +// Sort entries for a TOC by first character, dropping the +// leading common Qt prefixes like 'Q'. +static QChar sortKey(const QString &key) +{ + const auto size = key.size(); + if (size >= 2 && key.at(0) == u'Q' && key.at(1).isUpper()) + return key.at(1); // "QClass" -> 'C' + if (size >= 3 && key.startsWith("Q_"_L1)) + return key.at(2).toUpper(); // "Q_ARG" -> 'A' + if (size >= 4 && key.startsWith("QT_"_L1)) + return key.at(3).toUpper(); // "QT_TR" -> 'T' + auto idx = 0; + for (; idx < size && key.at(idx) == u'_'; ++idx) { + } // "__init__" -> 'I' + return idx < size ? key.at(idx).toUpper() : u'A'; +} + static void writeFancyToc(TextStream& s, const QStringList& items) { using TocMap = QMap<QChar, QStringList>; TocMap tocMap; - QChar idx; - for (QString item : items) { - if (item.isEmpty()) - continue; - item.chop(4); // Remove the .rst extension - // skip namespace if necessary - const QString className = item.split(u'.').last(); - if (className.startsWith(u'Q') && className.length() > 1) - idx = className[1]; - else - idx = className[0]; - tocMap[idx] << item; - } + for (const QString &item : items) + tocMap[sortKey(item)] << item; static const qsizetype numColumns = 4; |