]>
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 | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
269528f5 | 21 | #ifdef ENABLE_DECODE |
4e5a4405 | 22 | #include <libsigrokdecode/libsigrokdecode.h> |
269528f5 | 23 | #endif |
4e5a4405 | 24 | |
361c560e JH |
25 | #include <extdef.h> |
26 | ||
cf124e47 | 27 | #include <algorithm> |
c3a740dd JH |
28 | #include <cassert> |
29 | #include <climits> | |
30 | #include <cmath> | |
cf124e47 | 31 | #include <iterator> |
c3a740dd | 32 | #include <mutex> |
7ff0145f | 33 | #include <unordered_set> |
adb4b10c | 34 | |
e71eb81c JH |
35 | #include <boost/thread/locks.hpp> |
36 | ||
361c560e | 37 | #include <QApplication> |
adb4b10c | 38 | #include <QEvent> |
361c560e | 39 | #include <QFontMetrics> |
cbd80f64 | 40 | #include <QMouseEvent> |
adb4b10c JH |
41 | #include <QScrollBar> |
42 | ||
fe3a1c21 | 43 | #include <libsigrokcxx/libsigrokcxx.hpp> |
448a72cf | 44 | |
2acdb232 JH |
45 | #include "decodetrace.hpp" |
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 | |
f65cd27b | 55 | #include "pv/session.hpp" |
da30ecb7 | 56 | #include "pv/devices/device.hpp" |
2acdb232 | 57 | #include "pv/data/logic.hpp" |
f3d66e52 | 58 | #include "pv/data/logicsegment.hpp" |
361c560e | 59 | #include "pv/util.hpp" |
adb4b10c | 60 | |
aca64cac JH |
61 | using boost::shared_lock; |
62 | using boost::shared_mutex; | |
361c560e | 63 | |
1bc6525b | 64 | using pv::data::SignalData; |
f3d66e52 | 65 | using pv::data::Segment; |
ef454ad5 | 66 | using pv::util::TimeUnit; |
60d9b99a | 67 | using pv::util::Timestamp; |
361c560e | 68 | |
769a79b5 JH |
69 | using std::back_inserter; |
70 | using std::copy_if; | |
819f4c25 | 71 | using std::deque; |
448a72cf | 72 | using std::dynamic_pointer_cast; |
cf124e47 | 73 | using std::inserter; |
819f4c25 | 74 | using std::list; |
c3a740dd | 75 | using std::lock_guard; |
819f4c25 | 76 | using std::max; |
1bc6525b | 77 | using std::make_pair; |
769a79b5 | 78 | using std::make_shared; |
819f4c25 | 79 | using std::min; |
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; |
f9abf97e | 87 | using std::weak_ptr; |
adb4b10c | 88 | |
cdf7bea7 JH |
89 | namespace pv { |
90 | namespace view { | |
adb4b10c | 91 | |
60d9b99a JS |
92 | const Timestamp View::MaxScale("1e9"); |
93 | const Timestamp View::MinScale("1e-12"); | |
adb4b10c | 94 | |
f25770e2 | 95 | const int View::MaxScrollValue = INT_MAX / 2; |
ce11b2ea | 96 | const int View::MaxViewAutoUpdateRate = 25; // No more than 25 Hz with sticky scrolling |
f25770e2 | 97 | |
361c560e JH |
98 | const int View::ScaleUnits[3] = {1, 2, 5}; |
99 | ||
2b81ae46 | 100 | View::View(Session &session, QWidget *parent) : |
adb4b10c | 101 | QAbstractScrollArea(parent), |
8dbbc7f0 JH |
102 | session_(session), |
103 | viewport_(new Viewport(*this)), | |
104 | ruler_(new Ruler(*this)), | |
8dbbc7f0 | 105 | header_(new Header(*this)), |
c0100b55 | 106 | scale_(1e-3), |
8dbbc7f0 | 107 | offset_(0), |
8dbbc7f0 | 108 | updating_scroll_(false), |
c7b03d9d | 109 | sticky_scrolling_(false), // Default setting is set in MainWindow::setup_ui() |
ce11b2ea | 110 | always_zoom_to_fit_(false), |
c677193d | 111 | tick_period_(0), |
d001f416 | 112 | tick_prefix_(pv::util::SIPrefix::yocto), |
d40f4db7 | 113 | tick_precision_(0), |
d001f416 | 114 | time_unit_(util::TimeUnit::Time), |
8dbbc7f0 | 115 | show_cursors_(false), |
5c5ce757 | 116 | cursors_(new CursorPair(*this)), |
8914fe79 | 117 | next_flag_text_('A'), |
92ff2b60 | 118 | trigger_markers_(), |
8dbbc7f0 | 119 | hover_point_(-1, -1) |
adb4b10c | 120 | { |
b16907d3 JH |
121 | connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), |
122 | this, SLOT(h_scroll_value_changed(int))); | |
adb4b10c | 123 | connect(verticalScrollBar(), SIGNAL(valueChanged(int)), |
f8400017 | 124 | this, SLOT(v_scroll_value_changed())); |
69dd2b03 | 125 | |
8dbbc7f0 | 126 | connect(&session_, SIGNAL(signals_changed()), |
69dd2b03 | 127 | this, SLOT(signals_changed())); |
8dbbc7f0 | 128 | connect(&session_, SIGNAL(capture_state_changed(int)), |
7ee199a7 | 129 | this, SLOT(capture_state_updated(int))); |
8dbbc7f0 | 130 | connect(&session_, SIGNAL(data_received()), |
1f374035 | 131 | this, SLOT(data_updated())); |
8dbbc7f0 | 132 | connect(&session_, SIGNAL(frame_ended()), |
adb4b10c | 133 | this, SLOT(data_updated())); |
1d8dca91 | 134 | |
8dbbc7f0 | 135 | connect(header_, SIGNAL(selection_changed()), |
819e2e95 JH |
136 | ruler_, SLOT(clear_selection())); |
137 | connect(ruler_, SIGNAL(selection_changed()), | |
8dbbc7f0 | 138 | header_, SLOT(clear_selection())); |
17348f85 | 139 | |
8dbbc7f0 | 140 | connect(header_, SIGNAL(selection_changed()), |
8b454527 | 141 | this, SIGNAL(selection_changed())); |
819e2e95 | 142 | connect(ruler_, SIGNAL(selection_changed()), |
8b454527 JH |
143 | this, SIGNAL(selection_changed())); |
144 | ||
33c62f44 JH |
145 | connect(this, SIGNAL(hover_point_changed()), |
146 | this, SLOT(on_hover_point_changed())); | |
147 | ||
8dbbc7f0 | 148 | connect(&lazy_event_handler_, SIGNAL(timeout()), |
32218d3e | 149 | this, SLOT(process_sticky_events())); |
8dbbc7f0 | 150 | lazy_event_handler_.setSingleShot(true); |
32218d3e | 151 | |
c7b03d9d SA |
152 | connect(&delayed_view_updater_, SIGNAL(timeout()), |
153 | this, SLOT(perform_delayed_view_update())); | |
154 | delayed_view_updater_.setSingleShot(true); | |
155 | delayed_view_updater_.setInterval(1000 / MaxViewAutoUpdateRate); | |
156 | ||
8dbbc7f0 | 157 | setViewport(viewport_); |
cbd80f64 | 158 | |
8dbbc7f0 JH |
159 | viewport_->installEventFilter(this); |
160 | ruler_->installEventFilter(this); | |
8dbbc7f0 | 161 | header_->installEventFilter(this); |
d873f4d6 | 162 | |
9f46d905 JH |
163 | // Trigger the initial event manually. The default device has signals |
164 | // which were created before this object came into being | |
d873f4d6 | 165 | signals_changed(); |
84a0d458 | 166 | |
512bfc56 | 167 | // make sure the transparent widgets are on the top |
819e2e95 | 168 | ruler_->raise(); |
8dbbc7f0 | 169 | header_->raise(); |
361c560e JH |
170 | |
171 | // Update the zoom state | |
172 | calculate_tick_spacing(); | |
adb4b10c JH |
173 | } |
174 | ||
2b81ae46 | 175 | Session& View::session() |
1d19ef83 | 176 | { |
8dbbc7f0 | 177 | return session_; |
1d19ef83 JH |
178 | } |
179 | ||
2b81ae46 | 180 | const Session& View::session() const |
38eeddea | 181 | { |
8dbbc7f0 | 182 | return session_; |
38eeddea JH |
183 | } |
184 | ||
eae6e30a JH |
185 | View* View::view() |
186 | { | |
187 | return this; | |
188 | } | |
189 | ||
190 | const View* View::view() const | |
191 | { | |
192 | return this; | |
193 | } | |
194 | ||
2ae445ba SA |
195 | Viewport* View::viewport() |
196 | { | |
8dbbc7f0 | 197 | return viewport_; |
2ae445ba SA |
198 | } |
199 | ||
200 | const Viewport* View::viewport() const | |
201 | { | |
8dbbc7f0 | 202 | return viewport_; |
2ae445ba SA |
203 | } |
204 | ||
2496bf45 JH |
205 | vector< shared_ptr<TimeItem> > View::time_items() const |
206 | { | |
8914fe79 JH |
207 | const vector<shared_ptr<Flag>> f(flags()); |
208 | vector<shared_ptr<TimeItem>> items(f.begin(), f.end()); | |
5a3e53f6 | 209 | items.push_back(cursors_); |
5c5ce757 JH |
210 | items.push_back(cursors_->first()); |
211 | items.push_back(cursors_->second()); | |
1a2288a1 | 212 | |
92ff2b60 TS |
213 | for (auto trigger_marker : trigger_markers_) |
214 | items.push_back(trigger_marker); | |
1a2288a1 | 215 | |
2496bf45 JH |
216 | return items; |
217 | } | |
218 | ||
cdf7bea7 | 219 | double View::scale() const |
adb4b10c | 220 | { |
8dbbc7f0 | 221 | return scale_; |
adb4b10c JH |
222 | } |
223 | ||
4b0af0b6 JS |
224 | void View::set_scale(double scale) |
225 | { | |
226 | if (scale_ != scale) { | |
227 | scale_ = scale; | |
228 | Q_EMIT scale_changed(); | |
229 | } | |
230 | } | |
231 | ||
60d9b99a | 232 | const Timestamp& View::offset() const |
adb4b10c | 233 | { |
8dbbc7f0 | 234 | return offset_; |
adb4b10c JH |
235 | } |
236 | ||
4b0af0b6 JS |
237 | void View::set_offset(const pv::util::Timestamp& offset) |
238 | { | |
239 | if (offset_ != offset) { | |
240 | offset_ = offset; | |
241 | Q_EMIT offset_changed(); | |
242 | } | |
243 | } | |
244 | ||
7ff0145f | 245 | int View::owner_visual_v_offset() const |
adb4b10c | 246 | { |
f8400017 | 247 | return -verticalScrollBar()->sliderPosition(); |
adb4b10c JH |
248 | } |
249 | ||
4d476647 JH |
250 | void View::set_v_offset(int offset) |
251 | { | |
252 | verticalScrollBar()->setSliderPosition(offset); | |
253 | header_->update(); | |
254 | viewport_->update(); | |
255 | } | |
256 | ||
3e769a37 JH |
257 | unsigned int View::depth() const |
258 | { | |
259 | return 0; | |
260 | } | |
261 | ||
d001f416 | 262 | pv::util::SIPrefix View::tick_prefix() const |
361c560e JH |
263 | { |
264 | return tick_prefix_; | |
265 | } | |
266 | ||
4b0af0b6 JS |
267 | void View::set_tick_prefix(pv::util::SIPrefix tick_prefix) |
268 | { | |
269 | if (tick_prefix_ != tick_prefix) { | |
270 | tick_prefix_ = tick_prefix; | |
271 | Q_EMIT tick_prefix_changed(); | |
272 | } | |
273 | } | |
274 | ||
d40f4db7 SA |
275 | unsigned int View::tick_precision() const |
276 | { | |
277 | return tick_precision_; | |
278 | } | |
279 | ||
4b0af0b6 JS |
280 | void View::set_tick_precision(unsigned tick_precision) |
281 | { | |
282 | if (tick_precision_ != tick_precision) { | |
283 | tick_precision_ = tick_precision; | |
284 | Q_EMIT tick_precision_changed(); | |
285 | } | |
286 | } | |
287 | ||
c677193d | 288 | const pv::util::Timestamp& View::tick_period() const |
361c560e JH |
289 | { |
290 | return tick_period_; | |
291 | } | |
292 | ||
c677193d | 293 | void View::set_tick_period(const pv::util::Timestamp& tick_period) |
4b0af0b6 JS |
294 | { |
295 | if (tick_period_ != tick_period) { | |
296 | tick_period_ = tick_period; | |
297 | Q_EMIT tick_period_changed(); | |
298 | } | |
299 | } | |
300 | ||
ef454ad5 SA |
301 | TimeUnit View::time_unit() const |
302 | { | |
303 | return time_unit_; | |
304 | } | |
305 | ||
4b0af0b6 JS |
306 | void View::set_time_unit(pv::util::TimeUnit time_unit) |
307 | { | |
308 | if (time_unit_ != time_unit) { | |
309 | time_unit_ = time_unit; | |
310 | Q_EMIT time_unit_changed(); | |
311 | } | |
312 | } | |
313 | ||
cdf7bea7 | 314 | void View::zoom(double steps) |
adb4b10c | 315 | { |
8dbbc7f0 | 316 | zoom(steps, viewport_->width() / 2); |
adb4b10c JH |
317 | } |
318 | ||
17c0f398 JH |
319 | void View::zoom(double steps, int offset) |
320 | { | |
8dbbc7f0 | 321 | set_zoom(scale_ * pow(3.0/2.0, -steps), offset); |
17c0f398 JH |
322 | } |
323 | ||
ce11b2ea | 324 | void View::zoom_fit(bool gui_state) |
ca46b534 | 325 | { |
ce11b2ea SA |
326 | // Act as one-shot when stopped, toggle along with the GUI otherwise |
327 | if (session_.get_capture_state() == Session::Stopped) { | |
328 | always_zoom_to_fit_ = false; | |
329 | always_zoom_to_fit_changed(false); | |
330 | } else { | |
331 | always_zoom_to_fit_ = gui_state; | |
332 | always_zoom_to_fit_changed(gui_state); | |
333 | } | |
334 | ||
60d9b99a JS |
335 | const pair<Timestamp, Timestamp> extents = get_time_extents(); |
336 | const Timestamp delta = extents.second - extents.first; | |
337 | if (delta < Timestamp("1e-12")) | |
ca46b534 JH |
338 | return; |
339 | ||
8dbbc7f0 JH |
340 | assert(viewport_); |
341 | const int w = viewport_->width(); | |
ca46b534 JH |
342 | if (w <= 0) |
343 | return; | |
344 | ||
60d9b99a JS |
345 | const Timestamp scale = max(min(delta / w, MaxScale), MinScale); |
346 | set_scale_offset(scale.convert_to<double>(), extents.first); | |
ca46b534 JH |
347 | } |
348 | ||
d1e7d82c JH |
349 | void View::zoom_one_to_one() |
350 | { | |
351 | using pv::data::SignalData; | |
352 | ||
d1e7d82c | 353 | // Make a set of all the visible data objects |
0fc664a9 | 354 | set< shared_ptr<SignalData> > visible_data = get_visible_data(); |
d1e7d82c JH |
355 | if (visible_data.empty()) |
356 | return; | |
357 | ||
8dbbc7f0 JH |
358 | assert(viewport_); |
359 | const int w = viewport_->width(); | |
d1e7d82c JH |
360 | if (w <= 0) |
361 | return; | |
362 | ||
2220e942 | 363 | set_zoom(1.0 / session_.get_samplerate(), w / 2); |
d1e7d82c JH |
364 | } |
365 | ||
60d9b99a | 366 | void View::set_scale_offset(double scale, const Timestamp& offset) |
adb4b10c | 367 | { |
ce11b2ea SA |
368 | // Disable sticky scrolling / always zoom to fit when acquisition runs |
369 | // and user drags the viewport | |
c7b03d9d | 370 | if ((scale_ == scale) && (offset_ != offset) && |
ce11b2ea SA |
371 | (session_.get_capture_state() == Session::Running)) { |
372 | ||
373 | if (sticky_scrolling_) { | |
374 | sticky_scrolling_ = false; | |
375 | sticky_scrolling_changed(false); | |
376 | } | |
377 | ||
378 | if (always_zoom_to_fit_) { | |
379 | always_zoom_to_fit_ = false; | |
380 | always_zoom_to_fit_changed(false); | |
381 | } | |
c7b03d9d SA |
382 | } |
383 | ||
4b0af0b6 JS |
384 | set_scale(scale); |
385 | set_offset(offset); | |
ccdd3ef5 | 386 | |
361c560e JH |
387 | calculate_tick_spacing(); |
388 | ||
adb4b10c | 389 | update_scroll(); |
8dbbc7f0 | 390 | ruler_->update(); |
8dbbc7f0 | 391 | viewport_->update(); |
adb4b10c JH |
392 | } |
393 | ||
1bc6525b JH |
394 | set< shared_ptr<SignalData> > View::get_visible_data() const |
395 | { | |
bf914698 | 396 | const unordered_set< shared_ptr<Signal> > sigs(session().signals()); |
1bc6525b JH |
397 | |
398 | // Make a set of all the visible data objects | |
399 | set< shared_ptr<SignalData> > visible_data; | |
d9aecf1f | 400 | for (const shared_ptr<Signal> sig : sigs) |
1bc6525b JH |
401 | if (sig->enabled()) |
402 | visible_data.insert(sig->data()); | |
403 | ||
404 | return visible_data; | |
405 | } | |
406 | ||
60d9b99a | 407 | pair<Timestamp, Timestamp> View::get_time_extents() const |
1bc6525b | 408 | { |
60d9b99a | 409 | boost::optional<Timestamp> left_time, right_time; |
7f4038d6 | 410 | const set< shared_ptr<SignalData> > visible_data = get_visible_data(); |
2ad82c2e | 411 | for (const shared_ptr<SignalData> d : visible_data) { |
f3d66e52 JH |
412 | const vector< shared_ptr<Segment> > segments = |
413 | d->segments(); | |
414 | for (const shared_ptr<Segment> &s : segments) { | |
ff008de6 JH |
415 | double samplerate = s->samplerate(); |
416 | samplerate = (samplerate <= 0.0) ? 1.0 : samplerate; | |
417 | ||
60d9b99a JS |
418 | const Timestamp start_time = s->start_time(); |
419 | left_time = left_time ? | |
420 | min(*left_time, start_time) : | |
421 | start_time; | |
422 | right_time = right_time ? | |
423 | max(*right_time, start_time + d->max_sample_count() / samplerate) : | |
424 | start_time + d->max_sample_count() / samplerate; | |
7f4038d6 | 425 | } |
1bc6525b JH |
426 | } |
427 | ||
60d9b99a JS |
428 | if (!left_time || !right_time) |
429 | return make_pair(0, 0); | |
7f4038d6 | 430 | |
60d9b99a JS |
431 | assert(*left_time < *right_time); |
432 | return make_pair(*left_time, *right_time); | |
1bc6525b JH |
433 | } |
434 | ||
c7b03d9d SA |
435 | void View::enable_sticky_scrolling(bool state) |
436 | { | |
437 | sticky_scrolling_ = state; | |
438 | } | |
439 | ||
f76af637 JH |
440 | bool View::cursors_shown() const |
441 | { | |
8dbbc7f0 | 442 | return show_cursors_; |
f76af637 JH |
443 | } |
444 | ||
445 | void View::show_cursors(bool show) | |
446 | { | |
8dbbc7f0 | 447 | show_cursors_ = show; |
819e2e95 | 448 | ruler_->update(); |
8dbbc7f0 | 449 | viewport_->update(); |
f76af637 JH |
450 | } |
451 | ||
b4d91e56 JH |
452 | void View::centre_cursors() |
453 | { | |
8dbbc7f0 | 454 | const double time_width = scale_ * viewport_->width(); |
5c5ce757 JH |
455 | cursors_->first()->set_time(offset_ + time_width * 0.4); |
456 | cursors_->second()->set_time(offset_ + time_width * 0.6); | |
819e2e95 | 457 | ruler_->update(); |
8dbbc7f0 | 458 | viewport_->update(); |
b4d91e56 JH |
459 | } |
460 | ||
5c5ce757 | 461 | std::shared_ptr<CursorPair> View::cursors() const |
58864c5c | 462 | { |
8dbbc7f0 | 463 | return cursors_; |
58864c5c JH |
464 | } |
465 | ||
60d9b99a | 466 | void View::add_flag(const Timestamp& time) |
8914fe79 JH |
467 | { |
468 | flags_.push_back(shared_ptr<Flag>(new Flag(*this, time, | |
469 | QString("%1").arg(next_flag_text_)))); | |
48257a69 | 470 | |
8914fe79 JH |
471 | next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' : |
472 | (next_flag_text_ + 1); | |
48257a69 | 473 | |
8914fe79 JH |
474 | time_item_appearance_changed(true, true); |
475 | } | |
476 | ||
477 | void View::remove_flag(std::shared_ptr<Flag> flag) | |
478 | { | |
479 | flags_.remove(flag); | |
480 | time_item_appearance_changed(true, true); | |
481 | } | |
482 | ||
483 | vector< std::shared_ptr<Flag> > View::flags() const | |
484 | { | |
485 | vector< std::shared_ptr<Flag> > flags(flags_.begin(), flags_.end()); | |
486 | stable_sort(flags.begin(), flags.end(), | |
487 | [](const shared_ptr<Flag> &a, const shared_ptr<Flag> &b) { | |
488 | return a->time() < b->time(); | |
489 | }); | |
490 | ||
491 | return flags; | |
492 | } | |
493 | ||
cbd80f64 JH |
494 | const QPoint& View::hover_point() const |
495 | { | |
8dbbc7f0 | 496 | return hover_point_; |
cbd80f64 JH |
497 | } |
498 | ||
9cef9567 JH |
499 | void View::update_viewport() |
500 | { | |
8dbbc7f0 JH |
501 | assert(viewport_); |
502 | viewport_->update(); | |
503 | header_->update(); | |
7ff0145f JH |
504 | } |
505 | ||
af503b10 | 506 | void View::restack_all_trace_tree_items() |
7ff0145f | 507 | { |
873cbed0 | 508 | // Make a list of owners that is sorted from deepest first |
cc88566c JH |
509 | const vector<shared_ptr<TraceTreeItem>> items( |
510 | list_by_type<TraceTreeItem>()); | |
4800cf9a | 511 | set< TraceTreeItemOwner* > owners; |
cc88566c | 512 | for (const auto &r : items) |
4800cf9a | 513 | owners.insert(r->owner()); |
af503b10 | 514 | vector< TraceTreeItemOwner* > sorted_owners(owners.begin(), owners.end()); |
7ff0145f | 515 | sort(sorted_owners.begin(), sorted_owners.end(), |
af503b10 | 516 | [](const TraceTreeItemOwner* a, const TraceTreeItemOwner *b) { |
7ff0145f JH |
517 | return a->depth() > b->depth(); }); |
518 | ||
519 | // Restack the items recursively | |
520 | for (auto &o : sorted_owners) | |
521 | o->restack_items(); | |
522 | ||
523 | // Animate the items to their destination | |
cef5997e JH |
524 | for (const auto &i : items) |
525 | i->animate_to_layout_v_offset(); | |
9cef9567 JH |
526 | } |
527 | ||
48257a69 SA |
528 | void View::trigger_event(util::Timestamp location) |
529 | { | |
92ff2b60 TS |
530 | trigger_markers_.push_back(shared_ptr<TriggerMarker>( |
531 | new TriggerMarker(*this, location))); | |
48257a69 SA |
532 | } |
533 | ||
60d9b99a | 534 | void View::get_scroll_layout(double &length, Timestamp &offset) const |
f25770e2 | 535 | { |
60d9b99a JS |
536 | const pair<Timestamp, Timestamp> extents = get_time_extents(); |
537 | length = ((extents.second - extents.first) / scale_).convert_to<double>(); | |
8dbbc7f0 | 538 | offset = offset_ / scale_; |
f25770e2 JH |
539 | } |
540 | ||
d1e7d82c JH |
541 | void View::set_zoom(double scale, int offset) |
542 | { | |
ce11b2ea SA |
543 | // Reset the "always zoom to fit" feature as the user changed the zoom |
544 | always_zoom_to_fit_ = false; | |
545 | always_zoom_to_fit_changed(false); | |
546 | ||
60d9b99a JS |
547 | const Timestamp cursor_offset = offset_ + scale_ * offset; |
548 | const Timestamp new_scale = max(min(Timestamp(scale), MaxScale), MinScale); | |
549 | const Timestamp new_offset = cursor_offset - new_scale * offset; | |
550 | set_scale_offset(new_scale.convert_to<double>(), new_offset); | |
d1e7d82c JH |
551 | } |
552 | ||
361c560e JH |
553 | void View::calculate_tick_spacing() |
554 | { | |
8a1bc087 | 555 | const double SpacingIncrement = 10.0f; |
8a463dbc | 556 | const double MinValueSpacing = 40.0f; |
361c560e | 557 | |
1e124d4b SA |
558 | // Figure out the highest numeric value visible on a label |
559 | const QSize areaSize = viewport_->size(); | |
60d9b99a | 560 | const Timestamp max_time = max(fabs(offset_), |
1e124d4b SA |
561 | fabs(offset_ + scale_ * areaSize.width())); |
562 | ||
d40f4db7 SA |
563 | double min_width = SpacingIncrement; |
564 | double label_width, tick_period_width; | |
361c560e JH |
565 | |
566 | QFontMetrics m(QApplication::font()); | |
567 | ||
adb3831e JS |
568 | // Copies of the member variables with the same name, used in the calculation |
569 | // and written back afterwards, so that we don't emit signals all the time | |
570 | // during the calculation. | |
571 | pv::util::Timestamp tick_period = tick_period_; | |
572 | pv::util::SIPrefix tick_prefix = tick_prefix_; | |
573 | unsigned tick_precision = tick_precision_; | |
574 | ||
361c560e JH |
575 | do { |
576 | const double min_period = scale_ * min_width; | |
577 | ||
578 | const int order = (int)floorf(log10f(min_period)); | |
c677193d JS |
579 | const pv::util::Timestamp order_decimal = |
580 | pow(pv::util::Timestamp(10), order); | |
361c560e | 581 | |
8a1bc087 SA |
582 | // Allow for a margin of error so that a scale unit of 1 can be used. |
583 | // Otherwise, for a SU of 1 the tick period will almost always be below | |
584 | // the min_period by a small amount - and thus skipped in favor of 2. | |
585 | // Note: margin assumes that SU[0] and SU[1] contain the smallest values | |
586 | double tp_margin = (ScaleUnits[0] + ScaleUnits[1]) / 2.0; | |
587 | double tp_with_margin; | |
361c560e JH |
588 | unsigned int unit = 0; |
589 | ||
590 | do { | |
c677193d JS |
591 | tp_with_margin = order_decimal.convert_to<double>() * |
592 | (ScaleUnits[unit++] + tp_margin); | |
8a1bc087 | 593 | } while (tp_with_margin < min_period && unit < countof(ScaleUnits)); |
361c560e | 594 | |
adb3831e JS |
595 | tick_period = order_decimal * ScaleUnits[unit - 1]; |
596 | tick_prefix = static_cast<pv::util::SIPrefix>( | |
597 | (order - pv::util::exponent(pv::util::SIPrefix::yocto)) / 3); | |
361c560e | 598 | |
d40f4db7 SA |
599 | // Precision is the number of fractional digits required, not |
600 | // taking the prefix into account (and it must never be negative) | |
adb3831e | 601 | tick_precision = std::max(ceil(log10(1 / tick_period)).convert_to<int>(), 0); |
d40f4db7 | 602 | |
adb3831e | 603 | tick_period_width = (tick_period / scale_).convert_to<double>(); |
d40f4db7 | 604 | |
3ccf0f7f JS |
605 | const QString label_text = Ruler::format_time_with_distance( |
606 | tick_period, max_time, tick_prefix, time_unit_, tick_precision); | |
d40f4db7 SA |
607 | |
608 | label_width = m.boundingRect(0, 0, INT_MAX, INT_MAX, | |
609 | Qt::AlignLeft | Qt::AlignTop, label_text).width() + | |
361c560e JH |
610 | MinValueSpacing; |
611 | ||
612 | min_width += SpacingIncrement; | |
d40f4db7 | 613 | } while (tick_period_width < label_width); |
adb3831e JS |
614 | |
615 | set_tick_period(tick_period); | |
616 | set_tick_prefix(tick_prefix); | |
617 | set_tick_precision(tick_precision); | |
361c560e JH |
618 | } |
619 | ||
cdf7bea7 | 620 | void View::update_scroll() |
adb4b10c | 621 | { |
8dbbc7f0 | 622 | assert(viewport_); |
adb4b10c | 623 | |
8dbbc7f0 | 624 | const QSize areaSize = viewport_->size(); |
adb4b10c JH |
625 | |
626 | // Set the horizontal scroll bar | |
60d9b99a JS |
627 | double length = 0; |
628 | Timestamp offset; | |
f25770e2 JH |
629 | get_scroll_layout(length, offset); |
630 | length = max(length - areaSize.width(), 0.0); | |
adb4b10c | 631 | |
c677193d | 632 | int major_tick_distance = (tick_period_ / scale_).convert_to<int>(); |
d7aae647 | 633 | |
b4ef7f2a | 634 | horizontalScrollBar()->setPageStep(areaSize.width() / 2); |
d7aae647 | 635 | horizontalScrollBar()->setSingleStep(major_tick_distance); |
f25770e2 | 636 | |
8dbbc7f0 | 637 | updating_scroll_ = true; |
528bd8a1 | 638 | |
333d5bbc | 639 | if (length < MaxScrollValue) { |
f25770e2 | 640 | horizontalScrollBar()->setRange(0, length); |
60d9b99a | 641 | horizontalScrollBar()->setSliderPosition(offset.convert_to<double>()); |
f25770e2 JH |
642 | } else { |
643 | horizontalScrollBar()->setRange(0, MaxScrollValue); | |
644 | horizontalScrollBar()->setSliderPosition( | |
60d9b99a | 645 | (offset_ * MaxScrollValue / (scale_ * length)).convert_to<double>()); |
f25770e2 | 646 | } |
adb4b10c | 647 | |
8dbbc7f0 | 648 | updating_scroll_ = false; |
528bd8a1 | 649 | |
adb4b10c JH |
650 | // Set the vertical scrollbar |
651 | verticalScrollBar()->setPageStep(areaSize.height()); | |
65c34596 | 652 | verticalScrollBar()->setSingleStep(areaSize.height() / 8); |
a5d93c27 JH |
653 | |
654 | const pair<int, int> extents = v_extents(); | |
f1d9ac67 SA |
655 | verticalScrollBar()->setRange(extents.first - (areaSize.height() / 2), |
656 | extents.second - (areaSize.height() / 2)); | |
adb4b10c JH |
657 | } |
658 | ||
d7c0ca4a JH |
659 | void View::update_layout() |
660 | { | |
512bfc56 | 661 | setViewportMargins( |
8dbbc7f0 JH |
662 | header_->sizeHint().width() - pv::view::Header::BaselineOffset, |
663 | ruler_->sizeHint().height(), 0, 0); | |
664 | ruler_->setGeometry(viewport_->x(), 0, | |
819e2e95 | 665 | viewport_->width(), ruler_->extended_size_hint().height()); |
8dbbc7f0 | 666 | header_->setGeometry(0, viewport_->y(), |
819e2e95 | 667 | header_->extended_size_hint().width(), viewport_->height()); |
d7c0ca4a JH |
668 | update_scroll(); |
669 | } | |
670 | ||
b3f44329 | 671 | void View::paint_label(QPainter &p, const QRect &rect, bool hover) |
eae6e30a JH |
672 | { |
673 | (void)p; | |
b3f44329 | 674 | (void)rect; |
eae6e30a JH |
675 | (void)hover; |
676 | } | |
677 | ||
b3f44329 | 678 | QRectF View::label_rect(const QRectF &rect) |
eae6e30a | 679 | { |
b3f44329 | 680 | (void)rect; |
eae6e30a JH |
681 | return QRectF(); |
682 | } | |
683 | ||
af503b10 | 684 | TraceTreeItemOwner* View::find_prevalent_trace_group( |
cf124e47 JH |
685 | const shared_ptr<sigrok::ChannelGroup> &group, |
686 | const unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> > | |
687 | &signal_map) | |
448a72cf | 688 | { |
cf124e47 | 689 | assert(group); |
448a72cf | 690 | |
af503b10 JH |
691 | unordered_set<TraceTreeItemOwner*> owners; |
692 | vector<TraceTreeItemOwner*> owner_list; | |
448a72cf | 693 | |
cf124e47 JH |
694 | // Make a set and a list of all the owners |
695 | for (const auto &channel : group->channels()) { | |
448a72cf | 696 | const auto iter = signal_map.find(channel); |
cf124e47 | 697 | if (iter == signal_map.end()) |
448a72cf JH |
698 | continue; |
699 | ||
af503b10 | 700 | TraceTreeItemOwner *const o = (*iter).second->owner(); |
cf124e47 JH |
701 | owner_list.push_back(o); |
702 | owners.insert(o); | |
703 | } | |
448a72cf | 704 | |
cf124e47 JH |
705 | // Iterate through the list of owners, and find the most prevalent |
706 | size_t max_prevalence = 0; | |
af503b10 JH |
707 | TraceTreeItemOwner *prevalent_owner = nullptr; |
708 | for (TraceTreeItemOwner *owner : owners) { | |
cf124e47 JH |
709 | const size_t prevalence = std::count_if( |
710 | owner_list.begin(), owner_list.end(), | |
af503b10 | 711 | [&](TraceTreeItemOwner *o) { return o == owner; }); |
cf124e47 JH |
712 | if (prevalence > max_prevalence) { |
713 | max_prevalence = prevalence; | |
714 | prevalent_owner = owner; | |
715 | } | |
448a72cf JH |
716 | } |
717 | ||
cf124e47 | 718 | return prevalent_owner; |
448a72cf JH |
719 | } |
720 | ||
cf124e47 JH |
721 | vector< shared_ptr<Trace> > View::extract_new_traces_for_channels( |
722 | const vector< shared_ptr<sigrok::Channel> > &channels, | |
723 | const unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> > | |
724 | &signal_map, | |
725 | set< shared_ptr<Trace> > &add_list) | |
726 | { | |
727 | vector< shared_ptr<Trace> > filtered_traces; | |
728 | ||
2ad82c2e | 729 | for (const auto &channel : channels) { |
cf124e47 JH |
730 | const auto map_iter = signal_map.find(channel); |
731 | if (map_iter == signal_map.end()) | |
732 | continue; | |
733 | ||
734 | shared_ptr<Trace> trace = (*map_iter).second; | |
735 | const auto list_iter = add_list.find(trace); | |
736 | if (list_iter == add_list.end()) | |
737 | continue; | |
738 | ||
739 | filtered_traces.push_back(trace); | |
740 | add_list.erase(list_iter); | |
741 | } | |
742 | ||
743 | return filtered_traces; | |
448a72cf JH |
744 | } |
745 | ||
ef454ad5 SA |
746 | void View::determine_time_unit() |
747 | { | |
7ee199a7 | 748 | // Check whether we know the sample rate and hence can use time as the unit |
d001f416 | 749 | if (time_unit_ == util::TimeUnit::Samples) { |
bf914698 | 750 | const unordered_set< shared_ptr<Signal> > sigs(session().signals()); |
7ee199a7 SA |
751 | |
752 | // Check all signals but... | |
753 | for (const shared_ptr<Signal> signal : sigs) { | |
754 | const shared_ptr<SignalData> data = signal->data(); | |
755 | ||
756 | // ...only check first segment of each | |
757 | const vector< shared_ptr<Segment> > segments = data->segments(); | |
758 | if (!segments.empty()) | |
759 | if (segments[0]->samplerate()) { | |
4b0af0b6 | 760 | set_time_unit(util::TimeUnit::Time); |
7ee199a7 SA |
761 | break; |
762 | } | |
763 | } | |
ef454ad5 SA |
764 | } |
765 | } | |
766 | ||
cbd80f64 JH |
767 | bool View::eventFilter(QObject *object, QEvent *event) |
768 | { | |
769 | const QEvent::Type type = event->type(); | |
333d5bbc | 770 | if (type == QEvent::MouseMove) { |
cbd80f64 JH |
771 | |
772 | const QMouseEvent *const mouse_event = (QMouseEvent*)event; | |
8dbbc7f0 JH |
773 | if (object == viewport_) |
774 | hover_point_ = mouse_event->pos(); | |
819e2e95 | 775 | else if (object == ruler_) |
8dbbc7f0 JH |
776 | hover_point_ = QPoint(mouse_event->x(), 0); |
777 | else if (object == header_) | |
778 | hover_point_ = QPoint(0, mouse_event->y()); | |
cbd80f64 | 779 | else |
8dbbc7f0 | 780 | hover_point_ = QPoint(-1, -1); |
cbd80f64 JH |
781 | |
782 | hover_point_changed(); | |
783 | ||
333d5bbc | 784 | } else if (type == QEvent::Leave) { |
8dbbc7f0 | 785 | hover_point_ = QPoint(-1, -1); |
cbd80f64 JH |
786 | hover_point_changed(); |
787 | } | |
788 | ||
789 | return QObject::eventFilter(object, event); | |
790 | } | |
791 | ||
cdf7bea7 | 792 | bool View::viewportEvent(QEvent *e) |
adb4b10c | 793 | { |
2ad82c2e | 794 | switch (e->type()) { |
adb4b10c JH |
795 | case QEvent::Paint: |
796 | case QEvent::MouseButtonPress: | |
797 | case QEvent::MouseButtonRelease: | |
798 | case QEvent::MouseButtonDblClick: | |
799 | case QEvent::MouseMove: | |
800 | case QEvent::Wheel: | |
4b4f1c0d MC |
801 | case QEvent::TouchBegin: |
802 | case QEvent::TouchUpdate: | |
803 | case QEvent::TouchEnd: | |
adb4b10c | 804 | return false; |
adb4b10c JH |
805 | default: |
806 | return QAbstractScrollArea::viewportEvent(e); | |
807 | } | |
808 | } | |
809 | ||
e314eca4 | 810 | void View::resizeEvent(QResizeEvent*) |
adb4b10c | 811 | { |
d7c0ca4a | 812 | update_layout(); |
adb4b10c JH |
813 | } |
814 | ||
6e2c3c85 | 815 | void View::row_item_appearance_changed(bool label, bool content) |
32218d3e JH |
816 | { |
817 | if (label) | |
8dbbc7f0 | 818 | header_->update(); |
32218d3e | 819 | if (content) |
8dbbc7f0 | 820 | viewport_->update(); |
32218d3e JH |
821 | } |
822 | ||
98cfe4e8 JH |
823 | void View::time_item_appearance_changed(bool label, bool content) |
824 | { | |
825 | if (label) | |
819e2e95 | 826 | ruler_->update(); |
98cfe4e8 JH |
827 | if (content) |
828 | viewport_->update(); | |
829 | } | |
830 | ||
32218d3e JH |
831 | void View::extents_changed(bool horz, bool vert) |
832 | { | |
8dbbc7f0 | 833 | sticky_events_ |= |
af503b10 JH |
834 | (horz ? TraceTreeItemHExtentsChanged : 0) | |
835 | (vert ? TraceTreeItemVExtentsChanged : 0); | |
8dbbc7f0 | 836 | lazy_event_handler_.start(); |
32218d3e JH |
837 | } |
838 | ||
b16907d3 | 839 | void View::h_scroll_value_changed(int value) |
adb4b10c | 840 | { |
8dbbc7f0 | 841 | if (updating_scroll_) |
528bd8a1 JH |
842 | return; |
843 | ||
c7b03d9d SA |
844 | // Disable sticky scrolling when user moves the horizontal scroll bar |
845 | // during a running acquisition | |
846 | if (sticky_scrolling_ && (session_.get_capture_state() == Session::Running)) { | |
847 | sticky_scrolling_ = false; | |
848 | sticky_scrolling_changed(false); | |
849 | } | |
850 | ||
f25770e2 | 851 | const int range = horizontalScrollBar()->maximum(); |
333d5bbc | 852 | if (range < MaxScrollValue) |
4b0af0b6 | 853 | set_offset(scale_ * value); |
f25770e2 | 854 | else { |
60d9b99a JS |
855 | double length = 0; |
856 | Timestamp offset; | |
f25770e2 | 857 | get_scroll_layout(length, offset); |
4b0af0b6 | 858 | set_offset(scale_ * length * value / MaxScrollValue); |
f25770e2 JH |
859 | } |
860 | ||
8dbbc7f0 | 861 | ruler_->update(); |
8dbbc7f0 | 862 | viewport_->update(); |
adb4b10c JH |
863 | } |
864 | ||
f8400017 | 865 | void View::v_scroll_value_changed() |
adb4b10c | 866 | { |
8dbbc7f0 JH |
867 | header_->update(); |
868 | viewport_->update(); | |
adb4b10c JH |
869 | } |
870 | ||
69dd2b03 JH |
871 | void View::signals_changed() |
872 | { | |
769a79b5 JH |
873 | using sigrok::Channel; |
874 | ||
af503b10 | 875 | vector< shared_ptr<TraceTreeItem> > new_top_level_items; |
68b21a71 | 876 | |
e37e05f7 JH |
877 | const auto device = session_.device(); |
878 | if (!device) | |
879 | return; | |
880 | ||
881 | shared_ptr<sigrok::Device> sr_dev = device->device(); | |
882 | assert(sr_dev); | |
448a72cf | 883 | |
769a79b5 JH |
884 | const vector< shared_ptr<Channel> > channels( |
885 | sr_dev->channels()); | |
886 | ||
cf124e47 JH |
887 | // Make a list of traces that are being added, and a list of traces |
888 | // that are being removed | |
364d2155 JH |
889 | const vector<shared_ptr<Trace>> prev_trace_list = list_by_type<Trace>(); |
890 | const set<shared_ptr<Trace>> prev_traces( | |
891 | prev_trace_list.begin(), prev_trace_list.end()); | |
448a72cf | 892 | |
bf914698 | 893 | const unordered_set< shared_ptr<Signal> > sigs(session_.signals()); |
448a72cf | 894 | |
cf124e47 JH |
895 | set< shared_ptr<Trace> > traces(sigs.begin(), sigs.end()); |
896 | ||
897 | #ifdef ENABLE_DECODE | |
898 | const vector< shared_ptr<DecodeTrace> > decode_traces( | |
899 | session().get_decode_signals()); | |
900 | traces.insert(decode_traces.begin(), decode_traces.end()); | |
901 | #endif | |
902 | ||
903 | set< shared_ptr<Trace> > add_traces; | |
904 | set_difference(traces.begin(), traces.end(), | |
905 | prev_traces.begin(), prev_traces.end(), | |
906 | inserter(add_traces, add_traces.begin())); | |
907 | ||
908 | set< shared_ptr<Trace> > remove_traces; | |
909 | set_difference(prev_traces.begin(), prev_traces.end(), | |
910 | traces.begin(), traces.end(), | |
911 | inserter(remove_traces, remove_traces.begin())); | |
912 | ||
913 | // Make a look-up table of sigrok Channels to pulseview Signals | |
914 | unordered_map<shared_ptr<sigrok::Channel>, shared_ptr<Signal> > | |
915 | signal_map; | |
448a72cf JH |
916 | for (const shared_ptr<Signal> &sig : sigs) |
917 | signal_map[sig->channel()] = sig; | |
918 | ||
919 | // Populate channel groups | |
2ad82c2e | 920 | for (auto entry : sr_dev->channel_groups()) { |
448a72cf JH |
921 | const shared_ptr<sigrok::ChannelGroup> &group = entry.second; |
922 | ||
923 | if (group->channels().size() <= 1) | |
924 | continue; | |
925 | ||
cf124e47 | 926 | // Find best trace group to add to |
af503b10 | 927 | TraceTreeItemOwner *owner = find_prevalent_trace_group( |
cf124e47 | 928 | group, signal_map); |
448a72cf | 929 | |
cf124e47 JH |
930 | // If there is no trace group, create one |
931 | shared_ptr<TraceGroup> new_trace_group; | |
932 | if (!owner) { | |
933 | new_trace_group.reset(new TraceGroup()); | |
934 | owner = new_trace_group.get(); | |
935 | } | |
448a72cf | 936 | |
cf124e47 JH |
937 | // Extract traces for the trace group, removing them from |
938 | // the add list | |
939 | const vector< shared_ptr<Trace> > new_traces_in_group = | |
940 | extract_new_traces_for_channels(group->channels(), | |
941 | signal_map, add_traces); | |
942 | ||
943 | // Add the traces to the group | |
944 | const pair<int, int> prev_v_extents = owner->v_extents(); | |
945 | int offset = prev_v_extents.second - prev_v_extents.first; | |
946 | for (shared_ptr<Trace> trace : new_traces_in_group) { | |
947 | assert(trace); | |
948 | owner->add_child_item(trace); | |
949 | ||
950 | const pair<int, int> extents = trace->v_extents(); | |
951 | if (trace->enabled()) | |
952 | offset += -extents.first; | |
953 | trace->force_to_v_offset(offset); | |
954 | if (trace->enabled()) | |
955 | offset += extents.second; | |
956 | } | |
68b21a71 | 957 | |
cf124e47 JH |
958 | // If this is a new group, enqueue it in the new top level |
959 | // items list | |
960 | if (!new_traces_in_group.empty() && new_trace_group) | |
961 | new_top_level_items.push_back(new_trace_group); | |
448a72cf JH |
962 | } |
963 | ||
769a79b5 JH |
964 | // Enqueue the remaining logic channels in a group |
965 | vector< shared_ptr<Channel> > logic_channels; | |
966 | copy_if(channels.begin(), channels.end(), back_inserter(logic_channels), | |
967 | [](const shared_ptr<Channel>& c) { | |
968 | return c->type() == sigrok::ChannelType::LOGIC; }); | |
969 | const vector< shared_ptr<Trace> > non_grouped_logic_signals = | |
970 | extract_new_traces_for_channels(logic_channels, | |
971 | signal_map, add_traces); | |
972 | const shared_ptr<TraceGroup> non_grouped_trace_group( | |
973 | make_shared<TraceGroup>()); | |
974 | for (shared_ptr<Trace> trace : non_grouped_logic_signals) | |
975 | non_grouped_trace_group->add_child_item(trace); | |
976 | new_top_level_items.push_back(non_grouped_trace_group); | |
977 | ||
cf124e47 JH |
978 | // Enqueue the remaining channels as free ungrouped traces |
979 | const vector< shared_ptr<Trace> > new_top_level_signals = | |
769a79b5 | 980 | extract_new_traces_for_channels(channels, |
cf124e47 JH |
981 | signal_map, add_traces); |
982 | new_top_level_items.insert(new_top_level_items.end(), | |
983 | new_top_level_signals.begin(), new_top_level_signals.end()); | |
984 | ||
985 | // Enqueue any remaining traces i.e. decode traces | |
986 | new_top_level_items.insert(new_top_level_items.end(), | |
987 | add_traces.begin(), add_traces.end()); | |
988 | ||
989 | // Remove any removed traces | |
990 | for (shared_ptr<Trace> trace : remove_traces) { | |
af503b10 | 991 | TraceTreeItemOwner *const owner = trace->owner(); |
cf124e47 JH |
992 | assert(owner); |
993 | owner->remove_child_item(trace); | |
994 | } | |
448a72cf | 995 | |
cf124e47 JH |
996 | // Add and position the pending top levels items |
997 | for (auto item : new_top_level_items) { | |
998 | add_child_item(item); | |
999 | ||
1000 | // Position the item after the last present item | |
1001 | int offset = v_extents().second; | |
1002 | const pair<int, int> extents = item->v_extents(); | |
1003 | if (item->enabled()) | |
1004 | offset += -extents.first; | |
1005 | item->force_to_v_offset(offset); | |
1006 | if (item->enabled()) | |
1007 | offset += extents.second; | |
ef8311a4 JH |
1008 | } |
1009 | ||
a6c1726e | 1010 | update_layout(); |
cf124e47 JH |
1011 | |
1012 | header_->update(); | |
1013 | viewport_->update(); | |
69dd2b03 JH |
1014 | } |
1015 | ||
7ee199a7 | 1016 | void View::capture_state_updated(int state) |
adb4b10c | 1017 | { |
92ff2b60 | 1018 | if (state == Session::Running) { |
4b0af0b6 | 1019 | set_time_unit(util::TimeUnit::Samples); |
fd03a279 | 1020 | |
92ff2b60 TS |
1021 | trigger_markers_.clear(); |
1022 | } | |
1023 | ||
fd03a279 SA |
1024 | if (state == Session::Stopped) { |
1025 | // After acquisition has stopped we need to re-calculate the ticks once | |
1026 | // as it's otherwise done when the user pans or zooms, which is too late | |
1027 | calculate_tick_spacing(); | |
1028 | ||
1029 | // Reset "always zoom to fit", the acquisition has stopped | |
1030 | if (always_zoom_to_fit_) { | |
1031 | always_zoom_to_fit_ = false; | |
1032 | always_zoom_to_fit_changed(false); | |
1033 | } | |
1034 | } | |
7ee199a7 SA |
1035 | } |
1036 | ||
1037 | void View::data_updated() | |
1038 | { | |
ce11b2ea | 1039 | if (always_zoom_to_fit_ || sticky_scrolling_) { |
c7b03d9d SA |
1040 | if (!delayed_view_updater_.isActive()) |
1041 | delayed_view_updater_.start(); | |
1042 | } else { | |
ef454ad5 | 1043 | determine_time_unit(); |
c7b03d9d SA |
1044 | update_scroll(); |
1045 | ruler_->update(); | |
1046 | viewport_->update(); | |
1047 | } | |
1048 | } | |
1049 | ||
1050 | void View::perform_delayed_view_update() | |
1051 | { | |
ce11b2ea SA |
1052 | if (always_zoom_to_fit_) |
1053 | zoom_fit(true); | |
1054 | ||
c7b03d9d SA |
1055 | if (sticky_scrolling_) { |
1056 | // Make right side of the view sticky | |
60d9b99a JS |
1057 | double length = 0; |
1058 | Timestamp offset; | |
c7b03d9d SA |
1059 | get_scroll_layout(length, offset); |
1060 | ||
1061 | const QSize areaSize = viewport_->size(); | |
1062 | length = max(length - areaSize.width(), 0.0); | |
1063 | ||
4b0af0b6 | 1064 | set_offset(scale_ * length); |
c7b03d9d | 1065 | } |
adb4b10c | 1066 | |
ef454ad5 | 1067 | determine_time_unit(); |
c7b03d9d SA |
1068 | update_scroll(); |
1069 | ruler_->update(); | |
8dbbc7f0 | 1070 | viewport_->update(); |
adb4b10c | 1071 | } |
cdf7bea7 | 1072 | |
32218d3e | 1073 | void View::process_sticky_events() |
d7c0ca4a | 1074 | { |
af503b10 | 1075 | if (sticky_events_ & TraceTreeItemHExtentsChanged) |
32218d3e | 1076 | update_layout(); |
af503b10 JH |
1077 | if (sticky_events_ & TraceTreeItemVExtentsChanged) { |
1078 | restack_all_trace_tree_items(); | |
f15bb3bc JH |
1079 | update_scroll(); |
1080 | } | |
32218d3e JH |
1081 | |
1082 | // Clear the sticky events | |
8dbbc7f0 | 1083 | sticky_events_ = 0; |
d7c0ca4a JH |
1084 | } |
1085 | ||
33c62f44 JH |
1086 | void View::on_hover_point_changed() |
1087 | { | |
cc88566c JH |
1088 | const vector<shared_ptr<TraceTreeItem>> trace_tree_items( |
1089 | list_by_type<TraceTreeItem>()); | |
1090 | for (shared_ptr<TraceTreeItem> r : trace_tree_items) | |
eae6e30a | 1091 | r->hover_point_changed(); |
33c62f44 JH |
1092 | } |
1093 | ||
cdf7bea7 JH |
1094 | } // namespace view |
1095 | } // namespace pv |