forked from qt-creator/qt-creator
GitLab: Shift responsibility to signal changes
... from the option pasge (factory) to the settings (storage). This will help with removing the QObject base from IOptionPage Change-Id: I04a6b499bdca6065bf8f742b4624beabe7d8f8cc Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -132,7 +132,7 @@ void GitLabServerWidget::setGitLabServer(const GitLabServer &server)
|
||||
class GitLabOptionsWidget : public Core::IOptionsPageWidget
|
||||
{
|
||||
public:
|
||||
explicit GitLabOptionsWidget(GitLabOptionsPage *page, GitLabParameters *parameters);
|
||||
explicit GitLabOptionsWidget(GitLabParameters *parameters);
|
||||
|
||||
private:
|
||||
void showEditServerDialog();
|
||||
@@ -151,7 +151,7 @@ private:
|
||||
Utils::StringAspect m_curl;
|
||||
};
|
||||
|
||||
GitLabOptionsWidget::GitLabOptionsWidget(GitLabOptionsPage *page, GitLabParameters *params)
|
||||
GitLabOptionsWidget::GitLabOptionsWidget(GitLabParameters *params)
|
||||
: m_parameters(params)
|
||||
{
|
||||
auto defaultLabel = new QLabel(Tr::tr("Default:"), this);
|
||||
@@ -201,7 +201,7 @@ GitLabOptionsWidget::GitLabOptionsWidget(GitLabOptionsPage *page, GitLabParamete
|
||||
m_defaultGitLabServer->currentData().value<GitLabServer>());
|
||||
});
|
||||
|
||||
setOnApply([page, this] {
|
||||
setOnApply([this] {
|
||||
GitLabParameters result;
|
||||
// get all configured gitlabservers
|
||||
for (int i = 0, end = m_defaultGitLabServer->count(); i < end; ++i)
|
||||
@@ -211,9 +211,9 @@ GitLabOptionsWidget::GitLabOptionsWidget(GitLabOptionsPage *page, GitLabParamete
|
||||
result.curl = m_curl.filePath();
|
||||
|
||||
if (result != *m_parameters) {
|
||||
*m_parameters = result;
|
||||
m_parameters->assign(result);
|
||||
m_parameters->toSettings(Core::ICore::settings());
|
||||
emit page->settingsChanged();
|
||||
emit m_parameters->changed();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -304,7 +304,7 @@ GitLabOptionsPage::GitLabOptionsPage(GitLabParameters *p)
|
||||
setId(Constants::GITLAB_SETTINGS);
|
||||
setDisplayName(Tr::tr("GitLab"));
|
||||
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
||||
setWidgetCreator([this, p] { return new GitLabOptionsWidget(this, p); });
|
||||
setWidgetCreator([p] { return new GitLabOptionsWidget(p); });
|
||||
}
|
||||
|
||||
} // namespace GitLab
|
||||
|
||||
@@ -13,13 +13,8 @@ namespace Constants { const char GITLAB_SETTINGS[] = "GitLab"; }
|
||||
|
||||
class GitLabOptionsPage : public Core::IOptionsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GitLabOptionsPage(GitLabParameters *p);
|
||||
|
||||
signals:
|
||||
void settingsChanged();
|
||||
};
|
||||
|
||||
} // GitLab
|
||||
|
||||
@@ -102,6 +102,13 @@ GitLabParameters::GitLabParameters()
|
||||
{
|
||||
}
|
||||
|
||||
void GitLabParameters::assign(const GitLabParameters &other)
|
||||
{
|
||||
curl = other.curl;
|
||||
defaultGitLabServer = other.defaultGitLabServer;
|
||||
gitLabServers = other.gitLabServers;
|
||||
}
|
||||
|
||||
bool GitLabParameters::equals(const GitLabParameters &other) const
|
||||
{
|
||||
return curl == other.curl && defaultGitLabServer == other.defaultGitLabServer
|
||||
|
||||
@@ -38,11 +38,14 @@ public:
|
||||
bool validateCert = true;
|
||||
};
|
||||
|
||||
class GitLabParameters
|
||||
class GitLabParameters : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GitLabParameters();
|
||||
|
||||
void assign(const GitLabParameters &other);
|
||||
bool equals(const GitLabParameters &other) const;
|
||||
bool isValid() const;
|
||||
|
||||
@@ -52,6 +55,10 @@ public:
|
||||
GitLabServer currentDefaultServer() const;
|
||||
GitLabServer serverForId(const Utils::Id &id) const;
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
public:
|
||||
friend bool operator==(const GitLabParameters &p1, const GitLabParameters &p2)
|
||||
{
|
||||
return p1.equals(p2);
|
||||
|
||||
@@ -38,6 +38,18 @@ const char GITLAB_OPEN_VIEW[] = "GitLab.OpenView";
|
||||
class GitLabPluginPrivate : public QObject
|
||||
{
|
||||
public:
|
||||
void setupNotificationTimer();
|
||||
void fetchEvents();
|
||||
void fetchUser();
|
||||
void createAndSendEventsRequest(const QDateTime timeStamp, int page = -1);
|
||||
void handleUser(const User &user);
|
||||
void handleEvents(const Events &events, const QDateTime &timeStamp);
|
||||
|
||||
void onSettingsChanged() {
|
||||
if (dialog)
|
||||
dialog->updateRemotes();
|
||||
}
|
||||
|
||||
GitLabParameters parameters;
|
||||
GitLabOptionsPage optionsPage{¶meters};
|
||||
QHash<ProjectExplorer::Project *, GitLabProjectSettings *> projectSettings;
|
||||
@@ -47,13 +59,6 @@ public:
|
||||
QString projectName;
|
||||
Utils::Id serverId;
|
||||
bool runningQuery = false;
|
||||
|
||||
void setupNotificationTimer();
|
||||
void fetchEvents();
|
||||
void fetchUser();
|
||||
void createAndSendEventsRequest(const QDateTime timeStamp, int page = -1);
|
||||
void handleUser(const User &user);
|
||||
void handleEvents(const Events &events, const QDateTime &timeStamp);
|
||||
};
|
||||
|
||||
static GitLabPluginPrivate *dd = nullptr;
|
||||
@@ -89,10 +94,6 @@ void GitLabPlugin::initialize()
|
||||
connect(openViewAction, &QAction::triggered, this, &GitLabPlugin::openView);
|
||||
Core::ActionContainer *ac = Core::ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
||||
ac->addAction(gitlabCommand);
|
||||
connect(&dd->optionsPage, &GitLabOptionsPage::settingsChanged, this, [] {
|
||||
if (dd->dialog)
|
||||
dd->dialog->updateRemotes();
|
||||
});
|
||||
connect(ProjectExplorer::ProjectManager::instance(),
|
||||
&ProjectExplorer::ProjectManager::startupProjectChanged,
|
||||
this, &GitLabPlugin::onStartupProjectChanged);
|
||||
@@ -305,7 +306,7 @@ bool GitLabPlugin::handleCertificateIssue(const Utils::Id &serverId)
|
||||
int index = dd->parameters.gitLabServers.indexOf(server);
|
||||
server.validateCert = false;
|
||||
dd->parameters.gitLabServers.replace(index, server);
|
||||
emit dd->optionsPage.settingsChanged();
|
||||
dd->onSettingsChanged();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -157,7 +157,7 @@ GitLabProjectSettingsWidget::GitLabProjectSettingsWidget(ProjectExplorer::Projec
|
||||
connect(m_hostCB, &QComboBox::currentIndexChanged, this, [this] {
|
||||
m_infoLabel->setVisible(false);
|
||||
});
|
||||
connect(GitLabPlugin::optionsPage(), &GitLabOptionsPage::settingsChanged,
|
||||
connect(GitLabPlugin::globalParameters(), &GitLabParameters::changed,
|
||||
this, &GitLabProjectSettingsWidget::updateUi);
|
||||
updateUi();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user