]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #ifdef ENABLE_DECODE | |
21 | #include <libsigrokdecode/libsigrokdecode.h> | |
22 | #endif | |
23 | ||
24 | #include <extdef.h> | |
25 | ||
26 | #include <algorithm> | |
27 | #include <cassert> | |
28 | #include <climits> | |
29 | #include <cmath> | |
30 | #include <iostream> | |
31 | #include <iterator> | |
32 | #include <unordered_set> | |
33 | ||
34 | #include <boost/archive/text_iarchive.hpp> | |
35 | #include <boost/archive/text_oarchive.hpp> | |
36 | #include <boost/serialization/serialization.hpp> | |
37 | ||
38 | #include <QApplication> | |
39 | #include <QEvent> | |
40 | #include <QFontMetrics> | |
41 | #include <QMenu> | |
42 | #include <QMouseEvent> | |
43 | #include <QScrollBar> | |
44 | #include <QVBoxLayout> | |
45 | ||
46 | #include <libsigrokcxx/libsigrokcxx.hpp> | |
47 | ||
48 | #include "analogsignal.hpp" | |
49 | #include "header.hpp" | |
50 | #include "logicsignal.hpp" | |
51 | #include "ruler.hpp" | |
52 | #include "signal.hpp" | |
53 | #include "tracegroup.hpp" | |
54 | #include "triggermarker.hpp" | |
55 | #include "view.hpp" | |
56 | #include "viewport.hpp" | |
57 | ||
58 | #include "pv/data/logic.hpp" | |
59 | #include "pv/data/logicsegment.hpp" | |
60 | #include "pv/devices/device.hpp" | |
61 | #include "pv/globalsettings.hpp" | |
62 | #include "pv/session.hpp" | |
63 | #include "pv/util.hpp" | |
64 | ||
65 | #ifdef ENABLE_DECODE | |
66 | #include "decodetrace.hpp" | |
67 | #endif | |
68 | ||
69 | using pv::data::SignalData; | |
70 | using pv::data::Segment; | |
71 | using pv::util::TimeUnit; | |
72 | using pv::util::Timestamp; | |
73 | ||
74 | using std::back_inserter; | |
75 | using std::copy_if; | |
76 | using std::count_if; | |
77 | using std::inserter; | |
78 | using std::max; | |
79 | using std::make_pair; | |
80 | using std::make_shared; | |
81 | using std::min; | |
82 | using std::numeric_limits; | |
83 | using std::pair; | |
84 | using std::set; | |
85 | using std::set_difference; | |
86 | using std::shared_ptr; | |
87 | using std::stringstream; | |
88 | using std::unordered_map; | |
89 | using std::unordered_set; | |
90 | using std::vector; | |
91 | ||
92 | namespace pv { | |
93 | namespace views { | |
94 | namespace trace { | |
95 | ||
96 | const Timestamp View::MaxScale("1e9"); | |
97 | const Timestamp View::MinScale("1e-12"); | |
98 | ||
99 | const int View::MaxScrollValue = INT_MAX / 2; | |
100 | ||
101 | const int View::ScaleUnits[3] = {1, 2, 5}; | |
102 | ||
103 | ||
104 | CustomScrollArea::CustomScrollArea(QWidget *parent) : | |
105 | QAbstractScrollArea(parent) | |
106 | { | |
107 | } | |
108 | ||
109 | bool CustomScrollArea::viewportEvent(QEvent *event) | |
110 | { | |
111 | switch (event->type()) { | |
112 | case QEvent::Paint: | |
113 | case QEvent::MouseButtonPress: | |
114 | case QEvent::MouseButtonRelease: | |
115 | case QEvent::MouseButtonDblClick: | |
116 | case QEvent::MouseMove: | |
117 | case QEvent::Wheel: | |
118 | case QEvent::TouchBegin: | |
119 | case QEvent::TouchUpdate: | |
120 | case QEvent::TouchEnd: | |
121 | return false; | |
122 | default: | |
123 | return QAbstractScrollArea::viewportEvent(event); | |
124 | } | |
125 | } | |
126 | ||
127 | View::View(Session &session, bool is_main_view, QWidget *parent) : | |
128 | ViewBase(session, is_main_view, parent), | |
129 | ||
130 | // Note: Place defaults in View::reset_view_state(), not here | |
131 | splitter_(new QSplitter()), | |
132 | header_was_shrunk_(false), // The splitter remains unchanged after a reset, so this goes here | |
133 | sticky_scrolling_(false), // Default setting is set in MainWindow::setup_ui() | |
134 | scroll_needs_defaults_(true) | |
135 | { | |
136 | QVBoxLayout *root_layout = new QVBoxLayout(this); | |
137 | root_layout->setContentsMargins(0, 0, 0, 0); | |
138 | root_layout->addWidget(splitter_); | |
139 | ||
140 | viewport_ = new Viewport(*this); | |
141 | scrollarea_ = new CustomScrollArea(splitter_); | |
142 | scrollarea_->setViewport(viewport_); | |
143 | scrollarea_->setFrameShape(QFrame::NoFrame); | |
144 | ||
145 | ruler_ = new Ruler(*this); | |
146 | ||
147 | header_ = new Header(*this); | |
148 | header_->setMinimumWidth(10); // So that the arrow tips show at least | |
149 | ||
150 | // We put the header into a simple layout so that we can add the top margin, | |
151 | // allowing us to make it line up with the bottom of the ruler | |
152 | QWidget *header_container = new QWidget(); | |
153 | header_container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
154 | QVBoxLayout *header_layout = new QVBoxLayout(header_container); | |
155 | header_layout->setContentsMargins(0, ruler_->sizeHint().height(), 0, 0); | |
156 | header_layout->addWidget(header_); | |
157 | ||
158 | // To let the ruler and scrollarea be on the same split pane, we need a layout | |
159 | QWidget *trace_container = new QWidget(); | |
160 | trace_container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
161 | QVBoxLayout *trace_layout = new QVBoxLayout(trace_container); | |
162 | trace_layout->setSpacing(0); // We don't want space between the ruler and scrollarea | |
163 | trace_layout->setContentsMargins(0, 0, 0, 0); | |
164 | trace_layout->addWidget(ruler_); | |
165 | trace_layout->addWidget(scrollarea_); | |
166 | ||
167 | splitter_->addWidget(header_container); | |
168 | splitter_->addWidget(trace_container); | |
169 | splitter_->setHandleWidth(1); // Don't show a visible rubber band | |
170 | splitter_->setCollapsible(0, false); // Prevent the header from collapsing | |
171 | splitter_->setCollapsible(1, false); // Prevent the traces from collapsing | |
172 | splitter_->setStretchFactor(0, 0); // Prevent the panes from being resized | |
173 | splitter_->setStretchFactor(1, 1); // when the entire view is resized | |
174 | splitter_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
175 | ||
176 | viewport_->installEventFilter(this); | |
177 | ruler_->installEventFilter(this); | |
178 | header_->installEventFilter(this); | |
179 | ||
180 | // Set up settings and event handlers | |
181 | GlobalSettings settings; | |
182 | colored_bg_ = settings.value(GlobalSettings::Key_View_ColoredBG).toBool(); | |
183 | snap_distance_ = settings.value(GlobalSettings::Key_View_SnapDistance).toInt(); | |
184 | ||
185 | GlobalSettings::add_change_handler(this); | |
186 | ||
187 | connect(scrollarea_->horizontalScrollBar(), SIGNAL(valueChanged(int)), | |
188 | this, SLOT(h_scroll_value_changed(int))); | |
189 | connect(scrollarea_->verticalScrollBar(), SIGNAL(valueChanged(int)), | |
190 | this, SLOT(v_scroll_value_changed())); | |
191 | ||
192 | connect(header_, SIGNAL(selection_changed()), | |
193 | ruler_, SLOT(clear_selection())); | |
194 | connect(ruler_, SIGNAL(selection_changed()), | |
195 | header_, SLOT(clear_selection())); | |
196 | ||
197 | connect(header_, SIGNAL(selection_changed()), | |
198 | this, SIGNAL(selection_changed())); | |
199 | connect(ruler_, SIGNAL(selection_changed()), | |
200 | this, SIGNAL(selection_changed())); | |
201 | ||
202 | connect(splitter_, SIGNAL(splitterMoved(int, int)), | |
203 | this, SLOT(on_splitter_moved())); | |
204 | ||
205 | connect(&lazy_event_handler_, SIGNAL(timeout()), | |
206 | this, SLOT(process_sticky_events())); | |
207 | lazy_event_handler_.setSingleShot(true); | |
208 | ||
209 | // Trigger the initial event manually. The default device has signals | |
210 | // which were created before this object came into being | |
211 | signals_changed(); | |
212 | ||
213 | // make sure the transparent widgets are on the top | |
214 | ruler_->raise(); | |
215 | header_->raise(); | |
216 | ||
217 | reset_view_state(); | |
218 | } | |
219 | ||
220 | View::~View() | |
221 | { | |
222 | GlobalSettings::remove_change_handler(this); | |
223 | } | |
224 | ||
225 | void View::reset_view_state() | |
226 | { | |
227 | ViewBase::reset_view_state(); | |
228 | ||
229 | segment_display_mode_ = Trace::ShowLastSegmentOnly; | |
230 | segment_selectable_ = false; | |
231 | scale_ = 1e-3; | |
232 | offset_ = 0; | |
233 | ruler_offset_ = 0; | |
234 | updating_scroll_ = false; | |
235 | settings_restored_ = false; | |
236 | always_zoom_to_fit_ = false; | |
237 | tick_period_ = 0; | |
238 | tick_prefix_ = pv::util::SIPrefix::yocto; | |
239 | tick_precision_ = 0; | |
240 | time_unit_ = util::TimeUnit::Time; | |
241 | show_cursors_ = false; | |
242 | cursors_ = make_shared<CursorPair>(*this); | |
243 | next_flag_text_ = 'A'; | |
244 | trigger_markers_.clear(); | |
245 | hover_widget_ = nullptr; | |
246 | hover_point_ = QPoint(-1, -1); | |
247 | scroll_needs_defaults_ = true; | |
248 | saved_v_offset_ = 0; | |
249 | scale_at_acq_start_ = 0; | |
250 | offset_at_acq_start_ = 0; | |
251 | suppress_zoom_to_fit_after_acq_ = false; | |
252 | ||
253 | show_cursors_ = false; | |
254 | cursor_state_changed(show_cursors_); | |
255 | flags_.clear(); | |
256 | ||
257 | // Update the zoom state | |
258 | calculate_tick_spacing(); | |
259 | ||
260 | // Make sure the standard bar's segment selector is in sync | |
261 | set_segment_display_mode(segment_display_mode_); | |
262 | } | |
263 | ||
264 | Session& View::session() | |
265 | { | |
266 | return session_; | |
267 | } | |
268 | ||
269 | const Session& View::session() const | |
270 | { | |
271 | return session_; | |
272 | } | |
273 | ||
274 | unordered_set< shared_ptr<Signal> > View::signals() const | |
275 | { | |
276 | return signals_; | |
277 | } | |
278 | ||
279 | void View::clear_signals() | |
280 | { | |
281 | ViewBase::clear_signalbases(); | |
282 | signals_.clear(); | |
283 | } | |
284 | ||
285 | void View::add_signal(const shared_ptr<Signal> signal) | |
286 | { | |
287 | ViewBase::add_signalbase(signal->base()); | |
288 | signals_.insert(signal); | |
289 | ||
290 | signal->set_segment_display_mode(segment_display_mode_); | |
291 | signal->set_current_segment(current_segment_); | |
292 | ||
293 | connect(signal->base().get(), SIGNAL(name_changed(const QString&)), | |
294 | this, SLOT(on_signal_name_changed())); | |
295 | } | |
296 | ||
297 | #ifdef ENABLE_DECODE | |
298 | void View::clear_decode_signals() | |
299 | { | |
300 | decode_traces_.clear(); | |
301 | } | |
302 | ||
303 | void View::add_decode_signal(shared_ptr<data::DecodeSignal> signal) | |
304 | { | |
305 | shared_ptr<DecodeTrace> d( | |
306 | new DecodeTrace(session_, signal, decode_traces_.size())); | |
307 | decode_traces_.push_back(d); | |
308 | ||
309 | d->set_segment_display_mode(segment_display_mode_); | |
310 | d->set_current_segment(current_segment_); | |
311 | ||
312 | connect(signal.get(), SIGNAL(name_changed(const QString&)), | |
313 | this, SLOT(on_signal_name_changed())); | |
314 | } | |
315 | ||
316 | void View::remove_decode_signal(shared_ptr<data::DecodeSignal> signal) | |
317 | { | |
318 | for (auto i = decode_traces_.begin(); i != decode_traces_.end(); i++) | |
319 | if ((*i)->base() == signal) { | |
320 | decode_traces_.erase(i); | |
321 | signals_changed(); | |
322 | return; | |
323 | } | |
324 | } | |
325 | #endif | |
326 | ||
327 | shared_ptr<Signal> View::get_signal_under_mouse_cursor() const | |
328 | { | |
329 | return signal_under_mouse_cursor_; | |
330 | } | |
331 | ||
332 | View* View::view() | |
333 | { | |
334 | return this; | |
335 | } | |
336 | ||
337 | const View* View::view() const | |
338 | { | |
339 | return this; | |
340 | } | |
341 | ||
342 | Viewport* View::viewport() | |
343 | { | |
344 | return viewport_; | |
345 | } | |
346 | ||
347 | const Viewport* View::viewport() const | |
348 | { | |
349 | return viewport_; | |
350 | } | |
351 | ||
352 | const Ruler* View::ruler() const | |
353 | { | |
354 | return ruler_; | |
355 | } | |
356 | ||
357 | void View::save_settings(QSettings &settings) const | |
358 | { | |
359 | settings.setValue("scale", scale_); | |
360 | settings.setValue("v_offset", | |
361 | scrollarea_->verticalScrollBar()->sliderPosition()); | |
362 | ||
363 | settings.setValue("splitter_state", splitter_->saveState()); | |
364 | settings.setValue("segment_display_mode", segment_display_mode_); | |
365 | ||
366 | { | |
367 | stringstream ss; | |
368 | boost::archive::text_oarchive oa(ss); | |
369 | oa << boost::serialization::make_nvp("offset", offset_); | |
370 | settings.setValue("offset", QString::fromStdString(ss.str())); | |
371 | } | |
372 | ||
373 | for (const shared_ptr<Signal>& signal : signals_) { | |
374 | settings.beginGroup(signal->base()->internal_name()); | |
375 | signal->save_settings(settings); | |
376 | settings.endGroup(); | |
377 | } | |
378 | } | |
379 | ||
380 | void View::restore_settings(QSettings &settings) | |
381 | { | |
382 | // Note: It is assumed that this function is only called once, | |
383 | // immediately after restoring a previous session. | |
384 | ||
385 | if (settings.contains("scale")) | |
386 | set_scale(settings.value("scale").toDouble()); | |
387 | ||
388 | if (settings.contains("offset")) { | |
389 | util::Timestamp offset; | |
390 | stringstream ss; | |
391 | ss << settings.value("offset").toString().toStdString(); | |
392 | ||
393 | try { | |
394 | boost::archive::text_iarchive ia(ss); | |
395 | ia >> boost::serialization::make_nvp("offset", offset); | |
396 | // This also updates ruler_offset_ | |
397 | set_offset(offset); | |
398 | } catch (boost::archive::archive_exception&) { | |
399 | qDebug() << "Could not restore the view offset"; | |
400 | } | |
401 | } | |
402 | ||
403 | if (settings.contains("splitter_state")) | |
404 | splitter_->restoreState(settings.value("splitter_state").toByteArray()); | |
405 | ||
406 | if (settings.contains("segment_display_mode")) | |
407 | set_segment_display_mode( | |
408 | (Trace::SegmentDisplayMode)(settings.value("segment_display_mode").toInt())); | |
409 | ||
410 | for (shared_ptr<Signal> signal : signals_) { | |
411 | settings.beginGroup(signal->base()->internal_name()); | |
412 | signal->restore_settings(settings); | |
413 | settings.endGroup(); | |
414 | } | |
415 | ||
416 | if (settings.contains("v_offset")) { | |
417 | saved_v_offset_ = settings.value("v_offset").toInt(); | |
418 | set_v_offset(saved_v_offset_); | |
419 | scroll_needs_defaults_ = false; | |
420 | // Note: see eventFilter() for additional information | |
421 | } | |
422 | ||
423 | settings_restored_ = true; | |
424 | suppress_zoom_to_fit_after_acq_ = true; | |
425 | ||
426 | // Update the ruler so that it uses the new scale | |
427 | calculate_tick_spacing(); | |
428 | } | |
429 | ||
430 | vector< shared_ptr<TimeItem> > View::time_items() const | |
431 | { | |
432 | const vector<shared_ptr<Flag>> f(flags()); | |
433 | vector<shared_ptr<TimeItem>> items(f.begin(), f.end()); | |
434 | ||
435 | if (cursors_) { | |
436 | items.push_back(cursors_); | |
437 | items.push_back(cursors_->first()); | |
438 | items.push_back(cursors_->second()); | |
439 | } | |
440 | ||
441 | for (auto& trigger_marker : trigger_markers_) | |
442 | items.push_back(trigger_marker); | |
443 | ||
444 | return items; | |
445 | } | |
446 | ||
447 | double View::scale() const | |
448 | { | |
449 | return scale_; | |
450 | } | |
451 | ||
452 | void View::set_scale(double scale) | |
453 | { | |
454 | if (scale_ != scale) { | |
455 | scale_ = scale; | |
456 | scale_changed(); | |
457 | } | |
458 | } | |
459 | ||
460 | void View::set_offset(const pv::util::Timestamp& offset, bool force_update) | |
461 | { | |
462 | if ((offset_ != offset) || force_update) { | |
463 | offset_ = offset; | |
464 | ruler_offset_ = offset_ + zero_offset_; | |
465 | offset_changed(); | |
466 | } | |
467 | } | |
468 | ||
469 | const Timestamp& View::offset() const | |
470 | { | |
471 | return offset_; | |
472 | } | |
473 | ||
474 | const Timestamp& View::ruler_offset() const | |
475 | { | |
476 | return ruler_offset_; | |
477 | } | |
478 | ||
479 | void View::set_zero_position(const pv::util::Timestamp& position) | |
480 | { | |
481 | zero_offset_ = -position; | |
482 | ||
483 | // Force an immediate update of the offsets | |
484 | set_offset(offset_, true); | |
485 | ruler_->update(); | |
486 | } | |
487 | ||
488 | void View::reset_zero_position() | |
489 | { | |
490 | zero_offset_ = 0; | |
491 | ||
492 | // Force an immediate update of the offsets | |
493 | set_offset(offset_, true); | |
494 | ruler_->update(); | |
495 | } | |
496 | ||
497 | pv::util::Timestamp View::zero_offset() const | |
498 | { | |
499 | return zero_offset_; | |
500 | } | |
501 | ||
502 | int View::owner_visual_v_offset() const | |
503 | { | |
504 | return -scrollarea_->verticalScrollBar()->sliderPosition(); | |
505 | } | |
506 | ||
507 | void View::set_v_offset(int offset) | |
508 | { | |
509 | scrollarea_->verticalScrollBar()->setSliderPosition(offset); | |
510 | header_->update(); | |
511 | viewport_->update(); | |
512 | } | |
513 | ||
514 | void View::set_h_offset(int offset) | |
515 | { | |
516 | scrollarea_->horizontalScrollBar()->setSliderPosition(offset); | |
517 | header_->update(); | |
518 | viewport_->update(); | |
519 | } | |
520 | ||
521 | int View::get_h_scrollbar_maximum() const | |
522 | { | |
523 | return scrollarea_->horizontalScrollBar()->maximum(); | |
524 | } | |
525 | ||
526 | unsigned int View::depth() const | |
527 | { | |
528 | return 0; | |
529 | } | |
530 | ||
531 | uint32_t View::current_segment() const | |
532 | { | |
533 | return current_segment_; | |
534 | } | |
535 | ||
536 | pv::util::SIPrefix View::tick_prefix() const | |
537 | { | |
538 | return tick_prefix_; | |
539 | } | |
540 | ||
541 | void View::set_tick_prefix(pv::util::SIPrefix tick_prefix) | |
542 | { | |
543 | if (tick_prefix_ != tick_prefix) { | |
544 | tick_prefix_ = tick_prefix; | |
545 | tick_prefix_changed(); | |
546 | } | |
547 | } | |
548 | ||
549 | unsigned int View::tick_precision() const | |
550 | { | |
551 | return tick_precision_; | |
552 | } | |
553 | ||
554 | void View::set_tick_precision(unsigned tick_precision) | |
555 | { | |
556 | if (tick_precision_ != tick_precision) { | |
557 | tick_precision_ = tick_precision; | |
558 | tick_precision_changed(); | |
559 | } | |
560 | } | |
561 | ||
562 | const pv::util::Timestamp& View::tick_period() const | |
563 | { | |
564 | return tick_period_; | |
565 | } | |
566 | ||
567 | unsigned int View::minor_tick_count() const | |
568 | { | |
569 | return minor_tick_count_; | |
570 | } | |
571 | ||
572 | void View::set_tick_period(const pv::util::Timestamp& tick_period) | |
573 | { | |
574 | if (tick_period_ != tick_period) { | |
575 | tick_period_ = tick_period; | |
576 | tick_period_changed(); | |
577 | } | |
578 | } | |
579 | ||
580 | TimeUnit View::time_unit() const | |
581 | { | |
582 | return time_unit_; | |
583 | } | |
584 | ||
585 | void View::set_time_unit(pv::util::TimeUnit time_unit) | |
586 | { | |
587 | if (time_unit_ != time_unit) { | |
588 | time_unit_ = time_unit; | |
589 | time_unit_changed(); | |
590 | } | |
591 | } | |
592 | ||
593 | void View::set_current_segment(uint32_t segment_id) | |
594 | { | |
595 | current_segment_ = segment_id; | |
596 | ||
597 | for (const shared_ptr<Signal>& signal : signals_) | |
598 | signal->set_current_segment(current_segment_); | |
599 | #ifdef ENABLE_DECODE | |
600 | for (shared_ptr<DecodeTrace>& dt : decode_traces_) | |
601 | dt->set_current_segment(current_segment_); | |
602 | #endif | |
603 | ||
604 | vector<util::Timestamp> triggers = session_.get_triggers(current_segment_); | |
605 | ||
606 | trigger_markers_.clear(); | |
607 | for (util::Timestamp timestamp : triggers) | |
608 | trigger_markers_.push_back(make_shared<TriggerMarker>(*this, timestamp)); | |
609 | ||
610 | // When enabled, the first trigger for this segment is used as the zero position | |
611 | GlobalSettings settings; | |
612 | bool trigger_is_zero_time = settings.value(GlobalSettings::Key_View_TriggerIsZeroTime).toBool(); | |
613 | ||
614 | if (trigger_is_zero_time && (triggers.size() > 0)) | |
615 | set_zero_position(triggers.front()); | |
616 | ||
617 | viewport_->update(); | |
618 | ||
619 | segment_changed(segment_id); | |
620 | } | |
621 | ||
622 | bool View::segment_is_selectable() const | |
623 | { | |
624 | return segment_selectable_; | |
625 | } | |
626 | ||
627 | Trace::SegmentDisplayMode View::segment_display_mode() const | |
628 | { | |
629 | return segment_display_mode_; | |
630 | } | |
631 | ||
632 | void View::set_segment_display_mode(Trace::SegmentDisplayMode mode) | |
633 | { | |
634 | segment_display_mode_ = mode; | |
635 | ||
636 | for (const shared_ptr<Signal>& signal : signals_) | |
637 | signal->set_segment_display_mode(mode); | |
638 | ||
639 | uint32_t last_segment = session_.get_segment_count() - 1; | |
640 | ||
641 | switch (mode) { | |
642 | case Trace::ShowLastSegmentOnly: | |
643 | if (current_segment_ != last_segment) | |
644 | set_current_segment(last_segment); | |
645 | break; | |
646 | ||
647 | case Trace::ShowLastCompleteSegmentOnly: | |
648 | // Do nothing if we only have one segment so far | |
649 | if (last_segment > 0) { | |
650 | // If the last segment isn't complete, the previous one must be | |
651 | uint32_t segment_id = | |
652 | (session_.all_segments_complete(last_segment)) ? | |
653 | last_segment : last_segment - 1; | |
654 | ||
655 | if (current_segment_ != segment_id) | |
656 | set_current_segment(segment_id); | |
657 | } | |
658 | break; | |
659 | ||
660 | case Trace::ShowSingleSegmentOnly: | |
661 | case Trace::ShowAllSegments: | |
662 | case Trace::ShowAccumulatedIntensity: | |
663 | default: | |
664 | // Current segment remains as-is | |
665 | break; | |
666 | } | |
667 | ||
668 | segment_selectable_ = true; | |
669 | ||
670 | if ((mode == Trace::ShowAllSegments) || (mode == Trace::ShowAccumulatedIntensity)) | |
671 | segment_selectable_ = false; | |
672 | ||
673 | viewport_->update(); | |
674 | ||
675 | segment_display_mode_changed((int)mode, segment_selectable_); | |
676 | } | |
677 | ||
678 | void View::zoom(double steps) | |
679 | { | |
680 | zoom(steps, viewport_->width() / 2); | |
681 | } | |
682 | ||
683 | void View::zoom(double steps, int offset) | |
684 | { | |
685 | set_zoom(scale_ * pow(3.0 / 2.0, -steps), offset); | |
686 | } | |
687 | ||
688 | void View::zoom_fit(bool gui_state) | |
689 | { | |
690 | // Act as one-shot when stopped, toggle along with the GUI otherwise | |
691 | if (session_.get_capture_state() == Session::Stopped) { | |
692 | always_zoom_to_fit_ = false; | |
693 | always_zoom_to_fit_changed(false); | |
694 | } else { | |
695 | always_zoom_to_fit_ = gui_state; | |
696 | always_zoom_to_fit_changed(gui_state); | |
697 | } | |
698 | ||
699 | const pair<Timestamp, Timestamp> extents = get_time_extents(); | |
700 | const Timestamp delta = extents.second - extents.first; | |
701 | if (delta < Timestamp("1e-12")) | |
702 | return; | |
703 | ||
704 | assert(viewport_); | |
705 | const int w = viewport_->width(); | |
706 | if (w <= 0) | |
707 | return; | |
708 | ||
709 | const Timestamp scale = max(min(delta / w, MaxScale), MinScale); | |
710 | set_scale_offset(scale.convert_to<double>(), extents.first); | |
711 | } | |
712 | ||
713 | void View::set_scale_offset(double scale, const Timestamp& offset) | |
714 | { | |
715 | // Disable sticky scrolling / always zoom to fit when acquisition runs | |
716 | // and user drags the viewport | |
717 | if ((scale_ == scale) && (offset_ != offset) && | |
718 | (session_.get_capture_state() == Session::Running)) { | |
719 | ||
720 | if (sticky_scrolling_) { | |
721 | sticky_scrolling_ = false; | |
722 | sticky_scrolling_changed(false); | |
723 | } | |
724 | ||
725 | if (always_zoom_to_fit_) { | |
726 | always_zoom_to_fit_ = false; | |
727 | always_zoom_to_fit_changed(false); | |
728 | } | |
729 | } | |
730 | ||
731 | set_scale(scale); | |
732 | set_offset(offset); | |
733 | ||
734 | calculate_tick_spacing(); | |
735 | ||
736 | update_scroll(); | |
737 | ruler_->update(); | |
738 | viewport_->update(); | |
739 | } | |
740 | ||
741 | set< shared_ptr<SignalData> > View::get_visible_data() const | |
742 | { | |
743 | // Make a set of all the visible data objects | |
744 | set< shared_ptr<SignalData> > visible_data; | |
745 | for (const shared_ptr<Signal>& sig : signals_) | |
746 | if (sig->enabled()) | |
747 | visible_data.insert(sig->data()); | |
748 | ||
749 | return visible_data; | |
750 | } | |
751 | ||
752 | pair<Timestamp, Timestamp> View::get_time_extents() const | |
753 | { | |
754 | boost::optional<Timestamp> left_time, right_time; | |
755 | const set< shared_ptr<SignalData> > visible_data = get_visible_data(); | |
756 | for (const shared_ptr<SignalData>& d : visible_data) { | |
757 | const vector< shared_ptr<Segment> > segments = d->segments(); | |
758 | for (const shared_ptr<Segment>& s : segments) { | |
759 | double samplerate = s->samplerate(); | |
760 | samplerate = (samplerate <= 0.0) ? 1.0 : samplerate; | |
761 | ||
762 | const Timestamp start_time = s->start_time(); | |
763 | left_time = left_time ? | |
764 | min(*left_time, start_time) : | |
765 | start_time; | |
766 | right_time = right_time ? | |
767 | max(*right_time, start_time + d->max_sample_count() / samplerate) : | |
768 | start_time + d->max_sample_count() / samplerate; | |
769 | } | |
770 | } | |
771 | ||
772 | if (!left_time || !right_time) | |
773 | return make_pair(0, 0); | |
774 | ||
775 | assert(*left_time < *right_time); | |
776 | return make_pair(*left_time, *right_time); | |
777 | } | |
778 | ||
779 | void View::enable_show_sampling_points(bool state) | |
780 | { | |
781 | (void)state; | |
782 | ||
783 | viewport_->update(); | |
784 | } | |
785 | ||
786 | void View::enable_show_analog_minor_grid(bool state) | |
787 | { | |
788 | (void)state; | |
789 | ||
790 | viewport_->update(); | |
791 | } | |
792 | ||
793 | void View::enable_colored_bg(bool state) | |
794 | { | |
795 | colored_bg_ = state; | |
796 | viewport_->update(); | |
797 | } | |
798 | ||
799 | bool View::colored_bg() const | |
800 | { | |
801 | return colored_bg_; | |
802 | } | |
803 | ||
804 | bool View::cursors_shown() const | |
805 | { | |
806 | return show_cursors_; | |
807 | } | |
808 | ||
809 | void View::show_cursors(bool show) | |
810 | { | |
811 | if (show_cursors_ != show) { | |
812 | show_cursors_ = show; | |
813 | ||
814 | cursor_state_changed(show); | |
815 | ruler_->update(); | |
816 | viewport_->update(); | |
817 | } | |
818 | } | |
819 | ||
820 | void View::set_cursors(pv::util::Timestamp& first, pv::util::Timestamp& second) | |
821 | { | |
822 | assert(cursors_); | |
823 | ||
824 | cursors_->first()->set_time(first); | |
825 | cursors_->second()->set_time(second); | |
826 | ||
827 | ruler_->update(); | |
828 | viewport_->update(); | |
829 | } | |
830 | ||
831 | void View::centre_cursors() | |
832 | { | |
833 | assert(cursors_); | |
834 | ||
835 | const double time_width = scale_ * viewport_->width(); | |
836 | cursors_->first()->set_time(offset_ + time_width * 0.4); | |
837 | cursors_->second()->set_time(offset_ + time_width * 0.6); | |
838 | ||
839 | ruler_->update(); | |
840 | viewport_->update(); | |
841 | } | |
842 | ||
843 | shared_ptr<CursorPair> View::cursors() const | |
844 | { | |
845 | return cursors_; | |
846 | } | |
847 | ||
848 | shared_ptr<Flag> View::add_flag(const Timestamp& time) | |
849 | { | |
850 | shared_ptr<Flag> flag = | |
851 | make_shared<Flag>(*this, time, QString("%1").arg(next_flag_text_)); | |
852 | flags_.push_back(flag); | |
853 | ||
854 | next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' : | |
855 | (next_flag_text_ + 1); | |
856 | ||
857 | time_item_appearance_changed(true, true); | |
858 | return flag; | |
859 | } | |
860 | ||
861 | void View::remove_flag(shared_ptr<Flag> flag) | |
862 | { | |
863 | flags_.remove(flag); | |
864 | time_item_appearance_changed(true, true); | |
865 | } | |
866 | ||
867 | vector< shared_ptr<Flag> > View::flags() const | |
868 | { | |
869 | vector< shared_ptr<Flag> > flags(flags_.begin(), flags_.end()); | |
870 | stable_sort(flags.begin(), flags.end(), | |
871 | [](const shared_ptr<Flag> &a, const shared_ptr<Flag> &b) { | |
872 | return a->time() < b->time(); | |
873 | }); | |
874 | ||
875 | return flags; | |
876 | } | |
877 | ||
878 | const QPoint& View::hover_point() const | |
879 | { | |
880 | return hover_point_; | |
881 | } | |
882 | ||
883 | const QWidget* View::hover_widget() const | |
884 | { | |
885 | return hover_widget_; | |
886 | } | |
887 | ||
888 | int64_t View::get_nearest_level_change(const QPoint &p) | |
889 | { | |
890 | // Is snapping disabled? | |
891 | if (snap_distance_ == 0) | |
892 | return -1; | |
893 | ||
894 | struct entry_t { | |
895 | entry_t(shared_ptr<Signal> s) : | |
896 | signal(s), delta(numeric_limits<int64_t>::max()), sample(-1), is_dense(false) {} | |
897 | shared_ptr<Signal> signal; | |
898 | int64_t delta; | |
899 | int64_t sample; | |
900 | bool is_dense; | |
901 | }; | |
902 | ||
903 | vector<entry_t> list; | |
904 | ||
905 | // Create list of signals to consider | |
906 | if (signal_under_mouse_cursor_) | |
907 | list.emplace_back(signal_under_mouse_cursor_); | |
908 | else | |
909 | for (shared_ptr<Signal> s : signals_) { | |
910 | if (!s->enabled()) | |
911 | continue; | |
912 | ||
913 | list.emplace_back(s); | |
914 | } | |
915 | ||
916 | // Get data for listed signals | |
917 | for (entry_t &e : list) { | |
918 | // Calculate sample number from cursor position | |
919 | const double samples_per_pixel = e.signal->base()->get_samplerate() * scale(); | |
920 | const int64_t x_offset = offset().convert_to<double>() / scale(); | |
921 | const int64_t sample_num = max(((x_offset + p.x()) * samples_per_pixel), 0.0); | |
922 | ||
923 | vector<data::LogicSegment::EdgePair> edges = | |
924 | e.signal->get_nearest_level_changes(sample_num); | |
925 | ||
926 | if (edges.empty()) | |
927 | continue; | |
928 | ||
929 | // Check first edge | |
930 | const int64_t first_sample_delta = abs(sample_num - edges.front().first); | |
931 | const int64_t first_delta = first_sample_delta / samples_per_pixel; | |
932 | e.delta = first_delta; | |
933 | e.sample = edges.front().first; | |
934 | ||
935 | // Check second edge if available | |
936 | if (edges.size() == 2) { | |
937 | // Note: -1 because this is usually the right edge and sample points are left-aligned | |
938 | const int64_t second_sample_delta = abs(sample_num - edges.back().first - 1); | |
939 | const int64_t second_delta = second_sample_delta / samples_per_pixel; | |
940 | ||
941 | // If both edges are too close, we mark this signal as being dense | |
942 | if ((first_delta + second_delta) <= snap_distance_) | |
943 | e.is_dense = true; | |
944 | ||
945 | if (second_delta < first_delta) { | |
946 | e.delta = second_delta; | |
947 | e.sample = edges.back().first; | |
948 | } | |
949 | } | |
950 | } | |
951 | ||
952 | // Look for the best match: non-dense first, then dense | |
953 | entry_t *match = nullptr; | |
954 | ||
955 | for (entry_t &e : list) { | |
956 | if (e.delta > snap_distance_ || e.is_dense) | |
957 | continue; | |
958 | ||
959 | if (match) { | |
960 | if (e.delta < match->delta) | |
961 | match = &e; | |
962 | } else | |
963 | match = &e; | |
964 | } | |
965 | ||
966 | if (!match) { | |
967 | for (entry_t &e : list) { | |
968 | if (!e.is_dense) | |
969 | continue; | |
970 | ||
971 | if (match) { | |
972 | if (e.delta < match->delta) | |
973 | match = &e; | |
974 | } else | |
975 | match = &e; | |
976 | } | |
977 | } | |
978 | ||
979 | if (match) { | |
980 | // Somewhat ugly hack to make TimeItem::drag_by() work | |
981 | signal_under_mouse_cursor_ = match->signal; | |
982 | ||
983 | return match->sample; | |
984 | } | |
985 | ||
986 | return -1; | |
987 | } | |
988 | ||
989 | void View::restack_all_trace_tree_items() | |
990 | { | |
991 | // Make a list of owners that is sorted from deepest first | |
992 | const vector<shared_ptr<TraceTreeItem>> items( | |
993 | list_by_type<TraceTreeItem>()); | |
994 | set< TraceTreeItemOwner* > owners; | |
995 | for (const auto &r : items) | |
996 | owners.insert(r->owner()); | |
997 | vector< TraceTreeItemOwner* > sorted_owners(owners.begin(), owners.end()); | |
998 | sort(sorted_owners.begin(), sorted_owners.end(), | |
999 | [](const TraceTreeItemOwner* a, const TraceTreeItemOwner *b) { | |
1000 | return a->depth() > b->depth(); }); | |
1001 | ||
1002 | // Restack the items recursively | |
1003 | for (auto &o : sorted_owners) | |
1004 | o->restack_items(); | |
1005 | ||
1006 | // Animate the items to their destination | |
1007 | for (const auto &i : items) | |
1008 | i->animate_to_layout_v_offset(); | |
1009 | } | |
1010 | ||
1011 | int View::header_width() const | |
1012 | { | |
1013 | return header_->extended_size_hint().width(); | |
1014 | } | |
1015 | ||
1016 | void View::on_setting_changed(const QString &key, const QVariant &value) | |
1017 | { | |
1018 | if (key == GlobalSettings::Key_View_TriggerIsZeroTime) | |
1019 | on_settingViewTriggerIsZeroTime_changed(value); | |
1020 | ||
1021 | if (key == GlobalSettings::Key_View_SnapDistance) { | |
1022 | GlobalSettings settings; | |
1023 | snap_distance_ = settings.value(GlobalSettings::Key_View_SnapDistance).toInt(); | |
1024 | } | |
1025 | } | |
1026 | ||
1027 | void View::trigger_event(int segment_id, util::Timestamp location) | |
1028 | { | |
1029 | // TODO This doesn't work if we're showing multiple segments at once | |
1030 | if ((uint32_t)segment_id != current_segment_) | |
1031 | return; | |
1032 | ||
1033 | // Set zero location if the Key_View_TriggerIsZeroTime setting is set and | |
1034 | // if this is the first trigger for this segment. | |
1035 | GlobalSettings settings; | |
1036 | bool trigger_is_zero_time = settings.value(GlobalSettings::Key_View_TriggerIsZeroTime).toBool(); | |
1037 | ||
1038 | size_t trigger_count = session_.get_triggers(current_segment_).size(); | |
1039 | ||
1040 | if (trigger_is_zero_time && trigger_count == 1) | |
1041 | set_zero_position(location); | |
1042 | ||
1043 | trigger_markers_.push_back(make_shared<TriggerMarker>(*this, location)); | |
1044 | } | |
1045 | ||
1046 | void View::get_scroll_layout(double &length, Timestamp &offset) const | |
1047 | { | |
1048 | const pair<Timestamp, Timestamp> extents = get_time_extents(); | |
1049 | length = ((extents.second - extents.first) / scale_).convert_to<double>(); | |
1050 | offset = offset_ / scale_; | |
1051 | } | |
1052 | ||
1053 | void View::set_zoom(double scale, int offset) | |
1054 | { | |
1055 | // Reset the "always zoom to fit" feature as the user changed the zoom | |
1056 | always_zoom_to_fit_ = false; | |
1057 | always_zoom_to_fit_changed(false); | |
1058 | ||
1059 | const Timestamp cursor_offset = offset_ + scale_ * offset; | |
1060 | const Timestamp new_scale = max(min(Timestamp(scale), MaxScale), MinScale); | |
1061 | const Timestamp new_offset = cursor_offset - new_scale * offset; | |
1062 | set_scale_offset(new_scale.convert_to<double>(), new_offset); | |
1063 | } | |
1064 | ||
1065 | void View::calculate_tick_spacing() | |
1066 | { | |
1067 | const double SpacingIncrement = 10.0f; | |
1068 | const double MinValueSpacing = 40.0f; | |
1069 | ||
1070 | // Figure out the highest numeric value visible on a label | |
1071 | const QSize areaSize = viewport_->size(); | |
1072 | const Timestamp max_time = max(fabs(offset_), | |
1073 | fabs(offset_ + scale_ * areaSize.width())); | |
1074 | ||
1075 | double min_width = SpacingIncrement; | |
1076 | double label_width, tick_period_width; | |
1077 | ||
1078 | QFontMetrics m(QApplication::font()); | |
1079 | ||
1080 | // Copies of the member variables with the same name, used in the calculation | |
1081 | // and written back afterwards, so that we don't emit signals all the time | |
1082 | // during the calculation. | |
1083 | pv::util::Timestamp tick_period = tick_period_; | |
1084 | pv::util::SIPrefix tick_prefix = tick_prefix_; | |
1085 | unsigned tick_precision = tick_precision_; | |
1086 | ||
1087 | do { | |
1088 | const double min_period = scale_ * min_width; | |
1089 | ||
1090 | const int order = (int)floorf(log10f(min_period)); | |
1091 | const pv::util::Timestamp order_decimal = | |
1092 | pow(pv::util::Timestamp(10), order); | |
1093 | ||
1094 | // Allow for a margin of error so that a scale unit of 1 can be used. | |
1095 | // Otherwise, for a SU of 1 the tick period will almost always be below | |
1096 | // the min_period by a small amount - and thus skipped in favor of 2. | |
1097 | // Note: margin assumes that SU[0] and SU[1] contain the smallest values | |
1098 | double tp_margin = (ScaleUnits[0] + ScaleUnits[1]) / 2.0; | |
1099 | double tp_with_margin; | |
1100 | unsigned int unit = 0; | |
1101 | ||
1102 | do { | |
1103 | tp_with_margin = order_decimal.convert_to<double>() * | |
1104 | (ScaleUnits[unit++] + tp_margin); | |
1105 | } while (tp_with_margin < min_period && unit < countof(ScaleUnits)); | |
1106 | ||
1107 | minor_tick_count_ = (unit == 2) ? 4 : 5; | |
1108 | tick_period = order_decimal * ScaleUnits[unit - 1]; | |
1109 | tick_prefix = static_cast<pv::util::SIPrefix>( | |
1110 | (order - pv::util::exponent(pv::util::SIPrefix::yocto)) / 3); | |
1111 | ||
1112 | // Precision is the number of fractional digits required, not | |
1113 | // taking the prefix into account (and it must never be negative) | |
1114 | tick_precision = max(ceil(log10(1 / tick_period)).convert_to<int>(), 0); | |
1115 | ||
1116 | tick_period_width = (tick_period / scale_).convert_to<double>(); | |
1117 | ||
1118 | const QString label_text = Ruler::format_time_with_distance( | |
1119 | tick_period, max_time, tick_prefix, time_unit_, tick_precision); | |
1120 | ||
1121 | label_width = m.boundingRect(0, 0, INT_MAX, INT_MAX, | |
1122 | Qt::AlignLeft | Qt::AlignTop, label_text).width() + | |
1123 | MinValueSpacing; | |
1124 | ||
1125 | min_width += SpacingIncrement; | |
1126 | } while (tick_period_width < label_width); | |
1127 | ||
1128 | set_tick_period(tick_period); | |
1129 | set_tick_prefix(tick_prefix); | |
1130 | set_tick_precision(tick_precision); | |
1131 | } | |
1132 | ||
1133 | void View::adjust_top_margin() | |
1134 | { | |
1135 | assert(viewport_); | |
1136 | ||
1137 | const QSize areaSize = viewport_->size(); | |
1138 | ||
1139 | const pair<int, int> extents = v_extents(); | |
1140 | const int top_margin = owner_visual_v_offset() + extents.first; | |
1141 | const int trace_bottom = owner_visual_v_offset() + extents.first + extents.second; | |
1142 | ||
1143 | // Do we have empty space at the top while the last trace goes out of screen? | |
1144 | if ((top_margin > 0) && (trace_bottom > areaSize.height())) { | |
1145 | const int trace_height = extents.second - extents.first; | |
1146 | ||
1147 | // Center everything vertically if there is enough space | |
1148 | if (areaSize.height() >= trace_height) | |
1149 | set_v_offset(extents.first - | |
1150 | ((areaSize.height() - trace_height) / 2)); | |
1151 | else | |
1152 | // Remove the top margin to make as many traces fit on screen as possible | |
1153 | set_v_offset(extents.first); | |
1154 | } | |
1155 | } | |
1156 | ||
1157 | void View::update_scroll() | |
1158 | { | |
1159 | assert(viewport_); | |
1160 | QScrollBar *hscrollbar = scrollarea_->horizontalScrollBar(); | |
1161 | QScrollBar *vscrollbar = scrollarea_->verticalScrollBar(); | |
1162 | ||
1163 | const QSize areaSize = viewport_->size(); | |
1164 | ||
1165 | // Set the horizontal scroll bar | |
1166 | double length = 0; | |
1167 | Timestamp offset; | |
1168 | get_scroll_layout(length, offset); | |
1169 | length = max(length - areaSize.width(), 0.0); | |
1170 | ||
1171 | int major_tick_distance = (tick_period_ / scale_).convert_to<int>(); | |
1172 | ||
1173 | hscrollbar->setPageStep(areaSize.width() / 2); | |
1174 | hscrollbar->setSingleStep(major_tick_distance); | |
1175 | ||
1176 | updating_scroll_ = true; | |
1177 | ||
1178 | if (length < MaxScrollValue) { | |
1179 | hscrollbar->setRange(0, length); | |
1180 | hscrollbar->setSliderPosition(offset.convert_to<double>()); | |
1181 | } else { | |
1182 | hscrollbar->setRange(0, MaxScrollValue); | |
1183 | hscrollbar->setSliderPosition( | |
1184 | (offset_ * MaxScrollValue / (scale_ * length)).convert_to<double>()); | |
1185 | } | |
1186 | ||
1187 | updating_scroll_ = false; | |
1188 | ||
1189 | // Set the vertical scrollbar | |
1190 | vscrollbar->setPageStep(areaSize.height()); | |
1191 | vscrollbar->setSingleStep(areaSize.height() / 8); | |
1192 | ||
1193 | const pair<int, int> extents = v_extents(); | |
1194 | ||
1195 | // Don't change the scrollbar range if there are no traces | |
1196 | if (extents.first != extents.second) | |
1197 | vscrollbar->setRange(extents.first - areaSize.height(), | |
1198 | extents.second); | |
1199 | ||
1200 | if (scroll_needs_defaults_) { | |
1201 | set_scroll_default(); | |
1202 | scroll_needs_defaults_ = false; | |
1203 | } | |
1204 | } | |
1205 | ||
1206 | void View::reset_scroll() | |
1207 | { | |
1208 | scrollarea_->verticalScrollBar()->setRange(0, 0); | |
1209 | } | |
1210 | ||
1211 | void View::set_scroll_default() | |
1212 | { | |
1213 | assert(viewport_); | |
1214 | ||
1215 | const QSize areaSize = viewport_->size(); | |
1216 | ||
1217 | const pair<int, int> extents = v_extents(); | |
1218 | const int trace_height = extents.second - extents.first; | |
1219 | ||
1220 | // Do all traces fit in the view? | |
1221 | if (areaSize.height() >= trace_height) | |
1222 | // Center all traces vertically | |
1223 | set_v_offset(extents.first - | |
1224 | ((areaSize.height() - trace_height) / 2)); | |
1225 | else | |
1226 | // Put the first trace at the top, letting the bottom ones overflow | |
1227 | set_v_offset(extents.first); | |
1228 | } | |
1229 | ||
1230 | void View::determine_if_header_was_shrunk() | |
1231 | { | |
1232 | const int header_pane_width = | |
1233 | splitter_->sizes().front(); // clazy:exclude=detaching-temporary | |
1234 | ||
1235 | // Allow for a slight margin of error so that we also accept | |
1236 | // slight differences when e.g. a label name change increased | |
1237 | // the overall width | |
1238 | header_was_shrunk_ = (header_pane_width < (header_width() - 10)); | |
1239 | } | |
1240 | ||
1241 | void View::resize_header_to_fit() | |
1242 | { | |
1243 | // Setting the maximum width of the header widget doesn't work as | |
1244 | // expected because the splitter would allow the user to make the | |
1245 | // pane wider than that, creating empty space as a result. | |
1246 | // To make this work, we stricly enforce the maximum width by | |
1247 | // expanding the header unless the user shrunk it on purpose. | |
1248 | // As we're then setting the width of the header pane, we set the | |
1249 | // splitter to the maximum allowed position. | |
1250 | ||
1251 | int splitter_area_width = 0; | |
1252 | for (int w : splitter_->sizes()) // clazy:exclude=range-loop | |
1253 | splitter_area_width += w; | |
1254 | ||
1255 | // Make sure the header has enough horizontal space to show all labels fully | |
1256 | QList<int> pane_sizes; | |
1257 | pane_sizes.push_back(header_->extended_size_hint().width()); | |
1258 | pane_sizes.push_back(splitter_area_width - header_->extended_size_hint().width()); | |
1259 | splitter_->setSizes(pane_sizes); | |
1260 | } | |
1261 | ||
1262 | void View::update_layout() | |
1263 | { | |
1264 | update_scroll(); | |
1265 | } | |
1266 | ||
1267 | TraceTreeItemOwner* View::find_prevalent_trace_group( | |
1268 | const shared_ptr<sigrok::ChannelGroup> &group, | |
1269 | const unordered_map<shared_ptr<data::SignalBase>, shared_ptr<Signal> > | |
1270 | &signal_map) | |
1271 | { | |
1272 | assert(group); | |
1273 | ||
1274 | unordered_set<TraceTreeItemOwner*> owners; | |
1275 | vector<TraceTreeItemOwner*> owner_list; | |
1276 | ||
1277 | // Make a set and a list of all the owners | |
1278 | for (const auto& channel : group->channels()) { | |
1279 | for (auto& entry : signal_map) { | |
1280 | if (entry.first->channel() == channel) { | |
1281 | TraceTreeItemOwner *const o = (entry.second)->owner(); | |
1282 | owner_list.push_back(o); | |
1283 | owners.insert(o); | |
1284 | } | |
1285 | } | |
1286 | } | |
1287 | ||
1288 | // Iterate through the list of owners, and find the most prevalent | |
1289 | size_t max_prevalence = 0; | |
1290 | TraceTreeItemOwner *prevalent_owner = nullptr; | |
1291 | for (TraceTreeItemOwner *owner : owners) { | |
1292 | const size_t prevalence = count_if( | |
1293 | owner_list.begin(), owner_list.end(), | |
1294 | [&](TraceTreeItemOwner *o) { return o == owner; }); | |
1295 | if (prevalence > max_prevalence) { | |
1296 | max_prevalence = prevalence; | |
1297 | prevalent_owner = owner; | |
1298 | } | |
1299 | } | |
1300 | ||
1301 | return prevalent_owner; | |
1302 | } | |
1303 | ||
1304 | vector< shared_ptr<Trace> > View::extract_new_traces_for_channels( | |
1305 | const vector< shared_ptr<sigrok::Channel> > &channels, | |
1306 | const unordered_map<shared_ptr<data::SignalBase>, shared_ptr<Signal> > | |
1307 | &signal_map, | |
1308 | set< shared_ptr<Trace> > &add_list) | |
1309 | { | |
1310 | vector< shared_ptr<Trace> > filtered_traces; | |
1311 | ||
1312 | for (const auto& channel : channels) { | |
1313 | for (auto& entry : signal_map) { | |
1314 | if (entry.first->channel() == channel) { | |
1315 | shared_ptr<Trace> trace = entry.second; | |
1316 | const auto list_iter = add_list.find(trace); | |
1317 | if (list_iter == add_list.end()) | |
1318 | continue; | |
1319 | ||
1320 | filtered_traces.push_back(trace); | |
1321 | add_list.erase(list_iter); | |
1322 | } | |
1323 | } | |
1324 | } | |
1325 | ||
1326 | return filtered_traces; | |
1327 | } | |
1328 | ||
1329 | void View::determine_time_unit() | |
1330 | { | |
1331 | // Check whether we know the sample rate and hence can use time as the unit | |
1332 | if (time_unit_ == util::TimeUnit::Samples) { | |
1333 | // Check all signals but... | |
1334 | for (const shared_ptr<Signal>& signal : signals_) { | |
1335 | const shared_ptr<SignalData> data = signal->data(); | |
1336 | ||
1337 | // ...only check first segment of each | |
1338 | const vector< shared_ptr<Segment> > segments = data->segments(); | |
1339 | if (!segments.empty()) | |
1340 | if (segments[0]->samplerate()) { | |
1341 | set_time_unit(util::TimeUnit::Time); | |
1342 | break; | |
1343 | } | |
1344 | } | |
1345 | } | |
1346 | } | |
1347 | ||
1348 | bool View::eventFilter(QObject *object, QEvent *event) | |
1349 | { | |
1350 | const QEvent::Type type = event->type(); | |
1351 | if (type == QEvent::MouseMove) { | |
1352 | ||
1353 | if (object) | |
1354 | hover_widget_ = qobject_cast<QWidget*>(object); | |
1355 | ||
1356 | const QMouseEvent *const mouse_event = (QMouseEvent*)event; | |
1357 | if (object == viewport_) | |
1358 | hover_point_ = mouse_event->pos(); | |
1359 | else if (object == ruler_) | |
1360 | hover_point_ = mouse_event->pos(); | |
1361 | else if (object == header_) | |
1362 | hover_point_ = QPoint(0, mouse_event->y()); | |
1363 | else | |
1364 | hover_point_ = QPoint(-1, -1); | |
1365 | ||
1366 | update_hover_point(); | |
1367 | ||
1368 | } else if (type == QEvent::Leave) { | |
1369 | hover_point_ = QPoint(-1, -1); | |
1370 | update_hover_point(); | |
1371 | } else if (type == QEvent::Show) { | |
1372 | ||
1373 | // This is somewhat of a hack, unfortunately. We cannot use | |
1374 | // set_v_offset() from within restore_settings() as the view | |
1375 | // at that point is neither visible nor properly sized. | |
1376 | // This is the least intrusive workaround I could come up | |
1377 | // with: set the vertical offset (or scroll defaults) when | |
1378 | // the view is shown, which happens after all widgets were | |
1379 | // resized to their final sizes. | |
1380 | update_layout(); | |
1381 | ||
1382 | if (settings_restored_) | |
1383 | determine_if_header_was_shrunk(); | |
1384 | else | |
1385 | resize_header_to_fit(); | |
1386 | ||
1387 | if (scroll_needs_defaults_) { | |
1388 | set_scroll_default(); | |
1389 | scroll_needs_defaults_ = false; | |
1390 | } | |
1391 | ||
1392 | if (saved_v_offset_) { | |
1393 | set_v_offset(saved_v_offset_); | |
1394 | saved_v_offset_ = 0; | |
1395 | } | |
1396 | } | |
1397 | ||
1398 | return QObject::eventFilter(object, event); | |
1399 | } | |
1400 | ||
1401 | void View::contextMenuEvent(QContextMenuEvent *event) | |
1402 | { | |
1403 | QPoint pos = event->pos() - QPoint(0, ruler_->sizeHint().height()); | |
1404 | ||
1405 | const shared_ptr<ViewItem> r = viewport_->get_mouse_over_item(pos); | |
1406 | if (!r) | |
1407 | return; | |
1408 | ||
1409 | QMenu *menu = r->create_view_context_menu(this, pos); | |
1410 | if (menu) | |
1411 | menu->popup(event->globalPos()); | |
1412 | } | |
1413 | ||
1414 | void View::resizeEvent(QResizeEvent* event) | |
1415 | { | |
1416 | // Only adjust the top margin if we shrunk vertically | |
1417 | if (event->size().height() < event->oldSize().height()) | |
1418 | adjust_top_margin(); | |
1419 | ||
1420 | update_layout(); | |
1421 | } | |
1422 | ||
1423 | void View::update_hover_point() | |
1424 | { | |
1425 | // Determine signal that the mouse cursor is hovering over | |
1426 | signal_under_mouse_cursor_.reset(); | |
1427 | if (hover_widget_ == this) { | |
1428 | for (const shared_ptr<Signal>& s : signals_) { | |
1429 | const pair<int, int> extents = s->v_extents(); | |
1430 | const int top = s->get_visual_y() + extents.first; | |
1431 | const int btm = s->get_visual_y() + extents.second; | |
1432 | if ((hover_point_.y() >= top) && (hover_point_.y() <= btm) | |
1433 | && s->base()->enabled()) | |
1434 | signal_under_mouse_cursor_ = s; | |
1435 | } | |
1436 | } | |
1437 | ||
1438 | // Update all trace tree items | |
1439 | const vector<shared_ptr<TraceTreeItem>> trace_tree_items( | |
1440 | list_by_type<TraceTreeItem>()); | |
1441 | for (const shared_ptr<TraceTreeItem>& r : trace_tree_items) | |
1442 | r->hover_point_changed(hover_point_); | |
1443 | ||
1444 | // Notify any other listeners | |
1445 | hover_point_changed(hover_widget_, hover_point_); | |
1446 | } | |
1447 | ||
1448 | void View::row_item_appearance_changed(bool label, bool content) | |
1449 | { | |
1450 | if (label) | |
1451 | header_->update(); | |
1452 | if (content) | |
1453 | viewport_->update(); | |
1454 | } | |
1455 | ||
1456 | void View::time_item_appearance_changed(bool label, bool content) | |
1457 | { | |
1458 | if (label) { | |
1459 | ruler_->update(); | |
1460 | ||
1461 | // Make sure the header pane width is updated, too | |
1462 | update_layout(); | |
1463 | } | |
1464 | ||
1465 | if (content) | |
1466 | viewport_->update(); | |
1467 | } | |
1468 | ||
1469 | void View::extents_changed(bool horz, bool vert) | |
1470 | { | |
1471 | sticky_events_ |= | |
1472 | (horz ? TraceTreeItemHExtentsChanged : 0) | | |
1473 | (vert ? TraceTreeItemVExtentsChanged : 0); | |
1474 | ||
1475 | lazy_event_handler_.stop(); | |
1476 | lazy_event_handler_.start(); | |
1477 | } | |
1478 | ||
1479 | void View::on_signal_name_changed() | |
1480 | { | |
1481 | if (!header_was_shrunk_) | |
1482 | resize_header_to_fit(); | |
1483 | } | |
1484 | ||
1485 | void View::on_splitter_moved() | |
1486 | { | |
1487 | // The header can only shrink when the splitter is moved manually | |
1488 | determine_if_header_was_shrunk(); | |
1489 | ||
1490 | if (!header_was_shrunk_) | |
1491 | resize_header_to_fit(); | |
1492 | } | |
1493 | ||
1494 | void View::h_scroll_value_changed(int value) | |
1495 | { | |
1496 | if (updating_scroll_) | |
1497 | return; | |
1498 | ||
1499 | // Disable sticky scrolling when user moves the horizontal scroll bar | |
1500 | // during a running acquisition | |
1501 | if (sticky_scrolling_ && (session_.get_capture_state() == Session::Running)) { | |
1502 | sticky_scrolling_ = false; | |
1503 | sticky_scrolling_changed(false); | |
1504 | } | |
1505 | ||
1506 | const int range = scrollarea_->horizontalScrollBar()->maximum(); | |
1507 | if (range < MaxScrollValue) | |
1508 | set_offset(scale_ * value); | |
1509 | else { | |
1510 | double length = 0; | |
1511 | Timestamp offset; | |
1512 | get_scroll_layout(length, offset); | |
1513 | set_offset(scale_ * length * value / MaxScrollValue); | |
1514 | } | |
1515 | ||
1516 | ruler_->update(); | |
1517 | viewport_->update(); | |
1518 | } | |
1519 | ||
1520 | void View::v_scroll_value_changed() | |
1521 | { | |
1522 | header_->update(); | |
1523 | viewport_->update(); | |
1524 | } | |
1525 | ||
1526 | void View::signals_changed() | |
1527 | { | |
1528 | using sigrok::Channel; | |
1529 | ||
1530 | vector< shared_ptr<Channel> > channels; | |
1531 | shared_ptr<sigrok::Device> sr_dev; | |
1532 | bool signals_added_or_removed = false; | |
1533 | ||
1534 | // Do we need to set the vertical scrollbar to its default position later? | |
1535 | // We do if there are no traces, i.e. the scroll bar has no range set | |
1536 | bool reset_scrollbar = | |
1537 | (scrollarea_->verticalScrollBar()->minimum() == | |
1538 | scrollarea_->verticalScrollBar()->maximum()); | |
1539 | ||
1540 | if (!session_.device()) { | |
1541 | reset_scroll(); | |
1542 | signals_.clear(); | |
1543 | } else { | |
1544 | sr_dev = session_.device()->device(); | |
1545 | assert(sr_dev); | |
1546 | channels = sr_dev->channels(); | |
1547 | } | |
1548 | ||
1549 | vector< shared_ptr<TraceTreeItem> > new_top_level_items; | |
1550 | ||
1551 | // Make a list of traces that are being added, and a list of traces | |
1552 | // that are being removed | |
1553 | const vector<shared_ptr<Trace>> prev_trace_list = list_by_type<Trace>(); | |
1554 | const set<shared_ptr<Trace>> prev_traces( | |
1555 | prev_trace_list.begin(), prev_trace_list.end()); | |
1556 | ||
1557 | set< shared_ptr<Trace> > traces(signals_.begin(), signals_.end()); | |
1558 | ||
1559 | #ifdef ENABLE_DECODE | |
1560 | traces.insert(decode_traces_.begin(), decode_traces_.end()); | |
1561 | #endif | |
1562 | ||
1563 | set< shared_ptr<Trace> > add_traces; | |
1564 | set_difference(traces.begin(), traces.end(), | |
1565 | prev_traces.begin(), prev_traces.end(), | |
1566 | inserter(add_traces, add_traces.begin())); | |
1567 | ||
1568 | set< shared_ptr<Trace> > remove_traces; | |
1569 | set_difference(prev_traces.begin(), prev_traces.end(), | |
1570 | traces.begin(), traces.end(), | |
1571 | inserter(remove_traces, remove_traces.begin())); | |
1572 | ||
1573 | // Make a look-up table of sigrok Channels to pulseview Signals | |
1574 | unordered_map<shared_ptr<data::SignalBase>, shared_ptr<Signal> > | |
1575 | signal_map; | |
1576 | for (const shared_ptr<Signal>& sig : signals_) | |
1577 | signal_map[sig->base()] = sig; | |
1578 | ||
1579 | // Populate channel groups | |
1580 | if (sr_dev) | |
1581 | for (auto& entry : sr_dev->channel_groups()) { | |
1582 | const shared_ptr<sigrok::ChannelGroup> &group = entry.second; | |
1583 | ||
1584 | if (group->channels().size() <= 1) | |
1585 | continue; | |
1586 | ||
1587 | // Find best trace group to add to | |
1588 | TraceTreeItemOwner *owner = find_prevalent_trace_group( | |
1589 | group, signal_map); | |
1590 | ||
1591 | // If there is no trace group, create one | |
1592 | shared_ptr<TraceGroup> new_trace_group; | |
1593 | if (!owner) { | |
1594 | new_trace_group.reset(new TraceGroup()); | |
1595 | owner = new_trace_group.get(); | |
1596 | } | |
1597 | ||
1598 | // Extract traces for the trace group, removing them from | |
1599 | // the add list | |
1600 | const vector< shared_ptr<Trace> > new_traces_in_group = | |
1601 | extract_new_traces_for_channels(group->channels(), | |
1602 | signal_map, add_traces); | |
1603 | ||
1604 | // Add the traces to the group | |
1605 | const pair<int, int> prev_v_extents = owner->v_extents(); | |
1606 | int offset = prev_v_extents.second - prev_v_extents.first; | |
1607 | for (const shared_ptr<Trace>& trace : new_traces_in_group) { | |
1608 | assert(trace); | |
1609 | owner->add_child_item(trace); | |
1610 | ||
1611 | const pair<int, int> extents = trace->v_extents(); | |
1612 | if (trace->enabled()) | |
1613 | offset += -extents.first; | |
1614 | trace->force_to_v_offset(offset); | |
1615 | if (trace->enabled()) | |
1616 | offset += extents.second; | |
1617 | } | |
1618 | ||
1619 | if (new_trace_group) { | |
1620 | // Assign proper vertical offsets to each channel in the group | |
1621 | new_trace_group->restack_items(); | |
1622 | ||
1623 | // If this is a new group, enqueue it in the new top level | |
1624 | // items list | |
1625 | if (!new_traces_in_group.empty()) | |
1626 | new_top_level_items.push_back(new_trace_group); | |
1627 | } | |
1628 | } | |
1629 | ||
1630 | // Enqueue the remaining logic channels in a group | |
1631 | vector< shared_ptr<Channel> > logic_channels; | |
1632 | copy_if(channels.begin(), channels.end(), back_inserter(logic_channels), | |
1633 | [](const shared_ptr<Channel>& c) { | |
1634 | return c->type() == sigrok::ChannelType::LOGIC; }); | |
1635 | ||
1636 | const vector< shared_ptr<Trace> > non_grouped_logic_signals = | |
1637 | extract_new_traces_for_channels(logic_channels, signal_map, add_traces); | |
1638 | ||
1639 | if (non_grouped_logic_signals.size() > 0) { | |
1640 | const shared_ptr<TraceGroup> non_grouped_trace_group( | |
1641 | make_shared<TraceGroup>()); | |
1642 | for (const shared_ptr<Trace>& trace : non_grouped_logic_signals) | |
1643 | non_grouped_trace_group->add_child_item(trace); | |
1644 | ||
1645 | non_grouped_trace_group->restack_items(); | |
1646 | new_top_level_items.push_back(non_grouped_trace_group); | |
1647 | } | |
1648 | ||
1649 | // Enqueue the remaining channels as free ungrouped traces | |
1650 | const vector< shared_ptr<Trace> > new_top_level_signals = | |
1651 | extract_new_traces_for_channels(channels, signal_map, add_traces); | |
1652 | new_top_level_items.insert(new_top_level_items.end(), | |
1653 | new_top_level_signals.begin(), new_top_level_signals.end()); | |
1654 | ||
1655 | // Enqueue any remaining traces i.e. decode traces | |
1656 | new_top_level_items.insert(new_top_level_items.end(), | |
1657 | add_traces.begin(), add_traces.end()); | |
1658 | ||
1659 | // Remove any removed traces | |
1660 | for (const shared_ptr<Trace>& trace : remove_traces) { | |
1661 | TraceTreeItemOwner *const owner = trace->owner(); | |
1662 | assert(owner); | |
1663 | owner->remove_child_item(trace); | |
1664 | signals_added_or_removed = true; | |
1665 | } | |
1666 | ||
1667 | // Remove any empty trace groups | |
1668 | for (shared_ptr<TraceGroup> group : list_by_type<TraceGroup>()) | |
1669 | if (group->child_items().size() == 0) { | |
1670 | remove_child_item(group); | |
1671 | group.reset(); | |
1672 | } | |
1673 | ||
1674 | // Add and position the pending top levels items | |
1675 | int offset = v_extents().second; | |
1676 | for (auto item : new_top_level_items) { | |
1677 | add_child_item(item); | |
1678 | ||
1679 | // Position the item after the last item or at the top if there is none | |
1680 | const pair<int, int> extents = item->v_extents(); | |
1681 | ||
1682 | if (item->enabled()) | |
1683 | offset += -extents.first; | |
1684 | ||
1685 | item->force_to_v_offset(offset); | |
1686 | ||
1687 | if (item->enabled()) | |
1688 | offset += extents.second; | |
1689 | signals_added_or_removed = true; | |
1690 | } | |
1691 | ||
1692 | ||
1693 | if (signals_added_or_removed && !header_was_shrunk_) | |
1694 | resize_header_to_fit(); | |
1695 | ||
1696 | update_layout(); | |
1697 | ||
1698 | header_->update(); | |
1699 | viewport_->update(); | |
1700 | ||
1701 | if (reset_scrollbar) | |
1702 | set_scroll_default(); | |
1703 | } | |
1704 | ||
1705 | void View::capture_state_updated(int state) | |
1706 | { | |
1707 | GlobalSettings settings; | |
1708 | ||
1709 | if (state == Session::Running) { | |
1710 | set_time_unit(util::TimeUnit::Samples); | |
1711 | ||
1712 | trigger_markers_.clear(); | |
1713 | set_zero_position(0); | |
1714 | ||
1715 | scale_at_acq_start_ = scale_; | |
1716 | offset_at_acq_start_ = offset_; | |
1717 | ||
1718 | // Activate "always zoom to fit" if the setting is enabled and we're | |
1719 | // the main view of this session (other trace views may be used for | |
1720 | // zooming and we don't want to mess them up) | |
1721 | bool state = settings.value(GlobalSettings::Key_View_ZoomToFitDuringAcq).toBool(); | |
1722 | if (is_main_view_ && state) { | |
1723 | always_zoom_to_fit_ = true; | |
1724 | always_zoom_to_fit_changed(always_zoom_to_fit_); | |
1725 | } | |
1726 | ||
1727 | // Enable sticky scrolling if the setting is enabled | |
1728 | sticky_scrolling_ = settings.value(GlobalSettings::Key_View_StickyScrolling).toBool(); | |
1729 | ||
1730 | // Reset all traces to segment 0 | |
1731 | current_segment_ = 0; | |
1732 | set_current_segment(current_segment_); | |
1733 | } | |
1734 | ||
1735 | if (state == Session::Stopped) { | |
1736 | // After acquisition has stopped we need to re-calculate the ticks once | |
1737 | // as it's otherwise done when the user pans or zooms, which is too late | |
1738 | calculate_tick_spacing(); | |
1739 | ||
1740 | // Reset "always zoom to fit", the acquisition has stopped | |
1741 | if (always_zoom_to_fit_) { | |
1742 | // Perform a final zoom-to-fit before disabling | |
1743 | zoom_fit(always_zoom_to_fit_); | |
1744 | always_zoom_to_fit_ = false; | |
1745 | always_zoom_to_fit_changed(always_zoom_to_fit_); | |
1746 | } | |
1747 | ||
1748 | bool zoom_to_fit_after_acq = | |
1749 | settings.value(GlobalSettings::Key_View_ZoomToFitAfterAcq).toBool(); | |
1750 | ||
1751 | // Only perform zoom-to-fit if the user hasn't altered the viewport and | |
1752 | // we didn't restore settings in the meanwhile | |
1753 | if (zoom_to_fit_after_acq && | |
1754 | !suppress_zoom_to_fit_after_acq_ && | |
1755 | (scale_ == scale_at_acq_start_) && | |
1756 | (offset_ == offset_at_acq_start_)) | |
1757 | zoom_fit(false); // We're stopped, so the GUI state doesn't matter | |
1758 | ||
1759 | suppress_zoom_to_fit_after_acq_ = false; | |
1760 | } | |
1761 | } | |
1762 | ||
1763 | void View::on_new_segment(int new_segment_id) | |
1764 | { | |
1765 | on_segment_changed(new_segment_id); | |
1766 | } | |
1767 | ||
1768 | void View::on_segment_completed(int segment_id) | |
1769 | { | |
1770 | on_segment_changed(segment_id); | |
1771 | } | |
1772 | ||
1773 | void View::on_segment_changed(int segment) | |
1774 | { | |
1775 | switch (segment_display_mode_) { | |
1776 | case Trace::ShowLastSegmentOnly: | |
1777 | case Trace::ShowSingleSegmentOnly: | |
1778 | set_current_segment(segment); | |
1779 | break; | |
1780 | ||
1781 | case Trace::ShowLastCompleteSegmentOnly: | |
1782 | // Only update if all segments are complete | |
1783 | if (session_.all_segments_complete(segment)) | |
1784 | set_current_segment(segment); | |
1785 | break; | |
1786 | ||
1787 | case Trace::ShowAllSegments: | |
1788 | case Trace::ShowAccumulatedIntensity: | |
1789 | default: | |
1790 | break; | |
1791 | } | |
1792 | } | |
1793 | ||
1794 | void View::on_settingViewTriggerIsZeroTime_changed(const QVariant new_value) | |
1795 | { | |
1796 | if (new_value.toBool()) { | |
1797 | // The first trigger for this segment is used as the zero position | |
1798 | vector<util::Timestamp> triggers = session_.get_triggers(current_segment_); | |
1799 | if (triggers.size() > 0) | |
1800 | set_zero_position(triggers.front()); | |
1801 | } else | |
1802 | reset_zero_position(); | |
1803 | } | |
1804 | ||
1805 | void View::perform_delayed_view_update() | |
1806 | { | |
1807 | if (always_zoom_to_fit_) { | |
1808 | zoom_fit(true); | |
1809 | } else if (sticky_scrolling_) { | |
1810 | // Make right side of the view sticky | |
1811 | double length = 0; | |
1812 | Timestamp offset; | |
1813 | get_scroll_layout(length, offset); | |
1814 | ||
1815 | const QSize areaSize = viewport_->size(); | |
1816 | length = max(length - areaSize.width(), 0.0); | |
1817 | ||
1818 | set_offset(scale_ * length); | |
1819 | } | |
1820 | ||
1821 | determine_time_unit(); | |
1822 | update_scroll(); | |
1823 | ruler_->update(); | |
1824 | viewport_->update(); | |
1825 | } | |
1826 | ||
1827 | void View::process_sticky_events() | |
1828 | { | |
1829 | if (sticky_events_ & TraceTreeItemHExtentsChanged) | |
1830 | update_layout(); | |
1831 | if (sticky_events_ & TraceTreeItemVExtentsChanged) { | |
1832 | restack_all_trace_tree_items(); | |
1833 | update_scroll(); | |
1834 | } | |
1835 | ||
1836 | // Clear the sticky events | |
1837 | sticky_events_ = 0; | |
1838 | } | |
1839 | ||
1840 | } // namespace trace | |
1841 | } // namespace views | |
1842 | } // namespace pv |