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