From d2b61bf3f0462426c145326c79232358d154c912 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 26 Jun 2023 13:19:54 +0200 Subject: [PATCH] Examples: Order categories According to hard-coded list. This should come from the manifest file in the future. Follow-up of qtdoc/4e38729111989dbb738042d4a8beb35d01b77fe1 Change-Id: If46383e1cf8e44c2a52ca5a458c497495e132639 Reviewed-by: Qt CI Bot Reviewed-by: Christian Stenger --- src/plugins/qtsupport/examplesparser.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/plugins/qtsupport/examplesparser.cpp b/src/plugins/qtsupport/examplesparser.cpp index 84469ca2c4d..441db6a6ca0 100644 --- a/src/plugins/qtsupport/examplesparser.cpp +++ b/src/plugins/qtsupport/examplesparser.cpp @@ -301,6 +301,21 @@ expected_str> parseExamples(const QByteArray &manifestData, return items; } +// ordered list of "known" categories +// TODO this should be defined in the manifest +Q_GLOBAL_STATIC(QList, + defaultOrder, + {"Application Examples", + "Desktop", + "Mobile", + "Embedded", + "Graphics", + "Input/Output", + "Connectivity", + "Networking", + "Positioning & Location", + "Internationalization"}); + static bool sortByHighlightedAndName(ExampleItem *first, ExampleItem *second) { if (first->isHighlighted && !second->isHighlighted) @@ -350,15 +365,20 @@ QList>> getCategories(const QList< } else { // All original items have been copied into a category or other, delete. qDeleteAll(items); + static const int defaultOrderSize = defaultOrder->size(); int index = 0; const auto end = categoryMap.constKeyValueEnd(); for (auto it = categoryMap.constKeyValueBegin(); it != end; ++it) { - categories.append({{it->first, index, /*maxRows=*/index == 0 ? 2 : 1}, it->second}); + // order "known" categories as wanted, others come afterwards + const int defaultIndex = defaultOrder->indexOf(it->first); + const int priority = defaultIndex >= 0 ? defaultIndex : (index + defaultOrderSize); + categories.append({{it->first, priority, /*maxRows=*/index == 0 ? 2 : 1}, it->second}); ++index; } if (!other.isEmpty()) - categories.append({{otherDisplayName, index, /*maxRows=*/1}, other}); + categories.append({{otherDisplayName, index + defaultOrderSize, /*maxRows=*/1}, other}); } + const auto end = categories.end(); for (auto it = categories.begin(); it != end; ++it) sort(it->second, sortByHighlightedAndName);