Automatically configure examples opened from the welcome page.

Each example can now provide a list of platforms by the examples manifest
.xml file. This list can control the target configuration of the example
when it is opened in the welcomepage.

Change-Id: I893230fd2850b7a1272db71a7f589044d52041d1
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Daniel Teske
2012-03-06 13:14:42 +01:00
committed by hjk
parent 4415224f99
commit 6f45ec97f8
16 changed files with 88 additions and 19 deletions

View File

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

View File

@@ -87,8 +87,6 @@ class PROJECTEXPLORER_EXPORT IProjectPanelFactory : public IPanelFactory
public:
virtual bool supports(Project *project) = 0;
virtual PropertiesPanel *createPanel(Project *project) = 0;
signals:
void projectUpdated(ProjectExplorer::Project *project);
};
class PROJECTEXPLORER_EXPORT ITargetPanelFactory : public IPanelFactory

View File

@@ -388,4 +388,9 @@ bool Project::needsConfiguration() const
return false;
}
void Project::configureAsExampleProject(const QStringList &platforms)
{
}
} // namespace ProjectExplorer

View File

@@ -118,6 +118,7 @@ public:
void setNamedSettings(const QString &name, QVariant &value);
virtual bool needsConfiguration() const;
virtual void configureAsExampleProject(const QStringList &platforms);
signals:
void fileListChanged();

View File

