From: Joel Holdsworth Date: Mon, 17 Aug 2015 00:20:57 +0000 (-0600) Subject: Use list_by_type instead of iterator X-Git-Tag: pulseview-0.3.0~89 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cc88566ce77bed57358a82dec5da648feb66d10b;p=pulseview.git Use list_by_type instead of iterator --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index be4cebcb..58c21e59 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -67,7 +67,9 @@ Header::Header(View &parent) : QSize Header::sizeHint() const { QRectF max_rect(-Padding, 0, Padding, 0); - for (auto &i : view_) + const vector> items( + view_.list_by_type()); + for (auto &i : items) if (i->enabled()) max_rect = max_rect.united(i->label_rect(QRect())); return QSize(max_rect.width() + Padding + BaselineOffset, 0); @@ -80,13 +82,17 @@ QSize Header::extended_size_hint() const vector< shared_ptr > Header::items() { - return vector< shared_ptr >(view_.begin(), view_.end()); + const vector> items( + view_.list_by_type()); + return vector< shared_ptr >(items.begin(), items.end()); } shared_ptr Header::get_mouse_over_item(const QPoint &pt) { const QRect r(0, 0, width() - BaselineOffset, height()); - for (auto &i : view_) + const vector> items( + view_.list_by_type()); + for (auto &i : items) if (i->enabled() && i->label_rect(r).contains(pt)) return i; return shared_ptr(); @@ -100,7 +106,7 @@ void Header::paintEvent(QPaintEvent*) const QRect rect(0, 0, width() - BaselineOffset, height()); vector< shared_ptr > items( - view_.begin(), view_.end()); + view_.list_by_type()); stable_sort(items.begin(), items.end(), [](const shared_ptr &a, const shared_ptr &b) { @@ -131,7 +137,9 @@ void Header::contextMenuEvent(QContextMenuEvent *event) if (!menu) menu = new QMenu(this); - if (std::count_if(view_.begin(), view_.end(), item_selected) > 1) + const vector< shared_ptr > items( + view_.list_by_type()); + if (std::count_if(items.begin(), items.end(), item_selected) > 1) { menu->addSeparator(); @@ -160,9 +168,11 @@ void Header::keyPressEvent(QKeyEvent *e) void Header::on_group() { + const vector< shared_ptr > items( + view_.list_by_type()); vector< shared_ptr > selected_items( - make_filter_iterator(item_selected, view_.begin(), view_.end()), - make_filter_iterator(item_selected, view_.end(), view_.end())); + make_filter_iterator(item_selected, items.begin(), items.end()), + make_filter_iterator(item_selected, items.end(), items.end())); stable_sort(selected_items.begin(), selected_items.end(), [](const shared_ptr &a, const shared_ptr &b) { return a->visual_v_offset() < b->visual_v_offset(); }); diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 3eb04920..6d366e73 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -509,8 +509,10 @@ void View::update_viewport() void View::restack_all_trace_tree_items() { // Make a list of owners that is sorted from deepest first + const vector> items( + list_by_type()); set< TraceTreeItemOwner* > owners; - for (const auto &r : *this) + for (const auto &r : items) owners.insert(r->owner()); vector< TraceTreeItemOwner* > sorted_owners(owners.begin(), owners.end()); sort(sorted_owners.begin(), sorted_owners.end(), @@ -522,8 +524,6 @@ void View::restack_all_trace_tree_items() o->restack_items(); // Animate the items to their destination - const vector< shared_ptr > items( - list_by_type()); for (const auto &i : items) i->animate_to_layout_v_offset(); } @@ -1065,7 +1065,9 @@ void View::process_sticky_events() void View::on_hover_point_changed() { - for (shared_ptr r : *this) + const vector> trace_tree_items( + list_by_type()); + for (shared_ptr r : trace_tree_items) r->hover_point_changed(); } diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 007a8c21..c55e76a2 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -95,7 +95,11 @@ void Viewport::drag_release() vector< shared_ptr > Viewport::items() { - vector< shared_ptr > items(view_.begin(), view_.end()); + vector< shared_ptr > items; + const vector< shared_ptr > trace_tree_items( + view_.list_by_type()); + copy(trace_tree_items.begin(), trace_tree_items.end(), + back_inserter(items)); const vector< shared_ptr > time_items(view_.time_items()); copy(time_items.begin(), time_items.end(), back_inserter(items)); return items; @@ -148,11 +152,12 @@ bool Viewport::touch_event(QTouchEvent *event) void Viewport::paintEvent(QPaintEvent*) { - vector< shared_ptr > row_items(view_.begin(), view_.end()); - assert(none_of(row_items.begin(), row_items.end(), + vector< shared_ptr > trace_tree_items( + view_.list_by_type()); + assert(none_of(trace_tree_items.begin(), trace_tree_items.end(), [](const shared_ptr &r) { return !r; })); - stable_sort(row_items.begin(), row_items.end(), + stable_sort(trace_tree_items.begin(), trace_tree_items.end(), [](const shared_ptr &a, const shared_ptr &b) { return a->visual_v_offset() < b->visual_v_offset(); }); @@ -167,17 +172,17 @@ void Viewport::paintEvent(QPaintEvent*) for (const shared_ptr t : time_items) t->paint_back(p, pp); - for (const shared_ptr r : row_items) + for (const shared_ptr r : trace_tree_items) r->paint_back(p, pp); for (const shared_ptr t : time_items) t->paint_mid(p, pp); - for (const shared_ptr r : row_items) + for (const shared_ptr r : trace_tree_items) r->paint_mid(p, pp); p.setRenderHint(QPainter::Antialiasing, false); - for (const shared_ptr r : row_items) + for (const shared_ptr r : trace_tree_items) r->paint_fore(p, pp); for (const shared_ptr t : time_items) t->paint_fore(p, pp); diff --git a/pv/view/viewwidget.cpp b/pv/view/viewwidget.cpp index 9913b5cc..69e34566 100644 --- a/pv/view/viewwidget.cpp +++ b/pv/view/viewwidget.cpp @@ -64,8 +64,11 @@ void ViewWidget::item_clicked(const shared_ptr &item) bool ViewWidget::accept_drag() const { const vector< shared_ptr > items(view_.time_items()); + const vector< shared_ptr > trace_tree_items( + view_.list_by_type()); - const bool any_row_items_selected = any_of(view_.begin(), view_.end(), + const bool any_row_items_selected = any_of( + trace_tree_items.begin(), trace_tree_items.end(), [](const shared_ptr &r) { return r->selected(); }); const bool any_time_items_selected = any_of(items.begin(), items.end(), @@ -75,7 +78,7 @@ bool ViewWidget::accept_drag() const { // Check all the drag items share a common owner TraceTreeItemOwner *item_owner = nullptr; - for (shared_ptr r : view_) + for (shared_ptr r : trace_tree_items) if (r->dragging()) { if (!item_owner) item_owner = r->owner(); @@ -106,7 +109,9 @@ void ViewWidget::drag_items(const QPoint &delta) // Drag the row items TraceTreeItemOwner *item_owner = nullptr; - for (std::shared_ptr r : view_) + const vector< shared_ptr > trace_tree_items( + view_.list_by_type()); + for (shared_ptr r : trace_tree_items) if (r->dragging()) { item_owner = r->owner(); r->drag_by(delta); @@ -118,7 +123,7 @@ void ViewWidget::drag_items(const QPoint &delta) if (item_owner) { item_dragged = true; item_owner->restack_items(); - for (const auto &r : *item_owner) + for (shared_ptr r : trace_tree_items) r->animate_to_layout_v_offset(); }