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) if (model.isVideo)
gettingStarted.openUrl(model.videoUrl); gettingStarted.openUrl(model.videoUrl);
else if (model.hasSourceCode) 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 else
gettingStarted.openSplitHelp(model.docUrl); gettingStarted.openSplitHelp(model.docUrl);
} }

View File

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

View File

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

View File

@@ -380,14 +380,24 @@ QString ExamplesWelcomePage::copyToAlternativeLocation(const QFileInfo& proFileI
} }
void ExamplesWelcomePage::openProject(const QString &projectFile, const QStringList &additionalFilesToOpen, void ExamplesWelcomePage::openProject(const QString &projectFile,
const QUrl &help, const QStringList &dependencies, const QStringList &) const QStringList &additionalFilesToOpen,
const QString &mainFile,
const QUrl &help,
const QStringList &dependencies,
const QStringList &)
{ {
QString proFile = projectFile; QString proFile = projectFile;
if (proFile.isEmpty()) if (proFile.isEmpty())
return; return;
QStringList filesToOpen = additionalFilesToOpen; 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); QFileInfo proFileInfo(proFile);
if (!proFileInfo.exists()) if (!proFileInfo.exists())
return; return;

View File

@@ -64,7 +64,8 @@ public slots:
void openSplitHelp(const QUrl &help); void openSplitHelp(const QUrl &help);
void openHelp(const QUrl &help); void openHelp(const QUrl &help);
void openProject(const QString& projectFile, const QStringList& additionalFilesToOpen, 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: private:
ExamplesListModel *examplesModel() const; ExamplesListModel *examplesModel() const;