mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +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
@@ -1,6 +1,6 @@
|
||||
load(common_pre)
|
||||
|
||||
QT += core dbus gui network svg widgets
|
||||
QT += core dbus gui network svg widgets charts
|
||||
|
||||
TARGET = blackgui
|
||||
TEMPLATE = lib
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -40,6 +40,21 @@ namespace BlackGui
|
||||
//! Display the HTML matrix
|
||||
void displayHTMLMatrix();
|
||||
|
||||
//! Zoom in/out
|
||||
void zoom();
|
||||
|
||||
//! Init chart
|
||||
void initChart();
|
||||
|
||||
//! Reset chart
|
||||
void resetChart();
|
||||
|
||||
//! Chart
|
||||
void showChart();
|
||||
|
||||
//! Chart for distributors
|
||||
void chartDistributors();
|
||||
|
||||
QScopedPointer<Ui::CAircraftModelStatisticsDialog> ui;
|
||||
BlackMisc::Simulation::CAircraftModelList m_models;
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>300</width>
|
||||
<height>298</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
@@ -42,6 +42,96 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tb_Charts">
|
||||
<attribute name="title">
|
||||
<string>Charts</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="vl_Charts" stretch="0,0">
|
||||
<item>
|
||||
<widget class="QFrame" name="fr_ChartType">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="hl_ChartType">
|
||||
<property name="leftMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rb_Distributors">
|
||||
<property name="text">
|
||||
<string>distributors</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="hs_ChartType">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="tb_ZoomIn">
|
||||
<property name="text">
|
||||
<string>+</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="tb_ZoomOut">
|
||||
<property name="text">
|
||||
<string>-</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignRight">
|
||||
<widget class="QPushButton" name="pb_ShowChart">
|
||||
<property name="text">
|
||||
<string>show</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QChartView" name="qv_Chart">
|
||||
<property name="sceneRect">
|
||||
<rectf>
|
||||
<x>0.000000000000000</x>
|
||||
<y>0.000000000000000</y>
|
||||
<width>400.000000000000000</width>
|
||||
<height>300.000000000000000</height>
|
||||
</rectf>
|
||||
</property>
|
||||
<property name="dragMode">
|
||||
<enum>QGraphicsView::ScrollHandDrag</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tb_Matrix">
|
||||
<attribute name="title">
|
||||
<string>Matrix</string>
|
||||
@@ -54,7 +144,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="0" column="1" alignment="Qt::AlignLeft">
|
||||
<widget class="QPushButton" name="pb_GenerateMatrix">
|
||||
<property name="text">
|
||||
<string>generate matix</string>
|
||||
@@ -77,6 +167,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QChartView</class>
|
||||
<extends>QGraphicsView</extends>
|
||||
<header>QtCharts</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
||||
Reference in New Issue
Block a user