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