cmakerunconfiguration.cpp 19.3 KB
Newer Older
1
/**************************************************************************
dt's avatar
dt committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
dt's avatar
dt committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
dt's avatar
dt committed
8
**
9
** Commercial Usage
dt's avatar
dt committed
10
**
11
12
13
14
** 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.
dt's avatar
dt committed
15
**
16
** GNU Lesser General Public License Usage
dt's avatar
dt committed
17
**
18
19
20
21
22
23
** 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.
dt's avatar
dt committed
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
dt's avatar
dt committed
27
**
28
**************************************************************************/
dt's avatar
dt committed
29
30

#include "cmakerunconfiguration.h"
hjk's avatar
hjk committed
31

dt's avatar
dt committed
32
#include "cmakeproject.h"
33
#include "cmakebuildconfiguration.h"
hjk's avatar
hjk committed
34
#include "cmakeprojectconstants.h"
dt's avatar
dt committed
35
36

#include <projectexplorer/environment.h>
37
#include <projectexplorer/debugginghelper.h>
hjk's avatar
hjk committed
38
#include <utils/qtcassert.h>
39
40
#include <QtGui/QFormLayout>
#include <QtGui/QLineEdit>
41
42
#include <QtGui/QGroupBox>
#include <QtGui/QLabel>
43
#include <QtGui/QComboBox>
44
#include <QtGui/QToolButton>
dt's avatar
dt committed
45
46
47
48

using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;

49
50
51
52
53
54
55
56
57
58
59
60
61
62
namespace {
const char * const CMAKE_RC_ID("CMakeProjectManager.CMakeRunConfiguration");
const char * const CMAKE_RC_PREFIX("CMakeProjectManager.CMakeRunConfiguration.");

const char * const TARGET_KEY("CMakeProjectManager.CMakeRunConfiguration.Target");
const char * const WORKING_DIRECTORY_KEY("CMakeProjectManager.CMakeRunConfiguration.WorkingDirectory");
const char * const USER_WORKING_DIRECTORY_KEY("CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory");
const char * const USE_TERMINAL_KEY("CMakeProjectManager.CMakeRunConfiguration.UseTerminal");
const char * const TITLE_KEY("CMakeProjectManager.CMakeRunConfiguation.Title");
const char * const ARGUMENTS_KEY("CMakeProjectManager.CMakeRunConfiguration.Arguments");
const char * const USER_ENVIRONMENT_CHANGES_KEY("CMakeProjectManager.CMakeRunConfiguration.UserEnvironmentChanges");
const char * const BASE_ENVIRONMENT_BASE_KEY("CMakeProjectManager.BaseEnvironmentBase");

QString targetFromId(const QString &id)
dt's avatar
dt committed
63
{
64
65
66
67
    if (!id.startsWith(QLatin1String(CMAKE_RC_PREFIX)))
        return QString();
    return id.mid(QString::fromLatin1(CMAKE_RC_PREFIX).length());
}
68

69
70
71
QString idFromTarget(const QString &target)
{
    return QString::fromLatin1(CMAKE_RC_PREFIX) + target;
dt's avatar
dt committed
72
}
hjk's avatar
hjk committed
73

74
75
76
77
78
79
80
81
82
} // namespace

CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, const QString &target, const QString &workingDirectory, const QString &title) :
    ProjectExplorer::LocalApplicationRunConfiguration(pro, QString::fromLatin1(CMAKE_RC_PREFIX)),
    m_runMode(Gui),
    m_target(target),
    m_workingDirectory(workingDirectory),
    m_title(title),
    m_baseEnvironmentBase(CMakeRunConfiguration::BuildEnvironmentBase)
dt's avatar
dt committed
83
{
84
85
    ctor();
}
dt's avatar
dt committed
86

87
88
89
90
91
92
93
94
95
96
97
98
CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, CMakeRunConfiguration *source) :
    ProjectExplorer::LocalApplicationRunConfiguration(pro, source),
    m_runMode(source->m_runMode),
    m_target(source->m_target),
    m_workingDirectory(source->m_workingDirectory),
    m_userWorkingDirectory(source->m_userWorkingDirectory),
    m_title(source->m_title),
    m_arguments(source->m_arguments),
    m_userEnvironmentChanges(source->m_userEnvironmentChanges),
    m_baseEnvironmentBase(source->m_baseEnvironmentBase)
{
    ctor();
dt's avatar
dt committed
99
100
}

101
CMakeRunConfiguration::~CMakeRunConfiguration()
dt's avatar
dt committed
102
{
dt's avatar
dt committed
103
104
}

