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 "cdboptionspage.h"
35 #include "cdboptions.h"
36 #include "debuggerconstants.h"
37 #include "cdbengine.h"
39 #include <utils/synchronousprocess.h>
41 #include <coreplugin/icore.h>
43 #include <QtCore/QTextStream>
44 #include <QtGui/QLineEdit>
45 #include <QtGui/QCheckBox>
50 struct EventsDescription {
51 const char *abbreviation;
53 const char *description;
56 // Parameters of the "sxe" command
57 const EventsDescription eventDescriptions[] =
59 {"eh", false, QT_TRANSLATE_NOOP("Debugger::Cdb::CdbBreakEventWidget",
61 {"ct", false, QT_TRANSLATE_NOOP("Debugger::Cdb::CdbBreakEventWidget",
63 {"et", false, QT_TRANSLATE_NOOP("Debugger::Cdb::CdbBreakEventWidget",
65 {"ld", true, QT_TRANSLATE_NOOP("Debugger::Cdb::CdbBreakEventWidget",
67 {"ud", true, QT_TRANSLATE_NOOP("Debugger::Cdb::CdbBreakEventWidget",
69 {"out", true, QT_TRANSLATE_NOOP("Debugger::Cdb::CdbBreakEventWidget",
73 static inline int indexOfEvent(const QString &abbrev)
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))
82 CdbBreakEventWidget::CdbBreakEventWidget(QWidget *parent) : QWidget(parent)
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));
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);
101 parameterLayout->addRow(cb, le);
102 if (parameterLayout->count() >= 4) // New column
105 leftLayout->addWidget(cb);
107 m_checkBoxes.push_back(cb);
108 m_lineEdits.push_back(le);
110 setLayout(mainLayout);
113 void CdbBreakEventWidget::clear()
115 foreach (QLineEdit *l, m_lineEdits) {
119 foreach (QCheckBox *c, m_checkBoxes)
120 c->setChecked(false);
123 void CdbBreakEventWidget::setBreakEvents(const QStringList &l)
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);
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));
138 QString CdbBreakEventWidget::filterText(int i) const
140 return m_lineEdits.at(i) ? m_lineEdits.at(i)->text() : QString();
143 QStringList CdbBreakEventWidget::breakEvents() const
145 // Compile a list of ("eh", "out:MyOutput")
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(':');
162 CdbOptionsPageWidget::CdbOptionsPageWidget(QWidget *parent) :
163 QWidget(parent), m_breakEventWidget(new CdbBreakEventWidget)
167 QVBoxLayout *eventLayout = new QVBoxLayout;
168 eventLayout->addWidget(m_breakEventWidget);
169 m_ui.eventGroupBox->setLayout(eventLayout);
172 void CdbOptionsPageWidget::setOptions(CdbOptions &o)
174 m_ui.additionalArgumentsLineEdit->setText(o.additionalArguments);
175 setSymbolPaths(o.symbolPaths);
176 m_ui.sourcePathListEditor->setPathList(o.sourcePaths);
177 m_breakEventWidget->setBreakEvents(o.breakEvents);
180 CdbOptions CdbOptionsPageWidget::options() const
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();
190 QStringList CdbOptionsPageWidget::symbolPaths() const
192 return m_ui.symbolPathListEditor->pathList();
195 void CdbOptionsPageWidget::setSymbolPaths(const QStringList &s)
197 m_ui.symbolPathListEditor->setPathList(s);
200 QString CdbOptionsPageWidget::searchKeywords() const
203 QTextStream(&rc) << m_ui.symbolPathLabel->text()
204 << ' ' << m_ui.sourcePathLabel->text();
205 rc.remove(QLatin1Char('&'));
209 // ---------- CdbOptionsPage
211 CdbOptionsPage *CdbOptionsPage::m_instance = 0;
213 CdbOptionsPage::CdbOptionsPage() :
214 m_options(new CdbOptions)
216 CdbOptionsPage::m_instance = this;
217 m_options->fromSettings(Core::ICore::instance()->settings());
220 CdbOptionsPage::~CdbOptionsPage()
222 CdbOptionsPage::m_instance = 0;
225 QString CdbOptionsPage::settingsId()
227 return QLatin1String("F.Cda"); // before old CDB
230 QString CdbOptionsPage::displayName() const
235 QString CdbOptionsPage::category() const
237 return QLatin1String(Debugger::Constants::DEBUGGER_SETTINGS_CATEGORY);
240 QString CdbOptionsPage::displayCategory() const
242 return QCoreApplication::translate("Debugger", Debugger::Constants::DEBUGGER_SETTINGS_TR_CATEGORY);
245 QIcon CdbOptionsPage::categoryIcon() const
247 return QIcon(QLatin1String(Debugger::Constants::DEBUGGER_COMMON_SETTINGS_CATEGORY_ICON));
250 QWidget *CdbOptionsPage::createPage(QWidget *parent)
252 m_widget = new CdbOptionsPageWidget(parent);
253 m_widget->setOptions(*m_options);
254 if (m_searchKeywords.isEmpty())
255 m_searchKeywords = m_widget->searchKeywords();
259 void CdbOptionsPage::apply()
263 const CdbOptions newOptions = m_widget->options();
264 if (*m_options != newOptions) {
265 *m_options = newOptions;
266 m_options->toSettings(Core::ICore::instance()->settings());
270 void CdbOptionsPage::finish()
274 bool CdbOptionsPage::matches(const QString &s) const
276 return m_searchKeywords.contains(s, Qt::CaseInsensitive);
279 CdbOptionsPage *CdbOptionsPage::instance()
284 } // namespace Internal
285 } // namespace Debugger