QtSupport: Simplify example reading code

The default empty QVariant converts well enough to empty strings etc
to not have to check for its presence explicitly.

Change-Id: I8d3b20b3e463d8b504e27e86dc44c1b5de6de63a
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
hjk
2017-02-28 09:52:41 +01:00
parent 4d3d2d0dfb
commit 865a1ea259

View File

@@ -302,8 +302,6 @@ void ExamplesListModel::parseExamples(QXmlStreamReader *reader,
item.projectPath = relativeOrInstallPath(item.projectPath, projectsOffset, examplesInstallPath); item.projectPath = relativeOrInstallPath(item.projectPath, projectsOffset, examplesInstallPath);
item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString(); item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString();
item.docUrl = attributes.value(QLatin1String("docUrl")).toString(); item.docUrl = attributes.value(QLatin1String("docUrl")).toString();
if (attributes.hasAttribute(QLatin1String("isHighlighted")))
item.isHighlighted = attributes.value(QLatin1String("isHighlighted")).toString() == QLatin1String("true"); item.isHighlighted = attributes.value(QLatin1String("isHighlighted")).toString() == QLatin1String("true");
} else if (reader->name() == QLatin1String("fileToOpen")) { } else if (reader->name() == QLatin1String("fileToOpen")) {
@@ -357,10 +355,7 @@ void ExamplesListModel::parseDemos(QXmlStreamReader *reader,
item.projectPath = relativeOrInstallPath(item.projectPath, projectsOffset, demosInstallPath); item.projectPath = relativeOrInstallPath(item.projectPath, projectsOffset, demosInstallPath);
item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString(); item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString();
item.docUrl = attributes.value(QLatin1String("docUrl")).toString(); item.docUrl = attributes.value(QLatin1String("docUrl")).toString();
if (attributes.hasAttribute(QLatin1String("isHighlighted")))
item.isHighlighted = attributes.value(QLatin1String("isHighlighted")).toString() == QLatin1String("true"); item.isHighlighted = attributes.value(QLatin1String("isHighlighted")).toString() == QLatin1String("true");
} else if (reader->name() == QLatin1String("fileToOpen")) { } else if (reader->name() == QLatin1String("fileToOpen")) {
item.filesToOpen.append(relativeOrInstallPath(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement), item.filesToOpen.append(relativeOrInstallPath(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement),
projectsOffset, demosInstallPath)); projectsOffset, demosInstallPath));
@@ -402,15 +397,10 @@ void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString &
item.hasSourceCode = !item.projectPath.isEmpty(); item.hasSourceCode = !item.projectPath.isEmpty();
item.projectPath.prepend(slash); item.projectPath.prepend(slash);
item.projectPath.prepend(projectsOffset); item.projectPath.prepend(projectsOffset);
if (attributes.hasAttribute(QLatin1String("imageUrl")))
item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString(); item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString();
if (attributes.hasAttribute(QLatin1String("docUrl")))
item.docUrl = attributes.value(QLatin1String("docUrl")).toString(); item.docUrl = attributes.value(QLatin1String("docUrl")).toString();
if (attributes.hasAttribute(QLatin1String("isVideo")))
item.isVideo = attributes.value(QLatin1String("isVideo")).toString() == QLatin1String("true"); item.isVideo = attributes.value(QLatin1String("isVideo")).toString() == QLatin1String("true");
if (attributes.hasAttribute(QLatin1String("videoUrl")))
item.videoUrl = attributes.value(QLatin1String("videoUrl")).toString(); item.videoUrl = attributes.value(QLatin1String("videoUrl")).toString();
if (attributes.hasAttribute(QLatin1String("videoLength")))
item.videoLength = attributes.value(QLatin1String("videoLength")).toString(); item.videoLength = attributes.value(QLatin1String("videoLength")).toString();
} else if (reader->name() == QLatin1String("fileToOpen")) { } else if (reader->name() == QLatin1String("fileToOpen")) {
item.filesToOpen.append(projectsOffset + slash + reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement)); item.filesToOpen.append(projectsOffset + slash + reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));