Debugger: Move StartApplicationDialog implementation to .cpp

Change-Id: I70422f55f0189da0ee5a369b31688a87bd4b595e
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2024-11-18 13:46:27 +01:00
parent b62bd26bd9
commit 10685ae911
3 changed files with 166 additions and 185 deletions

View File

@@ -44,38 +44,6 @@ using namespace Utils;
namespace Debugger::Internal {
///////////////////////////////////////////////////////////////////////
//
// StartApplicationDialogPrivate
//
///////////////////////////////////////////////////////////////////////
class StartApplicationDialogPrivate
{
public:
KitChooser *kitChooser;
QLabel *serverPortLabel;
QLabel *channelOverrideHintLabel;
QLabel *channelOverrideLabel;
QLineEdit *channelOverrideEdit;
QSpinBox *serverPortSpinBox;
PathChooser *localExecutablePathChooser;
FancyLineEdit *arguments;
PathChooser *workingDirectory;
QCheckBox *breakAtMainCheckBox;
QCheckBox *runInTerminalCheckBox;
QCheckBox *useTargetExtendedRemoteCheckBox;
PathChooser *debuginfoPathChooser;
QLabel *sysRootLabel;
PathChooser *sysRootPathChooser;
QLabel *serverInitCommandsLabel;
QPlainTextEdit *serverInitCommandsTextEdit;
QLabel *serverResetCommandsLabel;
QPlainTextEdit *serverResetCommandsTextEdit;
QComboBox *historyComboBox;
QDialogButtonBox *buttonBox;
};
///////////////////////////////////////////////////////////////////////
//
// StartApplicationParameters
@@ -181,166 +149,198 @@ void StartApplicationParameters::fromSettings(const QtcSettings *settings)
//
///////////////////////////////////////////////////////////////////////
StartApplicationDialog::StartApplicationDialog(QWidget *parent)
: QDialog(parent), d(new StartApplicationDialogPrivate)
class StartApplicationDialog final : public QDialog
{
public:
StartApplicationDialog();
static void run(bool);
private:
void historyIndexChanged(int);
void updateState();
StartApplicationParameters parameters() const;
void setParameters(const StartApplicationParameters &p);
void setHistory(const QList<StartApplicationParameters> &l);
void onChannelOverrideChanged(const QString &channel);
KitChooser *kitChooser;
QLabel *serverPortLabel;
QLabel *channelOverrideHintLabel;
QLabel *channelOverrideLabel;
QLineEdit *channelOverrideEdit;
QSpinBox *serverPortSpinBox;
PathChooser *localExecutablePathChooser;
FancyLineEdit *arguments;
PathChooser *workingDirectory;
QCheckBox *breakAtMainCheckBox;
QCheckBox *runInTerminalCheckBox;
QCheckBox *useTargetExtendedRemoteCheckBox;
PathChooser *debuginfoPathChooser;
QLabel *sysRootLabel;
PathChooser *sysRootPathChooser;
QLabel *serverInitCommandsLabel;
QPlainTextEdit *serverInitCommandsTextEdit;
QLabel *serverResetCommandsLabel;
QPlainTextEdit *serverResetCommandsTextEdit;
QComboBox *historyComboBox;
QDialogButtonBox *buttonBox;
};
StartApplicationDialog::StartApplicationDialog()
: QDialog(ICore::dialogParent())
{
setWindowTitle(Tr::tr("Start Debugger"));
d->kitChooser = new KitChooser(this);
d->kitChooser->setShowIcons(true);
d->kitChooser->populate();
kitChooser = new KitChooser(this);
kitChooser->setShowIcons(true);
kitChooser->populate();
d->serverPortLabel = new QLabel(Tr::tr("Server port:"), this);
d->serverPortSpinBox = new QSpinBox(this);
d->serverPortSpinBox->setRange(1, 65535);
serverPortLabel = new QLabel(Tr::tr("Server port:"), this);
serverPortSpinBox = new QSpinBox(this);
serverPortSpinBox->setRange(1, 65535);
d->channelOverrideHintLabel =
channelOverrideHintLabel =
new QLabel(Tr::tr("Normally, the running server is identified by the IP of the "
"device in the kit and the server port selected above.\n"
"You can choose another communication channel here, such as "
"a serial line or custom ip:port."));
d->channelOverrideLabel = new QLabel(Tr::tr("Override server channel:"), this);
d->channelOverrideEdit = new QLineEdit(this);
channelOverrideLabel = new QLabel(Tr::tr("Override server channel:"), this);
channelOverrideEdit = new QLineEdit(this);
//: "For example, /dev/ttyS0, COM1, 127.0.0.1:1234"
d->channelOverrideEdit->setPlaceholderText(
channelOverrideEdit->setPlaceholderText(
Tr::tr("For example, %1").arg("/dev/ttyS0, COM1, 127.0.0.1:1234"));
d->localExecutablePathChooser = new PathChooser(this);
d->localExecutablePathChooser->setExpectedKind(PathChooser::File);
d->localExecutablePathChooser->setPromptDialogTitle(Tr::tr("Select Executable"));
d->localExecutablePathChooser->setHistoryCompleter("LocalExecutable");
localExecutablePathChooser = new PathChooser(this);
localExecutablePathChooser->setExpectedKind(PathChooser::File);
localExecutablePathChooser->setPromptDialogTitle(Tr::tr("Select Executable"));
localExecutablePathChooser->setHistoryCompleter("LocalExecutable");
d->arguments = new FancyLineEdit(this);
d->arguments->setClearButtonEnabled(true);
d->arguments->setHistoryCompleter("CommandlineArguments");
arguments = new FancyLineEdit(this);
arguments->setClearButtonEnabled(true);
arguments->setHistoryCompleter("CommandlineArguments");
d->workingDirectory = new PathChooser(this);
d->workingDirectory->setExpectedKind(PathChooser::ExistingDirectory);
d->workingDirectory->setPromptDialogTitle(Tr::tr("Select Working Directory"));
d->workingDirectory->setHistoryCompleter("WorkingDirectory");
workingDirectory = new PathChooser(this);
workingDirectory->setExpectedKind(PathChooser::ExistingDirectory);
workingDirectory->setPromptDialogTitle(Tr::tr("Select Working Directory"));
workingDirectory->setHistoryCompleter("WorkingDirectory");
d->runInTerminalCheckBox = new QCheckBox(this);
runInTerminalCheckBox = new QCheckBox(this);
d->breakAtMainCheckBox = new QCheckBox(this);
d->breakAtMainCheckBox->setText(QString());
breakAtMainCheckBox = new QCheckBox(this);
breakAtMainCheckBox->setText(QString());
d->useTargetExtendedRemoteCheckBox = new QCheckBox(this);
useTargetExtendedRemoteCheckBox = new QCheckBox(this);
d->sysRootPathChooser = new PathChooser(this);
d->sysRootPathChooser->setExpectedKind(PathChooser::Directory);
d->sysRootPathChooser->setHistoryCompleter("Debugger.SysRoot.History");
d->sysRootPathChooser->setPromptDialogTitle(Tr::tr("Select SysRoot Directory"));
d->sysRootPathChooser->setToolTip(Tr::tr(
sysRootPathChooser = new PathChooser(this);
sysRootPathChooser->setExpectedKind(PathChooser::Directory);
sysRootPathChooser->setHistoryCompleter("Debugger.SysRoot.History");
sysRootPathChooser->setPromptDialogTitle(Tr::tr("Select SysRoot Directory"));
sysRootPathChooser->setToolTip(Tr::tr(
"This option can be used to override the kit's SysRoot setting."));
d->sysRootLabel = new QLabel(Tr::tr("Override S&ysRoot:"), this);
d->sysRootLabel->setBuddy(d->sysRootPathChooser);
d->sysRootLabel->setToolTip(d->sysRootPathChooser->toolTip());
sysRootLabel = new QLabel(Tr::tr("Override S&ysRoot:"), this);
sysRootLabel->setBuddy(sysRootPathChooser);
sysRootLabel->setToolTip(sysRootPathChooser->toolTip());
d->serverInitCommandsTextEdit = new QPlainTextEdit(this);
d->serverInitCommandsTextEdit->setToolTip(Tr::tr(
serverInitCommandsTextEdit = new QPlainTextEdit(this);
serverInitCommandsTextEdit->setToolTip(Tr::tr(
"This option can be used to send the target init commands."));
d->serverInitCommandsLabel = new QLabel(Tr::tr("&Init commands:"), this);
d->serverInitCommandsLabel->setBuddy(d->serverInitCommandsTextEdit);
d->serverInitCommandsLabel->setToolTip(d->serverInitCommandsTextEdit->toolTip());
serverInitCommandsLabel = new QLabel(Tr::tr("&Init commands:"), this);
serverInitCommandsLabel->setBuddy(serverInitCommandsTextEdit);
serverInitCommandsLabel->setToolTip(serverInitCommandsTextEdit->toolTip());
d->serverResetCommandsTextEdit = new QPlainTextEdit(this);
d->serverResetCommandsTextEdit->setToolTip(Tr::tr(
serverResetCommandsTextEdit = new QPlainTextEdit(this);
serverResetCommandsTextEdit->setToolTip(Tr::tr(
"This option can be used to send the target reset commands."));
d->serverResetCommandsLabel = new QLabel(Tr::tr("&Reset commands:"), this);
d->serverResetCommandsLabel->setBuddy(d->serverResetCommandsTextEdit);
d->serverResetCommandsLabel->setToolTip(d->serverResetCommandsTextEdit->toolTip());
serverResetCommandsLabel = new QLabel(Tr::tr("&Reset commands:"), this);
serverResetCommandsLabel->setBuddy(serverResetCommandsTextEdit);
serverResetCommandsLabel->setToolTip(serverResetCommandsTextEdit->toolTip());
d->debuginfoPathChooser = new PathChooser(this);
d->debuginfoPathChooser->setPromptDialogTitle(Tr::tr("Select Location of Debugging Information"));
d->debuginfoPathChooser->setToolTip(Tr::tr(
debuginfoPathChooser = new PathChooser(this);
debuginfoPathChooser->setPromptDialogTitle(Tr::tr("Select Location of Debugging Information"));
debuginfoPathChooser->setToolTip(Tr::tr(
"Base path for external debug information and debug sources. "
"If empty, $SYSROOT/usr/lib/debug will be chosen."));
d->debuginfoPathChooser->setHistoryCompleter("Debugger.DebugLocation.History");
debuginfoPathChooser->setHistoryCompleter("Debugger.DebugLocation.History");
d->historyComboBox = new QComboBox(this);
historyComboBox = new QComboBox(this);
d->buttonBox = new QDialogButtonBox(this);
d->buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
d->buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
buttonBox = new QDialogButtonBox(this);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
auto formLayout = new QFormLayout();
formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
formLayout->addRow(Tr::tr("&Kit:"), d->kitChooser);
formLayout->addRow(d->serverPortLabel, d->serverPortSpinBox);
formLayout->addRow(Tr::tr("Local &executable:"), d->localExecutablePathChooser);
formLayout->addRow(Tr::tr("Command line &arguments:"), d->arguments);
formLayout->addRow(Tr::tr("&Working directory:"), d->workingDirectory);
formLayout->addRow(Tr::tr("Run in &terminal:"), d->runInTerminalCheckBox);
formLayout->addRow(Tr::tr("Break at \"&main\":"), d->breakAtMainCheckBox);
formLayout->addRow(Tr::tr("Use target extended-remote to connect:"), d->useTargetExtendedRemoteCheckBox);
formLayout->addRow(d->sysRootLabel, d->sysRootPathChooser);
formLayout->addRow(d->serverInitCommandsLabel, d->serverInitCommandsTextEdit);
formLayout->addRow(d->serverResetCommandsLabel, d->serverResetCommandsTextEdit);
formLayout->addRow(Tr::tr("Debug &information:"), d->debuginfoPathChooser);
formLayout->addRow(d->channelOverrideHintLabel);
formLayout->addRow(d->channelOverrideLabel, d->channelOverrideEdit);
formLayout->addRow(Tr::tr("&Kit:"), kitChooser);
formLayout->addRow(serverPortLabel, serverPortSpinBox);
formLayout->addRow(Tr::tr("Local &executable:"), localExecutablePathChooser);
formLayout->addRow(Tr::tr("Command line &arguments:"), arguments);
formLayout->addRow(Tr::tr("&Working directory:"), workingDirectory);
formLayout->addRow(Tr::tr("Run in &terminal:"), runInTerminalCheckBox);
formLayout->addRow(Tr::tr("Break at \"&main\":"), breakAtMainCheckBox);
formLayout->addRow(Tr::tr("Use target extended-remote to connect:"), useTargetExtendedRemoteCheckBox);
formLayout->addRow(sysRootLabel, sysRootPathChooser);
formLayout->addRow(serverInitCommandsLabel, serverInitCommandsTextEdit);
formLayout->addRow(serverResetCommandsLabel, serverResetCommandsTextEdit);
formLayout->addRow(Tr::tr("Debug &information:"), debuginfoPathChooser);
formLayout->addRow(channelOverrideHintLabel);
formLayout->addRow(channelOverrideLabel, channelOverrideEdit);
formLayout->addRow(Layouting::createHr());
formLayout->addRow(Tr::tr("&Recent:"), d->historyComboBox);
formLayout->addRow(Tr::tr("&Recent:"), historyComboBox);
auto verticalLayout = new QVBoxLayout(this);
verticalLayout->addLayout(formLayout);
verticalLayout->addStretch();
verticalLayout->addWidget(Layouting::createHr());
verticalLayout->addWidget(d->buttonBox);
verticalLayout->addWidget(buttonBox);
connect(d->localExecutablePathChooser,
&PathChooser::validChanged,
this,
&StartApplicationDialog::updateState);
connect(localExecutablePathChooser, &PathChooser::validChanged,
this, &StartApplicationDialog::updateState);
connect(d->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(d->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(d->historyComboBox, &QComboBox::currentIndexChanged,
connect(historyComboBox, &QComboBox::currentIndexChanged,
this, &StartApplicationDialog::historyIndexChanged);
connect(d->channelOverrideEdit, &QLineEdit::textChanged,
connect(channelOverrideEdit, &QLineEdit::textChanged,
this, &StartApplicationDialog::onChannelOverrideChanged);
updateState();
}
StartApplicationDialog::~StartApplicationDialog()
{
delete d;
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
void StartApplicationDialog::setHistory(const QList<StartApplicationParameters> &l)
{
d->historyComboBox->clear();
historyComboBox->clear();
for (int i = l.size(); --i >= 0; ) {
const StartApplicationParameters &p = l.at(i);
if (!p.runnable.command.isEmpty())
d->historyComboBox->addItem(p.displayName(), QVariant::fromValue(p));
historyComboBox->addItem(p.displayName(), QVariant::fromValue(p));
}
}
void StartApplicationDialog::onChannelOverrideChanged(const QString &channel)
{
d->serverPortSpinBox->setEnabled(channel.isEmpty());
d->serverPortLabel->setEnabled(channel.isEmpty());
serverPortSpinBox->setEnabled(channel.isEmpty());
serverPortLabel->setEnabled(channel.isEmpty());
}
void StartApplicationDialog::historyIndexChanged(int index)
{
if (index < 0)
return;
const QVariant v = d->historyComboBox->itemData(index);
const QVariant v = historyComboBox->itemData(index);
QTC_ASSERT(v.canConvert<StartApplicationParameters>(), return);
setParameters(v.value<StartApplicationParameters>());
}
void StartApplicationDialog::updateState()
{
bool okEnabled = d->localExecutablePathChooser->isValid();
d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(okEnabled);
bool okEnabled = localExecutablePathChooser->isValid();
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(okEnabled);
}
void StartApplicationDialog::run(bool attachRemote)
@@ -364,24 +364,24 @@ void StartApplicationDialog::run(bool attachRemote)
settings->endArray();
settings->endGroup();
StartApplicationDialog dialog(ICore::dialogParent());
StartApplicationDialog dialog;
dialog.setHistory(history);
dialog.setParameters(history.back());
if (!attachRemote) {
dialog.d->serverInitCommandsTextEdit->setVisible(false);
dialog.d->serverInitCommandsLabel->setVisible(false);
dialog.d->serverResetCommandsTextEdit->setVisible(false);
dialog.d->serverResetCommandsLabel->setVisible(false);
dialog.d->serverPortSpinBox->setVisible(false);
dialog.d->serverPortLabel->setVisible(false);
dialog.d->channelOverrideHintLabel->setVisible(false);
dialog.d->channelOverrideLabel->setVisible(false);
dialog.d->channelOverrideEdit->setVisible(false);
dialog.serverInitCommandsTextEdit->setVisible(false);
dialog.serverInitCommandsLabel->setVisible(false);
dialog.serverResetCommandsTextEdit->setVisible(false);
dialog.serverResetCommandsLabel->setVisible(false);
dialog.serverPortSpinBox->setVisible(false);
dialog.serverPortLabel->setVisible(false);
dialog.channelOverrideHintLabel->setVisible(false);
dialog.channelOverrideLabel->setVisible(false);
dialog.channelOverrideEdit->setVisible(false);
}
if (dialog.exec() != QDialog::Accepted)
return;
Kit *k = dialog.d->kitChooser->currentKit();
Kit *k = dialog.kitChooser->currentKit();
auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
runControl->setKit(k);
@@ -409,7 +409,7 @@ void StartApplicationDialog::run(bool attachRemote)
return;
}
ProcessRunData inferior = newParameters.runnable;
const QString inputAddress = dialog.d->channelOverrideEdit->text();
const QString inputAddress = dialog.channelOverrideEdit->text();
if (!inputAddress.isEmpty())
debugger->setRemoteChannel(inputAddress);
else
@@ -441,50 +441,50 @@ void StartApplicationDialog::run(bool attachRemote)
debugger->startRunControl();
}
void StartApplicationDialog::attachToRemoteServer()
void runAttachToRemoteServerDialog()
{
run(true);
StartApplicationDialog::run(true);
}
void StartApplicationDialog::startAndDebugApplication()
void runStartAndDebugApplicationDialog()
{
run(false);
StartApplicationDialog::run(false);
}
StartApplicationParameters StartApplicationDialog::parameters() const
{
StartApplicationParameters result;
result.serverPort = d->serverPortSpinBox->value();
result.serverAddress = d->channelOverrideEdit->text();
result.runnable.command.setExecutable(d->localExecutablePathChooser->filePath());
result.sysRoot = d->sysRootPathChooser->filePath();
result.serverInitCommands = d->serverInitCommandsTextEdit->toPlainText();
result.serverResetCommands = d->serverResetCommandsTextEdit->toPlainText();
result.kitId = d->kitChooser->currentKitId();
result.debugInfoLocation = d->debuginfoPathChooser->filePath();
result.runnable.command.setArguments(d->arguments->text());
result.runnable.workingDirectory = d->workingDirectory->filePath();
result.breakAtMain = d->breakAtMainCheckBox->isChecked();
result.runInTerminal = d->runInTerminalCheckBox->isChecked();
result.useTargetExtendedRemote = d->useTargetExtendedRemoteCheckBox->isChecked();
result.serverPort = serverPortSpinBox->value();
result.serverAddress = channelOverrideEdit->text();
result.runnable.command.setExecutable(localExecutablePathChooser->filePath());
result.sysRoot = sysRootPathChooser->filePath();
result.serverInitCommands = serverInitCommandsTextEdit->toPlainText();
result.serverResetCommands = serverResetCommandsTextEdit->toPlainText();
result.kitId = kitChooser->currentKitId();
result.debugInfoLocation = debuginfoPathChooser->filePath();
result.runnable.command.setArguments(arguments->text());
result.runnable.workingDirectory = workingDirectory->filePath();
result.breakAtMain = breakAtMainCheckBox->isChecked();
result.runInTerminal = runInTerminalCheckBox->isChecked();
result.useTargetExtendedRemote = useTargetExtendedRemoteCheckBox->isChecked();
return result;
}
void StartApplicationDialog::setParameters(const StartApplicationParameters &p)
{
d->kitChooser->setCurrentKitId(p.kitId);
d->serverPortSpinBox->setValue(p.serverPort);
d->channelOverrideEdit->setText(p.serverAddress);
d->localExecutablePathChooser->setFilePath(p.runnable.command.executable());
d->sysRootPathChooser->setFilePath(p.sysRoot);
d->serverInitCommandsTextEdit->setPlainText(p.serverInitCommands);
d->serverResetCommandsTextEdit->setPlainText(p.serverResetCommands);
d->debuginfoPathChooser->setFilePath(p.debugInfoLocation);
d->arguments->setText(p.runnable.command.arguments());
d->workingDirectory->setFilePath(p.runnable.workingDirectory);
d->breakAtMainCheckBox->setChecked(p.breakAtMain);
d->runInTerminalCheckBox->setChecked(p.runInTerminal);
d->useTargetExtendedRemoteCheckBox->setChecked(p.useTargetExtendedRemote);
kitChooser->setCurrentKitId(p.kitId);
serverPortSpinBox->setValue(p.serverPort);
channelOverrideEdit->setText(p.serverAddress);
localExecutablePathChooser->setFilePath(p.runnable.command.executable());
sysRootPathChooser->setFilePath(p.sysRoot);
serverInitCommandsTextEdit->setPlainText(p.serverInitCommands);
serverResetCommandsTextEdit->setPlainText(p.serverResetCommands);
debuginfoPathChooser->setFilePath(p.debugInfoLocation);
arguments->setText(p.runnable.command.arguments());
workingDirectory->setFilePath(p.runnable.workingDirectory);
breakAtMainCheckBox->setChecked(p.breakAtMain);
runInTerminalCheckBox->setChecked(p.runInTerminal);
useTargetExtendedRemoteCheckBox->setChecked(p.useTargetExtendedRemote);
updateState();
}

View File

@@ -21,29 +21,10 @@ namespace Debugger::Internal {
class AttachToQmlPortDialogPrivate;
class DebuggerRunParameters;
class StartApplicationParameters;
class StartApplicationDialogPrivate;
class StartRemoteEngineDialogPrivate;
class StartApplicationDialog : public QDialog
{
public:
explicit StartApplicationDialog(QWidget *parent);
~StartApplicationDialog() override;
static void attachToRemoteServer();
static void startAndDebugApplication();
private:
void historyIndexChanged(int);
void updateState();
StartApplicationParameters parameters() const;
void setParameters(const StartApplicationParameters &p);
void setHistory(const QList<StartApplicationParameters> &l);
void onChannelOverrideChanged(const QString &channel);
static void run(bool);
StartApplicationDialogPrivate *d;
};
void runAttachToRemoteServerDialog();
void runStartAndDebugApplicationDialog();
class AttachToQmlPortDialog : public QDialog
{

View File

@@ -872,7 +872,7 @@ DebuggerPluginPrivate::DebuggerPluginPrivate(const QStringList &arguments)
});
connect(&m_startAndDebugApplicationAction, &QAction::triggered,
this, &StartApplicationDialog::startAndDebugApplication);
this, [] { runStartAndDebugApplicationDialog(); });
connect(&m_attachToCoreAction, &QAction::triggered,
this, &DebuggerPluginPrivate::attachCore);
@@ -881,7 +881,7 @@ DebuggerPluginPrivate::DebuggerPluginPrivate(const QStringList &arguments)
this, &DebuggerPluginPrivate::attachToLastCore);
connect(&m_attachToRemoteServerAction, &QAction::triggered,
this, &StartApplicationDialog::attachToRemoteServer);
this, [] { runAttachToRemoteServerDialog(); });
connect(&m_attachToRunningApplication, &QAction::triggered,
this, &DebuggerPluginPrivate::attachToRunningApplication);