]> sigrok.org Git - pulseview.git/blame - pv/view/rowitemowner.cpp
RowItemOwner: Added list_by_type
[pulseview.git] / pv / view / rowitemowner.cpp
CommitLineData
18f7104f
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
68b21a71
JH
21#include <cassert>
22
2acdb232
JH
23#include "rowitem.hpp"
24#include "rowitemowner.hpp"
6046c19d 25#include "trace.hpp"
68b21a71 26
6046c19d 27using std::dynamic_pointer_cast;
a5d93c27
JH
28using std::max;
29using std::make_pair;
30using std::min;
31using std::pair;
873cbed0 32using std::set;
68b21a71
JH
33using std::shared_ptr;
34using std::vector;
35
36namespace pv {
37namespace view {
38
6b715302
JH
39vector< shared_ptr<RowItem> >& RowItemOwner::child_items()
40{
8dbbc7f0 41 return items_;
6b715302
JH
42}
43
68b21a71
JH
44const vector< shared_ptr<RowItem> >& RowItemOwner::child_items() const
45{
8dbbc7f0 46 return items_;
68b21a71
JH
47}
48
49void RowItemOwner::clear_child_items()
50{
8dbbc7f0 51 for (auto &i : items_) {
68b21a71
JH
52 assert(i->owner() == this);
53 i->set_owner(nullptr);
54 }
8dbbc7f0 55 items_.clear();
68b21a71
JH
56}
57
58void RowItemOwner::add_child_item(std::shared_ptr<RowItem> item)
59{
60 assert(!item->owner());
61 item->set_owner(this);
8dbbc7f0 62 items_.push_back(item);
32218d3e
JH
63
64 extents_changed(true, true);
68b21a71
JH
65}
66
67void RowItemOwner::remove_child_item(std::shared_ptr<RowItem> item)
68{
69 assert(item->owner() == this);
70 item->set_owner(nullptr);
8dbbc7f0
JH
71 auto iter = std::find(items_.begin(), items_.end(), item);
72 assert(iter != items_.end());
73 items_.erase(iter);
32218d3e
JH
74
75 extents_changed(true, true);
68b21a71
JH
76}
77
6b715302
JH
78RowItemOwner::iterator RowItemOwner::begin()
79{
8dbbc7f0 80 return iterator(this, items_.begin());
6b715302
JH
81}
82
83RowItemOwner::iterator RowItemOwner::end()
84{
85 return iterator(this);
86}
87
88RowItemOwner::const_iterator RowItemOwner::begin() const
89{
8dbbc7f0 90 return const_iterator(this, items_.cbegin());
6b715302
JH
91}
92
93RowItemOwner::const_iterator RowItemOwner::end() const
94{
95 return const_iterator(this);
96}
97
873cbed0
JH
98set< RowItemOwner* > RowItemOwner::list_row_item_owners()
99{
100 set< RowItemOwner* > owners;
101 for (const auto &r : *this)
102 owners.insert(r->owner());
103 return owners;
104}
105
6046c19d
JH
106template<class T>
107set< shared_ptr<T> > RowItemOwner::list_by_type()
108{
109 set< shared_ptr<T> > items;
110 for (const auto &r : *this) {
111 shared_ptr<T> p = dynamic_pointer_cast<T>(r);
112 if (p)
113 items.insert(p);
114 }
115
116 return items;
117}
118
119template set< shared_ptr<Trace> > RowItemOwner::list_by_type();
120
a5d93c27
JH
121pair<int, int> RowItemOwner::v_extents() const
122{
82ba380c
SA
123 pair<int, int> extents(INT_MAX, INT_MIN);
124
a5d93c27
JH
125 for (const shared_ptr<RowItem> r : child_items()) {
126 assert(r);
127 if (!r->enabled())
128 continue;
129
be9e7b4b 130 const int child_offset = r->layout_v_offset();
a5d93c27
JH
131 const pair<int, int> child_extents = r->v_extents();
132 extents.first = min(child_extents.first + child_offset,
133 extents.first);
134 extents.second = max(child_extents.second + child_offset,
135 extents.second);
136 }
137
138 return extents;
139}
140
7ff0145f
JH
141void RowItemOwner::restack_items()
142{
143}
144
68b21a71
JH
145} // view
146} // pv