]>
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 | |
efdec55a | 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
18f7104f JH |
18 | */ |
19 | ||
68b21a71 JH |
20 | #include <cassert> |
21 | ||
af503b10 | 22 | #include "tracetreeitem.hpp" |
6046c19d | 23 | #include "trace.hpp" |
aca9aa83 | 24 | #include "tracetreeitemowner.hpp" |
68b21a71 | 25 | |
6f925ba9 | 26 | using std::find; |
a5d93c27 | 27 | using std::make_pair; |
6f925ba9 | 28 | using std::max; |
a5d93c27 JH |
29 | using std::min; |
30 | using std::pair; | |
68b21a71 | 31 | using std::shared_ptr; |
c373f828 | 32 | using std::static_pointer_cast; |
68b21a71 JH |
33 | using std::vector; |
34 | ||
35 | namespace pv { | |
f4e57597 SA |
36 | namespace views { |
37 | namespace TraceView { | |
68b21a71 | 38 | |
a8743cd9 | 39 | const ViewItemOwner::item_list& TraceTreeItemOwner::child_items() const |
68b21a71 | 40 | { |
8dbbc7f0 | 41 | return items_; |
68b21a71 JH |
42 | } |
43 | ||
6f925ba9 | 44 | vector< shared_ptr<TraceTreeItem> > |
c373f828 | 45 | TraceTreeItemOwner::trace_tree_child_items() const |
68b21a71 | 46 | { |
c373f828 | 47 | vector< shared_ptr<TraceTreeItem> > items; |
8dbbc7f0 | 48 | for (auto &i : items_) { |
c373f828 JH |
49 | assert(dynamic_pointer_cast<TraceTreeItem>(i)); |
50 | const shared_ptr<TraceTreeItem> t( | |
51 | static_pointer_cast<TraceTreeItem>(i)); | |
52 | items.push_back(t); | |
53 | } | |
54 | ||
55 | return items; | |
56 | } | |
57 | ||
58 | void TraceTreeItemOwner::clear_child_items() | |
59 | { | |
60 | for (auto &t : trace_tree_child_items()) { | |
61 | assert(t->owner() == this); | |
62 | t->set_owner(nullptr); | |
68b21a71 | 63 | } |
8dbbc7f0 | 64 | items_.clear(); |
68b21a71 JH |
65 | } |
66 | ||
6f925ba9 | 67 | void TraceTreeItemOwner::add_child_item(shared_ptr<TraceTreeItem> item) |
68b21a71 JH |
68 | { |
69 | assert(!item->owner()); | |
70 | item->set_owner(this); | |
8dbbc7f0 | 71 | items_.push_back(item); |
32218d3e JH |
72 | |
73 | extents_changed(true, true); | |
68b21a71 JH |
74 | } |
75 | ||
6f925ba9 | 76 | void TraceTreeItemOwner::remove_child_item(shared_ptr<TraceTreeItem> item) |
68b21a71 JH |
77 | { |
78 | assert(item->owner() == this); | |
79 | item->set_owner(nullptr); | |
6f925ba9 | 80 | auto iter = find(items_.begin(), items_.end(), item); |
8dbbc7f0 JH |
81 | assert(iter != items_.end()); |
82 | items_.erase(iter); | |
32218d3e JH |
83 | |
84 | extents_changed(true, true); | |
68b21a71 JH |
85 | } |
86 | ||
af503b10 | 87 | pair<int, int> TraceTreeItemOwner::v_extents() const |
a5d93c27 | 88 | { |
d9177e6c | 89 | bool has_children = false; |
82ba380c | 90 | |
d9177e6c | 91 | pair<int, int> extents(INT_MAX, INT_MIN); |
c373f828 JH |
92 | for (const shared_ptr<TraceTreeItem> t : trace_tree_child_items()) { |
93 | assert(t); | |
94 | if (!t->enabled()) | |
a5d93c27 JH |
95 | continue; |
96 | ||
d9177e6c SA |
97 | has_children = true; |
98 | ||
c373f828 JH |
99 | const int child_offset = t->layout_v_offset(); |
100 | const pair<int, int> child_extents = t->v_extents(); | |
a5d93c27 JH |
101 | extents.first = min(child_extents.first + child_offset, |
102 | extents.first); | |
103 | extents.second = max(child_extents.second + child_offset, | |
104 | extents.second); | |
105 | } | |
106 | ||
d9177e6c SA |
107 | if (!has_children) |
108 | extents = make_pair(0, 0); | |
109 | ||
a5d93c27 JH |
110 | return extents; |
111 | } | |
112 | ||
af503b10 | 113 | void TraceTreeItemOwner::restack_items() |
7ff0145f JH |
114 | { |
115 | } | |
116 | ||
f4e57597 SA |
117 | } // namespace TraceView |
118 | } // namespace views | |
119 | } // namespace pv |