forked from qt-creator/qt-creator
Gitlab: Use IOptionPage::setWidgetCreator() for settings
Change-Id: If5e0cead9092836f23bc8551bb0f1495fe41a400 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/aspects.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -44,6 +45,25 @@ static bool hostValid(const QString &host)
|
||||
return (host == "localhost") || dn.match(host).hasMatch();
|
||||
}
|
||||
|
||||
class GitLabServerWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
enum Mode { Display, Edit };
|
||||
explicit GitLabServerWidget(Mode m, QWidget *parent = nullptr);
|
||||
|
||||
GitLabServer gitLabServer() const;
|
||||
void setGitLabServer(const GitLabServer &server);
|
||||
|
||||
private:
|
||||
Mode m_mode = Display;
|
||||
Id m_id;
|
||||
StringAspect m_host;
|
||||
StringAspect m_description;
|
||||
StringAspect m_token;
|
||||
IntegerAspect m_port;
|
||||
BoolAspect m_secure;
|
||||
};
|
||||
|
||||
GitLabServerWidget::GitLabServerWidget(Mode m, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_mode(m)
|
||||
@@ -108,8 +128,43 @@ void GitLabServerWidget::setGitLabServer(const GitLabServer &server)
|
||||
m_secure.setValue(server.secure);
|
||||
}
|
||||
|
||||
GitLabOptionsWidget::GitLabOptionsWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
class GitLabOptionsWidget : public Core::IOptionsPageWidget
|
||||
{
|
||||
public:
|
||||
explicit GitLabOptionsWidget(GitLabOptionsPage *page, GitLabParameters *parameters);
|
||||
|
||||
GitLabParameters parameters() const;
|
||||
|
||||
void apply() final
|
||||
{
|
||||
GitLabParameters newParameters = parameters();
|
||||
if (newParameters != *m_parameters) {
|
||||
*m_parameters = newParameters;
|
||||
m_parameters->toSettings(Core::ICore::settings());
|
||||
emit m_page->settingsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void showEditServerDialog();
|
||||
void showAddServerDialog();
|
||||
void removeCurrentTriggered();
|
||||
void addServer(const GitLabServer &newServer);
|
||||
void modifyCurrentServer(const GitLabServer &newServer);
|
||||
void updateButtonsState();
|
||||
|
||||
GitLabOptionsPage *m_page = nullptr;
|
||||
GitLabParameters *m_parameters = nullptr;
|
||||
GitLabServerWidget *m_gitLabServerWidget = nullptr;
|
||||
QPushButton *m_edit = nullptr;
|
||||
QPushButton *m_remove = nullptr;
|
||||
QPushButton *m_add = nullptr;
|
||||
QComboBox *m_defaultGitLabServer = nullptr;
|
||||
Utils::StringAspect m_curl;
|
||||
};
|
||||
|
||||
GitLabOptionsWidget::GitLabOptionsWidget(GitLabOptionsPage *page, GitLabParameters *params)
|
||||
: m_page(page), m_parameters(params)
|
||||
{
|
||||
auto defaultLabel = new QLabel(Tr::tr("Default:"), this);
|
||||
m_defaultGitLabServer = new QComboBox(this);
|
||||
@@ -136,6 +191,20 @@ GitLabOptionsWidget::GitLabOptionsWidget(QWidget *parent)
|
||||
}, Column { m_add, m_edit, m_remove, st },
|
||||
}.attachTo(this);
|
||||
|
||||
m_curl.setFilePath(params->curl);
|
||||
|
||||
for (const auto &gitLabServer : params->gitLabServers) {
|
||||
m_defaultGitLabServer->addItem(gitLabServer.displayString(),
|
||||
QVariant::fromValue(gitLabServer));
|
||||
}
|
||||
|
||||
const GitLabServer found = params->currentDefaultServer();
|
||||
if (found.id.isValid()) {
|
||||
m_defaultGitLabServer->setCurrentIndex(m_defaultGitLabServer->findData(
|
||||
QVariant::fromValue(found)));
|
||||
}
|
||||
updateButtonsState();
|
||||
|
||||
connect(m_edit, &QPushButton::clicked, this, &GitLabOptionsWidget::showEditServerDialog);
|
||||
connect(m_remove, &QPushButton::clicked, this, &GitLabOptionsWidget::removeCurrentTriggered);
|
||||
connect(m_add, &QPushButton::clicked, this, &GitLabOptionsWidget::showAddServerDialog);
|
||||
@@ -157,23 +226,6 @@ GitLabParameters GitLabOptionsWidget::parameters() const
|
||||
return result;
|
||||
}
|
||||
|
||||
void GitLabOptionsWidget::setParameters(const GitLabParameters ¶ms)
|
||||
{
|
||||
m_curl.setFilePath(params.curl);
|
||||
|
||||
for (const auto &gitLabServer : params.gitLabServers) {
|
||||
m_defaultGitLabServer->addItem(gitLabServer.displayString(),
|
||||
QVariant::fromValue(gitLabServer));
|
||||
}
|
||||
|
||||
const GitLabServer found = params.currentDefaultServer();
|
||||
if (found.id.isValid()) {
|
||||
m_defaultGitLabServer->setCurrentIndex(m_defaultGitLabServer->findData(
|
||||
QVariant::fromValue(found)));
|
||||
}
|
||||
updateButtonsState();
|
||||
}
|
||||
|
||||
void GitLabOptionsWidget::showEditServerDialog()
|
||||
{
|
||||
const GitLabServer old = m_defaultGitLabServer->currentData().value<GitLabServer>();
|
||||
@@ -253,39 +305,14 @@ void GitLabOptionsWidget::updateButtonsState()
|
||||
m_remove->setEnabled(hasItems);
|
||||
}
|
||||
|
||||
GitLabOptionsPage::GitLabOptionsPage(GitLabParameters *p, QObject *parent)
|
||||
: Core::IOptionsPage{parent}
|
||||
, m_parameters(p)
|
||||
// GitLabOptionsPage
|
||||
|
||||
GitLabOptionsPage::GitLabOptionsPage(GitLabParameters *p)
|
||||
{
|
||||
setId(Constants::GITLAB_SETTINGS);
|
||||
setDisplayName(Tr::tr("GitLab"));
|
||||
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
||||
}
|
||||
|
||||
QWidget *GitLabOptionsPage::widget()
|
||||
{
|
||||
if (!m_widget) {
|
||||
m_widget = new GitLabOptionsWidget;
|
||||
m_widget->setParameters(*m_parameters);
|
||||
}
|
||||
return m_widget;
|
||||
}
|
||||
|
||||
void GitLabOptionsPage::apply()
|
||||
{
|
||||
if (GitLabOptionsWidget *w = m_widget.data()) {
|
||||
GitLabParameters newParameters = w->parameters();
|
||||
if (newParameters != *m_parameters) {
|
||||
*m_parameters = newParameters;
|
||||
m_parameters->toSettings(Core::ICore::settings());
|
||||
emit settingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GitLabOptionsPage::finish()
|
||||
{
|
||||
delete m_widget;
|
||||
setWidgetCreator([this, p] { return new GitLabOptionsWidget(this, p); });
|
||||
}
|
||||
|
||||
} // namespace GitLab
|
||||
|
@@ -6,84 +6,20 @@
|
||||
#include "gitlabparameters.h"
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
#include <utils/aspects.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QComboBox;
|
||||
class QPushButton;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace GitLab {
|
||||
|
||||
namespace Constants {
|
||||
const char GITLAB_SETTINGS[] = "GitLab";
|
||||
} // namespace Constants
|
||||
|
||||
class GitLabServerWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
enum Mode { Display, Edit };
|
||||
explicit GitLabServerWidget(Mode m, QWidget *parent = nullptr);
|
||||
|
||||
GitLabServer gitLabServer() const;
|
||||
void setGitLabServer(const GitLabServer &server);
|
||||
|
||||
bool isValid() const;
|
||||
private:
|
||||
Mode m_mode = Display;
|
||||
Utils::Id m_id;
|
||||
Utils::StringAspect m_host;
|
||||
Utils::StringAspect m_description;
|
||||
Utils::StringAspect m_token;
|
||||
Utils::IntegerAspect m_port;
|
||||
Utils::BoolAspect m_secure;
|
||||
};
|
||||
|
||||
class GitLabOptionsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GitLabOptionsWidget(QWidget *parent = nullptr);
|
||||
|
||||
GitLabParameters parameters() const;
|
||||
void setParameters(const GitLabParameters ¶ms);
|
||||
|
||||
private:
|
||||
void showEditServerDialog();
|
||||
void showAddServerDialog();
|
||||
void removeCurrentTriggered();
|
||||
void addServer(const GitLabServer &newServer);
|
||||
void modifyCurrentServer(const GitLabServer &newServer);
|
||||
void updateButtonsState();
|
||||
|
||||
GitLabServerWidget *m_gitLabServerWidget = nullptr;
|
||||
QPushButton *m_edit = nullptr;
|
||||
QPushButton *m_remove = nullptr;
|
||||
QPushButton *m_add = nullptr;
|
||||
QComboBox *m_defaultGitLabServer = nullptr;
|
||||
Utils::StringAspect m_curl;
|
||||
};
|
||||
namespace Constants { const char GITLAB_SETTINGS[] = "GitLab"; }
|
||||
|
||||
class GitLabOptionsPage : public Core::IOptionsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GitLabOptionsPage(GitLabParameters *p, QObject *parent = nullptr);
|
||||
|
||||
QWidget *widget() final;
|
||||
void apply() final;
|
||||
void finish() final;
|
||||
public:
|
||||
explicit GitLabOptionsPage(GitLabParameters *p);
|
||||
|
||||
signals:
|
||||
void settingsChanged();
|
||||
|
||||
private:
|
||||
void addServer();
|
||||
|
||||
GitLabParameters *m_parameters;
|
||||
QPointer<GitLabOptionsWidget> m_widget;
|
||||
};
|
||||
|
||||
} // namespace GitLab
|
||||
} // GitLab
|
||||
|
Reference in New Issue
Block a user