OSDN Git Service

18caf5ac8429a7ed91c9761cd544d86ed17da8f9
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / cdb / cdboptionspage.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 (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "cdboptionspage.h"
35 #include "cdboptions.h"
36 #include "debuggerconstants.h"
37 #include "cdbengine.h"
38
39 #include <utils/synchronousprocess.h>
40
41 #include <coreplugin/icore.h>
42
43 #include <QtCore/QTextStream>
44 #include <QtGui/QLineEdit>
45 #include <QtGui/QCheckBox>
46
47 namespace Debugger {
48 namespace Internal {
49
50 struct EventsDescription {
51     const char *abbreviation;
52     bool hasParameter;
53     const char *description;
54 };
55
56 // Parameters of the "sxe" command
57 const EventsDescription eventDescriptions[] =
58 {
59     {"eh", false, QT_TRANSLATE_NOOP("Debugger::Cdb::CdbBreakEventWidget",
60                                     "C++ exception")},
61     {"ct", false, QT_TRANSLATE_NOOP("Debugger::Cdb::CdbBreakEventWidget",
62                                     "Thread creation")},
63     {"et", false, QT_TRANSLATE_NOOP("Debugger::Cdb::CdbBreakEventWidget",
64                                     "Thread exit")},
65     {"ld", true,  QT_TRANSLATE_NOOP("Debugger::Cdb::CdbBreakEventWidget",
66                                     "Load Module:")},
67     {"ud", true,  QT_TRANSLATE_NOOP("Debugger::Cdb::CdbBreakEventWidget",
68                                     "Unload Module:")},
69     {"out", true, QT_TRANSLATE_NOOP("Debugger::Cdb::CdbBreakEventWidget",
70                                     "Output:")}
71 };
72
73 static inline int indexOfEvent(const QString &abbrev)
74 {
75     const size_t eventCount = sizeof(eventDescriptions) / sizeof(EventsDescription);
76     for (size_t e = 0; e < eventCount; e++)
77         if (abbrev == QLatin1String(eventDescriptions[e].abbreviation))
78                 return int(e);
79     return -1;
80 }
81
82 CdbBreakEventWidget::CdbBreakEventWidget(QWidget *parent) : QWidget(parent)
83 {
84     // 1 column with checkboxes only,
85     // further columns with checkbox + parameter
86     QHBoxLayout *mainLayout = new QHBoxLayout;
87     QVBoxLayout *leftLayout = new QVBoxLayout;
88     QFormLayout *parameterLayout = 0;
89     mainLayout->addLayout(leftLayout);
90     const size_t eventCount = sizeof(eventDescriptions) / sizeof(EventsDescription);
91     for (size_t e = 0; e < eventCount; e++) {
92         QCheckBox *cb = new QCheckBox(tr(eventDescriptions[e].description));
93         QLineEdit *le = 0;
94         if (eventDescriptions[e].hasParameter) {
95             if (!parameterLayout) {
96                 parameterLayout = new QFormLayout;
97                 mainLayout->addSpacerItem(new QSpacerItem(20, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
98                 mainLayout->addLayout(parameterLayout);
99             }
100             le = new QLineEdit;
101             parameterLayout->addRow(cb, le);
102             if (parameterLayout->count() >= 4) // New column
103                 parameterLayout = 0;
104         } else {
105             leftLayout->addWidget(cb);
106         }
107         m_checkBoxes.push_back(cb);
108         m_lineEdits.push_back(le);
109     }
110     setLayout(mainLayout);
111 }
112
113 void CdbBreakEventWidget::clear()
114 {
115     foreach (QLineEdit *l, m_lineEdits) {
116         if (l)
117             l->clear();
118     }
119     foreach (QCheckBox *c, m_checkBoxes)
120         c->setChecked(false);
121 }
122
123 void CdbBreakEventWidget::setBreakEvents(const QStringList &l)
124 {
125     clear();
126     // Split the list of ("eh", "out:MyOutput")
127     foreach (const QString &evt, l) {
128         const int colonPos = evt.indexOf(QLatin1Char(':'));
129         const QString abbrev = colonPos != -1 ? evt.mid(0, colonPos) : evt;
130         const int index = indexOfEvent(abbrev);
131         if (index != -1)
132             m_checkBoxes.at(index)->setChecked(true);
133         if (colonPos != -1 && m_lineEdits.at(index))
134             m_lineEdits.at(index)->setText(evt.mid(colonPos + 1));
135     }
136 }
137
138 QString CdbBreakEventWidget::filterText(int i) const
139 {
140     return m_lineEdits.at(i) ? m_lineEdits.at(i)->text() : QString();
141 }
142
143 QStringList CdbBreakEventWidget::breakEvents() const
144 {
145     // Compile a list of ("eh", "out:MyOutput")
146     QStringList rc;
147     const int eventCount = sizeof(eventDescriptions) / sizeof(EventsDescription);
148     for (int e = 0; e < eventCount; e++) {
149         if (m_checkBoxes.at(e)->isChecked()) {
150             const QString filter = filterText(e);
151             QString s = QLatin1String(eventDescriptions[e].abbreviation);
152             if (!filter.isEmpty()) {
153                 s += QLatin1Char(':');
154                 s += filter;
155             }
156             rc.push_back(s);
157         }
158     }
159     return rc;
160 }
161
162 CdbOptionsPageWidget::CdbOptionsPageWidget(QWidget *parent) :
163     QWidget(parent), m_breakEventWidget(new CdbBreakEventWidget)
164 {
165     m_ui.setupUi(this);
166
167     QVBoxLayout *eventLayout = new QVBoxLayout;
168     eventLayout->addWidget(m_breakEventWidget);
169     m_ui.eventGroupBox->setLayout(eventLayout);
170 }
171
172 void CdbOptionsPageWidget::setOptions(CdbOptions &o)
173 {
174     m_ui.additionalArgumentsLineEdit->setText(o.additionalArguments);
175     setSymbolPaths(o.symbolPaths);
176     m_ui.sourcePathListEditor->setPathList(o.sourcePaths);
177     m_breakEventWidget->setBreakEvents(o.breakEvents);
178 }
179
180 CdbOptions CdbOptionsPageWidget::options() const
181 {
182     CdbOptions  rc;
183     rc.additionalArguments = m_ui.additionalArgumentsLineEdit->text().trimmed();
184     rc.symbolPaths = symbolPaths();
185     rc.sourcePaths = m_ui.sourcePathListEditor->pathList();
186     rc.breakEvents = m_breakEventWidget->breakEvents();
187     return rc;
188 }
189
190 QStringList CdbOptionsPageWidget::symbolPaths() const
191 {
192     return m_ui.symbolPathListEditor->pathList();
193 }
194
195 void CdbOptionsPageWidget::setSymbolPaths(const QStringList &s)
196 {
197     m_ui.symbolPathListEditor->setPathList(s);
198 }
199
200 QString CdbOptionsPageWidget::searchKeywords() const
201 {
202     QString rc;
203     QTextStream(&rc) << m_ui.symbolPathLabel->text()
204             << ' ' << m_ui.sourcePathLabel->text();
205     rc.remove(QLatin1Char('&'));
206     return rc;
207 }
208
209 // ---------- CdbOptionsPage
210
211 CdbOptionsPage *CdbOptionsPage::m_instance = 0;
212
213 CdbOptionsPage::CdbOptionsPage() :
214         m_options(new CdbOptions)
215 {
216     CdbOptionsPage::m_instance = this;
217     m_options->fromSettings(Core::ICore::instance()->settings());
218 }
219
220 CdbOptionsPage::~CdbOptionsPage()
221 {
222     CdbOptionsPage::m_instance = 0;
223 }
224
225 QString CdbOptionsPage::settingsId()
226 {
227     return QLatin1String("F.Cda"); // before old CDB
228 }
229
230 QString CdbOptionsPage::displayName() const
231 {
232     return tr("CDB");
233 }
234
235 QString CdbOptionsPage::category() const
236 {
237     return QLatin1String(Debugger::Constants::DEBUGGER_SETTINGS_CATEGORY);
238 }
239
240 QString CdbOptionsPage::displayCategory() const
241 {
242     return QCoreApplication::translate("Debugger", Debugger::Constants::DEBUGGER_SETTINGS_TR_CATEGORY);
243 }
244
245 QIcon CdbOptionsPage::categoryIcon() const
246 {
247     return QIcon(QLatin1String(Debugger::Constants::DEBUGGER_COMMON_SETTINGS_CATEGORY_ICON));
248 }
249
250 QWidget *CdbOptionsPage::createPage(QWidget *parent)
251 {
252     m_widget = new CdbOptionsPageWidget(parent);
253     m_widget->setOptions(*m_options);
254     if (m_searchKeywords.isEmpty())
255         m_searchKeywords = m_widget->searchKeywords();
256     return m_widget;
257 }
258
259 void CdbOptionsPage::apply()
260 {
261     if (!m_widget)
262         return;
263     const CdbOptions newOptions = m_widget->options();
264     if (*m_options != newOptions) {
265         *m_options = newOptions;
266         m_options->toSettings(Core::ICore::instance()->settings());
267     }
268 }
269
270 void CdbOptionsPage::finish()
271 {
272 }
273
274 bool CdbOptionsPage::matches(const QString &s) const
275 {
276     return m_searchKeywords.contains(s, Qt::CaseInsensitive);
277 }
278
279 CdbOptionsPage *CdbOptionsPage::instance()
280 {
281     return m_instance;
282 }
283
284 } // namespace Internal
285 } // namespace Debugger