forked from qt-creator/qt-creator
Git: Use IOptionPage::setWidgetCreator() for gerrit settings
Change-Id: I7402f3342bb11726ec7383c807fa98052cb38bd8 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -16,63 +16,28 @@
|
|||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
|
|
||||||
namespace Gerrit {
|
namespace Gerrit::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
GerritOptionsPage::GerritOptionsPage(const QSharedPointer<GerritParameters> &p,
|
class GerritOptionsWidget : public Core::IOptionsPageWidget
|
||||||
QObject *parent)
|
|
||||||
: Core::IOptionsPage(parent)
|
|
||||||
, m_parameters(p)
|
|
||||||
{
|
{
|
||||||
setId("Gerrit");
|
public:
|
||||||
setDisplayName(Git::Tr::tr("Gerrit"));
|
GerritOptionsWidget(GerritOptionsPage *page, const QSharedPointer<GerritParameters> &p)
|
||||||
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
: m_page(page)
|
||||||
}
|
|
||||||
|
|
||||||
GerritOptionsPage::~GerritOptionsPage()
|
|
||||||
{
|
|
||||||
delete m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *GerritOptionsPage::widget()
|
|
||||||
{
|
|
||||||
if (!m_widget) {
|
|
||||||
m_widget = new GerritOptionsWidget;
|
|
||||||
m_widget->setParameters(*m_parameters);
|
|
||||||
}
|
|
||||||
return m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GerritOptionsPage::apply()
|
|
||||||
{
|
|
||||||
if (GerritOptionsWidget *w = m_widget.data()) {
|
|
||||||
GerritParameters newParameters = w->parameters();
|
|
||||||
if (newParameters != *m_parameters) {
|
|
||||||
if (m_parameters->ssh == newParameters.ssh)
|
|
||||||
newParameters.portFlag = m_parameters->portFlag;
|
|
||||||
else
|
|
||||||
newParameters.setPortFlagBySshType();
|
|
||||||
*m_parameters = newParameters;
|
|
||||||
m_parameters->toSettings(Core::ICore::settings());
|
|
||||||
emit settingsChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GerritOptionsPage::finish()
|
|
||||||
{
|
|
||||||
delete m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
GerritOptionsWidget::GerritOptionsWidget(QWidget *parent)
|
|
||||||
: QWidget(parent)
|
|
||||||
, m_hostLineEdit(new QLineEdit(this))
|
, m_hostLineEdit(new QLineEdit(this))
|
||||||
, m_userLineEdit(new QLineEdit(this))
|
, m_userLineEdit(new QLineEdit(this))
|
||||||
, m_sshChooser(new Utils::PathChooser)
|
, m_sshChooser(new Utils::PathChooser)
|
||||||
, m_curlChooser(new Utils::PathChooser)
|
, m_curlChooser(new Utils::PathChooser)
|
||||||
, m_portSpinBox(new QSpinBox(this))
|
, m_portSpinBox(new QSpinBox(this))
|
||||||
, m_httpsCheckBox(new QCheckBox(Git::Tr::tr("HTTPS")))
|
, m_httpsCheckBox(new QCheckBox(Git::Tr::tr("HTTPS")))
|
||||||
{
|
, 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 formLayout = new QFormLayout(this);
|
auto formLayout = new QFormLayout(this);
|
||||||
formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
||||||
formLayout->addRow(Git::Tr::tr("&Host:"), m_hostLineEdit);
|
formLayout->addRow(Git::Tr::tr("&Host:"), m_hostLineEdit);
|
||||||
@@ -94,30 +59,52 @@ GerritOptionsWidget::GerritOptionsWidget(QWidget *parent)
|
|||||||
"\"gerrit.config\"."));
|
"\"gerrit.config\"."));
|
||||||
setTabOrder(m_sshChooser, m_curlChooser);
|
setTabOrder(m_sshChooser, m_curlChooser);
|
||||||
setTabOrder(m_curlChooser, m_portSpinBox);
|
setTabOrder(m_curlChooser, m_portSpinBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
GerritParameters GerritOptionsWidget::parameters() const
|
private:
|
||||||
|
void apply() final;
|
||||||
|
|
||||||
|
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()
|
||||||
{
|
{
|
||||||
GerritParameters result;
|
GerritParameters newParameters;
|
||||||
result.server = GerritServer(m_hostLineEdit->text().trimmed(),
|
newParameters.server = GerritServer(m_hostLineEdit->text().trimmed(),
|
||||||
static_cast<unsigned short>(m_portSpinBox->value()),
|
static_cast<unsigned short>(m_portSpinBox->value()),
|
||||||
m_userLineEdit->text().trimmed(),
|
m_userLineEdit->text().trimmed(),
|
||||||
GerritServer::Ssh);
|
GerritServer::Ssh);
|
||||||
result.ssh = m_sshChooser->filePath();
|
newParameters.ssh = m_sshChooser->filePath();
|
||||||
result.curl = m_curlChooser->filePath();
|
newParameters.curl = m_curlChooser->filePath();
|
||||||
result.https = m_httpsCheckBox->isChecked();
|
newParameters.https = m_httpsCheckBox->isChecked();
|
||||||
return result;
|
|
||||||
|
if (newParameters != *m_parameters) {
|
||||||
|
if (m_parameters->ssh == newParameters.ssh)
|
||||||
|
newParameters.portFlag = m_parameters->portFlag;
|
||||||
|
else
|
||||||
|
newParameters.setPortFlagBySshType();
|
||||||
|
*m_parameters = newParameters;
|
||||||
|
m_parameters->toSettings(Core::ICore::settings());
|
||||||
|
emit m_page->settingsChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GerritOptionsWidget::setParameters(const GerritParameters &p)
|
// GerritOptionsPage
|
||||||
|
|
||||||
|
GerritOptionsPage::GerritOptionsPage(const QSharedPointer<GerritParameters> &p, QObject *parent)
|
||||||
|
: Core::IOptionsPage(parent)
|
||||||
{
|
{
|
||||||
m_hostLineEdit->setText(p.server.host);
|
setId("Gerrit");
|
||||||
m_userLineEdit->setText(p.server.user.userName);
|
setDisplayName(Git::Tr::tr("Gerrit"));
|
||||||
m_sshChooser->setFilePath(p.ssh);
|
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
||||||
m_curlChooser->setFilePath(p.curl);
|
setWidgetCreator([this, p] { return new GerritOptionsWidget(this, p); });
|
||||||
m_portSpinBox->setValue(p.server.port);
|
|
||||||
m_httpsCheckBox->setChecked(p.https);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // Gerrit::Internal
|
||||||
} // namespace Gerrit
|
|
||||||
|
@@ -6,57 +6,20 @@
|
|||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QPointer>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
namespace Gerrit::Internal {
|
||||||
class QLineEdit;
|
|
||||||
class QSpinBox;
|
|
||||||
class QCheckBox;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace Utils { class PathChooser; }
|
|
||||||
namespace Gerrit {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class GerritParameters;
|
class GerritParameters;
|
||||||
|
|
||||||
class GerritOptionsWidget : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit GerritOptionsWidget(QWidget *parent = nullptr);
|
|
||||||
|
|
||||||
GerritParameters parameters() const;
|
|
||||||
void setParameters(const GerritParameters &);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QLineEdit *m_hostLineEdit;
|
|
||||||
QLineEdit *m_userLineEdit;
|
|
||||||
Utils::PathChooser *m_sshChooser;
|
|
||||||
Utils::PathChooser *m_curlChooser;
|
|
||||||
QSpinBox *m_portSpinBox;
|
|
||||||
QCheckBox *m_httpsCheckBox;
|
|
||||||
};
|
|
||||||
|
|
||||||
class GerritOptionsPage : public Core::IOptionsPage
|
class GerritOptionsPage : public Core::IOptionsPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GerritOptionsPage(const QSharedPointer<GerritParameters> &p, QObject *parent = nullptr);
|
GerritOptionsPage(const QSharedPointer<GerritParameters> &p, QObject *parent = nullptr);
|
||||||
~GerritOptionsPage() override;
|
|
||||||
|
|
||||||
QWidget *widget() override;
|
|
||||||
void apply() override;
|
|
||||||
void finish() override;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
|
|
||||||
private:
|
|
||||||
const QSharedPointer<GerritParameters> &m_parameters;
|
|
||||||
QPointer<GerritOptionsWidget> m_widget;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // Gerrit::Internal
|
||||||
} // namespace Gerrit
|
|
||||||
|
Reference in New Issue
Block a user