X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fdecodetrace.cpp;h=2d9a6bf82227a3b50f59c3fa746a216fcc5e3ef5;hp=6bafa11e8c3a8d3ad2075fa0e7107fe51e073fdb;hb=cbd2a2de848f957507096785d3be1cc97d30df9a;hpb=4fb5fb99ba0453af3080e82e4f3e2f295a55616b diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 6bafa11e..2d9a6bf8 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -44,6 +44,7 @@ extern "C" { #include "decodetrace.hpp" #include +#include #include #include #include @@ -128,10 +129,11 @@ const QColor DecodeTrace::OutlineColours[16] = { }; DecodeTrace::DecodeTrace(pv::Session &session, + shared_ptr signalbase, std::shared_ptr decoder_stack, int index) : - Trace(QString::fromUtf8( - decoder_stack->stack().front()->decoder()->name)), + Trace(signalbase), session_(session), + signalbase_(signalbase), decoder_stack_(decoder_stack), row_height_(0), max_visible_rows_(0), @@ -140,7 +142,12 @@ DecodeTrace::DecodeTrace(pv::Session &session, { assert(decoder_stack_); - set_colour(DecodeColours[index % countof(DecodeColours)]); + // 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 + + signalbase_->set_name(QString::fromUtf8(decoder_stack->stack().front()->decoder()->name)); + signalbase_->set_colour(DecodeColours[index % countof(DecodeColours)]); connect(decoder_stack_.get(), SIGNAL(new_decode_data()), this, SLOT(on_new_decode_data())); @@ -164,7 +171,10 @@ pair DecodeTrace::v_extents() const { const int row_height = (ViewItemPaintParams::text_height() * 6) / 4; - return make_pair(-row_height, row_height * max_visible_rows_); + // Make an empty decode trace appear symmetrical + const int row_count = max(1, max_visible_rows_); + + return make_pair(-row_height, row_height * row_count); } void DecodeTrace::paint_back(QPainter &p, const ViewItemPaintParams &pp) @@ -190,6 +200,9 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp) return; } + // Set default pen to allow for text width calculation + p.setPen(Qt::black); + // Iterate through the rows int y = get_visual_y(); pair sample_range = get_sample_range( @@ -234,6 +247,9 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp) // Draw the hatching draw_unresolved_period(p, annotation_height, pp.left(), pp.right()); + if ((int)visible_rows_.size() > max_visible_rows_) + owner_->extents_changed(false, true); + // Update the maximum row count if needed max_visible_rows_ = std::max(max_visible_rows_, (int)visible_rows_.size()); } @@ -372,7 +388,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 @@ -835,7 +851,8 @@ QComboBox* DecodeTrace::create_channel_selector( vector< shared_ptr > sig_list(sigs.begin(), sigs.end()); std::sort(sig_list.begin(), sig_list.end(), [](const shared_ptr &a, const shared_ptr b) { - return a->name().compare(b->name()) < 0; }); + return strnatcasecmp(a->base()->name().toStdString(), + b->base()->name().toStdString()) < 0; }); assert(decoder_stack_); const auto channel_iter = dec->channels().find(pdch); @@ -850,7 +867,7 @@ QComboBox* DecodeTrace::create_channel_selector( for (const shared_ptr &s : sig_list) { assert(s); if (dynamic_pointer_cast(s) && s->enabled()) { - selector->addItem(s->name(), + selector->addItem(s->base()->name(), qVariantFromValue((void*)s.get())); if (channel_iter != dec->channels().end() &&