Skip to content

Commit 9156ece

Browse files
authored
Merge pull request #61 from ChrisHal/feature_global_autoscale
new feature: global autoscale (all displayed traces are regarded when autoscaling)
2 parents 74bc289 + 511d1e3 commit 9156ece

File tree

5 files changed

+107
-57
lines changed

5 files changed

+107
-57
lines changed

QtPMbrowser/DlgGraphSettings.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ void DlgGraphSettings::selectBkTraceColor()
7070
}
7171
}
7272

73-
void DlgGraphSettings::setValues(bool autoscale, double xmin, double xmax, double ymin, double ymax,
73+
void DlgGraphSettings::setValues(bool autoscale, bool global_autoscale,
74+
double xmin, double xmax, double ymin, double ymax,
7475
int numtraces, bool grid_horz, bool grid_vert, bool shift_all_y_scales,
7576
QColor color_grid, QColor color_trace, QColor color_bktrace)
7677
{
7778
QLocale loc{};
7879
ui.checkBoxEnableAutoscale->setChecked(autoscale);
80+
ui.checkBoxGlobalAutoscale->setChecked(global_autoscale);
7981
ui.checkBoxHorzGrid->setChecked(grid_horz);
8082
ui.checkBoxVertGrid->setChecked(grid_vert);
8183
ui.checkBoxShiftAllYScales->setChecked(shift_all_y_scales);
@@ -92,12 +94,14 @@ void DlgGraphSettings::setValues(bool autoscale, double xmin, double xmax, doubl
9294
ui.widgetColorBkTrace->setPalette(QPalette(m_color_bktrace));
9395
}
9496

95-
void DlgGraphSettings::getValues(bool& autoscale, double& xmin, double& xmax, double& ymin, double& ymax,
97+
void DlgGraphSettings::getValues(bool& autoscale, bool& global_autoscale,
98+
double& xmin, double& xmax, double& ymin, double& ymax,
9699
int& numtraces, bool& grid_horz, bool& grid_vert, bool& shift_all_y_scales,
97100
QColor& color_grid, QColor& color_trace, QColor& color_bktrace)
98101
{
99102
QLocale loc{};
100103
autoscale = ui.checkBoxEnableAutoscale->isChecked();
104+
global_autoscale = ui.checkBoxGlobalAutoscale->isChecked();
101105
grid_horz = ui.checkBoxHorzGrid->isChecked();
102106
grid_vert = ui.checkBoxVertGrid->isChecked();
103107
shift_all_y_scales = ui.checkBoxShiftAllYScales->isChecked();

QtPMbrowser/DlgGraphSettings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ private slots:
3535
public:
3636
DlgGraphSettings(QWidget *parent = Q_NULLPTR);
3737
~DlgGraphSettings();
38-
void setValues(bool autoscale, double xmin, double xmax,
38+
void setValues(bool autoscale, bool global_autoscale, double xmin, double xmax,
3939
double ymin, double ymax, int numtraces, bool grid_horz, bool gird_vert,
4040
bool shift_all_y_scales,
4141
QColor color_grid, QColor color_trace, QColor color_bktrace);
42-
void getValues(bool& autoscale, double& xmin, double& xmax,
42+
void getValues(bool& autoscale, bool& global_autoscale, double& xmin, double& xmax,
4343
double& ymin, double& ymax, int& numtraces,
4444
bool& grid_horz, bool& gird_vert, bool& shift_all_y_scales,
4545
QColor& color_grid, QColor& color_trace, QColor& color_bktrace);

QtPMbrowser/DlgGraphSettings.ui

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@
77
<x>0</x>
88
<y>0</y>
99
<width>359</width>
10-
<height>447</height>
10+
<height>501</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Graph Settings &amp; Axis Ranges</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout_2">
17-
<item row="1" column="0">
18-
<widget class="QCheckBox" name="checkBoxHorzGrid">
17+
<item row="3" column="0">
18+
<widget class="QCheckBox" name="checkBoxVertGrid">
1919
<property name="text">
20-
<string>show horizontal grid lines</string>
20+
<string>show vertical grid lines</string>
2121
</property>
2222
</widget>
2323
</item>
2424
<item row="2" column="0">
25-
<widget class="QCheckBox" name="checkBoxVertGrid">
25+
<widget class="QCheckBox" name="checkBoxHorzGrid">
2626
<property name="text">
27-
<string>show vertical grid lines</string>
27+
<string>show horizontal grid lines</string>
2828
</property>
2929
</widget>
3030
</item>
@@ -35,27 +35,7 @@
3535
</property>
3636
</widget>
3737
</item>
38-
<item row="6" column="1">
39-
<widget class="QLineEdit" name="lineEditNumTraces"/>
40-
</item>
41-
<item row="6" column="0">
42-
<widget class="QLabel" name="label_5">
43-
<property name="text">
44-
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Number of traces to hold&lt;br/&gt;in persistance buffer (max. 99)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
45-
</property>
46-
</widget>
47-
</item>
48-
<item row="8" column="0" colspan="2">
49-
<widget class="QDialogButtonBox" name="buttonBox">
50-
<property name="orientation">
51-
<enum>Qt::Orientation::Horizontal</enum>
52-
</property>
53-
<property name="standardButtons">
54-
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
55-
</property>
56-
</widget>
57-
</item>
58-
<item row="5" column="0" colspan="2">
38+
<item row="6" column="0" colspan="2">
5939
<widget class="QGroupBox" name="groupBox">
6040
<property name="title">
6141
<string>Axis Ranges</string>
@@ -134,14 +114,33 @@
134114
</layout>
135115
</widget>
136116
</item>
137-
<item row="3" column="0">
138-
<widget class="QCheckBox" name="checkBoxShiftAllYScales">
139-
<property name="text">
140-
<string>dragging affects all Y scales</string>
117+
<item row="9" column="0" colspan="2">
118+
<widget class="QDialogButtonBox" name="buttonBox">
119+
<property name="orientation">
120+
<enum>Qt::Orientation::Horizontal</enum>
121+
</property>
122+
<property name="standardButtons">
123+
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
141124
</property>
142125
</widget>
143126
</item>
144-
<item row="4" column="0" colspan="2">
127+
<item row="8" column="0" colspan="2">
128+
<spacer name="verticalSpacer">
129+
<property name="orientation">
130+
<enum>Qt::Orientation::Vertical</enum>
131+
</property>
132+
<property name="sizeHint" stdset="0">
133+
<size>
134+
<width>20</width>
135+
<height>40</height>
136+
</size>
137+
</property>
138+
</spacer>
139+
</item>
140+
<item row="7" column="1">
141+
<widget class="QLineEdit" name="lineEditNumTraces"/>
142+
</item>
143+
<item row="5" column="0" colspan="2">
145144
<widget class="QGroupBox" name="groupBoxColors">
146145
<property name="title">
147146
<string>Select Line Colors</string>
@@ -192,18 +191,26 @@
192191
</layout>
193192
</widget>
194193
</item>
195-
<item row="7" column="0" colspan="2">
196-
<spacer name="verticalSpacer">
197-
<property name="orientation">
198-
<enum>Qt::Orientation::Vertical</enum>
194+
<item row="4" column="0">
195+
<widget class="QCheckBox" name="checkBoxShiftAllYScales">
196+
<property name="text">
197+
<string>dragging affects all Y scales</string>
199198
</property>
200-
<property name="sizeHint" stdset="0">
201-
<size>
202-
<width>20</width>
203-
<height>40</height>
204-
</size>
199+
</widget>
200+
</item>
201+
<item row="7" column="0">
202+
<widget class="QLabel" name="label_5">
203+
<property name="text">
204+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Number of traces to hold&lt;br/&gt;in persistance buffer (max. 99)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
205205
</property>
206-
</spacer>
206+
</widget>
207+
</item>
208+
<item row="1" column="0">
209+
<widget class="QCheckBox" name="checkBoxGlobalAutoscale">
210+
<property name="text">
211+
<string>autoscale regards all displayed trace</string>
212+
</property>
213+
</widget>
207214
</item>
208215
</layout>
209216
</widget>

QtPMbrowser/renderarea.cpp

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ RenderArea::RenderArea(QWidget* parent) :
5050
clipped{ false },
5151
x_min{ 0.0 }, x_max{ 0.0 },
5252
a_x{}, b_x{}, a_y{}, b_y{}, numtraces{ 10 },
53-
do_autoscale_on_load{ true }, isTraceDragging{ false }, isPinching{false},
53+
do_autoscale_on_load{ true }, global_autoscale{false},
54+
isTraceDragging{ false }, isPinching{false},
5455
isSelecting{ false }, selStart{}, selEnd{}, tempPixMap{ nullptr },
5556
settings_modified{ false }
5657
{
@@ -565,18 +566,51 @@ static void find_min_max(std::vector<double>::const_iterator first,
565566
void RenderArea::autoScale()
566567
{
567568
if (noData()) return;
568-
if (isXYmode()) {
569-
find_min_max(xTrace.data.cbegin(), xTrace.data.cend(), x_min, x_max);
569+
570+
double g_x_min{std::numeric_limits<double>::max()},
571+
g_x_max{std::numeric_limits<double>::min()},
572+
g_y_min{std::numeric_limits<double>::max()},
573+
g_y_max{std::numeric_limits<double>::min()};
574+
// first find min/max for x
575+
if(isXYmode()){
576+
find_min_max(xTrace.data.cbegin(), xTrace.data.cend(), g_x_min, g_x_max);
570577
}
571578
else if (yTrace.has_x_trace()) {
572-
find_min_max(yTrace.p_xdata->cbegin(), yTrace.p_xdata->cend(), x_min, x_max);
579+
find_min_max(yTrace.p_xdata->cbegin(), yTrace.p_xdata->cend(), g_x_min, g_x_max);
573580
}
574581
else
575582
{
576-
x_min = yTrace.x0;
577-
x_max = yTrace.x0 + static_cast<double>(yTrace.data.size() - 1) * yTrace.deltax;
583+
g_x_min = yTrace.x0;
584+
g_x_max = yTrace.x0 + static_cast<double>(yTrace.data.size() - 1) * yTrace.deltax;
585+
}
586+
if(global_autoscale){
587+
for(const auto* t: tracebuffer){
588+
if(t->has_x_trace()){
589+
double minx, maxx;
590+
find_min_max(t->p_xdata->cbegin(), t->p_xdata->cend(), minx, maxx);
591+
g_x_min=std::min(g_x_min,minx);
592+
g_x_max=std::max(g_x_max, maxx);
593+
}
594+
}
595+
}
596+
x_min=g_x_min;
597+
x_max=g_x_max;
598+
599+
600+
//find_min_max(yTrace.data.cbegin(), yTrace.data.cend(), currentYscale->y_min, currentYscale->y_max);
601+
find_min_max(yTrace.data.cbegin(), yTrace.data.cend(), g_y_min, g_y_max);
602+
if(global_autoscale){
603+
for(const auto* t: tracebuffer){
604+
// only touch scaling for curent y-unit
605+
if(t->y_unit!=yTrace.y_unit) continue;
606+
double miny, maxy;
607+
find_min_max(t->data.cbegin(), t->data.cend(), miny, maxy);
608+
g_y_min=std::min(g_y_min,miny);
609+
g_y_max=std::max(g_y_max, maxy);
610+
}
578611
}
579-
find_min_max(yTrace.data.cbegin(), yTrace.data.cend(), currentYscale->y_min, currentYscale->y_max);
612+
currentYscale->y_min=g_y_min;
613+
currentYscale->y_max=g_y_max;
580614
update();
581615
}
582616

@@ -655,11 +689,13 @@ void RenderArea::copyToClipboard()
655689
void RenderArea::showSettingsDialog()
656690
{
657691
DlgGraphSettings dlg(this);
658-
dlg.setValues(do_autoscale_on_load, x_min, x_max, currentYscale->y_min, currentYscale->y_max, numtraces,
692+
dlg.setValues(do_autoscale_on_load, global_autoscale,
693+
x_min, x_max, currentYscale->y_min, currentYscale->y_max, numtraces,
659694
show_grid_horz, show_grid_vert, shift_all_y_scales, color_grid, color_trace, color_bktrace);
660695
if (dlg.exec()) {
661696
settings_modified = true;
662-
dlg.getValues(do_autoscale_on_load, x_min, x_max, currentYscale->y_min, currentYscale->y_max, numtraces,
697+
dlg.getValues(do_autoscale_on_load, global_autoscale,
698+
x_min, x_max, currentYscale->y_min, currentYscale->y_max, numtraces,
663699
show_grid_horz, show_grid_vert, shift_all_y_scales, color_grid, color_trace, color_bktrace);
664700
// if numtraces has been reduced we want to get rid of excess traces
665701
while (tracebuffer.size() > numtraces) {
@@ -845,7 +881,8 @@ void RenderArea::loadSettings()
845881
{
846882
QSettings s;
847883
s.beginGroup("renderarea");
848-
do_autoscale_on_load = s.value("do_autoscale_on_load", int(do_autoscale_on_load)).toInt();
884+
do_autoscale_on_load = s.value("do_autoscale_on_load", do_autoscale_on_load).toBool();
885+
global_autoscale = s.value("global_autoscale", global_autoscale).toBool();
849886
shift_all_y_scales = s.value("shift_all_y_scales", int(shift_all_y_scales)).toInt();
850887
show_grid_horz = s.value("show_grid_horz", int(show_grid_horz)).toInt();
851888
show_grid_vert = s.value("show_grid_vert", int(show_grid_vert)).toInt();
@@ -863,7 +900,8 @@ void RenderArea::saveSettings()
863900
{
864901
QSettings s;
865902
s.beginGroup("renderarea");
866-
s.setValue("do_autoscale_on_load", int(do_autoscale_on_load));
903+
s.setValue("do_autoscale_on_load", do_autoscale_on_load);
904+
s.setValue("global_autoscale", global_autoscale);
867905
s.setValue("shift_all_y_scales", int(shift_all_y_scales));
868906
s.setValue("show_grid_horz", int(show_grid_horz));
869907
s.setValue("show_grid_vert", int(show_grid_vert));

QtPMbrowser/renderarea.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public slots:
140140
double a_x, b_x, a_y, b_y; // for scaling
141141
int numtraces; // number of traces in persistance buffer
142142
bool do_autoscale_on_load;
143+
bool global_autoscale;
143144
bool show_grid_horz{ true }, show_grid_vert{ true };
144145
bool isTraceDragging, isPinching;
145146
// for marquee zoom function:

0 commit comments

Comments
 (0)