]> sigrok.org Git - pulseview.git/blame - pv/view/view.cpp
RowItem: Pass rect into label_rect
[pulseview.git] / pv / view / view.cpp
CommitLineData
adb4b10c 1/*
b3f22de0 2 * This file is part of the PulseView project.
adb4b10c
JH
3 *
4 * Copyright (C) 2012 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
269528f5 21#ifdef ENABLE_DECODE
4e5a4405 22#include <libsigrokdecode/libsigrokdecode.h>
269528f5 23#endif
4e5a4405 24
361c560e
JH
25#include <extdef.h>
26
c3a740dd
JH
27#include <cassert>
28#include <climits>
29#include <cmath>
30#include <mutex>
7ff0145f 31#include <unordered_set>
adb4b10c 32
361c560e 33#include <QApplication>
adb4b10c 34#include <QEvent>
361c560e 35#include <QFontMetrics>
cbd80f64 36#include <QMouseEvent>
adb4b10c
JH
37#include <QScrollBar>
38
448a72cf
JH
39#include <libsigrok/libsigrok.hpp>
40
2acdb232
JH
41#include "cursorheader.hpp"
42#include "decodetrace.hpp"
43#include "header.hpp"
44#include "logicsignal.hpp"
45#include "ruler.hpp"
46#include "signal.hpp"
47#include "tracegroup.hpp"
48#include "view.hpp"
49#include "viewport.hpp"
adb4b10c 50
f65cd27b 51#include "pv/session.hpp"
2acdb232 52#include "pv/data/logic.hpp"
f3d66e52 53#include "pv/data/logicsegment.hpp"
361c560e 54#include "pv/util.hpp"
adb4b10c 55
aca64cac
JH
56using boost::shared_lock;
57using boost::shared_mutex;
361c560e 58
1bc6525b 59using pv::data::SignalData;
f3d66e52 60using pv::data::Segment;
361c560e
JH
61using pv::util::format_time;
62
a2321722 63using std::back_inserter;
819f4c25 64using std::deque;
448a72cf 65using std::dynamic_pointer_cast;
819f4c25 66using std::list;
c3a740dd 67using std::lock_guard;
819f4c25 68using std::max;
1bc6525b 69using std::make_pair;
819f4c25 70using std::min;
1bc6525b 71using std::pair;
819f4c25 72using std::set;
f9abf97e 73using std::shared_ptr;
448a72cf 74using std::unordered_map;
7ff0145f 75using std::unordered_set;
819f4c25 76using std::vector;
f9abf97e 77using std::weak_ptr;
adb4b10c 78
cdf7bea7
JH
79namespace pv {
80namespace view {
adb4b10c 81
cdf7bea7
JH
82const double View::MaxScale = 1e9;
83const double View::MinScale = 1e-15;
adb4b10c 84
f25770e2
JH
85const int View::MaxScrollValue = INT_MAX / 2;
86
361c560e
JH
87const int View::ScaleUnits[3] = {1, 2, 5};
88
f76af637
JH
89const QColor View::CursorAreaColour(220, 231, 243);
90
2e04f9bd
JH
91const QSizeF View::LabelPadding(4, 0);
92
2b81ae46 93View::View(Session &session, QWidget *parent) :
adb4b10c 94 QAbstractScrollArea(parent),
8dbbc7f0
JH
95 session_(session),
96 viewport_(new Viewport(*this)),
97 ruler_(new Ruler(*this)),
98 cursorheader_(new CursorHeader(*this)),
99 header_(new Header(*this)),
100 scale_(1e-6),
101 offset_(0),
102 v_offset_(0),
103 updating_scroll_(false),
361c560e
JH
104 tick_period_(0.0),
105 tick_prefix_(0),
8dbbc7f0 106 show_cursors_(false),
5c5ce757 107 cursors_(new CursorPair(*this)),
8dbbc7f0 108 hover_point_(-1, -1)
adb4b10c 109{
b16907d3
JH
110 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
111 this, SLOT(h_scroll_value_changed(int)));
adb4b10c
JH
112 connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
113 this, SLOT(v_scroll_value_changed(int)));
69dd2b03 114
8dbbc7f0 115 connect(&session_, SIGNAL(signals_changed()),
69dd2b03 116 this, SLOT(signals_changed()));
8dbbc7f0 117 connect(&session_, SIGNAL(capture_state_changed(int)),
50f97924 118 this, SLOT(data_updated()));
8dbbc7f0 119 connect(&session_, SIGNAL(data_received()),
1f374035 120 this, SLOT(data_updated()));
8dbbc7f0 121 connect(&session_, SIGNAL(frame_ended()),
adb4b10c 122 this, SLOT(data_updated()));
1d8dca91 123
5c5ce757 124 connect(cursors_->first().get(), SIGNAL(time_changed()),
ca4ec3ea 125 this, SLOT(marker_time_changed()));
5c5ce757 126 connect(cursors_->second().get(), SIGNAL(time_changed()),
ca4ec3ea
JH
127 this, SLOT(marker_time_changed()));
128
8dbbc7f0 129 connect(header_, SIGNAL(signals_moved()),
07204819 130 this, SLOT(on_signals_moved()));
54401bbb 131
8dbbc7f0
JH
132 connect(header_, SIGNAL(selection_changed()),
133 cursorheader_, SLOT(clear_selection()));
134 connect(cursorheader_, SIGNAL(selection_changed()),
135 header_, SLOT(clear_selection()));
17348f85 136
8dbbc7f0 137 connect(header_, SIGNAL(selection_changed()),
8b454527 138 this, SIGNAL(selection_changed()));
8dbbc7f0 139 connect(cursorheader_, SIGNAL(selection_changed()),
8b454527
JH
140 this, SIGNAL(selection_changed()));
141
33c62f44
JH
142 connect(this, SIGNAL(hover_point_changed()),
143 this, SLOT(on_hover_point_changed()));
144
8dbbc7f0 145 connect(&lazy_event_handler_, SIGNAL(timeout()),
32218d3e 146 this, SLOT(process_sticky_events()));
8dbbc7f0 147 lazy_event_handler_.setSingleShot(true);
32218d3e 148
8dbbc7f0 149 setViewport(viewport_);
cbd80f64 150
8dbbc7f0
JH
151 viewport_->installEventFilter(this);
152 ruler_->installEventFilter(this);
153 cursorheader_->installEventFilter(this);
154 header_->installEventFilter(this);
d873f4d6 155
9f46d905
JH
156 // Trigger the initial event manually. The default device has signals
157 // which were created before this object came into being
d873f4d6 158 signals_changed();
84a0d458 159
512bfc56 160 // make sure the transparent widgets are on the top
8dbbc7f0
JH
161 cursorheader_->raise();
162 header_->raise();
361c560e
JH
163
164 // Update the zoom state
165 calculate_tick_spacing();
adb4b10c
JH
166}
167
2b81ae46 168Session& View::session()
1d19ef83 169{
8dbbc7f0 170 return session_;
1d19ef83
JH
171}
172
2b81ae46 173const Session& View::session() const
38eeddea 174{
8dbbc7f0 175 return session_;
38eeddea
JH
176}
177
eae6e30a
JH
178View* View::view()
179{
180 return this;
181}
182
183const View* View::view() const
184{
185 return this;
186}
187
2ae445ba
SA
188Viewport* View::viewport()
189{
8dbbc7f0 190 return viewport_;
2ae445ba
SA
191}
192
193const Viewport* View::viewport() const
194{
8dbbc7f0 195 return viewport_;
2ae445ba
SA
196}
197
2496bf45
JH
198vector< shared_ptr<TimeItem> > View::time_items() const
199{
200 vector< shared_ptr<TimeItem> > items;
5c5ce757
JH
201 items.push_back(cursors_->first());
202 items.push_back(cursors_->second());
2496bf45
JH
203 return items;
204}
205
cdf7bea7 206double View::scale() const
adb4b10c 207{
8dbbc7f0 208 return scale_;
adb4b10c
JH
209}
210
cdf7bea7 211double View::offset() const
adb4b10c 212{
8dbbc7f0 213 return offset_;
adb4b10c
JH
214}
215
7ff0145f 216int View::owner_visual_v_offset() const
adb4b10c 217{
8dbbc7f0 218 return -v_offset_;
adb4b10c
JH
219}
220
3e769a37
JH
221unsigned int View::depth() const
222{
223 return 0;
224}
225
361c560e
JH
226unsigned int View::tick_prefix() const
227{
228 return tick_prefix_;
229}
230
231double View::tick_period() const
232{
233 return tick_period_;
234}
235
cdf7bea7 236void View::zoom(double steps)
adb4b10c 237{
8dbbc7f0 238 zoom(steps, viewport_->width() / 2);
adb4b10c
JH
239}
240
17c0f398
JH
241void View::zoom(double steps, int offset)
242{
8dbbc7f0 243 set_zoom(scale_ * pow(3.0/2.0, -steps), offset);
17c0f398
JH
244}
245
ca46b534
JH
246void View::zoom_fit()
247{
1bc6525b
JH
248 const pair<double, double> extents = get_time_extents();
249 const double delta = extents.second - extents.first;
250 if (delta < 1e-12)
ca46b534
JH
251 return;
252
8dbbc7f0
JH
253 assert(viewport_);
254 const int w = viewport_->width();
ca46b534
JH
255 if (w <= 0)
256 return;
257
78311127
JH
258 const double scale = max(min(delta / w, MaxScale), MinScale);
259 set_scale_offset(scale, extents.first);
ca46b534
JH
260}
261
d1e7d82c
JH
262void View::zoom_one_to_one()
263{
264 using pv::data::SignalData;
265
d1e7d82c 266 // Make a set of all the visible data objects
0fc664a9 267 set< shared_ptr<SignalData> > visible_data = get_visible_data();
d1e7d82c
JH
268 if (visible_data.empty())
269 return;
270
271 double samplerate = 0.0;
d9aecf1f 272 for (const shared_ptr<SignalData> d : visible_data) {
d1e7d82c 273 assert(d);
f3d66e52
JH
274 const vector< shared_ptr<Segment> > segments =
275 d->segments();
276 for (const shared_ptr<Segment> &s : segments)
ff008de6 277 samplerate = max(samplerate, s->samplerate());
d1e7d82c
JH
278 }
279
280 if (samplerate == 0.0)
281 return;
282
8dbbc7f0
JH
283 assert(viewport_);
284 const int w = viewport_->width();
d1e7d82c
JH
285 if (w <= 0)
286 return;
287
288 set_zoom(1.0 / samplerate, w / 2);
289}
290
cdf7bea7 291void View::set_scale_offset(double scale, double offset)
adb4b10c 292{
8dbbc7f0
JH
293 scale_ = scale;
294 offset_ = offset;
ccdd3ef5 295
361c560e
JH
296 calculate_tick_spacing();
297
adb4b10c 298 update_scroll();
8dbbc7f0
JH
299 ruler_->update();
300 cursorheader_->update();
301 viewport_->update();
e0fc5810 302 scale_offset_changed();
adb4b10c
JH
303}
304
1bc6525b
JH
305set< shared_ptr<SignalData> > View::get_visible_data() const
306{
aca64cac 307 shared_lock<shared_mutex> lock(session().signals_mutex());
c3a740dd 308 const vector< shared_ptr<Signal> > &sigs(session().signals());
1bc6525b
JH
309
310 // Make a set of all the visible data objects
311 set< shared_ptr<SignalData> > visible_data;
d9aecf1f 312 for (const shared_ptr<Signal> sig : sigs)
1bc6525b
JH
313 if (sig->enabled())
314 visible_data.insert(sig->data());
315
316 return visible_data;
317}
318
319pair<double, double> View::get_time_extents() const
320{
1bc6525b 321 double left_time = DBL_MAX, right_time = DBL_MIN;
7f4038d6 322 const set< shared_ptr<SignalData> > visible_data = get_visible_data();
d9aecf1f 323 for (const shared_ptr<SignalData> d : visible_data)
1bc6525b 324 {
f3d66e52
JH
325 const vector< shared_ptr<Segment> > segments =
326 d->segments();
327 for (const shared_ptr<Segment> &s : segments) {
ff008de6
JH
328 double samplerate = s->samplerate();
329 samplerate = (samplerate <= 0.0) ? 1.0 : samplerate;
330
7f4038d6
JH
331 const double start_time = s->start_time();
332 left_time = min(left_time, start_time);
333 right_time = max(right_time, start_time +
334 d->get_max_sample_count() / samplerate);
335 }
1bc6525b
JH
336 }
337
7f4038d6
JH
338 if (left_time == DBL_MAX && right_time == DBL_MIN)
339 return make_pair(0.0, 0.0);
340
1bc6525b
JH
341 assert(left_time < right_time);
342 return make_pair(left_time, right_time);
343}
344
f76af637
JH
345bool View::cursors_shown() const
346{
8dbbc7f0 347 return show_cursors_;
f76af637
JH
348}
349
350void View::show_cursors(bool show)
351{
8dbbc7f0
JH
352 show_cursors_ = show;
353 cursorheader_->update();
354 viewport_->update();
f76af637
JH
355}
356
b4d91e56
JH
357void View::centre_cursors()
358{
8dbbc7f0 359 const double time_width = scale_ * viewport_->width();
5c5ce757
JH
360 cursors_->first()->set_time(offset_ + time_width * 0.4);
361 cursors_->second()->set_time(offset_ + time_width * 0.6);
8dbbc7f0
JH
362 cursorheader_->update();
363 viewport_->update();
b4d91e56
JH
364}
365
5c5ce757 366std::shared_ptr<CursorPair> View::cursors() const
58864c5c 367{
8dbbc7f0 368 return cursors_;
58864c5c
JH
369}
370
cbd80f64
JH
371const QPoint& View::hover_point() const
372{
8dbbc7f0 373 return hover_point_;
cbd80f64
JH
374}
375
9cef9567
JH
376void View::update_viewport()
377{
8dbbc7f0
JH
378 assert(viewport_);
379 viewport_->update();
380 header_->update();
7ff0145f
JH
381}
382
383void View::restack_all_row_items()
384{
385 // Make a set of owners
386 unordered_set< RowItemOwner* > owners;
387 for (const auto &r : *this)
388 owners.insert(r->owner());
389
390 // Make a list that is sorted from deepest first
391 vector< RowItemOwner* > sorted_owners(owners.begin(), owners.end());
392 sort(sorted_owners.begin(), sorted_owners.end(),
393 [](const RowItemOwner* a, const RowItemOwner *b) {
394 return a->depth() > b->depth(); });
395
396 // Restack the items recursively
397 for (auto &o : sorted_owners)
398 o->restack_items();
399
400 // Animate the items to their destination
401 for (const auto &r : *this)
402 r->animate_to_layout_v_offset();
9cef9567
JH
403}
404
f25770e2
JH
405void View::get_scroll_layout(double &length, double &offset) const
406{
1bc6525b 407 const pair<double, double> extents = get_time_extents();
8dbbc7f0
JH
408 length = (extents.second - extents.first) / scale_;
409 offset = offset_ / scale_;
f25770e2
JH
410}
411
d1e7d82c
JH
412void View::set_zoom(double scale, int offset)
413{
8dbbc7f0 414 const double cursor_offset = offset_ + scale_ * offset;
d1e7d82c
JH
415 const double new_scale = max(min(scale, MaxScale), MinScale);
416 const double new_offset = cursor_offset - new_scale * offset;
417 set_scale_offset(new_scale, new_offset);
418}
419
361c560e
JH
420void View::calculate_tick_spacing()
421{
422 const double SpacingIncrement = 32.0f;
423 const double MinValueSpacing = 32.0f;
424
425 double min_width = SpacingIncrement, typical_width;
426
427 QFontMetrics m(QApplication::font());
428
429 do {
430 const double min_period = scale_ * min_width;
431
432 const int order = (int)floorf(log10f(min_period));
433 const double order_decimal = pow(10.0, order);
434
435 unsigned int unit = 0;
436
437 do {
438 tick_period_ = order_decimal * ScaleUnits[unit++];
439 } while (tick_period_ < min_period &&
440 unit < countof(ScaleUnits));
441
442 tick_prefix_ = (order - pv::util::FirstSIPrefixPower) / 3;
443
444 typical_width = m.boundingRect(0, 0, INT_MAX, INT_MAX,
445 Qt::AlignLeft | Qt::AlignTop,
446 format_time(offset_, tick_prefix_)).width() +
447 MinValueSpacing;
448
449 min_width += SpacingIncrement;
450
451 } while(typical_width > tick_period_ / scale_);
452}
453
cdf7bea7 454void View::update_scroll()
adb4b10c 455{
8dbbc7f0 456 assert(viewport_);
adb4b10c 457
8dbbc7f0 458 const QSize areaSize = viewport_->size();
adb4b10c
JH
459
460 // Set the horizontal scroll bar
461 double length = 0, offset = 0;
f25770e2
JH
462 get_scroll_layout(length, offset);
463 length = max(length - areaSize.width(), 0.0);
adb4b10c 464
d7aae647
SA
465 int major_tick_distance = tick_period_ / scale_;
466
b4ef7f2a 467 horizontalScrollBar()->setPageStep(areaSize.width() / 2);
d7aae647 468 horizontalScrollBar()->setSingleStep(major_tick_distance);
f25770e2 469
8dbbc7f0 470 updating_scroll_ = true;
528bd8a1 471
333d5bbc 472 if (length < MaxScrollValue) {
f25770e2
JH
473 horizontalScrollBar()->setRange(0, length);
474 horizontalScrollBar()->setSliderPosition(offset);
475 } else {
476 horizontalScrollBar()->setRange(0, MaxScrollValue);
477 horizontalScrollBar()->setSliderPosition(
8dbbc7f0 478 offset_ * MaxScrollValue / (scale_ * length));
f25770e2 479 }
adb4b10c 480
8dbbc7f0 481 updating_scroll_ = false;
528bd8a1 482
adb4b10c
JH
483 // Set the vertical scrollbar
484 verticalScrollBar()->setPageStep(areaSize.height());
a5d93c27
JH
485
486 const pair<int, int> extents = v_extents();
487 const int extra_scroll_height = (extents.second - extents.first) / 4;
488 verticalScrollBar()->setRange(extents.first - extra_scroll_height,
489 extents.first + extra_scroll_height);
adb4b10c
JH
490}
491
d7c0ca4a
JH
492void View::update_layout()
493{
512bfc56 494 setViewportMargins(
8dbbc7f0
JH
495 header_->sizeHint().width() - pv::view::Header::BaselineOffset,
496 ruler_->sizeHint().height(), 0, 0);
497 ruler_->setGeometry(viewport_->x(), 0,
498 viewport_->width(), viewport_->y());
499 cursorheader_->setGeometry(
500 viewport_->x(),
501 ruler_->sizeHint().height() - cursorheader_->sizeHint().height() / 2,
502 viewport_->width(), cursorheader_->sizeHint().height());
503 header_->setGeometry(0, viewport_->y(),
504 header_->sizeHint().width(), viewport_->height());
d7c0ca4a
JH
505 update_scroll();
506}
507
b3f44329 508void View::paint_label(QPainter &p, const QRect &rect, bool hover)
eae6e30a
JH
509{
510 (void)p;
b3f44329 511 (void)rect;
eae6e30a
JH
512 (void)hover;
513}
514
b3f44329 515QRectF View::label_rect(const QRectF &rect)
eae6e30a 516{
b3f44329 517 (void)rect;
eae6e30a
JH
518 return QRectF();
519}
520
448a72cf
JH
521bool View::add_channels_to_owner(
522 const vector< shared_ptr<sigrok::Channel> > &channels,
523 RowItemOwner *owner, int &offset,
524 unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
525 &signal_map,
526 std::function<bool (shared_ptr<RowItem>)> filter_func)
527{
528 bool any_added = false;
529
530 assert(owner);
531
532 for (const auto &channel : channels)
533 {
534 const auto iter = signal_map.find(channel);
535 if (iter == signal_map.end() ||
536 (filter_func && !filter_func((*iter).second)))
537 continue;
538
539 shared_ptr<RowItem> row_item = (*iter).second;
540 owner->add_child_item(row_item);
541 apply_offset(row_item, offset);
542 signal_map.erase(iter);
543
544 any_added = true;
545 }
546
547 return any_added;
548}
549
550void View::apply_offset(shared_ptr<RowItem> row_item, int &offset) {
551 assert(row_item);
552 const pair<int, int> extents = row_item->v_extents();
553 if (row_item->enabled())
554 offset += -extents.first;
555 row_item->force_to_v_offset(offset);
556 if (row_item->enabled())
557 offset += extents.second;
558}
559
cbd80f64
JH
560bool View::eventFilter(QObject *object, QEvent *event)
561{
562 const QEvent::Type type = event->type();
333d5bbc 563 if (type == QEvent::MouseMove) {
cbd80f64
JH
564
565 const QMouseEvent *const mouse_event = (QMouseEvent*)event;
8dbbc7f0
JH
566 if (object == viewport_)
567 hover_point_ = mouse_event->pos();
568 else if (object == ruler_ || object == cursorheader_)
569 hover_point_ = QPoint(mouse_event->x(), 0);
570 else if (object == header_)
571 hover_point_ = QPoint(0, mouse_event->y());
cbd80f64 572 else
8dbbc7f0 573 hover_point_ = QPoint(-1, -1);
cbd80f64
JH
574
575 hover_point_changed();
576
333d5bbc 577 } else if (type == QEvent::Leave) {
8dbbc7f0 578 hover_point_ = QPoint(-1, -1);
cbd80f64
JH
579 hover_point_changed();
580 }
581
582 return QObject::eventFilter(object, event);
583}
584
cdf7bea7 585bool View::viewportEvent(QEvent *e)
adb4b10c
JH
586{
587 switch(e->type()) {
588 case QEvent::Paint:
589 case QEvent::MouseButtonPress:
590 case QEvent::MouseButtonRelease:
591 case QEvent::MouseButtonDblClick:
592 case QEvent::MouseMove:
593 case QEvent::Wheel:
4b4f1c0d
MC
594 case QEvent::TouchBegin:
595 case QEvent::TouchUpdate:
596 case QEvent::TouchEnd:
adb4b10c
JH
597 return false;
598
599 default:
600 return QAbstractScrollArea::viewportEvent(e);
601 }
602}
603
e314eca4 604void View::resizeEvent(QResizeEvent*)
adb4b10c 605{
d7c0ca4a 606 update_layout();
adb4b10c
JH
607}
608
32218d3e
JH
609void View::appearance_changed(bool label, bool content)
610{
611 if (label)
8dbbc7f0 612 header_->update();
32218d3e 613 if (content)
8dbbc7f0 614 viewport_->update();
32218d3e
JH
615}
616
617void View::extents_changed(bool horz, bool vert)
618{
8dbbc7f0 619 sticky_events_ |=
32218d3e
JH
620 (horz ? SelectableItemHExtentsChanged : 0) |
621 (vert ? SelectableItemVExtentsChanged : 0);
8dbbc7f0 622 lazy_event_handler_.start();
32218d3e
JH
623}
624
b16907d3 625void View::h_scroll_value_changed(int value)
adb4b10c 626{
8dbbc7f0 627 if (updating_scroll_)
528bd8a1
JH
628 return;
629
f25770e2 630 const int range = horizontalScrollBar()->maximum();
333d5bbc 631 if (range < MaxScrollValue)
8dbbc7f0 632 offset_ = scale_ * value;
f25770e2
JH
633 else {
634 double length = 0, offset;
635 get_scroll_layout(length, offset);
8dbbc7f0 636 offset_ = scale_ * length * value / MaxScrollValue;
f25770e2
JH
637 }
638
8dbbc7f0
JH
639 ruler_->update();
640 cursorheader_->update();
641 viewport_->update();
adb4b10c
JH
642}
643
cdf7bea7 644void View::v_scroll_value_changed(int value)
adb4b10c 645{
8dbbc7f0
JH
646 v_offset_ = value;
647 header_->update();
648 viewport_->update();
adb4b10c
JH
649}
650
69dd2b03
JH
651void View::signals_changed()
652{
448a72cf
JH
653 int offset = 0;
654
68b21a71
JH
655 // Populate the traces
656 clear_child_items();
657
8dbbc7f0 658 shared_ptr<sigrok::Device> device = session_.device();
448a72cf
JH
659 assert(device);
660
661 // Collect a set of signals
662 unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> >
663 signal_map;
664
8dbbc7f0
JH
665 shared_lock<shared_mutex> lock(session_.signals_mutex());
666 const vector< shared_ptr<Signal> > &sigs(session_.signals());
448a72cf
JH
667
668 for (const shared_ptr<Signal> &sig : sigs)
669 signal_map[sig->channel()] = sig;
670
671 // Populate channel groups
672 for (auto entry : device->channel_groups())
673 {
674 const shared_ptr<sigrok::ChannelGroup> &group = entry.second;
675
676 if (group->channels().size() <= 1)
677 continue;
678
679 shared_ptr<TraceGroup> trace_group(new TraceGroup());
680 int child_offset = 0;
681 if (add_channels_to_owner(group->channels(),
682 trace_group.get(), child_offset, signal_map))
683 {
684 add_child_item(trace_group);
685 apply_offset(trace_group, offset);
686 }
687 }
688
689 // Add the remaining logic channels
690 shared_ptr<TraceGroup> logic_trace_group(new TraceGroup());
691 int child_offset = 0;
692
693 if (add_channels_to_owner(device->channels(),
694 logic_trace_group.get(), child_offset, signal_map,
695 [](shared_ptr<RowItem> r) -> bool {
696 return dynamic_pointer_cast<LogicSignal>(r) != nullptr;
697 }))
68b21a71 698
448a72cf
JH
699 {
700 add_child_item(logic_trace_group);
701 apply_offset(logic_trace_group, offset);
702 }
703
704 // Add the remaining channels
705 add_channels_to_owner(device->channels(), this, offset, signal_map);
706 assert(signal_map.empty());
707
708 // Add decode signals
68b21a71
JH
709#ifdef ENABLE_DECODE
710 const vector< shared_ptr<DecodeTrace> > decode_sigs(
711 session().get_decode_signals());
448a72cf 712 for (auto s : decode_sigs) {
68b21a71 713 add_child_item(s);
448a72cf 714 apply_offset(s, offset);
ef8311a4 715 }
448a72cf 716#endif
ef8311a4 717
a6c1726e 718 update_layout();
69dd2b03
JH
719}
720
cdf7bea7 721void View::data_updated()
adb4b10c 722{
adb4b10c
JH
723 // Update the scroll bars
724 update_scroll();
725
726 // Repaint the view
8dbbc7f0 727 viewport_->update();
adb4b10c 728}
cdf7bea7 729
ca4ec3ea
JH
730void View::marker_time_changed()
731{
8dbbc7f0
JH
732 cursorheader_->update();
733 viewport_->update();
ca4ec3ea
JH
734}
735
07204819 736void View::on_signals_moved()
54401bbb 737{
07204819
JH
738 update_scroll();
739 signals_moved();
54401bbb
JH
740}
741
32218d3e 742void View::process_sticky_events()
d7c0ca4a 743{
8dbbc7f0 744 if (sticky_events_ & SelectableItemHExtentsChanged)
32218d3e 745 update_layout();
8dbbc7f0 746 if (sticky_events_ & SelectableItemVExtentsChanged)
7ff0145f 747 restack_all_row_items();
32218d3e
JH
748
749 // Clear the sticky events
8dbbc7f0 750 sticky_events_ = 0;
d7c0ca4a
JH
751}
752
33c62f44
JH
753void View::on_hover_point_changed()
754{
aa59d5c2 755 for (shared_ptr<RowItem> r : *this)
eae6e30a 756 r->hover_point_changed();
33c62f44
JH
757}
758
cdf7bea7
JH
759} // namespace view
760} // namespace pv