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 <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/aspects.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
@@ -44,6 +45,25 @@ static bool hostValid(const QString &host)
|
|||||||
return (host == "localhost") || dn.match(host).hasMatch();
|
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)
|
GitLabServerWidget::GitLabServerWidget(Mode m, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_mode(m)
|
, m_mode(m)
|
||||||
@@ -108,8 +128,43 @@ void GitLabServerWidget::setGitLabServer(const GitLabServer &server)
|
|||||||
m_secure.setValue(server.secure);
|
m_secure.setValue(server.secure);
|
||||||
}
|
}
|
||||||
|
|
||||||
GitLabOptionsWidget::GitLabOptionsWidget(QWidget *parent)
|
class GitLabOptionsWidget : public Core::IOptionsPageWidget
|
||||||
: QWidget(parent)
|
{
|
||||||
|
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);
|
auto defaultLabel = new QLabel(Tr::tr("Default:"), this);
|
||||||
m_defaultGitLabServer = new QComboBox(this);
|
m_defaultGitLabServer = new QComboBox(this);
|
||||||
@@ -136,6 +191,20 @@ GitLabOptionsWidget::GitLabOptionsWidget(QWidget *parent)
|
|||||||
}, Column { m_add, m_edit, m_remove, st },
|
}, Column { m_add, m_edit, m_remove, st },
|
||||||
}.attachTo(this);
|
}.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_edit, &QPushButton::clicked, this, &GitLabOptionsWidget::showEditServerDialog);
|
||||||
connect(m_remove, &QPushButton::clicked, this, &GitLabOptionsWidget::removeCurrentTriggered);
|
connect(m_remove, &QPushButton::clicked, this, &GitLabOptionsWidget::removeCurrentTriggered);
|
||||||
connect(m_add, &QPushButton::clicked, this, &GitLabOptionsWidget::showAddServerDialog);
|
connect(m_add, &QPushButton::clicked, this, &GitLabOptionsWidget::showAddServerDialog);
|
||||||
@@ -157,23 +226,6 @@ GitLabParameters GitLabOptionsWidget::parameters() const
|
|||||||
return result;
|
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()
|
void GitLabOptionsWidget::showEditServerDialog()
|
||||||
{
|
{
|
||||||
const GitLabServer old = m_defaultGitLabServer->currentData().value<GitLabServer>();
|
const GitLabServer old = m_defaultGitLabServer->currentData().value<GitLabServer>();
|
||||||
@@ -253,39 +305,14 @@ void GitLabOptionsWidget::updateButtonsState()
|
|||||||
m_remove->setEnabled(hasItems);
|
m_remove->setEnabled(hasItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
GitLabOptionsPage::GitLabOptionsPage(GitLabParameters *p, QObject *parent)
|
// GitLabOptionsPage
|
||||||
: Core::IOptionsPage{parent}
|
|
||||||
, m_parameters(p)
|
GitLabOptionsPage::GitLabOptionsPage(GitLabParameters *p)
|
||||||
{
|
{
|
||||||
setId(Constants::GITLAB_SETTINGS);
|
setId(Constants::GITLAB_SETTINGS);
|
||||||
setDisplayName(Tr::tr("GitLab"));
|
setDisplayName(Tr::tr("GitLab"));
|
||||||
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
||||||
}
|
setWidgetCreator([this, p] { return new GitLabOptionsWidget(this, p); });
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace GitLab
|
} // namespace GitLab
|
||||||
|
@@ -6,84 +6,20 @@
|
|||||||
#include "gitlabparameters.h"
|
#include "gitlabparameters.h"
|
||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.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 GitLab {
|
||||||
|
|
||||||
namespace Constants {
|
namespace Constants { const char GITLAB_SETTINGS[] = "GitLab"; }
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
class GitLabOptionsPage : public Core::IOptionsPage
|
class GitLabOptionsPage : public Core::IOptionsPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
|
||||||
explicit GitLabOptionsPage(GitLabParameters *p, QObject *parent = nullptr);
|
|
||||||
|
|
||||||
QWidget *widget() final;
|
public:
|
||||||
void apply() final;
|
explicit GitLabOptionsPage(GitLabParameters *p);
|
||||||
void finish() final;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
|
|
||||||
private:
|
|
||||||
void addServer();
|
|
||||||
|
|
||||||
GitLabParameters *m_parameters;
|
|
||||||
QPointer<GitLabOptionsWidget> m_widget;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GitLab
|
} // GitLab
|
||||||
|
Reference in New Issue
Block a user