Skip to content

Commit 4d59b4c

Browse files
committed
QDoc: Make example-related warnings configurable
While processing example documentation, QDoc may emit warnings if the example lacks a project file and/or doesn't contain any images. These warnings are generated as a result of Qt's internal business rules. While a case can certainly be made for their validity, this behavior in QDoc imposes Qt's rules on external parties that use QDoc. This change makes these warnings configurable, such that projects can decide to opt out from getting them, by introducing the following configuration variables: `examples.warnaboutmissingimages = false` `examples.warnaboutmissingprojectfiles = false` This allows a project to disable these warnings according to whichever business rules are in place, by setting the configuration value to empty, `0`, or `false`. Any other value is considered a truthy value. The QDoc manual is updated with information about the two new configuration variables. [ChangeLog][QDoc][Configuration] Two new configuration variables have been introduced to QDoc to control whether QDoc emits warnings about missing images or missing project files, specific to example documentation. These warnings can now be disabled by setting `examples.warnaboutmissingimages = false` and `examples.warnaboutmissingprojectfiles = false` in the QDoc configuration file(s). Fixes: QTBUG-128910 Change-Id: I3093f97c8328ebba49ed6fe219ba571b6bdaa575 Reviewed-by: Topi Reiniö <[email protected]>
1 parent afa9c76 commit 4d59b4c

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

src/qdoc/qdoc/doc/qdoc-manual-qdocconf.qdoc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@
146146
\li \l {examples-variable} {examples}
147147
\li \l {examplesinstallpath-variable} {examplesinstallpath}
148148
\li \l {examples.fileextensions-variable} {examples.fileextensions}
149+
\li \l {examples.warnaboutmissingimages-variable} {examples.warnaboutmissingimages}
150+
\li \l {examples.warnaboutmissingprojectfiles-variable} {examples.warnaboutmissingprojectfiles}
149151
\li \l {excludedirs-variable} {excludedirs}
150152
\li \l {excludefiles-variable} {excludefiles}
151153
\li \l {extraimages-variable} {extraimages}
@@ -477,6 +479,34 @@
477479

478480
See also \l{headers.fileextensions}.
479481

482+
\target examples.warnaboutmissingimages-variable
483+
\section1 examples.warnaboutmissingimages
484+
485+
While processing example documentation, QDoc may emit warnings if an example
486+
doesn't contain any images. This warning can be disabled by setting the
487+
following configuration variable in the .qdocconf file for the project:
488+
489+
\c {examples.warnaboutmissingimages = false}
490+
491+
This configuration variable was introduced to QDoc with Qt 6.9.
492+
493+
See also \l{examples.warnaboutmissingprojectfiles-variable}
494+
{examples.warnaboutmissingprojectfiles}.
495+
496+
\target examples.warnaboutmissingprojectfiles-variable
497+
\section1 examples.warnaboutmissingprojectfiles
498+
499+
While processing example documentation, QDoc may emit warnings if an example
500+
doesn't contain a project file. This warning can be disabled by setting the
501+
following configuration variable in the .qdocconf file for the project:
502+
503+
\c {examples.warnaboutmissingprojectfiles = false}
504+
505+
This configuration variable was introduced to QDoc with Qt 6.9.
506+
507+
See also \l{examples.warnaboutmissingimages-variable}
508+
{examples.warnaboutmissingimages}.
509+
480510
\target excludedirs-variable
481511
\section1 excludedirs
482512

src/qdoc/qdoc/src/qdoc/config.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ QString ConfigStrings::FILEEXTENSIONS = QStringLiteral("fileextensions");
8989
QString ConfigStrings::IMAGEEXTENSIONS = QStringLiteral("imageextensions");
9090
QString ConfigStrings::QMLTYPESPAGE = QStringLiteral("qmltypespage");
9191
QString ConfigStrings::QMLTYPESTITLE = QStringLiteral("qmltypestitle");
92+
QString ConfigStrings::WARNABOUTMISSINGIMAGES = QStringLiteral("warnaboutmissingimages");
93+
QString ConfigStrings::WARNABOUTMISSINGPROJECTFILES = QStringLiteral("warnaboutmissingprojectfiles");
9294
QString ConfigStrings::WARNINGLIMIT = QStringLiteral("warninglimit");
9395

9496
/*!
@@ -370,6 +372,8 @@ void Config::reset()
370372
setStringList(CONFIG_OUTPUTFORMATS, QStringList("HTML"));
371373
setStringList(CONFIG_TABSIZE, QStringList("8"));
372374
setStringList(CONFIG_LOCATIONINFO, QStringList("true"));
375+
setStringList(CONFIG_WARNABOUTMISSINGIMAGES, QStringList("true"));
376+
setStringList(CONFIG_WARNABOUTMISSINGPROJECTFILES, QStringList("true"));
373377

374378
// Publish options from the command line as config variables
375379
const auto setListFlag = [this](const QString &key, bool test) {

src/qdoc/qdoc/src/qdoc/config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ struct ConfigStrings
315315
static QString IMAGEEXTENSIONS;
316316
static QString QMLTYPESPAGE;
317317
static QString QMLTYPESTITLE;
318+
static QString WARNABOUTMISSINGIMAGES;
319+
static QString WARNABOUTMISSINGPROJECTFILES;
318320
static QString WARNINGLIMIT;
319321
};
320322

@@ -393,6 +395,8 @@ struct ConfigStrings
393395
#define CONFIG_IMAGEEXTENSIONS ConfigStrings::IMAGEEXTENSIONS
394396
#define CONFIG_QMLTYPESPAGE ConfigStrings::QMLTYPESPAGE
395397
#define CONFIG_QMLTYPESTITLE ConfigStrings::QMLTYPESTITLE
398+
#define CONFIG_WARNABOUTMISSINGIMAGES ConfigStrings::WARNABOUTMISSINGIMAGES
399+
#define CONFIG_WARNABOUTMISSINGPROJECTFILES ConfigStrings::WARNABOUTMISSINGPROJECTFILES
396400
#define CONFIG_WARNINGLIMIT ConfigStrings::WARNINGLIMIT
397401

398402
inline bool Config::singleExec() const

src/qdoc/qdoc/src/qdoc/manifestwriter.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ QT_BEGIN_NAMESPACE
2323
void warnAboutUnusedAttributes(const QStringList &usedAttributes, const ExampleNode *example)
2424
{
2525
QMap<QString, QString> attributesToWarnFor;
26-
attributesToWarnFor.insert(QStringLiteral("imageUrl"),
27-
QStringLiteral("Example documentation should have at least one '\\image'"));
28-
attributesToWarnFor.insert(QStringLiteral("projectPath"),
29-
QStringLiteral("Example has no project file"));
26+
bool missingImageWarning = Config::instance().get(CONFIG_EXAMPLES + Config::dot + CONFIG_WARNABOUTMISSINGIMAGES).asBool();
27+
bool missingProjectFileWarning = Config::instance().get(CONFIG_EXAMPLES + Config::dot + CONFIG_WARNABOUTMISSINGPROJECTFILES).asBool();
28+
29+
if (missingImageWarning)
30+
attributesToWarnFor.insert(QStringLiteral("imageUrl"),
31+
QStringLiteral("Example documentation should have at least one '\\image'"));
32+
if (missingProjectFileWarning)
33+
attributesToWarnFor.insert(QStringLiteral("projectPath"),
34+
QStringLiteral("Example has no project file"));
35+
36+
if (attributesToWarnFor.empty())
37+
return;
3038

3139
for (auto it = attributesToWarnFor.cbegin(); it != attributesToWarnFor.cend(); ++it) {
3240
if (!usedAttributes.contains(it.key()))

0 commit comments

Comments
 (0)