summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-01-24 13:36:08 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2017-01-24 16:04:37 +0000
commit6ec8f78e02aadec769252cf9be8218098c9a3289 (patch)
tree7d1a39b74be6049e5efb6712d7b052d90e6b0eed
parentfe23614c7a502b7d89845b554c82bf4acd805ed9 (diff)
Improve error message in QHelpProjectDataPrivate::readKeywords()
Store name, id and ref attribute values in local variables to prevent duplicated string construction and map lookups and add a message function to format an error message containing file name and name. For example: Missing attribute in keyword at line 3349. becomes: qtbase/doc/qtcore/qtcore.qhp:3349: Missing attribute in <keyword name="Q_ENUM_NS">. Change-Id: Ia850ac1428471436b53e461a083b0ef8a8ba8bf6 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
-rw-r--r--src/assistant/help/qhelpprojectdata.cpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/assistant/help/qhelpprojectdata.cpp b/src/assistant/help/qhelpprojectdata.cpp
index 77f3eba8d..8b0615dc8 100644
--- a/src/assistant/help/qhelpprojectdata.cpp
+++ b/src/assistant/help/qhelpprojectdata.cpp
@@ -45,6 +45,7 @@
#include <QtCore/QStack>
#include <QtCore/QMap>
#include <QtCore/QRegExp>
+#include <QtCore/QTextStream>
#include <QtCore/QUrl>
#include <QtCore/QVariant>
#include <QtCore/QXmlStreamReader>
@@ -223,23 +224,33 @@ void QHelpProjectDataPrivate::readTOC()
}
}
+static inline QString msgMissingAttribute(const QString &fileName, qint64 lineNumber, const QString &name)
+{
+ QString result;
+ QTextStream str(&result);
+ str << QDir::toNativeSeparators(fileName) << ':' << lineNumber
+ << ": Missing attribute in <keyword";
+ if (!name.isEmpty())
+ str << " name=\"" << name << '"';
+ str << ">.";
+ return result;
+}
+
void QHelpProjectDataPrivate::readKeywords()
{
while (!atEnd()) {
readNext();
if (isStartElement()) {
if (name() == QLatin1String("keyword")) {
- if (attributes().value(QLatin1String("ref")).toString().isEmpty()
- || (attributes().value(QLatin1String("name")).toString().isEmpty()
- && attributes().value(QLatin1String("id")).toString().isEmpty())) {
- qWarning("Missing attribute in keyword at line %d.", (int)lineNumber());
+ const QString &refAttribute = attributes().value(QStringLiteral("ref")).toString();
+ const QString &nameAttribute = attributes().value(QStringLiteral("name")).toString();
+ const QString &idAttribute = attributes().value(QStringLiteral("id")).toString();
+ if (refAttribute.isEmpty() || (nameAttribute.isEmpty() && idAttribute.isEmpty())) {
+ qWarning("%s", qPrintable(msgMissingAttribute(fileName, lineNumber(), nameAttribute)));
continue;
}
filterSectionList.last()
- .addIndex(QHelpDataIndexItem(attributes().
- value(QLatin1String("name")).toString(),
- attributes().value(QLatin1String("id")).toString(),
- attributes().value(QLatin1String("ref")).toString()));
+ .addIndex(QHelpDataIndexItem(nameAttribute, idAttribute, refAttribute));
} else {
raiseUnknownTokenError();
}