From 0f78bda6f69296ce927e1b7dd488b9e2cc7ec27d Mon Sep 17 00:00:00 2001 From: Alexander Ivash Date: Sat, 11 May 2024 15:49:11 +0200 Subject: [PATCH] wip --- Project/QtCreator/qctools-gui/qctools-gui.pro | 9 +- Source/GUI/Plot.cpp | 45 +++++--- Source/GUI/Plot.h | 10 ++ Source/GUI/Plots.cpp | 21 ++++ Source/GUI/Plots.h | 3 + Source/GUI/yminmaxselector.cpp | 24 ++++ Source/GUI/yminmaxselector.h | 25 ++++ Source/GUI/yminmaxselector.ui | 107 ++++++++++++++++++ 8 files changed, 225 insertions(+), 19 deletions(-) create mode 100644 Source/GUI/yminmaxselector.cpp create mode 100644 Source/GUI/yminmaxselector.h create mode 100644 Source/GUI/yminmaxselector.ui diff --git a/Project/QtCreator/qctools-gui/qctools-gui.pro b/Project/QtCreator/qctools-gui/qctools-gui.pro index 2c7112ec7..320ab5611 100644 --- a/Project/QtCreator/qctools-gui/qctools-gui.pro +++ b/Project/QtCreator/qctools-gui/qctools-gui.pro @@ -75,7 +75,8 @@ HEADERS += \ $$SOURCES_PATH/GUI/filterselector.h \ $$SOURCES_PATH/GUI/playercontrol.h \ $$SOURCES_PATH/GUI/panelsview.h \ - $$SOURCES_PATH/GUI/plotschooser.h + $$SOURCES_PATH/GUI/plotschooser.h \ + $$SOURCES_PATH/GUI/yminmaxselector.h SOURCES += \ $$SOURCES_PATH/GUI/FilesList.cpp \ @@ -108,7 +109,8 @@ SOURCES += \ $$SOURCES_PATH/GUI/filterselector.cpp \ $$SOURCES_PATH/GUI/playercontrol.cpp \ $$SOURCES_PATH/GUI/panelsview.cpp \ - $$SOURCES_PATH/GUI/plotschooser.cpp + $$SOURCES_PATH/GUI/plotschooser.cpp \ + $$SOURCES_PATH/GUI/yminmaxselector.cpp include(../zlib.pri) @@ -121,7 +123,8 @@ FORMS += \ $$SOURCES_PATH/GUI/barchartconditioninput.ui \ $$SOURCES_PATH/GUI/managebarchartconditions.ui \ $$SOURCES_PATH/GUI/playercontrol.ui \ - $$SOURCES_PATH/GUI/plotschooser.ui + $$SOURCES_PATH/GUI/plotschooser.ui \ + $$SOURCES_PATH/GUI/yminmaxselector.ui \ RESOURCES += \ $$SOURCES_PATH/Resource/Resources.qrc diff --git a/Source/GUI/Plot.cpp b/Source/GUI/Plot.cpp index d7fad43f8..e0448b51f 100644 --- a/Source/GUI/Plot.cpp +++ b/Source/GUI/Plot.cpp @@ -346,30 +346,37 @@ void Plot::initYAxis() } else { + auto yMin = 0.0; + auto yMax = 0.0; const size_t plotType = type(); const size_t plotGroup = group(); CommonStats* stat = stats( streamPos() ); const struct per_group& group = PerStreamType[plotType].PerGroup[plotGroup]; - auto yMin = 0.0; - if(m_minValue.isNull() || m_minValue.isError() || m_minValue.isUndefined()) { - yMin = stat->y_Min[plotGroup]; // auto-select min - } else { - if(m_minValue.isNumber()) - yMin = m_minValue.toNumber(); - else if(m_minValue.isCallable()) - yMin = m_minValue.call().toNumber(); - } + if(m_yminMaxMode == Default) + { + if(m_minValue.isNull() || m_minValue.isError() || m_minValue.isUndefined()) { + yMin = stat->y_Min[plotGroup]; // auto-select min + } else { + if(m_minValue.isNumber()) + yMin = m_minValue.toNumber(); + else if(m_minValue.isCallable()) + yMin = m_minValue.call().toNumber(); + } - auto yMax = 0.0; - if(m_maxValue.isNull() || m_maxValue.isError() || m_maxValue.isUndefined()) { + if(m_maxValue.isNull() || m_maxValue.isError() || m_maxValue.isUndefined()) { + yMax = stat->y_Max[plotGroup]; // auto-select min + } else { + if(m_maxValue.isNumber()) + yMax = m_maxValue.toNumber(); + else if(m_maxValue.isCallable()) + yMax = m_maxValue.call().toNumber(); + } + } else if(m_yminMaxMode == MinMaxOfThePlot) { + + yMin = stat->y_Min[plotGroup]; // auto-select min yMax = stat->y_Max[plotGroup]; // auto-select min - } else { - if(m_maxValue.isNumber()) - yMax = m_maxValue.toNumber(); - else if(m_maxValue.isCallable()) - yMax = m_maxValue.call().toNumber(); } setYAxis( yMin, yMax, group.StepsCount ); @@ -428,6 +435,12 @@ bool Plot::isBarchart() const return m_barchart; } +void Plot::setYAxisMinMaxMode(YMinMaxMode mode) +{ + m_yminMaxMode = mode; + initYAxis(); +} + void Plot::setBarchart(bool value) { if(m_barchart != value) diff --git a/Source/GUI/Plot.h b/Source/GUI/Plot.h index 12138aa3a..e3f30425f 100644 --- a/Source/GUI/Plot.h +++ b/Source/GUI/Plot.h @@ -437,6 +437,12 @@ class Plot : public QwtPlot Q_OBJECT public: + enum YMinMaxMode { + Default, + MinMaxOfThePlot, + Custom + }; + explicit Plot( size_t streamPos, size_t Type, size_t Group, const FileInformation* fileInformation, QWidget *parent ); virtual ~Plot(); @@ -472,6 +478,7 @@ class Plot : public QwtPlot void updateSymbols(); bool isBarchart() const; + void setYAxisMinMaxMode(YMinMaxMode mode); Q_SIGNALS: void cursorMoved(const QPointF& point, int index); void visibilityChanged(bool visible); @@ -488,6 +495,9 @@ private Q_SLOTS: const QwtPlotCurve* curve( int index ) const; QColor curveColor( int index ) const; + YMinMaxMode m_yminMaxMode { Default }; + double m_customYMin { 0.0 }; + double m_customYMax { 0.0 }; QJSValue m_maxValue; QJSValue m_minValue; QJSEngine m_engine; diff --git a/Source/GUI/Plots.cpp b/Source/GUI/Plots.cpp index 8473e1e48..a2716299a 100755 --- a/Source/GUI/Plots.cpp +++ b/Source/GUI/Plots.cpp @@ -17,6 +17,7 @@ #include "Core/Core.h" #include #include "playercontrol.h" +#include "yminmaxselector.h" #include #include #include @@ -123,6 +124,16 @@ void Plots::showEditBarchartProfileDialog(const size_t plotGroup, Plot* plot, co } } +void Plots::showYMinMaxConfigDialog(const size_t plotGroup, Plot *plot, const stream_info &streamInfo, QToolButton* button) +{ + auto globalButtonPos = button->mapToGlobal(QPoint(0, 0)); + auto geometry = m_yMinMaxSelector->geometry(); + + m_yMinMaxSelector->move(QPoint(globalButtonPos.x() - geometry.width(), globalButtonPos.y())); + if(!m_yMinMaxSelector->isVisible()) + m_yMinMaxSelector->show(); +} + Plots::Plots( QWidget *parent, FileInformation* fileInformation ) : QWidget( parent ), m_zoomFactor ( 0 ), @@ -282,11 +293,18 @@ Plots::Plots( QWidget *parent, FileInformation* fileInformation ) : barchartPlotSwitch->setIcon(switchToBarcharts ? QIcon(":/icon/chart_chart.png") : QIcon(":/icon/bar_chart.png")); }); + QToolButton* yMinMaxConfigButton = new QToolButton(); + connect(plot, SIGNAL(visibilityChanged(bool)), yMinMaxConfigButton, SLOT(setVisible(bool))); + connect(yMinMaxConfigButton, &QToolButton::clicked, [=]() { + showYMinMaxConfigDialog(plotGroup, plot, streamInfo, yMinMaxConfigButton); + }); + QHBoxLayout* barchartAndConfigurationLayout = new QHBoxLayout(); barchartAndConfigurationLayout->setAlignment(Qt::AlignLeft); barchartAndConfigurationLayout->setSpacing(5); barchartAndConfigurationLayout->addWidget(barchartPlotSwitch); barchartAndConfigurationLayout->addWidget(barchartConfigButton); + barchartAndConfigurationLayout->addWidget(yMinMaxConfigButton); legendLayout->addItem(barchartAndConfigurationLayout); legendLayout->addWidget(plot->plotLegend()); @@ -496,6 +514,9 @@ Plots::Plots( QWidget *parent, FileInformation* fileInformation ) : m_scaleWidget->setScale( m_timeInterval.from, m_timeInterval.to); setCursorPos( framePos() ); + + m_yMinMaxSelector = new YMinMaxSelector(this); + m_yMinMaxSelector->setWindowFlag(Qt::Popup); } //--------------------------------------------------------------------------- diff --git a/Source/GUI/Plots.h b/Source/GUI/Plots.h index 65f9a303c..ce24e2fe4 100755 --- a/Source/GUI/Plots.h +++ b/Source/GUI/Plots.h @@ -22,6 +22,7 @@ class QwtPlot; class Plot; class PlotScaleWidget; class PlayerControl; +class YMinMaxSelector; void showEditFrameCommentsDialog(QWidget* parentWidget, FileInformation* info, CommonStats* stats, size_t frameIndex); @@ -116,6 +117,7 @@ class Plots : public QWidget void loadBarchartsProfile(const QJsonObject& profile); void showEditBarchartProfileDialog(const size_t plotGroup, Plot* plot, const stream_info& streamInfo); + void showYMinMaxConfigDialog(const size_t plotGroup, Plot* plot, const stream_info& streamInfo, QToolButton* button); Q_SIGNALS: void visibleFramesChanged(int from, int to); @@ -146,6 +148,7 @@ private Q_SLOTS: void setFramePos( size_t framePos, size_t statsPos = (size_t)-1 ) const { m_fileInfoData->Frames_Pos_Set(framePos, statsPos); } private: + YMinMaxSelector* m_yMinMaxSelector; PlotScaleWidget* m_scaleWidget; CommentsPlot* m_commentsPlot; std::vector m_PanelsViews; diff --git a/Source/GUI/yminmaxselector.cpp b/Source/GUI/yminmaxselector.cpp new file mode 100644 index 000000000..f50c6f0e2 --- /dev/null +++ b/Source/GUI/yminmaxselector.cpp @@ -0,0 +1,24 @@ +#include "yminmaxselector.h" +#include "ui_yminmaxselector.h" + +YMinMaxSelector::YMinMaxSelector(QWidget *parent) + : QWidget(parent) + , ui(new Ui::YMinMaxSelector) +{ + ui->setupUi(this); + + connect(ui->customMinMax_radioButton, &QRadioButton::toggled, this, &YMinMaxSelector::activateCustomMinMax); +} + +YMinMaxSelector::~YMinMaxSelector() +{ + delete ui; +} + +void YMinMaxSelector::activateCustomMinMax(bool value) +{ + ui->min_label->setEnabled(value); + ui->min_doubleSpinBox->setEnabled(value); + ui->max_label->setEnabled(value); + ui->max_doubleSpinBox->setEnabled(value); +} diff --git a/Source/GUI/yminmaxselector.h b/Source/GUI/yminmaxselector.h new file mode 100644 index 000000000..bf67d3c82 --- /dev/null +++ b/Source/GUI/yminmaxselector.h @@ -0,0 +1,25 @@ +#ifndef YMINMAXSELECTOR_H +#define YMINMAXSELECTOR_H + +#include + +namespace Ui { +class YMinMaxSelector; +} + +class YMinMaxSelector : public QWidget +{ + Q_OBJECT + +public: + explicit YMinMaxSelector(QWidget *parent = nullptr); + ~YMinMaxSelector(); + +private Q_SLOTS: + void activateCustomMinMax(bool value); + +private: + Ui::YMinMaxSelector *ui; +}; + +#endif // YMINMAXSELECTOR_H diff --git a/Source/GUI/yminmaxselector.ui b/Source/GUI/yminmaxselector.ui new file mode 100644 index 000000000..31a128f01 --- /dev/null +++ b/Source/GUI/yminmaxselector.ui @@ -0,0 +1,107 @@ + + + YMinMaxSelector + + + + 0 + 0 + 400 + 156 + + + + Form + + + true + + + + + + Select y-axis min/max + + + + + + min/max value of the plot + + + + + + + system provided min/max + + + true + + + + + + + + + custom + + + + + + + false + + + min: + + + + + + + false + + + + 0 + 0 + + + + + + + + false + + + max: + + + + + + + false + + + + 0 + 0 + + + + + + + + + + + + + +