diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2010-11-29 12:50:44 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2010-11-29 14:18:11 +0100 |
commit | e398225cd002c65372035ff2c8c9b5ea5ac8d4bf (patch) | |
tree | 96efc33a1b01d98918305c2c7aa3419159b6f743 | |
parent | b1ce0af3f5ae8de48b98785948d80af6f09ebb00 (diff) | |
download | qt-creator-e398225cd002c65372035ff2c8c9b5ea5ac8d4bf.tar.gz |
QmlProject: Allow user to change process environment
Task-number: QTCREATORBUG-2600
6 files changed, 211 insertions, 15 deletions
diff --git a/src/plugins/qmlprojectmanager/qmlprojectmanagerconstants.h b/src/plugins/qmlprojectmanager/qmlprojectmanagerconstants.h index b028af50d0..6cd599cf80 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectmanagerconstants.h +++ b/src/plugins/qmlprojectmanager/qmlprojectmanagerconstants.h @@ -39,6 +39,9 @@ const char * const QML_VIEWER_ARGUMENTS_KEY = "QmlProjectManager.QmlRunConfigura const char * const QML_VIEWER_TARGET_ID = "QmlProjectManager.QmlTarget"; const char * const QML_VIEWER_TARGET_DISPLAY_NAME = "QML Viewer"; const char * const QML_MAINSCRIPT_KEY = "QmlProjectManager.QmlRunConfiguration.MainScript"; +const char * const USER_ENVIRONMENT_CHANGES_KEY("QmlProjectManager.QmlRunConfiguration.UserEnvironmentChanges"); +const char * const BASE_ENVIRONMENT_BASE_KEY("QmlProjectManager.QmlRunConfiguration.BaseEnvironmentBase"); + } // namespace Constants } // namespace QmlProjectManager diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp index 4de5c80c96..7cac48a2b4 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp @@ -57,7 +57,8 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(QmlProjectTarget *parent) m_qtVersionId(-1), m_projectTarget(parent), m_usingCurrentFile(true), - m_isEnabled(false) + m_isEnabled(false), + m_baseEnvironmentBase(BuildEnvironmentBase) { ctor(); updateQtVersions(); @@ -68,7 +69,9 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(QmlProjectTarget *parent, ProjectExplorer::RunConfiguration(parent, source), m_qtVersionId(source->m_qtVersionId), m_qmlViewerArgs(source->m_qmlViewerArgs), - m_projectTarget(parent) + m_projectTarget(parent), + m_userEnvironmentChanges(source->m_userEnvironmentChanges), + m_baseEnvironmentBase(source->m_baseEnvironmentBase) { ctor(); setMainScript(source->m_scriptFile); @@ -215,6 +218,13 @@ void QmlProjectRunConfiguration::setMainScript(const QString &scriptFile) } } +Utils::Environment QmlProjectRunConfiguration::environment() const +{ + Utils::Environment env = baseEnvironment(); + env.modify(userEnvironmentChanges()); + return env; +} + QVariantMap QmlProjectRunConfiguration::toMap() const { QVariantMap map(ProjectExplorer::RunConfiguration::toMap()); @@ -222,6 +232,10 @@ QVariantMap QmlProjectRunConfiguration::toMap() const map.insert(QLatin1String(Constants::QML_VIEWER_QT_KEY), m_qtVersionId); map.insert(QLatin1String(Constants::QML_VIEWER_ARGUMENTS_KEY), m_qmlViewerArgs); map.insert(QLatin1String(Constants::QML_MAINSCRIPT_KEY), m_scriptFile); + map.insert(QLatin1String(Constants::USER_ENVIRONMENT_CHANGES_KEY), + Utils::EnvironmentItem::toStringList(m_userEnvironmentChanges)); + map.insert(QLatin1String(Constants::BASE_ENVIRONMENT_BASE_KEY), + static_cast<int>(m_baseEnvironmentBase)); return map; } @@ -230,6 +244,14 @@ bool QmlProjectRunConfiguration::fromMap(const QVariantMap &map) setQtVersionId(map.value(QLatin1String(Constants::QML_VIEWER_QT_KEY), -1).toInt()); m_qmlViewerArgs = map.value(QLatin1String(Constants::QML_VIEWER_ARGUMENTS_KEY)).toString(); m_scriptFile = map.value(QLatin1String(Constants::QML_MAINSCRIPT_KEY), M_CURRENT_FILE).toString(); + m_userEnvironmentChanges = Utils::EnvironmentItem::fromStringList( + map.value(QLatin1String(Constants::USER_ENVIRONMENT_CHANGES_KEY)).toStringList()); + m_baseEnvironmentBase + = static_cast<BaseEnvironmentBase>( + map.value(QLatin1String(Constants::BASE_ENVIRONMENT_BASE_KEY), + static_cast<int>(BuildEnvironmentBase)).toInt()); + + updateQtVersions(); setMainScript(m_scriptFile); @@ -317,4 +339,48 @@ bool QmlProjectRunConfiguration::isValidVersion(Qt4ProjectManager::QtVersion *ve return false; } +Utils::Environment QmlProjectRunConfiguration::baseEnvironment() const +{ + Utils::Environment env; + + if (m_baseEnvironmentBase == QmlProjectRunConfiguration::CleanEnvironmentBase) { + // Nothing + } else if (m_baseEnvironmentBase == QmlProjectRunConfiguration::SystemEnvironmentBase) { + env = Utils::Environment::systemEnvironment(); + } else if (m_baseEnvironmentBase == QmlProjectRunConfiguration::BuildEnvironmentBase) { + env = qtVersion()->qmlToolsEnvironment(); + } + return env; +} + +void QmlProjectRunConfiguration::setBaseEnvironmentBase(BaseEnvironmentBase env) +{ + if (m_baseEnvironmentBase == env) + return; + m_baseEnvironmentBase = env; + if (m_configurationWidget) + m_configurationWidget.data()->baseEnvironmentChanged(); +} + +QmlProjectRunConfiguration::BaseEnvironmentBase +QmlProjectRunConfiguration::baseEnvironmentBase() const +{ + return m_baseEnvironmentBase; +} + +void QmlProjectRunConfiguration::setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff) +{ + if (m_userEnvironmentChanges != diff) { + m_userEnvironmentChanges = diff; + if (m_configurationWidget) + m_configurationWidget.data()->userEnvironmentChangesChanged(); + } +} + +QList<Utils::EnvironmentItem> QmlProjectRunConfiguration::userEnvironmentChanges() const +{ + return m_userEnvironmentChanges; +} + + } // namespace QmlProjectManager diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h index 46a362e681..5319cd1363 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h +++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h @@ -42,6 +42,11 @@ namespace Core { class IEditor; } +namespace Utils { + class Environment; + class EnvironmentItem; +} + namespace Qt4ProjectManager { class QtVersion; } @@ -79,6 +84,8 @@ public: QString mainScript() const; void setMainScript(const QString &scriptFile); + Utils::Environment environment() const; + // RunConfiguration bool isEnabled(ProjectExplorer::BuildConfiguration *bc) const; virtual QWidget *createConfigurationWidget(); @@ -103,6 +110,16 @@ private: static bool isValidVersion(Qt4ProjectManager::QtVersion *version); void setQtVersionId(int id); + Utils::Environment baseEnvironment() const; + enum BaseEnvironmentBase { CleanEnvironmentBase = 0, + SystemEnvironmentBase = 1, + BuildEnvironmentBase = 2}; + + void setBaseEnvironmentBase(BaseEnvironmentBase env); + BaseEnvironmentBase baseEnvironmentBase() const; + void setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff); + QList<Utils::EnvironmentItem> userEnvironmentChanges() const; + // absolute path to current file (if being used) QString m_currentFileFilename; // absolute path to selected main script (if being used) @@ -117,6 +134,9 @@ private: bool m_usingCurrentFile; bool m_isEnabled; + + QList<Utils::EnvironmentItem> m_userEnvironmentChanges; + BaseEnvironmentBase m_baseEnvironmentBase; }; } // namespace QmlProjectManager diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationwidget.cpp b/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationwidget.cpp index f27665858a..694650bc9e 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationwidget.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationwidget.cpp @@ -33,6 +33,7 @@ #include "qmlproject.h" #include <coreplugin/icore.h> +#include <projectexplorer/environmenteditmodel.h> #include <projectexplorer/projectexplorer.h> #include <utils/debuggerlanguagechooser.h> #include <utils/detailswidget.h> @@ -58,6 +59,12 @@ QmlProjectRunConfigurationWidget::QmlProjectRunConfigurationWidget(QmlProjectRun m_fileListCombo(0), m_fileListModel(new QStringListModel(this)) { + QVBoxLayout *layout = new QVBoxLayout(this); + + // + // Qt Version, Arguments + // + Utils::DetailsWidget *detailsWidget = new Utils::DetailsWidget(); detailsWidget->setState(Utils::DetailsWidget::NoSummary); @@ -68,7 +75,6 @@ QmlProjectRunConfigurationWidget::QmlProjectRunConfigurationWidget(QmlProjectRun m_fileListCombo = new QComboBox; m_fileListCombo->setModel(m_fileListModel); - updateFileComboBox(); connect(m_fileListCombo, SIGNAL(activated(QString)), this, SLOT(setMainScript(QString))); connect(ProjectExplorer::ProjectExplorerPlugin::instance(), SIGNAL(fileListChanged()), @@ -93,6 +99,16 @@ QmlProjectRunConfigurationWidget::QmlProjectRunConfigurationWidget(QmlProjectRun form->addRow(tr("Qt version:"), qtVersionLayout); form->addRow(tr("Arguments:"), qmlViewerArgs); + form->addRow(tr("Main QML file:"), m_fileListCombo); + + layout->addWidget(detailsWidget); + + updateFileComboBox(); + updateQtVersionComboBox(); + + // + // Debugging + // QWidget *debuggerLabelWidget = new QWidget; QVBoxLayout *debuggerLabelLayout = new QVBoxLayout(debuggerLabelWidget); @@ -104,8 +120,6 @@ QmlProjectRunConfigurationWidget::QmlProjectRunConfigurationWidget(QmlProjectRun debuggerLabelLayout->addStretch(10); DebuggerLanguageChooser *debuggerLanguageChooser = new DebuggerLanguageChooser(formWidget); - - form->addRow(tr("Main QML file:"), m_fileListCombo); form->addRow(debuggerLabelWidget, debuggerLanguageChooser); debuggerLanguageChooser->setCppChecked(rc->useCppDebugger()); @@ -123,10 +137,45 @@ QmlProjectRunConfigurationWidget::QmlProjectRunConfigurationWidget(QmlProjectRun connect(qtVersions, SIGNAL(qtVersionsChanged(QList<int>)), this, SLOT(updateQtVersionComboBox())); - updateQtVersionComboBox(); - - QVBoxLayout *layout = new QVBoxLayout(this); - layout->addWidget(detailsWidget); + // + // Environment + // + + QLabel *environmentLabel = new QLabel(this); + environmentLabel->setText(tr("Run Environment")); + QFont f = environmentLabel->font(); + f.setBold(true); + f.setPointSizeF(f.pointSizeF() *1.2); + environmentLabel->setFont(f); + + layout->addWidget(environmentLabel); + + QWidget *baseEnvironmentWidget = new QWidget; + QHBoxLayout *baseEnvironmentLayout = new QHBoxLayout(baseEnvironmentWidget); + baseEnvironmentLayout->setMargin(0); + QLabel *label = new QLabel(tr("Base environment for this runconfiguration:"), this); + baseEnvironmentLayout->addWidget(label); + m_baseEnvironmentComboBox = new QComboBox(this); + m_baseEnvironmentComboBox->addItems(QStringList() + << tr("Clean Environment") + << tr("System Environment") + << tr("Build Environment")); + m_baseEnvironmentComboBox->setCurrentIndex(rc->baseEnvironmentBase()); + connect(m_baseEnvironmentComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(baseEnvironmentSelected(int))); + baseEnvironmentLayout->addWidget(m_baseEnvironmentComboBox); + baseEnvironmentLayout->addStretch(10); + + m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this, baseEnvironmentWidget); + m_environmentWidget->setBaseEnvironment(rc->baseEnvironment()); + m_environmentWidget->setBaseEnvironmentText(baseEnvironmentText()); + m_environmentWidget->setUserChanges(rc->userEnvironmentChanges()); + + connect(m_environmentWidget, SIGNAL(userChangesChanged()), + this, SLOT(userChangesChanged())); + + + layout->addWidget(m_environmentWidget); } static bool caseInsensitiveLessThan(const QString &s1, const QString &s2) @@ -228,6 +277,51 @@ void QmlProjectRunConfigurationWidget::updateQtVersionComboBox() } } +void QmlProjectRunConfigurationWidget::userChangesChanged() +{ + m_runConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges()); +} + +void QmlProjectRunConfigurationWidget::baseEnvironmentChanged() +{ +// if (m_ignoreChange) +// return; + + int index = QmlProjectRunConfiguration::BaseEnvironmentBase( + m_runConfiguration->baseEnvironmentBase()); + m_baseEnvironmentComboBox->setCurrentIndex(index); + m_environmentWidget->setBaseEnvironment(m_runConfiguration->baseEnvironment()); + m_environmentWidget->setBaseEnvironmentText(baseEnvironmentText()); +} + +void QmlProjectRunConfigurationWidget::userEnvironmentChangesChanged() +{ + m_environmentWidget->setUserChanges(m_runConfiguration->userEnvironmentChanges()); +} + +void QmlProjectRunConfigurationWidget::baseEnvironmentSelected(int index) +{ +// m_ignoreChange = true; + m_runConfiguration->setBaseEnvironmentBase( + QmlProjectRunConfiguration::BaseEnvironmentBase(index)); + + m_environmentWidget->setBaseEnvironment(m_runConfiguration->baseEnvironment()); + m_environmentWidget->setBaseEnvironmentText(baseEnvironmentText()); +// m_ignoreChange = false; +} + +QString QmlProjectRunConfigurationWidget::baseEnvironmentText() const +{ + if (m_runConfiguration->m_baseEnvironmentBase + == QmlProjectRunConfiguration::CleanEnvironmentBase) { + return tr("Clean Environment"); + } else if (m_runConfiguration->m_baseEnvironmentBase + == QmlProjectRunConfiguration::SystemEnvironmentBase) { + return tr("System Environment"); + } else { + return tr("Build Environment"); + } +} } // namespace Internal } // namespace QmlProjectManager diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationwidget.h b/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationwidget.h index 2cee2f051c..ca156355d2 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationwidget.h +++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfigurationwidget.h @@ -35,6 +35,12 @@ QT_FORWARD_DECLARE_CLASS(QComboBox); QT_FORWARD_DECLARE_CLASS(QStringListModel); +namespace ProjectExplorer { + +class EnvironmentWidget; + +} // namespace Qt4ProjectManager + namespace QmlProjectManager { class QmlProjectRunConfiguration; @@ -51,6 +57,8 @@ public: public slots: void updateQtVersionComboBox(); + void baseEnvironmentChanged(); + void userEnvironmentChangesChanged(); private slots: void updateFileComboBox(); @@ -62,14 +70,23 @@ private slots: void useQmlDebuggerToggled(bool toggled); void qmlDebugServerPortChanged(uint port); + void userChangesChanged(); + void baseEnvironmentSelected(int index); + void manageQtVersions(); private: + QString baseEnvironmentText() const; + + QmlProjectRunConfiguration *m_runConfiguration; QComboBox *m_qtVersionComboBox; QComboBox *m_fileListCombo; QStringListModel *m_fileListModel; + + ProjectExplorer::EnvironmentWidget *m_environmentWidget; + QComboBox *m_baseEnvironmentComboBox; }; } // namespace Internal diff --git a/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp b/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp index cfaf92e77d..a76c374bd8 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectruncontrol.cpp @@ -64,10 +64,7 @@ namespace Internal { QmlRunControl::QmlRunControl(QmlProjectRunConfiguration *runConfiguration, QString mode) : RunControl(runConfiguration, mode) { - if (Qt4ProjectManager::QtVersion *qtVersion = runConfiguration->qtVersion()) - m_applicationLauncher.setEnvironment(qtVersion->qmlToolsEnvironment()); - else - m_applicationLauncher.setEnvironment(Utils::Environment::systemEnvironment()); + m_applicationLauncher.setEnvironment(runConfiguration->environment()); m_applicationLauncher.setWorkingDirectory(runConfiguration->workingDirectory()); if (mode == ProjectExplorer::Constants::RUNMODE) { @@ -206,8 +203,7 @@ ProjectExplorer::RunControl *QmlRunControlFactory::createDebugRunControl(QmlProj Utils::QtcProcess::addArg(¶ms.processArgs, QLatin1String("-qmljsdebugger=port:") + QString::number(runConfig->qmlDebugServerPort())); params.workingDirectory = runConfig->workingDirectory(); - if (Qt4ProjectManager::QtVersion *qtVersion = runConfig->qtVersion()) - params.environment = qtVersion->qmlToolsEnvironment(); + params.environment = runConfig->environment(); params.displayName = runConfig->displayName(); if (params.executable.isEmpty()) { |