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