aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qtsupport/exampleslistmodel.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2024-01-17 15:08:45 +0100
committerEike Ziller <eike.ziller@qt.io>2024-01-19 09:44:53 +0000
commit2865f6eae0f0ed928b529944c4c9eedde559af60 (patch)
tree8bed443d56e4534748f8f902fc994180ea93c0f7 /src/plugins/qtsupport/exampleslistmodel.cpp
parent716c68ac5a85554c9d776947d970e55d42030a42 (diff)
Examples: Read and handle "documentation dependencies"
Some examples are defined in a Qt module (and therefore examples- manifest), but have dependencies on other modules. The example-manifests contain a `module` attribute for their `instructionals` tag, and examples can contain "docdependencies" items in their meta data, which are comma-separated lists of these module names. Read the `module` attributes (the meta data is already generically read) and check if the current set of examples-manifest contains all required ones for an example. Hide it, if not. Task-number: QTBUG-120759 Change-Id: Ib8ff80cf8a13965e57b5c4317e5d121c4127278b Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Kai Köhne <kai.koehne@qt.io>
Diffstat (limited to 'src/plugins/qtsupport/exampleslistmodel.cpp')
-rw-r--r--src/plugins/qtsupport/exampleslistmodel.cpp77
1 files changed, 49 insertions, 28 deletions
diff --git a/src/plugins/qtsupport/exampleslistmodel.cpp b/src/plugins/qtsupport/exampleslistmodel.cpp
index d8593cb1fd..18aa6cc381 100644
--- a/src/plugins/qtsupport/exampleslistmodel.cpp
+++ b/src/plugins/qtsupport/exampleslistmodel.cpp
@@ -299,35 +299,53 @@ ExamplesViewController::ExamplesViewController(ExampleSetModel *exampleSetModel,
updateExamples();
}
-static bool isValidExampleOrDemo(ExampleItem *item)
+static std::function<bool(ExampleItem *)> isValidExampleOrDemo(
+ const QSet<QString> &instructionalsModules)
{
- QTC_ASSERT(item, return false);
- if (item->type == Tutorial)
- return true;
- static QString invalidPrefix = QLatin1String("qthelp:////"); /* means that the qthelp url
+ return [instructionalsModules](ExampleItem *item) -> bool {
+ QTC_ASSERT(item, return false);
+ if (item->type == Tutorial)
+ return true;
+ static QString invalidPrefix = QLatin1String("qthelp:////"); /* means that the qthelp url
doesn't have any namespace */
- QString reason;
- bool ok = true;
- if (!item->hasSourceCode || !item->projectPath.exists()) {
- ok = false;
- reason = QString::fromLatin1("projectPath \"%1\" empty or does not exist")
- .arg(item->projectPath.toUserOutput());
- } else if (item->imageUrl.startsWith(invalidPrefix) || !QUrl(item->imageUrl).isValid()) {
- ok = false;
- reason = QString::fromLatin1("imageUrl \"%1\" not valid").arg(item->imageUrl);
- } else if (!item->docUrl.isEmpty()
- && (item->docUrl.startsWith(invalidPrefix) || !QUrl(item->docUrl).isValid())) {
- ok = false;
- reason = QString::fromLatin1("docUrl \"%1\" non-empty but not valid").arg(item->docUrl);
- }
- if (!ok) {
- item->tags.append(QLatin1String("broken"));
- qCDebug(log) << QString::fromLatin1("ERROR: Item \"%1\" broken: %2").arg(item->name, reason);
- }
- if (item->description.isEmpty())
- qCDebug(log) << QString::fromLatin1("WARNING: Item \"%1\" has no description")
- .arg(item->name);
- return ok || debugExamples();
+ QString reason;
+ bool ok = true;
+ if (!item->hasSourceCode || !item->projectPath.exists()) {
+ ok = false;
+ reason = QString::fromLatin1("projectPath \"%1\" empty or does not exist")
+ .arg(item->projectPath.toUserOutput());
+ } else if (item->imageUrl.startsWith(invalidPrefix) || !QUrl(item->imageUrl).isValid()) {
+ ok = false;
+ reason = QString::fromLatin1("imageUrl \"%1\" not valid").arg(item->imageUrl);
+ } else if (!item->docUrl.isEmpty()
+ && (item->docUrl.startsWith(invalidPrefix) || !QUrl(item->docUrl).isValid())) {
+ ok = false;
+ reason = QString::fromLatin1("docUrl \"%1\" non-empty but not valid").arg(item->docUrl);
+ }
+ if (!ok) {
+ item->tags.append(QLatin1String("broken"));
+ qCDebug(log) << QString::fromLatin1("ERROR: Item \"%1\" broken: %2")
+ .arg(item->name, reason);
+ }
+ if (item->description.isEmpty())
+ qCDebug(log) << QString::fromLatin1("WARNING: Item \"%1\" has no description")
+ .arg(item->name);
+ // a single docdependencies entry is a string of items concatenated with ','
+ // the collected meta data can be a list of this
+ for (const QString &entry : item->metaData.value("docdependencies")) {
+ const QStringList deps = entry.split(',');
+ for (const QString &dep : deps) {
+ if (!instructionalsModules.contains(dep)) {
+ item->tags.append("unresolvedDependency");
+ qCDebug(log) << QLatin1String("INFO: Item \"%1\" requires \"%2\"")
+ .arg(item->name, dep);
+ ok = false;
+ break;
+ }
+ }
+ }
+ return ok || debugExamples();
+ };
}
// ordered list of "known" categories
@@ -365,6 +383,7 @@ void ExamplesViewController::updateExamples()
&demosInstallPath,
&qtVersion,
m_isExamples);
+ QSet<QString> instructionalsModules;
QStringList categoryOrder;
QList<ExampleItem *> items;
for (const QString &exampleSource : sources) {
@@ -382,10 +401,12 @@ void ExamplesViewController::updateExamples()
<< result.error();
continue;
}
- items += filtered(result->items, isValidExampleOrDemo);
+ instructionalsModules.insert(result->instructionalsModule);
+ items += result->items;
if (categoryOrder.isEmpty())
categoryOrder = result->categoryOrder;
}
+ items = filtered(items, isValidExampleOrDemo(instructionalsModules));
if (m_isExamples) {
if (m_exampleSetModel->selectedQtSupports(Android::Constants::ANDROID_DEVICE_TYPE)) {