]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the PulseView project. | |
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 | ||
21 | #ifdef ENABLE_DECODE | |
22 | #include <libsigrokdecode/libsigrokdecode.h> | |
23 | #endif | |
24 | ||
25 | #include <extdef.h> | |
26 | ||
27 | #include <algorithm> | |
28 | #include <cassert> | |
29 | #include <climits> | |
30 | #include <cmath> | |
31 | #include <iostream> | |
32 | #include <iterator> | |
33 | #include <mutex> | |
34 | #include <unordered_set> | |
35 | ||
36 | #include <boost/archive/text_iarchive.hpp> | |
37 | #include <boost/archive/text_oarchive.hpp> | |
38 | #include <boost/serialization/serialization.hpp> | |
39 | #include <boost/thread/locks.hpp> | |
40 | ||
41 | #include <QApplication> | |
42 | #include <QHBoxLayout> | |
43 | #include <QEvent> | |
44 | #include <QFontMetrics> | |
45 | #include <QMouseEvent> | |
46 | #include <QScrollBar> | |
47 | ||
48 | #include <libsigrokcxx/libsigrokcxx.hpp> | |
49 | ||
50 | #include "analogsignal.hpp" | |
51 | #include "header.hpp" | |
52 | #include "logicsignal.hpp" | |
53 | #include "ruler.hpp" | |
54 | #include "signal.hpp" | |
55 | #include "tracegroup.hpp" | |
56 | #include "triggermarker.hpp" | |
57 | #include "view.hpp" | |
58 | #include "viewport.hpp" | |
59 | ||
60 | #include "pv/session.hpp" | |
61 | #include "pv/devices/device.hpp" | |
62 | #include "pv/data/logic.hpp" | |
63 | #include "pv/data/logicsegment.hpp" | |
64 | #include "pv/util.hpp" | |
65 | ||
66 | #ifdef ENABLE_DECODE | |
67 | #include "decodetrace.hpp" | |
68 | #endif | |
69 | ||
70 | using boost::shared_lock; | |
71 | using boost::shared_mutex; | |
72 | ||
73 | using pv::data::SignalData; | |
74 | using pv::data::Segment; | |
75 | using pv::util::TimeUnit; | |
76 | using pv::util::Timestamp; | |
77 | ||
78 | using std::back_inserter; | |
79 | using std::copy_if; | |
80 | using std::deque; | |
81 | using std::dynamic_pointer_cast; | |
82 | using std::inserter; | |
83 | using std::list; | |
84 | using std::lock_guard; | |
85 | using std::max; | |
86 | using std::make_pair; | |
87 | using std::make_shared; | |
88 | using std::min; | |
89 | using std::pair; | |
90 | using std::set; | |
91 | using std::set_difference; | |
92 | using std::shared_ptr; | |
93 | using std::unordered_map; | |
94 | using std::unordered_set; | |
95 | using std::vector; | |
96 | using std::weak_ptr; | |
97 | ||
98 | namespace pv { | |
99 | namespace views { | |
100 | namespace TraceView { | |
101 | ||
102 | const Timestamp View::MaxScale("1e9"); | |
103 | const Timestamp View::MinScale("1e-12"); | |
104 | ||
105 | const int View::MaxScrollValue = INT_MAX / 2; | |
106 | const int View::MaxViewAutoUpdateRate = 25; // No more than 25 Hz with sticky scrolling | |
107 | ||
108 | const int View::ScaleUnits[3] = {1, 2, 5}; | |
109 | ||
110 | ||
111 | CustomAbstractScrollArea::CustomAbstractScrollArea(QWidget *parent) : | |
112 | QAbstractScrollArea(parent) | |
113 | { | |
114 | } | |
115 | ||
116 | void CustomAbstractScrollArea::setViewportMargins(int left, int top, int right, int bottom) | |
117 | { | |
118 | QAbstractScrollArea::setViewportMargins(left, top, right, bottom); | |
119 | } | |
120 | ||
121 | bool CustomAbstractScrollArea::viewportEvent(QEvent *event) | |
122 | { | |
123 | switch (event->type()) { | |
124 | case QEvent::Paint: | |
125 | case QEvent::MouseButtonPress: | |
126 | case QEvent::MouseButtonRelease: | |
127 | case QEvent::MouseButtonDblClick: | |
128 | case QEvent::MouseMove: | |
129 | case QEvent::Wheel: | |
130 | case QEvent::TouchBegin: | |
131 | case QEvent::TouchUpdate: | |
132 | case QEvent::TouchEnd: | |
133 | return false; | |
134 | default: | |
135 | return QAbstractScrollArea::viewportEvent(event); | |
136 | } | |
137 | } | |
138 | ||
139 | View::View(Session &session, QWidget *parent) : | |
140 | ViewBase(session, parent), | |
141 | viewport_(new Viewport(*this)), | |
142 | ruler_(new Ruler(*this)), | |
143 | header_(new Header(*this)), | |
144 | scrollarea_(this), | |
145 | scale_(1e-3), | |
146 | offset_(0), | |
147 | updating_scroll_(false), | |
148 | sticky_scrolling_(false), // Default setting is set in MainWindow::setup_ui() | |
149 | always_zoom_to_fit_(false), | |
150 | tick_period_(0), | |
151 | tick_prefix_(pv::util::SIPrefix::yocto), | |
152 | tick_precision_(0), | |
153 | time_unit_(util::TimeUnit::Time), | |
154 | show_cursors_(false), | |
155 | cursors_(new CursorPair(*this)), | |
156 | next_flag_text_('A'), | |
157 | trigger_markers_(), | |
158 | hover_point_(-1, -1) | |
159 | { | |
160 | connect(scrollarea_.horizontalScrollBar(), SIGNAL(valueChanged(int)), | |
161 | this, SLOT(h_scroll_value_changed(int))); | |
162 | connect(scrollarea_.verticalScrollBar(), SIGNAL(valueChanged(int)), | |
163 | this, SLOT(v_scroll_value_changed())); | |
164 | ||
165 | connect(header_, SIGNAL(selection_changed()), | |
166 | ruler_, SLOT(clear_selection())); | |
167 | connect(ruler_, SIGNAL(selection_changed()), | |
168 | header_, SLOT(clear_selection())); | |
169 | ||
170 | connect(header_, SIGNAL(selection_changed()), | |
171 | this, SIGNAL(selection_changed())); | |
172 | connect(ruler_, SIGNAL(selection_changed()), | |
173 | this, SIGNAL(selection_changed())); | |
174 | ||
175 | connect(this, SIGNAL(hover_point_changed()), | |
176 | this, SLOT(on_hover_point_changed())); | |
177 | ||
178 | connect(&lazy_event_handler_, SIGNAL(timeout()), | |
179 | this, SLOT(process_sticky_events())); | |
180 | lazy_event_handler_.setSingleShot(true); | |
181 | ||
182 | connect(&delayed_view_updater_, SIGNAL(timeout()), | |
183 | this, SLOT(perform_delayed_view_update())); | |
184 | delayed_view_updater_.setSingleShot(true); | |
185 | delayed_view_updater_.setInterval(1000 / MaxViewAutoUpdateRate); | |
186 | ||
187 | /* To let the scroll area fill up the parent QWidget (this), we need a layout */ | |
188 | QHBoxLayout *layout = new QHBoxLayout(this); | |
189 | setLayout(layout); | |
190 | layout->setContentsMargins(0, 0, 0, 0); | |
191 | layout->addWidget(&scrollarea_); | |
192 | ||
193 | scrollarea_.setViewport(viewport_); | |
194 | ||
195 | viewport_->installEventFilter(this); | |
196 | ruler_->installEventFilter(this); | |
197 | header_->installEventFilter(this); | |
198 | ||
199 | // Trigger the initial event manually. The default device has signals | |
200 | // which were created before this object came into being | |
201 | signals_changed(); | |
202 | ||
203 | // make sure the transparent widgets are on the top | |
204 | ruler_->raise(); | |
205 | header_->raise(); | |
206 | ||
207 | // Update the zoom state | |
208 | calculate_tick_spacing(); | |
209 | } | |
210 | ||
211 | Session& View::session() | |
212 | { | |
213 | return session_; | |
214 | } | |
215 | ||
216 | const Session& View::session() const | |
217 | { | |
218 | return session_; | |
219 | } | |
220 | ||
221 | std::unordered_set< std::shared_ptr<Signal> > View::signals() const | |
222 | { | |
223 | return signals_; | |
224 | } | |
225 | ||
226 | void View::clear_signals() | |
227 | { | |
228 | signals_.clear(); | |
229 | } | |
230 | ||
231 | void View::add_signal(const shared_ptr<Signal> signal) | |
232 | { | |
233 | signals_.insert(signal); | |
234 | } | |
235 | ||
236 | #ifdef ENABLE_DECODE | |
237 | void View::clear_decode_signals() | |
238 | { | |
239 | decode_traces_.clear(); | |
240 | } | |
241 | ||
242 | void View::add_decode_signal(shared_ptr<data::SignalBase> signalbase) | |
243 | { | |
244 | shared_ptr<DecodeTrace> d( | |
245 | new DecodeTrace(session_, signalbase, decode_traces_.size())); | |
246 | decode_traces_.push_back(d); | |
247 | } | |
248 | ||
249 | void View::remove_decode_signal(shared_ptr<data::SignalBase> signalbase) | |
250 | { | |
251 | for (auto i = decode_traces_.begin(); i != decode_traces_.end(); i++) | |
252 | if ((*i)->base() == signalbase) { | |
253 | decode_traces_.erase(i); | |
254 | signals_changed(); | |
255 | return; | |
256 | } | |
257 | } | |
258 | #endif | |
259 | ||
260 | View* View::view() | |
261 | { | |
262 | return this; | |
263 | } | |
264 | ||
265 | const View* View::view() const | |
266 | { | |
267 | return this; | |
268 | } | |
269 | ||
270 | Viewport* View::viewport() | |
271 | { | |
272 | return viewport_; | |
273 | } | |
274 | ||
275 | const Viewport* View::viewport() const | |
276 | { | |
277 | return viewport_; | |
278 | } | |
279 | ||
280 | void View::save_settings(QSettings &settings) const | |
281 | { | |
282 | settings.setValue("scale", scale_); | |
283 | ||
284 | std::stringstream ss; | |
285 | boost::archive::text_oarchive oa(ss); | |
286 | oa << boost::serialization::make_nvp("offset", offset_); | |
287 | settings.setValue("offset", QString::fromStdString(ss.str())); | |
288 | ||
289 | for (shared_ptr<Signal> signal : signals_) { | |
290 | settings.beginGroup(signal->base()->internal_name()); | |
291 | signal->save_settings(settings); | |
292 | settings.endGroup(); | |
293 | } | |
294 | } | |
295 | ||
296 | void View::restore_settings(QSettings &settings) | |
297 | { | |
298 | if (settings.contains("scale")) | |
299 | set_scale(settings.value("scale").toDouble()); | |
300 | ||
301 | if (settings.contains("offset")) { | |
302 | util::Timestamp offset; | |
303 | std::stringstream ss; | |
304 | ss << settings.value("offset").toString().toStdString(); | |
305 | ||
306 | boost::archive::text_iarchive ia(ss); | |
307 | ia >> boost::serialization::make_nvp("offset", offset); | |
308 | ||
309 | set_offset(offset); | |
310 | } | |
311 | ||
312 | for (shared_ptr<Signal> signal : signals_) { | |
313 | settings.beginGroup(signal->base()->internal_name()); | |
314 | signal->restore_settings(settings); | |
315 | settings.endGroup(); | |
316 | } | |
317 | } | |
318 | ||
319 | vector< shared_ptr<TimeItem> > View::time_items() const | |
320 | { | |
321 | const vector<shared_ptr<Flag>> f(flags()); | |
322 | vector<shared_ptr<TimeItem>> items(f.begin(), f.end()); | |
323 | items.push_back(cursors_); | |
324 | items.push_back(cursors_->first()); | |
325 | items.push_back(cursors_->second()); | |
326 | ||
327 | for (auto trigger_marker : trigger_markers_) | |
328 | items.push_back(trigger_marker); | |
329 | ||
330 | return items; | |
331 | } | |
332 | ||
333 | double View::scale() const | |
334 | { | |
335 | return scale_; | |
336 | } | |
337 | ||
338 | void View::set_scale(double scale) | |
339 | { | |
340 | if (scale_ != scale) { | |
341 | scale_ = scale; | |
342 | Q_EMIT scale_changed(); | |
343 | } | |
344 | } | |
345 | ||
346 | const Timestamp& View::offset() const | |
347 | { | |
348 | return offset_; | |
349 | } | |
350 | ||
351 | void View::set_offset(const pv::util::Timestamp& offset) | |
352 | { | |
353 | if (offset_ != offset) { | |
354 | offset_ = offset; | |
355 | Q_EMIT offset_changed(); | |
356 | } | |
357 | } | |
358 | ||
359 | int View::owner_visual_v_offset() const | |
360 | { | |
361 | return -scrollarea_.verticalScrollBar()->sliderPosition(); | |
362 | } | |
363 | ||
364 | void View::set_v_offset(int offset) | |
365 | { | |
366 | scrollarea_.verticalScrollBar()->setSliderPosition(offset); | |
367 | header_->update(); | |
368 | viewport_->update(); | |
369 | } | |
370 | ||
371 | unsigned int View::depth() const | |
372 | { | |
373 | return 0; | |
374 | } | |
375 | ||
376 | pv::util::SIPrefix View::tick_prefix() const | |
377 | { | |
378 | return tick_prefix_; | |
379 | } | |
380 | ||
381 | void View::set_tick_prefix(pv::util::SIPrefix tick_prefix) | |
382 | { | |
383 | if (tick_prefix_ != tick_prefix) { | |
384 | tick_prefix_ = tick_prefix; | |
385 | Q_EMIT tick_prefix_changed(); | |
386 | } | |
387 | } | |
388 | ||
389 | unsigned int View::tick_precision() const | |
390 | { | |
391 | return tick_precision_; | |
392 | } | |
393 | ||
394 | void View::set_tick_precision(unsigned tick_precision) | |
395 | { | |
396 | if (tick_precision_ != tick_precision) { | |
397 | tick_precision_ = tick_precision; | |
398 | Q_EMIT tick_precision_changed(); | |
399 | } | |
400 | } | |
401 | ||
402 | const pv::util::Timestamp& View::tick_period() const | |
403 | { | |
404 | return tick_period_; | |
405 | } | |
406 | ||
407 | void View::set_tick_period(const pv::util::Timestamp& tick_period) | |
408 | { | |
409 | if (tick_period_ != tick_period) { | |
410 | tick_period_ = tick_period; | |
411 | Q_EMIT tick_period_changed(); | |
412 | } | |
413 | } | |
414 | ||
415 | TimeUnit View::time_unit() const | |
416 | { | |
417 | return time_unit_; | |
418 | } | |
419 | ||
420 | void View::set_time_unit(pv::util::TimeUnit time_unit) | |
421 | { | |
422 | if (time_unit_ != time_unit) { | |
423 | time_unit_ = time_unit; | |
424 | Q_EMIT time_unit_changed(); | |
425 | } | |
426 | } | |
427 | ||
428 | void View::zoom(double steps) | |
429 | { | |
430 | zoom(steps, viewport_->width() / 2); | |
431 | } | |
432 | ||
433 | void View::zoom(double steps, int offset) | |
434 | { | |
435 | set_zoom(scale_ * pow(3.0/2.0, -steps), offset); | |
436 | } | |
437 | ||
438 | void View::zoom_fit(bool gui_state) | |
439 | { | |
440 | // Act as one-shot when stopped, toggle along with the GUI otherwise | |
441 | if (session_.get_capture_state() == Session::Stopped) { | |
442 | always_zoom_to_fit_ = false; | |
443 | always_zoom_to_fit_changed(false); | |
444 | } else { | |
445 | always_zoom_to_fit_ = gui_state; | |
446 | always_zoom_to_fit_changed(gui_state); | |
447 | } | |
448 | ||
449 | const pair<Timestamp, Timestamp> extents = get_time_extents(); | |
450 | const Timestamp delta = extents.second - extents.first; | |
451 | if (delta < Timestamp("1e-12")) | |
452 | return; | |
453 | ||
454 | assert(viewport_); | |
455 | const int w = viewport_->width(); | |
456 | if (w <= 0) | |
457 | return; | |
458 | ||
459 | const Timestamp scale = max(min(delta / w, MaxScale), MinScale); | |
460 | set_scale_offset(scale.convert_to<double>(), extents.first); | |
461 | } | |
462 | ||
463 | void View::zoom_one_to_one() | |
464 | { | |
465 | using pv::data::SignalData; | |
466 | ||
467 | // Make a set of all the visible data objects | |
468 | set< shared_ptr<SignalData> > visible_data = get_visible_data(); | |
469 | if (visible_data.empty()) | |
470 | return; | |
471 | ||
472 | assert(viewport_); | |
473 | const int w = viewport_->width(); | |
474 | if (w <= 0) | |
475 | return; | |
476 | ||
477 | set_zoom(1.0 / session_.get_samplerate(), w / 2); | |
478 | } | |
479 | ||
480 | void View::set_scale_offset(double scale, const Timestamp& offset) | |
481 | { | |
482 | // Disable sticky scrolling / always zoom to fit when acquisition runs | |
483 | // and user drags the viewport | |
484 | if ((scale_ == scale) && (offset_ != offset) && | |
485 | (session_.get_capture_state() == Session::Running)) { | |
486 | ||
487 | if (sticky_scrolling_) { | |
488 | sticky_scrolling_ = false; | |
489 | sticky_scrolling_changed(false); | |
490 | } | |
491 | ||
492 | if (always_zoom_to_fit_) { | |
493 | always_zoom_to_fit_ = false; | |
494 | always_zoom_to_fit_changed(false); | |
495 | } | |
496 | } | |
497 | ||
498 | set_scale(scale); | |
499 | set_offset(offset); | |
500 | ||
501 | calculate_tick_spacing(); | |
502 | ||
503 | update_scroll(); | |
504 | ruler_->update(); | |
505 | viewport_->update(); | |
506 | } | |
507 | ||
508 | set< shared_ptr<SignalData> > View::get_visible_data() const | |
509 | { | |
510 | // Make a set of all the visible data objects | |
511 | set< shared_ptr<SignalData> > visible_data; | |
512 | for (const shared_ptr<Signal> sig : signals_) | |
513 | if (sig->enabled()) | |
514 | visible_data.insert(sig->data()); | |
515 | ||
516 | return visible_data; | |
517 | } | |
518 | ||
519 | pair<Timestamp, Timestamp> View::get_time_extents() const | |
520 | { | |
521 | boost::optional<Timestamp> left_time, right_time; | |
522 | const set< shared_ptr<SignalData> > visible_data = get_visible_data(); | |
523 | for (const shared_ptr<SignalData> d : visible_data) { | |
524 | const vector< shared_ptr<Segment> > segments = | |
525 | d->segments(); | |
526 | for (const shared_ptr<Segment> &s : segments) { | |
527 | double samplerate = s->samplerate(); | |
528 | samplerate = (samplerate <= 0.0) ? 1.0 : samplerate; | |
529 | ||
530 | const Timestamp start_time = s->start_time(); | |
531 | left_time = left_time ? | |
532 | min(*left_time, start_time) : | |
533 | start_time; | |
534 | right_time = right_time ? | |
535 | max(*right_time, start_time + d->max_sample_count() / samplerate) : | |
536 | start_time + d->max_sample_count() / samplerate; | |
537 | } | |
538 | } | |
539 | ||
540 | if (!left_time || !right_time) | |
541 | return make_pair(0, 0); | |
542 | ||
543 | assert(*left_time < *right_time); | |
544 | return make_pair(*left_time, *right_time); | |
545 | } | |
546 | ||
547 | void View::enable_sticky_scrolling(bool state) | |
548 | { | |
549 | sticky_scrolling_ = state; | |
550 | } | |
551 | ||
552 | void View::enable_coloured_bg(bool state) | |
553 | { | |
554 | const vector<shared_ptr<TraceTreeItem>> items( | |
555 | list_by_type<TraceTreeItem>()); | |
556 | ||
557 | for (shared_ptr<TraceTreeItem> i : items) { | |
558 | // Can't cast to Trace because it's abstract, so we need to | |
559 | // check for any derived classes individually | |
560 | ||
561 | shared_ptr<AnalogSignal> a = dynamic_pointer_cast<AnalogSignal>(i); | |
562 | if (a) | |
563 | a->set_coloured_bg(state); | |
564 | ||
565 | shared_ptr<LogicSignal> l = dynamic_pointer_cast<LogicSignal>(i); | |
566 | if (l) | |
567 | l->set_coloured_bg(state); | |
568 | ||
569 | #ifdef ENABLE_DECODE | |
570 | shared_ptr<DecodeTrace> d = dynamic_pointer_cast<DecodeTrace>(i); | |
571 | if (d) | |
572 | d->set_coloured_bg(state); | |
573 | #endif | |
574 | } | |
575 | ||
576 | viewport_->update(); | |
577 | } | |
578 | ||
579 | bool View::cursors_shown() const | |
580 | { | |
581 | return show_cursors_; | |
582 | } | |
583 | ||
584 | void View::show_cursors(bool show) | |
585 | { | |
586 | show_cursors_ = show; | |
587 | ruler_->update(); | |
588 | viewport_->update(); | |
589 | } | |
590 | ||
591 | void View::centre_cursors() | |
592 | { | |
593 | const double time_width = scale_ * viewport_->width(); | |
594 | cursors_->first()->set_time(offset_ + time_width * 0.4); | |
595 | cursors_->second()->set_time(offset_ + time_width * 0.6); | |
596 | ruler_->update(); | |
597 | viewport_->update(); | |
598 | } | |
599 | ||
600 | std::shared_ptr<CursorPair> View::cursors() const | |
601 | { | |
602 | return cursors_; | |
603 | } | |
604 | ||
605 | void View::add_flag(const Timestamp& time) | |
606 | { | |
607 | flags_.push_back(shared_ptr<Flag>(new Flag(*this, time, | |
608 | QString("%1").arg(next_flag_text_)))); | |
609 | ||
610 | next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' : | |
611 | (next_flag_text_ + 1); | |
612 | ||
613 | time_item_appearance_changed(true, true); | |
614 | } | |
615 | ||
616 | void View::remove_flag(std::shared_ptr<Flag> flag) | |
617 | { | |
618 | flags_.remove(flag); | |
619 | time_item_appearance_changed(true, true); | |
620 | } | |
621 | ||
622 | vector< std::shared_ptr<Flag> > View::flags() const | |
623 | { | |
624 | vector< std::shared_ptr<Flag> > flags(flags_.begin(), flags_.end()); | |
625 | stable_sort(flags.begin(), flags.end(), | |
626 | [](const shared_ptr<Flag> &a, const shared_ptr<Flag> &b) { | |
627 | return a->time() < b->time(); | |
628 | }); | |
629 | ||
630 | return flags; | |
631 | } | |
632 | ||
633 | const QPoint& View::hover_point() const | |
634 | { | |
635 | return hover_point_; | |
636 | } | |
637 | ||
638 | void View::restack_all_trace_tree_items() | |
639 | { | |
640 | // Make a list of owners that is sorted from deepest first | |
641 | const vector<shared_ptr<TraceTreeItem>> items( | |
642 | list_by_type<TraceTreeItem>()); | |
643 | set< TraceTreeItemOwner* > owners; | |
644 | for (const auto &r : items) | |
645 | owners.insert(r->owner()); | |
646 | vector< TraceTreeItemOwner* > sorted_owners(owners.begin(), owners.end()); | |
647 | sort(sorted_owners.begin(), sorted_owners.end(), | |
648 | [](const TraceTreeItemOwner* a, const TraceTreeItemOwner *b) { | |
649 | return a->depth() > b->depth(); }); | |
650 | ||
651 | // Restack the items recursively | |
652 | for (auto &o : sorted_owners) | |
653 | o->restack_items(); | |
654 | ||
655 | // Re-assign background colors | |
656 | bool next_bgcolour_state = 0; | |
657 | ||
658 | for (auto &o : sorted_owners) | |
659 | next_bgcolour_state = o->reassign_bgcolour_states(next_bgcolour_state); | |
660 | ||
661 | // Animate the items to their destination | |
662 | for (const auto &i : items) | |
663 | i->animate_to_layout_v_offset(); | |
664 | } | |
665 | ||
666 | void View::trigger_event(util::Timestamp location) | |
667 | { | |
668 | trigger_markers_.push_back(shared_ptr<TriggerMarker>( | |
669 | new TriggerMarker(*this, location))); | |
670 | } | |
671 | ||
672 | void View::get_scroll_layout(double &length, Timestamp &offset) const | |
673 | { | |
674 | const pair<Timestamp, Timestamp> extents = get_time_extents(); | |
675 | length = ((extents.second - extents.first) / scale_).convert_to<double>(); | |
676 | offset = offset_ / scale_; | |
677 | } | |
678 | ||
679 | void View::set_zoom(double scale, int offset) | |
680 | { | |
681 | // Reset the "always zoom to fit" feature as the user changed the zoom | |
682 | always_zoom_to_fit_ = false; | |
683 | always_zoom_to_fit_changed(false); | |
684 | ||
685 | const Timestamp cursor_offset = offset_ + scale_ * offset; | |
686 | const Timestamp new_scale = max(min(Timestamp(scale), MaxScale), MinScale); | |
687 | const Timestamp new_offset = cursor_offset - new_scale * offset; | |
688 | set_scale_offset(new_scale.convert_to<double>(), new_offset); | |
689 | } | |
690 | ||
691 | void View::calculate_tick_spacing() | |
692 | { | |
693 | const double SpacingIncrement = 10.0f; | |
694 | const double MinValueSpacing = 40.0f; | |
695 | ||
696 | // Figure out the highest numeric value visible on a label | |
697 | const QSize areaSize = viewport_->size(); | |
698 | const Timestamp max_time = max(fabs(offset_), | |
699 | fabs(offset_ + scale_ * areaSize.width())); | |
700 | ||
701 | double min_width = SpacingIncrement; | |
702 | double label_width, tick_period_width; | |
703 | ||
704 | QFontMetrics m(QApplication::font()); | |
705 | ||
706 | // Copies of the member variables with the same name, used in the calculation | |
707 | // and written back afterwards, so that we don't emit signals all the time | |
708 | // during the calculation. | |
709 | pv::util::Timestamp tick_period = tick_period_; | |
710 | pv::util::SIPrefix tick_prefix = tick_prefix_; | |
711 | unsigned tick_precision = tick_precision_; | |
712 | ||
713 | do { | |
714 | const double min_period = scale_ * min_width; | |
715 | ||
716 | const int order = (int)floorf(log10f(min_period)); | |
717 | const pv::util::Timestamp order_decimal = | |
718 | pow(pv::util::Timestamp(10), order); | |
719 | ||
720 | // Allow for a margin of error so that a scale unit of 1 can be used. | |
721 | // Otherwise, for a SU of 1 the tick period will almost always be below | |
722 | // the min_period by a small amount - and thus skipped in favor of 2. | |
723 | // Note: margin assumes that SU[0] and SU[1] contain the smallest values | |
724 | double tp_margin = (ScaleUnits[0] + ScaleUnits[1]) / 2.0; | |
725 | double tp_with_margin; | |
726 | unsigned int unit = 0; | |
727 | ||
728 | do { | |
729 | tp_with_margin = order_decimal.convert_to<double>() * | |
730 | (ScaleUnits[unit++] + tp_margin); | |
731 | } while (tp_with_margin < min_period && unit < countof(ScaleUnits)); | |
732 | ||
733 | tick_period = order_decimal * ScaleUnits[unit - 1]; | |
734 | tick_prefix = static_cast<pv::util::SIPrefix>( | |
735 | (order - pv::util::exponent(pv::util::SIPrefix::yocto)) / 3); | |
736 | ||
737 | // Precision is the number of fractional digits required, not | |
738 | // taking the prefix into account (and it must never be negative) | |
739 | tick_precision = std::max(ceil(log10(1 / tick_period)).convert_to<int>(), 0); | |
740 | ||
741 | tick_period_width = (tick_period / scale_).convert_to<double>(); | |
742 | ||
743 | const QString label_text = Ruler::format_time_with_distance( | |
744 | tick_period, max_time, tick_prefix, time_unit_, tick_precision); | |
745 | ||
746 | label_width = m.boundingRect(0, 0, INT_MAX, INT_MAX, | |
747 | Qt::AlignLeft | Qt::AlignTop, label_text).width() + | |
748 | MinValueSpacing; | |
749 | ||
750 | min_width += SpacingIncrement; | |
751 | } while (tick_period_width < label_width); | |
752 | ||
753 | set_tick_period(tick_period); | |
754 | set_tick_prefix(tick_prefix); | |
755 | set_tick_precision(tick_precision); | |
756 | } | |
757 | ||
758 | void View::update_scroll() | |
759 | { | |
760 | assert(viewport_); | |
761 | QScrollBar *hscrollbar = scrollarea_.horizontalScrollBar(); | |
762 | QScrollBar *vscrollbar = scrollarea_.verticalScrollBar(); | |
763 | ||
764 | const QSize areaSize = viewport_->size(); | |
765 | ||
766 | // Set the horizontal scroll bar | |
767 | double length = 0; | |
768 | Timestamp offset; | |
769 | get_scroll_layout(length, offset); | |
770 | length = max(length - areaSize.width(), 0.0); | |
771 | ||
772 | int major_tick_distance = (tick_period_ / scale_).convert_to<int>(); | |
773 | ||
774 | hscrollbar->setPageStep(areaSize.width() / 2); | |
775 | hscrollbar->setSingleStep(major_tick_distance); | |
776 | ||
777 | updating_scroll_ = true; | |
778 | ||
779 | if (length < MaxScrollValue) { | |
780 | hscrollbar->setRange(0, length); | |
781 | hscrollbar->setSliderPosition(offset.convert_to<double>()); | |
782 | } else { | |
783 | hscrollbar->setRange(0, MaxScrollValue); | |
784 | hscrollbar->setSliderPosition( | |
785 | (offset_ * MaxScrollValue / (scale_ * length)).convert_to<double>()); | |
786 | } | |
787 | ||
788 | updating_scroll_ = false; | |
789 | ||
790 | // Set the vertical scrollbar | |
791 | vscrollbar->setPageStep(areaSize.height()); | |
792 | vscrollbar->setSingleStep(areaSize.height() / 8); | |
793 | ||
794 | const pair<int, int> extents = v_extents(); | |
795 | ||
796 | // Don't change the scrollbar range if there are no traces | |
797 | if (extents.first != extents.second) | |
798 | vscrollbar->setRange(extents.first - areaSize.height(), | |
799 | extents.second); | |
800 | ||
801 | if (scroll_needs_defaults) | |
802 | set_scroll_default(); | |
803 | } | |
804 | ||
805 | void View::reset_scroll() | |
806 | { | |
807 | scrollarea_.verticalScrollBar()->setRange(0, 0); | |
808 | } | |
809 | ||
810 | void View::set_scroll_default() | |
811 | { | |
812 | assert(viewport_); | |
813 | ||
814 | const QSize areaSize = viewport_->size(); | |
815 | ||
816 | // Special case: when starting up and the window isn't visible yet, | |
817 | // areaSize is [0, 0]. In this case we want to be called again later | |
818 | if (areaSize.height() == 0) { | |
819 | scroll_needs_defaults = true; | |
820 | return; | |
821 | } else { | |
822 | scroll_needs_defaults = false; | |
823 | } | |
824 | ||
825 | const pair<int, int> extents = v_extents(); | |
826 | const int trace_height = extents.second - extents.first; | |
827 | ||
828 | // Do all traces fit in the view? | |
829 | if (areaSize.height() >= trace_height) | |
830 | // Center all traces vertically | |
831 | set_v_offset(extents.first - | |
832 | ((areaSize.height() - trace_height) / 2)); | |
833 | else | |
834 | // Put the first trace at the top, letting the bottom ones overflow | |
835 | set_v_offset(extents.first); | |
836 | } | |
837 | ||
838 | void View::update_layout() | |
839 | { | |
840 | scrollarea_.setViewportMargins( | |
841 | header_->sizeHint().width() - Header::BaselineOffset, | |
842 | ruler_->sizeHint().height(), 0, 0); | |
843 | ruler_->setGeometry(viewport_->x(), 0, | |
844 | viewport_->width(), ruler_->extended_size_hint().height()); | |
845 | header_->setGeometry(0, viewport_->y(), | |
846 | header_->extended_size_hint().width(), viewport_->height()); | |
847 | update_scroll(); | |
848 | } | |
849 | ||
850 | TraceTreeItemOwner* View::find_prevalent_trace_group( | |
851 | const shared_ptr<sigrok::ChannelGroup> &group, | |
852 | const unordered_map<shared_ptr<data::SignalBase>, shared_ptr<Signal> > | |
853 | &signal_map) | |
854 | { | |
855 | assert(group); | |
856 | ||
857 | unordered_set<TraceTreeItemOwner*> owners; | |
858 | vector<TraceTreeItemOwner*> owner_list; | |
859 | ||
860 | // Make a set and a list of all the owners | |
861 | for (const auto &channel : group->channels()) { | |
862 | for (auto entry : signal_map) { | |
863 | if (entry.first->channel() == channel) { | |
864 | TraceTreeItemOwner *const o = (entry.second)->owner(); | |
865 | owner_list.push_back(o); | |
866 | owners.insert(o); | |
867 | } | |
868 | } | |
869 | } | |
870 | ||
871 | // Iterate through the list of owners, and find the most prevalent | |
872 | size_t max_prevalence = 0; | |
873 | TraceTreeItemOwner *prevalent_owner = nullptr; | |
874 | for (TraceTreeItemOwner *owner : owners) { | |
875 | const size_t prevalence = std::count_if( | |
876 | owner_list.begin(), owner_list.end(), | |
877 | [&](TraceTreeItemOwner *o) { return o == owner; }); | |
878 | if (prevalence > max_prevalence) { | |
879 | max_prevalence = prevalence; | |
880 | prevalent_owner = owner; | |
881 | } | |
882 | } | |
883 | ||
884 | return prevalent_owner; | |
885 | } | |
886 | ||
887 | vector< shared_ptr<Trace> > View::extract_new_traces_for_channels( | |
888 | const vector< shared_ptr<sigrok::Channel> > &channels, | |
889 | const unordered_map<shared_ptr<data::SignalBase>, shared_ptr<Signal> > | |
890 | &signal_map, | |
891 | set< shared_ptr<Trace> > &add_list) | |
892 | { | |
893 | vector< shared_ptr<Trace> > filtered_traces; | |
894 | ||
895 | for (const auto &channel : channels) { | |
896 | for (auto entry : signal_map) { | |
897 | if (entry.first->channel() == channel) { | |
898 | shared_ptr<Trace> trace = entry.second; | |
899 | const auto list_iter = add_list.find(trace); | |
900 | if (list_iter == add_list.end()) | |
901 | continue; | |
902 | ||
903 | filtered_traces.push_back(trace); | |
904 | add_list.erase(list_iter); | |
905 | } | |
906 | } | |
907 | } | |
908 | ||
909 | return filtered_traces; | |
910 | } | |
911 | ||
912 | void View::determine_time_unit() | |
913 | { | |
914 | // Check whether we know the sample rate and hence can use time as the unit | |
915 | if (time_unit_ == util::TimeUnit::Samples) { | |
916 | // Check all signals but... | |
917 | for (const shared_ptr<Signal> signal : signals_) { | |
918 | const shared_ptr<SignalData> data = signal->data(); | |
919 | ||
920 | // ...only check first segment of each | |
921 | const vector< shared_ptr<Segment> > segments = data->segments(); | |
922 | if (!segments.empty()) | |
923 | if (segments[0]->samplerate()) { | |
924 | set_time_unit(util::TimeUnit::Time); | |
925 | break; | |
926 | } | |
927 | } | |
928 | } | |
929 | } | |
930 | ||
931 | bool View::eventFilter(QObject *object, QEvent *event) | |
932 | { | |
933 | const QEvent::Type type = event->type(); | |
934 | if (type == QEvent::MouseMove) { | |
935 | ||
936 | const QMouseEvent *const mouse_event = (QMouseEvent*)event; | |
937 | if (object == viewport_) | |
938 | hover_point_ = mouse_event->pos(); | |
939 | else if (object == ruler_) | |
940 | hover_point_ = QPoint(mouse_event->x(), 0); | |
941 | else if (object == header_) | |
942 | hover_point_ = QPoint(0, mouse_event->y()); | |
943 | else | |
944 | hover_point_ = QPoint(-1, -1); | |
945 | ||
946 | hover_point_changed(); | |
947 | ||
948 | } else if (type == QEvent::Leave) { | |
949 | hover_point_ = QPoint(-1, -1); | |
950 | hover_point_changed(); | |
951 | } | |
952 | ||
953 | return QObject::eventFilter(object, event); | |
954 | } | |
955 | ||
956 | void View::resizeEvent(QResizeEvent*) | |
957 | { | |
958 | update_layout(); | |
959 | } | |
960 | ||
961 | void View::row_item_appearance_changed(bool label, bool content) | |
962 | { | |
963 | if (label) | |
964 | header_->update(); | |
965 | if (content) | |
966 | viewport_->update(); | |
967 | } | |
968 | ||
969 | void View::time_item_appearance_changed(bool label, bool content) | |
970 | { | |
971 | if (label) | |
972 | ruler_->update(); | |
973 | if (content) | |
974 | viewport_->update(); | |
975 | } | |
976 | ||
977 | void View::extents_changed(bool horz, bool vert) | |
978 | { | |
979 | sticky_events_ |= | |
980 | (horz ? TraceTreeItemHExtentsChanged : 0) | | |
981 | (vert ? TraceTreeItemVExtentsChanged : 0); | |
982 | lazy_event_handler_.start(); | |
983 | } | |
984 | ||
985 | void View::h_scroll_value_changed(int value) | |
986 | { | |
987 | if (updating_scroll_) | |
988 | return; | |
989 | ||
990 | // Disable sticky scrolling when user moves the horizontal scroll bar | |
991 | // during a running acquisition | |
992 | if (sticky_scrolling_ && (session_.get_capture_state() == Session::Running)) { | |
993 | sticky_scrolling_ = false; | |
994 | sticky_scrolling_changed(false); | |
995 | } | |
996 | ||
997 | const int range = scrollarea_.horizontalScrollBar()->maximum(); | |
998 | if (range < MaxScrollValue) | |
999 | set_offset(scale_ * value); | |
1000 | else { | |
1001 | double length = 0; | |
1002 | Timestamp offset; | |
1003 | get_scroll_layout(length, offset); | |
1004 | set_offset(scale_ * length * value / MaxScrollValue); | |
1005 | } | |
1006 | ||
1007 | ruler_->update(); | |
1008 | viewport_->update(); | |
1009 | } | |
1010 | ||
1011 | void View::v_scroll_value_changed() | |
1012 | { | |
1013 | header_->update(); | |
1014 | viewport_->update(); | |
1015 | } | |
1016 | ||
1017 | void View::signals_changed() | |
1018 | { | |
1019 | using sigrok::Channel; | |
1020 | ||
1021 | vector< shared_ptr<Channel> > channels; | |
1022 | shared_ptr<sigrok::Device> sr_dev; | |
1023 | ||
1024 | // Do we need to set the vertical scrollbar to its default position later? | |
1025 | // We do if there are no traces, i.e. the scroll bar has no range set | |
1026 | bool reset_scrollbar = | |
1027 | (scrollarea_.verticalScrollBar()->minimum() == | |
1028 | scrollarea_.verticalScrollBar()->maximum()); | |
1029 | ||
1030 | if (!session_.device()) { | |
1031 | reset_scroll(); | |
1032 | signals_.clear(); | |
1033 | } else { | |
1034 | sr_dev = session_.device()->device(); | |
1035 | assert(sr_dev); | |
1036 | channels = sr_dev->channels(); | |
1037 | } | |
1038 | ||
1039 | vector< shared_ptr<TraceTreeItem> > new_top_level_items; | |
1040 | ||
1041 | // Make a list of traces that are being added, and a list of traces | |
1042 | // that are being removed | |
1043 | const vector<shared_ptr<Trace>> prev_trace_list = list_by_type<Trace>(); | |
1044 | const set<shared_ptr<Trace>> prev_traces( | |
1045 | prev_trace_list.begin(), prev_trace_list.end()); | |
1046 | ||
1047 | set< shared_ptr<Trace> > traces(signals_.begin(), signals_.end()); | |
1048 | ||
1049 | #ifdef ENABLE_DECODE | |
1050 | traces.insert(decode_traces_.begin(), decode_traces_.end()); | |
1051 | #endif | |
1052 | ||
1053 | set< shared_ptr<Trace> > add_traces; | |
1054 | set_difference(traces.begin(), traces.end(), | |
1055 | prev_traces.begin(), prev_traces.end(), | |
1056 | inserter(add_traces, add_traces.begin())); | |
1057 | ||
1058 | set< shared_ptr<Trace> > remove_traces; | |
1059 | set_difference(prev_traces.begin(), prev_traces.end(), | |
1060 | traces.begin(), traces.end(), | |
1061 | inserter(remove_traces, remove_traces.begin())); | |
1062 | ||
1063 | // Make a look-up table of sigrok Channels to pulseview Signals | |
1064 | unordered_map<shared_ptr<data::SignalBase>, shared_ptr<Signal> > | |
1065 | signal_map; | |
1066 | for (const shared_ptr<Signal> &sig : signals_) | |
1067 | signal_map[sig->base()] = sig; | |
1068 | ||
1069 | // Populate channel groups | |
1070 | if (sr_dev) | |
1071 | for (auto entry : sr_dev->channel_groups()) { | |
1072 | const shared_ptr<sigrok::ChannelGroup> &group = entry.second; | |
1073 | ||
1074 | if (group->channels().size() <= 1) | |
1075 | continue; | |
1076 | ||
1077 | // Find best trace group to add to | |
1078 | TraceTreeItemOwner *owner = find_prevalent_trace_group( | |
1079 | group, signal_map); | |
1080 | ||
1081 | // If there is no trace group, create one | |
1082 | shared_ptr<TraceGroup> new_trace_group; | |
1083 | if (!owner) { | |
1084 | new_trace_group.reset(new TraceGroup()); | |
1085 | owner = new_trace_group.get(); | |
1086 | } | |
1087 | ||
1088 | // Extract traces for the trace group, removing them from | |
1089 | // the add list | |
1090 | const vector< shared_ptr<Trace> > new_traces_in_group = | |
1091 | extract_new_traces_for_channels(group->channels(), | |
1092 | signal_map, add_traces); | |
1093 | ||
1094 | // Add the traces to the group | |
1095 | const pair<int, int> prev_v_extents = owner->v_extents(); | |
1096 | int offset = prev_v_extents.second - prev_v_extents.first; | |
1097 | for (shared_ptr<Trace> trace : new_traces_in_group) { | |
1098 | assert(trace); | |
1099 | owner->add_child_item(trace); | |
1100 | ||
1101 | const pair<int, int> extents = trace->v_extents(); | |
1102 | if (trace->enabled()) | |
1103 | offset += -extents.first; | |
1104 | trace->force_to_v_offset(offset); | |
1105 | if (trace->enabled()) | |
1106 | offset += extents.second; | |
1107 | } | |
1108 | ||
1109 | if (new_trace_group) { | |
1110 | // Assign proper vertical offsets to each channel in the group | |
1111 | new_trace_group->restack_items(); | |
1112 | ||
1113 | // If this is a new group, enqueue it in the new top level | |
1114 | // items list | |
1115 | if (!new_traces_in_group.empty()) | |
1116 | new_top_level_items.push_back(new_trace_group); | |
1117 | } | |
1118 | } | |
1119 | ||
1120 | // Enqueue the remaining logic channels in a group | |
1121 | vector< shared_ptr<Channel> > logic_channels; | |
1122 | copy_if(channels.begin(), channels.end(), back_inserter(logic_channels), | |
1123 | [](const shared_ptr<Channel>& c) { | |
1124 | return c->type() == sigrok::ChannelType::LOGIC; }); | |
1125 | ||
1126 | const vector< shared_ptr<Trace> > non_grouped_logic_signals = | |
1127 | extract_new_traces_for_channels(logic_channels, signal_map, add_traces); | |
1128 | ||
1129 | if (non_grouped_logic_signals.size() > 0) { | |
1130 | const shared_ptr<TraceGroup> non_grouped_trace_group( | |
1131 | make_shared<TraceGroup>()); | |
1132 | for (shared_ptr<Trace> trace : non_grouped_logic_signals) | |
1133 | non_grouped_trace_group->add_child_item(trace); | |
1134 | ||
1135 | non_grouped_trace_group->restack_items(); | |
1136 | new_top_level_items.push_back(non_grouped_trace_group); | |
1137 | } | |
1138 | ||
1139 | // Enqueue the remaining channels as free ungrouped traces | |
1140 | const vector< shared_ptr<Trace> > new_top_level_signals = | |
1141 | extract_new_traces_for_channels(channels, signal_map, add_traces); | |
1142 | new_top_level_items.insert(new_top_level_items.end(), | |
1143 | new_top_level_signals.begin(), new_top_level_signals.end()); | |
1144 | ||
1145 | // Enqueue any remaining traces i.e. decode traces | |
1146 | new_top_level_items.insert(new_top_level_items.end(), | |
1147 | add_traces.begin(), add_traces.end()); | |
1148 | ||
1149 | // Remove any removed traces | |
1150 | for (shared_ptr<Trace> trace : remove_traces) { | |
1151 | TraceTreeItemOwner *const owner = trace->owner(); | |
1152 | assert(owner); | |
1153 | owner->remove_child_item(trace); | |
1154 | } | |
1155 | ||
1156 | // Remove any empty trace groups | |
1157 | for (shared_ptr<TraceGroup> group : list_by_type<TraceGroup>()) | |
1158 | if (group->child_items().size() == 0) { | |
1159 | remove_child_item(group); | |
1160 | group.reset(); | |
1161 | } | |
1162 | ||
1163 | // Add and position the pending top levels items | |
1164 | for (auto item : new_top_level_items) { | |
1165 | add_child_item(item); | |
1166 | ||
1167 | // Position the item after the last item or at the top if there is none | |
1168 | int offset = v_extents().second; | |
1169 | const pair<int, int> extents = item->v_extents(); | |
1170 | ||
1171 | if (item->enabled()) | |
1172 | offset += -extents.first; | |
1173 | ||
1174 | item->force_to_v_offset(offset); | |
1175 | ||
1176 | if (item->enabled()) | |
1177 | offset += extents.second; | |
1178 | } | |
1179 | ||
1180 | update_layout(); | |
1181 | ||
1182 | header_->update(); | |
1183 | viewport_->update(); | |
1184 | ||
1185 | if (reset_scrollbar) | |
1186 | set_scroll_default(); | |
1187 | } | |
1188 | ||
1189 | void View::capture_state_updated(int state) | |
1190 | { | |
1191 | if (state == Session::Running) { | |
1192 | set_time_unit(util::TimeUnit::Samples); | |
1193 | ||
1194 | trigger_markers_.clear(); | |
1195 | } | |
1196 | ||
1197 | if (state == Session::Stopped) { | |
1198 | // After acquisition has stopped we need to re-calculate the ticks once | |
1199 | // as it's otherwise done when the user pans or zooms, which is too late | |
1200 | calculate_tick_spacing(); | |
1201 | ||
1202 | // Reset "always zoom to fit", the acquisition has stopped | |
1203 | if (always_zoom_to_fit_) { | |
1204 | always_zoom_to_fit_ = false; | |
1205 | always_zoom_to_fit_changed(false); | |
1206 | } | |
1207 | } | |
1208 | } | |
1209 | ||
1210 | void View::data_updated() | |
1211 | { | |
1212 | if (always_zoom_to_fit_ || sticky_scrolling_) { | |
1213 | if (!delayed_view_updater_.isActive()) | |
1214 | delayed_view_updater_.start(); | |
1215 | } else { | |
1216 | determine_time_unit(); | |
1217 | update_scroll(); | |
1218 | ruler_->update(); | |
1219 | viewport_->update(); | |
1220 | } | |
1221 | } | |
1222 | ||
1223 | void View::perform_delayed_view_update() | |
1224 | { | |
1225 | if (always_zoom_to_fit_) | |
1226 | zoom_fit(true); | |
1227 | ||
1228 | if (sticky_scrolling_) { | |
1229 | // Make right side of the view sticky | |
1230 | double length = 0; | |
1231 | Timestamp offset; | |
1232 | get_scroll_layout(length, offset); | |
1233 | ||
1234 | const QSize areaSize = viewport_->size(); | |
1235 | length = max(length - areaSize.width(), 0.0); | |
1236 | ||
1237 | set_offset(scale_ * length); | |
1238 | } | |
1239 | ||
1240 | determine_time_unit(); | |
1241 | update_scroll(); | |
1242 | ruler_->update(); | |
1243 | viewport_->update(); | |
1244 | } | |
1245 | ||
1246 | void View::process_sticky_events() | |
1247 | { | |
1248 | if (sticky_events_ & TraceTreeItemHExtentsChanged) | |
1249 | update_layout(); | |
1250 | if (sticky_events_ & TraceTreeItemVExtentsChanged) { | |
1251 | restack_all_trace_tree_items(); | |
1252 | update_scroll(); | |
1253 | } | |
1254 | ||
1255 | // Clear the sticky events | |
1256 | sticky_events_ = 0; | |
1257 | } | |
1258 | ||
1259 | void View::on_hover_point_changed() | |
1260 | { | |
1261 | const vector<shared_ptr<TraceTreeItem>> trace_tree_items( | |
1262 | list_by_type<TraceTreeItem>()); | |
1263 | for (shared_ptr<TraceTreeItem> r : trace_tree_items) | |
1264 | r->hover_point_changed(); | |
1265 | } | |
1266 | ||
1267 | } // namespace TraceView | |
1268 | } // namespace views | |
1269 | } // namespace pv |