1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "debuggertoolchaincombobox.h"
36 #include <projectexplorer/toolchainmanager.h>
37 #include <utils/qtcassert.h>
39 #include <QtCore/QFileInfo>
40 #include <QtCore/QDir>
41 #include <QtCore/QPair>
43 #include <QtGui/QtEvents>
45 typedef QPair<ProjectExplorer::Abi, QString> AbiDebuggerCommandPair;
47 Q_DECLARE_METATYPE(AbiDebuggerCommandPair)
52 DebuggerToolChainComboBox::DebuggerToolChainComboBox(QWidget *parent) :
57 void DebuggerToolChainComboBox::init(bool hostAbiOnly)
59 const ProjectExplorer::Abi hostAbi = ProjectExplorer::Abi::hostAbi();
60 foreach (const ProjectExplorer::ToolChain *tc, ProjectExplorer::ToolChainManager::instance()->toolChains()) {
61 const ProjectExplorer::Abi abi = tc->targetAbi();
62 if (!hostAbiOnly || hostAbi.os() == abi.os()) { // Offer MSVC and Mingw, etc.
63 const QString debuggerCommand = tc->debuggerCommand();
64 if (!debuggerCommand.isEmpty()) {
65 const AbiDebuggerCommandPair data(abi, debuggerCommand);
66 const QString completeBase = QFileInfo(debuggerCommand).completeBaseName();
67 const QString name = tr("%1 (%2)").arg(tc->displayName(), completeBase);
68 addItem(name, qVariantFromValue(data));
72 setEnabled(count() > 1);
75 void DebuggerToolChainComboBox::setAbi(const ProjectExplorer::Abi &abi)
77 QTC_ASSERT(abi.isValid(), return; )
78 const int c = count();
79 for (int i = 0; i < c; i++) {
80 if (abiAt(i) == abi) {
87 ProjectExplorer::Abi DebuggerToolChainComboBox::abi() const
89 return abiAt(currentIndex());
92 QString DebuggerToolChainComboBox::debuggerCommand() const
94 return debuggerCommandAt(currentIndex());
97 QString DebuggerToolChainComboBox::debuggerCommandAt(int index) const
99 if (index >= 0 && index < count()) {
100 const AbiDebuggerCommandPair abiCommandPair = qvariant_cast<AbiDebuggerCommandPair>(itemData(index));
101 return abiCommandPair.second;
106 ProjectExplorer::Abi DebuggerToolChainComboBox::abiAt(int index) const
108 if (index >= 0 && index < count()) {
109 const AbiDebuggerCommandPair abiCommandPair = qvariant_cast<AbiDebuggerCommandPair>(itemData(index));
110 return abiCommandPair.first;
112 return ProjectExplorer::Abi();
115 static inline QString abiToolTip(const AbiDebuggerCommandPair &abiCommandPair)
117 QString debugger = QDir::toNativeSeparators(abiCommandPair.second);
118 debugger.replace(QString(QLatin1Char(' ')), QLatin1String(" "));
119 return DebuggerToolChainComboBox::tr(
120 "<html><head/><body><table><tr><td>ABI:</td><td><i>%1</i></td></tr>"
121 "<tr><td>Debugger:</td><td>%2</td></tr>").
122 arg(abiCommandPair.first.toString(),
123 QDir::toNativeSeparators(debugger));
126 bool DebuggerToolChainComboBox::event(QEvent *event)
128 if (event->type() == QEvent::ToolTip) {
129 const int index = currentIndex();
131 const AbiDebuggerCommandPair abiCommandPair = qvariant_cast<AbiDebuggerCommandPair>(itemData(index));
132 setToolTip(abiToolTip(abiCommandPair));
134 setToolTip(QString());
137 return QComboBox::event(event);
140 } // namespace Debugger
141 } // namespace Internal