X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Futil.cpp;fp=pv%2Futil.cpp;h=dfb8c72b43504a95ad1f107c66a16e289858ba82;hp=897254e12160fa59e60c7766efbd5e84f1d5fff5;hb=ae726b70a7ada9a4be5808e00f0c951318479684;hpb=f14dee773586e9f6afbeac8b7f552fb378f36d9b diff --git a/pv/util.cpp b/pv/util.cpp index 897254e1..dfb8c72b 100644 --- a/pv/util.cpp +++ b/pv/util.cpp @@ -143,7 +143,7 @@ QString format_time_si(const Timestamp& v, SIPrefix prefix, QString s; QTextStream ts(&s); if (sign && !v.is_zero()) - ts << forcesign; + ts.setNumberFlags(ts.numberFlags() | QTextStream::ForceSign); ts << qSetRealNumberPrecision(precision) << (v * multiplier); ts << ' ' << prefix << unit; @@ -169,7 +169,7 @@ QString format_value_si(double v, SIPrefix prefix, unsigned precision, QString s; QTextStream ts(&s); if (sign && (v != 0)) - ts << forcesign; + ts.setNumberFlags(ts.numberFlags() | QTextStream::ForceSign); ts.setRealNumberNotation(QTextStream::FixedNotation); ts.setRealNumberPrecision(precision); ts << (v * multiplier) << ' ' << prefix << unit; @@ -279,5 +279,22 @@ vector split_string(string text, string separator) return result; } +/** + * Return the width of a string in a given font. + * + * @param[in] metric metrics of the font + * @param[in] string the string whose width should be determined + * + * @return width of the string in pixels + */ +std::streamsize text_width(const QFontMetrics &metric, const QString &string) +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) + return metric.horizontalAdvance(string); +#else + return metric.width(string); +#endif +} + } // namespace util } // namespace pv