From: Joel Holdsworth Date: Sat, 15 Nov 2014 10:04:52 +0000 (+0000) Subject: RowItem: Split appart visual and layout v offsets X-Git-Tag: pulseview-0.3.0~451 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=be9e7b4bb29b6594ec2b64442748ab135b684bf8 RowItem: Split appart visual and layout v offsets --- diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index 250fb94e..a8d7b3e8 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -90,7 +90,7 @@ std::pair AnalogSignal::v_extents() const void AnalogSignal::paint_back(QPainter &p, int left, int right) { if (_channel->enabled()) - paint_axis(p, get_y(), left, right); + paint_axis(p, get_visual_y(), left, right); } void AnalogSignal::paint_mid(QPainter &p, int left, int right) @@ -99,7 +99,7 @@ void AnalogSignal::paint_mid(QPainter &p, int left, int right) assert(right >= left); assert(_owner); - const int y = get_y(); + const int y = get_visual_y(); const View *const view = _owner->view(); assert(view); diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index d97d01ef..5ca665e0 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -169,7 +169,7 @@ pair DecodeTrace::v_extents() const void DecodeTrace::paint_back(QPainter &p, int left, int right) { Trace::paint_back(p, left, right); - paint_axis(p, get_y(), left, right); + paint_axis(p, get_visual_y(), left, right); } void DecodeTrace::paint_mid(QPainter &p, int left, int right) @@ -191,7 +191,7 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right) } // Iterate through the rows - int y = get_y(); + int y = get_visual_y(); pair sample_range = get_sample_range(left, right); assert(_decoder_stack); @@ -236,7 +236,7 @@ void DecodeTrace::paint_fore(QPainter &p, int left, int right) for (size_t i = 0; i < _visible_rows.size(); i++) { - const int y = i * _row_height + get_y(); + const int y = i * _row_height + get_visual_y(); p.setPen(QPen(Qt::NoPen)); p.setBrush(QApplication::palette().brush(QPalette::WindowText)); @@ -443,7 +443,7 @@ void DecodeTrace::draw_range(const pv::data::decode::Annotation &a, QPainter &p, void DecodeTrace::draw_error(QPainter &p, const QString &message, int left, int right) { - const int y = get_y(); + const int y = get_visual_y(); p.setPen(ErrorBgColour.darker()); p.setBrush(ErrorBgColour); @@ -499,7 +499,7 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left, if (sample_count == samples_decoded) return; - const int y = get_y(); + const int y = get_visual_y(); tie(pixels_offset, samples_per_pixel) = get_pixels_offset_samples_per_pixel(); @@ -562,7 +562,8 @@ int DecodeTrace::get_row_at_point(const QPoint &point) if (!_row_height) return -1; - const int row = (point.y() - get_y() + _row_height / 2) / _row_height; + const int row = (point.y() - get_visual_y() + _row_height / 2) / + _row_height; if (row < 0 || row >= (int)_visible_rows.size()) return -1; @@ -630,8 +631,9 @@ void DecodeTrace::hover_point_changed() // decode trace, not below. hp.setX(hp.x() - (text_size.width() / 2) - padding); - hp.setY(get_y() - (_row_height / 2) + (hover_row * _row_height) - - _row_height - text_size.height()); + hp.setY(get_visual_y() - (_row_height / 2) + + (hover_row * _row_height) - + _row_height - text_size.height()); QToolTip::showText(view->viewport()->mapToGlobal(hp), ann); } diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 514a3e49..2264bc2c 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -101,7 +101,7 @@ void Header::show_popup(const shared_ptr &item) if (!p) return; - const QPoint pt(width() - BaselineOffset, item->get_y()); + const QPoint pt(width() - BaselineOffset, item->get_visual_y()); p->set_position(mapToGlobal(pt), Popup::Right); p->show(); } @@ -118,7 +118,7 @@ void Header::paintEvent(QPaintEvent*) stable_sort(row_items.begin(), row_items.end(), [](const shared_ptr &a, const shared_ptr &b) { - return a->v_offset() < b->v_offset(); }); + return a->visual_v_offset() < b->visual_v_offset(); }); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); @@ -246,7 +246,7 @@ void Header::mouseMoveEvent(QMouseEvent *event) for (std::shared_ptr r : _view) if (r->dragging()) { - r->set_v_offset(r->drag_point().y() + delta); + r->force_to_v_offset(r->drag_point().y() + delta); // Ensure the trace is selected r->select(); diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index 37445d96..75a125a7 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -132,7 +132,7 @@ std::pair LogicSignal::v_extents() const void LogicSignal::paint_back(QPainter &p, int left, int right) { if (_channel->enabled()) - paint_axis(p, get_y(), left, right); + paint_axis(p, get_visual_y(), left, right); } void LogicSignal::paint_mid(QPainter &p, int left, int right) @@ -148,11 +148,11 @@ void LogicSignal::paint_mid(QPainter &p, int left, int right) assert(right >= left); assert(_owner); - const int y = get_y(); + const int y = get_visual_y(); const View *const view = _owner->view(); assert(view); - + const double scale = view->scale(); assert(scale > 0); diff --git a/pv/view/rowitem.cpp b/pv/view/rowitem.cpp index d850e321..120a00a3 100644 --- a/pv/view/rowitem.cpp +++ b/pv/view/rowitem.cpp @@ -29,18 +29,37 @@ namespace view { RowItem::RowItem() : _owner(NULL), - _v_offset(0) + _layout_v_offset(0), + _visual_v_offset(0) { } -int RowItem::v_offset() const +int RowItem::layout_v_offset() const { - return _v_offset; + return _layout_v_offset; } -void RowItem::set_v_offset(int v_offset) +void RowItem::set_layout_v_offset(int v_offset) { - _v_offset = v_offset; + if (_layout_v_offset == v_offset) + return; + + _layout_v_offset = v_offset; +} + +int RowItem::visual_v_offset() const +{ + return _visual_v_offset; +} + +void RowItem::set_visual_v_offset(int v_offset) +{ + _visual_v_offset = v_offset; +} + +void RowItem::force_to_v_offset(int v_offset) +{ + _layout_v_offset = _visual_v_offset = v_offset; } RowItemOwner* RowItem::owner() const @@ -50,19 +69,24 @@ RowItemOwner* RowItem::owner() const void RowItem::set_owner(RowItemOwner *owner) { - assert((_owner && !owner) || (!_owner && owner)); + assert(_owner || owner); + + if (_owner) + _visual_v_offset += _owner->owner_v_offset(); _owner = owner; + if (_owner) + _visual_v_offset -= _owner->owner_v_offset(); } -int RowItem::get_y() const +int RowItem::get_visual_y() const { assert(_owner); - return _v_offset + _owner->owner_v_offset(); + return _visual_v_offset + _owner->owner_v_offset(); } QPoint RowItem::point() const { - return QPoint(0, v_offset()); + return QPoint(0, visual_v_offset()); } void RowItem::paint_back(QPainter &p, int left, int right) diff --git a/pv/view/rowitem.h b/pv/view/rowitem.h index 1aafca4b..aba7260b 100644 --- a/pv/view/rowitem.h +++ b/pv/view/rowitem.h @@ -49,12 +49,27 @@ public: /** * Gets the vertical layout offset of this signal. */ - int v_offset() const; + int layout_v_offset() const; /** * Sets the vertical layout offset of this signal. */ - void set_v_offset(int v_offset); + void set_layout_v_offset(int v_offset); + + /** + * Gets the vertical visual offset of this signal. + */ + int visual_v_offset() const; + + /** + * Sets the vertical visual offset of this signal. + */ + void set_visual_v_offset(int v_offset); + + /** + * Sets the visual and layout offset of this signal. + */ + void force_to_v_offset(int v_offset); /** * Gets the owner this trace in the view trace hierachy. @@ -68,9 +83,9 @@ public: void set_owner(pv::view::RowItemOwner *owner); /** - * Gets the y-offset of the axis. + * Gets the visual y-offset of the axis. */ - int get_y() const; + int get_visual_y() const; /** * Gets the drag point of the row item. @@ -133,7 +148,8 @@ Q_SIGNALS: protected: pv::view::RowItemOwner *_owner; - int _v_offset; + int _layout_v_offset; + int _visual_v_offset; }; } // namespace view diff --git a/pv/view/rowitemowner.cpp b/pv/view/rowitemowner.cpp index 0fa230ab..03f0e68d 100644 --- a/pv/view/rowitemowner.cpp +++ b/pv/view/rowitemowner.cpp @@ -96,7 +96,7 @@ pair RowItemOwner::v_extents() const if (!r->enabled()) continue; - const int child_offset = r->v_offset(); + const int child_offset = r->layout_v_offset(); const pair child_extents = r->v_extents(); extents.first = min(child_extents.first + child_offset, extents.first); diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 3b92abe4..166fc1ab 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -70,7 +70,7 @@ void Trace::set_colour(QColor colour) void Trace::paint_label(QPainter &p, int right, bool hover) { - const int y = get_y(); + const int y = get_visual_y(); p.setBrush(_colour); @@ -157,7 +157,7 @@ QRectF Trace::label_rect(int right) const const float half_height = label_size.height() / 2; return QRectF( right - half_height - label_size.width() - 0.5, - get_y() + 0.5f - half_height, + get_visual_y() + 0.5f - half_height, label_size.width() + half_height, label_size.height()); } diff --git a/pv/view/tracegroup.cpp b/pv/view/tracegroup.cpp index f5263e3f..4404b1cd 100644 --- a/pv/view/tracegroup.cpp +++ b/pv/view/tracegroup.cpp @@ -152,7 +152,7 @@ pv::widgets::Popup* TraceGroup::create_popup(QWidget *parent) int TraceGroup::owner_v_offset() const { - return v_offset() + _owner->owner_v_offset(); + return _owner ? layout_v_offset() + _owner->owner_v_offset() : 0; } void TraceGroup::update_viewport() @@ -167,10 +167,8 @@ void TraceGroup::on_ungroup() child_items().begin(), child_items().end()); clear_child_items(); - for (shared_ptr r : items) { + for (shared_ptr r : items) _owner->add_child_item(r); - r->set_v_offset(r->v_offset() + v_offset()); - } _owner->remove_child_item(shared_from_this()); appearance_changed(); diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 80ade0d2..d48bbabe 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -503,7 +503,7 @@ void View::signals_changed() const pair extents = r->v_extents(); if (r->enabled()) offset += -extents.first; - r->set_v_offset(offset); + r->force_to_v_offset(offset); if (r->enabled()) offset += extents.second; } diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 82d13c92..c85f915a 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -70,7 +70,7 @@ void Viewport::paintEvent(QPaintEvent*) vector< shared_ptr > row_items(_view.begin(), _view.end()); stable_sort(row_items.begin(), row_items.end(), [](const shared_ptr &a, const shared_ptr &b) { - return a->v_offset() < b->v_offset(); }); + return a->visual_v_offset() < b->visual_v_offset(); }); QPainter p(this); p.setRenderHint(QPainter::Antialiasing);