forked from qt-creator/qt-creator
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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user