]> sigrok.org Git - pulseview.git/commitdiff
Use list_by_type instead of iterator
authorJoel Holdsworth <redacted>
Mon, 17 Aug 2015 00:20:57 +0000 (18:20 -0600)
committerJoel Holdsworth <redacted>
Sun, 18 Oct 2015 21:32:28 +0000 (15:32 -0600)
pv/view/header.cpp
pv/view/view.cpp
pv/view/viewport.cpp
pv/view/viewwidget.cpp

index be4cebcb26f40b4e23ffe337ebe211a1c745da97..58c21e596c7ab9ace1beb392a5510b270609dddf 100644 (file)
@@ -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<shared_ptr<TraceTreeItem>> items(
+               view_.list_by_type<TraceTreeItem>());
+       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<ViewItem> > Header::items()
 {
-       return vector< shared_ptr<ViewItem> >(view_.begin(), view_.end());
+       const vector<shared_ptr<TraceTreeItem>> items(
+               view_.list_by_type<TraceTreeItem>());
+       return vector< shared_ptr<ViewItem> >(items.begin(), items.end());
 }
 
 shared_ptr<ViewItem> Header::get_mouse_over_item(const QPoint &pt)
 {
        const QRect r(0, 0, width() - BaselineOffset, height());
-       for (auto &i : view_)
+       const vector<shared_ptr<TraceTreeItem>> items(
+               view_.list_by_type<TraceTreeItem>());
+       for (auto &i : items)
                if (i->enabled() && i->label_rect(r).contains(pt))
                        return i;
        return shared_ptr<TraceTreeItem>();
@@ -100,7 +106,7 @@ void Header::paintEvent(QPaintEvent*)
        const QRect rect(0, 0, width() - BaselineOffset, height());
 
        vector< shared_ptr<TraceTreeItem> > items(
-               view_.begin(), view_.end());
+               view_.list_by_type<TraceTreeItem>());
 
        stable_sort(items.begin(), items.end(),
                [](const shared_ptr<TraceTreeItem> &a, const shared_ptr<TraceTreeItem> &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<TraceTreeItem> > items(
+               view_.list_by_type<TraceTreeItem>());
+       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<TraceTreeItem> > items(
+               view_.list_by_type<TraceTreeItem>());
        vector< shared_ptr<TraceTreeItem> > 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<TraceTreeItem> &a, const shared_ptr<TraceTreeItem> &b) {
                        return a->visual_v_offset() < b->visual_v_offset(); });
index 3eb04920ef8f364ac19bd299f0f51a4e81039177..6d366e7311881b8736b80daf2709becd72d7c88b 100644 (file)
@@ -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<shared_ptr<TraceTreeItem>> items(
+               list_by_type<TraceTreeItem>());
        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<TraceTreeItem> > items(
-               list_by_type<TraceTreeItem>());
        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<TraceTreeItem> r : *this)
+       const vector<shared_ptr<TraceTreeItem>> trace_tree_items(
+               list_by_type<TraceTreeItem>());
+       for (shared_ptr<TraceTreeItem> r : trace_tree_items)
                r->hover_point_changed();
 }
 
index 007a8c218878fa14cf0477322b7557296a990a14..c55e76a2d301d0ce1b9e362a33194dbbe0909848 100644 (file)
@@ -95,7 +95,11 @@ void Viewport::drag_release()
 
 vector< shared_ptr<ViewItem> > Viewport::items()
 {
-       vector< shared_ptr<ViewItem> > items(view_.begin(), view_.end());
+       vector< shared_ptr<ViewItem> > items;
+       const vector< shared_ptr<TraceTreeItem> > trace_tree_items(
+               view_.list_by_type<TraceTreeItem>());
+       copy(trace_tree_items.begin(), trace_tree_items.end(),
+               back_inserter(items));
        const vector< shared_ptr<TimeItem> > 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<TraceTreeItem> > row_items(view_.begin(), view_.end());
-       assert(none_of(row_items.begin(), row_items.end(),
+       vector< shared_ptr<TraceTreeItem> > trace_tree_items(
+               view_.list_by_type<TraceTreeItem>());
+       assert(none_of(trace_tree_items.begin(), trace_tree_items.end(),
                [](const shared_ptr<TraceTreeItem> &r) { return !r; }));
 
-       stable_sort(row_items.begin(), row_items.end(),
+       stable_sort(trace_tree_items.begin(), trace_tree_items.end(),
                [](const shared_ptr<TraceTreeItem> &a, const shared_ptr<TraceTreeItem> &b) {
                        return a->visual_v_offset() < b->visual_v_offset(); });
 
@@ -167,17 +172,17 @@ void Viewport::paintEvent(QPaintEvent*)
 
        for (const shared_ptr<TimeItem> t : time_items)
                t->paint_back(p, pp);
-       for (const shared_ptr<TraceTreeItem> r : row_items)
+       for (const shared_ptr<TraceTreeItem> r : trace_tree_items)
                r->paint_back(p, pp);
 
        for (const shared_ptr<TimeItem> t : time_items)
                t->paint_mid(p, pp);
-       for (const shared_ptr<TraceTreeItem> r : row_items)
+       for (const shared_ptr<TraceTreeItem> r : trace_tree_items)
                r->paint_mid(p, pp);
 
        p.setRenderHint(QPainter::Antialiasing, false);
 
-       for (const shared_ptr<TraceTreeItem> r : row_items)
+       for (const shared_ptr<TraceTreeItem> r : trace_tree_items)
                r->paint_fore(p, pp);
        for (const shared_ptr<TimeItem> t : time_items)
                t->paint_fore(p, pp);
index 9913b5cc1640550a5cf563849a1c0a361a3f5cb2..69e345660ab3558cf677ef66a2d7b7083602b65a 100644 (file)
@@ -64,8 +64,11 @@ void ViewWidget::item_clicked(const shared_ptr<ViewItem> &item)
 bool ViewWidget::accept_drag() const
 {
        const vector< shared_ptr<TimeItem> > items(view_.time_items());
+       const vector< shared_ptr<TraceTreeItem> > trace_tree_items(
+               view_.list_by_type<TraceTreeItem>());
 
-       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<TraceTreeItem> &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<TraceTreeItem> r : view_)
+               for (shared_ptr<TraceTreeItem> 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<TraceTreeItem> r : view_)
+       const vector< shared_ptr<TraceTreeItem> > trace_tree_items(
+               view_.list_by_type<TraceTreeItem>());
+       for (shared_ptr<TraceTreeItem> 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<TraceTreeItem> r : trace_tree_items)
                        r->animate_to_layout_v_offset();
        }