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