diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-02-08 09:49:15 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-02-09 18:08:45 +0100 |
commit | 95df729709f6b460479c0a374e46ea4af629a0bb (patch) | |
tree | 961521d8342e48bb4e9c3ee22e38896286f33ad5 /sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp | |
parent | 1481fc31f6500d899e2b8ea4f5ec5c80cfe36fbf (diff) |
shiboken6/Documentation: Fix the TOC table
Change writeFancyToc() to output a table like the Qt documentation
(3 columns).
Task-number: PYSIDE-841
Change-Id: I05a53e4c78ffb8022e6e3fb6db0e6387b953eafd
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
(cherry picked from commit e20d9db9e9dc8d599b76873d90a34acafe9fd9fe)
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp')
-rw-r--r-- | sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp index e25bd5c76..5850754ae 100644 --- a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp @@ -772,7 +772,7 @@ void QtDocGenerator::writeFunction(TextStream& s, const AbstractMetaClass* cppCl writeInjectDocumentation(s, TypeSystem::DocModificationAppend, cppClass, func); } -static void writeFancyToc(TextStream& s, const QStringList& items, int cols = 2) +static void writeFancyToc(TextStream& s, const QStringList& items) { using TocMap = QMap<QChar, QStringList>; TocMap tocMap; @@ -790,41 +790,30 @@ static void writeFancyToc(TextStream& s, const QStringList& items, int cols = 2) idx = className[0]; tocMap[idx] << item; } - QtXmlToSphinx::Table table; - QtXmlToSphinx::TableRow row; - int itemsPerCol = (items.size() + tocMap.size()*2) / cols; - QString currentColData; - int i = 0; - TextStream ss(¤tColData); - for (auto it = tocMap.cbegin(), end = tocMap.cend(); it != end; ++it) { - if (i) - ss << '\n'; + static const qsizetype numColumns = 4; - ss << "**" << it.key() << "**\n\n"; - i += 2; // a letter title is equivalent to two entries in space + QtXmlToSphinx::Table table; + for (auto it = tocMap.cbegin(), end = tocMap.cend(); it != end; ++it) { + QtXmlToSphinx::TableRow row; + const QString charEntry = QLatin1String("**") + it.key() + QLatin1String("**"); + row << QtXmlToSphinx::TableCell(charEntry); for (const QString &item : qAsConst(it.value())) { - ss << "* :doc:`" << item << "`\n"; - ++i; - - // end of column detected! - if (i > itemsPerCol) { - ss.flush(); - QtXmlToSphinx::TableCell cell(currentColData); - row << cell; - currentColData.clear(); - i = 0; + if (row.size() >= numColumns) { + table.appendRow(row); + row.clear(); + row << QtXmlToSphinx::TableCell(QString{}); } + const QString entry = QLatin1String("* :doc:`") + item + QLatin1Char('`'); + row << QtXmlToSphinx::TableCell(entry); + } + if (!row.isEmpty()) { + while (row.size() < numColumns) + row << QtXmlToSphinx::TableCell(QString{}); + table.appendRow(row); } } - if (i) { - ss.flush(); - QtXmlToSphinx::TableCell cell(currentColData); - row << cell; - currentColData.clear(); - i = 0; - } - table.appendRow(row); + table.normalize(); s << ".. container:: pysidetoc\n\n"; table.format(s); |