Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

give an option for a toggle button on graphs to change y-axis min/max… #825

Merged
merged 6 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Project/QtCreator/qctools-gui/qctools-gui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct per_group
const bool CheckedByDefault;
const char* Description;
activefilter ActiveFilterGroup;
const char* YAxisMinMaxMode;
};

struct per_item
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/VideoCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct per_group VideoPerGroup [Group_VideoMax]=
"LOW (10th percentile), and HIGH (90th percentile) values for each frame.\n"
"The Y plane provides information about video brightness or luminance.",
ActiveFilter_Video_signalstats,
"MinMaxOfThePlot",
},
//U
{
Expand All @@ -25,6 +26,7 @@ struct per_group VideoPerGroup [Group_VideoMax]=
"LOW (10th percentile), and HIGH (90th percentile) values for each frame.\n"
"The U plane (along with V) provides information about video color.",
ActiveFilter_Video_signalstats,
"Formula",
},
//V
{
Expand All @@ -33,6 +35,7 @@ struct per_group VideoPerGroup [Group_VideoMax]=
"LOW (10th percentile), and HIGH (90th percentile) values for each frame.\n"
"The V plane (along with U) provides information about video color.",
ActiveFilter_Video_signalstats,
"Custom;0;55"
},
//YDiff
{
Expand Down
121 changes: 112 additions & 9 deletions Source/GUI/Plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <qwt_clipper.h>

#include "Core/FileInformation.h"
#include <QMetaEnum>
#include <QSettings>
#include <cassert>
#include <optional>

Expand Down Expand Up @@ -438,31 +440,35 @@ 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_yminMaxMode == Formula)
{
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()) {
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 max
} else if(m_yminMaxMode == Custom)
{
yMin = m_customYMin;
yMax = m_customYMax;
}

setYAxis( yMin, yMax, group.StepsCount );
}
Expand Down Expand Up @@ -520,6 +526,61 @@ bool Plot::isBarchart() const
return m_barchart;
}

void Plot::setYAxisMinMaxMode(YMinMaxMode mode)
{
m_yminMaxMode = mode;
QColor color;
switch(m_yminMaxMode) {
case MinMaxOfThePlot:
color = "darkblue";
break;
case Formula:
color = "black";
break;
case Custom:
color = QColor(85, 0, 127);
break;
}

setYAxisColor(color);
initYAxis();
}

Plot::YMinMaxMode Plot::yAxisMinMaxMode() const
{
return m_yminMaxMode;
}

void Plot::setYAxisCustomMinMax(double min, double max)
{
m_customYMin = min;
m_customYMax = max;
}

void Plot::getYAxisCustomMinMax(double &min, double &max)
{
min = m_customYMin;
max = m_customYMax;
}

bool Plot::hasMinMaxFormula() const
{
if(m_minValue.isNull() || m_minValue.isError() || m_minValue.isUndefined()) {
return false;
}

if(m_maxValue.isNull() || m_maxValue.isError() || m_maxValue.isUndefined()) {
return false;
}

return true;
}

const CommonStats *Plot::getStats() const
{
return stats( streamPos() );
}

void Plot::setBarchart(bool value)
{
if(m_barchart != value)
Expand Down Expand Up @@ -751,6 +812,39 @@ Plot::Plot( size_t streamPos, size_t Type, size_t Group, const FileInformation*
#else
panner->setMouseButton( Qt::MiddleButton );
#endif // QT_VERSION < QT_VERSION_CHECK(6, 0, 0)

auto applyYMinMaxMode = [&](QString value) {
QMetaEnum metaEnum = QMetaEnum::fromType<Plot::YMinMaxMode>();
auto splitted = value.split(";");
auto yMinMaxMode = (Plot::YMinMaxMode) metaEnum.keyToValue(splitted[0].toLatin1().constData());

if(yMinMaxMode == Plot::Custom) {
auto min = splitted[1].toDouble();
auto max = splitted[2].toDouble();

setYAxisCustomMinMax(min, max);
}

setYAxisMinMaxMode(yMinMaxMode);
};

if(group.YAxisMinMaxMode) {
QString yMinMaxModeStringValue = group.YAxisMinMaxMode;
qDebug() << "applying default yMinMaxMode: " << yMinMaxModeStringValue;
applyYMinMaxMode(yMinMaxModeStringValue);
}

QSettings settings;
settings.beginGroup("yminmax");

QString value = settings.value(QString::number(m_group)).toString();
if(!value.isEmpty()) {
qDebug() << "applying yMinMaxMode from settings: " << value;
applyYMinMaxMode(value);
}

settings.endGroup();

}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -791,6 +885,15 @@ QSize Plot::minimumSizeHint() const
return QSize( hint.width(), -1 );
}

