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