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