gnu: Add kafs-client
[jackhill/guix/guix.git] / gnu / packages / patches / pulseview-qt515-compat.patch
CommitLineData
d0fff8f8
EF
1https://sigrok.org/gitweb/?p=pulseview.git;a=patch;h=ae726b70a7ada9a4be5808e00f0c951318479684
2
3From ae726b70a7ada9a4be5808e00f0c951318479684 Mon Sep 17 00:00:00 2001
4From: Valentin Ochs <a@0au.de>
5Date: Sat, 20 Jun 2020 16:01:27 +0200
6Subject: [PATCH] Replace obsolete/deprecated Qt methods
7
8---
9 pv/subwindows/decoder_selector/subwindow.cpp | 2 +-
10 pv/util.cpp | 21 ++++++++++++++++++--
11 pv/util.hpp | 10 ++++++++++
12 pv/views/trace/decodetrace.cpp | 3 ++-
13 pv/views/trace/ruler.cpp | 2 +-
14 pv/widgets/timestampspinbox.cpp | 2 +-
15 6 files changed, 34 insertions(+), 6 deletions(-)
16
17diff --git a/pv/subwindows/decoder_selector/subwindow.cpp b/pv/subwindows/decoder_selector/subwindow.cpp
18index 94ed6f4b..2c65dcf2 100644
19--- a/pv/subwindows/decoder_selector/subwindow.cpp
20+++ b/pv/subwindows/decoder_selector/subwindow.cpp
21@@ -185,7 +185,7 @@ QToolBar* SubWindow::create_toolbar(QWidget *parent) const
22 int SubWindow::minimum_width() const
23 {
24 QFontMetrics m(info_label_body_->font());
25- const int label_width = m.width(QString(tr(initial_notice)));
26+ const int label_width = util::text_width(m, tr(initial_notice));
27
28 return label_width + min_width_margin;
29 }
30diff --git a/pv/util.cpp b/pv/util.cpp
31index 897254e1..dfb8c72b 100644
32--- a/pv/util.cpp
33+++ b/pv/util.cpp
34@@ -143,7 +143,7 @@ QString format_time_si(const Timestamp& v, SIPrefix prefix,
35 QString s;
36 QTextStream ts(&s);
37 if (sign && !v.is_zero())
38- ts << forcesign;
39+ ts.setNumberFlags(ts.numberFlags() | QTextStream::ForceSign);
40 ts << qSetRealNumberPrecision(precision) << (v * multiplier);
41 ts << ' ' << prefix << unit;
42
43@@ -169,7 +169,7 @@ QString format_value_si(double v, SIPrefix prefix, unsigned precision,
44 QString s;
45 QTextStream ts(&s);
46 if (sign && (v != 0))
47- ts << forcesign;
48+ ts.setNumberFlags(ts.numberFlags() | QTextStream::ForceSign);
49 ts.setRealNumberNotation(QTextStream::FixedNotation);
50 ts.setRealNumberPrecision(precision);
51 ts << (v * multiplier) << ' ' << prefix << unit;
52@@ -279,5 +279,22 @@ vector<string> split_string(string text, string separator)
53 return result;
54 }
55
56+/**
57+ * Return the width of a string in a given font.
58+ *
59+ * @param[in] metric metrics of the font
60+ * @param[in] string the string whose width should be determined
61+ *
62+ * @return width of the string in pixels
63+ */
64+std::streamsize text_width(const QFontMetrics &metric, const QString &string)
65+{
66+#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
67+ return metric.horizontalAdvance(string);
68+#else
69+ return metric.width(string);
70+#endif
71+}
72+
73 } // namespace util
74 } // namespace pv
75diff --git a/pv/util.hpp b/pv/util.hpp
76index fab29a14..49ae04b2 100644
77--- a/pv/util.hpp
78+++ b/pv/util.hpp
79@@ -30,6 +30,7 @@
80
81 #include <QMetaType>
82 #include <QString>
83+#include <QFontMetrics>
84
85 using std::string;
86 using std::vector;
87@@ -143,6 +144,15 @@ QString format_time_minutes(const Timestamp& t, signed precision = 0,
88
89 vector<string> split_string(string text, string separator);
90
91+/**
92+ * Return the width of a string in a given font.
93+ * @param[in] metric metrics of the font
94+ * @param[in] string the string whose width should be determined
95+ *
96+ * @return width of the string in pixels
97+ */
98+std::streamsize text_width(const QFontMetrics &metric, const QString &string);
99+
100 } // namespace util
101 } // namespace pv
102
103diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp
104index 67c9b1c4..93c7c5a9 100644
105--- a/pv/views/trace/decodetrace.cpp
106+++ b/pv/views/trace/decodetrace.cpp
107@@ -161,7 +161,8 @@ DecodeTrace::DecodeTrace(pv::Session &session,
108
109 // Determine shortest string we want to see displayed in full
110 QFontMetrics m(QApplication::font());
111- min_useful_label_width_ = m.width("XX"); // e.g. two hex characters
112+ // e.g. two hex characters
113+ min_useful_label_width_ = util::text_width(m, "XX");
114
115 default_row_height_ = (ViewItemPaintParams::text_height() * 6) / 4;
116 annotation_height_ = (ViewItemPaintParams::text_height() * 5) / 4;
117diff --git a/pv/views/trace/ruler.cpp b/pv/views/trace/ruler.cpp
118index 555794fc..83ffed28 100644
119--- a/pv/views/trace/ruler.cpp
120+++ b/pv/views/trace/ruler.cpp
121@@ -283,7 +283,7 @@ void Ruler::paintEvent(QPaintEvent*)
122 const int rightedge = width();
123 const int x_tick = tick.first;
124 if ((x_tick > leftedge) && (x_tick < rightedge)) {
125- const int x_left_bound = QFontMetrics(font()).width(tick.second) / 2;
126+ const int x_left_bound = util::text_width(QFontMetrics(font()), tick.second) / 2;
127 const int x_right_bound = rightedge - x_left_bound;
128 const int x_legend = min(max(x_tick, x_left_bound), x_right_bound);
129 p.drawText(x_legend, ValueMargin, 0, text_height,
130diff --git a/pv/widgets/timestampspinbox.cpp b/pv/widgets/timestampspinbox.cpp
131index fea8175e..01424a5b 100644
132--- a/pv/widgets/timestampspinbox.cpp
133+++ b/pv/widgets/timestampspinbox.cpp
134@@ -76,7 +76,7 @@ QSize TimestampSpinBox::minimumSizeHint() const
135 {
136 const QFontMetrics fm(fontMetrics());
137 const int l = round(value_).str().size() + precision_ + 10;
138- const int w = fm.width(QString(l, '0'));
139+ const int w = util::text_width(fm, QString(l, '0'));
140 const int h = lineEdit()->minimumSizeHint().height();
141 return QSize(w, h);
142 }
143--
1442.24.0.rc2
145