105
void CMakeRunConfiguration::ctor()
dt's avatar
dt committed
106
{
107
108
109
110
111
112
113
114
115
    setDisplayName(m_title);

    connect(project(), SIGNAL(environmentChanged()),
            this, SIGNAL(baseEnvironmentChanged()));
}

CMakeProject *CMakeRunConfiguration::cmakeProject() const
{
    return static_cast<CMakeProject *>(project());
dt's avatar
dt committed
116
117
118
119
120
121
122
}

QString CMakeRunConfiguration::executable() const
{
    return m_target;
}

123
ProjectExplorer::LocalApplicationRunConfiguration::RunMode CMakeRunConfiguration::runMode() const
dt's avatar
dt committed
124
{
125
    return m_runMode;
dt's avatar
dt committed
126
127
128
129
}

QString CMakeRunConfiguration::workingDirectory() const
{
130
131
    if (!m_userWorkingDirectory.isEmpty())
        return m_userWorkingDirectory;
dt's avatar
dt committed
132
133
134
135
136
    return m_workingDirectory;
}

QStringList CMakeRunConfiguration::commandLineArguments() const
{
137
    return ProjectExplorer::Environment::parseCombinedArgString(m_arguments);
dt's avatar
dt committed
138
139
}

dt's avatar
dt committed
140
141
142
143
144
145
146
147
148
149
QString CMakeRunConfiguration::title() const
{
    return m_title;
}

void CMakeRunConfiguration::setExecutable(const QString &executable)
{
    m_target = executable;
}

150
void CMakeRunConfiguration::setWorkingDirectory(const QString &wd)
dt's avatar
dt committed
151
{
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
    const QString & oldWorkingDirectory = workingDirectory();

    m_workingDirectory = wd;

    const QString &newWorkingDirectory = workingDirectory();
    if (oldWorkingDirectory != newWorkingDirectory)
        emit workingDirectoryChanged(newWorkingDirectory);
}

void CMakeRunConfiguration::setUserWorkingDirectory(const QString &wd)
{
    const QString & oldWorkingDirectory = workingDirectory();

    m_userWorkingDirectory = wd;

    const QString &newWorkingDirectory = workingDirectory();
    if (oldWorkingDirectory != newWorkingDirectory)
        emit workingDirectoryChanged(newWorkingDirectory);
dt's avatar
dt committed
170
171
}

172
QVariantMap CMakeRunConfiguration::toMap() const
dt's avatar
dt committed
173
{
174
175
176
177
178
179
180
181
182
183
    QVariantMap map(ProjectExplorer::LocalApplicationRunConfiguration::toMap());

    map.insert(QLatin1String(TARGET_KEY), m_target);
    map.insert(QLatin1String(WORKING_DIRECTORY_KEY), m_workingDirectory);
    map.insert(QLatin1String(USER_WORKING_DIRECTORY_KEY), m_userWorkingDirectory);
    map.insert(QLatin1String(USE_TERMINAL_KEY), m_runMode == Console);
    map.insert(QLatin1String(TITLE_KEY), m_title);
    map.insert(QLatin1String(ARGUMENTS_KEY), m_arguments);
    map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges));
    map.insert(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), m_baseEnvironmentBase);
184

185
    return map;
dt's avatar
dt committed
186
187
}

188
bool CMakeRunConfiguration::fromMap(const QVariantMap &map)
dt's avatar
dt committed
189
{
190
191
192
193
194
195
196
197
198
199
    m_target = map.value(QLatin1String(TARGET_KEY)).toString();
    m_workingDirectory = map.value(QLatin1String(WORKING_DIRECTORY_KEY)).toString();
    m_userWorkingDirectory = map.value(QLatin1String(USER_WORKING_DIRECTORY_KEY)).toString();
    m_runMode = map.value(QLatin1String(USE_TERMINAL_KEY)).toBool() ? Console : Gui;
    m_title = map.value(QLatin1String(TITLE_KEY)).toString();
    m_arguments = map.value(QLatin1String(ARGUMENTS_KEY)).toString();
    m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
    m_baseEnvironmentBase = static_cast<BaseEnvironmentBase>(map.value(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), static_cast<int>(CMakeRunConfiguration::BuildEnvironmentBase)).toInt());

    return RunConfiguration::fromMap(map);
dt's avatar
dt committed
200
201
202
203
}

QWidget *CMakeRunConfiguration::configurationWidget()
{
204
    return new CMakeRunConfigurationWidget(this);
205
206
207
208
209
}

