diff --git a/src/plugins/git/CMakeLists.txt b/src/plugins/git/CMakeLists.txt index 0dfd44a6ca5..b6f94c7174f 100644 --- a/src/plugins/git/CMakeLists.txt +++ b/src/plugins/git/CMakeLists.txt @@ -33,8 +33,7 @@ add_qtc_plugin(Git gitutils.cpp gitutils.h logchangedialog.cpp logchangedialog.h mergetool.cpp mergetool.h - remoteadditiondialog.ui - remotedialog.cpp remotedialog.h remotedialog.ui + remotedialog.cpp remotedialog.h remotemodel.cpp remotemodel.h stashdialog.cpp stashdialog.h ) diff --git a/src/plugins/git/git.qbs b/src/plugins/git/git.qbs index c998fa007ec..e54b9e465b4 100644 --- a/src/plugins/git/git.qbs +++ b/src/plugins/git/git.qbs @@ -54,10 +54,8 @@ QtcPlugin { "logchangedialog.h", "mergetool.cpp", "mergetool.h", - "remoteadditiondialog.ui", "remotedialog.cpp", "remotedialog.h", - "remotedialog.ui", "remotemodel.cpp", "remotemodel.h", "stashdialog.cpp", diff --git a/src/plugins/git/remoteadditiondialog.ui b/src/plugins/git/remoteadditiondialog.ui deleted file mode 100644 index 3768c8945db..00000000000 --- a/src/plugins/git/remoteadditiondialog.ui +++ /dev/null @@ -1,91 +0,0 @@ - - - Git::Internal::RemoteAdditionDialog - - - - 0 - 0 - 381 - 93 - - - - Add Remote - - - - - - Name: - - - - - - - - - - URL: - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - Utils::FancyLineEdit - QLineEdit -
utils/fancylineedit.h
-
-
- - - - buttonBox - rejected() - Git::Internal::RemoteAdditionDialog - reject() - - - 283 - 81 - - - 380 - 27 - - - - - buttonBox - accepted() - Git::Internal::RemoteAdditionDialog - accept() - - - 211 - 81 - - - 182 - 92 - - - - -
diff --git a/src/plugins/git/remotedialog.cpp b/src/plugins/git/remotedialog.cpp index e99572ad11f..2856d1e0c85 100644 --- a/src/plugins/git/remotedialog.cpp +++ b/src/plugins/git/remotedialog.cpp @@ -28,15 +28,24 @@ #include "gitclient.h" #include "gitplugin.h" #include "remotemodel.h" -#include "ui_remotedialog.h" -#include "ui_remoteadditiondialog.h" #include #include +#include + #include +#include +#include +#include +#include +#include +#include +#include #include +#include #include +#include using namespace Utils; @@ -54,9 +63,11 @@ public: m_invalidRemoteNameChars(GitPlugin::invalidBranchAndRemoteNamePattern()), m_remoteNames(remoteNames) { - m_ui.setupUi(this); - m_ui.nameEdit->setHistoryCompleter("Git.RemoteNames"); - m_ui.nameEdit->setValidationFunction([this](Utils::FancyLineEdit *edit, QString *errorMessage) { + resize(381, 93); + + m_nameEdit = new FancyLineEdit(this); + m_nameEdit->setHistoryCompleter("Git.RemoteNames"); + m_nameEdit->setValidationFunction([this](FancyLineEdit *edit, QString *errorMessage) { if (!edit) return false; @@ -83,12 +94,10 @@ public: // is a valid remote name return !input.isEmpty(); }); - connect(m_ui.nameEdit, &QLineEdit::textChanged, [this]() { - m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_ui.nameEdit->isValid()); - }); - m_ui.urlEdit->setHistoryCompleter("Git.RemoteUrls"); - m_ui.urlEdit->setValidationFunction([](Utils::FancyLineEdit *edit, QString *errorMessage) { + m_urlEdit = new FancyLineEdit(this); + m_urlEdit->setHistoryCompleter("Git.RemoteUrls"); + m_urlEdit->setValidationFunction([](FancyLineEdit *edit, QString *errorMessage) { if (!edit || edit->text().isEmpty()) return false; @@ -99,21 +108,38 @@ public: return r.isValid; }); - m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + + using namespace Layouting; + Grid { + tr("Name:"), m_nameEdit, br, + tr("URL:"), m_urlEdit, br, + Span(2, buttonBox) + }.attachTo(this); + + connect(m_nameEdit, &QLineEdit::textChanged, [this, buttonBox] { + buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_nameEdit->isValid()); + }); + + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); } QString remoteName() const { - return m_ui.nameEdit->text(); + return m_nameEdit->text(); } QString remoteUrl() const { - return m_ui.urlEdit->text(); + return m_urlEdit->text(); } private: - Ui::RemoteAdditionDialog m_ui; + FancyLineEdit *m_nameEdit; + FancyLineEdit *m_urlEdit; + const QRegularExpression m_invalidRemoteNameChars; QStringList m_remoteNames; }; @@ -126,42 +152,78 @@ private: RemoteDialog::RemoteDialog(QWidget *parent) : QDialog(parent), - m_ui(new Ui::RemoteDialog), m_remoteModel(new RemoteModel(this)) { setModal(false); setAttribute(Qt::WA_DeleteOnClose, true); // Do not update unnecessarily + setWindowTitle(tr("Remotes")); - m_ui->setupUi(this); + m_repositoryLabel = new QLabel; - m_ui->remoteView->setModel(m_remoteModel); - new Utils::HeaderViewStretcher(m_ui->remoteView->header(), 1); + auto refreshButton = new QPushButton(tr("Re&fresh")); + refreshButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); - connect(m_ui->addButton, &QPushButton::clicked, this, &RemoteDialog::addRemote); - connect(m_ui->fetchButton, &QPushButton::clicked, this, &RemoteDialog::fetchFromRemote); - connect(m_ui->pushButton, &QPushButton::clicked, this, &RemoteDialog::pushToRemote); - connect(m_ui->removeButton, &QPushButton::clicked, this, &RemoteDialog::removeRemote); - connect(m_ui->refreshButton, &QPushButton::clicked, this, &RemoteDialog::refreshRemotes); + m_remoteView = new QTreeView; + m_remoteView->setMinimumSize(QSize(0, 100)); + m_remoteView->setEditTriggers(QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed); + m_remoteView->setSelectionMode(QAbstractItemView::SingleSelection); + m_remoteView->setSelectionBehavior(QAbstractItemView::SelectRows); + m_remoteView->setRootIsDecorated(false); + m_remoteView->setUniformRowHeights(true); + m_remoteView->setModel(m_remoteModel); + new HeaderViewStretcher(m_remoteView->header(), 1); - connect(m_ui->remoteView->selectionModel(), &QItemSelectionModel::selectionChanged, + m_addButton = new QPushButton(tr("&Add...")); + m_addButton->setAutoDefault(false); + + m_fetchButton = new QPushButton(tr("F&etch")); + + m_pushButton = new QPushButton(tr("&Push")); + + m_removeButton = new QPushButton(tr("&Remove")); + m_removeButton->setAutoDefault(false); + + auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); + + using namespace Layouting; + Column { + Group { + Row { m_repositoryLabel, refreshButton } + }, + Group { + title(tr("Remotes")), + Column { + m_remoteView, + Row { st, m_addButton, m_fetchButton, m_pushButton, m_removeButton } + } + }, + buttonBox, + }.attachTo(this); + + connect(m_addButton, &QPushButton::clicked, this, &RemoteDialog::addRemote); + connect(m_fetchButton, &QPushButton::clicked, this, &RemoteDialog::fetchFromRemote); + connect(m_pushButton, &QPushButton::clicked, this, &RemoteDialog::pushToRemote); + connect(m_removeButton, &QPushButton::clicked, this, &RemoteDialog::removeRemote); + connect(refreshButton, &QPushButton::clicked, this, &RemoteDialog::refreshRemotes); + + connect(m_remoteView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &RemoteDialog::updateButtonState); connect(m_remoteModel, &RemoteModel::refreshed, this, &RemoteDialog::updateButtonState); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + updateButtonState(); } -RemoteDialog::~RemoteDialog() -{ - delete m_ui; -} +RemoteDialog::~RemoteDialog() = default; void RemoteDialog::refresh(const FilePath &repository, bool force) { if (m_remoteModel->workingDirectory() == repository && !force) return; // Refresh - m_ui->repositoryLabel->setText(GitPlugin::msgRepositoryLabel(repository)); + m_repositoryLabel->setText(GitPlugin::msgRepositoryLabel(repository)); if (repository.isEmpty()) { m_remoteModel->clear(); } else { @@ -187,7 +249,7 @@ void RemoteDialog::addRemote() void RemoteDialog::removeRemote() { - const QModelIndexList indexList = m_ui->remoteView->selectionModel()->selectedIndexes(); + const QModelIndexList indexList = m_remoteView->selectionModel()->selectedIndexes(); if (indexList.isEmpty()) return; @@ -203,7 +265,7 @@ void RemoteDialog::removeRemote() void RemoteDialog::pushToRemote() { - const QModelIndexList indexList = m_ui->remoteView->selectionModel()->selectedIndexes(); + const QModelIndexList indexList = m_remoteView->selectionModel()->selectedIndexes(); if (indexList.isEmpty()) return; @@ -214,7 +276,7 @@ void RemoteDialog::pushToRemote() void RemoteDialog::fetchFromRemote() { - const QModelIndexList indexList = m_ui->remoteView->selectionModel()->selectedIndexes(); + const QModelIndexList indexList = m_remoteView->selectionModel()->selectedIndexes(); if (indexList.isEmpty()) return; @@ -225,13 +287,13 @@ void RemoteDialog::fetchFromRemote() void RemoteDialog::updateButtonState() { - const QModelIndexList indexList = m_ui->remoteView->selectionModel()->selectedIndexes(); + const QModelIndexList indexList = m_remoteView->selectionModel()->selectedIndexes(); const bool haveSelection = !indexList.isEmpty(); - m_ui->addButton->setEnabled(true); - m_ui->fetchButton->setEnabled(haveSelection); - m_ui->pushButton->setEnabled(haveSelection); - m_ui->removeButton->setEnabled(haveSelection); + m_addButton->setEnabled(true); + m_fetchButton->setEnabled(haveSelection); + m_pushButton->setEnabled(haveSelection); + m_removeButton->setEnabled(haveSelection); } } // namespace Internal diff --git a/src/plugins/git/remotedialog.h b/src/plugins/git/remotedialog.h index d8ecab63121..71696b7c620 100644 --- a/src/plugins/git/remotedialog.h +++ b/src/plugins/git/remotedialog.h @@ -27,13 +27,16 @@ #include +QT_BEGIN_NAMESPACE +class QLabel; +class QTreeView; +QT_END_NAMESPACE + namespace Utils { class FilePath; } namespace Git { namespace Internal { -namespace Ui { class RemoteDialog; } - class RemoteModel; class RemoteDialog : public QDialog @@ -55,9 +58,14 @@ private: void updateButtonState(); - Ui::RemoteDialog *m_ui; - RemoteModel *m_remoteModel; + + QLabel *m_repositoryLabel; + QTreeView *m_remoteView; + QPushButton *m_addButton; + QPushButton *m_fetchButton; + QPushButton *m_pushButton; + QPushButton *m_removeButton; }; } // namespace Internal diff --git a/src/plugins/git/remotedialog.ui b/src/plugins/git/remotedialog.ui deleted file mode 100644 index b84553303ae..00000000000 --- a/src/plugins/git/remotedialog.ui +++ /dev/null @@ -1,166 +0,0 @@ - - - Git::Internal::RemoteDialog - - - Remotes - - - - - - - 4 - - - 4 - - - - - Repository: Dummy - - - - - - - - 0 - 0 - - - - Re&fresh - - - - - - - - - - Remotes - - - - 9 - - - 4 - - - 4 - - - - - - 0 - 100 - - - - QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - false - - - true - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - &Add... - - - false - - - - - - - F&etch - - - - - - - &Push - - - - - - - &Remove - - - false - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Close - - - - - - - - - buttonBox - rejected() - Git::Internal::RemoteDialog - reject() - - - 466 - 614 - - - 544 - 23 - - - - - diff --git a/src/plugins/git/remotemodel.h b/src/plugins/git/remotemodel.h index 85ceabdafe8..6863ae8000b 100644 --- a/src/plugins/git/remotemodel.h +++ b/src/plugins/git/remotemodel.h @@ -34,7 +34,8 @@ namespace Git { namespace Internal { -class RemoteModel : public QAbstractTableModel { +class RemoteModel : public QAbstractTableModel +{ Q_OBJECT public: explicit RemoteModel(QObject *parent = nullptr);