void Plot::setYAxisColor(QColor color)
{
auto yAxis = axisWidget(QwtPlot::yLeft);
QPalette palette = yAxis->palette();
palette.setColor(QPalette::WindowText, color); // for ticks
palette.setColor(QPalette::Text, color); // for ticks' labels
yAxis->setPalette(palette);
}

const QwtPlotCurve* Plot::curve( int index ) const
{
const QwtPlotItemList curves = itemList( QwtPlotItem::Rtti_PlotCurve );
Expand Down
20 changes: 20 additions & 0 deletions Source/GUI/Plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,13 @@ class Plot : public QwtPlot
Q_OBJECT

public:
enum YMinMaxMode {
MinMaxOfThePlot,
Formula,
Custom
};
Q_ENUM(YMinMaxMode);

explicit Plot( size_t streamPos, size_t Type, size_t Group, const FileInformation* fileInformation, QWidget *parent );
virtual ~Plot();

Expand All @@ -446,6 +453,7 @@ class Plot : public QwtPlot
virtual QSize sizeHint() const;
virtual QSize minimumSizeHint() const;

void setYAxisColor(QColor color);
void setYAxis( double min, double max, int numSteps );
void setCursorPos( double x );

Expand All @@ -472,6 +480,15 @@ class Plot : public QwtPlot
void updateSymbols();
bool isBarchart() const;

void setYAxisMinMaxMode(YMinMaxMode mode);
YMinMaxMode yAxisMinMaxMode() const;

void setYAxisCustomMinMax(double min, double max);
void getYAxisCustomMinMax(double& min, double& max);

bool hasMinMaxFormula() const;

const CommonStats* getStats() const;
Q_SIGNALS:
void cursorMoved(const QPointF& point, int index);
void visibilityChanged(bool visible);
Expand All @@ -488,6 +505,9 @@ private Q_SLOTS:
const QwtPlotCurve* curve( int index ) const;
QColor curveColor( int index ) const;

YMinMaxMode m_yminMaxMode { MinMaxOfThePlot };
double m_customYMin { 0.0 };
double m_customYMax { 0.0 };
QJSValue m_maxValue;
QJSValue m_minValue;
QJSEngine m_engine;
Expand Down
24 changes: 24 additions & 0 deletions Source/GUI/Plots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Core/Core.h"
#include <QtAVPlayer/qavplayer.h>
#include "playercontrol.h"
#include "yminmaxselector.h"
#include <QComboBox>
#include <QGridLayout>
#include <QEvent>
Expand Down Expand Up @@ -123,6 +124,18 @@ 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->setPlot(plot);
m_yMinMaxSelector->enableFormulaMinMax(plot->hasMinMaxFormula());
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 ),
Expand Down Expand Up @@ -282,11 +295,19 @@ Plots::Plots( QWidget *parent, FileInformation* fileInformation ) :
barchartPlotSwitch->setIcon(switchToBarcharts ? QIcon(":/icon/chart_chart.png") : QIcon(":/icon/bar_chart.png"));
});

QToolButton* yMinMaxConfigButton = new QToolButton();
yMinMaxConfigButton->setIcon(QIcon(":/icon/signalserver_upload.png"));
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());
Expand Down Expand Up @@ -496,6 +517,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);
}

//---------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions Source/GUI/Plots.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class QwtPlot;
class Plot;
class PlotScaleWidget;
class PlayerControl;
class YMinMaxSelector;
class QToolButton;

void showEditFrameCommentsDialog(QWidget* parentWidget, FileInformation* info, CommonStats* stats, size_t frameIndex);

Expand Down Expand Up @@ -116,6 +118,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);
Expand Down Expand Up @@ -146,6 +149,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<PanelsView*> m_PanelsViews;
Expand Down
Loading
Loading