]> sigrok.org Git - pulseview.git/blobdiff - pv/view/viewport.cpp
RowItem: Combined appearance change signals into appearance_changed()
[pulseview.git] / pv / view / viewport.cpp
index f0c78e67fcd727bdea0249120259b80331f8f1b1..221714051504a81a7e48b47056217d98f67e05cb 100644 (file)
@@ -19,6 +19,8 @@
  */
 
 #include <cassert>
+#include <cmath>
+#include <algorithm>
 
 #include "view.h"
 #include "viewport.h"
 
 #include <QMouseEvent>
 
+using std::abs;
 using std::max;
 using std::min;
 using std::shared_ptr;
+using std::stable_sort;
 using std::vector;
 
 namespace pv {
@@ -53,27 +57,22 @@ Viewport::Viewport(View &parent) :
 
        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<Trace> > traces(_view.get_traces());
-       for (const shared_ptr<Trace> 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::paintEvent(QPaintEvent*)
 {
-       const vector< shared_ptr<Trace> > traces(_view.get_traces());
+       vector< shared_ptr<RowItem> > row_items(_view.begin(), _view.end());
+       stable_sort(row_items.begin(), row_items.end(),
+               [](const shared_ptr<RowItem> &a, const shared_ptr<RowItem> &b) {
+                       return a->v_offset() < b->v_offset(); });
 
        QPainter p(this);
        p.setRenderHint(QPainter::Antialiasing);
@@ -82,17 +81,17 @@ void Viewport::paintEvent(QPaintEvent*)
                _view.cursors().draw_viewport_background(p, rect());
 
        // Plot the signal
-       for (const shared_ptr<Trace> t : traces)
+       for (const shared_ptr<RowItem> r : row_items)
        {
-               assert(t);
-               t->paint_back(p, 0, width());
+               assert(r);
+               r->paint_back(p, 0, width());
        }
 
-       for (const shared_ptr<Trace> t : traces)
-               t->paint_mid(p, 0, width());
+       for (const shared_ptr<RowItem> r : row_items)
+               r->paint_mid(p, 0, width());
 
-       for (const shared_ptr<Trace> t : traces)
-               t->paint_fore(p, 0, width());
+       for (const shared_ptr<RowItem> r : row_items)
+               r->paint_fore(p, 0, width());
 
        if (_view.cursors_shown())
                _view.cursors().draw_viewport_foreground(p, rect());
@@ -228,10 +227,9 @@ bool Viewport::touchEvent(QTouchEvent *event)
 
 void Viewport::on_signals_changed()
 {
-       const vector< shared_ptr<Trace> > traces(_view.get_traces());
-       for (shared_ptr<Trace> t : traces) {
-               assert(t);
-               connect(t.get(), SIGNAL(visibility_changed()),
+       for (shared_ptr<RowItem> r : _view) {
+               assert(r);
+               connect(r.get(), SIGNAL(appearance_changed()),
                        this, SLOT(update()));
        }
 }