Examples: Support new mainFile attribute

Qt 5.3 adds a mainFile="yes" attribute to the fileToOpen tag for the
file that should be visible after opening the files.

Change-Id: I3ff67e514a16811cc730633e0fbcc470c4e54e5e
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
Eike Ziller
2014-06-16 12:50:32 +02:00
parent 2a6b41101e
commit 232024253f
5 changed files with 33 additions and 7 deletions

View File

@@ -221,7 +221,12 @@ Rectangle {
if (model.isVideo)
gettingStarted.openUrl(model.videoUrl);
else if (model.hasSourceCode)
gettingStarted.openProject(model.projectPath, model.filesToOpen, model.docUrl, model.dependencies, model.platforms)
gettingStarted.openProject(model.projectPath,
model.filesToOpen,
model.mainFile,
model.docUrl,
model.dependencies,
model.platforms)
else
gettingStarted.openSplitHelp(model.docUrl);
}

View File

@@ -207,6 +207,7 @@ ExamplesListModel::ExamplesListModel(QObject *parent) :
roleNames[Description] = "description";
roleNames[DocUrl] = "docUrl";
roleNames[FilesToOpen] = "filesToOpen";
roleNames[MainFile] = "mainFile";
roleNames[Tags] = "tags";
roleNames[Difficulty] = "difficulty";
roleNames[Type] = "type";
@@ -332,8 +333,14 @@ void ExamplesListModel::parseExamples(QXmlStreamReader *reader,
item.isHighlighted = attributes.value(QLatin1String("isHighlighted")).toString() == QLatin1String("true");
} else if (reader->name() == QLatin1String("fileToOpen")) {
item.filesToOpen.append(relativeOrInstallPath(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement),
projectsOffset, examplesInstallPath));
const QString mainFileAttribute = reader->attributes().value(
QLatin1String("mainFile")).toString();
const QString filePath = relativeOrInstallPath(
reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement),
projectsOffset, examplesInstallPath);
item.filesToOpen.append(filePath);
if (mainFileAttribute.compare(QLatin1String("true"), Qt::CaseInsensitive) == 0)
item.mainFile = filePath;
} else if (reader->name() == QLatin1String("description")) {
item.description = fixStringForTags(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
} else if (reader->name() == QLatin1String("dependency")) {
@@ -668,6 +675,8 @@ QVariant ExamplesListModel::data(const QModelIndex &index, int role) const
return item.docUrl;
case FilesToOpen:
return item.filesToOpen;
case MainFile:
return item.mainFile;
case Tags:
return item.tags;
case Difficulty:

View File

@@ -74,7 +74,7 @@ private:
enum ExampleRoles
{
Name = Qt::UserRole, ProjectPath, Description, ImageUrl,
DocUrl, FilesToOpen, Tags, Difficulty, HasSourceCode,
DocUrl, FilesToOpen, MainFile, Tags, Difficulty, HasSourceCode,
Type, Dependencies, IsVideo, VideoUrl, VideoLength, Platforms,
IsHighlighted
};
@@ -93,6 +93,7 @@ struct ExampleItem
QString imageUrl;
QString docUrl;
QStringList filesToOpen;
QString mainFile; /* file to be visible after opening filesToOpen */
QStringList tags;
QStringList dependencies;
InstructionalType type;

View File

@@ -380,14 +380,24 @@ QString ExamplesWelcomePage::copyToAlternativeLocation(const QFileInfo& proFileI
}
void ExamplesWelcomePage::openProject(const QString &projectFile, const QStringList &additionalFilesToOpen,
const QUrl &help, const QStringList &dependencies, const QStringList &)
void ExamplesWelcomePage::openProject(const QString &projectFile,
const QStringList &additionalFilesToOpen,
const QString &mainFile,
const QUrl &help,
const QStringList &dependencies,
const QStringList &)
{
QString proFile = projectFile;
if (proFile.isEmpty())
return;
QStringList filesToOpen = additionalFilesToOpen;
if (!mainFile.isEmpty()) {
// ensure that the main file is opened on top (i.e. opened last)
filesToOpen.removeAll(mainFile);
filesToOpen.append(mainFile);
}
QFileInfo proFileInfo(proFile);
if (!proFileInfo.exists())
return;

View File

@@ -64,7 +64,8 @@ public slots:
void openSplitHelp(const QUrl &help);
void openHelp(const QUrl &help);
void openProject(const QString& projectFile, const QStringList& additionalFilesToOpen,
const QUrl& help, const QStringList &dependencies, const QStringList &platforms);
const QString &mainFile, const QUrl& help, const QStringList &dependencies,
const QStringList &platforms);
private:
ExamplesListModel *examplesModel() const;