Git: inline gerritdialog.ui

Change-Id: Idefdd93a80ac87b9798bf2654413a5c78882b391
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2022-08-03 10:18:06 +02:00
parent 03035feac3
commit d2a205c74c
5 changed files with 147 additions and 361 deletions

View File

@@ -10,7 +10,7 @@ add_qtc_plugin(Git
commitdata.cpp commitdata.h
gerrit/authenticationdialog.cpp gerrit/authenticationdialog.h
gerrit/branchcombobox.cpp gerrit/branchcombobox.h
gerrit/gerritdialog.cpp gerrit/gerritdialog.h gerrit/gerritdialog.ui
gerrit/gerritdialog.cpp gerrit/gerritdialog.h
gerrit/gerritmodel.cpp gerrit/gerritmodel.h
gerrit/gerritoptionspage.cpp gerrit/gerritoptionspage.h
gerrit/gerritparameters.cpp gerrit/gerritparameters.h

View File

@@ -24,16 +24,19 @@
****************************************************************************/
#include "gerritdialog.h"
#include "ui_gerritdialog.h"
#include "gerritmodel.h"
#include "gerritparameters.h"
#include "gerritremotechooser.h"
#include "../gitplugin.h"
#include "../gitclient.h"
#include <coreplugin/icore.h>
#include <utils/fancylineedit.h>
#include <utils/hostosinfo.h>
#include <utils/itemviews.h>
#include <utils/layoutbuilder.h>
#include <utils/progressindicator.h>
#include <utils/qtcassert.h>
#include <utils/theme/theme.h>
@@ -46,6 +49,15 @@
#include <QStringListModel>
#include <QUrl>
#include <QApplication>
#include <QDialog>
#include <QDialogButtonBox>
#include <QGroupBox>
#include <QHeaderView>
#include <QLabel>
#include <QSplitter>
#include <QTextBrowser>
using namespace Utils;
namespace Gerrit {
@@ -61,56 +73,119 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
, m_parameters(p)
, m_server(s)
, m_filterModel(new QSortFilterProxyModel(this))
, m_ui(new Ui::GerritDialog)
, m_model(new GerritModel(p, this))
, m_queryModel(new QStringListModel(this))
{
m_ui->setupUi(this);
m_ui->remoteComboBox->setParameters(m_parameters);
m_ui->remoteComboBox->setFallbackEnabled(true);
setWindowTitle(tr("Gerrit"));
resize(950, 706);
m_repositoryLabel = new QLabel(this);
m_repositoryLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
m_remoteComboBox = new GerritRemoteChooser(this);
m_remoteComboBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
m_remoteComboBox->setMinimumSize(QSize(40, 0));
auto changesGroup = new QGroupBox(tr("Changes"));
changesGroup->setMinimumSize(QSize(0, 350));
m_queryLineEdit = new FancyLineEdit(changesGroup);
m_queryLineEdit->setMinimumSize(QSize(400, 0));
m_queryLineEdit->setPlaceholderText(tr("Change #, SHA-1, tr:id, owner:email or reviewer:email"));
m_queryLineEdit->setSpecialCompleter(new QCompleter(m_queryModel, this));
m_queryLineEdit->setValidationFunction(
[this](FancyLineEdit *, QString *) { return m_model->state() != GerritModel::Error; });
auto filterLineEdit = new FancyLineEdit(changesGroup);
filterLineEdit->setMinimumSize(QSize(300, 0));
filterLineEdit->setFiltering(true);
m_treeView = new TreeView(changesGroup);
m_treeView->setMinimumSize(QSize(600, 0));
m_treeView->setRootIsDecorated(false);
m_treeView->setUniformRowHeights(true);
m_treeView->setSortingEnabled(true);
auto detailsGroup = new QGroupBox(tr("Details"));
detailsGroup->setMinimumSize(QSize(0, 175));
m_detailsBrowser = new QTextBrowser(detailsGroup);
m_detailsBrowser->setOpenExternalLinks(true);
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
auto queryLabel = new QLabel(tr("&Query:"), changesGroup);
queryLabel->setBuddy(m_queryLineEdit);
m_remoteComboBox->setParameters(m_parameters);
m_remoteComboBox->setFallbackEnabled(true);
m_queryModel->setStringList(m_parameters->savedQueries);
auto completer = new QCompleter(this);
completer->setModel(m_queryModel);
m_ui->queryLineEdit->setSpecialCompleter(completer);
m_ui->queryLineEdit->setValidationFunction([this](Utils::FancyLineEdit *, QString *) {
return m_model->state() != GerritModel::Error;
});
m_ui->filterLineEdit->setFiltering(true);
connect(m_ui->filterLineEdit, &Utils::FancyLineEdit::filterChanged,
m_filterModel, &QSortFilterProxyModel::setFilterFixedString);
connect(m_ui->queryLineEdit, &QLineEdit::returnPressed, this, &GerritDialog::refresh);
connect(m_model, &GerritModel::stateChanged, m_ui->queryLineEdit, &Utils::FancyLineEdit::validate);
connect(m_ui->remoteComboBox, &GerritRemoteChooser::remoteChanged,
this, &GerritDialog::remoteChanged);
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
m_filterModel->setSourceModel(m_model);
m_filterModel->setFilterRole(GerritModel::FilterRole);
m_filterModel->setSortRole(GerritModel::SortRole);
m_ui->treeView->setModel(m_filterModel);
m_ui->treeView->setActivationMode(Utils::DoubleClickActivation);
connect(&m_progressIndicatorTimer, &QTimer::timeout,
[this]() { setProgressIndicatorVisible(true); });
m_treeView->setModel(m_filterModel);
m_treeView->setActivationMode(Utils::DoubleClickActivation);
m_progressIndicatorTimer.setSingleShot(true);
m_progressIndicatorTimer.setInterval(50); // don't show progress for < 50ms tasks
m_progressIndicator = new Utils::ProgressIndicator(Utils::ProgressIndicatorSize::Large,
m_ui->treeView);
m_progressIndicator->attachToWidget(m_ui->treeView->viewport());
m_progressIndicator = new ProgressIndicator(ProgressIndicatorSize::Large, m_treeView);
m_progressIndicator->attachToWidget(m_treeView->viewport());
m_progressIndicator->hide();
connect(m_model, &GerritModel::stateChanged, this, &GerritDialog::manageProgressIndicator);
QItemSelectionModel *selectionModel = m_ui->treeView->selectionModel();
connect(selectionModel, &QItemSelectionModel::currentChanged,
this, &GerritDialog::slotCurrentChanged);
connect(m_ui->treeView, &QAbstractItemView::activated,
this, &GerritDialog::slotActivated);
m_displayButton = addActionButton(tr("&Show"), [this]() { slotFetchDisplay(); });
m_cherryPickButton = addActionButton(tr("Cherry &Pick"), [this]() { slotFetchCherryPick(); });
m_checkoutButton = addActionButton(tr("C&heckout"), [this]() { slotFetchCheckout(); });
m_refreshButton = addActionButton(tr("&Refresh"), [this]() { refresh(); });
m_refreshButton->setDefault(true);
using namespace Layouting;
Column {
Row {
queryLabel,
m_queryLineEdit,
st,
filterLineEdit
},
m_treeView
}.attachTo(changesGroup);
Column {
m_detailsBrowser
}.attachTo(detailsGroup);
auto splitter = new QSplitter(this);
splitter->setOrientation(Qt::Vertical);
splitter->setChildrenCollapsible(false);
splitter->addWidget(changesGroup);
splitter->addWidget(detailsGroup);
Column {
Row { m_repositoryLabel, st, tr("Remote:"), m_remoteComboBox },
splitter,
m_buttonBox
}.attachTo(this);
connect(filterLineEdit, &Utils::FancyLineEdit::filterChanged,
m_filterModel, &QSortFilterProxyModel::setFilterFixedString);
connect(m_queryLineEdit, &QLineEdit::returnPressed,
this, &GerritDialog::refresh);
connect(m_model, &GerritModel::stateChanged,
m_queryLineEdit, &Utils::FancyLineEdit::validate);
connect(m_remoteComboBox, &GerritRemoteChooser::remoteChanged,
this, &GerritDialog::remoteChanged);
connect(&m_progressIndicatorTimer, &QTimer::timeout,
this, [this] { setProgressIndicatorVisible(true); });
connect(m_model, &GerritModel::stateChanged,
this, &GerritDialog::manageProgressIndicator);
connect(m_treeView->selectionModel(), &QItemSelectionModel::currentChanged,
this, &GerritDialog::slotCurrentChanged);
connect(m_treeView, &QAbstractItemView::activated,
this, &GerritDialog::slotActivated);
connect(m_model, &GerritModel::refreshStateChanged,
m_refreshButton, &QWidget::setDisabled);
@@ -125,8 +200,10 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
setCurrentPath(repository);
slotCurrentChanged();
m_ui->treeView->setFocus();
m_refreshButton->setDefault(true);
m_treeView->setFocus();
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
FilePath GerritDialog::repositoryPath() const
@@ -139,14 +216,14 @@ void GerritDialog::setCurrentPath(const FilePath &path)
if (path == m_repository)
return;
m_repository = path;
m_ui->repositoryLabel->setText(Git::Internal::GitPlugin::msgRepositoryLabel(path));
m_repositoryLabel->setText(Git::Internal::GitPlugin::msgRepositoryLabel(path));
updateRemotes();
}
QPushButton *GerritDialog::addActionButton(const QString &text,
const std::function<void()> &buttonSlot)
{
QPushButton *button = m_ui->buttonBox->addButton(text, QDialogButtonBox::ActionRole);
QPushButton *button = m_buttonBox->addButton(text, QDialogButtonBox::ActionRole);
connect(button, &QPushButton::clicked, this, buttonSlot);
return button;
}
@@ -162,10 +239,7 @@ void GerritDialog::updateCompletions(const QString &query)
m_parameters->saveQueries(Core::ICore::settings());
}
GerritDialog::~GerritDialog()
{
delete m_ui;
}
GerritDialog::~GerritDialog() = default;
void GerritDialog::slotActivated(const QModelIndex &i)
{
@@ -177,11 +251,11 @@ void GerritDialog::slotActivated(const QModelIndex &i)
void GerritDialog::slotRefreshStateChanged(bool v)
{
if (!v && m_model->rowCount()) {
m_ui->treeView->expandAll();
m_treeView->expandAll();
for (int c = 0; c < GerritModel::ColumnCount; ++c)
m_ui->treeView->resizeColumnToContents(c);
if (m_ui->treeView->columnWidth(GerritModel::TitleColumn) > maxTitleWidth)
m_ui->treeView->setColumnWidth(GerritModel::TitleColumn, maxTitleWidth);
m_treeView->resizeColumnToContents(c);
if (m_treeView->columnWidth(GerritModel::TitleColumn) > maxTitleWidth)
m_treeView->setColumnWidth(GerritModel::TitleColumn, maxTitleWidth);
}
}
@@ -208,10 +282,10 @@ void GerritDialog::slotFetchCheckout()
void GerritDialog::refresh()
{
const QString &query = m_ui->queryLineEdit->text().trimmed();
const QString &query = m_queryLineEdit->text().trimmed();
updateCompletions(query);
m_model->refresh(m_server, query);
m_ui->treeView->sortByColumn(-1, Qt::DescendingOrder);
m_treeView->sortByColumn(-1, Qt::DescendingOrder);
}
void GerritDialog::scheduleUpdateRemotes()
@@ -233,7 +307,7 @@ void GerritDialog::showEvent(QShowEvent *event)
void GerritDialog::remoteChanged()
{
const GerritServer server = m_ui->remoteComboBox->currentServer();
const GerritServer server = m_remoteComboBox->currentServer();
if (QSharedPointer<GerritServer> modelServer = m_model->server()) {
if (*modelServer == server)
return;
@@ -245,11 +319,11 @@ void GerritDialog::remoteChanged()
void GerritDialog::updateRemotes(bool forceReload)
{
m_ui->remoteComboBox->setRepository(m_repository);
m_remoteComboBox->setRepository(m_repository);
if (m_repository.isEmpty() || !m_repository.isDir())
return;
*m_server = m_parameters->server;
m_ui->remoteComboBox->updateRemotes(forceReload);
m_remoteComboBox->updateRemotes(forceReload);
}
void GerritDialog::manageProgressIndicator()
@@ -264,13 +338,13 @@ void GerritDialog::manageProgressIndicator()
QModelIndex GerritDialog::currentIndex() const
{
const QModelIndex index = m_ui->treeView->selectionModel()->currentIndex();
const QModelIndex index = m_treeView->selectionModel()->currentIndex();
return index.isValid() ? m_filterModel->mapToSource(index) : QModelIndex();
}
void GerritDialog::updateButtons()
{
const bool enabled = !m_fetchRunning && m_ui->treeView->selectionModel()->currentIndex().isValid();
const bool enabled = !m_fetchRunning && m_treeView->selectionModel()->currentIndex().isValid();
m_displayButton->setEnabled(enabled);
m_cherryPickButton->setEnabled(enabled);
m_checkoutButton->setEnabled(enabled);
@@ -279,7 +353,7 @@ void GerritDialog::updateButtons()
void GerritDialog::slotCurrentChanged()
{
const QModelIndex current = currentIndex();
m_ui->detailsBrowser->setText(current.isValid() ? m_model->toHtml(current) : QString());
m_detailsBrowser->setText(current.isValid() ? m_model->toHtml(current) : QString());
updateButtons();
}

View File

@@ -34,20 +34,28 @@
#include <functional>
QT_BEGIN_NAMESPACE
class QDialogButtonBox;
class QLabel;
class QModelIndex;
class QSortFilterProxyModel;
class QStringListModel;
class QPushButton;
class QTextBrowser;
QT_END_NAMESPACE
namespace Utils { class ProgressIndicator; }
namespace Utils {
class FancyLineEdit;
class ProgressIndicator;
class TreeView;
} // Utils
namespace Gerrit {
namespace Internal {
namespace Ui { class GerritDialog; }
class GerritChange;
class GerritModel;
class GerritParameters;
class GerritRemoteChooser;
class GerritServer;
class GerritDialog : public QDialog
@@ -86,14 +94,13 @@ private:
void setProgressIndicatorVisible(bool v);
QModelIndex currentIndex() const;
QPushButton *addActionButton(const QString &text, const std::function<void()> &buttonSlot);
void updateCompletions(const QString &query);
QPushButton *addActionButton(const QString &text, const std::function<void ()> &buttonSlot);
void updateButtons();
const QSharedPointer<GerritParameters> m_parameters;
const QSharedPointer<GerritServer> m_server;
QSortFilterProxyModel *m_filterModel;
Ui::GerritDialog *m_ui;
GerritModel *m_model;
QStringListModel *m_queryModel;
QPushButton *m_displayButton;
@@ -106,6 +113,13 @@ private:
bool m_fetchRunning = false;
bool m_updatingRemotes = false;
bool m_shouldUpdateRemotes = false;
QLabel *m_repositoryLabel;
GerritRemoteChooser *m_remoteComboBox;
Utils::TreeView *m_treeView;
QTextBrowser *m_detailsBrowser;
QDialogButtonBox *m_buttonBox;
Utils::FancyLineEdit *m_queryLineEdit;
};
} // namespace Internal

View File

@@ -1,301 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Gerrit::Internal::GerritDialog</class>
<widget class="QDialog" name="Gerrit::Internal::GerritDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>950</width>
<height>706</height>
</rect>
</property>
<property name="windowTitle">
<string>Gerrit</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="repositoryLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">Repository: Dummy</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="remoteLabel">
<property name="text">
<string>Remote:</string>
</property>
</widget>
</item>
<item>
<widget class="Gerrit::Internal::GerritRemoteChooser" name="remoteComboBox" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="QGroupBox" name="changesGroup">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>2</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>350</height>
</size>
</property>
<property name="title">
<string>Changes</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="filterLayout">
<item>
<widget class="QLabel" name="queryLabel">
<property name="text">
<string>&amp;Query:</string>
</property>
<property name="buddy">
<cstring>queryLineEdit</cstring>
</property>
</widget>
</item>
<item>
<widget class="Utils::FancyLineEdit" name="queryLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="placeholderText">
<string>Change #, SHA-1, tr:id, owner:email or reviewer:email</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Utils::FancyLineEdit" name="filterLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Utils::TreeView" name="treeView">
<property name="minimumSize">
<size>
<width>600</width>
<height>0</height>
</size>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QGroupBox" name="detailsGroup">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>175</height>
</size>
</property>
<property name="title">
<string>Details</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QTextBrowser" name="detailsBrowser">
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::FancyLineEdit</class>
<extends>QLineEdit</extends>
<header location="global">utils/fancylineedit.h</header>
</customwidget>
<customwidget>
<class>Utils::TreeView</class>
<extends>QTreeView</extends>
<header location="global">utils/itemviews.h</header>
</customwidget>
<customwidget>
<class>Gerrit::Internal::GerritRemoteChooser</class>
<extends>QWidget</extends>
<header location="global">git/gerrit/gerritremotechooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Gerrit::Internal::GerritDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Gerrit::Internal::GerritDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -77,7 +77,6 @@ QtcPlugin {
"branchcombobox.h",
"gerritdialog.cpp",
"gerritdialog.h",
"gerritdialog.ui",
"gerritmodel.cpp",
"gerritmodel.h",
"gerritoptionspage.cpp",