From 039a29d50d137ef89537efb9d40164df7eef1bae Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 12 May 2015 13:05:14 +0200 Subject: [PATCH] Qbs: Use TerminalAspect in QbsRunConfiguration Change-Id: I6f1ddec10abda39149dd3743bdff1d0186d1de31 Reviewed-by: Daniel Teske Reviewed-by: Tobias Hunger --- .../runconfigurationaspects.cpp | 9 ++- .../projectexplorer/runconfigurationaspects.h | 2 + .../qbsprojectmanager/qbsrunconfiguration.cpp | 69 +++---------------- .../qbsprojectmanager/qbsrunconfiguration.h | 12 ---- 4 files changed, 18 insertions(+), 74 deletions(-) diff --git a/src/plugins/projectexplorer/runconfigurationaspects.cpp b/src/plugins/projectexplorer/runconfigurationaspects.cpp index 19167c73103..f75b31cd6e7 100644 --- a/src/plugins/projectexplorer/runconfigurationaspects.cpp +++ b/src/plugins/projectexplorer/runconfigurationaspects.cpp @@ -112,6 +112,13 @@ void TerminalAspect::setUseTerminal(bool useTerminal) m_useTerminal = useTerminal; emit useTerminalChanged(useTerminal); } + if (m_checkBox) + m_checkBox->setChecked(m_useTerminal); +} + +bool TerminalAspect::isUserSet() const +{ + return m_userSet; } ApplicationLauncher::Mode TerminalAspect::runMode() const @@ -122,8 +129,6 @@ ApplicationLauncher::Mode TerminalAspect::runMode() const void TerminalAspect::setRunMode(ApplicationLauncher::Mode runMode) { setUseTerminal(runMode == ApplicationLauncher::Console); - if (m_checkBox) - m_checkBox->setChecked(m_useTerminal); } /*! diff --git a/src/plugins/projectexplorer/runconfigurationaspects.h b/src/plugins/projectexplorer/runconfigurationaspects.h index 85a05b0fbae..18a67217714 100644 --- a/src/plugins/projectexplorer/runconfigurationaspects.h +++ b/src/plugins/projectexplorer/runconfigurationaspects.h @@ -65,6 +65,8 @@ public: ApplicationLauncher::Mode runMode() const; void setRunMode(ApplicationLauncher::Mode runMode); + bool isUserSet() const; + signals: void useTerminalChanged(bool); diff --git a/src/plugins/qbsprojectmanager/qbsrunconfiguration.cpp b/src/plugins/qbsprojectmanager/qbsrunconfiguration.cpp index 7bcdb2b9a5b..ede7456db90 100644 --- a/src/plugins/qbsprojectmanager/qbsrunconfiguration.cpp +++ b/src/plugins/qbsprojectmanager/qbsrunconfiguration.cpp @@ -70,7 +70,6 @@ namespace QbsProjectManager { namespace Internal { const char QBS_RC_PREFIX[] = "Qbs.RunConfiguration:"; -const char USE_TERMINAL_KEY[] = "Qbs.RunConfiguration.UseTerminal"; static QString rcNameSeparator() { return QLatin1String("---Qbs.RC.NameSeparator---"); } @@ -113,7 +112,6 @@ const qbs::ProductData findProduct(const qbs::ProjectData &pro, const QString &u QbsRunConfiguration::QbsRunConfiguration(Target *parent, Core::Id id) : LocalApplicationRunConfiguration(parent, id), m_uniqueProductName(uniqueProductNameFromId(id)), - m_runMode(ApplicationLauncher::Gui), m_currentInstallStep(0), m_currentBuildStepList(0) { @@ -121,8 +119,9 @@ QbsRunConfiguration::QbsRunConfiguration(Target *parent, Core::Id id) : addExtraAspect(new ArgumentsAspect(this, QStringLiteral("Qbs.RunConfiguration.CommandLineArguments"))); addExtraAspect(new WorkingDirectoryAspect(this, QStringLiteral("Qbs.RunConfiguration.WorkingDirectory"))); - m_runModeForced = false; - m_runMode = isConsoleApplication() ? ApplicationLauncher::Console : ApplicationLauncher::Gui; + addExtraAspect(new TerminalAspect(this, + QStringLiteral("Qbs.RunConfiguration.UseTerminal"), + isConsoleApplication())); ctor(); } @@ -130,8 +129,6 @@ QbsRunConfiguration::QbsRunConfiguration(Target *parent, Core::Id id) : QbsRunConfiguration::QbsRunConfiguration(Target *parent, QbsRunConfiguration *source) : LocalApplicationRunConfiguration(parent, source), m_uniqueProductName(source->m_uniqueProductName), - m_runMode(source->m_runMode), - m_runModeForced(source->m_runModeForced), m_currentInstallStep(0), // no need to copy this, we will get if from the DC anyway. m_currentBuildStepList(0) // ditto { @@ -162,9 +159,9 @@ void QbsRunConfiguration::ctor() QbsProject *project = static_cast(target()->project()); connect(project, &QbsProject::projectParsingStarted, this, &RunConfiguration::enabledChanged); connect(project, &QbsProject::projectParsingDone, this, [this](bool success) { - if (success && !m_runModeForced) - m_runMode = isConsoleApplication() ? ApplicationLauncher::Console - : ApplicationLauncher::Gui; + auto terminalAspect = extraAspect(); + if (success && !terminalAspect->isUserSet()) + terminalAspect->setUseTerminal(isConsoleApplication()); emit enabledChanged(); }); @@ -178,25 +175,6 @@ QWidget *QbsRunConfiguration::createConfigurationWidget() return new QbsRunConfigurationWidget(this, 0); } -QVariantMap QbsRunConfiguration::toMap() const -{ - QVariantMap map(LocalApplicationRunConfiguration::toMap()); - if (m_runModeForced) - map.insert(QLatin1String(USE_TERMINAL_KEY), m_runMode == ApplicationLauncher::Console); - return map; -} - -bool QbsRunConfiguration::fromMap(const QVariantMap &map) -{ - if (map.contains(QLatin1String(USE_TERMINAL_KEY))) { - m_runMode = map.value(QLatin1String(USE_TERMINAL_KEY), false).toBool() ? - ApplicationLauncher::Console : ApplicationLauncher::Gui; - m_runModeForced = true; - } - - return RunConfiguration::fromMap(map); -} - void QbsRunConfiguration::installStepChanged() { if (m_currentInstallStep) @@ -249,7 +227,7 @@ QString QbsRunConfiguration::executable() const ApplicationLauncher::Mode QbsRunConfiguration::runMode() const { - return m_runMode; + return extraAspect()->runMode(); } bool QbsRunConfiguration::isConsoleApplication() const @@ -301,12 +279,7 @@ void QbsRunConfiguration::setBaseWorkingDirectory(const QString &wd) void QbsRunConfiguration::setRunMode(ApplicationLauncher::Mode runMode) { - if (m_runMode == runMode) - return; - - m_runModeForced = true; - m_runMode = runMode; - emit runModeChanged(runMode); + extraAspect()->setRunMode(runMode); } void QbsRunConfiguration::addToBaseEnvironment(Utils::Environment &env) const @@ -406,20 +379,10 @@ QbsRunConfigurationWidget::QbsRunConfigurationWidget(QbsRunConfiguration *rc, QW m_rc->extraAspect()->addToMainConfigurationWidget(this, toplayout); m_rc->extraAspect()->addToMainConfigurationWidget(this, toplayout); - QHBoxLayout *innerBox = new QHBoxLayout(); - m_useTerminalCheck = new QCheckBox(tr("Run in terminal"), this); - innerBox->addWidget(m_useTerminalCheck); - - innerBox->addStretch(); - toplayout->addRow(QString(), innerBox); + m_rc->extraAspect()->addToMainConfigurationWidget(this, toplayout); runConfigurationEnabledChange(); - connect(m_useTerminalCheck, SIGNAL(toggled(bool)), - this, SLOT(termToggled(bool))); - - connect(m_rc, SIGNAL(runModeChanged(ProjectExplorer::ApplicationLauncher::Mode)), - this, SLOT(runModeChanged(ProjectExplorer::ApplicationLauncher::Mode))); connect(m_rc, SIGNAL(targetInformationChanged()), this, SLOT(targetInformationHasChanged()), Qt::QueuedConnection); @@ -434,17 +397,9 @@ void QbsRunConfigurationWidget::runConfigurationEnabledChange() m_disabledReason->setVisible(!enabled); m_disabledReason->setText(m_rc->disabledReason()); - m_useTerminalCheck->setChecked(m_rc->runMode() == ApplicationLauncher::Console); targetInformationHasChanged(); } -void QbsRunConfigurationWidget::termToggled(bool on) -{ - m_ignoreChange = true; - m_rc->setRunMode(on ? ApplicationLauncher::Console : ApplicationLauncher::Gui); - m_ignoreChange = false; -} - void QbsRunConfigurationWidget::targetInformationHasChanged() { m_ignoreChange = true; @@ -462,12 +417,6 @@ void QbsRunConfigurationWidget::setExecutableLineText(const QString &text) m_executableLineLabel->setText(newText); } -void QbsRunConfigurationWidget::runModeChanged(ApplicationLauncher::Mode runMode) -{ - if (!m_ignoreChange) - m_useTerminalCheck->setChecked(runMode == ApplicationLauncher::Console); -} - // -------------------------------------------------------------------- // QbsRunConfigurationFactory: // -------------------------------------------------------------------- diff --git a/src/plugins/qbsprojectmanager/qbsrunconfiguration.h b/src/plugins/qbsprojectmanager/qbsrunconfiguration.h index f0f8f5eebe0..d6e2be2f23b 100644 --- a/src/plugins/qbsprojectmanager/qbsrunconfiguration.h +++ b/src/plugins/qbsprojectmanager/qbsrunconfiguration.h @@ -82,8 +82,6 @@ public: QString workingDirectory() const; QString commandLineArguments() const; - QVariantMap toMap() const; - Utils::OutputFormatter *createOutputFormatter() const; void setRunMode(ProjectExplorer::ApplicationLauncher::Mode runMode); @@ -95,13 +93,11 @@ public: signals: void baseWorkingDirectoryChanged(const QString&); - void runModeChanged(ProjectExplorer::ApplicationLauncher::Mode runMode); void targetInformationChanged(); void usingDyldImageSuffixChanged(bool); protected: QbsRunConfiguration(ProjectExplorer::Target *parent, QbsRunConfiguration *source); - bool fromMap(const QVariantMap &map); private slots: void installStepChanged(); @@ -121,8 +117,6 @@ private: QString m_uniqueProductName; // Cached startup sub project information - ProjectExplorer::ApplicationLauncher::Mode m_runMode; - bool m_runModeForced; QbsInstallStep *m_currentInstallStep; // We do not take ownership! ProjectExplorer::BuildStepList *m_currentBuildStepList; // We do not take ownership! @@ -137,11 +131,6 @@ public: private slots: void runConfigurationEnabledChange(); - void runModeChanged(ProjectExplorer::ApplicationLauncher::Mode runMode); - - void termToggled(bool); - -private slots: void targetInformationHasChanged(); private: @@ -152,7 +141,6 @@ private: QLabel *m_disabledIcon; QLabel *m_disabledReason; QLabel *m_executableLineLabel; - QCheckBox *m_useTerminalCheck; QCheckBox *m_usingDyldImageSuffix; QLineEdit *m_qmlDebugPort; Utils::DetailsWidget *m_detailsContainer;