X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fdecodetrace.cpp;h=20de3755be482688be6cc2ce4f28220c2bd84f5c;hp=95e0e5e9ef0f2d4ddfd0692da1ab478846351190;hb=e40a79cb13eef1ca4f8e7670ac4a36e56b26a23c;hpb=f765c3db91d60e9b038ee05f2fa6acc8587d8470 diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 95e0e5e9..20de3755 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 @@ -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()), @@ -164,7 +169,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) @@ -199,9 +207,7 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp) const vector rows(decoder_stack_->get_visible_rows()); visible_rows_.clear(); - for (size_t i = 0; i < rows.size(); i++) { - const Row &row = rows[i]; - + for (const Row& row : rows) { // Cache the row title widths int row_title_width; try { @@ -229,7 +235,7 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp) y += row_height_; - visible_rows_.push_back(rows[i]); + visible_rows_.push_back(row); } } @@ -374,7 +380,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 @@ -793,8 +799,8 @@ void DecodeTrace::create_decoder_form(int index, connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_channel_selected(int))); decoder_form->addRow(tr("%1 (%2) *") - .arg(QString::fromUtf8(pdch->name)) - .arg(QString::fromUtf8(pdch->desc)), combo); + .arg(QString::fromUtf8(pdch->name), + QString::fromUtf8(pdch->desc)), combo); const ChannelSelector s = {combo, dec, pdch}; channel_selectors_.push_back(s); @@ -808,8 +814,8 @@ void DecodeTrace::create_decoder_form(int index, connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_channel_selected(int))); decoder_form->addRow(tr("%1 (%2)") - .arg(QString::fromUtf8(pdch->name)) - .arg(QString::fromUtf8(pdch->desc)), combo); + .arg(QString::fromUtf8(pdch->name), + QString::fromUtf8(pdch->desc)), combo); const ChannelSelector s = {combo, dec, pdch}; channel_selectors_.push_back(s); @@ -837,7 +843,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->name().toStdString(), + b->name().toStdString()) < 0; }); assert(decoder_stack_); const auto channel_iter = dec->channels().find(pdch);