2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
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
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
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"
|
2010-02-08 15:50:06 +01:00
|
|
|
#include "target.h"
|
2009-09-29 11:39:55 +02:00
|
|
|
#include "project.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#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>
|
2009-09-29 11:39:55 +02:00
|
|
|
#include <QtGui/QMenu>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
namespace Internal {
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
struct FactoryAndId
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
ProjectExplorer::IRunConfigurationFactory *factory;
|
2010-01-07 18:17:24 +01:00
|
|
|
QString id;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
2008-12-09 15:25:01 +01:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ProjectExplorer
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
Q_DECLARE_METATYPE(ProjectExplorer::Internal::FactoryAndId);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace ProjectExplorer::Internal;
|
|
|
|
|
using ExtensionSystem::PluginManager;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// RunSettingsPanelFactory
|
|
|
|
|
///
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
QString RunSettingsPanelFactory::id() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String(RUNSETTINGS_PANEL_ID);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-21 13:46:19 +01:00
|
|
|
QString RunSettingsPanelFactory::displayName() const
|
|
|
|
|
{
|
2010-02-25 10:34:25 +01:00
|
|
|
return QCoreApplication::translate("RunSettingsPanelFactory", "Run Settings");
|
2010-01-21 13:46:19 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
bool RunSettingsPanelFactory::supports(Target *target)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
Q_UNUSED(target);
|
2008-12-02 12:01:29 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
IPropertiesPanel *RunSettingsPanelFactory::createPanel(Target *target)
|
|
|
|
|
{
|
|
|
|
|
return new RunSettingsPanel(target);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// RunSettingsPanel
|
|
|
|
|
///
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
RunSettingsPanel::RunSettingsPanel(Target *target) :
|
|
|
|
|
m_widget(new RunSettingsWidget(target)),
|
2010-02-19 14:16:37 +01:00
|
|
|
m_icon(":/projectexplorer/images/RunSettings.png")
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RunSettingsPanel::~RunSettingsPanel()
|
|
|
|
|
{
|
2009-11-25 15:18:51 +01:00
|
|
|
delete m_widget;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString RunSettingsPanel::displayName() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-02-24 16:34:22 +01:00
|
|
|
return QCoreApplication::translate("RunSettingsPanel", "Run Settings");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-25 15:57:09 +01:00
|
|
|
QWidget *RunSettingsPanel::widget() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-25 15:57:09 +01:00
|
|
|
QIcon RunSettingsPanel::icon() const
|
|
|
|
|
{
|
|
|
|
|
return m_icon;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
///
|
|
|
|
|
/// RunConfigurationsModel
|
|
|
|
|
///
|
|
|
|
|
|
2010-03-24 15:51:04 +01:00
|
|
|
RunConfigurationsModel::RunConfigurationsModel(Target *target, QObject *parent)
|
|
|
|
|
: QAbstractListModel(parent),
|
|
|
|
|
m_target(target)
|
|
|
|
|
{
|
|
|
|
|
m_runConfigurations = m_target->runConfigurations();
|
|
|
|
|
connect(target, SIGNAL(addedRunConfiguration(ProjectExplorer::RunConfiguration*)),
|
|
|
|
|
this, SLOT(addedRunConfiguration(ProjectExplorer::RunConfiguration*)));
|
|
|
|
|
connect(target, SIGNAL(removedRunConfiguration(ProjectExplorer::RunConfiguration*)),
|
|
|
|
|
this, SLOT(removedRunConfiguration(ProjectExplorer::RunConfiguration*)));
|
|
|
|
|
|
|
|
|
|
foreach (RunConfiguration *rc, m_runConfigurations)
|
|
|
|
|
connect(rc, SIGNAL(displayNameChanged()),
|
|
|
|
|
this, SLOT(displayNameChanged()));
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-24 15:51:04 +01:00
|
|
|
void RunConfigurationsModel::displayNameChanged()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-24 15:51:04 +01:00
|
|
|
RunConfiguration *rc = qobject_cast<RunConfiguration *>(sender());
|
|
|
|
|
QTC_ASSERT(rc, return);
|
|
|
|
|
for (int i = 0; i < m_runConfigurations.size(); ++i) {
|
2009-10-08 18:37:18 +02:00
|
|
|
if (m_runConfigurations.at(i) == rc) {
|
2008-12-02 12:01:29 +01:00
|
|
|
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()) {
|
2010-03-24 15:51:04 +01:00
|
|
|
return m_runConfigurations.at(row)->displayName();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-24 15:51:04 +01:00
|
|
|
RunConfiguration *RunConfigurationsModel::runConfigurationAt(int i)
|
|
|
|
|
{
|
|
|
|
|
if (i > m_runConfigurations.size() || i < 0)
|
|
|
|
|
return 0;
|
|
|
|
|
return m_runConfigurations.at(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RunConfiguration *RunConfigurationsModel::runConfigurationFor(const QModelIndex &idx)
|
|
|
|
|
{
|
|
|
|
|
if (idx.row() > m_runConfigurations.size() || idx.row() < 0)
|
|
|
|
|
return 0;
|
|
|
|
|
return m_runConfigurations.at(idx.row());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex RunConfigurationsModel::indexFor(RunConfiguration *rc)
|
|
|
|
|
{
|
|
|
|
|
int idx = m_runConfigurations.indexOf(rc);
|
|
|
|
|
if (idx == -1)
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
return index(idx, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunConfigurationsModel::addedRunConfiguration(ProjectExplorer::RunConfiguration *rc)
|
|
|
|
|
{
|
|
|
|
|
int i = m_target->runConfigurations().indexOf(rc);
|
|
|
|
|
QTC_ASSERT(i > 0, return);
|
|
|
|
|
beginInsertRows(QModelIndex(), i, i);
|
|
|
|
|
m_runConfigurations.insert(i, rc);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
QTC_ASSERT(m_runConfigurations == m_target->runConfigurations(), return);
|
|
|
|
|
connect(rc, SIGNAL(displayNameChanged()),
|
|
|
|
|
this, SLOT(displayNameChanged()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunConfigurationsModel::removedRunConfiguration(ProjectExplorer::RunConfiguration *rc)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-24 15:51:04 +01:00
|
|
|
int i = m_runConfigurations.indexOf(rc);
|
2010-04-07 15:09:58 +02:00
|
|
|
QTC_ASSERT(i >= 0, return);
|
2010-03-24 15:51:04 +01:00
|
|
|
beginRemoveRows(QModelIndex(), i, i);
|
|
|
|
|
m_runConfigurations.removeAt(i);
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
QTC_ASSERT(m_runConfigurations == m_target->runConfigurations(), return);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// RunSettingsWidget
|
|
|
|
|
///
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
RunSettingsWidget::RunSettingsWidget(Target *target)
|
|
|
|
|
: m_target(target),
|
2010-03-24 15:51:04 +01:00
|
|
|
m_runConfigurationsModel(new RunConfigurationsModel(target, this)),
|
|
|
|
|
m_runConfigurationWidget(0),
|
|
|
|
|
m_ignoreChange(false)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
Q_ASSERT(m_target);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui = new Ui::RunSettingsPropertiesPage;
|
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
m_addMenu = new QMenu(m_ui->addToolButton);
|
|
|
|
|
m_ui->addToolButton->setMenu(m_addMenu);
|
2009-07-16 15:33:19 +02:00
|
|
|
m_ui->addToolButton->setText(tr("Add"));
|
|
|
|
|
m_ui->removeToolButton->setText(tr("Remove"));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui->runConfigurationCombo->setModel(m_runConfigurationsModel);
|
2010-03-24 15:51:04 +01:00
|
|
|
m_ui->runConfigurationCombo->setCurrentIndex(
|
|
|
|
|
m_target->runConfigurations().indexOf(m_target->activeRunConfiguration()));
|
|
|
|
|
|
2010-04-07 14:06:33 +02:00
|
|
|
m_ui->removeToolButton->setEnabled(m_target->runConfigurations().size() > 1);
|
|
|
|
|
|
2010-03-24 15:51:04 +01:00
|
|
|
m_runConfigurationWidget = m_target->activeRunConfiguration()->configurationWidget();
|
|
|
|
|
layout()->addWidget(m_runConfigurationWidget);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
connect(m_addMenu, SIGNAL(aboutToShow()),
|
|
|
|
|
this, SLOT(aboutToShowAddMenu()));
|
|
|
|
|
connect(m_ui->runConfigurationCombo, SIGNAL(currentIndexChanged(int)),
|
2010-02-12 15:15:57 +01:00
|
|
|
this, SLOT(currentRunConfigurationChanged(int)));
|
2008-12-02 12:01:29 +01:00
|
|
|
connect(m_ui->removeToolButton, SIGNAL(clicked(bool)),
|
|
|
|
|
this, SLOT(removeRunConfiguration()));
|
2010-02-08 15:50:06 +01:00
|
|
|
|
|
|
|
|
connect(m_target, SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
|
2010-02-01 15:12:38 +01:00
|
|
|
this, SLOT(activeRunConfigurationChanged()));
|
2009-10-29 15:56:24 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// TODO: Add support for custom runner configuration widgets once we have some
|
|
|
|
|
/*
|
2009-09-25 11:35:44 +02:00
|
|
|
QList<IRunControlFactory *> runners = PluginManager::instance()->getObjects<IRunControlFactory>();
|
|
|
|
|
foreach (IRunControlFactory * runner, runners) {
|
2008-12-02 12:01:29 +01:00
|
|
|
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) {
|
2010-02-08 15:50:06 +01:00
|
|
|
QStringList ids = factory->availableCreationIds(m_target);
|
2010-01-07 18:17:24 +01:00
|
|
|
foreach (const QString &id, ids) {
|
|
|
|
|
QAction *action = m_addMenu->addAction(factory->displayNameForId(id));;
|
|
|
|
|
FactoryAndId fai;
|
|
|
|
|
fai.factory = factory;
|
|
|
|
|
fai.id = id;
|
2008-12-02 12:01:29 +01:00
|
|
|
QVariant v;
|
2010-01-07 18:17:24 +01:00
|
|
|
v.setValue(fai);
|
2008-12-02 12:01:29 +01:00
|
|
|
action->setData(v);
|
|
|
|
|
connect(action, SIGNAL(triggered()),
|
|
|
|
|
this, SLOT(addRunConfiguration()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunSettingsWidget::addRunConfiguration()
|
|
|
|
|
{
|
|
|
|
|
QAction *act = qobject_cast<QAction *>(sender());
|
|
|
|
|
if (!act)
|
|
|
|
|
return;
|
2010-01-07 18:17:24 +01:00
|
|
|
FactoryAndId fai = act->data().value<FactoryAndId>();
|
2010-02-08 15:50:06 +01:00
|
|
|
RunConfiguration *newRC = fai.factory->create(m_target, fai.id);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!newRC)
|
|
|
|
|
return;
|
2010-02-08 15:50:06 +01:00
|
|
|
m_target->addRunConfiguration(newRC);
|
2010-03-24 15:51:04 +01:00
|
|
|
m_target->setActiveRunConfiguration(newRC);
|
2010-04-07 14:06:33 +02:00
|
|
|
m_ui->removeToolButton->setEnabled(m_target->runConfigurations().size() > 1);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunSettingsWidget::removeRunConfiguration()
|
|
|
|
|
{
|
2010-03-24 15:51:04 +01:00
|
|
|
RunConfiguration *rc = m_target->activeRunConfiguration();
|
2010-02-08 15:50:06 +01:00
|
|
|
m_target->removeRunConfiguration(rc);
|
2010-04-07 14:06:33 +02:00
|
|
|
m_ui->removeToolButton->setEnabled(m_target->runConfigurations().size() > 1);
|
2010-02-01 15:12:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunSettingsWidget::activeRunConfigurationChanged()
|
|
|
|
|
{
|
2010-03-24 15:51:04 +01:00
|
|
|
if (m_ignoreChange)
|
|
|
|
|
return;
|
|
|
|
|
QModelIndex actRc = m_runConfigurationsModel->indexFor(m_target->activeRunConfiguration());
|
|
|
|
|
m_ignoreChange = true;
|
|
|
|
|
m_ui->runConfigurationCombo->setCurrentIndex(actRc.row());
|
|
|
|
|
m_ignoreChange = false;
|
|
|
|
|
|
|
|
|
|
delete m_runConfigurationWidget;
|
|
|
|
|
m_runConfigurationWidget = m_target->activeRunConfiguration()->configurationWidget();
|
|
|
|
|
layout()->addWidget(m_runConfigurationWidget);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-12 15:15:57 +01:00
|
|
|
void RunSettingsWidget::currentRunConfigurationChanged(int index)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-24 15:51:04 +01:00
|
|
|
if (m_ignoreChange)
|
|
|
|
|
return;
|
2009-11-03 16:23:40 +01:00
|
|
|
if (index == -1) {
|
|
|
|
|
delete m_runConfigurationWidget;
|
|
|
|
|
m_runConfigurationWidget = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-10-08 18:37:18 +02:00
|
|
|
RunConfiguration *selectedRunConfiguration =
|
2010-03-24 15:51:04 +01:00
|
|
|
m_runConfigurationsModel->runConfigurationAt(index);
|
|
|
|
|
|
|
|
|
|
m_ignoreChange = true;
|
|
|
|
|
m_target->setActiveRunConfiguration(selectedRunConfiguration);
|
|
|
|
|
m_ignoreChange = false;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Update the run configuration configuration widget
|
|
|
|
|
delete m_runConfigurationWidget;
|
|
|
|
|
m_runConfigurationWidget = selectedRunConfiguration->configurationWidget();
|
2009-09-17 13:59:10 +02:00
|
|
|
layout()->addWidget(m_runConfigurationWidget);
|
2009-04-15 14:52:31 +02:00
|
|
|
}
|