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;
74 
75  QLabel *swTriggerStatus;
76 
77  QHBoxLayout *markerLayout;
78  QLabel *markerInfoLabel;
79  QLabel *markerTimeLabel;
83 
84  QGridLayout *measurementLayout;
85  std::vector< QLabel * > measurementNameLabel;
86  std::vector< QLabel * > measurementGainLabel;
87  std::vector< QLabel * > measurementMagnitudeLabel;
88  std::vector< QLabel * > measurementMiscLabel;
89  std::vector< QLabel * > measurementVppLabel;
90  std::vector< QLabel * > measurementRMSLabel;
91  std::vector< QLabel * > measurementDCLabel;
92  std::vector< QLabel * > measurementACLabel;
93  std::vector< QLabel * > measurementdBLabel;
94  std::vector< QLabel * > measurementFrequencyLabel;
95  std::vector< QLabel * > measurementNoteLabel;
96  std::vector< QLabel * > measurementRMSPowerLabel;
97  std::vector< QLabel * > measurementTHDLabel;
98 
100 
104 
107 
108  private:
109  double samplerate;
110  double timebase;
111  double pulseWidth1 = 0.0;
112  double pulseWidth2 = 0.0;
113  double zoomFactor = 1.0;
114  int mainScopeRow = 0;
115  int zoomScopeRow = 0;
116  void setColors();
117  std::vector< Unit > voltageUnits = { UNIT_VOLTS, UNIT_VOLTS, UNIT_VOLTS };
119  QPoint cursorGlobalPosition = QPoint();
120  QPointF cursorMeasurementPosition = QPointF();
122  void switchToMarker();
123  void showCursorMessage( QPoint globalPos = QPoint(), const QString &message = QString() );
124  void updateItem( ChannelID index, bool switchOn = false );
125 
126  public slots:
127  // Horizontal axis
128  // void horizontalFormatChanged(HorizontalFormat format);
129  void updateFrequencybase( double frequencybase );
130  void updateSamplerate( double samplerate );
131  void updateTimebase( double timebase );
132 
133  // Trigger
134  void updateTriggerMode();
135  void updateTriggerSlope();
136  void updateTriggerSource();
137 
138  // Spectrum
139  void updateSpectrumMagnitude( ChannelID channel );
140  void updateSpectrumUsed( ChannelID channel, bool used );
141 
142  // Vertical axis
143  void updateVoltageCoupling( ChannelID channel );
144  void updateMathMode();
145  void updateVoltageGain( ChannelID channel );
146  void updateVoltageUsed( ChannelID channel, bool used );
147 
148  // Menus
149  void updateRecordLength( int size );
150 
151  // Scope control
152  void updateZoom( bool enabled );
153  void updateCursorGrid( bool enabled );
154  void wheelEvent( QWheelEvent *event ) override;
155 
156  // Scope control
157  void updateSlidersSettings();
158 
159  private slots:
160  // Sliders
161  void updateOffset( ChannelID channel, double value, bool pressed, QPoint globalPos );
162  void updateTriggerPosition( int index, double value, bool pressed, QPoint globalPos, bool mainView = true );
163  void updateTriggerLevel( ChannelID channel, double value, bool pressed, QPoint globalPos );
164  void updateMarker( unsigned marker, double value );
165 
166  signals:
167  // Sliders
168  void voltageOffsetChanged( ChannelID channel, double value );
169  void triggerPositionChanged( double value );
170  void triggerLevelChanged( ChannelID channel, double value );
171 };
void triggerPositionChanged(double value)
The pretrigger has been changed.
void updateTriggerMode()
Handles modeChanged signal from the trigger dock.
Definition: dsowidget.cpp:806
void wheelEvent(QWheelEvent *event) override
Definition: dsowidget.cpp:924
Definition: dsowidget.h:27
QLabel * markerFrequencybaseLabel
The frequencybase for the zoomed scope.
Definition: dsowidget.h:82
void updateVoltageGain(ChannelID channel)
Handles gainChanged signal from the voltage dock.
Definition: dsowidget.cpp:854
std::vector< QLabel *> measurementNoteLabel
Note value of the signal.
Definition: dsowidget.h:95
void updateVoltageDetails(ChannelID channel)
Update the label about the voltage settings.
Definition: dsowidget.cpp:731
GlScope * mainScope
The main scope screen.
Definition: dsowidget.h:105
DsoSettingsView * view
Definition: dsowidget.h:102
void updateMathMode()
Handles modeChanged signal from the voltage dock.
Definition: dsowidget.cpp:844
std::vector< QLabel *> measurementMagnitudeLabel
The magnitude for the spectrum (dB/div)
Definition: dsowidget.h:87
void updateOffset(ChannelID channel, double value, bool pressed, QPoint globalPos)
Handles valueChanged signal from the offset sliders.
Definition: dsowidget.cpp:1105
bool cursorMeasurementValid
Definition: dsowidget.h:118
void switchToMarker()
Definition: dsowidget.cpp:894
void restoreScreenColors()
Definition: dsowidget.cpp:318
void adaptTriggerPositionSlider()
Handles signals affecting trigger position in the zoom view.
Definition: dsowidget.cpp:1157
std::vector< QLabel *> measurementFrequencyLabel
Frequency of the signal (Hz)
Definition: dsowidget.h:94
QLabel * markerTimebaseLabel
The timebase for the zoomed scope.
Definition: dsowidget.h:81
void updateTimebase(double timebase)
Handles timebaseChanged signal from the horizontal dock.
Definition: dsowidget.cpp:765
std::vector< QLabel *> measurementRMSPowerLabel
RMS Power in Watts.
Definition: dsowidget.h:96
std::vector< Unit > voltageUnits
Definition: dsowidget.h:117
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:101
double samplerate
Definition: dsowidget.h:109
Sliders mainSliders
Definition: dsowidget.h:63
QLabel * markerFrequencyLabel
The frequency for the time period.
Definition: dsowidget.h:80
void updateTriggerDetails()
Update the label about the trigger settings.
Definition: dsowidget.cpp:699
std::vector< QLabel *> measurementACLabel
AC Amplitude of the signal (V)
Definition: dsowidget.h:92
std::vector< QLabel *> measurementGainLabel
The gain for the voltage (V/div)
Definition: dsowidget.h:86
virtual void showEvent(QShowEvent *event) override
Definition: dsowidget.cpp:1087
void setColors()
Definition: dsowidget.cpp:326
double pulseWidth2
Definition: dsowidget.h:112
void updateMarkerDetails()
Update the label about the marker measurements.
Definition: dsowidget.cpp:566
QHBoxLayout * settingsLayout
The table for the settings info.
Definition: dsowidget.h:68
QLabel * swTriggerStatus
The status of SW trigger.
Definition: dsowidget.h:75
std::vector< QLabel *> measurementMiscLabel
Coupling or math mode.
Definition: dsowidget.h:88
Definition: datagrid.h:13
double mainToZoom(double position) const
Translate horizontal position (0..1) from main view to zoom view.
Definition: dsowidget.cpp:1137
void showCursorMessage(QPoint globalPos=QPoint(), const QString &message=QString())
Definition: dsowidget.cpp:1080
void setupSliders(Sliders &sliders)
Definition: dsowidget.cpp:445
LevelSlider * triggerLevelSlider
The sliders for the trigger level.
Definition: dsowidget.h:30
std::vector< QLabel *> measurementdBLabel
AC Amplitude in dB.
Definition: dsowidget.h:93
void updateZoom(bool enabled)
Show/hide the zoom view.
Definition: dsowidget.cpp:902
void voltageOffsetChanged(ChannelID channel, double value)
A graph offset has been changed.
void updateCursorGrid(bool enabled)
Definition: dsowidget.cpp:380
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:1147
LevelSlider * triggerPositionSlider
The slider for the pretrigger.
Definition: dsowidget.h:29
void updateTriggerSlope()
Handles slopeChanged signal from the trigger dock.
Definition: dsowidget.cpp:814
void adaptTriggerLevelSlider(DsoWidget::Sliders &sliders, ChannelID channel)
Set the trigger level sliders minimum and maximum to the new values.
Definition: dsowidget.cpp:509
QLabel * markerInfoLabel
The info about the zoom factor.
Definition: dsowidget.h:78
void updateVoltageUsed(ChannelID channel, bool used)
Handles usedChanged signal from the voltage dock.
Definition: dsowidget.cpp:868
void setMeasurementVisible(ChannelID channel)
Show/Hide a line of the measurement table.
Definition: dsowidget.cpp:523
DataGrid * cursorDataGrid
Definition: dsowidget.h:99
void switchToPrintColors()
Definition: dsowidget.cpp:310
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:1212
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:89
int mainScopeRow
Definition: dsowidget.h:114
GlScope * zoomScope
The optional magnified scope screen.
Definition: dsowidget.h:106
std::vector< QLabel *> measurementTHDLabel
THD of the signal in Watts.
Definition: dsowidget.h:97
Definition: printutils.h:12
QLabel * settingsFrequencybaseLabel
The frequencybase of the main scope.
Definition: dsowidget.h:73
Holds all view settings.
Definition: viewsettings.h:35
QPointF cursorMeasurementPosition
Definition: dsowidget.h:120
void showNew(std::shared_ptr< PPresult > analysedData)
Prints analyzed data.
Definition: dsowidget.cpp:939
QLabel * settingsSamplerateLabel
The samplerate.
Definition: dsowidget.h:71
void updateMarker(unsigned marker, double value)
Handles valueChanged signal from the marker slider.
Definition: dsowidget.cpp:1243
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:688
QLabel * settingsSamplesOnScreen
The displayed dots on screen.
Definition: dsowidget.h:70
const Dso::ControlSpecification * spec
Definition: dsowidget.h:103
void triggerLevelChanged(ChannelID channel, double value)
A trigger level has been changed.
unsigned ChannelID
Definition: types.h:6
double zoomFactor
Definition: dsowidget.h:113
Sliders zoomSliders
Definition: dsowidget.h:64
void updateItem(ChannelID index, bool switchOn=false)
Definition: dsowidget.cpp:417
void updateSpectrumUsed(ChannelID channel, bool used)
Handles usedChanged signal from the spectrum dock.
Definition: dsowidget.cpp:785
QGridLayout * measurementLayout
The table for the signal details.
Definition: dsowidget.h:84
void updateRecordLength(int size)
Change the record length.
Definition: dsowidget.cpp:889
QLabel * settingsTimebaseLabel
The timebase of the main scope.
Definition: dsowidget.h:72
QPoint cursorGlobalPosition
Definition: dsowidget.h:119
void updateSlidersSettings()
Update the sliders settings.
Definition: dsowidget.cpp:1253
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:115
void updateVoltageCoupling(ChannelID channel)
Handles couplingChanged signal from the voltage dock.
Definition: dsowidget.cpp:836
~DsoWidget() override
Definition: dsowidget.cpp:304
std::vector< QLabel *> measurementRMSLabel
RMS Amplitude of the signal (V) = sqrt( DC² + AC² )
Definition: dsowidget.h:90
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:111
void updateSpectrumMagnitude(ChannelID channel)
Handles magnitudeChanged signal from the spectrum dock.
Definition: dsowidget.cpp:776
void updateSamplerate(double samplerate)
Updates the samplerate field after changing the samplerate.
Definition: dsowidget.cpp:755
std::vector< QLabel *> measurementDCLabel
DC Amplitude of the signal (V)
Definition: dsowidget.h:91
QLabel * markerTimeLabel
The time period between the markers.
Definition: dsowidget.h:79
void updateFrequencybase(double frequencybase)
Handles frequencybaseChanged signal from the horizontal dock.
Definition: dsowidget.cpp:747
QHBoxLayout * markerLayout
The table for the marker details.
Definition: dsowidget.h:77
ChannelID selectedCursor
Definition: dsowidget.h:121
void updateTriggerPosition(int index, double value, bool pressed, QPoint globalPos, bool mainView=true)
Handles valueChanged signal from the triggerPosition slider.
Definition: dsowidget.cpp:1180
std::vector< QLabel *> measurementNameLabel
The name of the channel.
Definition: dsowidget.h:85
double timebase
Definition: dsowidget.h:110
void updateTriggerSource()
Handles sourceChanged signal from the trigger dock.
Definition: dsowidget.cpp:818