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 <QFormLayout>
|
||||
|
||||
namespace Gerrit {
|
||||
namespace Internal {
|
||||
namespace Gerrit::Internal {
|
||||
|
||||
GerritOptionsPage::GerritOptionsPage(const QSharedPointer<GerritParameters> &p,
|
||||
QObject *parent)
|
||||
: Core::IOptionsPage(parent)
|
||||
, m_parameters(p)
|
||||
class GerritOptionsWidget : public Core::IOptionsPageWidget
|
||||
{
|
||||
setId("Gerrit");
|
||||
setDisplayName(Git::Tr::tr("Gerrit"));
|
||||
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
||||
}
|
||||
|
||||
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)
|
||||
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)
|
||||
{
|
||||
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);
|
||||
formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
||||
formLayout->addRow(Git::Tr::tr("&Host:"), m_hostLineEdit);
|
||||
@@ -94,30 +59,52 @@ GerritOptionsWidget::GerritOptionsWidget(QWidget *parent)
|
||||
"\"gerrit.config\"."));
|
||||
setTabOrder(m_sshChooser, m_curlChooser);
|
||||
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;
|
||||
result.server = GerritServer(m_hostLineEdit->text().trimmed(),
|
||||
GerritParameters newParameters;
|
||||
newParameters.server = GerritServer(m_hostLineEdit->text().trimmed(),
|
||||
static_cast<unsigned short>(m_portSpinBox->value()),
|
||||
m_userLineEdit->text().trimmed(),
|
||||
GerritServer::Ssh);
|
||||
result.ssh = m_sshChooser->filePath();
|
||||
result.curl = m_curlChooser->filePath();
|
||||
result.https = m_httpsCheckBox->isChecked();
|
||||
return result;
|
||||
newParameters.ssh = m_sshChooser->filePath();
|
||||
newParameters.curl = m_curlChooser->filePath();
|
||||
newParameters.https = m_httpsCheckBox->isChecked();
|
||||
|
||||
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);
|
||||
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);
|
||||
setId("Gerrit");
|
||||
setDisplayName(Git::Tr::tr("Gerrit"));
|
||||
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
||||
setWidgetCreator([this, p] { return new GerritOptionsWidget(this, p); });
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Gerrit
|
||||
} // Gerrit::Internal
|
||||
|
@@ -6,57 +6,20 @@
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
|
||||
#include <QSharedPointer>
|
||||
#include <QPointer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QLineEdit;
|
||||
class QSpinBox;
|
||||
class QCheckBox;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils { class PathChooser; }
|
||||
namespace Gerrit {
|
||||
namespace Internal {
|
||||
namespace Gerrit::Internal {
|
||||
|
||||
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
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GerritOptionsPage(const QSharedPointer<GerritParameters> &p, QObject *parent = nullptr);
|
||||
~GerritOptionsPage() override;
|
||||
|
||||
QWidget *widget() override;
|
||||
void apply() override;
|
||||
void finish() override;
|
||||
|
||||
signals:
|
||||
void settingsChanged();
|
||||
|
||||
private:
|
||||
const QSharedPointer<GerritParameters> &m_parameters;
|
||||
QPointer<GerritOptionsWidget> m_widget;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Gerrit
|
||||
} // Gerrit::Internal
|
||||
|
Reference in New Issue
Block a user