From ec1196f03a49ef2175168032b7defa2572375f01 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 12 Nov 2019 13:43:26 +0100 Subject: [PATCH] more logical marker status display Signed-off-by: Martin --- openhantek/src/OH_BUILD.h | 2 +- openhantek/src/dsowidget.cpp | 107 +++++++++++------- .../src/exporting/legacyexportdrawer.cpp | 53 ++++++--- openhantek/translations/openhantek_de.ts | 78 ++++++++----- openhantek/translations/openhantek_fr.ts | 76 ++++++++----- openhantek/translations/openhantek_it.ts | 76 ++++++++----- openhantek/translations/openhantek_pt.ts | 78 ++++++++----- 7 files changed, 295 insertions(+), 175 deletions(-) diff --git a/openhantek/src/OH_BUILD.h b/openhantek/src/OH_BUILD.h index f8b68f7f..73fcf950 100644 --- a/openhantek/src/OH_BUILD.h +++ b/openhantek/src/OH_BUILD.h @@ -1,2 +1,2 @@ // Do not edit, will be re-created at each commit! -#define OH_BUILD "20191109 build 547" +#define OH_BUILD "20191112 build 548" diff --git a/openhantek/src/dsowidget.cpp b/openhantek/src/dsowidget.cpp index 694f7ef1..5df04719 100644 --- a/openhantek/src/dsowidget.cpp +++ b/openhantek/src/dsowidget.cpp @@ -81,7 +81,7 @@ DsoWidget::DsoWidget(DsoSettingsScope *scope, DsoSettingsView *view, const Dso:: // The table for the marker details markerInfoLabel = new QLabel(); - markerInfoLabel->setMinimumWidth(160); + markerInfoLabel->setAlignment(Qt::AlignLeft); markerInfoLabel->setPalette(palette); markerTimeLabel = new QLabel(); markerTimeLabel->setAlignment(Qt::AlignRight); @@ -406,54 +406,32 @@ void DsoWidget::setMeasurementVisible(ChannelID channel) { if (!scope->spectrum[channel].used) { measurementMagnitudeLabel[channel]->setText(QString()); } } -static QString markerToString(DsoSettingsScope *scope, unsigned index) { - double value = (DIVS_TIME * (0.5 - scope->trigger.position) + scope->getMarker(index)) * scope->horizontal.timebase; - int precision = 3 - (int)floor(log10(fabs(value))); - - if (scope->horizontal.timebase < 1e-9) - return QApplication::tr("%L1 ps").arg(value / 1e-12, 0, 'f', qBound(0, precision - 12, 3)); - else if (scope->horizontal.timebase < 1e-6) - return QApplication::tr("%L1 ns").arg(value / 1e-9, 0, 'f', qBound(0, precision - 9, 3)); - else if (scope->horizontal.timebase < 1e-3) - return QApplication::tr("%L1 µs").arg(value / 1e-6, 0, 'f', qBound(0, precision - 6, 3)); - else if (scope->horizontal.timebase < 1) - return QApplication::tr("%L1 ms").arg(value / 1e-3, 0, 'f', qBound(0, precision - 3, 3)); - else - return QApplication::tr("%L1 s").arg(value, 0, 'f', qBound(0, precision, 3)); -} /// \brief Update the label about the marker measurements void DsoWidget::updateMarkerDetails() { - double divs = fabs(scope->horizontal.cursor.pos[1].x() - scope->horizontal.cursor.pos[0].x()); + double div0 = scope->horizontal.cursor.pos[0].x(); + double div1 = scope->horizontal.cursor.pos[1].x(); + if ( div0 > div1 ) + std::swap( div0, div1 ); + double divs = div1 - div0; + double time0 = div0 * scope->horizontal.timebase; + double time1 = div1 * scope->horizontal.timebase; double time = divs * scope->horizontal.timebase; - - QString prefix(tr("Markers")); - if (view->zoom) { - if ( divs != 0.0 ) - prefix = tr("Zoom x%L1").arg(DIVS_TIME / divs, -1, 'g', 3); - else // avoid div by zero - prefix = tr("Zoom ---"); - markerTimebaseLabel->setText(valueToString(time / DIVS_TIME, UNIT_SECONDS, 3) + tr("/div")); - markerFrequencybaseLabel->setText( - valueToString(divs * scope->horizontal.frequencybase / DIVS_TIME, UNIT_HERTZ, 4) + tr("/div")); - } - markerInfoLabel->setText(prefix.append(": %1 %2").arg(markerToString(scope, 0)).arg(markerToString(scope, 1))); - markerTimeLabel->setText(valueToString(time, UNIT_SECONDS, 4)); - if ( time != 0.0 ) - markerFrequencyLabel->setText(valueToString(1.0 / time, UNIT_HERTZ, 4)); - else // avoid div by zero - markerFrequencyLabel->setText( "--- Hz" ); + div0 += DIVS_TIME / 2; // zero at center -> zero at left margin + div1 += DIVS_TIME / 2; + double freq0 = div0 * scope->horizontal.frequencybase; + double freq1 = div1 * scope->horizontal.frequencybase; + double freq = divs * scope->horizontal.frequencybase; + bool timeUsed = false; + bool freqUsed = false; int index = 0; - if ( time != 0.0 ) - cursorDataGrid->updateInfo(index++, true, QString(), - valueToString(time, UNIT_SECONDS, 4), valueToString(1.0 / time, UNIT_HERTZ, 4)); - else // avoid div by zero - cursorDataGrid->updateInfo(index++, true, QString(), - valueToString(time, UNIT_SECONDS, 4), "--- Hz"); + cursorDataGrid->updateInfo(index++, true, QString(), + valueToString(time, UNIT_SECONDS, 3), valueToString( freq, UNIT_HERTZ, 3 ) ); for (ChannelID channel = 0; channel < scope->voltage.size(); ++channel) { if (scope->voltage[channel].used) { + timeUsed = true; // at least one voltage channel used -> show marker time details QPointF p0 = scope->voltage[channel].cursor.pos[0]; QPointF p1 = scope->voltage[channel].cursor.pos[1]; cursorDataGrid->updateInfo(index, true, @@ -467,6 +445,7 @@ void DsoWidget::updateMarkerDetails() { } for (ChannelID channel = 0; channel < scope->spectrum.size(); ++channel) { if (scope->spectrum[channel].used) { + freqUsed = true; // at least one spec channel used -> show marker freq details QPointF p0 = scope->spectrum[channel].cursor.pos[0]; QPointF p1 = scope->spectrum[channel].cursor.pos[1]; cursorDataGrid->updateInfo(index, true, @@ -478,6 +457,53 @@ void DsoWidget::updateMarkerDetails() { } ++index; } + + if ( DIVS_TIME == divs || (div0 == 0 && div1 == 0) || (div0 == DIVS_TIME && div1 == DIVS_TIME) ) { + // markers at left/right margins -> don't display + markerInfoLabel->setVisible( false ); + markerTimeLabel->setVisible( false ); + markerFrequencyLabel->setVisible( false ); + markerTimebaseLabel->setVisible( false ); + markerFrequencybaseLabel->setVisible( false ); + } else { + markerInfoLabel->setVisible( true ); + markerTimeLabel->setVisible( true ); + markerFrequencyLabel->setVisible( true ); + markerTimebaseLabel->setVisible( view->zoom ); + markerFrequencybaseLabel->setVisible( view->zoom ); + QString mInfo( tr( "Markers ") ); + QString mTime( tr( "Time: ") ); + QString mFreq( tr( "Frequency: ") ); + if (view->zoom) { + if ( divs != 0.0 ) + mInfo = tr( "Zoom x%L1 " ).arg( DIVS_TIME / divs, -1, 'g', 3 ); + else // avoid div by zero + mInfo = tr( "Zoom --- " ); + mTime = " t: "; + mFreq = " f: "; + markerTimebaseLabel->setText(" " + valueToString( time / DIVS_TIME, UNIT_SECONDS, 3 ) + tr("/div")); + markerTimebaseLabel->setVisible( timeUsed ); + markerFrequencybaseLabel->setText( " " + valueToString( freq / DIVS_TIME, UNIT_HERTZ, 3 ) + tr("/div")); + markerFrequencybaseLabel->setVisible( freqUsed ); + } + markerInfoLabel->setText( mInfo ); + if ( timeUsed ) + markerTimeLabel->setText( mTime.append( "%1 -> %2, Δt: %3 " ) + .arg( valueToString( time0, UNIT_SECONDS, 4 ) ) + .arg( valueToString( time1, UNIT_SECONDS, 4 ) ) + .arg( valueToString( time, UNIT_SECONDS, 4 ) ) + ); + else + markerTimeLabel->setText( "" ); + if ( freqUsed ) + markerFrequencyLabel->setText( mFreq.append( "%1 -> %2, Δf: %3 " ) + .arg( valueToString( freq0, UNIT_HERTZ, 4) ) + .arg( valueToString( freq1, UNIT_HERTZ, 4) ) + .arg( valueToString( freq, UNIT_HERTZ, 4) ) + ); + else + markerFrequencyLabel->setText( "" ); + } } /// \brief Update the label about the trigger settings @@ -535,6 +561,7 @@ void DsoWidget::updateVoltageDetails(ChannelID channel) { /// \param frequencybase The frequencybase used for displaying the trace. void DsoWidget::updateFrequencybase(double frequencybase) { settingsFrequencybaseLabel->setText(valueToString(frequencybase, UNIT_HERTZ, -1) + tr("/div")); + updateMarkerDetails(); } /// \brief Updates the samplerate field after changing the samplerate. diff --git a/openhantek/src/exporting/legacyexportdrawer.cpp b/openhantek/src/exporting/legacyexportdrawer.cpp index 095b3a52..4546e9fc 100644 --- a/openhantek/src/exporting/legacyexportdrawer.cpp +++ b/openhantek/src/exporting/legacyexportdrawer.cpp @@ -173,18 +173,27 @@ bool LegacyExportDrawer::exportSamples(const PPresult *result, QPaintDevice* pai } // Draw the marker table - stretchBase = (double)paintDevice->width() / 5; painter.setPen(colorValues->text); // Calculate variables needed for zoomed scope double m1 = settings->scope.getMarker(0); double m2 = settings->scope.getMarker(1); - double divs = fabs(m2 - m1); - double time = divs * settings->scope.horizontal.timebase; + if ( m1 > m2 ) + std::swap( m1, m2 ); + double divs = m2 - m1; double zoomFactor = DIVS_TIME / divs; double zoomOffset = (m1 + m2) / 2; + double time1 = m1 * settings->scope.horizontal.timebase; + double time2 = m2 * settings->scope.horizontal.timebase; + double time = divs * settings->scope.horizontal.timebase; + m1 += DIVS_TIME / 2; // zero at center -> zero at left margin + m2 += DIVS_TIME / 2; + double freq1 = m1 * settings->scope.horizontal.frequencybase; + double freq2 = m2 * settings->scope.horizontal.frequencybase; + double freq = freq2 - freq1; if (settings->view.zoom) { + stretchBase = (double)paintDevice->width() / 9; scopeHeight = (double)(paintDevice->height() - (channelCount + 5) * lineHeight) / 2; double top = 2.5 * lineHeight + scopeHeight; @@ -192,27 +201,43 @@ bool LegacyExportDrawer::exportSamples(const PPresult *result, QPaintDevice* pai tr("Zoom x%L1").arg(DIVS_TIME / divs, -1, 'g', 3)); painter.drawText(QRectF(stretchBase, top, stretchBase, lineHeight), - valueToString(time, UNIT_SECONDS, 4), QTextOption(Qt::AlignRight)); + valueToString( time1, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight)); painter.drawText(QRectF(stretchBase * 2, top, stretchBase, lineHeight), - valueToString(1.0 / time, UNIT_HERTZ, 4), QTextOption(Qt::AlignRight)); - + valueToString( time2, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight)); painter.drawText(QRectF(stretchBase * 3, top, stretchBase, lineHeight), - valueToString(time / DIVS_TIME, UNIT_SECONDS, 3) + tr("/div"), - QTextOption(Qt::AlignRight)); + valueToString( time, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight)); painter.drawText(QRectF(stretchBase * 4, top, stretchBase, lineHeight), - valueToString(divs * settings->scope.horizontal.frequencybase / DIVS_TIME, UNIT_HERTZ, 3) + + valueToString( freq1, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight)); + painter.drawText(QRectF(stretchBase * 5, top, stretchBase, lineHeight), + valueToString( freq2, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight)); + painter.drawText(QRectF(stretchBase * 6, top, stretchBase, lineHeight), + valueToString( freq, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight)); + + painter.drawText(QRectF(stretchBase * 7, top, stretchBase, lineHeight), + valueToString( time / DIVS_TIME, UNIT_SECONDS, 3 ) + tr("/div"), + QTextOption(Qt::AlignRight)); + painter.drawText(QRectF(stretchBase * 8, top, stretchBase, lineHeight), + valueToString( freq / DIVS_TIME, UNIT_HERTZ, 3 ) + tr("/div"), QTextOption(Qt::AlignRight)); } else { + stretchBase = (double)paintDevice->width() / 7; scopeHeight = (double)paintDevice->height() - (channelCount + 4) * lineHeight; double top = 2.5 * lineHeight + scopeHeight; painter.drawText(QRectF(0, top, stretchBase, lineHeight), tr("Marker 1/2")); - - painter.drawText(QRectF(stretchBase * 0, top, stretchBase, lineHeight), - valueToString(time, UNIT_SECONDS, 4), QTextOption(Qt::AlignRight)); - painter.drawText(QRectF(stretchBase * 1, top, stretchBase, lineHeight), - valueToString(1.0 / time, UNIT_HERTZ, 4), QTextOption(Qt::AlignRight)); + painter.drawText(QRectF(stretchBase, top, stretchBase, lineHeight), + "t1: " + valueToString( time1, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight)); + painter.drawText(QRectF(stretchBase * 2, top, stretchBase, lineHeight), + "t2: " + valueToString( time2, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight)); + painter.drawText(QRectF(stretchBase * 3, top, stretchBase, lineHeight), + "Δt: " + valueToString( time, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight)); + painter.drawText(QRectF(stretchBase * 4, top, stretchBase, lineHeight), + "f1: " + valueToString( freq1, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight)); + painter.drawText(QRectF(stretchBase * 5, top, stretchBase, lineHeight), + "f2: " + valueToString( freq2, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight)); + painter.drawText(QRectF(stretchBase * 6, top, stretchBase, lineHeight), + "Δf: " + valueToString( freq, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight)); } // Set DIVS_TIME x DIVS_VOLTAGE matrix for oscillograph diff --git a/openhantek/translations/openhantek_de.ts b/openhantek/translations/openhantek_de.ts index b7f9ece7..b2a0c6b1 100644 --- a/openhantek/translations/openhantek_de.ts +++ b/openhantek/translations/openhantek_de.ts @@ -321,17 +321,16 @@ DsoWidget - Zoom x%L1 - Zoom x%L1 + Zoom x%L1 - - - - - - + + + + + + /div /div @@ -342,34 +341,57 @@ - Markers Marker - Zoom --- - Zoom --- + Zoom --- - - + + ON EIN - - + + OFF AUS - + + Markers + + + + + Time: + + + + + Frequency: + + + + + Zoom x%L1 + + + + + Zoom --- + + + + %L1% %L1% - + %1 %2 %3 %4 %5 %1 %2 %3 %4 %5 @@ -386,12 +408,12 @@ %1 %2 %3 %4 - + /s /s - + on screen angezeigt @@ -528,18 +550,18 @@ - - + + /div /div - + Zoom x%L1 Zoom x%L1 - + Marker 1/2 Marker 1/2 @@ -880,25 +902,25 @@ - + %L1 ps %L1 ps - + %L1 ns %L1 ns - + %L1 ms %L1 ms - + %L1 s %L1 s @@ -917,7 +939,7 @@ - + %L1 µs %L1 µs diff --git a/openhantek/translations/openhantek_fr.ts b/openhantek/translations/openhantek_fr.ts index 1bc02725..2ace7c0e 100644 --- a/openhantek/translations/openhantek_fr.ts +++ b/openhantek/translations/openhantek_fr.ts @@ -316,59 +316,73 @@ - Markers - - Zoom x%L1 + + + + + + + /div - - Zoom --- + + + ON - - - - - - - /div + + + OFF - - - ON + + Markers - - - OFF + + Time: + + + + + Frequency: + + + + + Zoom x%L1 + + + + + Zoom --- - + %L1% - + %1 %2 %3 %4 %5 - + /s - + on screen @@ -485,18 +499,18 @@ - - + + /div - + Zoom x%L1 - + Marker 1/2 @@ -834,31 +848,31 @@ - + %L1 ps - + %L1 ns - + %L1 µs - + %L1 ms - + %L1 s diff --git a/openhantek/translations/openhantek_it.ts b/openhantek/translations/openhantek_it.ts index b0be2352..7dd85fa0 100644 --- a/openhantek/translations/openhantek_it.ts +++ b/openhantek/translations/openhantek_it.ts @@ -316,59 +316,73 @@ - Markers - - Zoom x%L1 + + + + + + + /div - - Zoom --- + + + ON - - - - - - - /div + + + OFF - - - ON + + Markers - - - OFF + + Time: + + + + + Frequency: + + + + + Zoom x%L1 + + + + + Zoom --- - + %L1% - + %1 %2 %3 %4 %5 - + /s - + on screen @@ -485,18 +499,18 @@ - - + + /div - + Zoom x%L1 - + Marker 1/2 @@ -834,31 +848,31 @@ - + %L1 ps - + %L1 ns - + %L1 µs - + %L1 ms - + %L1 s diff --git a/openhantek/translations/openhantek_pt.ts b/openhantek/translations/openhantek_pt.ts index da5113af..f3ca11ee 100644 --- a/openhantek/translations/openhantek_pt.ts +++ b/openhantek/translations/openhantek_pt.ts @@ -310,17 +310,16 @@ DsoWidget - Zoom x%L1 - Zoom x%L1 + Zoom x%L1 - - - - - - + + + + + + /div /div @@ -331,39 +330,58 @@ - Markers Marcadores - - Zoom --- + + + ON - - - ON + + + OFF - - - OFF + + Markers + + + + + Time: + + + + + Frequency: + + + + + Zoom x%L1 + + + + + Zoom --- - + %L1% %L1% - + %1 %2 %3 %4 %5 - + on screen @@ -380,7 +398,7 @@ %1 %2 %3 %4 - + /s /s @@ -509,18 +527,18 @@ - - + + /div /div - + Zoom x%L1 Zoom x%L1 - + Marker 1/2 Construtor 1/2 @@ -861,25 +879,25 @@ - + %L1 ps %L1 ps - + %L1 ns %L1 ns - + %L1 ms %L1 ms - + %L1 s %L1 s @@ -890,7 +908,7 @@ - + %L1 µs