2022-12-12 16:45:31 +01:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
2023-05-24 10:27:35 +02:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2022-11-28 09:48:11 +01:00
|
|
|
|
|
|
|
|
#include "axivionoutputpane.h"
|
|
|
|
|
|
2022-12-14 13:53:00 +01:00
|
|
|
#include "axivionplugin.h"
|
2022-11-28 09:48:11 +01:00
|
|
|
#include "axiviontr.h"
|
2023-07-25 18:48:18 +02:00
|
|
|
#include "dashboard/dto.h"
|
2022-11-28 09:48:11 +01:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
2023-01-13 15:43:01 +01:00
|
|
|
#include <utils/utilsicons.h>
|
2022-11-28 09:48:11 +01:00
|
|
|
|
2022-12-14 13:53:00 +01:00
|
|
|
#include <QFormLayout>
|
2023-06-19 10:22:03 +02:00
|
|
|
#include <QGridLayout>
|
2022-12-14 13:53:00 +01:00
|
|
|
#include <QLabel>
|
2023-01-11 14:44:27 +01:00
|
|
|
#include <QScrollArea>
|
2022-11-28 09:48:11 +01:00
|
|
|
#include <QStackedWidget>
|
2023-01-13 14:38:39 +01:00
|
|
|
#include <QTextBrowser>
|
2023-01-13 15:43:01 +01:00
|
|
|
#include <QToolButton>
|
2022-11-28 09:48:11 +01:00
|
|
|
|
2023-07-25 18:48:18 +02:00
|
|
|
#include <map>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2022-11-28 09:48:11 +01:00
|
|
|
namespace Axivion::Internal {
|
|
|
|
|
|
2023-01-11 14:44:27 +01:00
|
|
|
class DashboardWidget : public QScrollArea
|
2022-12-14 13:53:00 +01:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit DashboardWidget(QWidget *parent = nullptr);
|
|
|
|
|
void updateUi();
|
|
|
|
|
bool hasProject() const { return !m_project->text().isEmpty(); }
|
|
|
|
|
private:
|
|
|
|
|
QLabel *m_project = nullptr;
|
|
|
|
|
QLabel *m_loc = nullptr;
|
2023-06-16 10:11:41 +02:00
|
|
|
QLabel *m_timestamp = nullptr;
|
2023-06-19 10:22:03 +02:00
|
|
|
QGridLayout *m_gridLayout = nullptr;
|
2022-12-14 13:53:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DashboardWidget::DashboardWidget(QWidget *parent)
|
2023-01-11 14:44:27 +01:00
|
|
|
: QScrollArea(parent)
|
2022-12-14 13:53:00 +01:00
|
|
|
{
|
2023-01-11 14:44:27 +01:00
|
|
|
QWidget *widget = new QWidget(this);
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(widget);
|
2022-12-14 13:53:00 +01:00
|
|
|
QFormLayout *projectLayout = new QFormLayout;
|
|
|
|
|
m_project = new QLabel(this);
|
|
|
|
|
projectLayout->addRow(Tr::tr("Project:"), m_project);
|
|
|
|
|
m_loc = new QLabel(this);
|
2023-06-19 10:55:58 +02:00
|
|
|
projectLayout->addRow(Tr::tr("Lines of code:"), m_loc);
|
2023-06-16 10:11:41 +02:00
|
|
|
m_timestamp = new QLabel(this);
|
|
|
|
|
projectLayout->addRow(Tr::tr("Analysis timestamp:"), m_timestamp);
|
2022-12-14 13:53:00 +01:00
|
|
|
layout->addLayout(projectLayout);
|
2023-06-16 10:11:41 +02:00
|
|
|
layout->addSpacing(10);
|
2023-06-19 10:22:03 +02:00
|
|
|
auto row = new QHBoxLayout;
|
|
|
|
|
m_gridLayout = new QGridLayout;
|
|
|
|
|
row->addLayout(m_gridLayout);
|
|
|
|
|
row->addStretch(1);
|
|
|
|
|
layout->addLayout(row);
|
2023-06-16 10:11:41 +02:00
|
|
|
layout->addStretch(1);
|
2023-01-11 14:44:27 +01:00
|
|
|
setWidget(widget);
|
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
|
|
|
|
setWidgetResizable(true);
|
2022-12-14 13:53:00 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-25 18:48:18 +02:00
|
|
|
static QPixmap trendIcon(qint64 added, qint64 removed)
|
2023-06-19 10:22:03 +02:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 18:48:18 +02:00
|
|
|
static qint64 extract_value(const std::map<QString, Dto::Any> &map, const QString &key)
|
|
|
|
|
{
|
|
|
|
|
const auto search = map.find(key);
|
|
|
|
|
if (search == map.end())
|
|
|
|
|
return 0;
|
|
|
|
|
const Dto::Any &value = search->second;
|
|
|
|
|
if (!value.isDouble())
|
|
|
|
|
return 0;
|
|
|
|
|
return static_cast<qint64>(value.getDouble());
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-14 13:53:00 +01:00
|
|
|
void DashboardWidget::updateUi()
|
|
|
|
|
{
|
2023-07-25 18:48:18 +02:00
|
|
|
m_project->setText({});
|
2022-12-14 13:53:00 +01:00
|
|
|
m_loc->setText({});
|
2023-06-16 10:11:41 +02:00
|
|
|
m_timestamp->setText({});
|
2023-06-19 10:22:03 +02:00
|
|
|
QLayoutItem *child;
|
|
|
|
|
while ((child = m_gridLayout->takeAt(0)) != nullptr) {
|
|
|
|
|
delete child->widget();
|
|
|
|
|
delete child;
|
|
|
|
|
}
|
2023-09-15 14:38:48 +02:00
|
|
|
std::shared_ptr<const DashboardClient::ProjectInfo> projectInfo = AxivionPlugin::projectInfo();
|
|
|
|
|
if (!projectInfo)
|
2023-07-25 18:48:18 +02:00
|
|
|
return;
|
2023-09-15 14:38:48 +02:00
|
|
|
const Dto::ProjectInfoDto &info = projectInfo->data;
|
|
|
|
|
m_project->setText(info.name);
|
|
|
|
|
if (info.versions.empty())
|
2022-12-14 13:53:00 +01:00
|
|
|
return;
|
|
|
|
|
|
2023-09-15 14:38:48 +02:00
|
|
|
const Dto::AnalysisVersionDto &last = info.versions.back();
|
2023-07-25 18:48:18 +02:00
|
|
|
if (last.linesOfCode.has_value())
|
|
|
|
|
m_loc->setText(QString::number(last.linesOfCode.value()));
|
|
|
|
|
const QDateTime timeStamp = QDateTime::fromString(last.date, Qt::ISODate);
|
|
|
|
|
m_timestamp->setText(timeStamp.isValid() ? timeStamp.toString("yyyy-MM-dd HH:mm:ss t")
|
2023-06-16 10:11:41 +02:00
|
|
|
: Tr::tr("unknown"));
|
2022-12-14 13:53:00 +01:00
|
|
|
|
2023-09-15 14:38:48 +02:00
|
|
|
const std::vector<Dto::IssueKindInfoDto> &issueKinds = info.issueKinds;
|
2022-12-14 13:53:00 +01:00
|
|
|
auto toolTip = [issueKinds](const QString &prefix){
|
2023-07-25 18:48:18 +02:00
|
|
|
for (const Dto::IssueKindInfoDto &kind : issueKinds) {
|
2022-12-14 13:53:00 +01:00
|
|
|
if (kind.prefix == prefix)
|
2023-07-25 18:48:18 +02:00
|
|
|
return kind.nicePluralName;
|
2022-12-14 13:53:00 +01:00
|
|
|
}
|
2023-06-19 10:22:03 +02:00
|
|
|
return prefix;
|
2022-12-14 13:53:00 +01:00
|
|
|
};
|
2023-07-25 18:48:18 +02:00
|
|
|
auto addValuesWidgets = [this, &toolTip](const QString &issueKind, qint64 total, qint64 added, qint64 removed, int row) {
|
|
|
|
|
const QString currentToolTip = toolTip(issueKind);
|
|
|
|
|
QLabel *label = new QLabel(issueKind, this);
|
2023-06-19 10:22:03 +02:00
|
|
|
label->setToolTip(currentToolTip);
|
|
|
|
|
m_gridLayout->addWidget(label, row, 0);
|
2023-07-25 18:48:18 +02:00
|
|
|
label = new QLabel(QString::number(total), this);
|
2023-06-19 10:22:03 +02:00
|
|
|
label->setToolTip(currentToolTip);
|
|
|
|
|
label->setAlignment(Qt::AlignRight);
|
|
|
|
|
m_gridLayout->addWidget(label, row, 1);
|
|
|
|
|
label = new QLabel(this);
|
2023-07-25 18:48:18 +02:00
|
|
|
label->setPixmap(trendIcon(added, removed));
|
2023-06-19 10:22:03 +02:00
|
|
|
label->setToolTip(currentToolTip);
|
|
|
|
|
m_gridLayout->addWidget(label, row, 2);
|
2023-07-25 18:48:18 +02:00
|
|
|
label = new QLabel('+' + QString::number(added));
|
2023-06-19 10:22:03 +02:00
|
|
|
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);
|
2023-07-25 18:48:18 +02:00
|
|
|
label = new QLabel('-' + QString::number(removed));
|
2023-06-19 10:22:03 +02:00
|
|
|
label->setAlignment(Qt::AlignRight);
|
|
|
|
|
label->setToolTip(currentToolTip);
|
|
|
|
|
m_gridLayout->addWidget(label, row, 5);
|
|
|
|
|
};
|
2023-07-25 18:48:18 +02:00
|
|
|
qint64 allTotal = 0;
|
|
|
|
|
qint64 allAdded = 0;
|
|
|
|
|
qint64 allRemoved = 0;
|
|
|
|
|
qint64 row = 0;
|
|
|
|
|
// This code is overly complex because of a heedlessness in the
|
|
|
|
|
// Axivion Dashboard API definition. Other Axivion IDE plugins do
|
|
|
|
|
// not use the issue counts, thus the QtCreator Axivion Plugin
|
|
|
|
|
// is going to stop using them, too.
|
|
|
|
|
if (last.issueCounts.isMap()) {
|
2023-08-22 15:55:28 +02:00
|
|
|
for (const Dto::Any::MapEntry &issueCount : last.issueCounts.getMap()) {
|
2023-07-25 18:48:18 +02:00
|
|
|
if (issueCount.second.isMap()) {
|
2023-08-22 15:55:28 +02:00
|
|
|
const Dto::Any::Map &counts = issueCount.second.getMap();
|
2023-07-25 18:48:18 +02:00
|
|
|
qint64 total = extract_value(counts, QStringLiteral(u"Total"));
|
|
|
|
|
allTotal += total;
|
|
|
|
|
qint64 added = extract_value(counts, QStringLiteral(u"Added"));
|
|
|
|
|
allAdded += added;
|
|
|
|
|
qint64 removed = extract_value(counts, QStringLiteral(u"Removed"));
|
|
|
|
|
allRemoved += removed;
|
|
|
|
|
addValuesWidgets(issueCount.first, total, added, removed, row);
|
|
|
|
|
++row;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-14 13:53:00 +01:00
|
|
|
}
|
2023-07-25 18:48:18 +02:00
|
|
|
addValuesWidgets(Tr::tr("Total:"), allTotal, allAdded, allRemoved, row);
|
2022-12-14 13:53:00 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-28 09:48:11 +01:00
|
|
|
AxivionOutputPane::AxivionOutputPane(QObject *parent)
|
|
|
|
|
: Core::IOutputPane(parent)
|
|
|
|
|
{
|
2023-09-13 15:36:07 +02:00
|
|
|
setId("Axivion");
|
2023-09-13 11:46:00 +02:00
|
|
|
setDisplayName(Tr::tr("Axivion"));
|
2023-09-14 09:40:56 +02:00
|
|
|
setPriorityInStatusBar(-50);
|
2023-09-13 11:46:00 +02:00
|
|
|
|
2022-11-28 09:48:11 +01:00
|
|
|
m_outputWidget = new QStackedWidget;
|
2022-12-14 13:53:00 +01:00
|
|
|
DashboardWidget *dashboardWidget = new DashboardWidget(m_outputWidget);
|
|
|
|
|
m_outputWidget->addWidget(dashboardWidget);
|
2023-01-13 14:38:39 +01:00
|
|
|
QTextBrowser *browser = new QTextBrowser(m_outputWidget);
|
|
|
|
|
m_outputWidget->addWidget(browser);
|
2022-11-28 09:48:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AxivionOutputPane::~AxivionOutputPane()
|
|
|
|
|
{
|
|
|
|
|
if (!m_outputWidget->parent())
|
|
|
|
|
delete m_outputWidget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *AxivionOutputPane::outputWidget(QWidget *parent)
|
|
|
|
|
{
|
|
|
|
|
if (m_outputWidget)
|
|
|
|
|
m_outputWidget->setParent(parent);
|
|
|
|
|
else
|
|
|
|
|
QTC_CHECK(false);
|
|
|
|
|
return m_outputWidget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QWidget *> AxivionOutputPane::toolBarWidgets() const
|
|
|
|
|
{
|
|
|
|
|
QList<QWidget *> buttons;
|
2023-01-13 15:43:01 +01:00
|
|
|
auto showDashboard = new QToolButton(m_outputWidget);
|
2023-06-07 15:39:16 +02:00
|
|
|
showDashboard->setIcon(Utils::Icons::HOME_TOOLBAR.icon());
|
2023-01-13 15:43:01 +01:00
|
|
|
showDashboard->setToolTip(Tr::tr("Show dashboard"));
|
|
|
|
|
connect(showDashboard, &QToolButton::clicked, this, [this]{
|
|
|
|
|
QTC_ASSERT(m_outputWidget, return);
|
|
|
|
|
m_outputWidget->setCurrentIndex(0);
|
|
|
|
|
});
|
|
|
|
|
buttons.append(showDashboard);
|
2022-11-28 09:48:11 +01:00
|
|
|
return buttons;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AxivionOutputPane::clearContents()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AxivionOutputPane::setFocus()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AxivionOutputPane::hasFocus() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AxivionOutputPane::canFocus() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AxivionOutputPane::canNavigate() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AxivionOutputPane::canNext() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AxivionOutputPane::canPrevious() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AxivionOutputPane::goToNext()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AxivionOutputPane::goToPrev()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-14 12:11:03 +01:00
|
|
|
void AxivionOutputPane::updateDashboard()
|
|
|
|
|
{
|
2022-12-14 13:53:00 +01:00
|
|
|
if (auto dashboard = static_cast<DashboardWidget *>(m_outputWidget->widget(0))) {
|
|
|
|
|
dashboard->updateUi();
|
|
|
|
|
m_outputWidget->setCurrentIndex(0);
|
|
|
|
|
if (dashboard->hasProject())
|
|
|
|
|
flash();
|
|
|
|
|
}
|
2022-12-14 12:11:03 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-13 14:38:39 +01:00
|
|
|
void AxivionOutputPane::updateAndShowRule(const QString &ruleHtml)
|
|
|
|
|
{
|
|
|
|
|
if (auto browser = static_cast<QTextBrowser *>(m_outputWidget->widget(1))) {
|
|
|
|
|
browser->setText(ruleHtml);
|
|
|
|
|
if (!ruleHtml.isEmpty()) {
|
|
|
|
|
m_outputWidget->setCurrentIndex(1);
|
|
|
|
|
popup(Core::IOutputPane::NoModeSwitch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-12 16:45:31 +01:00
|
|
|
} // Axivion::Internal
|