]> sigrok.org Git - pulseview.git/commitdiff
Replace obsolete/deprecated Qt methods
authorValentin Ochs <redacted>
Sat, 20 Jun 2020 14:01:27 +0000 (16:01 +0200)
committerSoeren Apel <redacted>
Thu, 25 Jun 2020 19:05:34 +0000 (21:05 +0200)
pv/subwindows/decoder_selector/subwindow.cpp
pv/util.cpp
pv/util.hpp
pv/views/trace/decodetrace.cpp
pv/views/trace/ruler.cpp
pv/widgets/timestampspinbox.cpp

index 94ed6f4b6da970e02a3191ba2a87dc7d951bd054..2c65dcf2e4f3f928ac38216a4303fd7fe543b8be 100644 (file)
@@ -185,7 +185,7 @@ QToolBar* SubWindow::create_toolbar(QWidget *parent) const
 int SubWindow::minimum_width() const
 {
        QFontMetrics m(info_label_body_->font());
 int SubWindow::minimum_width() const
 {
        QFontMetrics m(info_label_body_->font());
-       const int label_width = m.width(QString(tr(initial_notice)));
+       const int label_width = util::text_width(m, tr(initial_notice));
 
        return label_width + min_width_margin;
 }
 
        return label_width + min_width_margin;
 }
index 897254e12160fa59e60c7766efbd5e84f1d5fff5..dfb8c72b43504a95ad1f107c66a16e289858ba82 100644 (file)
@@ -143,7 +143,7 @@ QString format_time_si(const Timestamp& v, SIPrefix prefix,
        QString s;
        QTextStream ts(&s);
        if (sign && !v.is_zero())
        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;
 
        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))
        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;
        ts.setRealNumberNotation(QTextStream::FixedNotation);
        ts.setRealNumberPrecision(precision);
        ts << (v * multiplier) << ' ' << prefix << unit;
@@ -279,5 +279,22 @@ vector<string> split_string(string text, string separator)
        return result;
 }
 
        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
 } // namespace util
 } // namespace pv
index fab29a14f05ac21ea90b88d37088c2f9274a278f..49ae04b2dbc024814e61e88428dc896e8949e0b2 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <QMetaType>
 #include <QString>
 
 #include <QMetaType>
 #include <QString>
+#include <QFontMetrics>
 
 using std::string;
 using std::vector;
 
 using std::string;
 using std::vector;
@@ -143,6 +144,15 @@ QString format_time_minutes(const Timestamp& t, signed precision = 0,
 
 vector<string> split_string(string text, string separator);
 
 
 vector<string> split_string(string text, string separator);
 
+/**
+ * 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);
+
 } // namespace util
 } // namespace pv
 
 } // namespace util
 } // namespace pv
 
index 67c9b1c48409e4e2a2525f6592ee3d47d963afde..93c7c5a93cdd3bae6af7db425b612e12618ab200 100644 (file)
@@ -161,7 +161,8 @@ DecodeTrace::DecodeTrace(pv::Session &session,
 
        // Determine shortest string we want to see displayed in full
        QFontMetrics m(QApplication::font());
 
        // Determine shortest string we want to see displayed in full
        QFontMetrics m(QApplication::font());
-       min_useful_label_width_ = m.width("XX"); // e.g. two hex characters
+       // e.g. two hex characters
+       min_useful_label_width_ = util::text_width(m, "XX");
 
        default_row_height_ = (ViewItemPaintParams::text_height() * 6) / 4;
        annotation_height_ = (ViewItemPaintParams::text_height() * 5) / 4;
 
        default_row_height_ = (ViewItemPaintParams::text_height() * 6) / 4;
        annotation_height_ = (ViewItemPaintParams::text_height() * 5) / 4;
index 555794fc42c6e881c5691fc1d64c43a0355e7cd3..83ffed281b5f6768085d1a03ee77f2840a443487 100644 (file)
@@ -283,7 +283,7 @@ void Ruler::paintEvent(QPaintEvent*)
                const int rightedge = width();
                const int x_tick = tick.first;
                if ((x_tick > leftedge) && (x_tick < rightedge)) {
                const int rightedge = width();
                const int x_tick = tick.first;
                if ((x_tick > leftedge) && (x_tick < rightedge)) {
-                       const int x_left_bound = QFontMetrics(font()).width(tick.second) / 2;
+                       const int x_left_bound = util::text_width(QFontMetrics(font()), tick.second) / 2;
                        const int x_right_bound = rightedge - x_left_bound;
                        const int x_legend = min(max(x_tick, x_left_bound), x_right_bound);
                        p.drawText(x_legend, ValueMargin, 0, text_height,
                        const int x_right_bound = rightedge - x_left_bound;
                        const int x_legend = min(max(x_tick, x_left_bound), x_right_bound);
                        p.drawText(x_legend, ValueMargin, 0, text_height,
index fea8175e8e00b74b21f6690cf9d726e3a9cd418c..01424a5b7837654e50c36de5f3f4ce27c33ec8a1 100644 (file)
@@ -76,7 +76,7 @@ QSize TimestampSpinBox::minimumSizeHint() const
 {
        const QFontMetrics fm(fontMetrics());
        const int l = round(value_).str().size() + precision_ + 10;
 {
        const QFontMetrics fm(fontMetrics());
        const int l = round(value_).str().size() + precision_ + 10;
-       const int w = fm.width(QString(l, '0'));
+       const int w = util::text_width(fm, QString(l, '0'));
        const int h = lineEdit()->minimumSizeHint().height();
        return QSize(w, h);
 }
        const int h = lineEdit()->minimumSizeHint().height();
        return QSize(w, h);
 }