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