Persistent settings reader: Emit proper warning on value read failure.

Fix annoying assertion when reading session files:

SOFT ASSERT: "simpleValue.isValid()" in file
.\persistentsettings.cpp, line 126 .

Change-Id: Ia73a7a4a6f7a28c20876daf11a527b638ee02d89
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
Friedemann Kleint
2013-07-04 14:17:41 +02:00
parent 6dd6ce935e
commit 87fa3adb2d

View File

@@ -174,6 +174,8 @@ private:
bool handleStartElement(QXmlStreamReader &r); bool handleStartElement(QXmlStreamReader &r);
bool handleEndElement(const QStringRef &name); bool handleEndElement(const QStringRef &name);
static QString formatWarning(const QXmlStreamReader &r, const QString &message);
QStack<ParseValueStackEntry> m_valueStack; QStack<ParseValueStackEntry> m_valueStack;
QVariantMap m_result; QVariantMap m_result;
QString m_currentVariableName; QString m_currentVariableName;
@@ -223,10 +225,16 @@ bool ParseContext::handleStartElement(QXmlStreamReader &r)
const QString key = attributes.hasAttribute(keyAttribute) ? const QString key = attributes.hasAttribute(keyAttribute) ?
attributes.value(keyAttribute).toString() : QString(); attributes.value(keyAttribute).toString() : QString();
switch (e) { switch (e) {
case SimpleValueElement: case SimpleValueElement: {
// This reads away the end element, so, handle end element right here. // This reads away the end element, so, handle end element right here.
m_valueStack.push_back(ParseValueStackEntry(readSimpleValue(r, attributes), key)); const QVariant v = readSimpleValue(r, attributes);
if (!v.isValid()) {
qWarning() << ParseContext::formatWarning(r, QString::fromLatin1("Failed to read element \"%1\".").arg(name.toString()));
return false;
}
m_valueStack.push_back(ParseValueStackEntry(v, key));
return handleEndElement(name); return handleEndElement(name);
}
case ListValueElement: case ListValueElement:
m_valueStack.push_back(ParseValueStackEntry(QVariant::List, key)); m_valueStack.push_back(ParseValueStackEntry(QVariant::List, key));
break; break;
@@ -256,6 +264,18 @@ bool ParseContext::handleEndElement(const QStringRef &name)
return e == QtCreatorElement; return e == QtCreatorElement;
} }
QString ParseContext::formatWarning(const QXmlStreamReader &r, const QString &message)
{
QString result = QLatin1String("Warning reading ");
if (const QIODevice *device = r.device())
if (const QFile *file = qobject_cast<const QFile *>(device))
result += QDir::toNativeSeparators(file->fileName()) + QLatin1Char(':');
result += QString::number(r.lineNumber());
result += QLatin1String(": ");
result += message;
return result;
}
ParseContext::Element ParseContext::element(const QStringRef &r) const ParseContext::Element ParseContext::element(const QStringRef &r) const
{ {
if (r == valueElement) if (r == valueElement)