]> sigrok.org Git - pulseview.git/blob - pv/view/tracegroup.cpp
af756d49be6bea0a4877433223773d0b3bbc84c2
[pulseview.git] / pv / view / tracegroup.cpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2013 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 <assert.h>
22
23 #include <algorithm>
24
25 #include <QMenu>
26
27 #include "tracegroup.h"
28
29 using std::pair;
30 using std::shared_ptr;
31 using std::vector;
32
33 namespace pv {
34 namespace view {
35
36 const int TraceGroup::Padding = 8;
37 const int TraceGroup::Width = 12;
38
39 TraceGroup::~TraceGroup()
40 {
41         _owner = nullptr;
42         clear_child_items();
43 }
44
45 bool TraceGroup::enabled() const
46 {
47         return std::any_of(child_items().begin(), child_items().end(),
48                 [](const shared_ptr<RowItem> &r) { return r->enabled(); });
49 }
50
51 pv::SigSession& TraceGroup::session()
52 {
53         assert(_owner);
54         return _owner->session();
55 }
56
57 const pv::SigSession& TraceGroup::session() const
58 {
59         assert(_owner);
60         return _owner->session();
61 }
62
63 pv::view::View* TraceGroup::view()
64 {
65         assert(_owner);
66         return _owner->view();
67 }
68
69 const pv::view::View* TraceGroup::view() const
70 {
71         assert(_owner);
72         return _owner->view();
73 }
74
75 pair<int, int> TraceGroup::v_extents() const
76 {
77         return RowItemOwner::v_extents();
78 }
79
80 void TraceGroup::paint_label(QPainter &p, int right, bool hover)
81 {
82         (void)p;
83         (void)right;
84         (void)hover;
85 }
86
87 QRectF TraceGroup::label_rect(int right) const
88 {
89         QRectF rect;
90         for (const shared_ptr<RowItem> r : child_items())
91                 if (r)
92                         rect = rect.united(r->label_rect(right));
93
94         return QRectF(rect.x() - Width - Padding, rect.y(),
95                 Width, rect.height());
96 }
97
98 bool TraceGroup::pt_in_label_rect(int left, int right, const QPoint &point)
99 {
100         (void)left;
101         (void)right;
102         (void)point;
103
104         return false;
105 }
106
107 QMenu* TraceGroup::create_context_menu(QWidget *parent)
108 {
109         QMenu *const menu = new QMenu(parent);
110
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);
115
116         return menu;
117 }
118
119 pv::widgets::Popup* TraceGroup::create_popup(QWidget *parent)
120 {
121         (void)parent;
122         return NULL;
123 }
124
125 int TraceGroup::owner_v_offset() const
126 {
127         return v_offset() + _owner->owner_v_offset();
128 }
129
130 void TraceGroup::update_viewport()
131 {
132         if (_owner)
133                 _owner->update_viewport();
134 }
135
136 void TraceGroup::on_ungroup()
137 {
138         const vector< shared_ptr<RowItem> > items(
139                 child_items().begin(), child_items().end());
140         clear_child_items();
141
142         for (shared_ptr<RowItem> r : items) {
143                 _owner->add_child_item(r);
144                 r->set_v_offset(r->v_offset() + v_offset());
145         }
146
147         _owner->remove_child_item(shared_from_this());
148         appearance_changed();
149 }
150
151 } // namespace view
152 } // namespace pv