diff --git a/src/plugins/git/CMakeLists.txt b/src/plugins/git/CMakeLists.txt index 33b44cbb7e3..e7bec67761e 100644 --- a/src/plugins/git/CMakeLists.txt +++ b/src/plugins/git/CMakeLists.txt @@ -37,5 +37,5 @@ add_qtc_plugin(Git remoteadditiondialog.ui remotedialog.cpp remotedialog.h remotedialog.ui remotemodel.cpp remotemodel.h - stashdialog.cpp stashdialog.h stashdialog.ui + stashdialog.cpp stashdialog.h ) diff --git a/src/plugins/git/git.qbs b/src/plugins/git/git.qbs index 51f25cb1505..cfd23f6cda7 100644 --- a/src/plugins/git/git.qbs +++ b/src/plugins/git/git.qbs @@ -63,7 +63,6 @@ QtcPlugin { "remotemodel.h", "stashdialog.cpp", "stashdialog.h", - "stashdialog.ui", ] Group { diff --git a/src/plugins/git/stashdialog.cpp b/src/plugins/git/stashdialog.cpp index 2763a03618e..84f0a9a75c3 100644 --- a/src/plugins/git/stashdialog.cpp +++ b/src/plugins/git/stashdialog.cpp @@ -24,22 +24,29 @@ ****************************************************************************/ #include "stashdialog.h" + #include "gitclient.h" #include "gitplugin.h" #include "gitutils.h" -#include "ui_stashdialog.h" #include +#include +#include +#include #include -#include -#include -#include +#include #include -#include -#include +#include +#include +#include +#include +#include #include +#include #include +#include +#include using namespace Utils; @@ -48,7 +55,7 @@ enum { NameColumn, BranchColumn, MessageColumn, ColumnCount }; namespace Git { namespace Internal { -static inline QList stashModelRowItems(const Stash &s) +static QList stashModelRowItems(const Stash &s) { Qt::ItemFlags itemFlags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; auto nameItem = new QStandardItem(s.name); @@ -63,7 +70,8 @@ static inline QList stashModelRowItems(const Stash &s) } // ----------- StashModel -class StashModel : public QStandardItemModel { +class StashModel : public QStandardItemModel +{ public: explicit StashModel(QObject *parent = nullptr); @@ -93,7 +101,6 @@ void StashModel::setStashes(const QList &stashes) // ---------- StashDialog StashDialog::StashDialog(QWidget *parent) : QDialog(parent), - ui(new Ui::StashDialog), m_model(new StashModel), m_proxyModel(new QSortFilterProxyModel), m_deleteAllButton(new QPushButton(tr("Delete &All..."))), @@ -105,52 +112,76 @@ StashDialog::StashDialog(QWidget *parent) : QDialog(parent), m_refreshButton(new QPushButton(tr("Re&fresh"))) { setAttribute(Qt::WA_DeleteOnClose, true); // Do not update unnecessarily + setWindowTitle(tr("Stashes")); + + resize(599, 485); + + m_repositoryLabel = new QLabel(this); + + auto filterLineEdit = new FancyLineEdit(this); + filterLineEdit->setFiltering(true); + + auto buttonBox = new QDialogButtonBox(this); + buttonBox->setOrientation(Qt::Vertical); + buttonBox->setStandardButtons(QDialogButtonBox::Close); - ui->setupUi(this); - ui->filterLineEdit->setFiltering(true); // Buttons - ui->buttonBox->addButton(m_showCurrentButton, QDialogButtonBox::ActionRole); + buttonBox->addButton(m_showCurrentButton, QDialogButtonBox::ActionRole); connect(m_showCurrentButton, &QPushButton::clicked, this, &StashDialog::showCurrent); - ui->buttonBox->addButton(m_refreshButton, QDialogButtonBox::ActionRole); + buttonBox->addButton(m_refreshButton, QDialogButtonBox::ActionRole); connect(m_refreshButton, &QPushButton::clicked, this, &StashDialog::forceRefresh); - ui->buttonBox->addButton(m_restoreCurrentButton, QDialogButtonBox::ActionRole); + buttonBox->addButton(m_restoreCurrentButton, QDialogButtonBox::ActionRole); connect(m_restoreCurrentButton, &QPushButton::clicked, this, &StashDialog::restoreCurrent); - ui->buttonBox->addButton(m_restoreCurrentInBranchButton, QDialogButtonBox::ActionRole); + buttonBox->addButton(m_restoreCurrentInBranchButton, QDialogButtonBox::ActionRole); connect(m_restoreCurrentInBranchButton, &QPushButton::clicked, this, &StashDialog::restoreCurrentInBranch); - ui->buttonBox->addButton(m_deleteSelectionButton, QDialogButtonBox::ActionRole); + buttonBox->addButton(m_deleteSelectionButton, QDialogButtonBox::ActionRole); connect(m_deleteSelectionButton, &QPushButton::clicked, this, &StashDialog::deleteSelection); - ui->buttonBox->addButton(m_deleteAllButton, QDialogButtonBox::ActionRole); + buttonBox->addButton(m_deleteAllButton, QDialogButtonBox::ActionRole); connect(m_deleteAllButton, &QPushButton::clicked, this, &StashDialog::deleteAll); + // Models m_proxyModel->setSourceModel(m_model); m_proxyModel->setFilterKeyColumn(-1); m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); - ui->stashView->setActivationMode(Utils::DoubleClickActivation); - ui->stashView->setModel(m_proxyModel); - ui->stashView->setSelectionMode(QAbstractItemView::ExtendedSelection); - ui->stashView->setAllColumnsShowFocus(true); - ui->stashView->setUniformRowHeights(true); - connect(ui->filterLineEdit, &Utils::FancyLineEdit::filterChanged, + + m_stashView = new TreeView(this); + m_stashView->setActivationMode(Utils::DoubleClickActivation); + m_stashView->setModel(m_proxyModel); + m_stashView->setSelectionMode(QAbstractItemView::ExtendedSelection); + m_stashView->setAllColumnsShowFocus(true); + m_stashView->setUniformRowHeights(true); + m_stashView->setFocus(); + + using namespace Layouting; + Row { + Column { + m_repositoryLabel, + filterLineEdit, + m_stashView + }, + buttonBox + }.attachTo(this); + + connect(filterLineEdit, &Utils::FancyLineEdit::filterChanged, m_proxyModel, &QSortFilterProxyModel::setFilterFixedString); - connect(ui->stashView->selectionModel(), &QItemSelectionModel::currentRowChanged, + connect(m_stashView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &StashDialog::enableButtons); - connect(ui->stashView->selectionModel(), &QItemSelectionModel::selectionChanged, + connect(m_stashView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &StashDialog::enableButtons); - connect(ui->stashView, &Utils::TreeView::activated, + connect(m_stashView, &Utils::TreeView::activated, this, &StashDialog::showCurrent); - ui->stashView->setFocus(); + + connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); } -StashDialog::~StashDialog() -{ - delete ui; -} +StashDialog::~StashDialog() = default; void StashDialog::refresh(const FilePath &repository, bool force) { @@ -158,7 +189,7 @@ void StashDialog::refresh(const FilePath &repository, bool force) return; // Refresh m_repository = repository; - ui->repositoryLabel->setText(GitPlugin::msgRepositoryLabel(repository)); + m_repositoryLabel->setText(GitPlugin::msgRepositoryLabel(repository)); if (m_repository.isEmpty()) { m_model->setStashes(QList()); } else { @@ -167,7 +198,7 @@ void StashDialog::refresh(const FilePath &repository, bool force) m_model->setStashes(stashes); if (!stashes.isEmpty()) { for (int c = 0; c < ColumnCount; c++) - ui->stashView->resizeColumnToContents(c); + m_stashView->resizeColumnToContents(c); } } enableButtons(); @@ -346,7 +377,7 @@ void StashDialog::restoreCurrentInBranch() int StashDialog::currentRow() const { - const QModelIndex proxyIndex = ui->stashView->currentIndex(); + const QModelIndex proxyIndex = m_stashView->currentIndex(); if (proxyIndex.isValid()) { const QModelIndex index = m_proxyModel->mapToSource(proxyIndex); if (index.isValid()) @@ -358,7 +389,7 @@ int StashDialog::currentRow() const QList StashDialog::selectedRows() const { QList rc; - const QModelIndexList rows = ui->stashView->selectionModel()->selectedRows(); + const QModelIndexList rows = m_stashView->selectionModel()->selectedRows(); for (const QModelIndex &proxyIndex : rows) { const QModelIndex index = m_proxyModel->mapToSource(proxyIndex); if (index.isValid()) @@ -382,7 +413,7 @@ void StashDialog::enableButtons() m_showCurrentButton->setEnabled(hasCurrentRow); m_restoreCurrentButton->setEnabled(hasCurrentRow); m_restoreCurrentInBranchButton->setEnabled(hasCurrentRow); - const bool hasSelection = !ui->stashView->selectionModel()->selectedRows().isEmpty(); + const bool hasSelection = !m_stashView->selectionModel()->selectedRows().isEmpty(); m_deleteSelectionButton->setEnabled(hasSelection); m_refreshButton->setEnabled(hasRepository); } diff --git a/src/plugins/git/stashdialog.h b/src/plugins/git/stashdialog.h index 96d5a0a8a86..f2153315854 100644 --- a/src/plugins/git/stashdialog.h +++ b/src/plugins/git/stashdialog.h @@ -30,14 +30,16 @@ #include QT_BEGIN_NAMESPACE -class QSortFilterProxyModel; +class QLabel; class QPushButton; +class QSortFilterProxyModel; QT_END_NAMESPACE +namespace Utils { class TreeView; } + namespace Git { namespace Internal { -namespace Ui { class StashDialog; } class StashModel; /* StashDialog: Non-modal dialog that manages the list of stashes @@ -78,7 +80,6 @@ private: int currentRow() const; QList selectedRows() const; \ - Ui::StashDialog *ui; StashModel *m_model; QSortFilterProxyModel *m_proxyModel; QPushButton *m_deleteAllButton; @@ -88,6 +89,9 @@ private: QPushButton *m_restoreCurrentInBranchButton; QPushButton *m_refreshButton; Utils::FilePath m_repository; + + QLabel *m_repositoryLabel; + Utils::TreeView *m_stashView; }; } // namespace Internal diff --git a/src/plugins/git/stashdialog.ui b/src/plugins/git/stashdialog.ui deleted file mode 100644 index 3416e39ddf5..00000000000 --- a/src/plugins/git/stashdialog.ui +++ /dev/null @@ -1,93 +0,0 @@ - - - Git::Internal::StashDialog - - - - 0 - 0 - 599 - 485 - - - - Stashes - - - - - - - - Repository: Dummy - - - - - - - - - - - - - - - Qt::Vertical - - - QDialogButtonBox::Close - - - - - - - - Utils::FancyLineEdit - QLineEdit -
utils/fancylineedit.h
-
- - Utils::TreeView - QTreeView -
utils/itemviews.h
-
-
- - - - buttonBox - accepted() - Git::Internal::StashDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - Git::Internal::StashDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - -