2022-12-12 16:45:31 +01:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial
|
2022-11-28 09:48:11 +01:00
|
|
|
|
|
|
|
|
#include "axivionoutputpane.h"
|
|
|
|
|
|
2022-12-14 13:53:00 +01:00
|
|
|
#include "axivionplugin.h"
|
|
|
|
|
#include "axivionresultparser.h"
|
2022-11-28 09:48:11 +01:00
|
|
|
#include "axiviontr.h"
|
|
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
QFormLayout *m_formLayout = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
projectLayout->addRow(Tr::tr("Lines of Code:"), m_loc);
|
|
|
|
|
layout->addLayout(projectLayout);
|
|
|
|
|
m_formLayout = new QFormLayout;
|
|
|
|
|
layout->addLayout(m_formLayout);
|
2023-01-11 14:44:27 +01:00
|
|
|
setWidget(widget);
|
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
|
|
|
|
setWidgetResizable(true);
|
2022-12-14 13:53:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DashboardWidget::updateUi()
|
|
|
|
|
{
|
|
|
|
|
const ProjectInfo &info = AxivionPlugin::projectInfo();
|
|
|
|
|
m_project->setText(info.name);
|
|
|
|
|
m_loc->setText({});
|
|
|
|
|
while (m_formLayout->rowCount())
|
|
|
|
|
m_formLayout->removeRow(0);
|
|
|
|
|
|
|
|
|
|
if (info.versions.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const ResultVersion &last = info.versions.last();
|
|
|
|
|
m_loc->setText(QString::number(last.linesOfCode));
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
auto toolTip = [issueKinds](const QString &prefix){
|
|
|
|
|
for (const IssueKind &kind : issueKinds) {
|
|
|
|
|
if (kind.prefix == prefix)
|
|
|
|
|
return kind.nicePlural;
|
|
|
|
|
}
|
|
|
|
|
return QString();
|
|
|
|
|
};
|
|
|
|
|
int allTotal = 0, allAdded = 0, allRemoved = 0;
|
|
|
|
|
for (auto issueCount : std::as_const(last.issueCounts)) {
|
|
|
|
|
allTotal += issueCount.total;
|
|
|
|
|
allAdded += issueCount.added;
|
|
|
|
|
allRemoved += issueCount.removed;
|
|
|
|
|
const QString txt = apply(issueCount.total, issueCount.added, issueCount.removed);
|
|
|
|
|
const QString currentToolTip = toolTip(issueCount.issueKind);
|
|
|
|
|
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);
|
|
|
|
|
m_formLayout->addRow(Tr::tr("Total:"), label);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 09:48:11 +01:00
|
|
|
AxivionOutputPane::AxivionOutputPane(QObject *parent)
|
|
|
|
|
: Core::IOutputPane(parent)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
showDashboard->setIcon(Utils::Icons::ONLINE_TOOLBAR.icon());
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AxivionOutputPane::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return Tr::tr("Axivion");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AxivionOutputPane::priorityInStatusBar() const
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|