2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at qt-sales@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "runsettingspropertiespage.h"
|
|
|
|
|
#include "runconfiguration.h"
|
|
|
|
|
|
|
|
|
|
#include "ui_runsettingspropertiespage.h"
|
|
|
|
|
|
2009-01-12 15:06:43 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <QtCore/QDebug>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QPair>
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
namespace Internal {
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
struct FactoryAndType
|
|
|
|
|
{
|
|
|
|
|
ProjectExplorer::IRunConfigurationFactory *factory;
|
|
|
|
|
QString type;
|
|
|
|
|
};
|
2008-12-09 15:25:01 +01:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ProjectExplorer
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
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<QSharedPointer<RunConfiguration> > &runConfigurations);
|
|
|
|
|
void nameChanged(RunConfiguration *rc);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QList<QSharedPointer<RunConfiguration> > 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<m_runConfigurations.size(); ++i) {
|
|
|
|
|
if (m_runConfigurations.at(i).data() == rc) {
|
|
|
|
|
emit dataChanged(index(i, 0), index(i,0));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant RunConfigurationsModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
|
const int row = index.row();
|
|
|
|
|
if (row < m_runConfigurations.size()) {
|
|
|
|
|
QSharedPointer<RunConfiguration> c = m_runConfigurations.at(row);
|
|
|
|
|
return c->name();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunConfigurationsModel::setRunConfigurations(const QList<QSharedPointer<RunConfiguration> > &runConfigurations)
|
|
|
|
|
{
|
|
|
|
|
m_runConfigurations = runConfigurations;
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// RunSettingsWidget
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
RunSettingsWidget::RunSettingsWidget(Project *project)
|
2008-12-09 15:25:01 +01:00
|
|
|
: m_project(project),
|
|
|
|
|
m_runConfigurationsModel(new RunConfigurationsModel(this)),
|
|
|
|
|
m_runConfigurationWidget(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_ui = new Ui::RunSettingsPropertiesPage;
|
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
m_addMenu = new QMenu(m_ui->addToolButton);
|
2009-01-12 15:06:43 +01:00
|
|
|
m_ui->addToolButton->setIcon(QIcon(Core::Constants::ICON_PLUS));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui->addToolButton->setMenu(m_addMenu);
|
2009-01-12 15:06:43 +01:00
|
|
|
m_ui->removeToolButton->setIcon(QIcon(Core::Constants::ICON_MINUS));
|
2008-12-02 12:01:29 +01:00
|
|
|
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<QSharedPointer<RunConfiguration> > runConfigurations = m_project->runConfigurations();
|
|
|
|
|
for (int i=0; i<runConfigurations.size(); ++i) {
|
|
|
|
|
connect(runConfigurations.at(i).data(), SIGNAL(nameChanged()),
|
|
|
|
|
this, SLOT(nameChanged()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Add support for custom runner configuration widgets once we have some
|
|
|
|
|
/*
|
|
|
|
|
QList<IRunConfigurationRunner *> runners = PluginManager::instance()->getObjects<IRunConfigurationRunner>();
|
|
|
|
|
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();
|
2008-12-09 15:25:01 +01:00
|
|
|
QList<IRunConfigurationFactory *> factories =
|
|
|
|
|
ExtensionSystem::PluginManager::instance()->getObjects<IRunConfigurationFactory>();
|
|
|
|
|
foreach (IRunConfigurationFactory *factory, factories) {
|
2008-12-02 12:01:29 +01:00
|
|
|
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<QAction *>(sender());
|
|
|
|
|
if (!act)
|
|
|
|
|
return;
|
|
|
|
|
FactoryAndType fat = act->data().value<FactoryAndType>();
|
|
|
|
|
QSharedPointer<RunConfiguration> newRC = fat.factory->create(m_project, fat.type);
|
|
|
|
|
if (!newRC)
|
|
|
|
|
return;
|
|
|
|
|
m_project->addRunConfiguration(newRC);
|
|
|
|
|
m_project->setActiveRunConfiguration(newRC);
|
|
|
|
|
initRunConfigurationComboBox();
|
2008-12-09 15:25:01 +01:00
|
|
|
connect(newRC.data(), SIGNAL(nameChanged()), this, SLOT(nameChanged()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunSettingsWidget::removeRunConfiguration()
|
|
|
|
|
{
|
|
|
|
|
int index = m_ui->runConfigurationCombo->currentIndex();
|
|
|
|
|
QSharedPointer<RunConfiguration> rc = m_project->runConfigurations().at(index);
|
2008-12-09 15:25:01 +01:00
|
|
|
disconnect(rc.data(), SIGNAL(nameChanged()), this, SLOT(nameChanged()));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_project->removeRunConfiguration(rc);
|
|
|
|
|
initRunConfigurationComboBox();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunSettingsWidget::initRunConfigurationComboBox()
|
|
|
|
|
{
|
|
|
|
|
const QList<QSharedPointer<RunConfiguration> > runConfigurations = m_project->runConfigurations();
|
|
|
|
|
QSharedPointer<RunConfiguration> 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)
|
|
|
|
|
{
|
2008-12-17 15:51:48 +01:00
|
|
|
Q_ASSERT(m_project);
|
2008-12-02 12:01:29 +01:00
|
|
|
const QList<QSharedPointer<RunConfiguration> > runConfigurations = m_project->runConfigurations();
|
2008-12-17 15:51:48 +01:00
|
|
|
Q_ASSERT(index < runConfigurations.size());
|
2008-12-02 12:01:29 +01:00
|
|
|
QSharedPointer<RunConfiguration> 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<RunConfiguration *>(sender());
|
|
|
|
|
m_runConfigurationsModel->nameChanged(rc);
|
|
|
|
|
}
|