forked from qt-creator/qt-creator
Axivion: Add possibility to add and remove configurations
Change-Id: I6748eef02e68de7714e94292826eb710b625efd3 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -231,9 +231,6 @@ void AxivionProjectSettingsWidget::linkProject()
|
|||||||
|
|
||||||
const QString projectName = selected.first()->text(0);
|
const QString projectName = selected.first()->text(0);
|
||||||
m_projectSettings->setDashboardProjectName(projectName);
|
m_projectSettings->setDashboardProjectName(projectName);
|
||||||
const Id serverId = settings().defaultDashboardId();
|
|
||||||
m_projectSettings->setDashboardId(serverId);
|
|
||||||
switchActiveDashboardId(serverId);
|
|
||||||
updateUi();
|
updateUi();
|
||||||
fetchProjectInfo(projectName);
|
fetchProjectInfo(projectName);
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
@@ -126,12 +127,13 @@ AxivionSettings::AxivionSettings()
|
|||||||
highlightMarks.setLabelText(Tr::tr("Highlight marks"));
|
highlightMarks.setLabelText(Tr::tr("Highlight marks"));
|
||||||
highlightMarks.setToolTip(Tr::tr("Marks issues on the scroll bar."));
|
highlightMarks.setToolTip(Tr::tr("Marks issues on the scroll bar."));
|
||||||
highlightMarks.setDefaultValue(false);
|
highlightMarks.setDefaultValue(false);
|
||||||
|
m_defaultServerId.setSettingsKey("DefaultDashboardId");
|
||||||
AspectContainer::readSettings();
|
AspectContainer::readSettings();
|
||||||
|
|
||||||
m_allServers = readTokenFile(tokensFilePath());
|
m_allServers = readTokenFile(tokensFilePath());
|
||||||
|
|
||||||
if (m_allServers.size() == 1 && !m_defaultServerId.isValid()) // handle settings transition
|
if (m_allServers.size() == 1 && m_defaultServerId().isEmpty()) // handle settings transition
|
||||||
m_defaultServerId = m_allServers.first().id;
|
m_defaultServerId.setValue(m_allServers.first().id.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxivionSettings::toSettings() const
|
void AxivionSettings::toSettings() const
|
||||||
@@ -142,7 +144,7 @@ void AxivionSettings::toSettings() const
|
|||||||
|
|
||||||
Id AxivionSettings::defaultDashboardId() const
|
Id AxivionSettings::defaultDashboardId() const
|
||||||
{
|
{
|
||||||
return m_defaultServerId;
|
return Id::fromString(m_defaultServerId());
|
||||||
}
|
}
|
||||||
|
|
||||||
const AxivionServer AxivionSettings::defaultServer() const
|
const AxivionServer AxivionSettings::defaultServer() const
|
||||||
@@ -173,10 +175,10 @@ void AxivionSettings::updateDashboardServers(const QList<AxivionServer> &other)
|
|||||||
if (m_allServers == other)
|
if (m_allServers == other)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!Utils::anyOf(other, [this](const AxivionServer &s) { return s.id == m_defaultServerId; })) {
|
const Id oldDefault = defaultDashboardId();
|
||||||
if (QTC_GUARD(!m_defaultServerId.isValid() && other.size() == 1))
|
if (!Utils::anyOf(other, [&oldDefault](const AxivionServer &s) { return s.id == oldDefault; }))
|
||||||
m_defaultServerId = other.first().id;
|
m_defaultServerId.setValue(other.isEmpty() ? QString{} : other.first().id.toString());
|
||||||
}
|
|
||||||
m_allServers = other;
|
m_allServers = other;
|
||||||
emit changed(); // should we be more detailed? (id)
|
emit changed(); // should we be more detailed? (id)
|
||||||
}
|
}
|
||||||
@@ -285,11 +287,14 @@ public:
|
|||||||
void apply() override;
|
void apply() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void showEditServerDialog();
|
void showServerDialog(bool add);
|
||||||
|
void removeCurrentServerConfig();
|
||||||
void updateDashboardServers();
|
void updateDashboardServers();
|
||||||
|
void updateEnabledStates();
|
||||||
|
|
||||||
QComboBox *m_dashboardServers = nullptr;
|
QComboBox *m_dashboardServers = nullptr;
|
||||||
QPushButton *m_edit = nullptr;
|
QPushButton *m_edit = nullptr;
|
||||||
|
QPushButton *m_remove = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
AxivionSettingsWidget::AxivionSettingsWidget()
|
AxivionSettingsWidget::AxivionSettingsWidget()
|
||||||
@@ -300,19 +305,30 @@ AxivionSettingsWidget::AxivionSettingsWidget()
|
|||||||
m_dashboardServers->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
m_dashboardServers->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||||
updateDashboardServers();
|
updateDashboardServers();
|
||||||
|
|
||||||
|
auto addButton = new QPushButton(Tr::tr("Add..."), this);
|
||||||
m_edit = new QPushButton(Tr::tr("Edit..."), this);
|
m_edit = new QPushButton(Tr::tr("Edit..."), this);
|
||||||
|
m_remove = new QPushButton(Tr::tr("Remove"), this);
|
||||||
Column {
|
Column {
|
||||||
Row {
|
Row {
|
||||||
Form {
|
Form {
|
||||||
Tr::tr("Default dashboard server"), m_dashboardServers, br
|
Tr::tr("Default dashboard server"), m_dashboardServers, br
|
||||||
}, st,
|
}, st,
|
||||||
Column { m_edit },
|
Column { addButton, m_edit, st, m_remove },
|
||||||
},
|
},
|
||||||
Space(10), br,
|
Space(10), br,
|
||||||
Row { settings().highlightMarks }, st
|
Row { settings().highlightMarks }, st
|
||||||
}.attachTo(this);
|
}.attachTo(this);
|
||||||
|
|
||||||
connect(m_edit, &QPushButton::clicked, this, &AxivionSettingsWidget::showEditServerDialog);
|
connect(addButton, &QPushButton::clicked, this, [this] {
|
||||||
|
// add an empty item unconditionally
|
||||||
|
m_dashboardServers->addItem(Tr::tr("unset"), QVariant::fromValue(AxivionServer()));
|
||||||
|
m_dashboardServers->setCurrentIndex(m_dashboardServers->count() - 1);
|
||||||
|
showServerDialog(true);
|
||||||
|
});
|
||||||
|
connect(m_edit, &QPushButton::clicked, this, [this] { showServerDialog(false); });
|
||||||
|
connect(m_remove, &QPushButton::clicked,
|
||||||
|
this, &AxivionSettingsWidget::removeCurrentServerConfig);
|
||||||
|
updateEnabledStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxivionSettingsWidget::apply()
|
void AxivionSettingsWidget::apply()
|
||||||
@@ -331,11 +347,32 @@ void AxivionSettingsWidget::updateDashboardServers()
|
|||||||
m_dashboardServers->addItem(server.displayString(), QVariant::fromValue(server));
|
m_dashboardServers->addItem(server.displayString(), QVariant::fromValue(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxivionSettingsWidget::showEditServerDialog()
|
void AxivionSettingsWidget::updateEnabledStates()
|
||||||
|
{
|
||||||
|
const bool enabled = m_dashboardServers->count();
|
||||||
|
m_edit->setEnabled(enabled);
|
||||||
|
m_remove->setEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AxivionSettingsWidget::removeCurrentServerConfig()
|
||||||
|
{
|
||||||
|
const QString config = m_dashboardServers->currentData().value<AxivionServer>().displayString();
|
||||||
|
if (QMessageBox::question(ICore::dialogParent(), Tr::tr("Remove Server Configuration"),
|
||||||
|
Tr::tr("Do you really want to remove the server configuration "
|
||||||
|
"\"%1\"?").arg(config))
|
||||||
|
!= QMessageBox::Yes) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_dashboardServers->removeItem(m_dashboardServers->currentIndex());
|
||||||
|
updateEnabledStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AxivionSettingsWidget::showServerDialog(bool add)
|
||||||
{
|
{
|
||||||
const AxivionServer old = m_dashboardServers->currentData().value<AxivionServer>();
|
const AxivionServer old = m_dashboardServers->currentData().value<AxivionServer>();
|
||||||
QDialog d;
|
QDialog d;
|
||||||
d.setWindowTitle(Tr::tr("Edit Dashboard Configuration"));
|
d.setWindowTitle(add ? Tr::tr("Add Dashboard Configuration")
|
||||||
|
: Tr::tr("Edit Dashboard Configuration"));
|
||||||
QVBoxLayout *layout = new QVBoxLayout;
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
auto buttons = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok, this);
|
auto buttons = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok, this);
|
||||||
auto ok = buttons->button(QDialogButtonBox::Ok);
|
auto ok = buttons->button(QDialogButtonBox::Ok);
|
||||||
@@ -349,21 +386,23 @@ void AxivionSettingsWidget::showEditServerDialog()
|
|||||||
d.setLayout(layout);
|
d.setLayout(layout);
|
||||||
d.resize(500, 200);
|
d.resize(500, 200);
|
||||||
|
|
||||||
if (d.exec() != QDialog::Accepted)
|
if (d.exec() != QDialog::Accepted) {
|
||||||
|
if (add) { // if we canceled an add, remove the canceled item
|
||||||
|
m_dashboardServers->removeItem(m_dashboardServers->currentIndex());
|
||||||
|
updateEnabledStates();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if (dashboardWidget->isValid()) {
|
if (dashboardWidget->isValid()) {
|
||||||
const AxivionServer server = dashboardWidget->dashboardServer();
|
const AxivionServer server = dashboardWidget->dashboardServer();
|
||||||
if (server != old) {
|
if (server != old) {
|
||||||
if (m_dashboardServers->currentIndex() == -1) { // temporary hack
|
m_dashboardServers->setItemData(m_dashboardServers->currentIndex(),
|
||||||
m_dashboardServers->addItem(server.displayString(), QVariant::fromValue(server));
|
QVariant::fromValue(server));
|
||||||
} else {
|
m_dashboardServers->setItemData(m_dashboardServers->currentIndex(),
|
||||||
m_dashboardServers->setItemData(m_dashboardServers->currentIndex(),
|
server.displayString(), Qt::DisplayRole);
|
||||||
QVariant::fromValue(server));
|
|
||||||
m_dashboardServers->setItemData(m_dashboardServers->currentIndex(),
|
|
||||||
server.displayString(), Qt::DisplayRole);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateEnabledStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
// AxivionSettingsPage
|
// AxivionSettingsPage
|
||||||
|
@@ -44,12 +44,12 @@ public:
|
|||||||
const AxivionServer defaultServer() const;
|
const AxivionServer defaultServer() const;
|
||||||
const AxivionServer serverForId(const Utils::Id &id) const;
|
const AxivionServer serverForId(const Utils::Id &id) const;
|
||||||
void disableCertificateValidation(const Utils::Id &id);
|
void disableCertificateValidation(const Utils::Id &id);
|
||||||
const QList<AxivionServer> allAvailableServers() const { return allServers; };
|
const QList<AxivionServer> allAvailableServers() const { return m_allServers; };
|
||||||
void updateDashboardServers(const QList<AxivionServer> &other);
|
void updateDashboardServers(const QList<AxivionServer> &other);
|
||||||
|
|
||||||
Utils::BoolAspect highlightMarks{this};
|
Utils::BoolAspect highlightMarks{this};
|
||||||
private:
|
private:
|
||||||
Utils::Id m_defaultServerId; // holds the current selected
|
Utils::StringAspect m_defaultServerId{this};
|
||||||
QList<AxivionServer> m_allServers;
|
QList<AxivionServer> m_allServers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user