mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
Ref T509, added a first version of QChart for distributors
This commit is contained in:
committed by
Mat Sutcliffe
parent
1652fb7074
commit
80a36f4346
@@ -15,7 +15,10 @@
|
||||
#include <QPushButton>
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
#include <QStringList>
|
||||
#include <QtCharts>
|
||||
|
||||
using namespace QtCharts;
|
||||
using namespace BlackMisc::Simulation;
|
||||
|
||||
namespace BlackGui
|
||||
@@ -27,9 +30,15 @@ namespace BlackGui
|
||||
ui(new Ui::CAircraftModelStatisticsDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->tw_ModelStatistics->setCurrentIndex(0);
|
||||
this->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
connect(ui->pb_GenerateMatrix, &QPushButton::clicked, this, &CAircraftModelStatisticsDialog::displayHTMLMatrix);
|
||||
connect(ui->pb_GenerateMatrix, &QPushButton::released, this, &CAircraftModelStatisticsDialog::displayHTMLMatrix);
|
||||
connect(ui->pb_ShowChart, &QPushButton::released, this, &CAircraftModelStatisticsDialog::showChart);
|
||||
connect(ui->tb_ZoomIn, &QToolButton::released, this, &CAircraftModelStatisticsDialog::zoom);
|
||||
connect(ui->tb_ZoomOut, &QToolButton::released, this, &CAircraftModelStatisticsDialog::zoom);
|
||||
|
||||
this->initChart();
|
||||
}
|
||||
|
||||
CAircraftModelStatisticsDialog::~CAircraftModelStatisticsDialog()
|
||||
@@ -37,8 +46,8 @@ namespace BlackGui
|
||||
|
||||
void CAircraftModelStatisticsDialog::analyzeModels(const CAircraftModelList &models)
|
||||
{
|
||||
ui->te_GeneralStatistics->setHtml(models.htmlStatistics(true, true));
|
||||
m_models = models;
|
||||
ui->te_GeneralStatistics->setHtml(models.htmlStatistics(true, true));
|
||||
}
|
||||
|
||||
void CAircraftModelStatisticsDialog::displayHTMLMatrix()
|
||||
@@ -47,5 +56,79 @@ namespace BlackGui
|
||||
if (file.isEmpty()) { return; }
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(file));
|
||||
}
|
||||
|
||||
void CAircraftModelStatisticsDialog::zoom()
|
||||
{
|
||||
const QObject *sender = QObject::sender();
|
||||
QChart *chart = ui->qv_Chart->chart();
|
||||
if (sender == ui->tb_ZoomIn) { chart->zoomIn(); return; }
|
||||
if (sender == ui->tb_ZoomOut) { chart->zoomOut(); return; }
|
||||
}
|
||||
|
||||
void CAircraftModelStatisticsDialog::initChart()
|
||||
{
|
||||
QChart *chart = new QChart();
|
||||
chart->setAnimationOptions(QChart::SeriesAnimations);
|
||||
chart->legend()->setVisible(true);
|
||||
chart->legend()->setAlignment(Qt::AlignBottom);
|
||||
chart->setTheme(QChart::ChartThemeBlueIcy);
|
||||
ui->qv_Chart->setChart(chart);
|
||||
ui->qv_Chart->setRenderHint(QPainter::Antialiasing);
|
||||
}
|
||||
|
||||
void CAircraftModelStatisticsDialog::resetChart()
|
||||
{
|
||||
QChart *chart = ui->qv_Chart->chart();
|
||||
chart->removeAllSeries();
|
||||
const auto axes = chart->axes();
|
||||
for (auto axis : axes)
|
||||
{
|
||||
chart->removeAxis(axis);
|
||||
}
|
||||
}
|
||||
|
||||
void CAircraftModelStatisticsDialog::showChart()
|
||||
{
|
||||
if (ui->rb_Distributors->isChecked()) { this->chartDistributors(); return; }
|
||||
}
|
||||
|
||||
void CAircraftModelStatisticsDialog::chartDistributors()
|
||||
{
|
||||
QChart *chart = ui->qv_Chart->chart();
|
||||
this->resetChart();
|
||||
const QMap<CDistributor, int> distributors = m_models.countPerDistributor();
|
||||
QStringList distributorsForAxis;
|
||||
QBarSet *setDistributors = new QBarSet("Distributors");
|
||||
|
||||
// using number as uique key as it can happen there a identical distributor keys
|
||||
// and QChart requires uniques values
|
||||
int n = 1;
|
||||
for (const CDistributor &distributor : distributors.keys())
|
||||
{
|
||||
const int c = distributors[distributor];
|
||||
if (c < 1) { continue; }
|
||||
distributorsForAxis << QString::number(n) % u": " % distributor.getDbKey() % u" " % QString::number(c);
|
||||
*setDistributors << c;
|
||||
n++;
|
||||
// QString s += distributor.getDbKey() % u" " % QString::number(c) % "\n";
|
||||
}
|
||||
|
||||
QHorizontalBarSeries *series = new QHorizontalBarSeries(this);
|
||||
series->append(setDistributors);
|
||||
chart->addSeries(series);
|
||||
// chart->setTitle("Distributors");
|
||||
|
||||
// Y
|
||||
QBarCategoryAxis *axisY = new QBarCategoryAxis();
|
||||
axisY->append(distributorsForAxis);
|
||||
chart->addAxis(axisY, Qt::AlignLeft);
|
||||
series->attachAxis(axisY);
|
||||
|
||||
// X
|
||||
QValueAxis *axisX = new QValueAxis();
|
||||
chart->addAxis(axisX, Qt::AlignBottom);
|
||||
series->attachAxis(axisX);
|
||||
axisX->applyNiceNumbers();
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user