Axivion: Let issues count view appear nicer

Small overhaul of the layout and replace the former
text-only placeholder.

Change-Id: I0cee393f6aa7449b10b07f3daffa37f0b697d0af
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2023-06-19 10:22:03 +02:00
parent 972aaccde1
commit 5010f041cb

View File

@@ -11,6 +11,7 @@
#include <utils/utilsicons.h> #include <utils/utilsicons.h>
#include <QFormLayout> #include <QFormLayout>
#include <QGridLayout>
#include <QLabel> #include <QLabel>
#include <QScrollArea> #include <QScrollArea>
#include <QStackedWidget> #include <QStackedWidget>
@@ -29,7 +30,7 @@ private:
QLabel *m_project = nullptr; QLabel *m_project = nullptr;
QLabel *m_loc = nullptr; QLabel *m_loc = nullptr;
QLabel *m_timestamp = nullptr; QLabel *m_timestamp = nullptr;
QFormLayout *m_formLayout = nullptr; QGridLayout *m_gridLayout = nullptr;
}; };
DashboardWidget::DashboardWidget(QWidget *parent) DashboardWidget::DashboardWidget(QWidget *parent)
@@ -46,22 +47,40 @@ DashboardWidget::DashboardWidget(QWidget *parent)
projectLayout->addRow(Tr::tr("Analysis timestamp:"), m_timestamp); projectLayout->addRow(Tr::tr("Analysis timestamp:"), m_timestamp);
layout->addLayout(projectLayout); layout->addLayout(projectLayout);
layout->addSpacing(10); layout->addSpacing(10);
m_formLayout = new QFormLayout; auto row = new QHBoxLayout;
layout->addLayout(m_formLayout); m_gridLayout = new QGridLayout;
row->addLayout(m_gridLayout);
row->addStretch(1);
layout->addLayout(row);
layout->addStretch(1); layout->addStretch(1);
setWidget(widget); setWidget(widget);
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setWidgetResizable(true); setWidgetResizable(true);
} }
static QPixmap trendIcon(int added, int removed)
{
static const QPixmap unchanged = Utils::Icons::NEXT.pixmap();
static const QPixmap increased = Utils::Icon(
{ {":/utils/images/arrowup.png", Utils::Theme::IconsErrorColor} }).pixmap();
static const QPixmap decreased = Utils::Icon(
{ {":/utils/images/arrowdown.png", Utils::Theme::IconsRunColor} }).pixmap();
if (added == removed)
return unchanged;
return added < removed ? decreased : increased;
}
void DashboardWidget::updateUi() void DashboardWidget::updateUi()
{ {
const ProjectInfo &info = AxivionPlugin::projectInfo(); const ProjectInfo &info = AxivionPlugin::projectInfo();
m_project->setText(info.name); m_project->setText(info.name);
m_loc->setText({}); m_loc->setText({});
m_timestamp->setText({}); m_timestamp->setText({});
while (m_formLayout->rowCount()) QLayoutItem *child;
m_formLayout->removeRow(0); while ((child = m_gridLayout->takeAt(0)) != nullptr) {
delete child->widget();
delete child;
}
if (info.versions.isEmpty()) if (info.versions.isEmpty())
return; return;
@@ -72,36 +91,50 @@ void DashboardWidget::updateUi()
m_timestamp->setText(timeStamp.isValid() ? timeStamp.toString("yyyy-MM-dd HH::mm::ss") m_timestamp->setText(timeStamp.isValid() ? timeStamp.toString("yyyy-MM-dd HH::mm::ss")
: Tr::tr("unknown")); : Tr::tr("unknown"));
const QString tmpl("%1 %2 +%3 / -%4");
auto apply = [&tmpl](int t, int a, int r){
QChar tr = (a == r ? '=' : (a < r ? '^' : 'v'));
return tmpl.arg(t, 10, 10, QLatin1Char(' ')).arg(tr).arg(a, 5, 10, QLatin1Char(' '))
.arg(r, 5, 10, QLatin1Char(' '));
};
const QList<IssueKind> &issueKinds = info.issueKinds; const QList<IssueKind> &issueKinds = info.issueKinds;
auto toolTip = [issueKinds](const QString &prefix){ auto toolTip = [issueKinds](const QString &prefix){
for (const IssueKind &kind : issueKinds) { for (const IssueKind &kind : issueKinds) {
if (kind.prefix == prefix) if (kind.prefix == prefix)
return kind.nicePlural; return kind.nicePlural;
} }
return QString(); return prefix;
}; };
int allTotal = 0, allAdded = 0, allRemoved = 0; auto addValuesWidgets = [this, &toolTip](const IssueCount &issueCount, int row){
const QString currentToolTip = toolTip(issueCount.issueKind);
QLabel *label = new QLabel(issueCount.issueKind, this);
label->setToolTip(currentToolTip);
m_gridLayout->addWidget(label, row, 0);
label = new QLabel(QString::number(issueCount.total), this);
label->setToolTip(currentToolTip);
label->setAlignment(Qt::AlignRight);
m_gridLayout->addWidget(label, row, 1);
label = new QLabel(this);
label->setPixmap(trendIcon(issueCount.added, issueCount.removed));
label->setToolTip(currentToolTip);
m_gridLayout->addWidget(label, row, 2);
label = new QLabel('+' + QString::number(issueCount.added));
label->setAlignment(Qt::AlignRight);
label->setToolTip(currentToolTip);
m_gridLayout->addWidget(label, row, 3);
label = new QLabel("/");
label->setToolTip(currentToolTip);
m_gridLayout->addWidget(label, row, 4);
label = new QLabel('-' + QString::number(issueCount.removed));
label->setAlignment(Qt::AlignRight);
label->setToolTip(currentToolTip);
m_gridLayout->addWidget(label, row, 5);
};
int allTotal = 0, allAdded = 0, allRemoved = 0, row = 0;
for (auto issueCount : std::as_const(last.issueCounts)) { for (auto issueCount : std::as_const(last.issueCounts)) {
allTotal += issueCount.total; allTotal += issueCount.total;
allAdded += issueCount.added; allAdded += issueCount.added;
allRemoved += issueCount.removed; allRemoved += issueCount.removed;
const QString txt = apply(issueCount.total, issueCount.added, issueCount.removed); addValuesWidgets(issueCount, row);
const QString currentToolTip = toolTip(issueCount.issueKind); ++row;
QLabel *label = new QLabel(issueCount.issueKind, this);
label->setToolTip(currentToolTip);
QLabel *values = new QLabel(txt, this);
values->setToolTip(currentToolTip);
m_formLayout->addRow(label, values);
} }
QLabel *label = new QLabel(apply(allTotal, allAdded, allRemoved), this); const IssueCount total{{}, Tr::tr("Total:"), allTotal, allAdded, allRemoved};
m_formLayout->addRow(Tr::tr("Total:"), label); addValuesWidgets(total, row);
} }
AxivionOutputPane::AxivionOutputPane(QObject *parent) AxivionOutputPane::AxivionOutputPane(QObject *parent)