2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-03-04 16:21:57 +01:00
|
|
|
|
|
|
|
|
#include "debuggersourcepathmappingwidget.h"
|
2021-03-05 12:48:26 +01:00
|
|
|
|
2023-07-18 10:49:35 +02:00
|
|
|
#include "commonoptionspage.h"
|
2015-05-27 13:59:56 +02:00
|
|
|
#include "debuggerengine.h"
|
2022-07-05 15:37:08 +02:00
|
|
|
#include "debuggertr.h"
|
2011-03-04 16:21:57 +01:00
|
|
|
|
2012-08-09 04:25:13 +02:00
|
|
|
#include <utils/buildablehelperlibrary.h>
|
2014-09-21 09:27:08 +03:00
|
|
|
#include <utils/fancylineedit.h>
|
2020-09-18 12:11:40 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2021-03-05 12:48:26 +01:00
|
|
|
#include <utils/layoutbuilder.h>
|
2011-03-04 16:21:57 +01:00
|
|
|
#include <utils/pathchooser.h>
|
2023-05-03 17:05:35 +02:00
|
|
|
#include <utils/process.h>
|
2011-03-04 16:21:57 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2020-09-18 12:11:40 +02:00
|
|
|
#include <utils/variablechooser.h>
|
2011-03-04 16:21:57 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileDialog>
|
2021-03-05 12:48:26 +01:00
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QGroupBox>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QLabel>
|
2021-03-05 12:48:26 +01:00
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
|
#include <QTreeView>
|
2011-03-04 16:21:57 +01:00
|
|
|
|
2012-08-09 04:25:13 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2022-07-05 15:37:08 +02:00
|
|
|
namespace Debugger::Internal {
|
2011-03-04 16:21:57 +01:00
|
|
|
|
2021-03-05 12:48:26 +01:00
|
|
|
class SourcePathMappingModel;
|
|
|
|
|
|
|
|
|
|
enum { SourceColumn, TargetColumn, ColumnCount };
|
|
|
|
|
|
2021-09-28 12:38:08 +02:00
|
|
|
using Mapping = QPair<FilePath, FilePath>;
|
2021-03-05 12:48:26 +01:00
|
|
|
|
|
|
|
|
class DebuggerSourcePathMappingWidget : public QGroupBox
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DebuggerSourcePathMappingWidget();
|
|
|
|
|
|
|
|
|
|
SourcePathMap sourcePathMap() const;
|
|
|
|
|
void setSourcePathMap(const SourcePathMap &);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void slotAdd();
|
|
|
|
|
void slotAddQt();
|
|
|
|
|
void slotRemove();
|
|
|
|
|
void slotCurrentRowChanged(const QModelIndex &,const QModelIndex &);
|
|
|
|
|
void slotEditSourceFieldChanged();
|
|
|
|
|
void slotEditTargetFieldChanged();
|
|
|
|
|
|
|
|
|
|
void resizeColumns();
|
|
|
|
|
void updateEnabled();
|
|
|
|
|
QString editSourceField() const;
|
|
|
|
|
QString editTargetField() const;
|
2021-09-28 12:38:08 +02:00
|
|
|
void setEditFieldMapping(const Mapping &m);
|
2021-03-05 12:48:26 +01:00
|
|
|
int currentRow() const;
|
|
|
|
|
void setCurrentRow(int r);
|
|
|
|
|
|
|
|
|
|
SourcePathMappingModel *m_model;
|
|
|
|
|
QTreeView *m_treeView;
|
|
|
|
|
QPushButton *m_addButton;
|
|
|
|
|
QPushButton *m_addQtButton;
|
|
|
|
|
QPushButton *m_removeButton;
|
|
|
|
|
QLineEdit *m_sourceLineEdit;
|
|
|
|
|
Utils::PathChooser *m_targetChooser;
|
|
|
|
|
};
|
2011-03-11 13:19:20 +01:00
|
|
|
|
2017-12-08 13:55:15 +01:00
|
|
|
// Qt's various build paths for unpatched versions.
|
|
|
|
|
QStringList qtBuildPaths()
|
|
|
|
|
{
|
|
|
|
|
if (HostOsInfo::isWindowsHost()) {
|
|
|
|
|
return {"Q:/qt5_workdir/w/s",
|
|
|
|
|
"C:/work/build/qt5_workdir/w/s",
|
|
|
|
|
"c:/users/qt/work/qt",
|
2022-03-09 13:38:41 +01:00
|
|
|
"c:/Users/qt/work/install",
|
|
|
|
|
"/Users/qt/work/qt"};
|
2018-09-25 15:16:46 +02:00
|
|
|
} else if (HostOsInfo::isMacHost()) {
|
|
|
|
|
return { "/Users/qt/work/qt" };
|
2017-12-08 13:55:15 +01:00
|
|
|
} else {
|
2018-09-24 13:57:16 +02:00
|
|
|
return { "/home/qt/work/qt" };
|
2017-12-08 13:55:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-04 16:21:57 +01:00
|
|
|
/*!
|
2011-03-28 14:58:12 +02:00
|
|
|
\class Debugger::Internal::SourcePathMappingModel
|
2011-03-04 16:21:57 +01:00
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The SourcePathMappingModel class is a model for the
|
|
|
|
|
DebuggerSourcePathMappingWidget class.
|
2011-03-04 16:21:57 +01:00
|
|
|
|
|
|
|
|
Maintains mappings and a dummy placeholder row for adding new mappings.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class SourcePathMappingModel : public QStandardItemModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
explicit SourcePathMappingModel(QObject *parent);
|
|
|
|
|
|
|
|
|
|
SourcePathMap sourcePathMap() const;
|
2011-03-11 13:19:20 +01:00
|
|
|
void setSourcePathMap(const SourcePathMap &map);
|
2011-03-04 16:21:57 +01:00
|
|
|
|
|
|
|
|
Mapping mappingAt(int row) const;
|
|
|
|
|
bool isNewPlaceHolderAt(int row) { return isNewPlaceHolder(rawMappingAt(row)); }
|
|
|
|
|
|
|
|
|
|
void addMapping(const QString &source, const QString &target)
|
2014-09-13 23:30:34 +03:00
|
|
|
{ addRawMapping(source, QDir::toNativeSeparators(target)); }
|
2011-03-04 16:21:57 +01:00
|
|
|
|
|
|
|
|
void addNewMappingPlaceHolder()
|
|
|
|
|
{ addRawMapping(m_newSourcePlaceHolder, m_newTargetPlaceHolder); }
|
|
|
|
|
|
|
|
|
|
void setSource(int row, const QString &);
|
|
|
|
|
void setTarget(int row, const QString &);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
inline bool isNewPlaceHolder(const Mapping &m) const;
|
|
|
|
|
inline Mapping rawMappingAt(int row) const;
|
|
|
|
|
void addRawMapping(const QString &source, const QString &target);
|
|
|
|
|
|
|
|
|
|
const QString m_newSourcePlaceHolder;
|
|
|
|
|
const QString m_newTargetPlaceHolder;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SourcePathMappingModel::SourcePathMappingModel(QObject *parent) :
|
|
|
|
|
QStandardItemModel(0, ColumnCount, parent),
|
2022-07-05 15:37:08 +02:00
|
|
|
m_newSourcePlaceHolder(Tr::tr("<new source>")),
|
|
|
|
|
m_newTargetPlaceHolder(Tr::tr("<new target>"))
|
2011-03-04 16:21:57 +01:00
|
|
|
{
|
|
|
|
|
QStringList headers;
|
2022-07-05 15:37:08 +02:00
|
|
|
headers.append(Tr::tr("Source path"));
|
|
|
|
|
headers.append(Tr::tr("Target path"));
|
2011-03-04 16:21:57 +01:00
|
|
|
setHorizontalHeaderLabels(headers);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 13:19:20 +01:00
|
|
|
SourcePathMap SourcePathMappingModel::sourcePathMap() const
|
2011-03-04 16:21:57 +01:00
|
|
|
{
|
|
|
|
|
SourcePathMap rc;
|
|
|
|
|
const int rows = rowCount();
|
2011-03-11 13:19:20 +01:00
|
|
|
for (int r = 0; r < rows; ++r) {
|
2021-09-28 12:38:08 +02:00
|
|
|
const Mapping m = mappingAt(r); // Skip placeholders.
|
2011-03-04 16:21:57 +01:00
|
|
|
if (!m.first.isEmpty() && !m.second.isEmpty())
|
2021-09-28 12:38:08 +02:00
|
|
|
rc.insert(m.first.toString(), m.second.toString());
|
2011-03-04 16:21:57 +01:00
|
|
|
}
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check a mapping whether it still contains a placeholder.
|
|
|
|
|
bool SourcePathMappingModel::isNewPlaceHolder(const Mapping &m) const
|
|
|
|
|
{
|
2018-10-07 22:38:47 +03:00
|
|
|
const QChar lessThan('<');
|
|
|
|
|
const QChar greaterThan('>');
|
2011-03-11 13:19:20 +01:00
|
|
|
return m.first.isEmpty() || m.first.startsWith(lessThan)
|
|
|
|
|
|| m.first.endsWith(greaterThan)
|
2021-09-28 12:38:08 +02:00
|
|
|
|| m.first.toString() == m_newSourcePlaceHolder
|
2011-03-11 13:19:20 +01:00
|
|
|
|| m.second.isEmpty() || m.second.startsWith(lessThan)
|
|
|
|
|
|| m.second.endsWith(greaterThan)
|
2021-09-28 12:38:08 +02:00
|
|
|
|| m.second.toString() == m_newTargetPlaceHolder;
|
2011-03-04 16:21:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return raw, unfixed mapping
|
2011-03-11 13:19:20 +01:00
|
|
|
Mapping SourcePathMappingModel::rawMappingAt(int row) const
|
2011-03-04 16:21:57 +01:00
|
|
|
{
|
2021-09-28 12:38:08 +02:00
|
|
|
return Mapping(FilePath::fromUserInput(item(row, SourceColumn)->text()),
|
|
|
|
|
FilePath::fromUserInput(item(row, TargetColumn)->text()));
|
2011-03-04 16:21:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return mapping, empty if it is the place holder.
|
2011-03-11 13:19:20 +01:00
|
|
|
Mapping SourcePathMappingModel::mappingAt(int row) const
|
2011-03-04 16:21:57 +01:00
|
|
|
{
|
|
|
|
|
const Mapping raw = rawMappingAt(row);
|
2020-10-26 08:20:48 +02:00
|
|
|
return isNewPlaceHolder(raw) ? Mapping() : Mapping(raw.first, raw.second);
|
2011-03-04 16:21:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SourcePathMappingModel::setSourcePathMap(const SourcePathMap &m)
|
|
|
|
|
{
|
|
|
|
|
removeRows(0, rowCount());
|
|
|
|
|
const SourcePathMap::const_iterator cend = m.constEnd();
|
|
|
|
|
for (SourcePathMap::const_iterator it = m.constBegin(); it != cend; ++it)
|
|
|
|
|
addMapping(it.key(), it.value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SourcePathMappingModel::addRawMapping(const QString &source, const QString &target)
|
|
|
|
|
{
|
|
|
|
|
QList<QStandardItem *> items;
|
2018-07-23 22:28:49 +02:00
|
|
|
auto sourceItem = new QStandardItem(source);
|
2011-03-04 16:21:57 +01:00
|
|
|
sourceItem->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
|
2018-07-23 22:28:49 +02:00
|
|
|
auto targetItem = new QStandardItem(target);
|
2011-03-04 16:21:57 +01:00
|
|
|
targetItem->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
|
|
|
|
|
items << sourceItem << targetItem;
|
|
|
|
|
appendRow(items);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SourcePathMappingModel::setSource(int row, const QString &s)
|
|
|
|
|
{
|
|
|
|
|
QStandardItem *sourceItem = item(row, SourceColumn);
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(sourceItem, return);
|
2014-09-13 23:30:34 +03:00
|
|
|
sourceItem->setText(s.isEmpty() ? m_newSourcePlaceHolder : s);
|
2011-03-04 16:21:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SourcePathMappingModel::setTarget(int row, const QString &t)
|
|
|
|
|
{
|
|
|
|
|
QStandardItem *targetItem = item(row, TargetColumn);
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(targetItem, return);
|
2011-03-04 16:21:57 +01:00
|
|
|
targetItem->setText(t.isEmpty() ? m_newTargetPlaceHolder : QDir::toNativeSeparators(t));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2011-03-28 14:58:12 +02:00
|
|
|
\class Debugger::Internal::DebuggerSourcePathMappingWidget
|
2011-03-04 16:21:57 +01:00
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The DebuggerSourcePathMappingWidget class is a widget for maintaining
|
|
|
|
|
a set of source path mappings for the debugger.
|
2011-03-04 16:21:57 +01:00
|
|
|
|
2013-09-06 17:16:18 +02:00
|
|
|
Path mappings to be applied using source path substitution in GDB.
|
2011-03-04 16:21:57 +01:00
|
|
|
*/
|
|
|
|
|
|
2021-03-05 12:48:26 +01:00
|
|
|
DebuggerSourcePathMappingWidget::DebuggerSourcePathMappingWidget() :
|
2011-03-04 16:21:57 +01:00
|
|
|
m_model(new SourcePathMappingModel(this)),
|
2011-04-05 13:53:54 +02:00
|
|
|
m_treeView(new QTreeView(this)),
|
2022-07-05 15:37:08 +02:00
|
|
|
m_addButton(new QPushButton(Tr::tr("Add"), this)),
|
|
|
|
|
m_addQtButton(new QPushButton(Tr::tr("Add Qt sources..."), this)),
|
|
|
|
|
m_removeButton(new QPushButton(Tr::tr("Remove"), this)),
|
2011-04-05 13:53:54 +02:00
|
|
|
m_sourceLineEdit(new QLineEdit(this)),
|
2012-08-09 04:25:13 +02:00
|
|
|
m_targetChooser(new PathChooser(this))
|
2011-03-04 16:21:57 +01:00
|
|
|
{
|
2022-07-05 15:37:08 +02:00
|
|
|
setTitle(Tr::tr("Source Paths Mapping"));
|
|
|
|
|
setToolTip(Tr::tr("<p>Mappings of source file folders to "
|
2011-03-11 13:19:20 +01:00
|
|
|
"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 "
|
2014-09-07 23:24:10 +03:00
|
|
|
"doing remote debugging.</p>"
|
|
|
|
|
"<p>If source is specified as a regular expression by starting it with an "
|
2017-08-29 11:48:48 +02:00
|
|
|
"open parenthesis, the paths in the ELF are matched with the "
|
2014-09-07 23:24:10 +03:00
|
|
|
"regular expression to automatically determine the source path.</p>"
|
|
|
|
|
"<p>Example: <b>(/home/.*/Project)/KnownSubDir -> D:\\Project</b> will "
|
2015-07-02 13:42:22 +03:00
|
|
|
"substitute ELF built by any user to your local project directory.</p>"));
|
2011-03-04 16:21:57 +01:00
|
|
|
// 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);
|
2015-02-12 13:50:54 +01:00
|
|
|
connect(m_treeView->selectionModel(), &QItemSelectionModel::currentRowChanged,
|
|
|
|
|
this, &DebuggerSourcePathMappingWidget::slotCurrentRowChanged);
|
2011-03-04 16:21:57 +01:00
|
|
|
|
|
|
|
|
// Top list/Right part: Buttons.
|
2015-02-12 13:50:54 +01:00
|
|
|
auto buttonLayout = new QVBoxLayout;
|
2011-03-04 16:21:57 +01:00
|
|
|
buttonLayout->addWidget(m_addButton);
|
|
|
|
|
buttonLayout->addWidget(m_addQtButton);
|
2017-12-08 13:55:15 +01:00
|
|
|
m_addQtButton->setVisible(!qtBuildPaths().isEmpty());
|
2022-07-05 15:37:08 +02:00
|
|
|
m_addQtButton->setToolTip(Tr::tr("<p>Add a mapping for Qt's source folders "
|
2011-03-11 13:19:20 +01:00
|
|
|
"when using an unpatched version of Qt."));
|
2011-03-04 16:21:57 +01:00
|
|
|
buttonLayout->addWidget(m_removeButton);
|
2015-02-12 13:50:54 +01:00
|
|
|
connect(m_addButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &DebuggerSourcePathMappingWidget::slotAdd);
|
|
|
|
|
connect(m_addQtButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &DebuggerSourcePathMappingWidget::slotAddQt);
|
|
|
|
|
connect(m_removeButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &DebuggerSourcePathMappingWidget::slotRemove);
|
2011-03-04 16:21:57 +01:00
|
|
|
buttonLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
|
|
|
|
|
|
|
|
|
|
// Assemble top
|
2015-02-12 13:50:54 +01:00
|
|
|
auto treeHLayout = new QHBoxLayout;
|
2011-03-04 16:21:57 +01:00
|
|
|
treeHLayout->addWidget(m_treeView);
|
|
|
|
|
treeHLayout->addLayout(buttonLayout);
|
|
|
|
|
|
|
|
|
|
// Edit part
|
2012-08-09 04:25:13 +02:00
|
|
|
m_targetChooser->setExpectedKind(PathChooser::ExistingDirectory);
|
2018-10-07 22:38:47 +03:00
|
|
|
m_targetChooser->setHistoryCompleter("Debugger.MappingTarget.History");
|
2015-02-12 13:50:54 +01:00
|
|
|
connect(m_sourceLineEdit, &QLineEdit::textChanged,
|
|
|
|
|
this, &DebuggerSourcePathMappingWidget::slotEditSourceFieldChanged);
|
2022-09-02 11:49:36 +02:00
|
|
|
connect(m_targetChooser, &PathChooser::textChanged,
|
2015-02-12 13:50:54 +01:00
|
|
|
this, &DebuggerSourcePathMappingWidget::slotEditTargetFieldChanged);
|
|
|
|
|
auto editLayout = new QFormLayout;
|
2022-07-05 15:37:08 +02:00
|
|
|
const QString sourceToolTip = Tr::tr("<p>The source path contained in the "
|
2011-03-11 13:19:20 +01:00
|
|
|
"debug information of the executable as reported by the debugger");
|
2022-07-05 15:37:08 +02:00
|
|
|
auto editSourceLabel = new QLabel(Tr::tr("&Source path:"));
|
2011-03-04 16:21:57 +01:00
|
|
|
editSourceLabel->setToolTip(sourceToolTip);
|
|
|
|
|
m_sourceLineEdit->setToolTip(sourceToolTip);
|
|
|
|
|
editSourceLabel->setBuddy(m_sourceLineEdit);
|
|
|
|
|
editLayout->addRow(editSourceLabel, m_sourceLineEdit);
|
|
|
|
|
|
2022-07-05 15:37:08 +02:00
|
|
|
const QString targetToolTip = Tr::tr("<p>The actual location of the source "
|
2011-03-11 13:19:20 +01:00
|
|
|
"tree on the local machine");
|
2022-07-05 15:37:08 +02:00
|
|
|
auto editTargetLabel = new QLabel(Tr::tr("&Target path:"));
|
2011-03-04 16:21:57 +01:00
|
|
|
editTargetLabel->setToolTip(targetToolTip);
|
|
|
|
|
editTargetLabel->setBuddy(m_targetChooser);
|
|
|
|
|
m_targetChooser->setToolTip(targetToolTip);
|
|
|
|
|
editLayout->addRow(editTargetLabel, m_targetChooser);
|
2015-02-24 11:14:53 +01:00
|
|
|
editLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
2014-10-13 18:49:44 +02:00
|
|
|
|
2020-09-18 12:11:40 +02:00
|
|
|
auto chooser = new VariableChooser(this);
|
2014-10-13 18:49:44 +02:00
|
|
|
chooser->addSupportedWidget(m_targetChooser->lineEdit());
|
2011-03-04 16:21:57 +01:00
|
|
|
|
|
|
|
|
// Main layout
|
2015-02-12 13:50:54 +01:00
|
|
|
auto mainLayout = new QVBoxLayout;
|
2011-03-04 16:21:57 +01:00
|
|
|
mainLayout->addLayout(treeHLayout);
|
|
|
|
|
mainLayout->addLayout(editLayout);
|
|
|
|
|
setLayout(mainLayout);
|
|
|
|
|
updateEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DebuggerSourcePathMappingWidget::editSourceField() const
|
|
|
|
|
{
|
|
|
|
|
return QDir::cleanPath(m_sourceLineEdit->text().trimmed());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DebuggerSourcePathMappingWidget::editTargetField() const
|
|
|
|
|
{
|
2022-06-29 15:20:34 +02:00
|
|
|
return m_targetChooser->rawFilePath().toString();
|
2011-03-04 16:21:57 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-11 13:19:20 +01:00
|
|
|
void DebuggerSourcePathMappingWidget::setEditFieldMapping(const Mapping &m)
|
2011-03-04 16:21:57 +01:00
|
|
|
{
|
2021-09-28 12:38:08 +02:00
|
|
|
m_sourceLineEdit->setText(m.first.toUserOutput());
|
|
|
|
|
m_targetChooser->setFilePath(m.second);
|
2011-03-04 16:21:57 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-11 13:19:20 +01:00
|
|
|
void DebuggerSourcePathMappingWidget::slotCurrentRowChanged
|
|
|
|
|
(const QModelIndex ¤t, const QModelIndex &)
|
2011-03-04 16:21:57 +01:00
|
|
|
{
|
2021-09-28 12:38:08 +02:00
|
|
|
setEditFieldMapping(current.isValid() ? m_model->mappingAt(current.row()) : Mapping());
|
2011-03-04 16:21:57 +01:00
|
|
|
updateEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebuggerSourcePathMappingWidget::resizeColumns()
|
|
|
|
|
{
|
|
|
|
|
m_treeView->resizeColumnToContents(SourceColumn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebuggerSourcePathMappingWidget::updateEnabled()
|
|
|
|
|
{
|
|
|
|
|
// Allow for removing the current item.
|
|
|
|
|
const int row = currentRow();
|
|
|
|
|
const bool hasCurrent = row >= 0;
|
|
|
|
|
m_sourceLineEdit->setEnabled(hasCurrent);
|
|
|
|
|
m_targetChooser->setEnabled(hasCurrent);
|
|
|
|
|
m_removeButton->setEnabled(hasCurrent);
|
2011-03-11 13:19:20 +01:00
|
|
|
// Allow for adding only if the current item no longer is the place
|
|
|
|
|
// holder for new items.
|
2011-03-04 16:21:57 +01:00
|
|
|
const bool canAdd = !hasCurrent || !m_model->isNewPlaceHolderAt(row);
|
|
|
|
|
m_addButton->setEnabled(canAdd);
|
|
|
|
|
m_addQtButton->setEnabled(canAdd);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 13:19:20 +01:00
|
|
|
SourcePathMap DebuggerSourcePathMappingWidget::sourcePathMap() const
|
2011-03-04 16:21:57 +01:00
|
|
|
{
|
|
|
|
|
return m_model->sourcePathMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebuggerSourcePathMappingWidget::setSourcePathMap(const SourcePathMap &m)
|
|
|
|
|
{
|
|
|
|
|
m_model->setSourcePathMap(m);
|
|
|
|
|
if (!m.isEmpty())
|
|
|
|
|
resizeColumns();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int DebuggerSourcePathMappingWidget::currentRow() const
|
|
|
|
|
{
|
|
|
|
|
const QModelIndex index = m_treeView->selectionModel()->currentIndex();
|
|
|
|
|
return index.isValid() ? index.row() : -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebuggerSourcePathMappingWidget::setCurrentRow(int r)
|
|
|
|
|
{
|
|
|
|
|
m_treeView->selectionModel()->setCurrentIndex(m_model->index(r, 0),
|
|
|
|
|
QItemSelectionModel::ClearAndSelect
|
|
|
|
|
|QItemSelectionModel::Current
|
|
|
|
|
|QItemSelectionModel::Rows);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebuggerSourcePathMappingWidget::slotAdd()
|
|
|
|
|
{
|
|
|
|
|
m_model->addNewMappingPlaceHolder();
|
|
|
|
|
setCurrentRow(m_model->rowCount() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebuggerSourcePathMappingWidget::slotAddQt()
|
|
|
|
|
{
|
|
|
|
|
// Add a mapping for various Qt build locations in case of unpatched builds.
|
2022-07-05 15:37:08 +02:00
|
|
|
const FilePath qtSourcesPath = FileUtils::getExistingDirectory(this, Tr::tr("Qt Sources"));
|
2011-03-04 16:21:57 +01:00
|
|
|
if (qtSourcesPath.isEmpty())
|
|
|
|
|
return;
|
2017-12-08 13:55:15 +01:00
|
|
|
for (const QString &buildPath : qtBuildPaths())
|
2021-08-17 16:36:42 +02:00
|
|
|
m_model->addMapping(buildPath, qtSourcesPath.toString());
|
2011-03-04 16:21:57 +01:00
|
|
|
resizeColumns();
|
|
|
|
|
setCurrentRow(m_model->rowCount() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebuggerSourcePathMappingWidget::slotRemove()
|
|
|
|
|
{
|
|
|
|
|
const int row = currentRow();
|
|
|
|
|
if (row >= 0)
|
|
|
|
|
m_model->removeRow(row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebuggerSourcePathMappingWidget::slotEditSourceFieldChanged()
|
|
|
|
|
{
|
|
|
|
|
const int row = currentRow();
|
|
|
|
|
if (row >= 0) {
|
|
|
|
|
m_model->setSource(row, editSourceField());
|
|
|
|
|
updateEnabled();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebuggerSourcePathMappingWidget::slotEditTargetFieldChanged()
|
|
|
|
|
{
|
|
|
|
|
const int row = currentRow();
|
|
|
|
|
if (row >= 0) {
|
|
|
|
|
m_model->setTarget(row, editTargetField());
|
|
|
|
|
updateEnabled();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-05 12:48:26 +01:00
|
|
|
/* Merge settings for an installed Qt (unless another setting is already in the map. */
|
|
|
|
|
SourcePathMap mergePlatformQtPath(const DebuggerRunParameters &sp, const SourcePathMap &in)
|
2011-03-18 10:02:07 +01:00
|
|
|
{
|
2023-06-15 11:38:21 +02:00
|
|
|
static const QString qglobal = "qtbase/src/corelib/global/qglobal.h";
|
|
|
|
|
const FilePath sourceLocation = sp.qtSourceLocation;
|
|
|
|
|
if (!(sourceLocation / qglobal).exists())
|
2017-12-08 13:55:15 +01:00
|
|
|
return in;
|
2011-03-18 10:02:07 +01:00
|
|
|
|
2017-12-08 13:55:15 +01:00
|
|
|
SourcePathMap rc = in;
|
|
|
|
|
for (const QString &buildPath : qtBuildPaths()) {
|
2011-03-18 10:02:07 +01:00
|
|
|
if (!rc.contains(buildPath)) // Do not overwrite user settings.
|
2023-06-15 11:38:21 +02:00
|
|
|
rc.insert(buildPath, sourceLocation.path());
|
2011-03-18 10:02:07 +01:00
|
|
|
}
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-05 12:48:26 +01:00
|
|
|
//
|
|
|
|
|
// SourcePathMapAspect
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
class SourcePathMapAspectPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QPointer<DebuggerSourcePathMappingWidget> m_widget;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2023-07-21 12:37:43 +02:00
|
|
|
SourcePathMapAspect::SourcePathMapAspect(AspectContainer *container)
|
|
|
|
|
: TypedAspect(container), d(new SourcePathMapAspectPrivate)
|
2021-03-05 12:48:26 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourcePathMapAspect::~SourcePathMapAspect()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SourcePathMapAspect::fromMap(const QVariantMap &)
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(false); // This is only used via read/writeSettings
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SourcePathMapAspect::toMap(QVariantMap &) const
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(false);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-02 17:20:57 +02:00
|
|
|
void SourcePathMapAspect::addToLayout(Layouting::LayoutItem &parent)
|
2021-03-05 12:48:26 +01:00
|
|
|
{
|
|
|
|
|
QTC_CHECK(!d->m_widget);
|
|
|
|
|
d->m_widget = createSubWidget<DebuggerSourcePathMappingWidget>();
|
|
|
|
|
d->m_widget->setSourcePathMap(value());
|
2023-05-02 17:20:57 +02:00
|
|
|
parent.addItem(d->m_widget.data());
|
2021-03-05 12:48:26 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-20 14:25:13 +02:00
|
|
|
bool SourcePathMapAspect::guiToBuffer()
|
2021-03-05 12:48:26 +01:00
|
|
|
{
|
2023-07-20 14:25:13 +02:00
|
|
|
const SourcePathMap old = m_buffer;
|
2023-06-26 11:02:42 +02:00
|
|
|
if (d->m_widget)
|
2023-07-12 15:41:06 +02:00
|
|
|
m_buffer = d->m_widget->sourcePathMap();
|
2023-07-20 14:25:13 +02:00
|
|
|
return m_buffer != old;
|
2021-03-05 12:48:26 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-12 15:41:06 +02:00
|
|
|
void SourcePathMapAspect::bufferToGui()
|
2021-03-05 12:48:26 +01:00
|
|
|
{
|
|
|
|
|
if (d->m_widget)
|
2023-07-12 15:41:06 +02:00
|
|
|
d->m_widget->setSourcePathMap(m_buffer);
|
2021-03-05 12:48:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char sourcePathMappingArrayNameC[] = "SourcePathMappings";
|
|
|
|
|
const char sourcePathMappingSourceKeyC[] = "Source";
|
|
|
|
|
const char sourcePathMappingTargetKeyC[] = "Target";
|
|
|
|
|
|
2023-07-06 09:57:16 +02:00
|
|
|
void SourcePathMapAspect::writeSettings() const
|
2021-03-05 12:48:26 +01:00
|
|
|
{
|
|
|
|
|
const SourcePathMap sourcePathMap = value();
|
2023-07-21 18:58:18 +02:00
|
|
|
QSettings *s = qtcSettings();
|
2021-03-05 12:48:26 +01:00
|
|
|
s->beginWriteArray(sourcePathMappingArrayNameC);
|
|
|
|
|
if (!sourcePathMap.isEmpty()) {
|
|
|
|
|
const QString sourcePathMappingSourceKey(sourcePathMappingSourceKeyC);
|
|
|
|
|
const QString sourcePathMappingTargetKey(sourcePathMappingTargetKeyC);
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (auto it = sourcePathMap.constBegin(), cend = sourcePathMap.constEnd();
|
|
|
|
|
it != cend;
|
|
|
|
|
++it, ++i) {
|
|
|
|
|
s->setArrayIndex(i);
|
|
|
|
|
s->setValue(sourcePathMappingSourceKey, it.key());
|
|
|
|
|
s->setValue(sourcePathMappingTargetKey, it.value());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
s->endArray();
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-06 09:57:16 +02:00
|
|
|
void SourcePathMapAspect::readSettings()
|
2021-03-05 12:48:26 +01:00
|
|
|
{
|
2023-07-21 18:58:18 +02:00
|
|
|
QSettings *s = qtcSettings();
|
2021-03-05 12:48:26 +01:00
|
|
|
SourcePathMap sourcePathMap;
|
|
|
|
|
if (const int count = s->beginReadArray(sourcePathMappingArrayNameC)) {
|
|
|
|
|
const QString sourcePathMappingSourceKey(sourcePathMappingSourceKeyC);
|
|
|
|
|
const QString sourcePathMappingTargetKey(sourcePathMappingTargetKeyC);
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
|
s->setArrayIndex(i);
|
|
|
|
|
const QString key = s->value(sourcePathMappingSourceKey).toString();
|
|
|
|
|
const QString value = s->value(sourcePathMappingTargetKey).toString();
|
|
|
|
|
sourcePathMap.insert(key, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
s->endArray();
|
2023-06-26 11:02:42 +02:00
|
|
|
setValue(sourcePathMap);
|
2021-03-05 12:48:26 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 15:37:08 +02:00
|
|
|
} // Debugger::Internal
|