]>
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 | 33 | using std::shared_ptr; |
c373f828 | 34 | using std::static_pointer_cast; |
68b21a71 JH |
35 | using std::vector; |
36 | ||
37 | namespace pv { | |
38 | namespace view { | |
39 | ||
a8743cd9 | 40 | const ViewItemOwner::item_list& TraceTreeItemOwner::child_items() const |
68b21a71 | 41 | { |
8dbbc7f0 | 42 | return items_; |
68b21a71 JH |
43 | } |
44 | ||
c373f828 JH |
45 | vector< std::shared_ptr<TraceTreeItem> > |
46 | TraceTreeItemOwner::trace_tree_child_items() const | |
68b21a71 | 47 | { |
c373f828 | 48 | vector< shared_ptr<TraceTreeItem> > items; |
8dbbc7f0 | 49 | for (auto &i : items_) { |
c373f828 JH |
50 | assert(dynamic_pointer_cast<TraceTreeItem>(i)); |
51 | const shared_ptr<TraceTreeItem> t( | |
52 | static_pointer_cast<TraceTreeItem>(i)); | |
53 | items.push_back(t); | |
54 | } | |
55 | ||
56 | return items; | |
57 | } | |
58 | ||
59 | void TraceTreeItemOwner::clear_child_items() | |
60 | { | |
61 | for (auto &t : trace_tree_child_items()) { | |
62 | assert(t->owner() == this); | |
63 | t->set_owner(nullptr); | |
68b21a71 | 64 | } |
8dbbc7f0 | 65 | items_.clear(); |
68b21a71 JH |
66 | } |
67 | ||
af503b10 | 68 | void TraceTreeItemOwner::add_child_item(std::shared_ptr<TraceTreeItem> item) |
68b21a71 JH |
69 | { |
70 | assert(!item->owner()); | |
71 | item->set_owner(this); | |
8dbbc7f0 | 72 | items_.push_back(item); |
32218d3e JH |
73 | |
74 | extents_changed(true, true); | |
68b21a71 JH |
75 | } |
76 | ||
af503b10 | 77 | void TraceTreeItemOwner::remove_child_item(std::shared_ptr<TraceTreeItem> item) |
68b21a71 JH |
78 | { |
79 | assert(item->owner() == this); | |
80 | item->set_owner(nullptr); | |
8dbbc7f0 JH |
81 | auto iter = std::find(items_.begin(), items_.end(), item); |
82 | assert(iter != items_.end()); | |
83 | items_.erase(iter); | |
32218d3e JH |
84 | |
85 | extents_changed(true, true); | |
68b21a71 JH |
86 | } |
87 | ||
af503b10 | 88 | pair<int, int> TraceTreeItemOwner::v_extents() const |
a5d93c27 | 89 | { |
82ba380c SA |
90 | pair<int, int> extents(INT_MAX, INT_MIN); |
91 | ||
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 | ||
c373f828 JH |
97 | const int child_offset = t->layout_v_offset(); |
98 | const pair<int, int> child_extents = t->v_extents(); | |
a5d93c27 JH |
99 | extents.first = min(child_extents.first + child_offset, |
100 | extents.first); | |
101 | extents.second = max(child_extents.second + child_offset, | |
102 | extents.second); | |
103 | } | |
104 | ||
105 | return extents; | |
106 | } | |
107 | ||
ac0708fb SA |
108 | bool TraceTreeItemOwner::reassign_bgcolour_states(bool next_bgcolour_state) |
109 | { | |
110 | vector< shared_ptr<TraceTreeItem> > items = trace_tree_child_items(); | |
111 | ||
112 | // Sort items according to vertical position | |
113 | sort(items.begin(), items.end(), | |
114 | [](const shared_ptr<TraceTreeItem> a, const shared_ptr<TraceTreeItem> b) { | |
115 | return a->layout_v_offset() > b->layout_v_offset(); }); | |
116 | ||
117 | for (const shared_ptr<TraceTreeItem> item : items) { | |
118 | item->set_bgcolour_state(next_bgcolour_state); | |
119 | next_bgcolour_state = !next_bgcolour_state; | |
120 | } | |
121 | ||
122 | return next_bgcolour_state; | |
123 | } | |
124 | ||
af503b10 | 125 | void TraceTreeItemOwner::restack_items() |
7ff0145f JH |
126 | { |
127 | } | |
128 | ||
68b21a71 JH |
129 | } // view |
130 | } // pv |