1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
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 The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25
26 #include "toolchainconfigwidget.h"
27 #include "toolchain.h"
28
29 #include <utils/detailswidget.h>
30 #include <utils/qtcassert.h>
31 #include <utils/qtcprocess.h>
32
33 #include <QString>
34
35 #include <QFormLayout>
36 #include <QLineEdit>
37 #include <QLabel>
38 #include <QScrollArea>
39 #include <QPainter>
40
41 using namespace Utils;
42
43 namespace ProjectExplorer {
44
ToolChainConfigWidget(ToolChain * tc)45 ToolChainConfigWidget::ToolChainConfigWidget(ToolChain *tc) :
46 m_toolChain(tc)
47 {
48 Q_ASSERT(tc);
49
50 auto centralWidget = new Utils::DetailsWidget;
51 centralWidget->setState(Utils::DetailsWidget::NoSummary);
52
53 setFrameShape(QFrame::NoFrame);
54 setWidgetResizable(true);
55 setFocusPolicy(Qt::NoFocus);
56
57 setWidget(centralWidget);
58
59 auto detailsBox = new QWidget();
60
61 m_mainLayout = new QFormLayout(detailsBox);
62 m_mainLayout->setContentsMargins(0, 0, 0, 0);
63 centralWidget->setWidget(detailsBox);
64 m_mainLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); // for the Macs...
65
66 m_nameLineEdit = new QLineEdit;
67 m_nameLineEdit->setText(tc->displayName());
68
69 m_mainLayout->addRow(tr("Name:"), m_nameLineEdit);
70
71 connect(m_nameLineEdit, &QLineEdit::textChanged, this, &ToolChainConfigWidget::dirty);
72 }
73
apply()74 void ToolChainConfigWidget::apply()
75 {
76 m_toolChain->setDisplayName(m_nameLineEdit->text());
77 applyImpl();
78 }
79
discard()80 void ToolChainConfigWidget::discard()
81 {
82 m_nameLineEdit->setText(m_toolChain->displayName());
83 discardImpl();
84 }
85
isDirty() const86 bool ToolChainConfigWidget::isDirty() const
87 {
88 return m_nameLineEdit->text() != m_toolChain->displayName() || isDirtyImpl();
89 }
90
toolChain() const91 ToolChain *ToolChainConfigWidget::toolChain() const
92 {
93 return m_toolChain;
94 }
95
makeReadOnly()96 void ToolChainConfigWidget::makeReadOnly()
97 {
98 m_nameLineEdit->setEnabled(false);
99 makeReadOnlyImpl();
100 }
101
addErrorLabel()102 void ToolChainConfigWidget::addErrorLabel()
103 {
104 if (!m_errorLabel) {
105 m_errorLabel = new QLabel;
106 m_errorLabel->setVisible(false);
107 }
108 m_mainLayout->addRow(m_errorLabel);
109 }
110
setErrorMessage(const QString & m)111 void ToolChainConfigWidget::setErrorMessage(const QString &m)
112 {
113 QTC_ASSERT(m_errorLabel, return);
114 if (m.isEmpty()) {
115 clearErrorMessage();
116 } else {
117 m_errorLabel->setText(m);
118 m_errorLabel->setStyleSheet(QLatin1String("background-color: \"red\""));
119 m_errorLabel->setVisible(true);
120 }
121 }
122
clearErrorMessage()123 void ToolChainConfigWidget::clearErrorMessage()
124 {
125 QTC_ASSERT(m_errorLabel, return);
126 m_errorLabel->clear();
127 m_errorLabel->setStyleSheet(QString());
128 m_errorLabel->setVisible(false);
129 }
130
splitString(const QString & s)131 QStringList ToolChainConfigWidget::splitString(const QString &s)
132 {
133 ProcessArgs::SplitError splitError;
134 const OsType osType = HostOsInfo::hostOs();
135 QStringList res = ProcessArgs::splitArgs(s, osType, false, &splitError);
136 if (splitError != ProcessArgs::SplitOk) {
137 res = ProcessArgs::splitArgs(s + '\\', osType, false, &splitError);
138 if (splitError != ProcessArgs::SplitOk) {
139 res = ProcessArgs::splitArgs(s + '"', osType, false, &splitError);
140 if (splitError != ProcessArgs::SplitOk)
141 res = ProcessArgs::splitArgs(s + '\'', osType, false, &splitError);
142 }
143 }
144 return res;
145 }
146
147 } // namespace ProjectExplorer
148