/*************************************************************************** ** ** This file is part of Qt Creator ** ** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). ** ** Contact: Qt Software Information (qt-info@nokia.com) ** ** ** Non-Open Source Usage ** ** Licensees may use this file in accordance with the Qt Beta Version ** License Agreement, Agreement version 2.2 provided with the Software or, ** alternatively, in accordance with the terms contained in a written ** agreement between you and Nokia. ** ** GNU General Public License Usage ** ** Alternatively, this file may be used under the terms of the GNU General ** Public License versions 2.0 or 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the packaging ** of this file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and ** http://www.gnu.org/copyleft/gpl.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt GPL Exception ** version 1.3, included in the file GPL_EXCEPTION.txt in this package. ** ***************************************************************************/ #include "runsettingspropertiespage.h" #include "runconfiguration.h" #include "ui_runsettingspropertiespage.h" #include #include #include #include namespace ProjectExplorer { namespace Internal { struct FactoryAndType { ProjectExplorer::IRunConfigurationFactory *factory; QString type; }; } // namespace Internal } // namespace ProjectExplorer Q_DECLARE_METATYPE(ProjectExplorer::Internal::FactoryAndType); namespace ProjectExplorer { namespace Internal { /*! A model to represent the run configurations of a project. */ class RunConfigurationsModel : public QAbstractListModel { public: RunConfigurationsModel(QObject *parent = 0) : QAbstractListModel(parent) {} int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; void setRunConfigurations(const QList > &runConfigurations); void nameChanged(RunConfiguration *rc); private: QList > m_runConfigurations; }; } // namespace Internal } // namespace ProjectExplorer using namespace ProjectExplorer; using namespace ProjectExplorer::Internal; using ExtensionSystem::PluginManager; /// /// RunSettingsPanelFactory /// bool RunSettingsPanelFactory::supports(Project * /* project */) { return true; } PropertiesPanel *RunSettingsPanelFactory::createPanel(Project *project) { return new RunSettingsPanel(project); } /// /// RunSettingsPanel /// RunSettingsPanel::RunSettingsPanel(Project *project) : PropertiesPanel(), m_widget(new RunSettingsWidget(project)) { } RunSettingsPanel::~RunSettingsPanel() { delete m_widget; } QString RunSettingsPanel::name() const { return tr("Run Settings"); } QWidget *RunSettingsPanel::widget() { return m_widget; } /// /// RunConfigurationsModel /// int RunConfigurationsModel::rowCount(const QModelIndex &parent) const { return parent.isValid() ? 0 : m_runConfigurations.size(); } int RunConfigurationsModel::columnCount(const QModelIndex &parent) const { return parent.isValid() ? 0 : 1; } void RunConfigurationsModel::nameChanged(RunConfiguration *rc) { for (int i = 0; i c = m_runConfigurations.at(row); return c->name(); } } return QVariant(); } void RunConfigurationsModel::setRunConfigurations(const QList > &runConfigurations) { m_runConfigurations = runConfigurations; reset(); } /// /// RunSettingsWidget /// RunSettingsWidget::RunSettingsWidget(Project *project) : m_project(project), m_runConfigurationsModel(new RunConfigurationsModel(this)), m_runConfigurationWidget(0) { m_ui = new Ui::RunSettingsPropertiesPage; m_ui->setupUi(this); m_addMenu = new QMenu(m_ui->addToolButton); m_ui->addToolButton->setIcon(QIcon(":/qworkbench/images/plus.png")); m_ui->addToolButton->setMenu(m_addMenu); m_ui->removeToolButton->setIcon(QIcon(":/qworkbench/images/minus.png")); m_ui->runConfigurationCombo->setModel(m_runConfigurationsModel); connect(m_addMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowAddMenu())); connect(m_ui->runConfigurationCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(activateRunConfiguration(int))); connect(m_ui->removeToolButton, SIGNAL(clicked(bool)), this, SLOT(removeRunConfiguration())); initRunConfigurationComboBox(); const QList > runConfigurations = m_project->runConfigurations(); for (int i=0; i runners = PluginManager::instance()->getObjects(); foreach (IRunConfigurationRunner * runner, runners) { if (runner->canRun(activeRunConfiguration)) m_ui->layout->addWidget(runner->configurationWidget(activeRunConfiguration)); } */ } RunSettingsWidget::~RunSettingsWidget() { delete m_ui; } void RunSettingsWidget::aboutToShowAddMenu() { m_addMenu->clear(); QList factories = ExtensionSystem::PluginManager::instance()->getObjects(); foreach (IRunConfigurationFactory *factory, factories) { QStringList types = factory->canCreate(m_project); foreach (const QString &type, types) { QAction *action = m_addMenu->addAction(factory->nameForType(type));; FactoryAndType fat; fat.factory = factory; fat.type = type; QVariant v; v.setValue(fat); action->setData(v); connect(action, SIGNAL(triggered()), this, SLOT(addRunConfiguration())); } } } void RunSettingsWidget::addRunConfiguration() { QAction *act = qobject_cast(sender()); if (!act) return; FactoryAndType fat = act->data().value(); QSharedPointer newRC = fat.factory->create(m_project, fat.type); if (!newRC) return; m_project->addRunConfiguration(newRC); m_project->setActiveRunConfiguration(newRC); initRunConfigurationComboBox(); connect(newRC.data(), SIGNAL(nameChanged()), this, SLOT(nameChanged())); } void RunSettingsWidget::removeRunConfiguration() { int index = m_ui->runConfigurationCombo->currentIndex(); QSharedPointer rc = m_project->runConfigurations().at(index); disconnect(rc.data(), SIGNAL(nameChanged()), this, SLOT(nameChanged())); m_project->removeRunConfiguration(rc); initRunConfigurationComboBox(); } void RunSettingsWidget::initRunConfigurationComboBox() { const QList > runConfigurations = m_project->runConfigurations(); QSharedPointer activeRunConfiguration = m_project->activeRunConfiguration(); m_runConfigurationsModel->setRunConfigurations(runConfigurations); // Make sure the active run configuration is selected in the combo for (int i = 0; i < runConfigurations.size(); ++i) { if (runConfigurations.at(i) == activeRunConfiguration) m_ui->runConfigurationCombo->setCurrentIndex(i); } m_ui->removeToolButton->setEnabled(runConfigurations.size() > 1); } void RunSettingsWidget::activateRunConfiguration(int index) { QTC_ASSERT(m_project, return); const QList > runConfigurations = m_project->runConfigurations(); QTC_ASSERT(index < runConfigurations.size(), return); QSharedPointer selectedRunConfiguration = runConfigurations.at(index); // Change the active run configuration of the project m_project->setActiveRunConfiguration(selectedRunConfiguration); // Update the run configuration configuration widget delete m_runConfigurationWidget; m_runConfigurationWidget = selectedRunConfiguration->configurationWidget(); m_ui->groupBox->layout()->addWidget(m_runConfigurationWidget); } void RunSettingsWidget::nameChanged() { RunConfiguration *rc = qobject_cast(sender()); m_runConfigurationsModel->nameChanged(rc); }