]>
Commit | Line | Data |
---|---|---|
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 | ||
af503b10 JH |
23 | #include "tracetreeitem.hpp" |
24 | #include "tracetreeitemowner.hpp" | |
6046c19d | 25 | #include "trace.hpp" |
68b21a71 | 26 | |
6046c19d | 27 | using std::dynamic_pointer_cast; |
a5d93c27 JH |
28 | using std::max; |
29 | using std::make_pair; | |
30 | using std::min; | |
31 | using std::pair; | |
873cbed0 | 32 | using std::set; |
68b21a71 JH |
33 | using std::shared_ptr; |
34 | using std::vector; | |
35 | ||
36 | namespace pv { | |
37 | namespace view { | |
38 | ||
af503b10 | 39 | vector< shared_ptr<TraceTreeItem> >& TraceTreeItemOwner::child_items() |
6b715302 | 40 | { |
8dbbc7f0 | 41 | return items_; |
6b715302 JH |
42 | } |
43 | ||
af503b10 | 44 | const vector< shared_ptr<TraceTreeItem> >& TraceTreeItemOwner::child_items() const |
68b21a71 | 45 | { |
8dbbc7f0 | 46 | return items_; |
68b21a71 JH |
47 | } |
48 | ||
af503b10 | 49 | void TraceTreeItemOwner::clear_child_items() |
68b21a71 | 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 | ||
af503b10 | 58 | void TraceTreeItemOwner::add_child_item(std::shared_ptr<TraceTreeItem> item) |
68b21a71 JH |
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 | ||
af503b10 | 67 | void TraceTreeItemOwner::remove_child_item(std::shared_ptr<TraceTreeItem> item) |
68b21a71 JH |
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 | ||
af503b10 | 78 | TraceTreeItemOwner::iterator TraceTreeItemOwner::begin() |
6b715302 | 79 | { |
8dbbc7f0 | 80 | return iterator(this, items_.begin()); |
6b715302 JH |
81 | } |
82 | ||
af503b10 | 83 | TraceTreeItemOwner::iterator TraceTreeItemOwner::end() |
6b715302 JH |
84 | { |
85 | return iterator(this); | |
86 | } | |
87 | ||
af503b10 | 88 | TraceTreeItemOwner::const_iterator TraceTreeItemOwner::begin() const |
6b715302 | 89 | { |
8dbbc7f0 | 90 | return const_iterator(this, items_.cbegin()); |
6b715302 JH |
91 | } |
92 | ||
af503b10 | 93 | TraceTreeItemOwner::const_iterator TraceTreeItemOwner::end() const |
6b715302 JH |
94 | { |
95 | return const_iterator(this); | |
96 | } | |
97 | ||
af503b10 | 98 | pair<int, int> TraceTreeItemOwner::v_extents() const |
a5d93c27 | 99 | { |
82ba380c SA |
100 | pair<int, int> extents(INT_MAX, INT_MIN); |
101 | ||
af503b10 | 102 | for (const shared_ptr<TraceTreeItem> r : child_items()) { |
a5d93c27 JH |
103 | assert(r); |
104 | if (!r->enabled()) | |
105 | continue; | |
106 | ||
be9e7b4b | 107 | const int child_offset = r->layout_v_offset(); |
a5d93c27 JH |
108 | const pair<int, int> child_extents = r->v_extents(); |
109 | extents.first = min(child_extents.first + child_offset, | |
110 | extents.first); | |
111 | extents.second = max(child_extents.second + child_offset, | |
112 | extents.second); | |
113 | } | |
114 | ||
115 | return extents; | |
116 | } | |
117 | ||
af503b10 | 118 | void TraceTreeItemOwner::restack_items() |
7ff0145f JH |
119 | { |
120 | } | |
121 | ||
68b21a71 JH |
122 | } // view |
123 | } // pv |