2 * This file is part of the PulseView project.
4 * Copyright (C) 2013 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
27 #include "tracegroup.h"
30 using std::shared_ptr;
36 const int TraceGroup::Padding = 8;
37 const int TraceGroup::Width = 12;
39 TraceGroup::~TraceGroup()
45 bool TraceGroup::enabled() const
47 return std::any_of(child_items().begin(), child_items().end(),
48 [](const shared_ptr<RowItem> &r) { return r->enabled(); });
51 pv::SigSession& TraceGroup::session()
54 return _owner->session();
57 const pv::SigSession& TraceGroup::session() const
60 return _owner->session();
63 pv::view::View* TraceGroup::view()
66 return _owner->view();
69 const pv::view::View* TraceGroup::view() const
72 return _owner->view();
75 pair<int, int> TraceGroup::v_extents() const
77 return RowItemOwner::v_extents();
80 void TraceGroup::paint_label(QPainter &p, int right, bool hover)
87 QRectF TraceGroup::label_rect(int right) const
90 for (const shared_ptr<RowItem> r : child_items())
92 rect = rect.united(r->label_rect(right));
94 return QRectF(rect.x() - Width - Padding, rect.y(),
95 Width, rect.height());
98 bool TraceGroup::pt_in_label_rect(int left, int right, const QPoint &point)
107 QMenu* TraceGroup::create_context_menu(QWidget *parent)
109 QMenu *const menu = new QMenu(parent);
111 QAction *const ungroup = new QAction(tr("Ungroup"), this);
112 ungroup->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U));
113 connect(ungroup, SIGNAL(triggered()), this, SLOT(on_ungroup()));
114 menu->addAction(ungroup);
119 pv::widgets::Popup* TraceGroup::create_popup(QWidget *parent)
125 int TraceGroup::owner_v_offset() const
127 return v_offset() + _owner->owner_v_offset();
130 void TraceGroup::update_viewport()
133 _owner->update_viewport();
136 void TraceGroup::on_ungroup()
138 const vector< shared_ptr<RowItem> > items(
139 child_items().begin(), child_items().end());
142 for (shared_ptr<RowItem> r : items) {
143 _owner->add_child_item(r);
144 r->set_v_offset(r->v_offset() + v_offset());
147 _owner->remove_child_item(shared_from_this());
148 appearance_changed();