0001-Replace-obsolete-deprecated-Qt-methods.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. From caacc9bc622238ca48674ea6f40d07466e4b97a5 Mon Sep 17 00:00:00 2001
  2. From: Valentin Ochs <a@0au.de>
  3. Date: Sat, 20 Jun 2020 16:01:27 +0200
  4. Subject: [PATCH] Replace obsolete/deprecated Qt methods
  5. [Thomas: Backport from upstream commit
  6. ae726b70a7ada9a4be5808e00f0c951318479684, one conflict manually
  7. resolved in pv/util.cpp.]
  8. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  9. [Fabrice: restore original patch in pv/util.cpp for 0.4.2]
  10. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  11. ---
  12. pv/util.cpp | 21 +++++++++++++++++++--
  13. pv/util.hpp | 10 ++++++++++
  14. pv/views/trace/decodetrace.cpp | 3 ++-
  15. pv/views/trace/ruler.cpp | 2 +-
  16. pv/widgets/timestampspinbox.cpp | 2 +-
  17. 5 files changed, 33 insertions(+), 5 deletions(-)
  18. diff --git a/pv/util.cpp b/pv/util.cpp
  19. index 49b9467c..2a63038d 100644
  20. --- a/pv/util.cpp
  21. +++ b/pv/util.cpp
  22. @@ -137,7 +137,7 @@ QString format_time_si(const Timestamp& v, SIPrefix prefix,
  23. QString s;
  24. QTextStream ts(&s);
  25. if (sign && !v.is_zero())
  26. - ts << forcesign;
  27. + ts.setNumberFlags(ts.numberFlags() | QTextStream::ForceSign);
  28. ts << qSetRealNumberPrecision(precision) << (v * multiplier);
  29. ts << ' ' << prefix << unit;
  30. @@ -171,7 +171,7 @@ QString format_value_si(double v, SIPrefix prefix, unsigned precision,
  31. QString s;
  32. QTextStream ts(&s);
  33. if (sign && (v != 0))
  34. - ts << forcesign;
  35. + ts.setNumberFlags(ts.numberFlags() | QTextStream::ForceSign);
  36. ts.setRealNumberNotation(QTextStream::FixedNotation);
  37. ts.setRealNumberPrecision(precision);
  38. ts << (v * multiplier) << ' ' << prefix << unit;
  39. @@ -281,5 +281,22 @@ vector<string> split_string(string text, string separator)
  40. return result;
  41. }
  42. +/**
  43. + * Return the width of a string in a given font.
  44. + *
  45. + * @param[in] metric metrics of the font
  46. + * @param[in] string the string whose width should be determined
  47. + *
  48. + * @return width of the string in pixels
  49. + */
  50. +std::streamsize text_width(const QFontMetrics &metric, const QString &string)
  51. +{
  52. +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
  53. + return metric.horizontalAdvance(string);
  54. +#else
  55. + return metric.width(string);
  56. +#endif
  57. +}
  58. +
  59. } // namespace util
  60. } // namespace pv
  61. diff --git a/pv/util.hpp b/pv/util.hpp
  62. index dd7be222..ad904f85 100644
  63. --- a/pv/util.hpp
  64. +++ b/pv/util.hpp
  65. @@ -30,6 +30,7 @@
  66. #include <QMetaType>
  67. #include <QString>
  68. +#include <QFontMetrics>
  69. using std::string;
  70. using std::vector;
  71. @@ -137,6 +138,15 @@ QString format_time_minutes(const Timestamp& t, signed precision = 0,
  72. vector<string> split_string(string text, string separator);
  73. +/**
  74. + * Return the width of a string in a given font.
  75. + * @param[in] metric metrics of the font
  76. + * @param[in] string the string whose width should be determined
  77. + *
  78. + * @return width of the string in pixels
  79. + */
  80. +std::streamsize text_width(const QFontMetrics &metric, const QString &string);
  81. +
  82. } // namespace util
  83. } // namespace pv
  84. diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp
  85. index 9c7196bf..1ee7ae9f 100644
  86. --- a/pv/views/trace/decodetrace.cpp
  87. +++ b/pv/views/trace/decodetrace.cpp
  88. @@ -103,7 +103,8 @@ DecodeTrace::DecodeTrace(pv::Session &session,
  89. // Determine shortest string we want to see displayed in full
  90. QFontMetrics m(QApplication::font());
  91. - min_useful_label_width_ = m.width("XX"); // e.g. two hex characters
  92. + // e.g. two hex characters
  93. + min_useful_label_width_ = util::text_width(m, "XX");
  94. // For the base color, we want to start at a very different color for
  95. // every decoder stack, so multiply the index with a number that is
  96. diff --git a/pv/views/trace/ruler.cpp b/pv/views/trace/ruler.cpp
  97. index acea8a36..68134966 100644
  98. --- a/pv/views/trace/ruler.cpp
  99. +++ b/pv/views/trace/ruler.cpp
  100. @@ -218,7 +218,7 @@ void Ruler::paintEvent(QPaintEvent*)
  101. const int rightedge = width();
  102. const int x_tick = tick.first;
  103. if ((x_tick > leftedge) && (x_tick < rightedge)) {
  104. - const int x_left_bound = QFontMetrics(font()).width(tick.second) / 2;
  105. + const int x_left_bound = util::text_width(QFontMetrics(font()), tick.second) / 2;
  106. const int x_right_bound = rightedge - x_left_bound;
  107. const int x_legend = min(max(x_tick, x_left_bound), x_right_bound);
  108. p.drawText(x_legend, ValueMargin, 0, text_height,
  109. diff --git a/pv/widgets/timestampspinbox.cpp b/pv/widgets/timestampspinbox.cpp
  110. index 21b3d0d7..383aed1f 100644
  111. --- a/pv/widgets/timestampspinbox.cpp
  112. +++ b/pv/widgets/timestampspinbox.cpp
  113. @@ -75,7 +75,7 @@ QSize TimestampSpinBox::minimumSizeHint() const
  114. {
  115. const QFontMetrics fm(fontMetrics());
  116. const int l = round(value_).str().size() + precision_ + 10;
  117. - const int w = fm.width(QString(l, '0'));
  118. + const int w = util::text_width(fm, QString(l, '0'));
  119. const int h = lineEdit()->minimumSizeHint().height();
  120. return QSize(w, h);
  121. }
  122. --
  123. 2.26.2