1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "abiwidget.h"
#include "abi.h"
#include <QtGui/QComboBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QLabel>
/*!
\class ProjectExplorer::AbiWidget
\brief A widget to set an ABI.
\sa ProjectExplorer::Abi
*/
namespace ProjectExplorer {
namespace Internal {
// --------------------------------------------------------------------------
// AbiWidgetPrivate:
// --------------------------------------------------------------------------
class AbiWidgetPrivate
{
public:
QComboBox *m_abi;
QComboBox *m_architectureComboBox;
QComboBox *m_osComboBox;
QComboBox *m_osFlavorComboBox;
QComboBox *m_binaryFormatComboBox;
QComboBox *m_wordWidthComboBox;
};
} // namespace Internal
// --------------------------------------------------------------------------
// AbiWidget
// --------------------------------------------------------------------------
AbiWidget::AbiWidget(QWidget *parent) :
QWidget(parent),
d(new Internal::AbiWidgetPrivate)
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(2);
d->m_abi = new QComboBox(this);
layout->addWidget(d->m_abi);
connect(d->m_abi, SIGNAL(currentIndexChanged(int)), this, SLOT(modeChanged()));
layout->addSpacing(10);
d->m_architectureComboBox = new QComboBox(this);
layout->addWidget(d->m_architectureComboBox);
for (int i = 0; i <= static_cast<int>(Abi::UnknownArchitecture); ++i)
d->m_architectureComboBox->addItem(Abi::toString(static_cast<Abi::Architecture>(i)), i);
d->m_architectureComboBox->setCurrentIndex(static_cast<int>(Abi::UnknownArchitecture));
connect(d->m_architectureComboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(abiChanged()));
QLabel *separator1 = new QLabel(this);
separator1->setText(QLatin1String("-"));
layout->addWidget(separator1);
d->m_osComboBox = new QComboBox(this);
layout->addWidget(d->m_osComboBox);
for (int i = 0; i <= static_cast<int>(Abi::UnknownOS); ++i)
d->m_osComboBox->addItem(Abi::toString(static_cast<Abi::OS>(i)), i);
d->m_osComboBox->setCurrentIndex(static_cast<int>(Abi::UnknownOS));
connect(d->m_osComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(osChanged()));
QLabel *separator2 = new QLabel(this);
separator2->setText(QLatin1String("-"));
layout->addWidget(separator2);
d->m_osFlavorComboBox = new QComboBox(this);
layout->addWidget(d->m_osFlavorComboBox);
osChanged();
connect(d->m_osFlavorComboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(abiChanged()));
QLabel *separator3 = new QLabel(this);
separator3->setText(QLatin1String("-"));
layout->addWidget(separator3);
d->m_binaryFormatComboBox = new QComboBox(this);
layout->addWidget(d->m_binaryFormatComboBox);
for (int i = 0; i <= static_cast<int>(Abi::UnknownFormat); ++i)
d->m_binaryFormatComboBox->addItem(Abi::toString(static_cast<Abi::BinaryFormat>(i)), i);
d->m_binaryFormatComboBox->setCurrentIndex(static_cast<int>(Abi::UnknownFormat));
connect(d->m_binaryFormatComboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(abiChanged()));
QLabel *separator4 = new QLabel(this);
separator4->setText(QLatin1String("-"));
layout->addWidget(separator4);
d->m_wordWidthComboBox = new QComboBox(this);
layout->addWidget(d->m_wordWidthComboBox);
d->m_wordWidthComboBox->addItem(Abi::toString(32), 32);
d->m_wordWidthComboBox->addItem(Abi::toString(64), 64);
d->m_wordWidthComboBox->addItem(Abi::toString(0), 0);
d->m_wordWidthComboBox->setCurrentIndex(2);
connect(d->m_wordWidthComboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(abiChanged()));
layout->setStretchFactor(d->m_abi, 1);
setAbis(QList<Abi>(), Abi::hostAbi());
}
AbiWidget::~AbiWidget()
{
delete d;
}
void AbiWidget::setAbis(const QList<Abi> &abiList, const Abi ¤t)
{
blockSignals(true);
d->m_abi->clear();
d->m_abi->addItem(tr("<custom>"), QLatin1String("custom"));
d->m_abi->setCurrentIndex(0);
for (int i = 0; i < abiList.count(); ++i) {
const QString abiString = abiList.at(i).toString();
d->m_abi->addItem(abiString, abiString);
if (abiList.at(i) == current)
d->m_abi->setCurrentIndex(i + 1);
}
if (d->m_abi->currentIndex() == 0) {
if (!current.isValid() && !abiList.isEmpty())
d->m_abi->setCurrentIndex(1); // default to the first Abi if none is selected.
else
setCustomAbi(current);
}
modeChanged();
blockSignals(false);
}
Abi AbiWidget::currentAbi() const
{
if (d->m_abi->currentIndex() > 0)
return Abi(d->m_abi->itemData(d->m_abi->currentIndex()).toString());
return Abi(static_cast<Abi::Architecture>(d->m_architectureComboBox->currentIndex()),
static_cast<Abi::OS>(d->m_osComboBox->currentIndex()),
static_cast<Abi::OSFlavor>(d->m_osFlavorComboBox->itemData(d->m_osFlavorComboBox->currentIndex()).toInt()),
static_cast<Abi::BinaryFormat>(d->m_binaryFormatComboBox->currentIndex()),
d->m_wordWidthComboBox->itemData(d->m_wordWidthComboBox->currentIndex()).toInt());
}
void AbiWidget::osChanged()
{
d->m_osFlavorComboBox->blockSignals(true);
d->m_osFlavorComboBox->clear();
Abi::OS os = static_cast<Abi::OS>(d->m_osComboBox->itemData(d->m_osComboBox->currentIndex()).toInt());
QList<Abi::OSFlavor> flavors = Abi::flavorsForOs(os);
foreach (Abi::OSFlavor f, flavors)
d->m_osFlavorComboBox->addItem(Abi::toString(f), static_cast<int>(f));
d->m_osFlavorComboBox->setCurrentIndex(0); // default to generic flavor
d->m_osFlavorComboBox->blockSignals(false);
emit abiChanged();
}
void AbiWidget::modeChanged()
{
const bool customMode = (d->m_abi->currentIndex() == 0);
d->m_architectureComboBox->setEnabled(customMode);
d->m_osComboBox->setEnabled(customMode);
d->m_osFlavorComboBox->setEnabled(customMode);
d->m_binaryFormatComboBox->setEnabled(customMode);
d->m_wordWidthComboBox->setEnabled(customMode);
if (!customMode) {
Abi current(d->m_abi->itemData(d->m_abi->currentIndex()).toString());
setCustomAbi(current);
}
}
void AbiWidget::setCustomAbi(const Abi ¤t)
{
d->m_architectureComboBox->setCurrentIndex(static_cast<int>(current.architecture()));
d->m_osComboBox->setCurrentIndex(static_cast<int>(current.os()));
osChanged();
for (int i = 0; i < d->m_osFlavorComboBox->count(); ++i) {
if (d->m_osFlavorComboBox->itemData(i).toInt() == current.osFlavor()) {
d->m_osFlavorComboBox->setCurrentIndex(i);
break;
}
}
d->m_binaryFormatComboBox->setCurrentIndex(static_cast<int>(current.binaryFormat()));
for (int i = 0; i < d->m_wordWidthComboBox->count(); ++i) {
if (d->m_wordWidthComboBox->itemData(i).toInt() == current.wordWidth()) {
d->m_wordWidthComboBox->setCurrentIndex(i);
break;
}
}
}
} // namespace ProjectExplorer
|