void CMakeRunConfiguration::setArguments(const QString &newText)
{
    m_arguments = newText;
dt's avatar
dt committed
210
211
}

212
213
QString CMakeRunConfiguration::dumperLibrary() const
{
214
    QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment());
dt's avatar
dt committed
215
216
    QString qtInstallData = ProjectExplorer::DebuggingHelperLibrary::qtInstallDataDir(qmakePath);
    QString dhl = ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibraryByInstallData(qtInstallData);
217
    return dhl;
218
219
}

220
221
222
QStringList CMakeRunConfiguration::dumperLibraryLocations() const
{
    QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment());
dt's avatar
dt committed
223
224
    QString qtInstallData = ProjectExplorer::DebuggingHelperLibrary::qtInstallDataDir(qmakePath);
    return ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibraryLocationsByInstallData(qtInstallData);
225
226
}

227
228
ProjectExplorer::Environment CMakeRunConfiguration::baseEnvironment() const
{
229
230
231
232
233
234
    ProjectExplorer::Environment env;
    if (m_baseEnvironmentBase == CMakeRunConfiguration::CleanEnvironmentBase) {
        // Nothing
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::SystemEnvironmentBase) {
        env = ProjectExplorer::Environment::systemEnvironment();
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::BuildEnvironmentBase) {
235
        env = project()->activeBuildConfiguration()->environment();
236
    }
237
238
239
    return env;
}

240
241
242
243
244
245
246
247
248
249
250
251
QString CMakeRunConfiguration::baseEnvironmentText() const
{
    if (m_baseEnvironmentBase == CMakeRunConfiguration::CleanEnvironmentBase) {
        return tr("Clean Environment");
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::SystemEnvironmentBase) {
        return tr("System Environment");
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::BuildEnvironmentBase) {
        return tr("Build Environment");
    }
    return QString();
}

252
253
254
255
256
257
258
259
260
261
262
263
264
void CMakeRunConfiguration::setBaseEnvironmentBase(BaseEnvironmentBase env)
{
    if (m_baseEnvironmentBase == env)
        return;
    m_baseEnvironmentBase = env;
    emit baseEnvironmentChanged();
}

CMakeRunConfiguration::BaseEnvironmentBase CMakeRunConfiguration::baseEnvironmentBase() const
{
    return m_baseEnvironmentBase;
}

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
ProjectExplorer::Environment CMakeRunConfiguration::environment() const
{
    ProjectExplorer::Environment env = baseEnvironment();
    env.modify(userEnvironmentChanges());
    return env;
}

QList<ProjectExplorer::EnvironmentItem> CMakeRunConfiguration::userEnvironmentChanges() const
{
    return m_userEnvironmentChanges;
}

void CMakeRunConfiguration::setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff)
{
    if (m_userEnvironmentChanges != diff) {
        m_userEnvironmentChanges = diff;
        emit userEnvironmentChangesChanged(diff);
    }
}

285
286
ProjectExplorer::ToolChain::ToolChainType CMakeRunConfiguration::toolChainType() const
{
dt's avatar
dt committed
287
    CMakeBuildConfiguration *bc = cmakeProject()->activeCMakeBuildConfiguration();
288
    return bc->toolChainType();
289
290
}

291
292
293
294
// Configuration widget


CMakeRunConfigurationWidget::CMakeRunConfigurationWidget(CMakeRunConfiguration *cmakeRunConfiguration, QWidget *parent)
295
    : QWidget(parent), m_ignoreChange(false), m_cmakeRunConfiguration(cmakeRunConfiguration)
