]> sigrok.org Git - pulseview.git/blame_incremental - pv/view/tracetreeitem.cpp
Fix #849 by making sure no references to the DecodeTrace instance remain
[pulseview.git] / pv / view / tracetreeitem.cpp
... / ...
CommitLineData
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 "view.hpp"
24
25#include "tracetreeitem.hpp"
26
27namespace pv {
28namespace views {
29namespace TraceView {
30
31TraceTreeItem::TraceTreeItem() :
32 owner_(nullptr),
33 layout_v_offset_(0),
34 visual_v_offset_(0),
35 v_offset_animation_(this, "visual_v_offset")
36{
37}
38
39void TraceTreeItem::select(bool select)
40{
41 ViewItem::select(select);
42 owner_->row_item_appearance_changed(true, true);
43}
44
45int TraceTreeItem::layout_v_offset() const
46{
47 return layout_v_offset_;
48}
49
50void TraceTreeItem::set_layout_v_offset(int v_offset)
51{
52 if (layout_v_offset_ == v_offset)
53 return;
54
55 layout_v_offset_ = v_offset;
56
57 if (owner_)
58 owner_->extents_changed(false, true);
59}
60
61int TraceTreeItem::visual_v_offset() const
62{
63 return visual_v_offset_;
64}
65
66void TraceTreeItem::set_visual_v_offset(int v_offset)
67{
68 visual_v_offset_ = v_offset;
69
70 if (owner_)
71 owner_->row_item_appearance_changed(true, true);
72}
73
74void TraceTreeItem::force_to_v_offset(int v_offset)
75{
76 v_offset_animation_.stop();
77 layout_v_offset_ = visual_v_offset_ = v_offset;
78
79 if (owner_) {
80 owner_->row_item_appearance_changed(true, true);
81 owner_->extents_changed(false, true);
82 }
83}
84
85void TraceTreeItem::animate_to_layout_v_offset()
86{
87 if (visual_v_offset_ == layout_v_offset_ ||
88 (v_offset_animation_.endValue() == layout_v_offset_ &&
89 v_offset_animation_.state() == QAbstractAnimation::Running))
90 return;
91
92 v_offset_animation_.setDuration(100);
93 v_offset_animation_.setStartValue(visual_v_offset_);
94 v_offset_animation_.setEndValue(layout_v_offset_);
95 v_offset_animation_.setEasingCurve(QEasingCurve::OutQuad);
96 v_offset_animation_.start();
97}
98
99TraceTreeItemOwner* TraceTreeItem::owner() const
100{
101 return owner_;
102}
103
104void TraceTreeItem::set_owner(TraceTreeItemOwner *owner)
105{
106 assert(owner_ || owner);
107 v_offset_animation_.stop();
108
109 if (owner_) {
110 const int owner_offset = owner_->owner_visual_v_offset();
111 layout_v_offset_ += owner_offset;
112 visual_v_offset_ += owner_offset;
113 }
114
115 owner_ = owner;
116
117 if (owner_) {
118 const int owner_offset = owner_->owner_visual_v_offset();
119 layout_v_offset_ -= owner_offset;
120 visual_v_offset_ -= owner_offset;
121 }
122}
123
124int TraceTreeItem::get_visual_y() const
125{
126 assert(owner_);
127 return visual_v_offset_ + owner_->owner_visual_v_offset();
128}
129
130void TraceTreeItem::drag_by(const QPoint &delta)
131{
132 assert(owner_);
133 force_to_v_offset(drag_point_.y() + delta.y() -
134 owner_->owner_visual_v_offset());
135}
136
137QPoint TraceTreeItem::point(const QRect &rect) const
138{
139 return QPoint(rect.right(), get_visual_y());
140}
141
142void TraceTreeItem::set_bgcolour_state(bool state)
143{
144 bgcolour_state_ = state;
145}
146
147} // namespace TraceView
148} // namespace views
149} // namespace pv