1
/****************************************************************************
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of Qt Creator.
8
** Commercial License Usage
9
** Licensees holding valid commercial Qt licenses may use this file in
10
** accordance with the commercial license agreement provided with the
11
** Software or, alternatively, in accordance with the terms contained in
12
** a written agreement between you and Digia. For licensing terms and
13
** conditions see http://qt.digia.com/licensing. For further information
14
** use the contact form at http://qt.digia.com/contact-us.
16
** GNU Lesser General Public License Usage
17
** Alternatively, this file may be used under the terms of the GNU Lesser
18
** General Public License version 2.1 as published by the Free Software
19
** Foundation and appearing in the file LICENSE.LGPL included in the
20
** packaging of this file. Please review the following information to
21
** ensure the GNU Lesser General Public License version 2.1 requirements
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
** In addition, as a special exception, Digia gives you certain additional
25
** rights. These rights are described in the Digia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
****************************************************************************/
30
#include "qt4projectconfigwidget.h"
32
#include "qt4project.h"
33
#include "qt4buildconfiguration.h"
35
#include "ui_qt4projectconfigwidget.h"
37
#include <projectexplorer/target.h>
38
#include <qtsupport/qtkitinformation.h>
40
#include <utils/detailswidget.h>
42
using namespace Qt4ProjectManager;
43
using namespace Qt4ProjectManager::Internal;
44
using namespace ProjectExplorer;
46
Qt4ProjectConfigWidget::Qt4ProjectConfigWidget(Qt4BuildConfiguration *bc)
48
m_buildConfiguration(bc),
51
QVBoxLayout *vbox = new QVBoxLayout(this);
53
m_detailsContainer = new Utils::DetailsWidget(this);
54
m_detailsContainer->setState(Utils::DetailsWidget::NoSummary);
55
vbox->addWidget(m_detailsContainer);
56
QWidget *details = new QWidget(m_detailsContainer);
57
m_detailsContainer->setWidget(details);
58
m_ui = new Ui::Qt4ProjectConfigWidget();
59
m_ui->setupUi(details);
61
m_browseButton = m_ui->shadowBuildDirEdit->buttonAtIndex(0);
63
m_ui->shadowBuildDirEdit->setPromptDialogTitle(tr("Shadow Build Directory"));
64
m_ui->shadowBuildDirEdit->setExpectedKind(Utils::PathChooser::ExistingDirectory);
66
connect(m_ui->shadowBuildCheckBox, SIGNAL(clicked(bool)),
67
this, SLOT(shadowBuildClicked(bool)));
69
connect(m_ui->shadowBuildDirEdit, SIGNAL(beforeBrowsing()),
70
this, SLOT(onBeforeBeforeShadowBuildDirBrowsed()));
72
connect(m_ui->shadowBuildDirEdit, SIGNAL(changed(QString)),
73
this, SLOT(shadowBuildEdited()));
75
Qt4Project *project = static_cast<Qt4Project *>(bc->target()->project());
76
connect(project, SIGNAL(environmentChanged()), this, SLOT(environmentChanged()));
77
connect(project, SIGNAL(buildDirectoryInitialized()), this, SLOT(updateProblemLabel()));
78
connect(project, SIGNAL(proFilesEvaluated()), this, SLOT(updateProblemLabel()));
80
connect(bc->target(), SIGNAL(kitChanged()), this, SLOT(updateProblemLabel()));
82
m_ui->shadowBuildDirEdit->setEnvironment(m_buildConfiguration->environment());
84
connect(m_buildConfiguration, SIGNAL(buildDirectoryChanged()),
85
this, SLOT(buildDirectoryChanged()));
86
connect(m_buildConfiguration, SIGNAL(qmakeBuildConfigurationChanged()),
87
this, SLOT(updateProblemLabel()));
89
m_ui->shadowBuildDirEdit->setBaseDirectory(m_buildConfiguration->target()->project()->projectDirectory());
91
buildDirectoryChanged();
93
setDisplayName(tr("General"));
96
Qt4ProjectConfigWidget::~Qt4ProjectConfigWidget()
101
void Qt4ProjectConfigWidget::updateDetails()
103
m_detailsContainer->setSummaryText(
104
tr("building in <b>%1</b>")
105
.arg(QDir::toNativeSeparators(m_buildConfiguration->buildDirectory())));
108
void Qt4ProjectConfigWidget::setProblemLabel(const QString &text)
110
m_ui->warningLabel->setVisible(!text.isEmpty());
111
m_ui->problemLabel->setVisible(!text.isEmpty());
112
m_ui->problemLabel->setText(text);
115
void Qt4ProjectConfigWidget::environmentChanged()
117
m_ui->shadowBuildDirEdit->setEnvironment(m_buildConfiguration->environment());
120
void Qt4ProjectConfigWidget::buildDirectoryChanged()
124
m_ui->shadowBuildDirEdit->setPath(m_buildConfiguration->shadowBuildDirectory());
125
bool shadowBuild = m_buildConfiguration->shadowBuild();
126
m_ui->shadowBuildCheckBox->setChecked(shadowBuild);
127
m_ui->shadowBuildDirEdit->setEnabled(shadowBuild);
128
m_browseButton->setEnabled(shadowBuild);
131
updateProblemLabel();
134
void Qt4ProjectConfigWidget::onBeforeBeforeShadowBuildDirBrowsed()
136
QString initialDirectory = m_buildConfiguration->target()->project()->projectDirectory();
137
if (!initialDirectory.isEmpty())
138
m_ui->shadowBuildDirEdit->setInitialBrowsePathBackup(initialDirectory);
141
void Qt4ProjectConfigWidget::shadowBuildClicked(bool checked)
143
m_ui->shadowBuildDirEdit->setEnabled(checked);
144
m_browseButton->setEnabled(checked);
145
bool b = m_ui->shadowBuildCheckBox->isChecked();
147
m_ignoreChange = true;
148
m_buildConfiguration->setShadowBuildAndDirectory(b, m_ui->shadowBuildDirEdit->rawPath());
149
m_ignoreChange = false;
152
updateProblemLabel();
155
void Qt4ProjectConfigWidget::shadowBuildEdited()
157
if (m_buildConfiguration->shadowBuildDirectory() == m_ui->shadowBuildDirEdit->rawPath())
159
m_ignoreChange = true;
160
m_buildConfiguration->setShadowBuildAndDirectory(m_buildConfiguration->shadowBuild(), m_ui->shadowBuildDirEdit->rawPath());
161
m_ignoreChange = false;
163
// if the directory already exists
164
// check if we have a build in there and
165
// offer to import it
166
updateProblemLabel();
170
void Qt4ProjectConfigWidget::updateProblemLabel()
172
m_ui->shadowBuildDirEdit->triggerChanged();
173
ProjectExplorer::Kit *k = m_buildConfiguration->target()->kit();
174
const QString proFileName = m_buildConfiguration->target()->project()->document()->fileName();
176
// Check for Qt version:
177
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(k);
179
setProblemLabel(tr("This kit cannot build this project since it does not define a Qt version."));
183
Qt4Project *p = static_cast<Qt4Project *>(m_buildConfiguration->target()->project());
184
if (p->rootQt4ProjectNode()->parseInProgress() || !p->rootQt4ProjectNode()->validParse()) {
185
setProblemLabel(QString());
189
bool targetMismatch = false;
190
bool incompatibleBuild = false;
191
bool allGood = false;
192
// we only show if we actually have a qmake and makestep
193
if (m_buildConfiguration->qmakeStep() && m_buildConfiguration->makeStep()) {
194
QString makefile = m_buildConfiguration->buildDirectory() + QLatin1Char('/');
195
if (m_buildConfiguration->makefile().isEmpty())
196
makefile.append(QLatin1String("Makefile"));
198
makefile.append(m_buildConfiguration->makefile());
200
switch (m_buildConfiguration->compareToImportFrom(makefile)) {
201
case Qt4BuildConfiguration::MakefileMatches:
204
case Qt4BuildConfiguration::MakefileMissing:
207
case Qt4BuildConfiguration::MakefileIncompatible:
208
incompatibleBuild = true;
210
case Qt4BuildConfiguration::MakefileForWrongProject:
211
targetMismatch = true;
216
QString shadowBuildWarning;
217
if (!version->supportsShadowBuilds() && m_buildConfiguration->shadowBuild()) {
218
shadowBuildWarning = tr("The Qt version %1 does not support shadow builds, building might fail.")
219
.arg(version->displayName())
220
+ QLatin1String("<br>");
224
QString buildDirectory = m_buildConfiguration->target()->project()->projectDirectory();;
225
if (m_buildConfiguration->shadowBuild())
226
buildDirectory = m_buildConfiguration->buildDirectory();
227
QList<ProjectExplorer::Task> issues;
228
issues = version->reportIssues(proFileName, buildDirectory);
231
if (!issues.isEmpty() || !shadowBuildWarning.isEmpty()) {
232
QString text = QLatin1String("<nobr>") + shadowBuildWarning;
233
foreach (const ProjectExplorer::Task &task, issues) {
236
case ProjectExplorer::Task::Error:
238
type += QLatin1Char(' ');
240
case ProjectExplorer::Task::Warning:
241
type = tr("Warning:");
242
type += QLatin1Char(' ');
244
case ProjectExplorer::Task::Unknown:
248
if (!text.endsWith(QLatin1String("br>")))
249
text.append(QLatin1String("<br>"));
250
text.append(type + task.description);
252
setProblemLabel(text);
255
} else if (targetMismatch) {
256
setProblemLabel(shadowBuildWarning + tr("A build for a different project exists in %1, which will be overwritten.",
257
"%1 build directory")
258
.arg(QDir::toNativeSeparators(m_buildConfiguration->buildDirectory())));
260
} else if (incompatibleBuild) {
261
setProblemLabel(shadowBuildWarning +tr("An incompatible build exists in %1, which will be overwritten.",
262
"%1 build directory")
263
.arg(QDir::toNativeSeparators(m_buildConfiguration->buildDirectory())));
265
} else if (!shadowBuildWarning.isEmpty()) {
266
setProblemLabel(shadowBuildWarning);
270
setProblemLabel(QString());