From: Joel Holdsworth Date: Mon, 26 Aug 2013 15:08:21 +0000 (+0100) Subject: Add a pointer to the current View inside Trace X-Git-Tag: pulseview-0.2.0~304 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=01fd32630269c1cfb99eb2b0d6060d7d19a42475;p=pulseview.git Add a pointer to the current View inside Trace --- diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index 6aeef98a..681386ff 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -25,6 +25,7 @@ #include "analogsignal.h" #include "pv/data/analog.h" #include "pv/data/analogsnapshot.h" +#include "pv/view/view.h" using namespace boost; using namespace std; @@ -66,13 +67,19 @@ void AnalogSignal::set_scale(float scale) _scale = scale; } -void AnalogSignal::paint(QPainter &p, int y, int left, int right, double scale, - double offset) +void AnalogSignal::paint(QPainter &p, int left, int right) { - assert(scale > 0); assert(_data); assert(right >= left); + assert(_view); + const int y = _v_offset - _view->v_offset(); + + const double scale = _view->scale(); + assert(scale > 0); + + const double offset = _view->offset(); + if (!_probe->enabled) return; diff --git a/pv/view/analogsignal.h b/pv/view/analogsignal.h index 7815261e..002076a2 100644 --- a/pv/view/analogsignal.h +++ b/pv/view/analogsignal.h @@ -54,15 +54,10 @@ public: /** * Paints the signal with a QPainter * @param p the QPainter to paint into. - * @param y the y-coordinate to draw the signal at. * @param left the x-coordinate of the left edge of the signal. * @param right the x-coordinate of the right edge of the signal. - * @param scale the scale in seconds per pixel. - * @param offset the time to show at the left hand edge of - * the view in seconds. **/ - void paint(QPainter &p, int y, int left, int right, double scale, - double offset); + void paint(QPainter &p, int left, int right); private: void paint_trace(QPainter &p, diff --git a/pv/view/decodesignal.cpp b/pv/view/decodesignal.cpp index d2717892..556631c6 100644 --- a/pv/view/decodesignal.cpp +++ b/pv/view/decodesignal.cpp @@ -50,16 +50,11 @@ bool DecodeSignal::enabled() const return true; } -void DecodeSignal::paint(QPainter &p, int y, int left, int right, - double scale, double offset) +void DecodeSignal::paint(QPainter &p, int left, int right) { (void)p; - (void)y; (void)left; (void)right; - (void)offset; - - assert(scale > 0); } const list DecodeSignal::get_context_bar_actions() diff --git a/pv/view/decodesignal.h b/pv/view/decodesignal.h index 755fefe6..31804589 100644 --- a/pv/view/decodesignal.h +++ b/pv/view/decodesignal.h @@ -46,15 +46,10 @@ public: /** * Paints the trace with a QPainter * @param p the QPainter to paint into. - * @param y the y-coordinate to draw the signal at * @param left the x-coordinate of the left edge of the signal * @param right the x-coordinate of the right edge of the signal - * @param scale the scale in seconds per pixel. - * @param offset the time to show at the left hand edge of - * the view in seconds. **/ - void paint(QPainter &p, int y, int left, int right, - double scale, double offset); + void paint(QPainter &p, int left, int right); const std::list get_context_bar_actions(); diff --git a/pv/view/header.cpp b/pv/view/header.cpp index e14a9f24..b85b1bb1 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -66,13 +66,10 @@ shared_ptr Header::get_mouse_over_trace(const QPoint &pt) const int w = width(); const vector< shared_ptr > traces(_view.get_traces()); - const int v_offset = _view.v_offset(); BOOST_FOREACH(const shared_ptr t, traces) { assert(t); - - if (t->pt_in_label_rect(t->get_v_offset() - v_offset, - 0, w, pt)) + if (t->pt_in_label_rect(0, w, pt)) return t; } @@ -98,16 +95,14 @@ void Header::paintEvent(QPaintEvent*) QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); - const int v_offset = _view.v_offset(); const bool dragging = !_drag_traces.empty(); BOOST_FOREACH(const shared_ptr t, traces) { assert(t); - const int y = t->get_v_offset() - v_offset; const bool highlight = !dragging && t->pt_in_label_rect( - y, 0, w, _mouse_point); - t->paint_label(painter, y, w, highlight); + 0, w, _mouse_point); + t->paint_label(painter, w, highlight); } painter.end(); diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index 0c934cc7..3624ccf0 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -28,6 +28,7 @@ #include "pv/sigsession.h" #include "pv/data/logic.h" #include "pv/data/logicsnapshot.h" +#include "pv/view/view.h" using namespace boost; using namespace std; @@ -156,8 +157,7 @@ const list LogicSignal::get_context_bar_actions() return actions; } -void LogicSignal::paint(QPainter &p, int y, int left, int right, - double scale, double offset) +void LogicSignal::paint(QPainter &p, int left, int right) { using pv::view::View; @@ -166,10 +166,17 @@ void LogicSignal::paint(QPainter &p, int y, int left, int right, vector< pair > edges; assert(_probe); - assert(scale > 0); assert(_data); assert(right >= left); + assert(_view); + const int y = _v_offset - _view->v_offset(); + + const double scale = _view->scale(); + assert(scale > 0); + + const double offset = _view->offset(); + if (!_probe->enabled) return; diff --git a/pv/view/logicsignal.h b/pv/view/logicsignal.h index 3b37c5d3..b0a328c1 100644 --- a/pv/view/logicsignal.h +++ b/pv/view/logicsignal.h @@ -59,15 +59,10 @@ public: /** * Paints the signal with a QPainter * @param p the QPainter to paint into. - * @param y the y-coordinate to draw the signal at. * @param left the x-coordinate of the left edge of the signal. * @param right the x-coordinate of the right edge of the signal. - * @param scale the scale in seconds per pixel. - * @param offset the time to show at the left hand edge of - * the view in seconds. **/ - void paint(QPainter &p, int y, int left, int right, double scale, - double offset); + void paint(QPainter &p, int left, int right); private: diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 4de3f141..6c43c4c2 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -68,8 +68,17 @@ void Trace::set_v_offset(int v_offset) _v_offset = v_offset; } -void Trace::paint_label(QPainter &p, int y, int right, bool hover) +void Trace::set_view(pv::view::View *view) { + assert(view); + _view = view; +} + +void Trace::paint_label(QPainter &p, int right, bool hover) +{ + assert(_view); + const int y = _v_offset - _view->v_offset(); + p.setBrush(_colour); if (!enabled()) @@ -78,7 +87,7 @@ void Trace::paint_label(QPainter &p, int y, int right, bool hover) const QColor colour = get_colour(); compute_text_size(p); - const QRectF label_rect = get_label_rect(y, right); + const QRectF label_rect = get_label_rect(right); // Paint the label const QPointF points[] = { @@ -120,12 +129,11 @@ void Trace::paint_label(QPainter &p, int y, int right, bool hover) p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name); } -bool Trace::pt_in_label_rect(int y, int left, int right, - const QPoint &point) +bool Trace::pt_in_label_rect(int left, int right, const QPoint &point) { (void)left; - const QRectF label = get_label_rect(y, right); + const QRectF label = get_label_rect(right); return QRectF( QPointF(label.left() - LabelHitPadding, label.top() - LabelHitPadding), @@ -140,10 +148,13 @@ void Trace::compute_text_size(QPainter &p) p.boundingRect(QRectF(), 0, "Tg").height()); } -QRectF Trace::get_label_rect(int y, int right) +QRectF Trace::get_label_rect(int right) { using pv::view::View; + assert(_view); + const int y = _v_offset - _view->v_offset(); + const QSizeF label_size( _text_size.width() + View::LabelPadding.width() * 2, ceilf((_text_size.height() + View::LabelPadding.height() * 2) / 2) * 2); diff --git a/pv/view/trace.h b/pv/view/trace.h index 61433e9c..4d6b49be 100644 --- a/pv/view/trace.h +++ b/pv/view/trace.h @@ -36,6 +36,8 @@ class SigSession; namespace view { +class View; + class Trace : public SelectableItem { Q_OBJECT @@ -82,41 +84,34 @@ public: */ virtual bool enabled() const = 0; + void set_view(pv::view::View *view); + /** * Paints the trace with a QPainter * @param p the QPainter to paint into. - * @param y the y-coordinate to draw the signal at * @param left the x-coordinate of the left edge of the signal * @param right the x-coordinate of the right edge of the signal - * @param scale the scale in seconds per pixel. - * @param offset the time to show at the left hand edge of - * the view in seconds. **/ - virtual void paint(QPainter &p, int y, int left, int right, - double scale, double offset) = 0; + virtual void paint(QPainter &p, int left, int right) = 0; /** * Paints the signal label into a QGLWidget. * @param p the QPainter to paint into. - * @param y the y-coordinate of the signal. * @param right the x-coordinate of the right edge of the header * area. * @param hover true if the label is being hovered over by the mouse. */ - virtual void paint_label(QPainter &p, int y, int right, - bool hover); + virtual void paint_label(QPainter &p, int right, bool hover); /** * Determines if a point is in the header label rect. - * @param y the y-coordinate of the signal. * @param left the x-coordinate of the left edge of the header * area. * @param right the x-coordinate of the right edge of the header * area. * @param point the point to test. */ - bool pt_in_label_rect(int y, int left, int right, - const QPoint &point); + bool pt_in_label_rect(int left, int right, const QPoint &point); private: @@ -128,18 +123,18 @@ private: /** * Computes the outline rectangle of a label. * @param p the QPainter to lay out text with. - * @param y the y-coordinate of the signal. * @param right the x-coordinate of the right edge of the header * area. * @return Returns the rectangle of the signal label. */ - QRectF get_label_rect(int y, int right); + QRectF get_label_rect(int right); signals: void text_changed(); protected: pv::SigSession &_session; + pv::view::View *_view; QString _name; QColor _colour; diff --git a/pv/view/view.cpp b/pv/view/view.cpp index b4815e70..026d2e7f 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -384,10 +384,11 @@ void View::v_scroll_value_changed(int value) void View::signals_changed() { int offset = SignalMargin + SignalHeight; - const vector< shared_ptr > sigs(_session.get_signals()); - BOOST_FOREACH(shared_ptr s, sigs) { - s->init_context_bar_actions(NULL); - s->set_v_offset(offset); + const vector< shared_ptr > traces(get_traces()); + BOOST_FOREACH(shared_ptr t, traces) { + t->set_view(this); + t->init_context_bar_actions(NULL); + t->set_v_offset(offset); offset += SignalHeight + 2 * SignalMargin; } diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 0e0ae8ae..06fab904 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -69,12 +69,10 @@ void Viewport::paintEvent(QPaintEvent*) _view.cursors().draw_viewport_background(p, rect()); // Plot the signal - const int v_offset = _view.v_offset(); BOOST_FOREACH(const shared_ptr t, traces) { assert(t); - t->paint(p, t->get_v_offset() - v_offset, 0, width(), - _view.scale(), _view.offset()); + t->paint(p, 0, width()); } if (_view.cursors_shown())