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 <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Eike Ziller
2023-06-26 13:19:54 +02:00
parent 152d543cdf
commit d2b61bf3f0

View File

@@ -301,6 +301,21 @@ expected_str<QList<ExampleItem *>> parseExamples(const QByteArray &manifestData,
return items; return items;
} }
// ordered list of "known" categories
// TODO this should be defined in the manifest
Q_GLOBAL_STATIC(QList<QString>,
defaultOrder,
{"Application Examples",
"Desktop",
"Mobile",
"Embedded",
"Graphics",
"Input/Output",
"Connectivity",
"Networking",
"Positioning & Location",
"Internationalization"});
static bool sortByHighlightedAndName(ExampleItem *first, ExampleItem *second) static bool sortByHighlightedAndName(ExampleItem *first, ExampleItem *second)
{ {
if (first->isHighlighted && !second->isHighlighted) if (first->isHighlighted && !second->isHighlighted)
@@ -350,15 +365,20 @@ QList<std::pair<Core::Section, QList<ExampleItem *>>> getCategories(const QList<
} else { } else {
// All original items have been copied into a category or other, delete. // All original items have been copied into a category or other, delete.
qDeleteAll(items); qDeleteAll(items);
static const int defaultOrderSize = defaultOrder->size();
int index = 0; int index = 0;
const auto end = categoryMap.constKeyValueEnd(); const auto end = categoryMap.constKeyValueEnd();
for (auto it = categoryMap.constKeyValueBegin(); it != end; ++it) { 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; ++index;
} }
if (!other.isEmpty()) if (!other.isEmpty())
categories.append({{otherDisplayName, index, /*maxRows=*/1}, other}); categories.append({{otherDisplayName, index + defaultOrderSize, /*maxRows=*/1}, other});
} }
const auto end = categories.end(); const auto end = categories.end();
for (auto it = categories.begin(); it != end; ++it) for (auto it = categories.begin(); it != end; ++it)
sort(it->second, sortByHighlightedAndName); sort(it->second, sortByHighlightedAndName);