@@ -1869,6 +1869,11 @@ void ProjectExplorerPlugin::buildProject(ProjectExplorer::Project *p)
QStringList(QLatin1String(Constants::BUILDSTEPS_BUILD)));
}
void ProjectExplorerPlugin::requestProjectModeUpdate(Project *p)
{
d->m_proWindow->projectUpdated(p);
}
void ProjectExplorerPlugin::buildProject()
{
queue(d->m_session->projectOrder(session()->startupProject()),

View File

@@ -127,6 +127,9 @@ public:
void addExistingFiles(const QStringList &filePaths);
void buildProject(ProjectExplorer::Project *p);
/// Normally there's no need to call this function.
/// This function needs to be called, only if the pages that support a project changed.
void requestProjectModeUpdate(ProjectExplorer::Project *p);
QList<RunControl *> runControls() const;

View File

@@ -268,10 +268,6 @@ void ProjectWindow::extensionsInitialized()
QList<IProjectPanelFactory *> list = ExtensionSystem::PluginManager::instance()->getObjects<IProjectPanelFactory>();
qSort(list.begin(), list.end(), &IPanelFactory::prioritySort);
foreach (IProjectPanelFactory *fac, list)
connect (fac, SIGNAL(projectUpdated(ProjectExplorer::Project*)),
this, SLOT(projectUpdated(ProjectExplorer::Project*)));
}
void ProjectWindow::aboutToShutdown()

View File

@@ -82,6 +82,7 @@ public:
void aboutToShutdown();
void extensionsInitialized();
void projectUpdated(ProjectExplorer::Project *p);
private slots:
void targetFactoriesChanged();
void showProperties(int index, int subIndex);
@@ -90,7 +91,6 @@ private slots:
void registerProject(ProjectExplorer::Project*);
void deregisterProject(ProjectExplorer::Project*);
void startupProjectChanged(ProjectExplorer::Project *);
void projectUpdated(ProjectExplorer::Project *p);
private:
bool useTargetPage(ProjectExplorer::Project *project);

View File

@@ -41,6 +41,8 @@
#include "qt4projectmanagerconstants.h"
#include "qt4buildconfiguration.h"
#include "findqt4profiles.h"
#include "qt4basetargetfactory.h"
#include "buildconfigurationinfo.h"
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
@@ -1334,6 +1336,36 @@ bool Qt4Project::needsConfiguration() const
return targets().isEmpty();
}
void Qt4Project::configureAsExampleProject(const QStringList &platforms)
{
QList<Qt4BaseTargetFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<Qt4BaseTargetFactory>();
foreach (Qt4BaseTargetFactory *factory, factories) {
foreach (const QString &id, factory->supportedTargetIds()) {
QList<BuildConfigurationInfo> infos
= factory->availableBuildConfigurations(id, rootProjectNode()->path(),
QtSupport::QtVersionNumber(),
QtSupport::QtVersionNumber(INT_MAX, INT_MAX, INT_MAX),
Core::FeatureSet());
if (!platforms.isEmpty()) {
QList<BuildConfigurationInfo> filtered;
foreach (const BuildConfigurationInfo &info, infos) {
foreach (const QString &platform, platforms) {
if (info.version()->supportsPlatform(platform)) {
filtered << info;
break;
}
}
}
infos = filtered;
}
if (!infos.isEmpty())
addTarget(factory->create(this, id, infos));
}
}
ProjectExplorer::ProjectExplorerPlugin::instance()->requestProjectModeUpdate(this);
}
/*!
Handle special case were a subproject of the qt directory is opened, and
qt was configured to be built as a shadow build -> also build in the sub-

View File

@@ -140,6 +140,8 @@ public:
bool needsConfiguration() const;
void configureAsExampleProject(const QStringList &platforms);
signals:
void proParsingDone();
void proFileUpdated(Qt4ProjectManager::Qt4ProFileNode *node, bool, bool);

View File

@@ -43,6 +43,7 @@
#include <coreplugin/coreconstants.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/toolchain.h>
#include <QLabel>
@@ -87,8 +88,6 @@ ProjectExplorer::PropertiesPanel *Qt4ProjectManager::Internal::UnconfiguredProje
panel->setIcon(QIcon(":/projectexplorer/images/unconfigured.png"));
TargetSetupPageWrapper *w = new TargetSetupPageWrapper(project);
connect (w, SIGNAL(projectUpdated(ProjectExplorer::Project*)),
this, SIGNAL(projectUpdated(ProjectExplorer::Project*)));
panel->setWidget(w);
return panel;
}
@@ -188,7 +187,7 @@ void TargetSetupPageWrapper::keyReleaseEvent(QKeyEvent *event)
void TargetSetupPageWrapper::done()
{
m_targetSetupPage->setupProject(m_project);
emit projectUpdated(m_project);
ProjectExplorer::ProjectExplorerPlugin::instance()->requestProjectModeUpdate(m_project);
Core::ICore::instance()->modeManager()->activateMode(QLatin1String(Core::Constants::MODE_EDIT));
}

View File

@@ -65,8 +65,6 @@ public:
protected:
void keyReleaseEvent(QKeyEvent *event);
void keyPressEvent(QKeyEvent *event);
signals:
void projectUpdated(ProjectExplorer::Project *project);
private slots:
void done();
void noteTextLinkActivated();

View File

@@ -73,6 +73,7 @@ ExamplesListModel::ExamplesListModel(QObject *parent) :
roleNames[IsVideo] = "isVideo";
roleNames[VideoUrl] = "videoUrl";
roleNames[VideoLength] = "videoLength";
roleNames[Platforms] = "platforms";
setRoleNames(roleNames);
connect(Core::HelpManager::instance(), SIGNAL(setupFinished()),
@@ -91,6 +92,15 @@ static inline QString fixStringForTags(const QString &string)
return returnString;
}
static inline QStringList trimStringList(const QStringList &stringlist)
{
QStringList returnList;
foreach (const QString &string, stringlist)
returnList << string.trimmed();
return returnList;
}
QList<ExampleItem> ExamplesListModel::parseExamples(QXmlStreamReader* reader, const QString& projectsOffset)
{
QList<ExampleItem> examples;
@@ -117,8 +127,10 @@ QList<ExampleItem> ExamplesListModel::parseExamples(QXmlStreamReader* reader, co
} else if (reader->name() == QLatin1String("dependency")) {
item.dependencies.append(projectsOffset + slash + reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
} else if (reader->name() == QLatin1String("tags")) {
item.tags = reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement).split(QLatin1Char(','));
item.tags = trimStringList(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement).split(QLatin1Char(','), QString::SkipEmptyParts));
m_tags.append(item.tags);
} else if (reader->name() == QLatin1String("platforms")) {
item.platforms = trimStringList(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement).split(QLatin1Char(','), QString::SkipEmptyParts));
}
break;
case QXmlStreamReader::EndElement:
@@ -429,6 +441,8 @@ QVariant ExamplesListModel::data(const QModelIndex &index, int role) const
return item.videoUrl;
case VideoLength:
return item.videoLength;
case Platforms:
return item.platforms;
default:
qDebug() << Q_FUNC_INFO << "role type not supported";
return QVariant();

View File

@@ -43,7 +43,7 @@ namespace Internal {
enum ExampleRoles { Name=Qt::UserRole, ProjectPath, Description, ImageUrl,
DocUrl, FilesToOpen, Tags, Difficulty, HasSourceCode,
Type, Dependencies, IsVideo, VideoUrl, VideoLength };
Type, Dependencies, IsVideo, VideoUrl, VideoLength, Platforms };
enum InstructionalType { Example=0, Demo, Tutorial };
@@ -63,6 +63,7 @@ struct ExampleItem {
bool isVideo;
QString videoUrl;
QString videoLength;
QStringList platforms;
};
class ExamplesListModel : public QAbstractListModel {

View File

@@ -44,6 +44,9 @@
#include <coreplugin/icore.h>
#include <coreplugin/helpmanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h>
#include <QMutex>
#include <QThread>
@@ -389,7 +392,7 @@ QString ExamplesWelcomePage::copyToAlternativeLocation(const QFileInfo& proFileI
}
void ExamplesWelcomePage::openProject(const QString &projectFile, const QStringList &additionalFilesToOpen,
const QUrl &help, const QStringList &dependencies)
const QUrl &help, const QStringList &dependencies, const QStringList &platforms)
{
QString proFile = projectFile;
if (proFile.isEmpty())
@@ -403,12 +406,24 @@ void ExamplesWelcomePage::openProject(const QString &projectFile, const QStringL
// don't try to load help and files if loading the help request is being cancelled
QString errorMessage;
if (!proFile.isEmpty() && ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFile, &errorMessage)) {
ProjectExplorer::ProjectExplorerPlugin *peplugin = ProjectExplorer::ProjectExplorerPlugin::instance();
if (!proFile.isEmpty() && peplugin->openProject(proFile, &errorMessage)) {
Core::ICore::openFiles(filesToOpen);
Core::ICore::helpManager()->handleHelpRequest(help.toString()+QLatin1String("?view=split"));
}
if (!errorMessage.isEmpty())
QMessageBox::critical(Core::ICore::mainWindow(), tr("Failed to open project"), errorMessage);
// Configure project for building
ProjectExplorer::Project *project = 0;
foreach (ProjectExplorer::Project *pro, peplugin->session()->projects()) {
if (pro->rootProjectNode()->path() == proFile) {
project = pro;
break;
}
}
if (project && project->needsConfiguration())
project->configureAsExampleProject(platforms);
}
void ExamplesWelcomePage::updateTagsModel()

View File

@@ -88,7 +88,7 @@ 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 QUrl& help, const QStringList &dependencies, const QStringList &platforms);
void updateTagsModel();
private: