We do this by choosing the prefix (kV, V, mV) based on the min/max value
of the signal, not the value at the cursor position.
That way, we won't have the situation where values are printed as e.g.
"400 mV" when the values are usually shown as "1.600 V".
return stream << QString::fromStdString(str);
}
return stream << QString::fromStdString(str);
}
-QString format_time_si(const Timestamp& v, SIPrefix prefix,
- unsigned int precision, QString unit, bool sign)
+SIPrefix determine_value_prefix(double v)
- if (prefix == SIPrefix::unspecified) {
- // No prefix given, calculate it
-
- if (v.is_zero()) {
- prefix = SIPrefix::none;
- } else {
- int exp = exponent(SIPrefix::yotta);
- prefix = SIPrefix::yocto;
- while ((fabs(v) * pow(Timestamp(10), exp)) > 999 &&
- prefix < SIPrefix::yotta) {
- prefix = successor(prefix);
- exp -= 3;
- }
+ SIPrefix prefix;
+
+ if (v == 0) {
+ prefix = SIPrefix::none;
+ } else {
+ int exp = exponent(SIPrefix::yotta);
+ prefix = SIPrefix::yocto;
+ while ((fabs(v) * pow(10, exp)) > 999 &&
+ prefix < SIPrefix::yotta) {
+ prefix = successor(prefix);
+ exp -= 3;
+ return prefix;
+}
+
+QString format_time_si(const Timestamp& v, SIPrefix prefix,
+ unsigned int precision, QString unit, bool sign)
+{
+ if (prefix == SIPrefix::unspecified)
+ prefix = determine_value_prefix(v.convert_to<double>());
+
assert(prefix >= SIPrefix::yocto);
assert(prefix <= SIPrefix::yotta);
assert(prefix >= SIPrefix::yocto);
assert(prefix <= SIPrefix::yotta);
QString unit, bool sign)
{
if (prefix == SIPrefix::unspecified) {
QString unit, bool sign)
{
if (prefix == SIPrefix::unspecified) {
- // No prefix given, calculate it
-
- if (v == 0) {
- prefix = SIPrefix::none;
- } else {
- int exp = exponent(SIPrefix::yotta);
- prefix = SIPrefix::yocto;
- while ((fabs(v) * pow(Timestamp(10), exp)) > 999 &&
- prefix < SIPrefix::yotta) {
- prefix = successor(prefix);
- exp -= 3;
- }
- }
+ prefix = determine_value_prefix(v);
const int prefix_order = -exponent(prefix);
precision = (prefix >= SIPrefix::none) ? max((int)(precision + prefix_order), 0) :
const int prefix_order = -exponent(prefix);
precision = (prefix >= SIPrefix::none) ? max((int)(precision + prefix_order), 0) :
boost::multiprecision::cpp_dec_float<24>,
boost::multiprecision::et_off> Timestamp;
boost::multiprecision::cpp_dec_float<24>,
boost::multiprecision::et_off> Timestamp;
+/**
+ * Chooses a prefix so that the value in front of the decimal point is between 1 and 999.
+ */
+SIPrefix determine_value_prefix(double v);
+
/**
* Formats a given timestamp with the specified SI prefix.
*
/**
* Formats a given timestamp with the specified SI prefix.
*
using pv::data::LogicSegment;
using pv::data::SignalBase;
using pv::util::SIPrefix;
using pv::data::LogicSegment;
using pv::data::SignalBase;
using pv::util::SIPrefix;
+using pv::util::determine_value_prefix;
namespace pv {
namespace views {
namespace pv {
namespace views {
+ SIPrefix prefix;
+ if (fabs(signal_max_) > fabs(signal_min_))
+ prefix = determine_value_prefix(fabs(signal_max_));
+ else
+ prefix = determine_value_prefix(fabs(signal_min_));
+
// Show the info section on the right side of the trace, including
// the value at the hover point when the hover marker is enabled
// and we have corresponding data available
if (show_hover_marker_ && !std::isnan(value_at_hover_pos_)) {
infotext = QString("[%1] %2 V/div")
// Show the info section on the right side of the trace, including
// the value at the hover point when the hover marker is enabled
// and we have corresponding data available
if (show_hover_marker_ && !std::isnan(value_at_hover_pos_)) {
infotext = QString("[%1] %2 V/div")
- .arg(format_value_si(value_at_hover_pos_, SIPrefix::unspecified, 2, "V", false))
+ .arg(format_value_si(value_at_hover_pos_, prefix, 3, "V", false))
.arg(resolution_);
} else
infotext = QString("%1 V/div").arg(resolution_);
.arg(resolution_);
} else
infotext = QString("%1 V/div").arg(resolution_);
if (segments.empty())
return;
if (segments.empty())
return;
- double signal_min_ = 0, signal_max_ = 0;
double min = 0, max = 0;
for (const shared_ptr<pv::data::AnalogSegment>& segment : segments) {
double min = 0, max = 0;
for (const shared_ptr<pv::data::AnalogSegment>& segment : segments) {
void AnalogSignal::on_min_max_changed(float min, float max)
{
void AnalogSignal::on_min_max_changed(float min, float max)
{
- (void)min;
- (void)max;
-
if (autoranging_)
perform_autoranging(false, false);
if (autoranging_)
perform_autoranging(false, false);
+ else {
+ if (min < signal_min_) signal_min_ = min;
+ if (max > signal_max_) signal_max_ = max;
+ }
}
void AnalogSignal::on_pos_vdivs_changed(int vdivs)
}
void AnalogSignal::on_pos_vdivs_changed(int vdivs)
int current_pixel_pos_; // Only used during lookup table update
// ---------------------------------------------------------------------------
int current_pixel_pos_; // Only used during lookup table update
// ---------------------------------------------------------------------------
- // Note: Make sure to update .. when adding a trace-configurable variable here
+ // Note: Make sure to update save_settings() and restore_settings() when
+ // adding a trace-configurable variable here
float scale_;
int scale_index_;
float scale_;
int scale_index_;
void on_signal_height_changed(int height);
private:
void on_signal_height_changed(int height);
private:
QColor high_fill_color_;
bool show_sampling_points_, fill_high_areas_;
QColor high_fill_color_;
bool show_sampling_points_, fill_high_areas_;
static QCache<QString, const QIcon> icon_cache_;
static QCache<QString, const QPixmap> pixmap_cache_;
static QCache<QString, const QIcon> icon_cache_;
static QCache<QString, const QPixmap> pixmap_cache_;
+
+ // ---------------------------------------------------------------------------
+ // Note: Make sure to update save_settings() and restore_settings() when
+ // adding a trace-configurable variable here
+ int signal_height_;