Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ElderOrb committed May 11, 2024
1 parent 25ea0fe commit 0f78bda
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 19 deletions.
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
45 changes: 29 additions & 16 deletions Source/GUI/Plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions Source/GUI/Plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
21 changes: 21 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,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 ),
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}

//---------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions Source/GUI/Plots.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<PanelsView*> m_PanelsViews;
Expand Down
24 changes: 24 additions & 0 deletions Source/GUI/yminmaxselector.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
25 changes: 25 additions & 0 deletions Source/GUI/yminmaxselector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef YMINMAXSELECTOR_H
#define YMINMAXSELECTOR_H

#include <QWidget>

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
107 changes: 107 additions & 0 deletions Source/GUI/yminmaxselector.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>YMinMaxSelector</class>
<widget class="QWidget" name="YMinMaxSelector">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>156</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Select y-axis min/max</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QRadioButton" name="minMaxOfThePlot_radioButton">
<property name="text">
<string>min/max value of the plot</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="minMaxSystemProvided_radioButton">
<property name="text">
<string>system provided min/max</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="customMinMax_radioButton">
<property name="text">
<string>custom</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="min_label">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="min_doubleSpinBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="max_label">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="max_doubleSpinBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

0 comments on commit 0f78bda

Please sign in to comment.