forked from qt-creator/qt-creator
Git: Use LayoutBuilder in Gerrit options page
Move towards using aspects and away from IOptionPage's QObject base. Change-Id: I07850a6b8e9fa7d2591efc6f76a23f249dfc164f Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
#include "../gittr.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <utils/pathchooser.h>
|
||||
|
||||
#include <vcsbase/vcsbaseconstants.h>
|
||||
@@ -21,69 +23,56 @@ namespace Gerrit::Internal {
|
||||
class GerritOptionsWidget : public Core::IOptionsPageWidget
|
||||
{
|
||||
public:
|
||||
GerritOptionsWidget(GerritOptionsPage *page, const QSharedPointer<GerritParameters> &p)
|
||||
: m_page(page)
|
||||
, m_hostLineEdit(new QLineEdit(this))
|
||||
, m_userLineEdit(new QLineEdit(this))
|
||||
, m_sshChooser(new Utils::PathChooser)
|
||||
, m_curlChooser(new Utils::PathChooser)
|
||||
, m_portSpinBox(new QSpinBox(this))
|
||||
, m_httpsCheckBox(new QCheckBox(Git::Tr::tr("HTTPS")))
|
||||
, m_parameters(p)
|
||||
GerritOptionsWidget(const QSharedPointer<GerritParameters> &p,
|
||||
const std::function<void()> &onChanged)
|
||||
: m_parameters(p)
|
||||
{
|
||||
m_hostLineEdit->setText(p->server.host);
|
||||
m_userLineEdit->setText(p->server.user.userName);
|
||||
m_sshChooser->setFilePath(p->ssh);
|
||||
m_curlChooser->setFilePath(p->curl);
|
||||
m_portSpinBox->setValue(p->server.port);
|
||||
m_httpsCheckBox->setChecked(p->https);
|
||||
auto hostLineEdit = new QLineEdit(p->server.host);
|
||||
|
||||
auto formLayout = new QFormLayout(this);
|
||||
formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
||||
formLayout->addRow(Git::Tr::tr("&Host:"), m_hostLineEdit);
|
||||
formLayout->addRow(Git::Tr::tr("&User:"), m_userLineEdit);
|
||||
m_sshChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
||||
m_sshChooser->setCommandVersionArguments({"-V"});
|
||||
m_sshChooser->setHistoryCompleter("Git.SshCommand.History");
|
||||
formLayout->addRow(Git::Tr::tr("&ssh:"), m_sshChooser);
|
||||
m_curlChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
||||
m_curlChooser->setCommandVersionArguments({"-V"});
|
||||
formLayout->addRow(Git::Tr::tr("cur&l:"), m_curlChooser);
|
||||
m_portSpinBox->setMinimum(1);
|
||||
m_portSpinBox->setMaximum(65535);
|
||||
formLayout->addRow(Git::Tr::tr("SSH &Port:"), m_portSpinBox);
|
||||
formLayout->addRow(Git::Tr::tr("P&rotocol:"), m_httpsCheckBox);
|
||||
m_httpsCheckBox->setToolTip(Git::Tr::tr(
|
||||
auto userLineEdit = new QLineEdit(p->server.user.userName);
|
||||
|
||||
auto sshChooser = new Utils::PathChooser;
|
||||
sshChooser->setFilePath(p->ssh);
|
||||
sshChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
||||
sshChooser->setCommandVersionArguments({"-V"});
|
||||
sshChooser->setHistoryCompleter("Git.SshCommand.History");
|
||||
|
||||
auto curlChooser = new Utils::PathChooser;
|
||||
curlChooser->setFilePath(p->curl);
|
||||
curlChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
||||
curlChooser->setCommandVersionArguments({"-V"});
|
||||
|
||||
auto portSpinBox = new QSpinBox(this);
|
||||
portSpinBox->setValue(p->server.port);
|
||||
portSpinBox->setRange(1, 65535);
|
||||
|
||||
auto httpsCheckBox = new QCheckBox(Git::Tr::tr("HTTPS"));
|
||||
httpsCheckBox->setChecked(p->https);
|
||||
httpsCheckBox->setToolTip(Git::Tr::tr(
|
||||
"Determines the protocol used to form a URL in case\n"
|
||||
"\"canonicalWebUrl\" is not configured in the file\n"
|
||||
"\"gerrit.config\"."));
|
||||
setTabOrder(m_sshChooser, m_curlChooser);
|
||||
setTabOrder(m_curlChooser, m_portSpinBox);
|
||||
}
|
||||
|
||||
private:
|
||||
void apply() final;
|
||||
using namespace Layouting;
|
||||
Form {
|
||||
Git::Tr::tr("&Host:"), hostLineEdit, br,
|
||||
Git::Tr::tr("&User:"), userLineEdit, br,
|
||||
Git::Tr::tr("&ssh:"), sshChooser, br,
|
||||
Git::Tr::tr("cur&l:"), curlChooser, br,
|
||||
Git::Tr::tr("SSH &Port:"), portSpinBox, br,
|
||||
Git::Tr::tr("P&rotocol:"), httpsCheckBox
|
||||
}.attachTo(this);
|
||||
|
||||
GerritOptionsPage *m_page;
|
||||
QLineEdit *m_hostLineEdit;
|
||||
QLineEdit *m_userLineEdit;
|
||||
Utils::PathChooser *m_sshChooser;
|
||||
Utils::PathChooser *m_curlChooser;
|
||||
QSpinBox *m_portSpinBox;
|
||||
QCheckBox *m_httpsCheckBox;
|
||||
const QSharedPointer<GerritParameters> &m_parameters;
|
||||
};
|
||||
|
||||
void GerritOptionsWidget::apply()
|
||||
{
|
||||
setOnApply([this, hostLineEdit, userLineEdit, sshChooser,
|
||||
curlChooser, portSpinBox, httpsCheckBox, onChanged] {
|
||||
GerritParameters newParameters;
|
||||
newParameters.server = GerritServer(m_hostLineEdit->text().trimmed(),
|
||||
static_cast<unsigned short>(m_portSpinBox->value()),
|
||||
m_userLineEdit->text().trimmed(),
|
||||
newParameters.server = GerritServer(hostLineEdit->text().trimmed(),
|
||||
static_cast<unsigned short>(portSpinBox->value()),
|
||||
userLineEdit->text().trimmed(),
|
||||
GerritServer::Ssh);
|
||||
newParameters.ssh = m_sshChooser->filePath();
|
||||
newParameters.curl = m_curlChooser->filePath();
|
||||
newParameters.https = m_httpsCheckBox->isChecked();
|
||||
newParameters.ssh = sshChooser->filePath();
|
||||
newParameters.curl = curlChooser->filePath();
|
||||
newParameters.https = httpsCheckBox->isChecked();
|
||||
|
||||
if (newParameters != *m_parameters) {
|
||||
if (m_parameters->ssh == newParameters.ssh)
|
||||
@@ -92,19 +81,24 @@ void GerritOptionsWidget::apply()
|
||||
newParameters.setPortFlagBySshType();
|
||||
*m_parameters = newParameters;
|
||||
m_parameters->toSettings(Core::ICore::settings());
|
||||
emit m_page->settingsChanged();
|
||||
emit onChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
const QSharedPointer<GerritParameters> &m_parameters;
|
||||
};
|
||||
|
||||
// GerritOptionsPage
|
||||
|
||||
GerritOptionsPage::GerritOptionsPage(const QSharedPointer<GerritParameters> &p, QObject *parent)
|
||||
: Core::IOptionsPage(parent)
|
||||
GerritOptionsPage::GerritOptionsPage(const QSharedPointer<GerritParameters> &p,
|
||||
const std::function<void()> &onChanged)
|
||||
{
|
||||
setId("Gerrit");
|
||||
setDisplayName(Git::Tr::tr("Gerrit"));
|
||||
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
||||
setWidgetCreator([this, p] { return new GerritOptionsWidget(this, p); });
|
||||
setWidgetCreator([p, onChanged] { return new GerritOptionsWidget(p, onChanged); });
|
||||
}
|
||||
|
||||
} // Gerrit::Internal
|
||||
|
||||
@@ -13,13 +13,9 @@ class GerritParameters;
|
||||
|
||||
class GerritOptionsPage : public Core::IOptionsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GerritOptionsPage(const QSharedPointer<GerritParameters> &p, QObject *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void settingsChanged();
|
||||
GerritOptionsPage(const QSharedPointer<GerritParameters> &p,
|
||||
const std::function<void()> &onChanged);
|
||||
};
|
||||
|
||||
} // Gerrit::Internal
|
||||
|
||||
@@ -156,13 +156,22 @@ GerritPlugin::GerritPlugin()
|
||||
: m_parameters(new GerritParameters)
|
||||
, m_server(new GerritServer)
|
||||
{
|
||||
m_parameters->fromSettings(ICore::settings());
|
||||
|
||||
m_gerritOptionsPage = new GerritOptionsPage(m_parameters,
|
||||
[this] {
|
||||
if (m_dialog)
|
||||
m_dialog->scheduleUpdateRemotes();
|
||||
});
|
||||
}
|
||||
|
||||
GerritPlugin::~GerritPlugin() = default;
|
||||
GerritPlugin::~GerritPlugin()
|
||||
{
|
||||
delete m_gerritOptionsPage;
|
||||
}
|
||||
|
||||
void GerritPlugin::addToMenu(ActionContainer *ac)
|
||||
{
|
||||
m_parameters->fromSettings(ICore::settings());
|
||||
|
||||
QAction *openViewAction = new QAction(Git::Tr::tr("Gerrit..."), this);
|
||||
|
||||
@@ -177,13 +186,6 @@ void GerritPlugin::addToMenu(ActionContainer *ac)
|
||||
ActionManager::registerAction(pushAction, Constants::GERRIT_PUSH);
|
||||
connect(pushAction, &QAction::triggered, this, [this] { push(); });
|
||||
ac->addAction(m_pushToGerritCommand);
|
||||
|
||||
auto options = new GerritOptionsPage(m_parameters, this);
|
||||
connect(options, &GerritOptionsPage::settingsChanged,
|
||||
this, [this] {
|
||||
if (m_dialog)
|
||||
m_dialog->scheduleUpdateRemotes();
|
||||
});
|
||||
}
|
||||
|
||||
void GerritPlugin::updateActions(const VcsBase::VcsBasePluginState &state)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
@@ -25,6 +25,7 @@ class GerritChange;
|
||||
class GerritDialog;
|
||||
class GerritParameters;
|
||||
class GerritServer;
|
||||
class GerritOptionsPage;
|
||||
|
||||
class GerritPlugin : public QObject
|
||||
{
|
||||
@@ -60,6 +61,7 @@ private:
|
||||
Core::Command *m_gerritCommand = nullptr;
|
||||
Core::Command *m_pushToGerritCommand = nullptr;
|
||||
QString m_reviewers;
|
||||
GerritOptionsPage *m_gerritOptionsPage = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user