296
297
298
{

    QFormLayout *fl = new QFormLayout();
299
300
    fl->setMargin(0);
    fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
301
302
303
304
305
306
    QLineEdit *argumentsLineEdit = new QLineEdit();
    argumentsLineEdit->setText(ProjectExplorer::Environment::joinArgumentList(cmakeRunConfiguration->commandLineArguments()));
    connect(argumentsLineEdit, SIGNAL(textChanged(QString)),
            this, SLOT(setArguments(QString)));
    fl->addRow(tr("Arguments:"), argumentsLineEdit);

307
    m_workingDirectoryEdit = new Utils::PathChooser();
308
    m_workingDirectoryEdit->setPath(m_cmakeRunConfiguration->workingDirectory());
309
    m_workingDirectoryEdit->setExpectedKind(Utils::PathChooser::Directory);
310
311
312
313
314
315
316
317
318
319
320
321
    m_workingDirectoryEdit->setPromptDialogTitle(tr("Select the working directory"));

    QToolButton *resetButton = new QToolButton();
    resetButton->setToolTip(tr("Reset to default"));
    resetButton->setIcon(QIcon(":/core/images/reset.png"));

    QHBoxLayout *boxlayout = new QHBoxLayout();
    boxlayout->addWidget(m_workingDirectoryEdit);
    boxlayout->addWidget(resetButton);

    fl->addRow(tr("Working Directory:"), boxlayout);

322
    m_detailsContainer = new Utils::DetailsWidget(this);
dt's avatar
dt committed
323

324
325
326
    QWidget *m_details = new QWidget(m_detailsContainer);
    m_detailsContainer->setWidget(m_details);
    m_details->setLayout(fl);
dt's avatar
dt committed
327

328
    QVBoxLayout *vbx = new QVBoxLayout(this);
329
330
    vbx->setMargin(0);;
    vbx->addWidget(m_detailsContainer);
331
332
333
334
335
336
337
338

    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);
    vbx->addWidget(environmentLabel);
339

340
341
342
    QWidget *baseEnvironmentWidget = new QWidget;
    QHBoxLayout *baseEnvironmentLayout = new QHBoxLayout(baseEnvironmentWidget);
    baseEnvironmentLayout->setMargin(0);
343
    QLabel *label = new QLabel(tr("Base environment for this runconfiguration:"), this);
344
    baseEnvironmentLayout->addWidget(label);
345
    m_baseEnvironmentComboBox = new QComboBox(this);
346
347
348
349
350
351
352
    m_baseEnvironmentComboBox->addItems(QStringList()
                                        << tr("Clean Environment")
                                        << tr("System Environment")
                                        << tr("Build Environment"));
    m_baseEnvironmentComboBox->setCurrentIndex(m_cmakeRunConfiguration->baseEnvironmentBase());
    connect(m_baseEnvironmentComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(baseEnvironmentComboBoxChanged(int)));
353
354
    baseEnvironmentLayout->addWidget(m_baseEnvironmentComboBox);
    baseEnvironmentLayout->addStretch(10);
355

dt's avatar
dt committed
356
357
    m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this, baseEnvironmentWidget);
    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
358
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
dt's avatar
dt committed
359
360
361
362
363
364
    m_environmentWidget->setUserChanges(m_cmakeRunConfiguration->userEnvironmentChanges());

    vbx->addWidget(m_environmentWidget);

    updateSummary();

con's avatar
con committed
365
    connect(m_workingDirectoryEdit, SIGNAL(changed(QString)),
366
367
368
369
370
            this, SLOT(setWorkingDirectory()));

    connect(resetButton, SIGNAL(clicked()),
            this, SLOT(resetWorkingDirectory()));

371
372
    connect(m_environmentWidget, SIGNAL(userChangesChanged()),
            this, SLOT(userChangesChanged()));
373

374
375
    connect(m_cmakeRunConfiguration, SIGNAL(workingDirectoryChanged(QString)),
            this, SLOT(workingDirectoryChanged(QString)));
376
377
378
379
    connect(m_cmakeRunConfiguration, SIGNAL(baseEnvironmentChanged()),
            this, SLOT(baseEnvironmentChanged()));
    connect(m_cmakeRunConfiguration, SIGNAL(userEnvironmentChangesChanged(QList<ProjectExplorer::EnvironmentItem>)),
            this, SLOT(userEnvironmentChangesChanged()));
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402

}

void CMakeRunConfigurationWidget::setWorkingDirectory()
{
    if (m_ignoreChange)
        return;
    m_ignoreChange = true;
    m_cmakeRunConfiguration->setUserWorkingDirectory(m_workingDirectoryEdit->path());
    m_ignoreChange = false;
}

void CMakeRunConfigurationWidget::workingDirectoryChanged(const QString &workingDirectory)
{
    if (!m_ignoreChange)
        m_workingDirectoryEdit->setPath(workingDirectory);
}

void CMakeRunConfigurationWidget::resetWorkingDirectory()
{
    // This emits a signal connected to workingDirectoryChanged()
    // that sets the m_workingDirectoryEdit
    m_cmakeRunConfiguration->setUserWorkingDirectory("");
403
404
}

405
void CMakeRunConfigurationWidget::userChangesChanged()
406
407
408
409
{
    m_cmakeRunConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
}

