]> sigrok.org Git - pulseview.git/commitdiff
DecodeTrace: Replace magic number by proper calculation
authorSoeren Apel <redacted>
Fri, 8 Apr 2016 16:25:58 +0000 (18:25 +0200)
committerSoeren Apel <redacted>
Fri, 8 Apr 2016 21:34:45 +0000 (23:34 +0200)
pv/view/decodetrace.cpp
pv/view/decodetrace.hpp

index 19decfd4928420f484cf213c8329f0899dd068cd..ab9514cd4e4da34e706c522ecb4244a123a38ad9 100644 (file)
@@ -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<pv::data::decode::Annotation> 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
index b5da2dc2400082f8842167fffe398636e4e3331e..2705d3cf4a90c2fd3ca8b522900cb5bbc555ca81 100644 (file)
@@ -210,6 +210,8 @@ private:
        std::map<data::decode::Row, int> row_title_widths_;
        int row_height_, max_visible_rows_;
 
+       int min_useful_label_width_;
+
        QSignalMapper delete_mapper_, show_hide_mapper_;
 };