Axivion: Merge Axivion settings tabs and place it under Analyzer

Change-Id: I637309b6c49488a52ef72ca8ab31b330222cb840
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Jarek Kobus
2024-11-26 09:01:40 +01:00
parent 59635ee0e8
commit 23cf6a8382

View File

@@ -429,144 +429,6 @@ bool DashboardSettingsWidget::isValid() const
return isUrlValid(m_dashboardUrl()); return isUrlValid(m_dashboardUrl());
} }
class AxivionSettingsWidget : public IOptionsPageWidget
{
public:
AxivionSettingsWidget();
void apply() override;
private:
void showServerDialog(bool add);
void removeCurrentServerConfig();
void updateDashboardServers();
void updateEnabledStates();
QComboBox *m_dashboardServers = nullptr;
QPushButton *m_edit = nullptr;
QPushButton *m_remove = nullptr;
};
AxivionSettingsWidget::AxivionSettingsWidget()
{
using namespace Layouting;
m_dashboardServers = new QComboBox(this);
m_dashboardServers->setSizeAdjustPolicy(QComboBox::AdjustToContents);
updateDashboardServers();
auto addButton = new QPushButton(Tr::tr("Add..."), this);
m_edit = new QPushButton(Tr::tr("Edit..."), this);
m_remove = new QPushButton(Tr::tr("Remove"), this);
Column {
Row {
Form { Tr::tr("Default dashboard server:"), m_dashboardServers, br },
st,
Column { addButton, m_edit, st, m_remove },
},
Space(10),
br,
Row {settings().highlightMarks },
st
}.attachTo(this);
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()
{
QList<AxivionServer> servers;
for (int i = 0, end = m_dashboardServers->count(); i < end; ++i)
servers.append(m_dashboardServers->itemData(i).value<AxivionServer>());
const Id selected = servers.isEmpty() ? Id{}
: servers.at(m_dashboardServers->currentIndex()).id;
if (settings().updateDashboardServers(servers, selected))
settings().toSettings();
settings().apply();
}
void AxivionSettingsWidget::updateDashboardServers()
{
m_dashboardServers->clear();
const QList<AxivionServer> servers = settings().allAvailableServers();
for (const AxivionServer &server : servers)
m_dashboardServers->addItem(server.displayString(), QVariant::fromValue(server));
int index = Utils::indexOf(servers,
[id = settings().defaultDashboardId()](const AxivionServer &s) {
return id == s.id;
});
if (index != -1)
m_dashboardServers->setCurrentIndex(index);
}
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("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>();
QDialog d;
d.setWindowTitle(add ? Tr::tr("Add Dashboard Configuration")
: Tr::tr("Edit Dashboard Configuration"));
QVBoxLayout *layout = new QVBoxLayout;
auto buttons = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok, this);
auto ok = buttons->button(QDialogButtonBox::Ok);
auto dashboardWidget = new DashboardSettingsWidget(this, ok);
dashboardWidget->setDashboardServer(old);
layout->addWidget(dashboardWidget);
ok->setEnabled(dashboardWidget->isValid());
connect(buttons->button(QDialogButtonBox::Cancel), &QPushButton::clicked, &d, &QDialog::reject);
connect(ok, &QPushButton::clicked, &d, &QDialog::accept);
layout->addWidget(buttons);
d.setLayout(layout);
d.resize(500, 200);
if (d.exec() != QDialog::Accepted) {
if (add) { // if we canceled an add, remove the canceled item
m_dashboardServers->removeItem(m_dashboardServers->currentIndex());
updateEnabledStates();
}
return;
}
if (dashboardWidget->isValid()) {
const AxivionServer server = dashboardWidget->dashboardServer();
if (server != old) {
m_dashboardServers->setItemData(m_dashboardServers->currentIndex(),
QVariant::fromValue(server));
m_dashboardServers->setItemData(m_dashboardServers->currentIndex(),
server.displayString(), Qt::DisplayRole);
}
}
updateEnabledStates();
}
// PathMappingSettingsWidget // PathMappingSettingsWidget
class PathMappingDetails : public AspectContainer class PathMappingDetails : public AspectContainer
@@ -626,30 +488,47 @@ private:
FilePathAspect m_localPath{this}; FilePathAspect m_localPath{this};
}; };
class PathMappingSettingsWidget final : public IOptionsPageWidget class AxivionSettingsWidget : public IOptionsPageWidget
{ {
public: public:
PathMappingSettingsWidget(); AxivionSettingsWidget();
void apply() final; void apply() override;
private: private:
void showServerDialog(bool add);
void removeCurrentServerConfig();
void updateDashboardServers();
void updateEnabledStates();
void addMapping(); void addMapping();
void deleteMapping(); void deleteMapping();
void mappingChanged(); void mappingChanged();
void currentChanged(const QModelIndex &index, const QModelIndex &previous); void currentChanged(const QModelIndex &index, const QModelIndex &previous);
void moveCurrent(bool up); void moveCurrentMapping(bool up);
QComboBox *m_dashboardServers = nullptr;
QPushButton *m_editServerButton = nullptr;
QPushButton *m_removeServerButton = nullptr;
QTreeWidget m_mappingTree; QTreeWidget m_mappingTree;
PathMappingDetails m_details; PathMappingDetails m_details;
QWidget *m_detailsWidget = nullptr; QWidget *m_detailsWidget = nullptr;
QPushButton *m_deleteButton = nullptr; QPushButton *m_deleteMappingButton = nullptr;
QPushButton *m_moveUp = nullptr; QPushButton *m_moveUpMappingButton = nullptr;
QPushButton *m_moveDown = nullptr; QPushButton *m_moveDownMappingButton = nullptr;
}; };
PathMappingSettingsWidget::PathMappingSettingsWidget() AxivionSettingsWidget::AxivionSettingsWidget()
{ {
using namespace Layouting;
m_dashboardServers = new QComboBox(this);
m_dashboardServers->setSizeAdjustPolicy(QComboBox::AdjustToContents);
updateDashboardServers();
auto addServerButton = new QPushButton(Tr::tr("Add..."), this);
m_editServerButton = new QPushButton(Tr::tr("Edit..."), this);
m_removeServerButton = new QPushButton(Tr::tr("Remove"), this);
m_detailsWidget = new QWidget(this); m_detailsWidget = new QWidget(this);
m_details.layouter()().attachTo(m_detailsWidget); m_details.layouter()().attachTo(m_detailsWidget);
@@ -658,19 +537,46 @@ PathMappingSettingsWidget::PathMappingSettingsWidget()
m_mappingTree.setHeaderLabels({Tr::tr("Project Name"), Tr::tr("Analysis Path"), m_mappingTree.setHeaderLabels({Tr::tr("Project Name"), Tr::tr("Analysis Path"),
Tr::tr("Local Path")}); Tr::tr("Local Path")});
auto addButton = new QPushButton(Tr::tr("Add"), this); auto addMappingButton = new QPushButton(Tr::tr("Add"), this);
m_deleteButton = new QPushButton(Tr::tr("Delete"), this); m_deleteMappingButton = new QPushButton(Tr::tr("Delete"), this);
m_moveUp = new QPushButton(Tr::tr("Move Up"), this); m_moveUpMappingButton = new QPushButton(Tr::tr("Move Up"), this);
m_moveDown = new QPushButton(Tr::tr("Move Down"), this); m_moveDownMappingButton = new QPushButton(Tr::tr("Move Down"), this);
using namespace Layouting; Column buttons { addMappingButton, m_deleteMappingButton, empty, m_moveUpMappingButton, m_moveDownMappingButton, st };
Column buttons { addButton, m_deleteButton, empty, m_moveUp, m_moveDown, st };
Column {
Layouting::Group {
title(Tr::tr("Dashboard Servers")),
Row {
Form { Tr::tr("Default dashboard server:"), m_dashboardServers, br },
st,
Column { addServerButton, m_editServerButton, m_removeServerButton },
},
},
Layouting::Group {
title(Tr::tr("Path Mapping")),
Column { Column {
Row { &m_mappingTree, buttons }, Row { &m_mappingTree, buttons },
m_detailsWidget m_detailsWidget
}
},
Layouting::Group {
title(Tr::tr("Misc Options")),
Row {settings().highlightMarks },
},
st
}.attachTo(this); }.attachTo(this);
connect(addServerButton, &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_editServerButton, &QPushButton::clicked, this, [this] { showServerDialog(false); });
connect(m_removeServerButton, &QPushButton::clicked,
this, &AxivionSettingsWidget::removeCurrentServerConfig);
const QList<QTreeWidgetItem *> items = Utils::transform(pathMappingSettings().validPathMappings(), const QList<QTreeWidgetItem *> items = Utils::transform(pathMappingSettings().validPathMappings(),
[this](const PathMapping &m) { [this](const PathMapping &m) {
QTreeWidgetItem *item = new QTreeWidgetItem(&m_mappingTree, QTreeWidgetItem *item = new QTreeWidgetItem(&m_mappingTree,
@@ -683,24 +589,35 @@ PathMappingSettingsWidget::PathMappingSettingsWidget()
}); });
m_mappingTree.addTopLevelItems(items); m_mappingTree.addTopLevelItems(items);
m_deleteButton->setEnabled(false); m_deleteMappingButton->setEnabled(false);
m_moveUp->setEnabled(false); m_moveUpMappingButton->setEnabled(false);
m_moveDown->setEnabled(false); m_moveDownMappingButton->setEnabled(false);
m_detailsWidget->setVisible(false); m_detailsWidget->setVisible(false);
connect(addButton, &QPushButton::clicked, this, &PathMappingSettingsWidget::addMapping); connect(addMappingButton, &QPushButton::clicked, this, &AxivionSettingsWidget::addMapping);
connect(m_deleteButton, &QPushButton::clicked, this, &PathMappingSettingsWidget::deleteMapping); connect(m_deleteMappingButton, &QPushButton::clicked, this, &AxivionSettingsWidget::deleteMapping);
connect(m_moveUp, &QPushButton::clicked, this, [this]{ moveCurrent(true); }); connect(m_moveUpMappingButton, &QPushButton::clicked, this, [this]{ moveCurrentMapping(true); });
connect(m_moveDown, &QPushButton::clicked, this, [this]{ moveCurrent(false); }); connect(m_moveDownMappingButton, &QPushButton::clicked, this, [this]{ moveCurrentMapping(false); });
connect(m_mappingTree.selectionModel(), &QItemSelectionModel::currentChanged, connect(m_mappingTree.selectionModel(), &QItemSelectionModel::currentChanged,
this, &PathMappingSettingsWidget::currentChanged); this, &AxivionSettingsWidget::currentChanged);
connect(&m_details, &AspectContainer::changed, this, connect(&m_details, &AspectContainer::changed, this,
&PathMappingSettingsWidget::mappingChanged); &AxivionSettingsWidget::mappingChanged);
updateEnabledStates();
} }
void PathMappingSettingsWidget::apply() void AxivionSettingsWidget::apply()
{ {
QList<AxivionServer> servers;
for (int i = 0, end = m_dashboardServers->count(); i < end; ++i)
servers.append(m_dashboardServers->itemData(i).value<AxivionServer>());
const Id selected = servers.isEmpty() ? Id{}
: servers.at(m_dashboardServers->currentIndex()).id;
if (settings().updateDashboardServers(servers, selected))
settings().toSettings();
settings().apply();
const QList<PathMapping> oldMappings = settings().validPathMappings(); const QList<PathMapping> oldMappings = settings().validPathMappings();
QList<PathMapping> newMappings; QList<PathMapping> newMappings;
for (int row = 0, count = m_mappingTree.topLevelItemCount(); row < count; ++row) { for (int row = 0, count = m_mappingTree.topLevelItemCount(); row < count; ++row) {
@@ -716,14 +633,87 @@ void PathMappingSettingsWidget::apply()
pathMappingSettings().writeSettings(); pathMappingSettings().writeSettings();
} }
void PathMappingSettingsWidget::addMapping() void AxivionSettingsWidget::updateDashboardServers()
{
m_dashboardServers->clear();
const QList<AxivionServer> servers = settings().allAvailableServers();
for (const AxivionServer &server : servers)
m_dashboardServers->addItem(server.displayString(), QVariant::fromValue(server));
int index = Utils::indexOf(servers,
[id = settings().defaultDashboardId()](const AxivionServer &s) {
return id == s.id;
});
if (index != -1)
m_dashboardServers->setCurrentIndex(index);
}
void AxivionSettingsWidget::updateEnabledStates()
{
const bool enabled = m_dashboardServers->count();
m_editServerButton->setEnabled(enabled);
m_removeServerButton->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("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>();
QDialog d;
d.setWindowTitle(add ? Tr::tr("Add Dashboard Configuration")
: Tr::tr("Edit Dashboard Configuration"));
QVBoxLayout *layout = new QVBoxLayout;
auto buttons = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok, this);
auto ok = buttons->button(QDialogButtonBox::Ok);
auto dashboardWidget = new DashboardSettingsWidget(this, ok);
dashboardWidget->setDashboardServer(old);
layout->addWidget(dashboardWidget);
ok->setEnabled(dashboardWidget->isValid());
connect(buttons->button(QDialogButtonBox::Cancel), &QPushButton::clicked, &d, &QDialog::reject);
connect(ok, &QPushButton::clicked, &d, &QDialog::accept);
layout->addWidget(buttons);
d.setLayout(layout);
d.resize(500, 200);
if (d.exec() != QDialog::Accepted) {
if (add) { // if we canceled an add, remove the canceled item
m_dashboardServers->removeItem(m_dashboardServers->currentIndex());
updateEnabledStates();
}
return;
}
if (dashboardWidget->isValid()) {
const AxivionServer server = dashboardWidget->dashboardServer();
if (server != old) {
m_dashboardServers->setItemData(m_dashboardServers->currentIndex(),
QVariant::fromValue(server));
m_dashboardServers->setItemData(m_dashboardServers->currentIndex(),
server.displayString(), Qt::DisplayRole);
}
}
updateEnabledStates();
}
void AxivionSettingsWidget::addMapping()
{ {
QTreeWidgetItem *item = new QTreeWidgetItem(&m_mappingTree, {"", "", ""}); QTreeWidgetItem *item = new QTreeWidgetItem(&m_mappingTree, {"", "", ""});
m_mappingTree.setCurrentItem(item); m_mappingTree.setCurrentItem(item);
item->setIcon(0, Icons::CRITICAL.icon()); item->setIcon(0, Icons::CRITICAL.icon());
} }
void PathMappingSettingsWidget::deleteMapping() void AxivionSettingsWidget::deleteMapping()
{ {
QTreeWidgetItem *item = m_mappingTree.currentItem(); QTreeWidgetItem *item = m_mappingTree.currentItem();
QTC_ASSERT(item, return); QTC_ASSERT(item, return);
@@ -733,7 +723,7 @@ void PathMappingSettingsWidget::deleteMapping()
m_mappingTree.model()->removeRow(index.row()); m_mappingTree.model()->removeRow(index.row());
} }
void PathMappingSettingsWidget::mappingChanged() void AxivionSettingsWidget::mappingChanged()
{ {
QTreeWidgetItem *item = m_mappingTree.currentItem(); QTreeWidgetItem *item = m_mappingTree.currentItem();
QTC_ASSERT(item, return); QTC_ASSERT(item, return);
@@ -744,14 +734,14 @@ void PathMappingSettingsWidget::mappingChanged()
item->setIcon(0, modified.isValid() ? QIcon{} : Icons::CRITICAL.icon()); item->setIcon(0, modified.isValid() ? QIcon{} : Icons::CRITICAL.icon());
} }
void PathMappingSettingsWidget::currentChanged(const QModelIndex &index, void AxivionSettingsWidget::currentChanged(const QModelIndex &index,
const QModelIndex &/*previous*/) const QModelIndex &/*previous*/)
{ {
const bool indexValid = index.isValid(); const bool indexValid = index.isValid();
const int row = index.row(); const int row = index.row();
m_deleteButton->setEnabled(indexValid); m_deleteMappingButton->setEnabled(indexValid);
m_moveUp->setEnabled(indexValid && row > 0); m_moveUpMappingButton->setEnabled(indexValid && row > 0);
m_moveDown->setEnabled(indexValid && row < m_mappingTree.topLevelItemCount() - 1); m_moveDownMappingButton->setEnabled(indexValid && row < m_mappingTree.topLevelItemCount() - 1);
m_detailsWidget->setVisible(indexValid); m_detailsWidget->setVisible(indexValid);
if (indexValid) { if (indexValid) {
const QTreeWidgetItem * const item = m_mappingTree.itemFromIndex(index); const QTreeWidgetItem * const item = m_mappingTree.itemFromIndex(index);
@@ -761,7 +751,7 @@ void PathMappingSettingsWidget::currentChanged(const QModelIndex &index,
} }
} }
void PathMappingSettingsWidget::moveCurrent(bool up) void AxivionSettingsWidget::moveCurrentMapping(bool up)
{ {
const int itemCount = m_mappingTree.topLevelItemCount(); const int itemCount = m_mappingTree.topLevelItemCount();
const QModelIndexList indexes = m_mappingTree.selectionModel()->selectedRows(); const QModelIndexList indexes = m_mappingTree.selectionModel()->selectedRows();
@@ -783,26 +773,13 @@ class AxivionSettingsPage : public IOptionsPage
public: public:
AxivionSettingsPage() AxivionSettingsPage()
{ {
setId("Axivion.Settings.General"); setId("Analyzer.Axivion.Settings");
setDisplayName(Tr::tr("General")); setDisplayName(Tr::tr("Axivion"));
setCategory("XY.Axivion"); setCategory("T.Analyzer");
setWidgetCreator([] { return new AxivionSettingsWidget; }); setWidgetCreator([] { return new AxivionSettingsWidget; });
} }
}; };
class PathMappingSettingsPage : public IOptionsPage
{
public:
PathMappingSettingsPage()
{
setId("Axivion.Settings.PathMapping");
setDisplayName(Tr::tr("Path Mapping"));
setCategory("XY.Axivion");
setWidgetCreator([] { return new PathMappingSettingsWidget; });
}
};
const AxivionSettingsPage generalSettingsPage; const AxivionSettingsPage generalSettingsPage;
const PathMappingSettingsPage pathMappingSettingsPage;
} // Axivion::Internal } // Axivion::Internal