Skip to content

Commit 81b09a4

Browse files
author
David Graeff
committed
Split dock window files
1 parent 5d72ea9 commit 81b09a4

12 files changed

+1113
-1037
lines changed
+271
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
3+
#include <QCheckBox>
4+
#include <QCloseEvent>
5+
#include <QComboBox>
6+
#include <QDockWidget>
7+
#include <QLabel>
8+
9+
#include <cmath>
10+
11+
#include "dockwindows.h"
12+
#include "HorizontalDock.h"
13+
14+
#include "utils/printutils.h"
15+
#include "utils/dsoStrings.h"
16+
#include "settings.h"
17+
#include "sispinbox.h"
18+
19+
////////////////////////////////////////////////////////////////////////////////
20+
// class HorizontalDock
21+
/// \brief Initializes the horizontal axis docking window.
22+
/// \param settings The target settings object.
23+
/// \param parent The parent widget.
24+
/// \param flags Flags for the window manager.
25+
HorizontalDock::HorizontalDock(DsoSettings *settings, QWidget *parent,
26+
Qt::WindowFlags flags)
27+
: QDockWidget(tr("Horizontal"), parent, flags) {
28+
this->settings = settings;
29+
30+
// Initialize elements
31+
this->samplerateLabel = new QLabel(tr("Samplerate"));
32+
this->samplerateSiSpinBox = new SiSpinBox(UNIT_SAMPLES);
33+
this->samplerateSiSpinBox->setMinimum(1);
34+
this->samplerateSiSpinBox->setMaximum(1e8);
35+
this->samplerateSiSpinBox->setUnitPostfix("/s");
36+
37+
timebaseSteps << 1.0 << 2.0 << 4.0 << 10.0;
38+
39+
this->timebaseLabel = new QLabel(tr("Timebase"));
40+
this->timebaseSiSpinBox = new SiSpinBox(UNIT_SECONDS);
41+
this->timebaseSiSpinBox->setSteps(timebaseSteps);
42+
this->timebaseSiSpinBox->setMinimum(1e-9);
43+
this->timebaseSiSpinBox->setMaximum(3.6e3);
44+
45+
this->frequencybaseLabel = new QLabel(tr("Frequencybase"));
46+
this->frequencybaseSiSpinBox = new SiSpinBox(UNIT_HERTZ);
47+
this->frequencybaseSiSpinBox->setMinimum(1.0);
48+
this->frequencybaseSiSpinBox->setMaximum(100e6);
49+
50+
this->recordLengthLabel = new QLabel(tr("Record length"));
51+
this->recordLengthComboBox = new QComboBox();
52+
53+
this->formatLabel = new QLabel(tr("Format"));
54+
this->formatComboBox = new QComboBox();
55+
for (int format = Dso::GRAPHFORMAT_TY; format < Dso::GRAPHFORMAT_COUNT;
56+
++format)
57+
this->formatComboBox->addItem(
58+
Dso::graphFormatString((Dso::GraphFormat)format));
59+
60+
this->dockLayout = new QGridLayout();
61+
this->dockLayout->setColumnMinimumWidth(0, 64);
62+
this->dockLayout->setColumnStretch(1, 1);
63+
this->dockLayout->addWidget(this->samplerateLabel, 0, 0);
64+
this->dockLayout->addWidget(this->samplerateSiSpinBox, 0, 1);
65+
this->dockLayout->addWidget(this->timebaseLabel, 1, 0);
66+
this->dockLayout->addWidget(this->timebaseSiSpinBox, 1, 1);
67+
this->dockLayout->addWidget(this->frequencybaseLabel, 2, 0);
68+
this->dockLayout->addWidget(this->frequencybaseSiSpinBox, 2, 1);
69+
this->dockLayout->addWidget(this->recordLengthLabel, 3, 0);
70+
this->dockLayout->addWidget(this->recordLengthComboBox, 3, 1);
71+
this->dockLayout->addWidget(this->formatLabel, 4, 0);
72+
this->dockLayout->addWidget(this->formatComboBox, 4, 1);
73+
74+
this->dockWidget = new QWidget();
75+
SetupDockWidget(this, dockWidget, dockLayout);
76+
77+
// Connect signals and slots
78+
connect(this->samplerateSiSpinBox, SIGNAL(valueChanged(double)), this,
79+
SLOT(samplerateSelected(double)));
80+
connect(this->timebaseSiSpinBox, SIGNAL(valueChanged(double)), this,
81+
SLOT(timebaseSelected(double)));
82+
connect(this->frequencybaseSiSpinBox, SIGNAL(valueChanged(double)), this,
83+
SLOT(frequencybaseSelected(double)));
84+
connect(this->recordLengthComboBox, SIGNAL(currentIndexChanged(int)), this,
85+
SLOT(recordLengthSelected(int)));
86+
connect(this->formatComboBox, SIGNAL(currentIndexChanged(int)), this,
87+
SLOT(formatSelected(int)));
88+
89+
// Set values
90+
this->setSamplerate(this->settings->scope.horizontal.samplerate);
91+
this->setTimebase(this->settings->scope.horizontal.timebase);
92+
this->setFrequencybase(this->settings->scope.horizontal.frequencybase);
93+
this->setRecordLength(this->settings->scope.horizontal.recordLength);
94+
this->setFormat(this->settings->scope.horizontal.format);
95+
}
96+
97+
/// \brief Cleans up everything.
98+
HorizontalDock::~HorizontalDock() {}
99+
100+
/// \brief Don't close the dock, just hide it.
101+
/// \param event The close event that should be handled.
102+
void HorizontalDock::closeEvent(QCloseEvent *event) {
103+
this->hide();
104+
105+
event->accept();
106+
}
107+
108+
/// \brief Changes the frequencybase.
109+
/// \param frequencybase The frequencybase in hertz.
110+
void HorizontalDock::setFrequencybase(double frequencybase) {
111+
this->suppressSignals = true;
112+
this->frequencybaseSiSpinBox->setValue(frequencybase);
113+
this->suppressSignals = false;
114+
}
115+
116+
/// \brief Changes the samplerate.
117+
/// \param samplerate The samplerate in seconds.
118+
void HorizontalDock::setSamplerate(double samplerate) {
119+
this->suppressSignals = true;
120+
this->samplerateSiSpinBox->setValue(samplerate);
121+
this->suppressSignals = false;
122+
}
123+
124+
/// \brief Changes the timebase.
125+
/// \param timebase The timebase in seconds.
126+
double HorizontalDock::setTimebase(double timebase) {
127+
// timebaseSteps are repeated in each decade
128+
double decade = pow(10, floor(log10(timebase)));
129+
double vNorm = timebase / decade;
130+
for (int i = 0; i < timebaseSteps.size() - 1; ++i) {
131+
if (timebaseSteps.at(i) <= vNorm && vNorm < timebaseSteps.at(i + 1)) {
132+
suppressSignals = true;
133+
timebaseSiSpinBox->setValue(decade * timebaseSteps.at(i));
134+
suppressSignals = false;
135+
break;
136+
}
137+
}
138+
return timebaseSiSpinBox->value();
139+
}
140+
141+
/// \brief Changes the record length if the new value is supported.
142+
/// \param recordLength The record length in samples.
143+
void HorizontalDock::setRecordLength(unsigned int recordLength) {
144+
int index = this->recordLengthComboBox->findData(recordLength);
145+
146+
if (index != -1) {
147+
this->suppressSignals = true;
148+
this->recordLengthComboBox->setCurrentIndex(index);
149+
this->suppressSignals = false;
150+
}
151+
}
152+
153+
/// \brief Changes the format if the new value is supported.
154+
/// \param format The format for the horizontal axis.
155+
/// \return Index of format-value, -1 on error.
156+
int HorizontalDock::setFormat(Dso::GraphFormat format) {
157+
if (format >= Dso::GRAPHFORMAT_TY && format <= Dso::GRAPHFORMAT_XY) {
158+
this->suppressSignals = true;
159+
this->formatComboBox->setCurrentIndex(format);
160+
this->suppressSignals = false;
161+
return format;
162+
}
163+
164+
return -1;
165+
}
166+
167+
/// \brief Updates the available record lengths in the combo box.
168+
/// \param recordLengths The available record lengths for the combo box.
169+
void HorizontalDock::availableRecordLengthsChanged(
170+
const QList<unsigned int> &recordLengths) {
171+
/// \todo Empty lists should be interpreted as scope supporting continuous
172+
/// record length values.
173+
this->recordLengthComboBox->blockSignals(
174+
true); // Avoid messing up the settings
175+
this->recordLengthComboBox->setUpdatesEnabled(false);
176+
177+
// Update existing elements to avoid unnecessary index updates
178+
int index = 0;
179+
for (; index < recordLengths.size(); ++index) {
180+
unsigned int recordLengthItem = recordLengths[index];
181+
if (index < this->recordLengthComboBox->count()) {
182+
this->recordLengthComboBox->setItemData(index, recordLengthItem);
183+
this->recordLengthComboBox->setItemText(
184+
index, recordLengthItem == UINT_MAX
185+
? tr("Roll")
186+
: valueToString(recordLengthItem,
187+
UNIT_SAMPLES, 3));
188+
} else {
189+
this->recordLengthComboBox->addItem(
190+
recordLengthItem == UINT_MAX
191+
? tr("Roll")
192+
: valueToString(recordLengthItem, UNIT_SAMPLES,
193+
3),
194+
(uint)recordLengthItem);
195+
}
196+
}
197+
// Remove extra elements
198+
for (int extraIndex = this->recordLengthComboBox->count() - 1;
199+
extraIndex > index; --extraIndex) {
200+
this->recordLengthComboBox->removeItem(extraIndex);
201+
}
202+
203+
this->setRecordLength(this->settings->scope.horizontal.recordLength);
204+
this->recordLengthComboBox->setUpdatesEnabled(true);
205+
this->recordLengthComboBox->blockSignals(false);
206+
}
207+
208+
/// \brief Updates the minimum and maximum of the samplerate spin box.
209+
/// \param minimum The minimum value the spin box should accept.
210+
/// \param maximum The minimum value the spin box should accept.
211+
void HorizontalDock::samplerateLimitsChanged(double minimum, double maximum) {
212+
this->suppressSignals = true;
213+
this->samplerateSiSpinBox->setMinimum(minimum);
214+
this->samplerateSiSpinBox->setMaximum(maximum);
215+
this->suppressSignals = false;
216+
}
217+
218+
/// \brief Updates the mode and steps of the samplerate spin box.
219+
/// \param mode The mode value the spin box should accept.
220+
/// \param steps The steps value the spin box should accept.
221+
void HorizontalDock::samplerateSet(int mode, QList<double> steps) {
222+
this->suppressSignals = true;
223+
this->samplerateSiSpinBox->setMode(mode);
224+
this->samplerateSiSpinBox->setSteps(steps);
225+
this->suppressSignals = false;
226+
}
227+
228+
/// \brief Called when the frequencybase spinbox changes its value.
229+
/// \param frequencybase The frequencybase in hertz.
230+
void HorizontalDock::frequencybaseSelected(double frequencybase) {
231+
this->settings->scope.horizontal.frequencybase = frequencybase;
232+
if (!this->suppressSignals)
233+
emit frequencybaseChanged(frequencybase);
234+
}
235+
236+
/// \brief Called when the samplerate spinbox changes its value.
237+
/// \param samplerate The samplerate in samples/second.
238+
void HorizontalDock::samplerateSelected(double samplerate) {
239+
this->settings->scope.horizontal.samplerate = samplerate;
240+
if (!this->suppressSignals) {
241+
this->settings->scope.horizontal.samplerateSet = true;
242+
emit samplerateChanged(samplerate);
243+
}
244+
}
245+
246+
/// \brief Called when the timebase spinbox changes its value.
247+
/// \param timebase The timebase in seconds.
248+
void HorizontalDock::timebaseSelected(double timebase) {
249+
this->settings->scope.horizontal.timebase = timebase;
250+
if (!this->suppressSignals) {
251+
this->settings->scope.horizontal.samplerateSet = false;
252+
emit timebaseChanged(timebase);
253+
}
254+
}
255+
256+
/// \brief Called when the record length combo box changes its value.
257+
/// \param index The index of the combo box item.
258+
void HorizontalDock::recordLengthSelected(int index) {
259+
this->settings->scope.horizontal.recordLength =
260+
this->recordLengthComboBox->itemData(index).toUInt();
261+
if (!this->suppressSignals)
262+
emit recordLengthChanged(index);
263+
}
264+
265+
/// \brief Called when the format combo box changes its value.
266+
/// \param index The index of the combo box item.
267+
void HorizontalDock::formatSelected(int index) {
268+
this->settings->scope.horizontal.format = (Dso::GraphFormat)index;
269+
if (!this->suppressSignals)
270+
emit formatChanged(this->settings->scope.horizontal.format);
271+
}

