From 74e260a40d4d950ebb6e657505f111f0257b8fcc Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 4 Oct 2022 11:57:36 +0200 Subject: [PATCH] Mercurial: Inline srcdestdialog.ui Change-Id: I6866ffbe708600e47dd136e627a6c59207b50815 Reviewed-by: Alessandro Portale --- src/plugins/mercurial/CMakeLists.txt | 2 +- src/plugins/mercurial/mercurial.qbs | 3 +- src/plugins/mercurial/srcdestdialog.cpp | 87 ++++++++---- src/plugins/mercurial/srcdestdialog.h | 23 +++- src/plugins/mercurial/srcdestdialog.ui | 170 ------------------------ 5 files changed, 79 insertions(+), 206 deletions(-) delete mode 100644 src/plugins/mercurial/srcdestdialog.ui diff --git a/src/plugins/mercurial/CMakeLists.txt b/src/plugins/mercurial/CMakeLists.txt index e5326a816f0..37cccb62544 100644 --- a/src/plugins/mercurial/CMakeLists.txt +++ b/src/plugins/mercurial/CMakeLists.txt @@ -11,5 +11,5 @@ add_qtc_plugin(Mercurial mercurialplugin.cpp mercurialplugin.h mercurialsettings.cpp mercurialsettings.h revertdialog.cpp revertdialog.h - srcdestdialog.cpp srcdestdialog.h srcdestdialog.ui + srcdestdialog.cpp srcdestdialog.h ) diff --git a/src/plugins/mercurial/mercurial.qbs b/src/plugins/mercurial/mercurial.qbs index 4c56a350969..58fb641cb4d 100644 --- a/src/plugins/mercurial/mercurial.qbs +++ b/src/plugins/mercurial/mercurial.qbs @@ -32,7 +32,6 @@ QtcPlugin { "revertdialog.cpp", "revertdialog.h", "srcdestdialog.cpp", - "srcdestdialog.h", - "srcdestdialog.ui", + "srcdestdialog.h" ] } diff --git a/src/plugins/mercurial/srcdestdialog.cpp b/src/plugins/mercurial/srcdestdialog.cpp index a2b0c5a6052..792eb41cc4d 100644 --- a/src/plugins/mercurial/srcdestdialog.cpp +++ b/src/plugins/mercurial/srcdestdialog.cpp @@ -3,49 +3,85 @@ #include "authenticationdialog.h" #include "srcdestdialog.h" -#include "ui_srcdestdialog.h" +#include + +#include +#include +#include +#include #include #include +using namespace Utils; using namespace VcsBase; -namespace Mercurial { -namespace Internal { +namespace Mercurial::Internal { SrcDestDialog::SrcDestDialog(const VcsBasePluginState &state, Direction dir, QWidget *parent) : QDialog(parent), - m_ui(new Ui::SrcDestDialog), m_direction(dir), m_state(state) { - m_ui->setupUi(this); - m_ui->localPathChooser->setExpectedKind(Utils::PathChooser::ExistingDirectory); - m_ui->localPathChooser->setHistoryCompleter(QLatin1String("Hg.SourceDir.History")); - QUrl repoUrl(getRepoUrl()); - if (repoUrl.isEmpty()) - return; + resize(400, 187); + + m_defaultButton = new QRadioButton(tr("Default Location")); + m_defaultButton->setChecked(true); + + m_localButton = new QRadioButton(tr("Local filesystem:")); + + auto urlButton = new QRadioButton(tr("Specify URL:")); + urlButton->setToolTip(tr("For example: 'https://[user[:pass]@]host[:port]/[path]'.")); + + m_localPathChooser = new Utils::PathChooser; + m_localPathChooser->setEnabled(false); + m_localPathChooser->setExpectedKind(PathChooser::ExistingDirectory); + m_localPathChooser->setHistoryCompleter("Hg.SourceDir.History"); + + m_urlLineEdit = new QLineEdit; + m_urlLineEdit->setToolTip(tr("For example: 'https://[user[:pass]@]host[:port]/[path]'.", nullptr)); + m_urlLineEdit->setEnabled(false); + + QUrl repoUrl = getRepoUrl(); if (!repoUrl.password().isEmpty()) repoUrl.setPassword(QLatin1String("***")); - m_ui->defaultPath->setText(repoUrl.toString()); - m_ui->promptForCredentials->setChecked(!repoUrl.scheme().isEmpty() && repoUrl.scheme() != QLatin1String("file")); + + m_promptForCredentials = new QCheckBox(tr("Prompt for credentials")); + m_promptForCredentials->setChecked(!repoUrl.scheme().isEmpty() && repoUrl.scheme() != QLatin1String("file")); + + auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + + using namespace Layouting; + + Column { + Form { + m_defaultButton, Column { repoUrl.toString(), m_promptForCredentials }, br, + m_localButton, m_localPathChooser, br, + urlButton, m_urlLineEdit, br, + }, + st, + buttonBox + }.attachTo(this); + + connect(urlButton, &QRadioButton::toggled, m_urlLineEdit, &QLineEdit::setEnabled); + connect(m_localButton, &QAbstractButton::toggled, m_localPathChooser, &QWidget::setEnabled); + + connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); } -SrcDestDialog::~SrcDestDialog() -{ - delete m_ui; -} +SrcDestDialog::~SrcDestDialog() = default; void SrcDestDialog::setPathChooserKind(Utils::PathChooser::Kind kind) { - m_ui->localPathChooser->setExpectedKind(kind); + m_localPathChooser->setExpectedKind(kind); } QString SrcDestDialog::getRepositoryString() const { - if (m_ui->defaultButton->isChecked()) { + if (m_defaultButton->isChecked()) { QUrl repoUrl(getRepoUrl()); - if (m_ui->promptForCredentials->isChecked() && !repoUrl.scheme().isEmpty() && repoUrl.scheme() != QLatin1String("file")) { + if (m_promptForCredentials->isChecked() && !repoUrl.scheme().isEmpty() && repoUrl.scheme() != QLatin1String("file")) { QScopedPointer authDialog(new AuthenticationDialog(repoUrl.userName(), repoUrl.password())); authDialog->setPasswordEnabled(repoUrl.scheme() != QLatin1String("ssh")); if (authDialog->exec()== 0) @@ -63,14 +99,14 @@ QString SrcDestDialog::getRepositoryString() const } return repoUrl.toString(); } - if (m_ui->localButton->isChecked()) - return m_ui->localPathChooser->filePath().toString(); - return m_ui->urlLineEdit->text(); + if (m_localButton->isChecked()) + return m_localPathChooser->filePath().toString(); + return m_urlLineEdit->text(); } -Utils::FilePath SrcDestDialog::workingDir() const +FilePath SrcDestDialog::workingDir() const { - return Utils::FilePath::fromString(m_workingdir); + return FilePath::fromString(m_workingdir); } QUrl SrcDestDialog::getRepoUrl() const @@ -92,5 +128,4 @@ QUrl SrcDestDialog::getRepoUrl() const return url; } -} // namespace Internal -} // namespace Mercurial +} // Mercurial::Internal diff --git a/src/plugins/mercurial/srcdestdialog.h b/src/plugins/mercurial/srcdestdialog.h index 8afcaccef11..b448af2ba81 100644 --- a/src/plugins/mercurial/srcdestdialog.h +++ b/src/plugins/mercurial/srcdestdialog.h @@ -4,13 +4,18 @@ #pragma once #include + #include + #include -namespace Mercurial { -namespace Internal { +QT_BEGIN_NAMESPACE +class QCheckBox; +class QLineEdit; +class QRadioButton; +QT_END_NAMESPACE -namespace Ui { class SrcDestDialog; } +namespace Mercurial::Internal { class SrcDestDialog : public QDialog { @@ -18,6 +23,7 @@ class SrcDestDialog : public QDialog public: enum Direction { outgoing, incoming }; + explicit SrcDestDialog(const VcsBase::VcsBasePluginState &state, Direction dir, QWidget *parent = nullptr); ~SrcDestDialog() override; @@ -28,12 +34,15 @@ public: private: QUrl getRepoUrl() const; -private: - Ui::SrcDestDialog *m_ui; Direction m_direction; mutable QString m_workingdir; VcsBase::VcsBasePluginState m_state; + + QRadioButton *m_defaultButton; + QRadioButton *m_localButton; + Utils::PathChooser *m_localPathChooser; + QLineEdit *m_urlLineEdit; + QCheckBox *m_promptForCredentials; }; -} // namespace Internal -} // namespace Mercurial +} // Mercurial::Internal diff --git a/src/plugins/mercurial/srcdestdialog.ui b/src/plugins/mercurial/srcdestdialog.ui deleted file mode 100644 index b560d4857dc..00000000000 --- a/src/plugins/mercurial/srcdestdialog.ui +++ /dev/null @@ -1,170 +0,0 @@ - - - Mercurial::Internal::SrcDestDialog - - - - 0 - 0 - 400 - 187 - - - - Dialog - - - - - - - - Default Location - - - true - - - - - - - Local filesystem: - - - - - - - For example: 'https://[user[:pass]@]host[:port]/[path]'. - - - Specify URL: - - - - - - - false - - - - - - - false - - - For example: 'https://[user[:pass]@]host[:port]/[path]'. - - - - - - - - - - - - - - - - Prompt for credentials - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - Utils::PathChooser - QWidget -
utils/pathchooser.h
- 1 -
-
- - - - buttonBox - accepted() - Mercurial::Internal::SrcDestDialog - accept() - - - 257 - 177 - - - 157 - 274 - - - - - buttonBox - rejected() - Mercurial::Internal::SrcDestDialog - reject() - - - 325 - 177 - - - 286 - 274 - - - - - urlButton - toggled(bool) - urlLineEdit - setEnabled(bool) - - - 80 - 121 - - - 332 - 123 - - - - - localButton - toggled(bool) - localPathChooser - setEnabled(bool) - - - 112 - 81 - - - 346 - 81 - - - - -