]> sigrok.org Git - pulseview.git/commitdiff
Use static signal offsets instead of offsets calculated on-the-fly
authorJoel Holdsworth <redacted>
Sat, 17 Nov 2012 08:08:40 +0000 (08:08 +0000)
committerJoel Holdsworth <redacted>
Sat, 17 Nov 2012 08:10:35 +0000 (08:10 +0000)
This will be needed for dragging

pv/view/header.cpp
pv/view/signal.cpp
pv/view/signal.h
pv/view/view.cpp
pv/view/view.h
pv/view/viewport.cpp

index 2f02e7744782e330107c2484bd116536d0e7f506..125d3c2430ba868d95c0f535e162d9279dda9e90 100644 (file)
@@ -64,18 +64,17 @@ void Header::paintEvent(QPaintEvent *event)
        QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing);
 
        QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing);
 
-       int offset = -_view.v_offset();
+       const int v_offset = _view.v_offset();
        BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
        {
                assert(s);
 
                const QRect signal_heading_rect(
        BOOST_FOREACH(const shared_ptr<Signal> 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));
 
                s->paint_label(painter, signal_heading_rect,
                        s->pt_in_label_rect(signal_heading_rect, _mouse_point));
-
-               offset += View::SignalHeight;
        }
 
        painter.end();
        }
 
        painter.end();
@@ -100,13 +99,14 @@ void Header::contextMenuEvent(QContextMenuEvent *event)
        const vector< shared_ptr<Signal> > &sigs =
                _view.session().get_signals();
 
        const vector< shared_ptr<Signal> > &sigs =
                _view.session().get_signals();
 
-       int offset = -_view.v_offset();
+       const int v_offset = _view.v_offset();
        BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
        {
                assert(s);
 
                const QRect signal_heading_rect(
        BOOST_FOREACH(const shared_ptr<Signal> 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);
 
                if(s->pt_in_label_rect(signal_heading_rect, _mouse_point)) {
                        QMenu menu(this);
@@ -119,8 +119,6 @@ void Header::contextMenuEvent(QContextMenuEvent *event)
 
                        break;
                }
 
                        break;
                }
-
-               offset += View::SignalHeight;
        }
 }
 
        }
 }
 
index 3e951b339bc261c319e3807249c2a4d91ae35462..02732ffc7a19112d3e6fc236b7beea57ccf6ed8c 100644 (file)
@@ -29,7 +29,8 @@ namespace view {
 const int Signal::LabelHitPadding = 2;
 
 Signal::Signal(QString name) :
 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;
 }
 
        _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);
 void Signal::paint_label(QPainter &p, const QRect &rect, bool hover)
 {
        p.setBrush(_colour);
index 6f08e947c61a36958a8efbf5a0a380739576373d..b3212394115df5c5b043d27969cb8dcdfd117d84 100644 (file)
@@ -65,6 +65,16 @@ public:
         */
        void set_colour(QColor colour);
 
         */
        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.
        /**
         * Paints the signal with a QPainter
         * @param p the QPainter to paint into.
@@ -118,6 +128,7 @@ protected:
 protected:
        QString _name;
        QColor _colour;
 protected:
        QString _name;
        QColor _colour;
+       int _v_offset;
 
        QSizeF _text_size;
 };
 
        QSizeF _text_size;
 };
index 81b3fcd225c60f8c1d24e994557a94492e8acbdd..e36072ef78ce0d76b88547a32616a5f9a110f9b0 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "header.h"
 #include "ruler.h"
 
 #include "header.h"
 #include "ruler.h"
+#include "signal.h"
 #include "view.h"
 #include "viewport.h"
 
 #include "view.h"
 #include "viewport.h"
 
@@ -200,6 +201,16 @@ void View::update_scroll()
                _viewport->get_total_height() - areaSize.height());
 }
 
                _viewport->get_total_height() - areaSize.height());
 }
 
+void View::reset_signal_layout()
+{
+       int offset = 0;
+       vector< shared_ptr<Signal> > &sigs = _session.get_signals();
+       BOOST_FOREACH(shared_ptr<Signal> s, sigs) {
+               s->set_v_offset(offset);
+               offset += SignalHeight;
+       }
+}
+
 bool View::eventFilter(QObject *object, QEvent *event)
 {
        const QEvent::Type type = event->type();
 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();
 
        // Repaint the view
        _viewport->update();
+
+       /// @todo: Call this only once when the signals are first created.
+       reset_signal_layout();
 }
 
 void View::marker_time_changed()
 }
 
 void View::marker_time_changed()
index 3397ba2ce28800c3b996c7a1f19e455ef800ce6a..45ccd3459700a65c897fb9ab4a06efd8ba0f0083 100644 (file)
@@ -111,6 +111,8 @@ private:
        
        void update_scroll();
 
        
        void update_scroll();
 
+       void reset_signal_layout();
+
 private:
        bool eventFilter(QObject *object, QEvent *event);
 
 private:
        bool eventFilter(QObject *object, QEvent *event);
 
index d9b0ff1b85af41c44aa32a4212974470e437dfe5..7d844d27bccadd71a287f5aeb784f9d5f1ad5f85 100644 (file)
@@ -66,17 +66,15 @@ void Viewport::paintEvent(QPaintEvent *event)
        draw_cursors_background(p);
 
        // Plot the signal
        draw_cursors_background(p);
 
        // Plot the signal
-       int offset = -_view.v_offset();
+       const int v_offset = _view.v_offset();
        BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
        {
                assert(s);
 
        BOOST_FOREACH(const shared_ptr<Signal> 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());
                        width(), View::SignalHeight);
 
                s->paint(p, signal_rect, _view.scale(), _view.offset());
-
-               offset += View::SignalHeight;
        }
 
        draw_cursors_foreground(p);
        }
 
        draw_cursors_foreground(p);