Skip to content
Snippets Groups Projects
Commit 2a9e8af4 authored by hjk's avatar hjk
Browse files

debugger: code cosmetics

parent 126aa9ec
No related branches found
No related tags found
No related merge requests found
......@@ -54,9 +54,10 @@
// Qt's various build paths for unpatched versions.
#if defined(Q_OS_WIN)
static const char* qtBuildPaths[] = {
"C:/qt-greenhouse/Trolltech/Code_less_create_more/Trolltech/Code_less_create_more/Troll/4.6/qt",
"C:/iwmake/build_mingw_opensource",
"C:/ndk_buildrepos/qt-desktop/src"};
"C:/qt-greenhouse/Trolltech/Code_less_create_more/"
"Trolltech/Code_less_create_more/Troll/4.6/qt",
"C:/iwmake/build_mingw_opensource",
"C:/ndk_buildrepos/qt-desktop/src"};
#elif defined(Q_OS_MAC)
static const char* qtBuildPaths[] = {};
#else
......@@ -68,6 +69,9 @@ enum { SourceColumn, TargetColumn, ColumnCount };
namespace Debugger {
namespace Internal {
typedef QPair<QString, QString> Mapping;
typedef DebuggerSourcePathMappingWidget::SourcePathMap SourcePathMap;
/*!
\class SourcePathMappingModel
......@@ -79,13 +83,11 @@ namespace Internal {
class SourcePathMappingModel : public QStandardItemModel
{
public:
typedef QPair<QString, QString> Mapping;
typedef DebuggerSourcePathMappingWidget::SourcePathMap SourcePathMap;
explicit SourcePathMappingModel(QObject *parent);
SourcePathMap sourcePathMap() const;
void setSourcePathMap(const SourcePathMap&);
void setSourcePathMap(const SourcePathMap &map);
Mapping mappingAt(int row) const;
bool isNewPlaceHolderAt(int row) { return isNewPlaceHolder(rawMappingAt(row)); }
......@@ -114,15 +116,16 @@ SourcePathMappingModel::SourcePathMappingModel(QObject *parent) :
m_newTargetPlaceHolder(DebuggerSourcePathMappingWidget::tr("<new target>"))
{
QStringList headers;
headers << DebuggerSourcePathMappingWidget::tr("Source path") << DebuggerSourcePathMappingWidget::tr("Target path");
headers.append(DebuggerSourcePathMappingWidget::tr("Source path"));
headers.append(DebuggerSourcePathMappingWidget::tr("Target path"));
setHorizontalHeaderLabels(headers);
}
SourcePathMappingModel::SourcePathMap SourcePathMappingModel::sourcePathMap() const
SourcePathMap SourcePathMappingModel::sourcePathMap() const
{
SourcePathMap rc;
const int rows = rowCount();
for (int r = 0; r < rows; r++) {
for (int r = 0; r < rows; ++r) {
const QPair<QString, QString> m = mappingAt(r); // Skip placeholders.
if (!m.first.isEmpty() && !m.second.isEmpty())
rc.insert(m.first, m.second);
......@@ -135,23 +138,26 @@ bool SourcePathMappingModel::isNewPlaceHolder(const Mapping &m) const
{
const QLatin1Char lessThan('<');
const QLatin1Char greaterThan('<');
return m.first.isEmpty() || m.first.startsWith(lessThan) || m.first.endsWith(greaterThan)
return m.first.isEmpty() || m.first.startsWith(lessThan)
|| m.first.endsWith(greaterThan)
|| m.first == m_newSourcePlaceHolder
|| m.second.isEmpty() || m.second.startsWith(lessThan) || m.second.endsWith(greaterThan)
|| m.second.isEmpty() || m.second.startsWith(lessThan)
|| m.second.endsWith(greaterThan)
|| m.second == m_newTargetPlaceHolder;
}
// Return raw, unfixed mapping
SourcePathMappingModel::Mapping SourcePathMappingModel::rawMappingAt(int row) const
Mapping SourcePathMappingModel::rawMappingAt(int row) const
{
return Mapping(item(row, SourceColumn)->text(), item(row, TargetColumn)->text());
}
// Return mapping, empty if it is the place holder.
SourcePathMappingModel::Mapping SourcePathMappingModel::mappingAt(int row) const
Mapping SourcePathMappingModel::mappingAt(int row) const
{
const Mapping raw = rawMappingAt(row);
return isNewPlaceHolder(raw) ? Mapping() : Mapping(QDir::cleanPath(raw.first), QDir::cleanPath(raw.second));
return isNewPlaceHolder(raw) ? Mapping()
: Mapping(QDir::cleanPath(raw.first), QDir::cleanPath(raw.second));
}
void SourcePathMappingModel::setSourcePathMap(const SourcePathMap &m)
......@@ -206,24 +212,29 @@ DebuggerSourcePathMappingWidget::DebuggerSourcePathMappingWidget(QWidget *parent
m_targetChooser(new Utils::PathChooser)
{
setTitle(tr("Source Paths Mapping"));
setToolTip(tr("<html><head/><body><p>Mappings of source file folders to be used in the debugger can be entered here.</p>"
"<p>This is useful when using a copy of the source tree at a location different from the one "
"at which the modules where built, for example, while doing remote debugging.</body></html>"));
setToolTip(tr("<html><head/><body><p>Mappings of source file folders to "
"be used in the debugger can be entered here.</p>"
"<p>This is useful when using a copy of the source tree "
"at a location different from the one "
"at which the modules where built, for example, while "
"doing remote debugging.</body></html>"));
// Top list/left part.
m_treeView->setRootIsDecorated(false);
m_treeView->setUniformRowHeights(true);
m_treeView->setSelectionMode(QAbstractItemView::SingleSelection);
m_treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
m_treeView->setModel(m_model);
connect(m_treeView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
this, SLOT(slotCurrentRowChanged(QModelIndex,QModelIndex)));
connect(m_treeView->selectionModel(),
SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
SLOT(slotCurrentRowChanged(QModelIndex,QModelIndex)));
// Top list/Right part: Buttons.
QVBoxLayout *buttonLayout = new QVBoxLayout;
buttonLayout->addWidget(m_addButton);
buttonLayout->addWidget(m_addQtButton);
m_addQtButton->setVisible(sizeof(qtBuildPaths) > 0);
m_addQtButton->setToolTip(tr("Add a mapping for Qt's source folders when using an unpatched version of Qt."));
m_addQtButton->setToolTip(tr("Add a mapping for Qt's source folders "
"when using an unpatched version of Qt."));
buttonLayout->addWidget(m_removeButton);
connect(m_addButton, SIGNAL(clicked()), this, SLOT(slotAdd()));
connect(m_addQtButton, SIGNAL(clicked()), this, SLOT(slotAddQt()));
......@@ -238,17 +249,21 @@ DebuggerSourcePathMappingWidget::DebuggerSourcePathMappingWidget(QWidget *parent
// Edit part
m_targetChooser->setExpectedKind(Utils::PathChooser::ExistingDirectory);
connect(m_sourceLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotEditSourceFieldChanged()));
connect(m_targetChooser, SIGNAL(changed(QString)), this, SLOT(slotEditTargetFieldChanged()));
connect(m_sourceLineEdit, SIGNAL(textChanged(QString)),
this, SLOT(slotEditSourceFieldChanged()));
connect(m_targetChooser, SIGNAL(changed(QString)),
this, SLOT(slotEditTargetFieldChanged()));
QFormLayout *editLayout = new QFormLayout;
const QString sourceToolTip = tr("The source path contained in the executable's debug information as reported by the debugger");
const QString sourceToolTip = tr("The source path contained in the "
"debug information of the executable as reported by the debugger");
QLabel *editSourceLabel = new QLabel(tr("&Source path:"));
editSourceLabel->setToolTip(sourceToolTip);
m_sourceLineEdit->setToolTip(sourceToolTip);
editSourceLabel->setBuddy(m_sourceLineEdit);
editLayout->addRow(editSourceLabel, m_sourceLineEdit);
const QString targetToolTip = tr("The actual location of the source tree on the local machine");
const QString targetToolTip = tr("The actual location of the source "
"tree on the local machine");
QLabel *editTargetLabel = new QLabel(tr("&Target path:"));
editTargetLabel->setToolTip(targetToolTip);
editTargetLabel->setBuddy(m_targetChooser);
......@@ -273,15 +288,17 @@ QString DebuggerSourcePathMappingWidget::editTargetField() const
return m_targetChooser->path();
}
void DebuggerSourcePathMappingWidget::setEditFieldMapping(const QPair<QString, QString> &m)
void DebuggerSourcePathMappingWidget::setEditFieldMapping(const Mapping &m)
{
m_sourceLineEdit->setText(QDir::toNativeSeparators(m.first));
m_targetChooser->setPath(m.second);
}
void DebuggerSourcePathMappingWidget::slotCurrentRowChanged(const QModelIndex &current,const QModelIndex &)
void DebuggerSourcePathMappingWidget::slotCurrentRowChanged
(const QModelIndex &current, const QModelIndex &)
{
setEditFieldMapping(current.isValid() ? m_model->mappingAt(current.row()) : QPair<QString, QString>());
setEditFieldMapping(current.isValid()
? m_model->mappingAt(current.row()) : Mapping());
updateEnabled();
}
......@@ -298,13 +315,14 @@ void DebuggerSourcePathMappingWidget::updateEnabled()
m_sourceLineEdit->setEnabled(hasCurrent);
m_targetChooser->setEnabled(hasCurrent);
m_removeButton->setEnabled(hasCurrent);
// Allow for adding only if the current item no longer is the place holder for new items.
// Allow for adding only if the current item no longer is the place
// holder for new items.
const bool canAdd = !hasCurrent || !m_model->isNewPlaceHolderAt(row);
m_addButton->setEnabled(canAdd);
m_addQtButton->setEnabled(canAdd);
}
DebuggerSourcePathMappingWidget::SourcePathMap DebuggerSourcePathMappingWidget::sourcePathMap() const
SourcePathMap DebuggerSourcePathMappingWidget::sourcePathMap() const
{
return m_model->sourcePathMap();
}
......@@ -339,11 +357,12 @@ void DebuggerSourcePathMappingWidget::slotAdd()
void DebuggerSourcePathMappingWidget::slotAddQt()
{
// Add a mapping for various Qt build locations in case of unpatched builds.
const QString qtSourcesPath = QFileDialog::getExistingDirectory(this, tr("Qt Sources"));
const QString qtSourcesPath =
QFileDialog::getExistingDirectory(this, tr("Qt Sources"));
if (qtSourcesPath.isEmpty())
return;
const size_t buildPathCount = sizeof(qtBuildPaths)/sizeof(const char *);
for (size_t i = 0; i < buildPathCount; i++)
const size_t buildPathCount = sizeof(qtBuildPaths)/sizeof(qtBuildPaths[0]);
for (size_t i = 0; i < buildPathCount; ++i)
m_model->addMapping(QString::fromLatin1(qtBuildPaths[i]), qtSourcesPath);
resizeColumns();
setCurrentRow(m_model->rowCount() - 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment