From: Joel Holdsworth Date: Sat, 4 Oct 2014 10:40:04 +0000 (+0100) Subject: Use iterators to traverse signals X-Git-Tag: pulseview-0.3.0~467 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=aa59d5c201c953b3edce658bc677ac78f6f6612d;p=pulseview.git Use iterators to traverse signals --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index fdfd896f..22bc528c 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -70,14 +70,9 @@ QSize Header::sizeHint() const { int max_width = 0; - const vector< shared_ptr > row_items(_view.child_items()); - for (shared_ptr r : row_items) { - assert(r); - - if (r->enabled()) { - max_width = max(max_width, (int)r->label_rect(0).width()); - } - } + for (auto &i : _view) + if (i->enabled()) + max_width = max(max_width, (int)i->label_rect(0).width()); return QSize(max_width + Padding + BaselineOffset, 0); } @@ -85,26 +80,16 @@ QSize Header::sizeHint() const shared_ptr Header::get_mouse_over_row_item(const QPoint &pt) { const int w = width() - BaselineOffset; - const vector< shared_ptr > row_items(_view.child_items()); - - for (const shared_ptr r : row_items) - { - assert(r); - if (r->enabled() && r->label_rect(w).contains(pt)) - return r; - } - + for (auto &i : _view) + if (i->enabled() && i->label_rect(w).contains(pt)) + return i; return shared_ptr(); } void Header::clear_selection() { - const vector< shared_ptr > row_items(_view.child_items()); - for (const shared_ptr r : row_items) { - assert(r); - r->select(false); - } - + for (auto &i : _view) + i->select(false); update(); } @@ -128,7 +113,9 @@ void Header::paintEvent(QPaintEvent*) // would be clipped away. const int w = width() - BaselineOffset; - vector< shared_ptr > row_items(_view.child_items()); + 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(); }); @@ -153,13 +140,11 @@ void Header::mousePressEvent(QMouseEvent *event) { assert(event); - const vector< shared_ptr > row_items(_view.child_items()); - if (event->button() & Qt::LeftButton) { _mouse_down_point = event->pos(); // Save the offsets of any signals which will be dragged - for (const shared_ptr r : row_items) + for (const shared_ptr r : _view) if (r->selected()) _drag_row_items.push_back( make_pair(r, r->v_offset())); @@ -189,7 +174,7 @@ void Header::mousePressEvent(QMouseEvent *event) if (~QApplication::keyboardModifiers() & Qt::ControlModifier) { // Unselect all other signals because the Ctrl is not // pressed - for (const shared_ptr r : row_items) + for (const shared_ptr r : _view) if (r != mouse_over_row_item) r->select(false); } @@ -286,8 +271,7 @@ void Header::keyPressEvent(QKeyEvent *e) { case Qt::Key_Delete: { - const vector< shared_ptr > row_items(_view.child_items()); - for (const shared_ptr r : row_items) + for (const shared_ptr r : _view) if (r->selected()) r->delete_pressed(); break; @@ -297,8 +281,7 @@ void Header::keyPressEvent(QKeyEvent *e) void Header::on_signals_changed() { - const vector< shared_ptr > row_items(_view.child_items()); - for (shared_ptr r : row_items) { + for (shared_ptr r : _view) { assert(r); connect(r.get(), SIGNAL(visibility_changed()), this, SLOT(on_trace_changed())); diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 372aff25..035b7803 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -326,14 +326,12 @@ const QPoint& View::hover_point() const void View::normalize_layout() { - const vector< shared_ptr > row_items(child_items()); - int v_min = INT_MAX; - for (const shared_ptr r : row_items) + for (const shared_ptr r : *this) v_min = min(r->v_offset(), v_min); const int delta = -min(v_min, 0); - for (shared_ptr r : row_items) + for (shared_ptr r : *this) r->set_v_offset(r->v_offset() + delta); verticalScrollBar()->setSliderPosition(_v_offset + delta); @@ -517,7 +515,7 @@ void View::signals_changed() // Create the initial layout int offset = SignalMargin + SignalHeight; - for (shared_ptr r : child_items()) { + for (shared_ptr r : *this) { r->set_v_offset(offset); offset += SignalHeight + 2 * SignalMargin; } @@ -554,8 +552,7 @@ void View::on_geometry_updated() void View::on_hover_point_changed() { - const vector< shared_ptr > row_items(child_items()); - for (shared_ptr r : row_items) + for (shared_ptr r : *this) r->hover_point_changed(); } diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 43da4728..c0e9a69e 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -66,18 +66,14 @@ Viewport::Viewport(View &parent) : int Viewport::get_total_height() const { int h = 0; - const vector< shared_ptr > row_items(_view.child_items()); - for (const shared_ptr r : row_items) { - assert(r); - h = max(r->v_offset() + View::SignalHeight, h); - } - + for (auto &i : _view) + h = max(i->v_offset() + View::SignalHeight, h); return h; } void Viewport::paintEvent(QPaintEvent*) { - vector< shared_ptr > row_items(_view.child_items()); + 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(); }); @@ -235,8 +231,7 @@ bool Viewport::touchEvent(QTouchEvent *event) void Viewport::on_signals_changed() { - const vector< shared_ptr > row_items(_view.child_items()); - for (shared_ptr r : row_items) { + for (shared_ptr r : _view) { assert(r); connect(r.get(), SIGNAL(visibility_changed()), this, SLOT(update()));