From 1b06de0dc4f250d68303748409bc4130c9b044bf Mon Sep 17 00:00:00 2001 From: peri4 Date: Wed, 2 Aug 2023 12:32:09 +0300 Subject: [PATCH] add statistics to GraphicAnalysis --- libs/graphic_analysis/graphic_analysis.cpp | 40 ++- libs/graphic_analysis/graphic_analysis.h | 6 +- libs/graphic_analysis/graphic_analysis.ui | 37 ++- .../graphic_analysis_stat.cpp | 66 +++++ libs/graphic_analysis/graphic_analysis_stat.h | 54 ++++ .../graphic_analysis/graphic_analysis_stat.ui | 238 ++++++++++++++++++ .../lang/qad_graphic_analysis_en.ts | 71 +++++- .../lang/qad_graphic_analysis_ru.ts | 71 +++++- .../graphic_analysis/qad_graphic_analysis.qrc | 1 + 9 files changed, 558 insertions(+), 26 deletions(-) create mode 100644 libs/graphic_analysis/graphic_analysis_stat.cpp create mode 100644 libs/graphic_analysis/graphic_analysis_stat.h create mode 100644 libs/graphic_analysis/graphic_analysis_stat.ui diff --git a/libs/graphic_analysis/graphic_analysis.cpp b/libs/graphic_analysis/graphic_analysis.cpp index 8bc4609..8d8aa08 100644 --- a/libs/graphic_analysis/graphic_analysis.cpp +++ b/libs/graphic_analysis/graphic_analysis.cpp @@ -1,5 +1,6 @@ #include "graphic_analysis.h" +#include "graphic_analysis_stat.h" #include "qad_types.h" #include "ui_graphic_analysis.h" @@ -56,9 +57,11 @@ GraphicAnalysis::GraphicAnalysis(QWidget * parent): GraphicRanges(parent) { ui = new Ui::GraphicAnalysis(); ui->setupUi(widget_toolbox); ui->widgetSpectrum->hide(); + window_stat = new GraphicAnalysisStatistics(); connect(ui->checkSpectrum, SIGNAL(toggled(bool)), this, SLOT(checkSpectrum_toggled(bool))); connect(ui->buttonSpectrumRange, SIGNAL(toggled(bool)), this, SLOT(buttonSpectrumRange_toggled(bool))); connect(ui->checkSpectrumFixDuration, SIGNAL(toggled(bool)), this, SLOT(checkSpectrumFixDuration_toggled(bool))); + connect(ui->buttonStatistics, SIGNAL(toggled(bool)), this, SLOT(buttonStatistics_toggled(bool))); auto * lay = qobject_cast(layout()); lay->insertWidget(0, widget_toolbox); connect(ui->spinSpectrumDuration, SIGNAL(valueChanged(double)), this, SIGNAL(configChanged())); @@ -70,8 +73,8 @@ GraphicAnalysis::GraphicAnalysis(QWidget * parent): GraphicRanges(parent) { GraphicAnalysis::~GraphicAnalysis() { + delete window_stat; delete ui; - delete widget_toolbox; } @@ -119,13 +122,13 @@ void GraphicAnalysis::setLabelX(const QString & str) { } -QBoxLayout * GraphicAnalysis::toolboxLayout() { - return reinterpret_cast(widget_toolbox->layout()); +QWidget * GraphicAnalysis::toolboxWidget() { + return widget_toolbox; } -QWidget * GraphicAnalysis::toolboxWidget() { - return widget_toolbox; +void GraphicAnalysis::setShowSpectrum(bool on) { + ui->checkSpectrum->setChecked(on); } @@ -293,10 +296,15 @@ void GraphicAnalysis::gaMouseReleaseEvent(QPointF point, int buttons) { void GraphicAnalysis::gaRangeSelected(double start, double end) { - if (!ui->buttonSpectrumRange->isChecked()) return; - ui->buttonSpectrumRange->setChecked(false); - range_fft = GraphicRanges::Range(start, end); - updateAllGraphic(); + if (ui->buttonSpectrumRange->isChecked()) { + ui->buttonSpectrumRange->setChecked(false); + range_fft = GraphicRanges::Range(start, end); + updateAllGraphic(); + } + if (ui->buttonStatistics->isChecked()) { + ui->buttonStatistics->setChecked(false); + window_stat->show(this, GraphicRanges::Range(start, end)); + } } @@ -308,9 +316,10 @@ void GraphicAnalysis::checkSpectrum_toggled(bool on) { void GraphicAnalysis::buttonSpectrumRange_toggled(bool on) { setFFT(!on); - if (on) + if (on) { + ui->buttonStatistics->setChecked(false); checkRangeRequest(); - else + } else viewport()->unsetCursor(); } @@ -319,3 +328,12 @@ void GraphicAnalysis::checkSpectrumFixDuration_toggled(bool on) { checkRangeRequest(); emit configChanged(); } + + +void GraphicAnalysis::buttonStatistics_toggled(bool on) { + if (on) { + ui->buttonSpectrumRange->setChecked(false); + rangeRequest(); + } else + viewport()->unsetCursor(); +} diff --git a/libs/graphic_analysis/graphic_analysis.h b/libs/graphic_analysis/graphic_analysis.h index eda7344..b28fd34 100644 --- a/libs/graphic_analysis/graphic_analysis.h +++ b/libs/graphic_analysis/graphic_analysis.h @@ -29,11 +29,13 @@ namespace Ui { class GraphicAnalysis; } class GraphicAnalysisPlugin; +class GraphicAnalysisStatistics; class QAD_GRAPHIC_ANALYSIS_EXPORT GraphicAnalysis: public GraphicRanges { Q_OBJECT friend class GraphicAnalysisPlugin; Q_PROPERTY(bool toolboxVisible READ isToolboxVisible WRITE setToolboxVisible) + Q_PROPERTY(bool showSpectrum READ isShowSpectrum WRITE setShowSpectrum) public: GraphicAnalysis(QWidget * parent = 0); @@ -49,8 +51,8 @@ public: bool isToolboxVisible() const; void setToolboxVisible(bool yes); void setLabelX(const QString & str); - QBoxLayout * toolboxLayout(); QWidget * toolboxWidget(); + void setShowSpectrum(bool on); bool isShowSpectrum() const; void setGraphicsCount(int cnt, bool update = true); @@ -70,6 +72,7 @@ protected: void checkRangeRequest(); Ui::GraphicAnalysis * ui = nullptr; + GraphicAnalysisStatistics * window_stat; QWidget * widget_toolbox = nullptr; QMap src_data; GraphicRanges::Range range_fft; @@ -91,6 +94,7 @@ private slots: void checkSpectrum_toggled(bool on); void buttonSpectrumRange_toggled(bool on); void checkSpectrumFixDuration_toggled(bool on); + void buttonStatistics_toggled(bool on); signals: void showSpectrumChanged(bool); diff --git a/libs/graphic_analysis/graphic_analysis.ui b/libs/graphic_analysis/graphic_analysis.ui index 6687fd6..01481d5 100644 --- a/libs/graphic_analysis/graphic_analysis.ui +++ b/libs/graphic_analysis/graphic_analysis.ui @@ -20,6 +20,36 @@ 0 + + + + Select statistics input data + + + + :/icons/dialog-information.png:/icons/dialog-information.png + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 10 + 5 + + + + @@ -133,17 +163,12 @@ Qt::Horizontal - - - 104 - 0 - - + diff --git a/libs/graphic_analysis/graphic_analysis_stat.cpp b/libs/graphic_analysis/graphic_analysis_stat.cpp new file mode 100644 index 0000000..9b5138e --- /dev/null +++ b/libs/graphic_analysis/graphic_analysis_stat.cpp @@ -0,0 +1,66 @@ +#include "graphic_analysis_stat.h" + +#include "graphic_analysis.h" +#include "ui_graphic_analysis_stat.h" + +#include + + +GraphicAnalysisStatistics::GraphicAnalysisStatistics(QWidget * parent): QDialog(parent) { + ui = new Ui::GraphicAnalysisStatistics(); + ui->setupUi(this); +} + + +GraphicAnalysisStatistics::~GraphicAnalysisStatistics() { + delete ui; +} + + +void GraphicAnalysisStatistics::show(GraphicAnalysis * g, GraphicRanges::Range r) { + source = g; + range = r; + if (range.isEmpty()) range = source->rangeAll(); + ui->comboGraphic->clear(); + for (int i = 0; i < source->graphicsCount(); ++i) { + auto g = source->graphic(i); + ui->comboGraphic->addItem(g.icon, g.name); + } + QDialog::exec(); +} + + +void GraphicAnalysisStatistics::changeEvent(QEvent * e) { + QDialog::changeEvent(e); + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + return; + } +} + + +void GraphicAnalysisStatistics::on_comboGraphic_currentIndexChanged(int index) { + if (index < 0 || !source) return; + auto setNum = [](double v, QLineEdit * le) { le->setText(QString::number(v)); }; + const auto data = source->graphicData(index); + QPolygonF in; + for (const auto & i: data) { + if ((i.x() >= range.start) && (i.x() <= range.end)) in << i; + } + auto br = in.boundingRect(); + setNum(br.left(), ui->lineXMin); + setNum(br.right(), ui->lineXMax); + setNum(br.bottom(), ui->lineYMin); + setNum(br.top(), ui->lineYMax); + setNum(in.size(), ui->linePoints); + PIVector stat_in; + in.reserve(256); + for (const auto & i: in) + stat_in << i.y(); + PIStatisticd stat; + stat.calculate(stat_in); + setNum(stat.mean, ui->lineMean); + setNum(stat.variance, ui->lineVariance); + setNum(stat.skewness, ui->lineSkewness); + setNum(stat.kurtosis, ui->lineKurtosis); +} diff --git a/libs/graphic_analysis/graphic_analysis_stat.h b/libs/graphic_analysis/graphic_analysis_stat.h new file mode 100644 index 0000000..b71514d --- /dev/null +++ b/libs/graphic_analysis/graphic_analysis_stat.h @@ -0,0 +1,54 @@ +/* + QAD - Qt ADvanced + + Ivan Pelipenko peri4ko@yandex.ru + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#ifndef graphic_analysis_stat_h +#define graphic_analysis_stat_h + +#include "graphic_ranges.h" +#include "qad_graphic_analysis_export.h" + +#include + +namespace Ui { +class GraphicAnalysisStatistics; +} +class GraphicAnalysis; + +class QAD_GRAPHIC_ANALYSIS_EXPORT GraphicAnalysisStatistics: public QDialog { + Q_OBJECT + +public: + GraphicAnalysisStatistics(QWidget * parent = 0); + virtual ~GraphicAnalysisStatistics(); + + void show(GraphicAnalysis * g, GraphicRanges::Range r); + +protected: + void changeEvent(QEvent * e); + + Ui::GraphicAnalysisStatistics * ui = nullptr; + GraphicAnalysis * source = nullptr; + GraphicRanges::Range range; + +private slots: + void on_comboGraphic_currentIndexChanged(int index); +}; + + +#endif diff --git a/libs/graphic_analysis/graphic_analysis_stat.ui b/libs/graphic_analysis/graphic_analysis_stat.ui new file mode 100644 index 0000000..a97cc3a --- /dev/null +++ b/libs/graphic_analysis/graphic_analysis_stat.ui @@ -0,0 +1,238 @@ + + + GraphicAnalysisStatistics + + + + 0 + 0 + 417 + 488 + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + Graphic: + + + + + + + + + + Points: + + + + + + + true + + + + + + + + + Statistics + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + X min: + + + + + + + true + + + + + + + X max: + + + + + + + true + + + + + + + Mean: + + + + + + + true + + + + + + + Skewness: + + + + + + + true + + + + + + + Variance: + + + + + + + true + + + + + + + Kurtosis: + + + + + + + true + + + + + + + Y min: + + + + + + + Y max: + + + + + + + true + + + + + + + true + + + + + + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + QDialogButtonBox::Close + + + + + + + + + + + buttonBox + accepted() + GraphicAnalysisStatistics + accept() + + + 281 + 459 + + + 415 + 462 + + + + + buttonBox + rejected() + GraphicAnalysisStatistics + reject() + + + 395 + 447 + + + 413 + 447 + + + + + diff --git a/libs/graphic_analysis/lang/qad_graphic_analysis_en.ts b/libs/graphic_analysis/lang/qad_graphic_analysis_en.ts index 1738ed1..bbfc030 100644 --- a/libs/graphic_analysis/lang/qad_graphic_analysis_en.ts +++ b/libs/graphic_analysis/lang/qad_graphic_analysis_en.ts @@ -5,28 +5,91 @@ GraphicAnalysis + Select statistics input data + + + + Spectrum - + Select spectrum input data - + Fix dur.: - + s - + Hz + + GraphicAnalysisStatistics + + + Graphic: + + + + + Points: + + + + + Statistics + + + + + X min: + + + + + X max: + + + + + Mean: + + + + + Skewness: + + + + + Variance: + + + + + Kurtosis: + + + + + Y min: + + + + + Y max: + + + diff --git a/libs/graphic_analysis/lang/qad_graphic_analysis_ru.ts b/libs/graphic_analysis/lang/qad_graphic_analysis_ru.ts index bcb3d51..6a33a01 100644 --- a/libs/graphic_analysis/lang/qad_graphic_analysis_ru.ts +++ b/libs/graphic_analysis/lang/qad_graphic_analysis_ru.ts @@ -5,28 +5,91 @@ GraphicAnalysis + Select statistics input data + Выбрать данные для построения статистики + + + Spectrum Спектр - + Select spectrum input data Выбрать данные для построения спектра - + Fix dur.: Фикс. длит.: - + s с - + Hz Гц + + GraphicAnalysisStatistics + + + Graphic: + График: + + + + Points: + Точек: + + + + Statistics + Статистика + + + + X min: + X мин: + + + + X max: + X макс: + + + + Mean: + Среднее: + + + + Skewness: + Асимметрия: + + + + Variance: + Дисперсия: + + + + Kurtosis: + Эксцесс: + + + + Y min: + Y мин: + + + + Y max: + Y макс: + + diff --git a/libs/graphic_analysis/qad_graphic_analysis.qrc b/libs/graphic_analysis/qad_graphic_analysis.qrc index 93e0881..a21df69 100644 --- a/libs/graphic_analysis/qad_graphic_analysis.qrc +++ b/libs/graphic_analysis/qad_graphic_analysis.qrc @@ -2,5 +2,6 @@ ../../icons/axis_x.png ../../icons/graphic.png + ../../icons/dialog-information.png