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

add Reset button by Apply in the yaxis strategy selector #832 #833

Merged
merged 3 commits into from
Jul 11, 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
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", "All 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
14 changes: 14 additions & 0 deletions Source/GUI/yminmaxselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,17 @@ void YMinMaxSelector::on_customMinMax_radioButton_clicked()
updateMinMaxStyling();
}


void YMinMaxSelector::on_reset_pushButton_clicked()
{
QSettings settings;
settings.beginGroup("yminmax");
settings.remove(QString::number(m_plot->group()));
settings.endGroup();

m_plot->setYAxisCustomMinMax(0, 0);
m_plot->loadYAxisMinMaxMode();
m_plot->replot();
hide();
}

2 changes: 2 additions & 0 deletions Source/GUI/yminmaxselector.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ private Q_SLOTS:
void on_minMaxSystemProvided_radioButton_clicked();
void on_customMinMax_radioButton_clicked();

void on_reset_pushButton_clicked();

private:
void updateApplyButton();
void updateMinMaxStyling();
Expand Down
41 changes: 24 additions & 17 deletions Source/GUI/yminmaxselector.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>550</width>
<width>579</width>
<height>192</height>
</rect>
</property>
Expand All @@ -17,7 +17,27 @@
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="3">
<item row="1" column="2">
<widget class="QPushButton" name="apply_pushButton">
<property name="text">
<string>Apply</string>
</property>
</widget>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>132</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="4">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Set the y-axis range</string>
Expand Down Expand Up @@ -177,25 +197,12 @@
</spacer>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="apply_pushButton">
<widget class="QPushButton" name="reset_pushButton">
<property name="text">
<string>Apply</string>
<string>Reset</string>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>132</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
Expand Down
Loading