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