2 * This file is part of the PulseView project.
4 * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "tracetreeitem.hpp"
23 #include "tracetreeitemowner.hpp"
26 using std::dynamic_pointer_cast;
32 using std::shared_ptr;
33 using std::static_pointer_cast;
40 const ViewItemOwner::item_list& TraceTreeItemOwner::child_items() const
45 vector< std::shared_ptr<TraceTreeItem> >
46 TraceTreeItemOwner::trace_tree_child_items() const
48 vector< shared_ptr<TraceTreeItem> > items;
49 for (auto &i : items_) {
50 assert(dynamic_pointer_cast<TraceTreeItem>(i));
51 const shared_ptr<TraceTreeItem> t(
52 static_pointer_cast<TraceTreeItem>(i));
59 void TraceTreeItemOwner::clear_child_items()
61 for (auto &t : trace_tree_child_items()) {
62 assert(t->owner() == this);
63 t->set_owner(nullptr);
68 void TraceTreeItemOwner::add_child_item(std::shared_ptr<TraceTreeItem> item)
70 assert(!item->owner());
71 item->set_owner(this);
72 items_.push_back(item);
74 extents_changed(true, true);
77 void TraceTreeItemOwner::remove_child_item(std::shared_ptr<TraceTreeItem> item)
79 assert(item->owner() == this);
80 item->set_owner(nullptr);
81 auto iter = std::find(items_.begin(), items_.end(), item);
82 assert(iter != items_.end());
85 extents_changed(true, true);
88 pair<int, int> TraceTreeItemOwner::v_extents() const
90 bool has_children = false;
92 pair<int, int> extents(INT_MAX, INT_MIN);
93 for (const shared_ptr<TraceTreeItem> t : trace_tree_child_items()) {
100 const int child_offset = t->layout_v_offset();
101 const pair<int, int> child_extents = t->v_extents();
102 extents.first = min(child_extents.first + child_offset,
104 extents.second = max(child_extents.second + child_offset,
109 extents = make_pair(0, 0);
114 bool TraceTreeItemOwner::reassign_bgcolour_states(bool next_bgcolour_state)
116 vector< shared_ptr<TraceTreeItem> > items = trace_tree_child_items();
118 // Sort items according to vertical position
119 sort(items.begin(), items.end(),
120 [](const shared_ptr<TraceTreeItem> a, const shared_ptr<TraceTreeItem> b) {
121 return a->layout_v_offset() > b->layout_v_offset(); });
123 for (const shared_ptr<TraceTreeItem> item : items) {
124 item->set_bgcolour_state(next_bgcolour_state);
125 next_bgcolour_state = !next_bgcolour_state;
128 return next_bgcolour_state;
131 void TraceTreeItemOwner::restack_items()
135 } // namespace TraceView