Skip to content

Commit ec1196f

Browse files
committed
more logical marker status display
Signed-off-by: Martin <Ho-Ro@users.noreply.github.com>
1 parent ccdceeb commit ec1196f

File tree

7 files changed

+295
-175
lines changed

7 files changed

+295
-175
lines changed

openhantek/src/OH_BUILD.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Do not edit, will be re-created at each commit!
2-
#define OH_BUILD "20191109 build 547"
2+
#define OH_BUILD "20191112 build 548"

openhantek/src/dsowidget.cpp

+67-40
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ DsoWidget::DsoWidget(DsoSettingsScope *scope, DsoSettingsView *view, const Dso::
8181

8282
// The table for the marker details
8383
markerInfoLabel = new QLabel();
84-
markerInfoLabel->setMinimumWidth(160);
84+
markerInfoLabel->setAlignment(Qt::AlignLeft);
8585
markerInfoLabel->setPalette(palette);
8686
markerTimeLabel = new QLabel();
8787
markerTimeLabel->setAlignment(Qt::AlignRight);
@@ -406,54 +406,32 @@ void DsoWidget::setMeasurementVisible(ChannelID channel) {
406406
if (!scope->spectrum[channel].used) { measurementMagnitudeLabel[channel]->setText(QString()); }
407407
}
408408

409-
static QString markerToString(DsoSettingsScope *scope, unsigned index) {
410-
double value = (DIVS_TIME * (0.5 - scope->trigger.position) + scope->getMarker(index)) * scope->horizontal.timebase;
411-
int precision = 3 - (int)floor(log10(fabs(value)));
412-
413-
if (scope->horizontal.timebase < 1e-9)
414-
return QApplication::tr("%L1 ps").arg(value / 1e-12, 0, 'f', qBound(0, precision - 12, 3));
415-
else if (scope->horizontal.timebase < 1e-6)
416-
return QApplication::tr("%L1 ns").arg(value / 1e-9, 0, 'f', qBound(0, precision - 9, 3));
417-
else if (scope->horizontal.timebase < 1e-3)
418-
return QApplication::tr("%L1 µs").arg(value / 1e-6, 0, 'f', qBound(0, precision - 6, 3));
419-
else if (scope->horizontal.timebase < 1)
420-
return QApplication::tr("%L1 ms").arg(value / 1e-3, 0, 'f', qBound(0, precision - 3, 3));
421-
else
422-
return QApplication::tr("%L1 s").arg(value, 0, 'f', qBound(0, precision, 3));
423-
}
424409

425410
/// \brief Update the label about the marker measurements
426411
void DsoWidget::updateMarkerDetails() {
427-
double divs = fabs(scope->horizontal.cursor.pos[1].x() - scope->horizontal.cursor.pos[0].x());
412+
double div0 = scope->horizontal.cursor.pos[0].x();
413+
double div1 = scope->horizontal.cursor.pos[1].x();
414+
if ( div0 > div1 )
415+
std::swap( div0, div1 );
416+
double divs = div1 - div0;
417+
double time0 = div0 * scope->horizontal.timebase;
418+
double time1 = div1 * scope->horizontal.timebase;
428419
double time = divs * scope->horizontal.timebase;
429-
430-
QString prefix(tr("Markers"));
431-
if (view->zoom) {
432-
if ( divs != 0.0 )
433-
prefix = tr("Zoom x%L1").arg(DIVS_TIME / divs, -1, 'g', 3);
434-
else // avoid div by zero
435-
prefix = tr("Zoom ---");
436-
markerTimebaseLabel->setText(valueToString(time / DIVS_TIME, UNIT_SECONDS, 3) + tr("/div"));
437-
markerFrequencybaseLabel->setText(
438-
valueToString(divs * scope->horizontal.frequencybase / DIVS_TIME, UNIT_HERTZ, 4) + tr("/div"));
439-
}
440-
markerInfoLabel->setText(prefix.append(": %1 %2").arg(markerToString(scope, 0)).arg(markerToString(scope, 1)));
441-
markerTimeLabel->setText(valueToString(time, UNIT_SECONDS, 4));
442-
if ( time != 0.0 )
443-
markerFrequencyLabel->setText(valueToString(1.0 / time, UNIT_HERTZ, 4));
444-
else // avoid div by zero
445-
markerFrequencyLabel->setText( "--- Hz" );
420+
div0 += DIVS_TIME / 2; // zero at center -> zero at left margin
421+
div1 += DIVS_TIME / 2;
422+
double freq0 = div0 * scope->horizontal.frequencybase;
423+
double freq1 = div1 * scope->horizontal.frequencybase;
424+
double freq = divs * scope->horizontal.frequencybase;
425+
bool timeUsed = false;
426+
bool freqUsed = false;
446427

447428
int index = 0;
448-
if ( time != 0.0 )
449-
cursorDataGrid->updateInfo(index++, true, QString(),
450-
valueToString(time, UNIT_SECONDS, 4), valueToString(1.0 / time, UNIT_HERTZ, 4));
451-
else // avoid div by zero
452-
cursorDataGrid->updateInfo(index++, true, QString(),
453-
valueToString(time, UNIT_SECONDS, 4), "--- Hz");
429+
cursorDataGrid->updateInfo(index++, true, QString(),
430+
valueToString(time, UNIT_SECONDS, 3), valueToString( freq, UNIT_HERTZ, 3 ) );
454431

455432
for (ChannelID channel = 0; channel < scope->voltage.size(); ++channel) {
456433
if (scope->voltage[channel].used) {
434+
timeUsed = true; // at least one voltage channel used -> show marker time details
457435
QPointF p0 = scope->voltage[channel].cursor.pos[0];
458436
QPointF p1 = scope->voltage[channel].cursor.pos[1];
459437
cursorDataGrid->updateInfo(index, true,
@@ -467,6 +445,7 @@ void DsoWidget::updateMarkerDetails() {
467445
}
468446
for (ChannelID channel = 0; channel < scope->spectrum.size(); ++channel) {
469447
if (scope->spectrum[channel].used) {
448+
freqUsed = true; // at least one spec channel used -> show marker freq details
470449
QPointF p0 = scope->spectrum[channel].cursor.pos[0];
471450
QPointF p1 = scope->spectrum[channel].cursor.pos[1];
472451
cursorDataGrid->updateInfo(index, true,
@@ -478,6 +457,53 @@ void DsoWidget::updateMarkerDetails() {
478457
}
479458
++index;
480459
}
460+
461+
if ( DIVS_TIME == divs || (div0 == 0 && div1 == 0) || (div0 == DIVS_TIME && div1 == DIVS_TIME) ) {
462+
// markers at left/right margins -> don't display
463+
markerInfoLabel->setVisible( false );
464+
markerTimeLabel->setVisible( false );
465+
markerFrequencyLabel->setVisible( false );
466+
markerTimebaseLabel->setVisible( false );
467+
markerFrequencybaseLabel->setVisible( false );
468+
} else {
469+
markerInfoLabel->setVisible( true );
470+
markerTimeLabel->setVisible( true );
471+
markerFrequencyLabel->setVisible( true );
472+
markerTimebaseLabel->setVisible( view->zoom );
473+
markerFrequencybaseLabel->setVisible( view->zoom );
474+
QString mInfo( tr( "Markers ") );
475+
QString mTime( tr( "Time: ") );
476+
QString mFreq( tr( "Frequency: ") );
477+
if (view->zoom) {
478+
if ( divs != 0.0 )
479+
mInfo = tr( "Zoom x%L1 " ).arg( DIVS_TIME / divs, -1, 'g', 3 );
480+
else // avoid div by zero
481+
mInfo = tr( "Zoom --- " );
482+
mTime = " t: ";
483+
mFreq = " f: ";
484+
markerTimebaseLabel->setText(" " + valueToString( time / DIVS_TIME, UNIT_SECONDS, 3 ) + tr("/div"));
485+
markerTimebaseLabel->setVisible( timeUsed );
486+
markerFrequencybaseLabel->setText( " " + valueToString( freq / DIVS_TIME, UNIT_HERTZ, 3 ) + tr("/div"));
487+
markerFrequencybaseLabel->setVisible( freqUsed );
488+
}
489+
markerInfoLabel->setText( mInfo );
490+
if ( timeUsed )
491+
markerTimeLabel->setText( mTime.append( "%1 -> %2, Δt: %3 " )
492+
.arg( valueToString( time0, UNIT_SECONDS, 4 ) )
493+
.arg( valueToString( time1, UNIT_SECONDS, 4 ) )
494+
.arg( valueToString( time, UNIT_SECONDS, 4 ) )
495+
);
496+
else
497+
markerTimeLabel->setText( "" );
498+
if ( freqUsed )
499+
markerFrequencyLabel->setText( mFreq.append( "%1 -> %2, Δf: %3 " )
500+
.arg( valueToString( freq0, UNIT_HERTZ, 4) )
501+
.arg( valueToString( freq1, UNIT_HERTZ, 4) )
502+
.arg( valueToString( freq, UNIT_HERTZ, 4) )
503+
);
504+
else
505+
markerFrequencyLabel->setText( "" );
506+
}
481507
}
482508

483509
/// \brief Update the label about the trigger settings
@@ -535,6 +561,7 @@ void DsoWidget::updateVoltageDetails(ChannelID channel) {
535561
/// \param frequencybase The frequencybase used for displaying the trace.
536562
void DsoWidget::updateFrequencybase(double frequencybase) {
537563
settingsFrequencybaseLabel->setText(valueToString(frequencybase, UNIT_HERTZ, -1) + tr("/div"));
564+
updateMarkerDetails();
538565
}
539566

540567
/// \brief Updates the samplerate field after changing the samplerate.

openhantek/src/exporting/legacyexportdrawer.cpp

+39-14
Original file line numberDiff line numberDiff line change
@@ -173,46 +173,71 @@ bool LegacyExportDrawer::exportSamples(const PPresult *result, QPaintDevice* pai
173173
}
174174

175175
// Draw the marker table
176-
stretchBase = (double)paintDevice->width() / 5;
177176
painter.setPen(colorValues->text);
178177

179178
// Calculate variables needed for zoomed scope
180179
double m1 = settings->scope.getMarker(0);
181180
double m2 = settings->scope.getMarker(1);
182-
double divs = fabs(m2 - m1);
183-
double time = divs * settings->scope.horizontal.timebase;
181+
if ( m1 > m2 )
182+
std::swap( m1, m2 );
183+
double divs = m2 - m1;
184184
double zoomFactor = DIVS_TIME / divs;
185185
double zoomOffset = (m1 + m2) / 2;
186+
double time1 = m1 * settings->scope.horizontal.timebase;
187+
double time2 = m2 * settings->scope.horizontal.timebase;
188+
double time = divs * settings->scope.horizontal.timebase;
189+
m1 += DIVS_TIME / 2; // zero at center -> zero at left margin
190+
m2 += DIVS_TIME / 2;
191+
double freq1 = m1 * settings->scope.horizontal.frequencybase;
192+
double freq2 = m2 * settings->scope.horizontal.frequencybase;
193+
double freq = freq2 - freq1;
186194

187195
if (settings->view.zoom) {
196+
stretchBase = (double)paintDevice->width() / 9;
188197
scopeHeight = (double)(paintDevice->height() - (channelCount + 5) * lineHeight) / 2;
189198
double top = 2.5 * lineHeight + scopeHeight;
190199

191200
painter.drawText(QRectF(0, top, stretchBase, lineHeight),
192201
tr("Zoom x%L1").arg(DIVS_TIME / divs, -1, 'g', 3));
193202

194203
painter.drawText(QRectF(stretchBase, top, stretchBase, lineHeight),
195-
valueToString(time, UNIT_SECONDS, 4), QTextOption(Qt::AlignRight));
204+
valueToString( time1, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight));
196205
painter.drawText(QRectF(stretchBase * 2, top, stretchBase, lineHeight),
197-
valueToString(1.0 / time, UNIT_HERTZ, 4), QTextOption(Qt::AlignRight));
198-
206+
valueToString( time2, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight));
199207
painter.drawText(QRectF(stretchBase * 3, top, stretchBase, lineHeight),
200-
valueToString(time / DIVS_TIME, UNIT_SECONDS, 3) + tr("/div"),
201-
QTextOption(Qt::AlignRight));
208+
valueToString( time, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight));
202209
painter.drawText(QRectF(stretchBase * 4, top, stretchBase, lineHeight),
203-
valueToString(divs * settings->scope.horizontal.frequencybase / DIVS_TIME, UNIT_HERTZ, 3) +
210+
valueToString( freq1, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight));
211+
painter.drawText(QRectF(stretchBase * 5, top, stretchBase, lineHeight),
212+
valueToString( freq2, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight));
213+
painter.drawText(QRectF(stretchBase * 6, top, stretchBase, lineHeight),
214+
valueToString( freq, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight));
215+
216+
painter.drawText(QRectF(stretchBase * 7, top, stretchBase, lineHeight),
217+
valueToString( time / DIVS_TIME, UNIT_SECONDS, 3 ) + tr("/div"),
218+
QTextOption(Qt::AlignRight));
219+
painter.drawText(QRectF(stretchBase * 8, top, stretchBase, lineHeight),
220+
valueToString( freq / DIVS_TIME, UNIT_HERTZ, 3 ) +
204221
tr("/div"),
205222
QTextOption(Qt::AlignRight));
206223
} else {
224+
stretchBase = (double)paintDevice->width() / 7;
207225
scopeHeight = (double)paintDevice->height() - (channelCount + 4) * lineHeight;
208226
double top = 2.5 * lineHeight + scopeHeight;
209227

210228
painter.drawText(QRectF(0, top, stretchBase, lineHeight), tr("Marker 1/2"));
211-
212-
painter.drawText(QRectF(stretchBase * 0, top, stretchBase, lineHeight),
213-
valueToString(time, UNIT_SECONDS, 4), QTextOption(Qt::AlignRight));
214-
painter.drawText(QRectF(stretchBase * 1, top, stretchBase, lineHeight),
215-
valueToString(1.0 / time, UNIT_HERTZ, 4), QTextOption(Qt::AlignRight));
229+
painter.drawText(QRectF(stretchBase, top, stretchBase, lineHeight),
230+
"t1: " + valueToString( time1, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight));
231+
painter.drawText(QRectF(stretchBase * 2, top, stretchBase, lineHeight),
232+
"t2: " + valueToString( time2, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight));
233+
painter.drawText(QRectF(stretchBase * 3, top, stretchBase, lineHeight),
234+
"Δt: " + valueToString( time, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight));
235+
painter.drawText(QRectF(stretchBase * 4, top, stretchBase, lineHeight),
236+
"f1: " + valueToString( freq1, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight));
237+
painter.drawText(QRectF(stretchBase * 5, top, stretchBase, lineHeight),
238+
"f2: " + valueToString( freq2, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight));
239+
painter.drawText(QRectF(stretchBase * 6, top, stretchBase, lineHeight),
240+
"Δf: " + valueToString( freq, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight));
216241
}
217242

218243
// Set DIVS_TIME x DIVS_VOLTAGE matrix for oscillograph

0 commit comments

Comments
 (0)