Commit e861161a authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Show TargetSelectionPage when opening .pro files

Do this as part of the ProjectLoadWizard
parent ce14eab6
......@@ -30,13 +30,12 @@
#include "projectloadwizard.h"
#include "qt4project.h"
#include "qt4projectmanager.h"
#include "qmakestep.h"
#include "qt4target.h"
#include "makestep.h"
#include "qt4buildconfiguration.h"
#include <extensionsystem/pluginmanager.h>
#include "wizards/targetspage.h"
#include <QtGui/QCheckBox>
#include <QtGui/QHeaderView>
......@@ -48,7 +47,8 @@ using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
ProjectLoadWizard::ProjectLoadWizard(Qt4Project *project, QWidget *parent, Qt::WindowFlags flags)
: QWizard(parent, flags), m_project(project), m_importVersion(0), m_temporaryVersion(false)
: QWizard(parent, flags), m_project(project), m_importVersion(0), m_temporaryVersion(false),
m_targetsPage(0)
{
setWindowTitle(tr("Import existing build settings"));
QtVersionManager * vm = QtVersionManager::instance();
......@@ -88,8 +88,16 @@ ProjectLoadWizard::ProjectLoadWizard(Qt4Project *project, QWidget *parent, Qt::W
// The default buildConfiguration depends on QmakeBuildConfig::DebugBuild
// Also if the qt version is not yet in the Tools Options dialog we offer to add it there
QList<QtVersion *> validVersions;
foreach (QtVersion * v, vm->versions()) {
if (v->isValid())
validVersions.append(v);
}
if (m_importVersion)
setupImportPage(m_importVersion, m_importBuildConfig, m_additionalArguments);
else if (validVersions.count() > 1)
setupTargetsPage();
setOptions(options() | QWizard::NoCancelButton | QWizard::NoBackButtonOnLastPage);
}
......@@ -98,7 +106,7 @@ ProjectLoadWizard::ProjectLoadWizard(Qt4Project *project, QWidget *parent, Qt::W
// We used to simply call ::exec() on the dialog
void ProjectLoadWizard::execDialog()
{
if (m_importVersion)
if (!pageIds().isEmpty())
exec();
else
done(QDialog::Accepted);
......@@ -106,7 +114,6 @@ void ProjectLoadWizard::execDialog()
ProjectLoadWizard::~ProjectLoadWizard()
{
}
void ProjectLoadWizard::done(int result)
......@@ -132,32 +139,39 @@ void ProjectLoadWizard::done(int result)
}
if (m_project->targets().isEmpty())
qWarning() << "Failed to populate project with default targets for imported Qt" << m_importVersion->displayName();
} else {
// Not importing
if (m_temporaryVersion)
delete m_importVersion;
// Find a Qt version:
QList<QtVersion *> candidates = vm->versions();
QtVersion *defaultVersion = candidates.at(0); // always there and always valid!
// Check for the first valid desktop-Qt, fall back to any valid Qt if no desktop
// flavour is available.
foreach (QtVersion *v, candidates) {
if (v->isValid())
defaultVersion = v;
if (v->supportsTargetId(DESKTOP_TARGET_ID) && v->isValid())
break;
}
foreach (const QString &id, defaultVersion->supportedTargetIds()) {
Qt4Target *t(m_project->targetFactory()->create(m_project, id, QList<QtVersion *>() << defaultVersion));
if (!t)
continue;
m_project->addTarget(t);
}
if (m_project->targets().isEmpty())
qWarning() << "Failed to populate project with default targets for default Qt" << defaultVersion->displayName();
return;
}
if (m_targetsPage) {
m_targetsPage->setupProject(m_project);
return;
}
// Not importing anything
if (m_temporaryVersion)
delete m_importVersion;
// Find a Qt version:
QList<QtVersion *> candidates = vm->versions();
QtVersion *defaultVersion = candidates.at(0); // always there and always valid!
// Check for the first valid desktop-Qt, fall back to any valid Qt if no desktop
// flavour is available.
foreach (QtVersion *v, candidates) {
if (v->isValid())
defaultVersion = v;
if (v->supportsTargetId(DESKTOP_TARGET_ID) && v->isValid())
break;
}
foreach (const QString &id, defaultVersion->supportedTargetIds()) {
Qt4Target *t(m_project->targetFactory()->create(m_project, id, QList<QtVersion *>() << defaultVersion));
if (!t)
continue;
m_project->addTarget(t);
}
if (m_project->targets().isEmpty())
qWarning() << "Failed to populate project with default targets for default Qt" << defaultVersion->displayName();
}
// This function used to do the commented stuff instead of having only one page
......@@ -205,3 +219,12 @@ void ProjectLoadWizard::setupImportPage(QtVersion *version, QtVersion::QmakeBuil
addPage(importPage);
}
void ProjectLoadWizard::setupTargetsPage()
{
if (m_targetsPage)
return;
m_targetsPage = new TargetsPage(this);
addPage(m_targetsPage);
}
......@@ -46,6 +46,8 @@ class Qt4Project;
namespace Internal {
class TargetsPage;
class ProjectLoadWizard : public QWizard
{
Q_OBJECT
......@@ -58,6 +60,7 @@ public:
private:
void setupImportPage(QtVersion *version, QtVersion::QmakeBuildConfigs buildConfig, QStringList addtionalArguments);
void setupTargetsPage();
Qt4Project *m_project;
......@@ -75,6 +78,7 @@ private:
QLabel *importLabel;
QLabel *import2Label;
QCheckBox *importCheckbox;
TargetsPage *m_targetsPage;
void setupUi();
};
......
......@@ -30,7 +30,6 @@
#include "qtwizard.h"
#include "qt4project.h"
#include "qt4projectmanager.h"
#include "qt4projectmanagerconstants.h"
#include "qt4target.h"
#include "modulespage.h"
......@@ -109,26 +108,7 @@ bool QtWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l
const BaseQt4ProjectWizardDialog *dialog = qobject_cast<const BaseQt4ProjectWizardDialog *>(w);
// Generate user settings:
QSet<QString> targets;
if (dialog)
targets = dialog->selectedTargets();
if (!targets.isEmpty()) {
Qt4Manager *manager = ExtensionSystem::PluginManager::instance()->getObject<Qt4Manager>();
Q_ASSERT(manager);
QtVersionManager *vm = QtVersionManager::instance();
Qt4Project *pro = new Qt4Project(manager, proFileName);
foreach (const QString &targetId, targets) {
QList<int> versionIds = dialog->selectedQtVersionIdsForTarget(targetId);
QList<QtVersion *> versions;
foreach (int id, versionIds)
versions.append(vm->version(id));
Qt4Target * target = pro->targetFactory()->create(pro, targetId, versions);
pro->addTarget(target);
}
pro->saveSettings();
delete pro;
}
dialog->writeUserFile(proFileName);
// Post-Generate: Open the project
if (!ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFileName)) {
......@@ -256,18 +236,18 @@ void BaseQt4ProjectWizardDialog::setDeselectedModules(const QString &modules)
}
}
QSet<QString> BaseQt4ProjectWizardDialog::selectedTargets() const
void BaseQt4ProjectWizardDialog::writeUserFile(const QString &proFileName) const
{
if (!m_targetsPage)
return QSet<QString>();
return m_targetsPage->selectedTargets();
if (m_targetsPage)
m_targetsPage->writeUserFile(proFileName);
}
QList<int> BaseQt4ProjectWizardDialog::selectedQtVersionIdsForTarget(const QString &target) const
QSet<QString> BaseQt4ProjectWizardDialog::selectedTargets() const
{
if (!m_targetsPage)
return QList<int>();
return m_targetsPage->selectedVersionIdsForTarget(target);
QSet<QString> targets;
if (m_targetsPage)
targets = m_targetsPage->selectedTargets();
return targets;
}
QSet<QString> BaseQt4ProjectWizardDialog::desktopTarget()
......
......@@ -114,8 +114,8 @@ public:
QString deselectedModules() const;
void setDeselectedModules(const QString &);
void writeUserFile(const QString &proFileName) const;
QSet<QString> selectedTargets() const;
QList<int> selectedQtVersionIdsForTarget(const QString &target) const;
private:
inline void init(bool showModulesPage);
......
......@@ -29,9 +29,13 @@
#include "targetspage.h"
#include "qt4projectmanager/qt4project.h"
#include "qt4projectmanager/qt4projectmanager.h"
#include "qt4projectmanager/qt4target.h"
#include "qt4projectmanager/qtversionmanager.h"
#include <extensionsystem/pluginmanager.h>
#include <QtCore/QSet>
#include <QtCore/QString>
......@@ -134,14 +138,14 @@ QSet<QString> TargetsPage::selectedTargets() const
QTreeWidgetItem * targetItem = m_treeWidget->topLevelItem(i);
QString target = targetItem->data(0, Qt::UserRole).toString();
QList<int> versions = selectedVersionIdsForTarget(target);
QList<int> versions = selectedQtVersionIdsForTarget(target);
if (!versions.isEmpty())
result.insert(target);
}
return result;
}
QList<int> TargetsPage::selectedVersionIdsForTarget(const QString &t) const
QList<int> TargetsPage::selectedQtVersionIdsForTarget(const QString &t) const
{
QList<int> result;
for (int i = 0; i < m_treeWidget->topLevelItemCount(); ++i) {
......@@ -186,3 +190,37 @@ bool TargetsPage::needToDisplayPage() const
}
return false;
}
void TargetsPage::writeUserFile(const QString &proFileName) const
{
Qt4Manager *manager = ExtensionSystem::PluginManager::instance()->getObject<Qt4Manager>();
Q_ASSERT(manager);
Qt4Project *pro = new Qt4Project(manager, proFileName);
if (setupProject(pro))
pro->saveSettings();
delete pro;
}
bool TargetsPage::setupProject(Qt4ProjectManager::Qt4Project *project) const
{
if (!project)
return false;
// Generate user settings:
QSet<QString> targets = selectedTargets();
if (targets.isEmpty())
return false;
QtVersionManager *vm = QtVersionManager::instance();
foreach (const QString &targetId, targets) {
QList<int> versionIds = selectedQtVersionIdsForTarget(targetId);
QList<QtVersion *> versions;
foreach (int id, versionIds)
versions.append(vm->version(id));
Qt4Target * target = project->targetFactory()->create(project, targetId, versions);
project->addTarget(target);
}
return true;
}
......@@ -41,6 +41,8 @@ class QTreeWidget;
QT_END_NAMESPACE
namespace Qt4ProjectManager {
class Qt4Project;
namespace Internal {
class TargetsPage : public QWizardPage
......@@ -53,12 +55,15 @@ public:
void setValidTargets(const QSet<QString> &targets);
QSet<QString> selectedTargets() const;
QList<int> selectedVersionIdsForTarget(const QString &) const;
QList<int> selectedQtVersionIdsForTarget(const QString &) const;
bool isComplete() const;
bool needToDisplayPage() const;
void writeUserFile(const QString &proFileName) const;
bool setupProject(Qt4Project *project) const;
private slots:
void itemWasClicked();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment