OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / debuggertoolchaincombobox.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "debuggertoolchaincombobox.h"
34
35 #include <projectexplorer/toolchainmanager.h>
36 #include <utils/qtcassert.h>
37
38 #include <QtCore/QFileInfo>
39 #include <QtCore/QDir>
40 #include <QtCore/QPair>
41
42 #include <QtGui/QtEvents>
43
44 typedef QPair<ProjectExplorer::Abi, QString> AbiDebuggerCommandPair;
45
46 Q_DECLARE_METATYPE(AbiDebuggerCommandPair)
47
48 namespace Debugger {
49 namespace Internal {
50
51 DebuggerToolChainComboBox::DebuggerToolChainComboBox(QWidget *parent) :
52     QComboBox(parent)
53 {
54 }
55
56 void DebuggerToolChainComboBox::init(bool hostAbiOnly)
57 {
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));
68             }
69         }
70     }
71     setEnabled(count() > 1);
72 }
73
74 void DebuggerToolChainComboBox::setAbi(const ProjectExplorer::Abi &abi)
75 {
76     QTC_ASSERT(abi.isValid(), return; )
77     const int c = count();
78     for (int i = 0; i < c; i++) {
79         if (abiAt(i) == abi) {
80             setCurrentIndex(i);
81             break;
82         }
83     }
84 }
85
86 ProjectExplorer::Abi DebuggerToolChainComboBox::abi() const
87 {
88     return abiAt(currentIndex());
89 }
90
91 QString DebuggerToolChainComboBox::debuggerCommand() const
92 {
93     return debuggerCommandAt(currentIndex());
94 }
95
96 QString DebuggerToolChainComboBox::debuggerCommandAt(int index) const
97 {
98     if (index >= 0 && index < count()) {
99         const AbiDebuggerCommandPair abiCommandPair = qvariant_cast<AbiDebuggerCommandPair>(itemData(index));
100         return abiCommandPair.second;
101     }
102     return QString();
103 }
104
105 ProjectExplorer::Abi DebuggerToolChainComboBox::abiAt(int index) const
106 {
107     if (index >= 0 && index < count()) {
108         const AbiDebuggerCommandPair abiCommandPair = qvariant_cast<AbiDebuggerCommandPair>(itemData(index));
109         return abiCommandPair.first;
110     }
111     return ProjectExplorer::Abi();
112 }
113
114 static inline QString abiToolTip(const AbiDebuggerCommandPair &abiCommandPair)
115 {
116     QString debugger = QDir::toNativeSeparators(abiCommandPair.second);
117     debugger.replace(QString(QLatin1Char(' ')), QLatin1String("&nbsp;"));
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));
123 }
124
125 bool DebuggerToolChainComboBox::event(QEvent *event)
126 {
127     if (event->type() == QEvent::ToolTip) {
128         const int index = currentIndex();
129         if (index >= 0) {
130             const AbiDebuggerCommandPair abiCommandPair = qvariant_cast<AbiDebuggerCommandPair>(itemData(index));
131             setToolTip(abiToolTip(abiCommandPair));
132         } else {
133             setToolTip(QString());
134         }
135     }
136     return QComboBox::event(event);
137 }
138
139 } // namespace Debugger
140 } // namespace Internal