X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fview%2Fviewport.cpp;h=8963e047b355dc8f3f0d2d2eba30fd2cb3b92766;hb=0dda6fe595932b2e340930104fad8ac4fc574895;hp=b141c38ae35ab29b2b44233bff6e8d13be16de3d;hpb=c8870d9e7af0af746776680a266d0da3ec3280ec;p=pulseview.git diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index b141c38a..8963e047 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -19,6 +19,8 @@ */ #include +#include +#include #include "view.h" #include "viewport.h" @@ -32,6 +34,7 @@ using std::abs; using std::max; using std::min; using std::shared_ptr; +using std::stable_sort; using std::vector; namespace pv { @@ -49,32 +52,33 @@ Viewport::Viewport(View &parent) : setAutoFillBackground(true); setBackgroundRole(QPalette::Base); - connect(&_view.session(), SIGNAL(signals_changed()), - this, SLOT(on_signals_changed())); - connect(&_view, SIGNAL(signals_moved()), this, SLOT(on_signals_moved())); - - // Trigger the initial event manually. The default device has signals - // which were created before this object came into being - on_signals_changed(); } int Viewport::get_total_height() const { int h = 0; - const vector< shared_ptr > traces(_view.get_traces()); - for (const shared_ptr t : traces) { - assert(t); - h = max(t->get_v_offset() + View::SignalHeight, h); - } - + for (auto &i : _view) + h = max(i->v_offset() + View::SignalHeight, h); return h; } +void Viewport::signals_updated() +{ + for (shared_ptr r : _view) { + assert(r); + connect(r.get(), SIGNAL(appearance_changed()), + this, SLOT(update())); + } +} + void Viewport::paintEvent(QPaintEvent*) { - const vector< shared_ptr > traces(_view.get_traces()); + vector< shared_ptr > row_items(_view.begin(), _view.end()); + stable_sort(row_items.begin(), row_items.end(), + [](const shared_ptr &a, const shared_ptr &b) { + return a->v_offset() < b->v_offset(); }); QPainter p(this); p.setRenderHint(QPainter::Antialiasing); @@ -83,17 +87,17 @@ void Viewport::paintEvent(QPaintEvent*) _view.cursors().draw_viewport_background(p, rect()); // Plot the signal - for (const shared_ptr t : traces) + for (const shared_ptr r : row_items) { - assert(t); - t->paint_back(p, 0, width()); + assert(r); + r->paint_back(p, 0, width()); } - for (const shared_ptr t : traces) - t->paint_mid(p, 0, width()); + for (const shared_ptr r : row_items) + r->paint_mid(p, 0, width()); - for (const shared_ptr t : traces) - t->paint_fore(p, 0, width()); + for (const shared_ptr r : row_items) + r->paint_fore(p, 0, width()); if (_view.cursors_shown()) _view.cursors().draw_viewport_foreground(p, rect()); @@ -227,16 +231,6 @@ bool Viewport::touchEvent(QTouchEvent *event) return true; } -void Viewport::on_signals_changed() -{ - const vector< shared_ptr > traces(_view.get_traces()); - for (shared_ptr t : traces) { - assert(t); - connect(t.get(), SIGNAL(visibility_changed()), - this, SLOT(update())); - } -} - void Viewport::on_signals_moved() { update();