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