From: Soeren Apel Date: Tue, 17 Oct 2023 22:11:53 +0000 (+0200) Subject: Flags: Always save raw text, not display text in session setup X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=ef6cbaa21144ff25a74d5940bbe1c11ab2717e42 Flags: Always save raw text, not display text in session setup Before, get_text() would return the delta time to a selected flag, so if one was selected as the session was saved, this delta time would be saved as the name. --- diff --git a/pv/views/trace/cursor.cpp b/pv/views/trace/cursor.cpp index 80eaba23..8462a3a6 100644 --- a/pv/views/trace/cursor.cpp +++ b/pv/views/trace/cursor.cpp @@ -72,7 +72,7 @@ QRectF Cursor::label_rect(const QRectF &rect) const const float x = get_x(); QFontMetrics m(QApplication::font()); - QSize text_size = m.boundingRect(get_text()).size(); + QSize text_size = m.boundingRect(get_display_text()).size(); const QSizeF label_size( text_size.width() + LabelPadding.width() * 2, diff --git a/pv/views/trace/flag.cpp b/pv/views/trace/flag.cpp index b0518b64..c356b15b 100644 --- a/pv/views/trace/flag.cpp +++ b/pv/views/trace/flag.cpp @@ -57,7 +57,11 @@ bool Flag::enabled() const return true; } -QString Flag::get_text() const +/** + * Returns the text used to display this flag item. This is not necessarily the + * name that the user has given it. + */ +QString Flag::get_display_text() const { QString s; @@ -73,6 +77,14 @@ QString Flag::get_text() const return s; } +/** + * Returns the text of this flag item, i.e. the user-editable name. + */ +QString Flag::get_text() const +{ + return text_; +} + void Flag::set_text(const QString &text) { text_ = text; @@ -92,7 +104,7 @@ QRectF Flag::label_rect(const QRectF &rect) const const float x = get_x(); QFontMetrics m(QApplication::font()); - QSize text_size = m.boundingRect(get_text()).size(); + QSize text_size = m.boundingRect(get_display_text()).size(); const QSizeF label_size( text_size.width() + LabelPadding.width() * 2, diff --git a/pv/views/trace/flag.hpp b/pv/views/trace/flag.hpp index 4c4c977f..eb4bf87c 100644 --- a/pv/views/trace/flag.hpp +++ b/pv/views/trace/flag.hpp @@ -63,7 +63,13 @@ public: virtual bool enabled() const override; /** - * Gets the text to show in the marker. + * Gets the current text to show in the marker - this may be dynamic. + */ + virtual QString get_display_text() const override; + + /** + * Gets the default text used to show the marker - e.g. the user-editable + * name. */ virtual QString get_text() const override; diff --git a/pv/views/trace/timemarker.cpp b/pv/views/trace/timemarker.cpp index b428f602..af1d55d6 100644 --- a/pv/views/trace/timemarker.cpp +++ b/pv/views/trace/timemarker.cpp @@ -88,7 +88,7 @@ QRectF TimeMarker::label_rect(const QRectF &rect) const { QFontMetrics m(QApplication::font()); const QSizeF text_size( - max(m.boundingRect(get_text()).size().width(), ArrowSize), + max(m.boundingRect(get_display_text()).size().width(), ArrowSize), m.height()); const QSizeF label_size(text_size + LabelPadding * 2); const float top = rect.height() - label_size.height() - @@ -105,6 +105,11 @@ QRectF TimeMarker::hit_box_rect(const ViewItemPaintParams &pp) const return QRectF(x - h / 2.0f, pp.top(), h, pp.height()); } +QString TimeMarker::get_display_text() const +{ + return get_text(); +} + void TimeMarker::set_text(const QString &text) { (void)text; @@ -158,7 +163,7 @@ void TimeMarker::paint_label(QPainter &p, const QRect &rect, bool hover) p.drawPolygon(points, countof(points)); p.setPen(select_text_color(color_)); - p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter, get_text()); + p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter, get_display_text()); } void TimeMarker::paint_fore(QPainter &p, ViewItemPaintParams &pp) diff --git a/pv/views/trace/timemarker.hpp b/pv/views/trace/timemarker.hpp index 040a29ea..00998462 100644 --- a/pv/views/trace/timemarker.hpp +++ b/pv/views/trace/timemarker.hpp @@ -95,7 +95,13 @@ public: QRectF hit_box_rect(const ViewItemPaintParams &pp) const override; /** - * Gets the text to show in the marker. + * Gets the current text to show in the marker - this may be dynamic. + */ + virtual QString get_display_text() const; + + /** + * Gets the default text used to show the marker - e.g. the user-editable + * name. */ virtual QString get_text() const = 0;