From: Soeren Apel Date: Fri, 8 Apr 2016 16:25:58 +0000 (+0200) Subject: DecodeTrace: Replace magic number by proper calculation X-Git-Tag: pulseview-0.4.0~312 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=752281db3591fe0eeb2590379b2055b8e05cd14f;ds=sidebyside DecodeTrace: Replace magic number by proper calculation --- diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 19decfd4..ab9514cd 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -141,6 +141,10 @@ DecodeTrace::DecodeTrace(pv::Session &session, { assert(decoder_stack_); + // 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 + set_colour(DecodeColours[index % countof(DecodeColours)]); connect(decoder_stack_.get(), SIGNAL(new_decode_data()), @@ -373,7 +377,7 @@ void DecodeTrace::draw_annotations(vector annotati bool a_is_separate = false; // Annotation wider than the threshold for a useful label width? - if (a_width > 20) { + if (a_width >= min_useful_label_width_) { for (const QString &ann_text : a.annotations()) { const int w = p.boundingRect(QRectF(), 0, ann_text).width(); // Annotation wide enough to fit a label? Don't put it in a block then diff --git a/pv/view/decodetrace.hpp b/pv/view/decodetrace.hpp index b5da2dc2..2705d3cf 100644 --- a/pv/view/decodetrace.hpp +++ b/pv/view/decodetrace.hpp @@ -210,6 +210,8 @@ private: std::map row_title_widths_; int row_height_, max_visible_rows_; + int min_useful_label_width_; + QSignalMapper delete_mapper_, show_hide_mapper_; };