From 4cf40b24569018cb73eee24d852e60ce05ac483c Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 5 Aug 2022 11:51:35 +0200 Subject: [PATCH] Git: inline branchcheckoutdialog.ui Change-Id: I105f63dd7ae0110ecb0afbd13ff70027fb9431b1 Reviewed-by: Orgad Shaneh --- src/plugins/git/CMakeLists.txt | 2 +- src/plugins/git/branchcheckoutdialog.cpp | 82 +++++++++----- src/plugins/git/branchcheckoutdialog.h | 15 ++- src/plugins/git/branchcheckoutdialog.ui | 132 ----------------------- src/plugins/git/git.qbs | 1 - 5 files changed, 71 insertions(+), 161 deletions(-) delete mode 100644 src/plugins/git/branchcheckoutdialog.ui diff --git a/src/plugins/git/CMakeLists.txt b/src/plugins/git/CMakeLists.txt index 691af23eb26..33b44cbb7e3 100644 --- a/src/plugins/git/CMakeLists.txt +++ b/src/plugins/git/CMakeLists.txt @@ -3,7 +3,7 @@ add_qtc_plugin(Git SOURCES annotationhighlighter.cpp annotationhighlighter.h branchadddialog.cpp branchadddialog.h - branchcheckoutdialog.cpp branchcheckoutdialog.h branchcheckoutdialog.ui + branchcheckoutdialog.cpp branchcheckoutdialog.h branchmodel.cpp branchmodel.h branchview.cpp branchview.h changeselectiondialog.cpp changeselectiondialog.h changeselectiondialog.ui diff --git a/src/plugins/git/branchcheckoutdialog.cpp b/src/plugins/git/branchcheckoutdialog.cpp index 97881c7839b..84700d2d4f2 100644 --- a/src/plugins/git/branchcheckoutdialog.cpp +++ b/src/plugins/git/branchcheckoutdialog.cpp @@ -24,7 +24,14 @@ ****************************************************************************/ #include "branchcheckoutdialog.h" -#include "ui_branchcheckoutdialog.h" + +#include + +#include +#include +#include +#include +#include namespace Git { namespace Internal { @@ -32,63 +39,90 @@ namespace Internal { BranchCheckoutDialog::BranchCheckoutDialog(QWidget *parent, const QString ¤tBranch, const QString &nextBranch) : - QDialog(parent), - m_ui(new Ui::BranchCheckoutDialog) + QDialog(parent) { - m_ui->setupUi(this); - + setWindowModality(Qt::WindowModal); + resize(394, 199); + setModal(true); setWindowTitle(tr("Checkout branch \"%1\"").arg(nextBranch)); - m_ui->moveChangesRadioButton->setText(tr("Move Local Changes to \"%1\"").arg(nextBranch)); - m_ui->popStashCheckBox->setText(tr("Pop Stash of \"%1\"").arg(nextBranch)); + m_localChangesGroupBox = new QGroupBox(tr("Local Changes Found. Choose Action:")); + + m_moveChangesRadioButton = new QRadioButton(tr("Move Local Changes to \"%1\"").arg(nextBranch)); + + m_discardChangesRadioButton = new QRadioButton(tr("Discard Local Changes")); + m_discardChangesRadioButton->setEnabled(true); + + m_popStashCheckBox = new QCheckBox(tr("Pop Stash of \"%1\"").arg(nextBranch)); + m_popStashCheckBox->setEnabled(false); + + m_makeStashRadioButton = new QRadioButton; + m_makeStashRadioButton->setChecked(true); if (!currentBranch.isEmpty()) { - m_ui->makeStashRadioButton->setText(tr("Create Branch Stash for \"%1\"").arg(currentBranch)); + m_makeStashRadioButton->setText(tr("Create Branch Stash for \"%1\"").arg(currentBranch)); } else { - m_ui->makeStashRadioButton->setText(tr("Create Branch Stash for Current Branch")); + m_makeStashRadioButton->setText(tr("Create Branch Stash for Current Branch")); foundNoLocalChanges(); } - connect(m_ui->moveChangesRadioButton, &QRadioButton::toggled, + auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + + using namespace Utils::Layouting; + + Column { + m_makeStashRadioButton, + m_moveChangesRadioButton, + m_discardChangesRadioButton + }.attachTo(m_localChangesGroupBox); + + Column { + m_localChangesGroupBox, + m_popStashCheckBox, + st, + buttonBox + }.attachTo(this); + + connect(m_moveChangesRadioButton, &QRadioButton::toggled, this, &BranchCheckoutDialog::updatePopStashCheckBox); + + connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); } -BranchCheckoutDialog::~BranchCheckoutDialog() -{ - delete m_ui; -} +BranchCheckoutDialog::~BranchCheckoutDialog() = default; void BranchCheckoutDialog::foundNoLocalChanges() { - m_ui->discardChangesRadioButton->setChecked(true); - m_ui->localChangesGroupBox->setEnabled(false); + m_discardChangesRadioButton->setChecked(true); + m_localChangesGroupBox->setEnabled(false); m_hasLocalChanges = false; } void BranchCheckoutDialog::foundStashForNextBranch() { - m_ui->popStashCheckBox->setChecked(true); - m_ui->popStashCheckBox->setEnabled(true); + m_popStashCheckBox->setChecked(true); + m_popStashCheckBox->setEnabled(true); m_foundStashForNextBranch = true; } bool BranchCheckoutDialog::makeStashOfCurrentBranch() { - return m_ui->makeStashRadioButton->isChecked(); + return m_makeStashRadioButton->isChecked(); } bool BranchCheckoutDialog::moveLocalChangesToNextBranch() { - return m_ui->moveChangesRadioButton->isChecked(); + return m_moveChangesRadioButton->isChecked(); } bool BranchCheckoutDialog::discardLocalChanges() { - return m_ui->discardChangesRadioButton->isChecked() && m_ui->localChangesGroupBox->isEnabled(); + return m_discardChangesRadioButton->isChecked() && m_localChangesGroupBox->isEnabled(); } bool BranchCheckoutDialog::popStashOfNextBranch() { - return m_ui->popStashCheckBox->isChecked(); + return m_popStashCheckBox->isChecked(); } bool BranchCheckoutDialog::hasStashForNextBranch() @@ -103,8 +137,8 @@ bool BranchCheckoutDialog::hasLocalChanges() void BranchCheckoutDialog::updatePopStashCheckBox(bool moveChangesChecked) { - m_ui->popStashCheckBox->setChecked(!moveChangesChecked && m_foundStashForNextBranch); - m_ui->popStashCheckBox->setEnabled(!moveChangesChecked && m_foundStashForNextBranch); + m_popStashCheckBox->setChecked(!moveChangesChecked && m_foundStashForNextBranch); + m_popStashCheckBox->setEnabled(!moveChangesChecked && m_foundStashForNextBranch); } } // namespace Internal diff --git a/src/plugins/git/branchcheckoutdialog.h b/src/plugins/git/branchcheckoutdialog.h index 882e5ded40a..f62ccd454bc 100644 --- a/src/plugins/git/branchcheckoutdialog.h +++ b/src/plugins/git/branchcheckoutdialog.h @@ -27,11 +27,15 @@ #include +QT_BEGIN_NAMESPACE +class QCheckBox; +class QGroupBox; +class QRadioButton; +QT_END_NAMESPACE + namespace Git { namespace Internal { -namespace Ui { class BranchCheckoutDialog; } - class BranchCheckoutDialog : public QDialog { Q_OBJECT @@ -55,9 +59,14 @@ public: private: void updatePopStashCheckBox(bool moveChangesChecked); - Ui::BranchCheckoutDialog *m_ui; bool m_foundStashForNextBranch = false; bool m_hasLocalChanges = true; + + QGroupBox *m_localChangesGroupBox; + QRadioButton *m_makeStashRadioButton; + QRadioButton *m_moveChangesRadioButton; + QRadioButton *m_discardChangesRadioButton; + QCheckBox *m_popStashCheckBox; }; } // namespace Internal diff --git a/src/plugins/git/branchcheckoutdialog.ui b/src/plugins/git/branchcheckoutdialog.ui deleted file mode 100644 index 56026daf074..00000000000 --- a/src/plugins/git/branchcheckoutdialog.ui +++ /dev/null @@ -1,132 +0,0 @@ - - - Git::Internal::BranchCheckoutDialog - - - Qt::WindowModal - - - - 0 - 0 - 394 - 199 - - - - true - - - - - - Local Changes Found. Choose Action: - - - - - - RadioButton - - - true - - - - - - - RadioButton - - - - - - - true - - - Discard Local Changes - - - - - - - - - - false - - - CheckBox - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - makeStashRadioButton - moveChangesRadioButton - discardChangesRadioButton - popStashCheckBox - - - - - buttonBox - accepted() - Git::Internal::BranchCheckoutDialog - accept() - - - 227 - 219 - - - 157 - 179 - - - - - buttonBox - rejected() - Git::Internal::BranchCheckoutDialog - reject() - - - 295 - 219 - - - 286 - 179 - - - - - diff --git a/src/plugins/git/git.qbs b/src/plugins/git/git.qbs index 982fbf8bc8c..51f25cb1505 100644 --- a/src/plugins/git/git.qbs +++ b/src/plugins/git/git.qbs @@ -20,7 +20,6 @@ QtcPlugin { "branchadddialog.h", "branchcheckoutdialog.cpp", "branchcheckoutdialog.h", - "branchcheckoutdialog.ui", "branchmodel.cpp", "branchmodel.h", "branchview.cpp",