]> sigrok.org Git - pulseview.git/blobdiff - pv/view/decodetrace.cpp
DecodeTrace: Replace magic number by proper calculation
[pulseview.git] / pv / view / decodetrace.cpp
index 6bafa11e8c3a8d3ad2075fa0e7107fe51e073fdb..ab9514cd4e4da34e706c522ecb4244a123a38ad9 100644 (file)
@@ -44,6 +44,7 @@ extern "C" {
 #include "decodetrace.hpp"
 
 #include <pv/session.hpp>
+#include <pv/strnatcmp.hpp>
 #include <pv/data/decoderstack.hpp>
 #include <pv/data/decode/decoder.hpp>
 #include <pv/data/logic.hpp>
@@ -140,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()),
@@ -372,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
@@ -835,7 +840,8 @@ QComboBox* DecodeTrace::create_channel_selector(
        vector< shared_ptr<Signal> > sig_list(sigs.begin(), sigs.end());
        std::sort(sig_list.begin(), sig_list.end(),
                [](const shared_ptr<Signal> &a, const shared_ptr<Signal> b) {
-                       return a->name().compare(b->name()) < 0; });
+                       return strnatcasecmp(a->name().toStdString(),
+                               b->name().toStdString()) < 0; });
 
        assert(decoder_stack_);
        const auto channel_iter = dec->channels().find(pdch);