Skip to content

Commit

Permalink
i18n for dB suffix "V", "u", "m"; silence more warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Martin <[email protected]>
  • Loading branch information
Ho-Ro committed Mar 9, 2023
1 parent 507633c commit f261305
Show file tree
Hide file tree
Showing 15 changed files with 851 additions and 487 deletions.
17 changes: 5 additions & 12 deletions openhantek/src/configdialog/DsoConfigAnalysisPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ DsoConfigAnalysisPage::DsoConfigAnalysisPage( DsoSettings *settings, QWidget *pa
for ( auto wf : Dso::WindowFunctionEnum ) {
windowFunctionStrings.append( Dso::windowFunctionString( wf ) );
}

// Initialize elements
dBsuffix = settings->scope.analysis.dBsuffix;

windowFunctionLabel = new QLabel( tr( "Window function" ) );
windowFunctionComboBox = new QComboBox();
windowFunctionComboBox->addItems( windowFunctionStrings );
Expand All @@ -25,7 +22,7 @@ DsoConfigAnalysisPage::DsoConfigAnalysisPage( DsoSettings *settings, QWidget *pa
minimumMagnitudeSpinBox->setMinimum( -100.0 );
minimumMagnitudeSpinBox->setMaximum( 100.0 );
minimumMagnitudeSpinBox->setValue( settings->analysis.spectrumLimit );
minimumMagnitudeUnitLabel = new QLabel( QString( "dB" ) + dBsuffix );
minimumMagnitudeUnitLabel = new QLabel( tr( "dB" ) + settings->scope.analysis.dBsuffix() );
minimumMagnitudeLayout = new QHBoxLayout();
minimumMagnitudeLayout->addWidget( minimumMagnitudeSpinBox );
minimumMagnitudeLayout->addWidget( minimumMagnitudeUnitLabel );
Expand Down Expand Up @@ -69,7 +66,7 @@ DsoConfigAnalysisPage::DsoConfigAnalysisPage( DsoSettings *settings, QWidget *pa

referenceLevelButtonLayout = new QGridLayout();
dBVButton = new QPushButton( tr( "0 dBV" ) );
dBVLabel = new QLabel();
dBVLabel = new QLabel( tr( "<p>= 1 Vrms</p>" ) );
dBuButton = new QPushButton( tr( "0 dBu" ) );
dBuLabel = new QLabel( tr( "<p>= -2.2 dBV (1 mW @ 600 &Omega;)</p>" ) );
dBmButton = new QPushButton( tr( "0 dBm" ) );
Expand All @@ -84,20 +81,17 @@ DsoConfigAnalysisPage::DsoConfigAnalysisPage( DsoSettings *settings, QWidget *pa
connect( dBVButton, &QPushButton::clicked, referenceLevelSpinBox, [ this ]() {
referenceLevelSpinBox->setValue( 0.0 ); // set 0 dBV = 0 dBV
dummyLoadSpinBox->setValue( 50 ); // set RF load 50 Ohm
dBsuffix = "V";
minimumMagnitudeUnitLabel->setText( QString( "dB" ) + dBsuffix );
minimumMagnitudeUnitLabel->setText( tr( "dB" ) + this->settings->scope.analysis.dBsuffix( 0 ) );
} );
connect( dBuButton, &QPushButton::clicked, referenceLevelSpinBox, [ this ]() {
referenceLevelSpinBox->setValue( -2.2 ); // set 0 dBu = -2.2 dBV
dummyLoadSpinBox->setValue( 600 ); // set telco load 600 Ohm
dBsuffix = "u";
minimumMagnitudeUnitLabel->setText( QString( "dB" ) + dBsuffix );
minimumMagnitudeUnitLabel->setText( tr( "dB" ) + this->settings->scope.analysis.dBsuffix( 1 ) );
} );
connect( dBmButton, &QPushButton::clicked, referenceLevelSpinBox, [ this ]() {
referenceLevelSpinBox->setValue( -13.0 ); // set 0 dBm = -13 dBV
dummyLoadSpinBox->setValue( 50 ); // set RF load 50 Ohm
dBsuffix = "m";
minimumMagnitudeUnitLabel->setText( QString( "dB" ) + dBsuffix );
minimumMagnitudeUnitLabel->setText( tr( "dB" ) + this->settings->scope.analysis.dBsuffix( 2 ) );
} );

referenceLayout = new QGridLayout();
Expand Down Expand Up @@ -149,7 +143,6 @@ DsoConfigAnalysisPage::DsoConfigAnalysisPage( DsoSettings *settings, QWidget *pa
/// \brief Saves the new settings.
void DsoConfigAnalysisPage::saveSettings() {
settings->scope.analysis.spectrumReference = referenceLevelSpinBox->value();
settings->scope.analysis.dBsuffix = dBsuffix;
settings->analysis.spectrumWindow = Dso::WindowFunction( windowFunctionComboBox->currentIndex() );
settings->analysis.spectrumLimit = minimumMagnitudeSpinBox->value();
settings->analysis.reuseFftPlan = reuseFftPlanCheckBox->isChecked();
Expand Down
1 change: 0 additions & 1 deletion openhantek/src/configdialog/DsoConfigAnalysisPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class DsoConfigAnalysisPage : public QWidget {
QLabel *dBmLabel;
QGridLayout *referenceLevelButtonLayout;
QDoubleSpinBox *referenceLevelSpinBox;
QString dBsuffix = "V";
QLabel *referenceLevelUnitLabel;
QHBoxLayout *referenceLevelLayout;

Expand Down
6 changes: 3 additions & 3 deletions openhantek/src/dsosettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ void DsoSettings::load() {
storeSettings->beginGroup( "analysis" );
if ( storeSettings->contains( "spectrumReference" ) )
scope.analysis.spectrumReference = storeSettings->value( "spectrumReference" ).toDouble();
if ( storeSettings->contains( "dBsuffix" ) )
scope.analysis.dBsuffix = storeSettings->value( "dBsuffix" ).toString();
if ( storeSettings->contains( "dBsuffixIndex" ) )
scope.analysis.dBsuffixIndex = storeSettings->value( "dBsuffixIndex" ).toInt();
if ( storeSettings->contains( "calculateDummyLoad" ) )
scope.analysis.calculateDummyLoad = storeSettings->value( "calculateDummyLoad" ).toBool();
if ( storeSettings->contains( "dummyLoad" ) )
Expand Down Expand Up @@ -439,7 +439,7 @@ void DsoSettings::save() {
// Analysis
storeSettings->beginGroup( "analysis" );
storeSettings->setValue( "spectrumReference", scope.analysis.spectrumReference );
storeSettings->setValue( "dBsuffix", scope.analysis.dBsuffix );
storeSettings->setValue( "dBsuffixIndex", scope.analysis.dBsuffixIndex );
storeSettings->setValue( "calculateDummyLoad", scope.analysis.calculateDummyLoad );
storeSettings->setValue( "dummyLoad", scope.analysis.dummyLoad );
storeSettings->setValue( "calculateTHD", scope.analysis.calculateTHD );
Expand Down
40 changes: 21 additions & 19 deletions openhantek/src/dsowidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ DsoWidget::DsoWidget( DsoSettingsScope *scope, DsoSettingsView *view, const Dso:
setupSliders( zoomSliders );

// movement of the two vertical markers "1" and "2"
connect( mainScope, &GlScope::markerMoved, [ this ]( int cursorIndex, int marker ) {
connect( mainScope, &GlScope::markerMoved, mainScope, [ this ]( int cursorIndex, int marker ) {
mainSliders.markerSlider->setValue( marker, this->scope->getMarker( marker ) );
mainScope->updateCursor( cursorIndex );
zoomScope->updateCursor( cursorIndex );
} );
connect( zoomScope, &GlScope::markerMoved, [ this ]( int cursorIndex, int marker ) {
connect( zoomScope, &GlScope::markerMoved, mainScope, [ this ]( int cursorIndex, int marker ) {
mainSliders.markerSlider->setValue( int( marker ), this->scope->getMarker( marker ) );
mainScope->updateCursor( cursorIndex );
zoomScope->updateCursor( cursorIndex );
} );

// do cursor measurement when right button pressed/moved _inside_ window borders
connect( mainScope, &GlScope::cursorMeasurement, [ this ]( QPointF mPos, QPoint gPos, bool status ) {
connect( mainScope, &GlScope::cursorMeasurement, this, [ this ]( QPointF mPos, QPoint gPos, bool status ) {
cursorMeasurementPosition = mPos;
cursorGlobalPosition = gPos;
cursorMeasurementValid = status;
if ( !status )
showCursorMessage(); // switch off
} );
connect( zoomScope, &GlScope::cursorMeasurement, [ this ]( QPointF mPos, QPoint gPos, bool status ) {
connect( zoomScope, &GlScope::cursorMeasurement, this, [ this ]( QPointF mPos, QPoint gPos, bool status ) {
cursorMeasurementPosition = mPos;
cursorGlobalPosition = gPos;
cursorMeasurementValid = status;
Expand Down Expand Up @@ -200,13 +200,13 @@ DsoWidget::DsoWidget( DsoSettingsScope *scope, DsoSettingsView *view, const Dso:
}
cursorDataGrid->selectItem( 0 );

connect( cursorDataGrid, &DataGrid::itemSelected, [ this ]( int index ) {
connect( cursorDataGrid, &DataGrid::itemSelected, mainScope, [ this ]( int index ) {
mainScope->selectCursor( index );
zoomScope->selectCursor( index );
updateItem( ChannelID( index ), true );
} );

connect( cursorDataGrid, &DataGrid::itemUpdated, [ this ]( int index ) { updateItem( ChannelID( index ) ); } );
connect( cursorDataGrid, &DataGrid::itemUpdated, this, [ this ]( int index ) { updateItem( ChannelID( index ) ); } );

scope->horizontal.cursor.shape = DsoSettingsScopeCursor::VERTICAL;

Expand Down Expand Up @@ -268,11 +268,11 @@ DsoWidget::DsoWidget( DsoSettingsScope *scope, DsoSettingsView *view, const Dso:
connect( mainSliders.voltageOffsetSlider, &LevelSlider::valueChanged, this, &DsoWidget::updateOffset );
connect( zoomSliders.voltageOffsetSlider, &LevelSlider::valueChanged, this, &DsoWidget::updateOffset );

connect( mainSliders.triggerPositionSlider, &LevelSlider::valueChanged,
connect( mainSliders.triggerPositionSlider, &LevelSlider::valueChanged, this,
[ this ]( int index, double value, bool pressed, QPoint globalPos ) {
updateTriggerPosition( index, value, pressed, globalPos, true );
} );
connect( zoomSliders.triggerPositionSlider, &LevelSlider::valueChanged,
connect( zoomSliders.triggerPositionSlider, &LevelSlider::valueChanged, this,
[ this ]( int index, double value, bool pressed, QPoint globalPos ) {
updateTriggerPosition( index, value, pressed, globalPos, false );
} );
Expand All @@ -281,14 +281,16 @@ DsoWidget::DsoWidget( DsoSettingsScope *scope, DsoSettingsView *view, const Dso:
connect( zoomSliders.triggerLevelSlider, &LevelSlider::valueChanged, this, &DsoWidget::updateTriggerLevel );

// show a horizontal level line as long as the trigger level slider is active
connect( mainSliders.triggerLevelSlider, &LevelSlider::valueChanged, [ this ]( int index, double value, bool pressed ) {
mainScope->generateGrid( index, value, pressed );
zoomScope->generateGrid( index, value, pressed );
} );
connect( zoomSliders.triggerLevelSlider, &LevelSlider::valueChanged, [ this ]( int index, double value, bool pressed ) {
mainScope->generateGrid( index, value, pressed );
zoomScope->generateGrid( index, value, pressed );
} );
connect( mainSliders.triggerLevelSlider, &LevelSlider::valueChanged, mainScope,
[ this ]( int index, double value, bool pressed ) {
mainScope->generateGrid( index, value, pressed );
zoomScope->generateGrid( index, value, pressed );
} );
connect( zoomSliders.triggerLevelSlider, &LevelSlider::valueChanged, mainScope,
[ this ]( int index, double value, bool pressed ) {
mainScope->generateGrid( index, value, pressed );
zoomScope->generateGrid( index, value, pressed );
} );

connect( mainSliders.markerSlider, &LevelSlider::valueChanged, [ this ]( int index, double value ) {
updateMarker( unsigned( index ), value );
Expand Down Expand Up @@ -610,7 +612,7 @@ void DsoWidget::updateMarkerDetails() {
unsigned( index ), true, tr( "ON" ),
valueToString( fabs( p1.x() - p0.x() ) * scope->horizontal.frequencybase, UNIT_HERTZ, 4 ),
valueToString( fabs( p1.y() - p0.y() ) * scope->spectrum[ channel ].magnitude, UNIT_DECIBEL, 4 ) +
scope->analysis.dBsuffix );
scope->analysis.dBsuffix() );
} else {
cursorDataGrid->updateInfo( unsigned( index ), true, tr( "OFF" ), "", "" );
}
Expand Down Expand Up @@ -995,7 +997,7 @@ void DsoWidget::showNew( std::shared_ptr< PPresult > analysedData ) {
if ( mCursor > data->dBmin - 0.2 * scope->spectrum[ channel ].magnitude &&
mCursor <= data->dBmax + 0.2 * scope->spectrum[ channel ].magnitude )
mStr += '\t' + scope->spectrum[ channel ].name + ": " + valueToString( mCursor, UNIT_DECIBEL, 3 ) +
scope->analysis.dBsuffix;
scope->analysis.dBsuffix();
}
}
// Vpp Amplitude string representation (3 significant digits)
Expand All @@ -1007,7 +1009,7 @@ void DsoWidget::showNew( std::shared_ptr< PPresult > analysedData ) {
// RMS Amplitude string representation (3 significant digits)
measurementRMSLabel[ channel ]->setText( valueToString( data->rms, voltageUnit, 3 ) + tr( "rms" ) );
// dB Amplitude string representation (3 significant digits)
measurementdBLabel[ channel ]->setText( valueToString( data->dB, UNIT_DECIBEL, 3 ) + scope->analysis.dBsuffix );
measurementdBLabel[ channel ]->setText( valueToString( data->dB, UNIT_DECIBEL, 3 ) + scope->analysis.dBsuffix() );
// Frequency string representation (3 significant digits)
measurementFrequencyLabel[ channel ]->setText( valueToString( data->frequency, UNIT_HERTZ, 4 ) );
// Frequency note representation
Expand Down
12 changes: 10 additions & 2 deletions openhantek/src/scopesettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#pragma once

#include <QCoreApplication>
#include <QPointF>
#include <QString>

#include "hantekdso/controlspecification.h"
#include "hantekdso/enums.h"
Expand Down Expand Up @@ -68,7 +68,15 @@ struct DsoSettingsScopeAnalysis {
double spectrumReference = 0.0; ///< Reference level for spectrum in dBV
bool calculateDummyLoad = false;
unsigned dummyLoad = 50; ///< Dummy load in Ohms
QString dBsuffix = "V"; // dBV is default
QString dBsuffixStrings[ 3 ] = { QCoreApplication::translate( "DsoSettingsScopeAnalysis", "V" ),
QCoreApplication::translate( "DsoSettingsScopeAnalysis", "u" ),
QCoreApplication::translate( "DsoSettingsScopeAnalysis", "m" ) };
int dBsuffixIndex = 0; // dBV is default
QString dBsuffix( int index = -1 ) { // default is invalid -> keep old index
if ( index >= 0 && index < 3 ) // valid suffix index
dBsuffixIndex = index; // set new index
return dBsuffixStrings[ dBsuffixIndex ];
};
bool calculateTHD = false;
bool showNoteValue = false;
};
Expand Down
3 changes: 2 additions & 1 deletion openhantek/src/usb/scopedevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ bool ScopeDevice::connectDevice( QString &errorMessage ) {
int errorCode = libusb_open( device, &( handle ) );
if ( errorCode != LIBUSB_SUCCESS ) {
handle = nullptr;
errorMessage = QCoreApplication::translate( "", "Couldn't open device: %1" ).arg( libUsbErrorString( errorCode ) );
errorMessage =
QCoreApplication::translate( "ScopeDevice", "Couldn't open device: %1" ).arg( libUsbErrorString( errorCode ) );
return false;
}
serialNumber = readUSBdescriptor( handle, descriptor.iSerialNumber );
Expand Down
Loading

0 comments on commit f261305

Please sign in to comment.