]> sigrok.org Git - pulseview.git/commitdiff
RowItem: Split appart visual and layout v offsets
authorJoel Holdsworth <redacted>
Sat, 15 Nov 2014 10:04:52 +0000 (10:04 +0000)
committerJoel Holdsworth <redacted>
Wed, 19 Nov 2014 10:23:30 +0000 (10:23 +0000)
pv/view/analogsignal.cpp
pv/view/decodetrace.cpp
pv/view/header.cpp
pv/view/logicsignal.cpp
pv/view/rowitem.cpp
pv/view/rowitem.h
pv/view/rowitemowner.cpp
pv/view/trace.cpp
pv/view/tracegroup.cpp
pv/view/view.cpp
pv/view/viewport.cpp

index 250fb94e9bc6623c6720a581721662798cdb571c..a8d7b3e8113d6c514e9955fc9c897a65175977a3 100644 (file)
@@ -90,7 +90,7 @@ std::pair<int, int> 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);
index d97d01ef623931c2769c25dc5fe34b798cd6365c..5ca665e0dff947f17ebbcbd0a5a77aa8802d1b98 100644 (file)
@@ -169,7 +169,7 @@ pair<int, int> 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<uint64_t, uint64_t> 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);
 }
index 514a3e49694e348dc08123749da90ff0290d1f67..2264bc2c945f96b41ea88d387af4c5221d3a8cb9 100644 (file)
@@ -101,7 +101,7 @@ void Header::show_popup(const shared_ptr<RowItem> &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<RowItem> &a, const shared_ptr<RowItem> &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<RowItem> 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();
index 37445d96072133e64fe3d90d1798e4840a7d2f9d..75a125a7eae58f334427edd86b73f5531058b825 100644 (file)
@@ -132,7 +132,7 @@ std::pair<int, int> 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);
 
index d850e321fe4fdcf0572065e268d6393fa3af8982..120a00a39d1cd0a1fb478c5facf446d86e8722ad 100644 (file)
@@ -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)
index 1aafca4be3fbfee81b663532e9e6a887601d6f12..aba7260b0a814797c9ec689bedd16e663216056f 100644 (file)
@@ -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
index 0fa230ab4e3fb47a609c105cb1de0dc91ad4d277..03f0e68d3ae52e5a0451f80c66683052b470e460 100644 (file)
@@ -96,7 +96,7 @@ pair<int, int> 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<int, int> child_extents = r->v_extents();
                extents.first = min(child_extents.first + child_offset,
                        extents.first);
index 3b92abe484c14efd5964789eed731077fed21344..166fc1abc6831beb966adf001f7bdc92024a1356 100644 (file)
@@ -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());
 }
index f5263e3facc92ddc5805eaa92ac7f757e145f633..4404b1cd866fe9e160e05a676b9fd3423c3fddd4 100644 (file)
@@ -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<RowItem> r : items) {
+       for (shared_ptr<RowItem> 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();
index 80ade0d23f5bccd573bb5385d064a1d40d9aec04..d48bbabebd4088e0b49128e00f5152577350b6b6 100644 (file)
@@ -503,7 +503,7 @@ void View::signals_changed()
                const pair<int, int> 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;
        }
index 82d13c92b985985efa7c9033760d80307c181bb6..c85f915a591eba05e36791f870509da3b943eebe 100644 (file)
@@ -70,7 +70,7 @@ void Viewport::paintEvent(QPaintEvent*)
        vector< shared_ptr<RowItem> > row_items(_view.begin(), _view.end());
        stable_sort(row_items.begin(), row_items.end(),
                [](const shared_ptr<RowItem> &a, const shared_ptr<RowItem> &b) {
-                       return a->v_offset() < b->v_offset(); });
+                       return a->visual_v_offset() < b->visual_v_offset(); });
 
        QPainter p(this);
        p.setRenderHint(QPainter::Antialiasing);