openhantek/src/docks/HorizontalDock.h

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
3+
#pragma once
4+
5+
6+
#include <QDockWidget>
7+
#include <QGridLayout>
8+
9+
#include "definitions.h"
10+
#include "settings.h"
11+
12+
class QLabel;
13+
class QCheckBox;
14+
class QComboBox;
15+
16+
class SiSpinBox;
17+
18+
////////////////////////////////////////////////////////////////////////////////
19+
/// \class HorizontalDock dockwindows.h
20+
/// \brief Dock window for the horizontal axis.
21+
/// It contains the settings for the timebase and the display format.
22+
class HorizontalDock : public QDockWidget {
23+
Q_OBJECT
24+
25+
public:
26+
HorizontalDock(DsoSettings *settings, QWidget *parent,
27+
Qt::WindowFlags flags = 0);
28+
~HorizontalDock();
29+
30+
void setFrequencybase(double timebase);
31+
void setSamplerate(double samplerate);
32+
double setTimebase(double timebase);
33+
void setRecordLength(unsigned int recordLength);
34+
int setFormat(Dso::GraphFormat format);
35+
36+
protected:
37+
void closeEvent(QCloseEvent *event);
38+
39+
QGridLayout *dockLayout; ///< The main layout for the dock window
40+
QWidget *dockWidget; ///< The main widget for the dock window
41+
QLabel *samplerateLabel; ///< The label for the samplerate spinbox
42+
QLabel *timebaseLabel; ///< The label for the timebase spinbox
43+
QLabel *frequencybaseLabel; ///< The label for the frequencybase spinbox
44+
QLabel *recordLengthLabel; ///< The label for the record length combobox
45+
QLabel *formatLabel; ///< The label for the format combobox
46+
SiSpinBox *samplerateSiSpinBox; ///< Selects the samplerate for aquisitions
47+
SiSpinBox *timebaseSiSpinBox; ///< Selects the timebase for voltage graphs
48+
SiSpinBox *
49+
frequencybaseSiSpinBox; ///< Selects the frequencybase for spectrum graphs
50+
QComboBox
51+
*recordLengthComboBox; ///< Selects the record length for aquisitions
52+
QComboBox *formatComboBox; ///< Selects the way the sampled data is
53+
///interpreted and shown
54+
55+
DsoSettings *settings; ///< The settings provided by the parent class
56+
QList<double> timebaseSteps; ///< Steps for the timebase spinbox
57+
58+
QStringList formatStrings; ///< Strings for the formats
59+
60+
bool suppressSignals; ///< Disable changed-signals temporarily
61+
62+
public slots:
63+
void availableRecordLengthsChanged(const QList<unsigned int> &recordLengths);
64+
void samplerateLimitsChanged(double minimum, double maximum);
65+
void samplerateSet(int mode, QList<double> sampleSteps);
66+
67+
protected slots:
68+
void frequencybaseSelected(double frequencybase);
69+
void samplerateSelected(double samplerate);
70+
void timebaseSelected(double timebase);
71+
void recordLengthSelected(int index);
72+
void formatSelected(int index);
73+
74+
signals:
75+
void frequencybaseChanged(
76+
double frequencybase); ///< The frequencybase has been changed
77+
void
78+
samplerateChanged(double samplerate); ///< The samplerate has been changed
79+
void timebaseChanged(double timebase); ///< The timebase has been changed
80+
void recordLengthChanged(
81+
unsigned long recordLength); ///< The recordd length has been changed
82+
void formatChanged(
83+
Dso::GraphFormat format); ///< The viewing format has been changed
84+
};

0 commit comments

Comments
 (0)