1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "debuggertoolchaincombobox.h"
35 #include <projectexplorer/toolchainmanager.h>
36 #include <utils/qtcassert.h>
38 #include <QtCore/QFileInfo>
39 #include <QtCore/QDir>
40 #include <QtCore/QPair>
42 #include <QtGui/QtEvents>
44 typedef QPair<ProjectExplorer::Abi, QString> AbiDebuggerCommandPair;
46 Q_DECLARE_METATYPE(AbiDebuggerCommandPair)
51 DebuggerToolChainComboBox::DebuggerToolChainComboBox(QWidget *parent) :
56 void DebuggerToolChainComboBox::init(bool hostAbiOnly)
58 const ProjectExplorer::Abi hostAbi = ProjectExplorer::Abi::hostAbi();
59 foreach (const ProjectExplorer::ToolChain *tc, ProjectExplorer::ToolChainManager::instance()->toolChains()) {
60 const ProjectExplorer::Abi abi = tc->targetAbi();
61 if (!hostAbiOnly || hostAbi.os() == abi.os()) { // Offer MSVC and Mingw, etc.
62 const QString debuggerCommand = tc->debuggerCommand();
63 if (!debuggerCommand.isEmpty()) {
64 const AbiDebuggerCommandPair data(abi, debuggerCommand);
65 const QString completeBase = QFileInfo(debuggerCommand).completeBaseName();
66 const QString name = tr("%1 (%2)").arg(tc->displayName(), completeBase);
67 addItem(name, qVariantFromValue(data));
71 setEnabled(count() > 1);
74 void DebuggerToolChainComboBox::setAbi(const ProjectExplorer::Abi &abi)
76 QTC_ASSERT(abi.isValid(), return; )
77 const int c = count();
78 for (int i = 0; i < c; i++) {
79 if (abiAt(i) == abi) {
86 ProjectExplorer::Abi DebuggerToolChainComboBox::abi() const
88 return abiAt(currentIndex());
91 QString DebuggerToolChainComboBox::debuggerCommand() const
93 return debuggerCommandAt(currentIndex());
96 QString DebuggerToolChainComboBox::debuggerCommandAt(int index) const
98 if (index >= 0 && index < count()) {
99 const AbiDebuggerCommandPair abiCommandPair = qvariant_cast<AbiDebuggerCommandPair>(itemData(index));
100 return abiCommandPair.second;
105 ProjectExplorer::Abi DebuggerToolChainComboBox::abiAt(int index) const
107 if (index >= 0 && index < count()) {
108 const AbiDebuggerCommandPair abiCommandPair = qvariant_cast<AbiDebuggerCommandPair>(itemData(index));
109 return abiCommandPair.first;
111 return ProjectExplorer::Abi();
114 static inline QString abiToolTip(const AbiDebuggerCommandPair &abiCommandPair)
116 QString debugger = QDir::toNativeSeparators(abiCommandPair.second);
117 debugger.replace(QString(QLatin1Char(' ')), QLatin1String(" "));
118 return DebuggerToolChainComboBox::tr(
119 "<html><head/><body><table><tr><td>ABI:</td><td><i>%1</i></td></tr>"
120 "<tr><td>Debugger:</td><td>%2</td></tr>").
121 arg(abiCommandPair.first.toString(),
122 QDir::toNativeSeparators(debugger));
125 bool DebuggerToolChainComboBox::event(QEvent *event)
127 if (event->type() == QEvent::ToolTip) {
128 const int index = currentIndex();
130 const AbiDebuggerCommandPair abiCommandPair = qvariant_cast<AbiDebuggerCommandPair>(itemData(index));
131 setToolTip(abiToolTip(abiCommandPair));
133 setToolTip(QString());
136 return QComboBox::event(event);
139 } // namespace Debugger
140 } // namespace Internal