More diagnostic messages when debugging examples model.

And less messages when not debugging.

Change-Id: Ib30dfe061c399aeeb3523544232b394e12ccb1b6
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
Eike Ziller
2012-12-12 14:01:36 +01:00
parent 990ddf2c71
commit 4d5c95e156

View File

@@ -116,21 +116,37 @@ static QString relativeOrInstallPath(const QString &path, const QString &manifes
return relativeResolvedPath;
}
static bool debugExamples()
{
static bool isDebugging = !qgetenv("QTC_DEBUG_EXAMPLESMODEL").isEmpty();
return isDebugging;
}
static bool isValidExampleOrDemo(ExampleItem &item)
{
static QString invalidPrefix = QLatin1String("qthelp:////"); /* means that the qthelp url
doesn't have any namespace */
QString reason;
bool ok = true;
if (!item.hasSourceCode || !QFileInfo(item.projectPath).exists())
if (!item.hasSourceCode || !QFileInfo(item.projectPath).exists()) {
ok = false;
else if (item.imageUrl.startsWith(invalidPrefix) || !QUrl(item.imageUrl).isValid())
reason = QString::fromLatin1("projectPath '%1' empty or does not exist").arg(item.projectPath);
} else if (item.imageUrl.startsWith(invalidPrefix) || !QUrl(item.imageUrl).isValid()) {
ok = false;
else if (!item.docUrl.isEmpty()
&& (item.imageUrl.startsWith(invalidPrefix) || !QUrl(item.docUrl).isValid()))
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;
if (!ok)
reason = QString::fromLatin1("docUrl '%1' non-empty but not valid").arg(item.docUrl);
}
if (!ok) {
item.tags.append(QLatin1String("broken"));
return ok || !qgetenv("QTC_DEBUG_EXAMPLESMODEL").isEmpty();
if (debugExamples())
qWarning() << QString::fromLatin1("ERROR: Item '%1' broken: %2").arg(item.name, reason);
}
if (debugExamples() && item.description.isEmpty())
qWarning() << QString::fromLatin1("WARNING: Item '%1' has no description").arg(item.name);
return ok || debugExamples();
}
QList<ExampleItem> ExamplesListModel::parseExamples(QXmlStreamReader *reader,
@@ -298,7 +314,8 @@ void ExamplesListModel::updateExamples()
&examplesFallback, &demosFallback, &sourceFallback)) {
QFile exampleFile(exampleSource);
if (!exampleFile.open(QIODevice::ReadOnly)) {
qDebug() << Q_FUNC_INFO << "Could not open file" << exampleSource;
if (debugExamples())
qWarning() << "ERROR: Could not open file" << exampleSource;
continue;
}
@@ -319,6 +336,8 @@ void ExamplesListModel::updateExamples()
}
}
if (debugExamples())
qWarning() << QString::fromLatin1("Reading file '%1'...").arg(fi.absoluteFilePath());
QXmlStreamReader reader(&exampleFile);
while (!reader.atEnd())
switch (reader.readNext()) {
@@ -334,8 +353,8 @@ void ExamplesListModel::updateExamples()
break;
}
if (reader.hasError())
qDebug() << "error parsing file" << exampleSource << "as XML document";
if (reader.hasError() && debugExamples())
qWarning() << QString::fromLatin1("ERROR: Could not parse file as XML document ('%1')").arg(exampleSource);
}
m_tags.sort();