From: Joel Holdsworth Date: Sat, 17 Nov 2012 08:08:40 +0000 (+0000) Subject: Use static signal offsets instead of offsets calculated on-the-fly X-Git-Tag: pulseview-0.1.0~219 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=2e57535108a0ae2e5d1ee454f1e61b71d23afdb3 Use static signal offsets instead of offsets calculated on-the-fly This will be needed for dragging --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 2f02e774..125d3c24 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -64,18 +64,17 @@ void Header::paintEvent(QPaintEvent *event) QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); - int offset = -_view.v_offset(); + const int v_offset = _view.v_offset(); BOOST_FOREACH(const shared_ptr s, sigs) { assert(s); const QRect signal_heading_rect( - 0, offset, w, View::SignalHeight); + 0, s->get_v_offset() - v_offset, + w, View::SignalHeight); s->paint_label(painter, signal_heading_rect, s->pt_in_label_rect(signal_heading_rect, _mouse_point)); - - offset += View::SignalHeight; } painter.end(); @@ -100,13 +99,14 @@ void Header::contextMenuEvent(QContextMenuEvent *event) const vector< shared_ptr > &sigs = _view.session().get_signals(); - int offset = -_view.v_offset(); + const int v_offset = _view.v_offset(); BOOST_FOREACH(const shared_ptr s, sigs) { assert(s); const QRect signal_heading_rect( - 0, offset, w, View::SignalHeight); + 0, s->get_v_offset() - v_offset, + w, View::SignalHeight); if(s->pt_in_label_rect(signal_heading_rect, _mouse_point)) { QMenu menu(this); @@ -119,8 +119,6 @@ void Header::contextMenuEvent(QContextMenuEvent *event) break; } - - offset += View::SignalHeight; } } diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index 3e951b33..02732ffc 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -29,7 +29,8 @@ namespace view { const int Signal::LabelHitPadding = 2; Signal::Signal(QString name) : - _name(name) + _name(name), + _v_offset(0) { } @@ -53,6 +54,16 @@ void Signal::set_colour(QColor colour) _colour = colour; } +int Signal::get_v_offset() const +{ + return _v_offset; +} + +void Signal::set_v_offset(int v_offset) +{ + _v_offset = v_offset; +} + void Signal::paint_label(QPainter &p, const QRect &rect, bool hover) { p.setBrush(_colour); diff --git a/pv/view/signal.h b/pv/view/signal.h index 6f08e947..b3212394 100644 --- a/pv/view/signal.h +++ b/pv/view/signal.h @@ -65,6 +65,16 @@ public: */ void set_colour(QColor colour); + /** + * Gets the vertical layout offset of this signal. + */ + int get_v_offset() const; + + /** + * Sets the vertical layout offset of this signal. + */ + void set_v_offset(int v_offset); + /** * Paints the signal with a QPainter * @param p the QPainter to paint into. @@ -118,6 +128,7 @@ protected: protected: QString _name; QColor _colour; + int _v_offset; QSizeF _text_size; }; diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 81b3fcd2..e36072ef 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -30,6 +30,7 @@ #include "header.h" #include "ruler.h" +#include "signal.h" #include "view.h" #include "viewport.h" @@ -200,6 +201,16 @@ void View::update_scroll() _viewport->get_total_height() - areaSize.height()); } +void View::reset_signal_layout() +{ + int offset = 0; + vector< shared_ptr > &sigs = _session.get_signals(); + BOOST_FOREACH(shared_ptr s, sigs) { + s->set_v_offset(offset); + offset += SignalHeight; + } +} + bool View::eventFilter(QObject *object, QEvent *event) { const QEvent::Type type = event->type(); @@ -291,6 +302,9 @@ void View::data_updated() // Repaint the view _viewport->update(); + + /// @todo: Call this only once when the signals are first created. + reset_signal_layout(); } void View::marker_time_changed() diff --git a/pv/view/view.h b/pv/view/view.h index 3397ba2c..45ccd345 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -111,6 +111,8 @@ private: void update_scroll(); + void reset_signal_layout(); + private: bool eventFilter(QObject *object, QEvent *event); diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index d9b0ff1b..7d844d27 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -66,17 +66,15 @@ void Viewport::paintEvent(QPaintEvent *event) draw_cursors_background(p); // Plot the signal - int offset = -_view.v_offset(); + const int v_offset = _view.v_offset(); BOOST_FOREACH(const shared_ptr s, sigs) { assert(s); - const QRect signal_rect(0, offset, + const QRect signal_rect(0, s->get_v_offset() - v_offset, width(), View::SignalHeight); s->paint(p, signal_rect, _view.scale(), _view.offset()); - - offset += View::SignalHeight; } draw_cursors_foreground(p);