OpenHantek
dsowidget.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 #pragma once
4 
5 #include <QGridLayout>
6 #include <QHBoxLayout>
7 #include <QLabel>
8 #include <QList>
9 #include <memory>
10 
11 #include "glscope.h"
13 #include "levelslider.h"
14 #include "viewsettings.h"
15 
16 class SpectrumGenerator;
17 struct DsoSettingsScope;
18 struct DsoSettingsView;
19 class DataGrid;
20 
23 class DsoWidget : public QWidget {
24  Q_OBJECT
25 
26  public:
27  struct Sliders {
32  };
33 
39  DsoWidget( DsoSettingsScope *scope, DsoSettingsView *view, const Dso::ControlSpecification *spec, QWidget *parent = nullptr );
40 
41  ~DsoWidget() override;
42 
43  // Data arrived
44  void showNew( std::shared_ptr< PPresult > analysedData );
45 
46  void switchToPrintColors();
47  void restoreScreenColors();
48 
49  protected:
50  virtual void showEvent( QShowEvent *event ) override;
51  void setupSliders( Sliders &sliders );
52  void adaptTriggerLevelSlider( DsoWidget::Sliders &sliders, ChannelID channel );
54  void setMeasurementVisible( ChannelID channel );
55  void updateMarkerDetails();
56  void updateSpectrumDetails( ChannelID channel );
57  void updateTriggerDetails();
58  void updateVoltageDetails( ChannelID channel );
59 
60  double mainToZoom( double position ) const;
61  double zoomToMain( double position ) const;
62 
65 
66  QGridLayout *mainLayout;
67 
68  QHBoxLayout *settingsLayout;
75 
76  QLabel *swTriggerStatus;
77 
78  QHBoxLayout *markerLayout;
79  QLabel *markerInfoLabel;
80  QLabel *markerTimeLabel;
84 
85  QGridLayout *measurementLayout;
86  std::vector< QLabel * > measurementNameLabel;
87  std::vector< QLabel * > measurementGainLabel;
88  std::vector< QLabel * > measurementMagnitudeLabel;
89  std::vector< QLabel * > measurementMiscLabel;
90  std::vector< QLabel * > measurementVppLabel;
91  std::vector< QLabel * > measurementRMSLabel;
92  std::vector< QLabel * > measurementDCLabel;
93  std::vector< QLabel * > measurementACLabel;
94  std::vector< QLabel * > measurementdBLabel;
95  std::vector< QLabel * > measurementFrequencyLabel;
96  std::vector< QLabel * > measurementNoteLabel;
97  std::vector< QLabel * > measurementRMSPowerLabel;
98  std::vector< QLabel * > measurementTHDLabel;
99 
101 
105 
108 
109  private:
110  double samplerate;
111  unsigned oversample = 1;
112  double timebase;
113  double pulseWidth1 = 0.0;
114  double pulseWidth2 = 0.0;
115  double zoomFactor = 1.0;
116  int mainScopeRow = 0;
117  int zoomScopeRow = 0;
118  void setColors();
119  std::vector< Unit > voltageUnits = { UNIT_VOLTS, UNIT_VOLTS, UNIT_VOLTS };
121  QPoint cursorGlobalPosition = QPoint();
122  QPointF cursorMeasurementPosition = QPointF();
124  void switchToMarker();
125  void showCursorMessage( QPoint globalPos = QPoint(), const QString &message = QString() );
126  void updateItem( ChannelID index, bool switchOn = false );
127 
128  public slots:
129  // Horizontal axis
130  // void horizontalFormatChanged(HorizontalFormat format);
131  void updateFrequencybase( double frequencybase );
132  void updateSamplerate( double samplerate );
133  void updateOversample( unsigned oversample );
134  void updateTimebase( double timebase );
135 
136  // Trigger
137  void updateTriggerMode();
138  void updateTriggerSlope();
139  void updateTriggerSource();
140 
141  // Spectrum
142  void updateSpectrumMagnitude( ChannelID channel );
143  void updateSpectrumUsed( ChannelID channel, bool used );
144 
145  // Vertical axis
146  void updateVoltageCoupling( ChannelID channel );
147  void updateMathMode();
148  void updateVoltageGain( ChannelID channel );
149  void updateVoltageUsed( ChannelID channel, bool used );
150 
151  // Menus
152  void updateRecordLength( int size );
153 
154  // Scope control
155  void updateZoom( bool enabled );
156  void updateCursorGrid( bool enabled );
157  void wheelEvent( QWheelEvent *event ) override;
158 
159  // Scope control
160  void updateSlidersSettings();
161 
162  private slots:
163  // Sliders
164  void updateOffset( ChannelID channel, double value, bool pressed, QPoint globalPos );
165  void updateTriggerPosition( int index, double value, bool pressed, QPoint globalPos, bool mainView = true );
166  void updateTriggerLevel( ChannelID channel, double value, bool pressed, QPoint globalPos );
167  void updateMarker( unsigned marker, double value );
168 
169  signals:
170  // Sliders
171  void voltageOffsetChanged( ChannelID channel, double value );
172  void triggerPositionChanged( double value );
173  void triggerLevelChanged( ChannelID channel, double value );
174 };
void triggerPositionChanged(double value)
The pretrigger has been changed.
void updateTriggerMode()
Handles modeChanged signal from the trigger dock.
Definition: dsowidget.cpp:816
void wheelEvent(QWheelEvent *event) override
Definition: dsowidget.cpp:934
Definition: dsowidget.h:27
QLabel * markerFrequencybaseLabel
The frequencybase for the zoomed scope.
Definition: dsowidget.h:83
void updateVoltageGain(ChannelID channel)
Handles gainChanged signal from the voltage dock.
Definition: dsowidget.cpp:864
std::vector< QLabel *> measurementNoteLabel
Note value of the signal.
Definition: dsowidget.h:96
void updateVoltageDetails(ChannelID channel)
Update the label about the voltage settings.
Definition: dsowidget.cpp:734
GlScope * mainScope
The main scope screen.
Definition: dsowidget.h:106
DsoSettingsView * view
Definition: dsowidget.h:103
void updateMathMode()
Handles modeChanged signal from the voltage dock.
Definition: dsowidget.cpp:854
std::vector< QLabel *> measurementMagnitudeLabel
The magnitude for the spectrum (dB/div)
Definition: dsowidget.h:88
void updateOffset(ChannelID channel, double value, bool pressed, QPoint globalPos)
Handles valueChanged signal from the offset sliders.
Definition: dsowidget.cpp:1116
bool cursorMeasurementValid
Definition: dsowidget.h:120
void switchToMarker()
Definition: dsowidget.cpp:904
void restoreScreenColors()
Definition: dsowidget.cpp:321
void adaptTriggerPositionSlider()
Handles signals affecting trigger position in the zoom view.
Definition: dsowidget.cpp:1168
std::vector< QLabel *> measurementFrequencyLabel
Frequency of the signal (Hz)
Definition: dsowidget.h:95
QLabel * markerTimebaseLabel
The timebase for the zoomed scope.
Definition: dsowidget.h:82
void updateTimebase(double timebase)
Handles timebaseChanged signal from the horizontal dock.
Definition: dsowidget.cpp:775
std::vector< QLabel *> measurementRMSPowerLabel
RMS Power in Watts.
Definition: dsowidget.h:97
std::vector< Unit > voltageUnits
Definition: dsowidget.h:119
Slider widget for multiple level sliders. These are used for the trigger levels, offsets and so on...
Definition: levelslider.h:28
The widget for the oszilloscope-screen This widget contains the scopes and all level sliders...
Definition: dsowidget.h:23
DsoSettingsScope * scope
Definition: dsowidget.h:102
double samplerate
Definition: dsowidget.h:110
Sliders mainSliders
Definition: dsowidget.h:63
QLabel * markerFrequencyLabel
The frequency for the time period.
Definition: dsowidget.h:81
void updateTriggerDetails()
Update the label about the trigger settings.
Definition: dsowidget.cpp:702
std::vector< QLabel *> measurementACLabel
AC Amplitude of the signal (V)
Definition: dsowidget.h:93
std::vector< QLabel *> measurementGainLabel
The gain for the voltage (V/div)
Definition: dsowidget.h:87
QLabel * settingsOversampleLabel
The oversample factor.
Definition: dsowidget.h:72
virtual void showEvent(QShowEvent *event) override
Definition: dsowidget.cpp:1097
void setColors()
Definition: dsowidget.cpp:329
double pulseWidth2
Definition: dsowidget.h:114
void updateMarkerDetails()
Update the label about the marker measurements.
Definition: dsowidget.cpp:569
QHBoxLayout * settingsLayout
The table for the settings info.
Definition: dsowidget.h:68
QLabel * swTriggerStatus
The status of SW trigger.
Definition: dsowidget.h:76
std::vector< QLabel *> measurementMiscLabel
Coupling or math mode.
Definition: dsowidget.h:89
Definition: datagrid.h:13
double mainToZoom(double position) const
Translate horizontal position (0..1) from main view to zoom view.
Definition: dsowidget.cpp:1148
void showCursorMessage(QPoint globalPos=QPoint(), const QString &message=QString())
Definition: dsowidget.cpp:1090
void setupSliders(Sliders &sliders)
Definition: dsowidget.cpp:448
LevelSlider * triggerLevelSlider
The sliders for the trigger level.
Definition: dsowidget.h:30
std::vector< QLabel *> measurementdBLabel
AC Amplitude in dB.
Definition: dsowidget.h:94
void updateZoom(bool enabled)
Show/hide the zoom view.
Definition: dsowidget.cpp:912
void voltageOffsetChanged(ChannelID channel, double value)
A graph offset has been changed.
void updateCursorGrid(bool enabled)
Definition: dsowidget.cpp:383
QLabel * settingsTriggerLabel
The trigger details.
Definition: dsowidget.h:69
double zoomToMain(double position) const
Translate horizontal position (0..1) from zoom view to main view.
Definition: dsowidget.cpp:1158
LevelSlider * triggerPositionSlider
The slider for the pretrigger.
Definition: dsowidget.h:29
void updateTriggerSlope()
Handles slopeChanged signal from the trigger dock.
Definition: dsowidget.cpp:824
void adaptTriggerLevelSlider(DsoWidget::Sliders &sliders, ChannelID channel)
Set the trigger level sliders minimum and maximum to the new values.
Definition: dsowidget.cpp:512
QLabel * markerInfoLabel
The info about the zoom factor.
Definition: dsowidget.h:79
void updateVoltageUsed(ChannelID channel, bool used)
Handles usedChanged signal from the voltage dock.
Definition: dsowidget.cpp:878
void setMeasurementVisible(ChannelID channel)
Show/Hide a line of the measurement table.
Definition: dsowidget.cpp:526
DataGrid * cursorDataGrid
Definition: dsowidget.h:100
void switchToPrintColors()
Definition: dsowidget.cpp:313
LevelSlider * voltageOffsetSlider
The sliders for the graph offsets.
Definition: dsowidget.h:28
Stores the specifications of the currently connected device.
Definition: controlspecification.h:42
OpenGL accelerated widget that displays the oscilloscope screen.
Definition: glscope.h:29
void updateTriggerLevel(ChannelID channel, double value, bool pressed, QPoint globalPos)
Handles valueChanged signal from the trigger level slider.
Definition: dsowidget.cpp:1223
LevelSlider * markerSlider
The sliders for the markers.
Definition: dsowidget.h:31
std::vector< QLabel *> measurementVppLabel
Peak-to-peak amplitude of the signal (V)
Definition: dsowidget.h:90
int mainScopeRow
Definition: dsowidget.h:116
GlScope * zoomScope
The optional magnified scope screen.
Definition: dsowidget.h:107
std::vector< QLabel *> measurementTHDLabel
THD of the signal in Watts.
Definition: dsowidget.h:98
Definition: printutils.h:12
QLabel * settingsFrequencybaseLabel
The frequencybase of the main scope.
Definition: dsowidget.h:74
Holds all view settings.
Definition: viewsettings.h:35
QPointF cursorMeasurementPosition
Definition: dsowidget.h:122
void showNew(std::shared_ptr< PPresult > analysedData)
Prints analyzed data.
Definition: dsowidget.cpp:949
QLabel * settingsSamplerateLabel
The samplerate.
Definition: dsowidget.h:71
void updateMarker(unsigned marker, double value)
Handles valueChanged signal from the marker slider.
Definition: dsowidget.cpp:1254
QGridLayout * mainLayout
The main layout for this widget.
Definition: dsowidget.h:66
void updateSpectrumDetails(ChannelID channel)
Update the label about the spectrum settings.
Definition: dsowidget.cpp:691
unsigned oversample
Definition: dsowidget.h:111
QLabel * settingsSamplesOnScreen
The displayed dots on screen.
Definition: dsowidget.h:70
const Dso::ControlSpecification * spec
Definition: dsowidget.h:104
void triggerLevelChanged(ChannelID channel, double value)
A trigger level has been changed.
unsigned ChannelID
Definition: types.h:6
double zoomFactor
Definition: dsowidget.h:115
Sliders zoomSliders
Definition: dsowidget.h:64
void updateItem(ChannelID index, bool switchOn=false)
Definition: dsowidget.cpp:420
void updateSpectrumUsed(ChannelID channel, bool used)
Handles usedChanged signal from the spectrum dock.
Definition: dsowidget.cpp:795
QGridLayout * measurementLayout
The table for the signal details.
Definition: dsowidget.h:85
void updateRecordLength(int size)
Change the record length.
Definition: dsowidget.cpp:899
QLabel * settingsTimebaseLabel
The timebase of the main scope.
Definition: dsowidget.h:73
QPoint cursorGlobalPosition
Definition: dsowidget.h:121
void updateSlidersSettings()
Update the sliders settings.
Definition: dsowidget.cpp:1264
DsoWidget(DsoSettingsScope *scope, DsoSettingsView *view, const Dso::ControlSpecification *spec, QWidget *parent=nullptr)
Initializes the components of the oszilloscope-screen.
Definition: dsowidget.cpp:28
Holds the settings for the oscilloscope.
Definition: scopesettings.h:100
int zoomScopeRow
Definition: dsowidget.h:117
void updateVoltageCoupling(ChannelID channel)
Handles couplingChanged signal from the voltage dock.
Definition: dsowidget.cpp:846
~DsoWidget() override
Definition: dsowidget.cpp:307
void updateOversample(unsigned oversample)
Updates the oversample field after changing the oversampling.
Definition: dsowidget.cpp:767
std::vector< QLabel *> measurementRMSLabel
RMS Amplitude of the signal (V) = sqrt( DC² + AC² )
Definition: dsowidget.h:91
Analyzes the data from the dso. Calculates the spectrum and various data about the signal and saves t...
Definition: spectrumgenerator.h:26
double pulseWidth1
Definition: dsowidget.h:113
void updateSpectrumMagnitude(ChannelID channel)
Handles magnitudeChanged signal from the spectrum dock.
Definition: dsowidget.cpp:786
void updateSamplerate(double samplerate)
Updates the samplerate field after changing the samplerate.
Definition: dsowidget.cpp:758
std::vector< QLabel *> measurementDCLabel
DC Amplitude of the signal (V)
Definition: dsowidget.h:92
QLabel * markerTimeLabel
The time period between the markers.
Definition: dsowidget.h:80
void updateFrequencybase(double frequencybase)
Handles frequencybaseChanged signal from the horizontal dock.
Definition: dsowidget.cpp:750
QHBoxLayout * markerLayout
The table for the marker details.
Definition: dsowidget.h:78
ChannelID selectedCursor
Definition: dsowidget.h:123
void updateTriggerPosition(int index, double value, bool pressed, QPoint globalPos, bool mainView=true)
Handles valueChanged signal from the triggerPosition slider.
Definition: dsowidget.cpp:1191
std::vector< QLabel *> measurementNameLabel
The name of the channel.
Definition: dsowidget.h:86
double timebase
Definition: dsowidget.h:112
void updateTriggerSource()
Handles sourceChanged signal from the trigger dock.
Definition: dsowidget.cpp:828