410
void CMakeRunConfigurationWidget::baseEnvironmentComboBoxChanged(int index)
411
412
{
    m_ignoreChange = true;
413
    m_cmakeRunConfiguration->setBaseEnvironmentBase(CMakeRunConfiguration::BaseEnvironmentBase(index));
414
415

    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
416
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
417
418
419
    m_ignoreChange = false;
}

420
421
void CMakeRunConfigurationWidget::baseEnvironmentChanged()
{
422
423
424
    if (m_ignoreChange)
        return;

425
    m_baseEnvironmentComboBox->setCurrentIndex(m_cmakeRunConfiguration->baseEnvironmentBase());
426
    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
427
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
428
429
430
431
432
433
434
435
436
437
}

void CMakeRunConfigurationWidget::userEnvironmentChangesChanged()
{
    m_environmentWidget->setUserChanges(m_cmakeRunConfiguration->userEnvironmentChanges());
}

void CMakeRunConfigurationWidget::setArguments(const QString &args)
{
    m_cmakeRunConfiguration->setArguments(args);
dt's avatar
dt committed
438
439
440
441
442
443
444
445
    updateSummary();
}

void CMakeRunConfigurationWidget::updateSummary()
{
    QString text = tr("Running executable: <b>%1</b> %2")
                   .arg(QFileInfo(m_cmakeRunConfiguration->executable()).fileName(),
                        ProjectExplorer::Environment::joinArgumentList(m_cmakeRunConfiguration->commandLineArguments()));
446
    m_detailsContainer->setSummaryText(text);
447
448
449
}


dt's avatar
dt committed
450
// Factory
451
452
CMakeRunConfigurationFactory::CMakeRunConfigurationFactory(QObject *parent) :
    ProjectExplorer::IRunConfigurationFactory(parent)
dt's avatar
dt committed
453
454
455
456
457
458
459
{
}

CMakeRunConfigurationFactory::~CMakeRunConfigurationFactory()
{
}

460
// used to show the list of possible additons to a project, returns a list of ids
461
QStringList CMakeRunConfigurationFactory::availableCreationIds(ProjectExplorer::Project *parent) const
dt's avatar
dt committed
462
{
463
464
    CMakeProject *project(qobject_cast<CMakeProject *>(parent));
    if (!project)
dt's avatar
dt committed
465
        return QStringList();
466
467
468
469
    QStringList allIds;
    foreach (const QString &target, project->targets())
        allIds << idFromTarget(target);
    return allIds;
dt's avatar
dt committed
470
471
}

472
473
// used to translate the ids to names to display to the user
QString CMakeRunConfigurationFactory::displayNameForId(const QString &id) const
dt's avatar
dt committed
474
{
475
476
    return targetFromId(id);
}
dt's avatar
dt committed
477

478
479
480
481
482
483
bool CMakeRunConfigurationFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
{
    CMakeProject *project(qobject_cast<CMakeProject *>(parent));
    if (!project)
        return false;
    return project->hasTarget(targetFromId(id));
dt's avatar
dt committed
484
485
}

486
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::create(ProjectExplorer::Project *parent, const QString &id)
dt's avatar
dt committed
487
{
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
    if (!canCreate(parent, id))
        return 0;
    CMakeProject *project(static_cast<CMakeProject *>(parent));

    const QString title(targetFromId(id));
    const CMakeTarget &ct = project->targetForTitle(title);
    return new CMakeRunConfiguration(project, ct.executable, ct.workingDirectory, ct.title);
}

bool CMakeRunConfigurationFactory::canClone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source) const
{
    if (!qobject_cast<CMakeProject *>(parent))
        return false;
    return source->id() == QLatin1String(CMAKE_RC_ID);
}

ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::clone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration * source)
{
    if (!canClone(parent, source))
        return 0;
    CMakeProject *project(static_cast<CMakeProject *>(parent));
    CMakeRunConfiguration *crc(static_cast<CMakeRunConfiguration *>(source));
    return new CMakeRunConfiguration(project, crc);
}

bool CMakeRunConfigurationFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
{
    if (!qobject_cast<CMakeProject *>(parent))
        return false;
    QString id(ProjectExplorer::idFromMap(map));
    return id.startsWith(QLatin1String(CMAKE_RC_ID));
}

ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
{
    if (!canRestore(parent, map))
        return 0;
    CMakeProject *project(static_cast<CMakeProject *>(parent));
    CMakeRunConfiguration *rc(new CMakeRunConfiguration(project, QString(), QString(), QString()));
    if (rc->fromMap(map))
dt's avatar
dt committed
528
        return rc;
529
530
    delete rc;
    return 0;
dt's avatar
dt committed
531
}