Skip to content

Commit

Permalink
add Reset button by Apply in the yaxis strategy selector bavc#832
Browse files Browse the repository at this point in the history
  • Loading branch information
ElderOrb committed Jul 9, 2024
1 parent 0950ff3 commit ecc8cc5
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 32 deletions.
70 changes: 38 additions & 32 deletions Source/GUI/Plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,43 @@ bool Plot::isBarchart() const
return m_barchart;
}

void Plot::loadYAxisMinMaxMode()
{
const struct per_group& group = PerStreamType[m_type].PerGroup[m_group];

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();
}

void Plot::setYAxisMinMaxMode(YMinMaxMode mode)
{
m_yminMaxMode = mode;
Expand Down Expand Up @@ -813,38 +850,7 @@ Plot::Plot( size_t streamPos, size_t Type, size_t Group, const FileInformation*
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();

loadYAxisMinMaxMode();
}

//---------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions Source/GUI/Plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ class Plot : public QwtPlot
public Q_SLOTS:
void initYAxis();
void setBarchart(bool value);
void loadYAxisMinMaxMode(); // default or from settings

private Q_SLOTS:
void onPickerMoved( const QPointF& );
Expand Down
17 changes: 17 additions & 0 deletions Source/GUI/Plots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <QToolButton>
#include <QVideoFrame>
#include <qwt_plot_curve.h>
#include <QMessageBox>
#include <QSettings>

//---------------------------------------------------------------------------

Expand Down Expand Up @@ -177,6 +179,8 @@ Plots::Plots( QWidget *parent, FileInformation* fileInformation ) :
qDebug() << "Plot::visibilityChanged for " << plot << "visible: " << visible;
});

connect(this, &Plots::reloadYAxisMinMaxMode, plot, &Plot::loadYAxisMinMaxMode);

const size_t plotType = plot->type();
const size_t plotGroup = plot->group();
const CommonStats* stat = stats( plot->streamPos() );
Expand Down Expand Up @@ -1348,6 +1352,19 @@ void Plots::updatePlotsVisibility(const QMap<QString, std::tuple<quint64, quint6
}
}

void Plots::updatePlotsYAxisMinMaxMode()
{
auto reply = QMessageBox::question(this, "QCTools", "Y axis min/max to will be reset default. Are you sure?",
QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes) {
QSettings settings;
settings.remove("yminmax");

Q_EMIT reloadYAxisMinMaxMode();
replotAll();
}
}

//---------------------------------------------------------------------------
void Plots::zoomXAxis( ZoomTypes zoomType )
{
Expand Down
2 changes: 2 additions & 0 deletions Source/GUI/Plots.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class Plots : public QWidget
void setPlotVisible( size_t type, size_t group, bool on );
void setCommentsVisible(bool visible);
void updatePlotsVisibility(const QMap<QString, std::tuple<quint64, quint64>> & visiblePlots);
void updatePlotsYAxisMinMaxMode();

const QwtPlot* plot( size_t streamPos, size_t group ) const;
CommentsPlot* commentsPlot() const { return m_commentsPlot; }
Expand Down Expand Up @@ -123,6 +124,7 @@ class Plots : public QWidget
Q_SIGNALS:
void visibleFramesChanged(int from, int to);
void barchartProfileChanged();
void reloadYAxisMinMaxMode();

public Q_SLOTS:
void onCurrentFrameChanged();
Expand Down
7 changes: 7 additions & 0 deletions Source/GUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,3 +1060,10 @@ void MainWindow::on_setupFilters_pushButton_clicked()
m_plotsChooser->setGeometry(newGeometry);
}
}

void MainWindow::on_actionReset_all_y_axis_ranges_to_default_triggered()
{
if(PlotsArea)
PlotsArea->updatePlotsYAxisMinMaxMode();
}

2 changes: 2 additions & 0 deletions Source/GUI/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ private Q_SLOTS:

void on_setupFilters_pushButton_clicked();

void on_actionReset_all_y_axis_ranges_to_default_triggered();

protected:
void closeEvent(QCloseEvent* event);
void resizeEvent(QResizeEvent* event);
Expand Down
6 changes: 6 additions & 0 deletions Source/GUI/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
<addaction name="actionNavigateNextComment"/>
<addaction name="separator"/>
<addaction name="actionToolbar"/>
<addaction name="actionReset_all_y_axis_ranges_to_default"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
Expand Down Expand Up @@ -709,6 +710,11 @@
<string>Show / hide filters panel</string>
</property>
</action>
<action name="actionReset_all_y_axis_ranges_to_default">
<property name="text">
<string>Reset all y-axis ranges to default</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down

0 comments on commit ecc8cc5

Please sign in to comment.