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, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "rowitem.hpp"
24 #include "rowitemowner.hpp"
27 using std::dynamic_pointer_cast;
33 using std::shared_ptr;
39 vector< shared_ptr<RowItem> >& RowItemOwner::child_items()
44 const vector< shared_ptr<RowItem> >& RowItemOwner::child_items() const
49 void RowItemOwner::clear_child_items()
51 for (auto &i : items_) {
52 assert(i->owner() == this);
53 i->set_owner(nullptr);
58 void RowItemOwner::add_child_item(std::shared_ptr<RowItem> item)
60 assert(!item->owner());
61 item->set_owner(this);
62 items_.push_back(item);
64 extents_changed(true, true);
67 void RowItemOwner::remove_child_item(std::shared_ptr<RowItem> item)
69 assert(item->owner() == this);
70 item->set_owner(nullptr);
71 auto iter = std::find(items_.begin(), items_.end(), item);
72 assert(iter != items_.end());
75 extents_changed(true, true);
78 RowItemOwner::iterator RowItemOwner::begin()
80 return iterator(this, items_.begin());
83 RowItemOwner::iterator RowItemOwner::end()
85 return iterator(this);
88 RowItemOwner::const_iterator RowItemOwner::begin() const
90 return const_iterator(this, items_.cbegin());
93 RowItemOwner::const_iterator RowItemOwner::end() const
95 return const_iterator(this);
98 set< RowItemOwner* > RowItemOwner::list_row_item_owners()
100 set< RowItemOwner* > owners;
101 for (const auto &r : *this)
102 owners.insert(r->owner());
107 set< shared_ptr<T> > RowItemOwner::list_by_type()
109 set< shared_ptr<T> > items;
110 for (const auto &r : *this) {
111 shared_ptr<T> p = dynamic_pointer_cast<T>(r);
119 template set< shared_ptr<Trace> > RowItemOwner::list_by_type();
121 pair<int, int> RowItemOwner::v_extents() const
123 pair<int, int> extents(INT_MAX, INT_MIN);
125 for (const shared_ptr<RowItem> r : child_items()) {
130 const int child_offset = r->layout_v_offset();
131 const pair<int, int> child_extents = r->v_extents();
132 extents.first = min(child_extents.first + child_offset,
134 extents.second = max(child_extents.second + child_offset,
141 void RowItemOwner::restack_items()