]>
Commit | Line | Data |
---|---|---|
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 | ||
21 | #include <cassert> | |
22 | ||
23 | #include "tracetreeitem.hpp" | |
24 | #include "tracetreeitemowner.hpp" | |
25 | #include "trace.hpp" | |
26 | ||
27 | using std::dynamic_pointer_cast; | |
28 | using std::max; | |
29 | using std::make_pair; | |
30 | using std::min; | |
31 | using std::pair; | |
32 | using std::set; | |
33 | using std::shared_ptr; | |
34 | using std::static_pointer_cast; | |
35 | using std::vector; | |
36 | ||
37 | namespace pv { | |
38 | namespace views { | |
39 | namespace TraceView { | |
40 | ||
41 | const ViewItemOwner::item_list& TraceTreeItemOwner::child_items() const | |
42 | { | |
43 | return items_; | |
44 | } | |
45 | ||
46 | vector< std::shared_ptr<TraceTreeItem> > | |
47 | TraceTreeItemOwner::trace_tree_child_items() const | |
48 | { | |
49 | vector< shared_ptr<TraceTreeItem> > items; | |
50 | for (auto &i : items_) { | |
51 | assert(dynamic_pointer_cast<TraceTreeItem>(i)); | |
52 | const shared_ptr<TraceTreeItem> t( | |
53 | static_pointer_cast<TraceTreeItem>(i)); | |
54 | items.push_back(t); | |
55 | } | |
56 | ||
57 | return items; | |
58 | } | |
59 | ||
60 | void TraceTreeItemOwner::clear_child_items() | |
61 | { | |
62 | for (auto &t : trace_tree_child_items()) { | |
63 | assert(t->owner() == this); | |
64 | t->set_owner(nullptr); | |
65 | } | |
66 | items_.clear(); | |
67 | } | |
68 | ||
69 | void TraceTreeItemOwner::add_child_item(std::shared_ptr<TraceTreeItem> item) | |
70 | { | |
71 | assert(!item->owner()); | |
72 | item->set_owner(this); | |
73 | items_.push_back(item); | |
74 | ||
75 | extents_changed(true, true); | |
76 | } | |
77 | ||
78 | void TraceTreeItemOwner::remove_child_item(std::shared_ptr<TraceTreeItem> item) | |
79 | { | |
80 | assert(item->owner() == this); | |
81 | item->set_owner(nullptr); | |
82 | auto iter = std::find(items_.begin(), items_.end(), item); | |
83 | assert(iter != items_.end()); | |
84 | items_.erase(iter); | |
85 | ||
86 | extents_changed(true, true); | |
87 | } | |
88 | ||
89 | pair<int, int> TraceTreeItemOwner::v_extents() const | |
90 | { | |
91 | bool has_children = false; | |
92 | ||
93 | pair<int, int> extents(INT_MAX, INT_MIN); | |
94 | for (const shared_ptr<TraceTreeItem> t : trace_tree_child_items()) { | |
95 | assert(t); | |
96 | if (!t->enabled()) | |
97 | continue; | |
98 | ||
99 | has_children = true; | |
100 | ||
101 | const int child_offset = t->layout_v_offset(); | |
102 | const pair<int, int> child_extents = t->v_extents(); | |
103 | extents.first = min(child_extents.first + child_offset, | |
104 | extents.first); | |
105 | extents.second = max(child_extents.second + child_offset, | |
106 | extents.second); | |
107 | } | |
108 | ||
109 | if (!has_children) | |
110 | extents = make_pair(0, 0); | |
111 | ||
112 | return extents; | |
113 | } | |
114 | ||
115 | bool TraceTreeItemOwner::reassign_bgcolour_states(bool next_bgcolour_state) | |
116 | { | |
117 | vector< shared_ptr<TraceTreeItem> > items = trace_tree_child_items(); | |
118 | ||
119 | // Sort items according to vertical position | |
120 | sort(items.begin(), items.end(), | |
121 | [](const shared_ptr<TraceTreeItem> a, const shared_ptr<TraceTreeItem> b) { | |
122 | return a->layout_v_offset() > b->layout_v_offset(); }); | |
123 | ||
124 | for (const shared_ptr<TraceTreeItem> item : items) { | |
125 | item->set_bgcolour_state(next_bgcolour_state); | |
126 | next_bgcolour_state = !next_bgcolour_state; | |
127 | } | |
128 | ||
129 | return next_bgcolour_state; | |
130 | } | |
131 | ||
132 | void TraceTreeItemOwner::restack_items() | |
133 | { | |
134 | } | |
135 | ||
136 | } // namespace TraceView | |
137 | } // namespace views | |
138 | } // namespace pv |