]> sigrok.org Git - pulseview.git/commitdiff
ViewPort: Make ViewItemPaintParams mutable
authorJoel Holdsworth <redacted>
Wed, 26 Apr 2017 17:09:10 +0000 (11:09 -0600)
committerUwe Hermann <redacted>
Wed, 3 May 2017 17:08:10 +0000 (19:08 +0200)
21 files changed:
pv/view/analogsignal.cpp
pv/view/analogsignal.hpp
pv/view/cursorpair.cpp
pv/view/cursorpair.hpp
pv/view/decodetrace.cpp
pv/view/decodetrace.hpp
pv/view/logicsignal.cpp
pv/view/logicsignal.hpp
pv/view/signal.cpp
pv/view/signal.hpp
pv/view/signalscalehandle.cpp
pv/view/signalscalehandle.hpp
pv/view/timemarker.cpp
pv/view/timemarker.hpp
pv/view/trace.cpp
pv/view/trace.hpp
pv/view/triggermarker.cpp
pv/view/triggermarker.hpp
pv/view/viewitem.cpp
pv/view/viewitem.hpp
pv/view/viewport.cpp

index 906bbabb71a827746e5eb7b1aef39a89b3f28d76..b9d73126527a3f0a1820d8ce60a94e228a42fd14 100644 (file)
@@ -176,7 +176,7 @@ void AnalogSignal::scale_handle_drag_release()
        update_scale();
 }
 
-void AnalogSignal::paint_back(QPainter &p, const ViewItemPaintParams &pp)
+void AnalogSignal::paint_back(QPainter &p, ViewItemPaintParams &pp)
 {
        if (base_->enabled()) {
                Trace::paint_back(p, pp);
@@ -184,7 +184,7 @@ void AnalogSignal::paint_back(QPainter &p, const ViewItemPaintParams &pp)
        }
 }
 
-void AnalogSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
+void AnalogSignal::paint_mid(QPainter &p, ViewItemPaintParams &pp)
 {
        assert(base_->analog_data());
        assert(owner_);
@@ -237,7 +237,7 @@ void AnalogSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
        }
 }
 
-void AnalogSignal::paint_fore(QPainter &p, const ViewItemPaintParams &pp)
+void AnalogSignal::paint_fore(QPainter &p, ViewItemPaintParams &pp)
 {
        if (!enabled())
                return;
@@ -420,7 +420,7 @@ void AnalogSignal::paint_envelope(QPainter &p,
        delete[] e.samples;
 }
 
-void AnalogSignal::paint_logic_mid(QPainter &p, const ViewItemPaintParams &pp)
+void AnalogSignal::paint_logic_mid(QPainter &p, ViewItemPaintParams &pp)
 {
        QLineF *line;
 
index 5ea24039108908c6b2425146854b7488bfe8fd9a..eef424d5bafb1f871381476998b2e1c02830d648 100644 (file)
@@ -100,21 +100,21 @@ public:
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with..
         */
-       void paint_back(QPainter &p, const ViewItemPaintParams &pp);
+       void paint_back(QPainter &p, ViewItemPaintParams &pp);
 
        /**
         * Paints the mid-layer of the signal with a QPainter
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with..
         */
-       void paint_mid(QPainter &p, const ViewItemPaintParams &pp);
+       void paint_mid(QPainter &p, ViewItemPaintParams &pp);
 
        /**
         * Paints the foreground layer of the item with a QPainter
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with.
         */
-       void paint_fore(QPainter &p, const ViewItemPaintParams &pp);
+       void paint_fore(QPainter &p, ViewItemPaintParams &pp);
 
 private:
        void paint_grid(QPainter &p, int y, int left, int right);
@@ -129,7 +129,7 @@ private:
                int y, int left, const int64_t start, const int64_t end,
                const double pixels_offset, const double samples_per_pixel);
 
-       void paint_logic_mid(QPainter &p, const ViewItemPaintParams &pp);
+       void paint_logic_mid(QPainter &p, ViewItemPaintParams &pp);
 
        void paint_logic_caps(QPainter &p, QLineF *const lines,
                vector< pair<int64_t, bool> > &edges,
index 24d036652d763ca6d9a4be898a2cdcbeedd35020..05b9dfcad744bb6fb996ac4d91e178241bbe1702 100644 (file)
@@ -144,7 +144,7 @@ void CursorPair::paint_label(QPainter &p, const QRect &rect, bool hover)
        }
 }
 
-void CursorPair::paint_back(QPainter &p, const ViewItemPaintParams &pp)
+void CursorPair::paint_back(QPainter &p, ViewItemPaintParams &pp)
 {
        if (!enabled())
                return;
index 458f5cac0af186f08f7c4b3fa47e851bb815a68e..ee91ff427ee11dfae8737f9f28dde0bc4d870b4d 100644 (file)
@@ -91,7 +91,7 @@ public:
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with.
         */
-       void paint_back(QPainter &p, const ViewItemPaintParams &pp) override;
+       void paint_back(QPainter &p, ViewItemPaintParams &pp) override;
 
        /**
         * Constructs the string to display.
index f45ecf58e2e1a94dba92b775ccf198cfea917c2c..74d0dd6511b623a4c41aba5b66bd6cf13194f830 100644 (file)
@@ -170,13 +170,13 @@ pair<int, int> DecodeTrace::v_extents() const
        return make_pair(-row_height, row_height * row_count);
 }
 
-void DecodeTrace::paint_back(QPainter &p, const ViewItemPaintParams &pp)
+void DecodeTrace::paint_back(QPainter &p, ViewItemPaintParams &pp)
 {
        Trace::paint_back(p, pp);
        paint_axis(p, pp, get_visual_y());
 }
 
-void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
+void DecodeTrace::paint_mid(QPainter &p, ViewItemPaintParams &pp)
 {
        using namespace pv::data::decode;
 
@@ -248,7 +248,7 @@ void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
        max_visible_rows_ = max(max_visible_rows_, (int)visible_rows_.size());
 }
 
-void DecodeTrace::paint_fore(QPainter &p, const ViewItemPaintParams &pp)
+void DecodeTrace::paint_fore(QPainter &p, ViewItemPaintParams &pp)
 {
        using namespace pv::data::decode;
 
index 648bb04ae2f9b2391cfa8d6ac1a7c798549d5695..c4cb6fa553015b48a3f977d49629a3fe8b08830e 100644 (file)
@@ -112,21 +112,21 @@ public:
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with..
         */
-       void paint_back(QPainter &p, const ViewItemPaintParams &pp);
+       void paint_back(QPainter &p, ViewItemPaintParams &pp);
 
        /**
         * Paints the mid-layer of the trace with a QPainter
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with.
         */
-       void paint_mid(QPainter &p, const ViewItemPaintParams &pp);
+       void paint_mid(QPainter &p, ViewItemPaintParams &pp);
 
        /**
         * Paints the foreground layer of the trace with a QPainter
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with.
         */
-       void paint_fore(QPainter &p, const ViewItemPaintParams &pp);
+       void paint_fore(QPainter &p, ViewItemPaintParams &pp);
 
        void populate_popup_form(QWidget *parent, QFormLayout *form);
 
index 86d45a4319013536ed12664ab49deda7e427d543..3593a5d0a7035039e33ee312ee0de8ca0864e7e2 100644 (file)
@@ -154,7 +154,7 @@ void LogicSignal::scale_handle_dragged(int offset)
        signal_height_ = ((units < 1) ? 1 : units) * font_height;
 }
 
-void LogicSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
+void LogicSignal::paint_mid(QPainter &p, ViewItemPaintParams &pp)
 {
        QLineF *line;
 
@@ -253,7 +253,7 @@ void LogicSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
        delete[] sampling_points;
 }
 
-void LogicSignal::paint_fore(QPainter &p, const ViewItemPaintParams &pp)
+void LogicSignal::paint_fore(QPainter &p, ViewItemPaintParams &pp)
 {
        // Draw the trigger marker
        if (!trigger_match_ || !base_->enabled())
index 273120230d0b25f02af6b95d366f8ac633b31ed0..cc62d910845b012b2e1752d5973b8e7b52674be0 100644 (file)
@@ -100,14 +100,14 @@ public:
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with..
         */
-       void paint_mid(QPainter &p, const ViewItemPaintParams &pp);
+       void paint_mid(QPainter &p, ViewItemPaintParams &pp);
 
        /**
         * Paints the foreground layer of the signal with a QPainter
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with.
         */
-       virtual void paint_fore(QPainter &p, const ViewItemPaintParams &pp);
+       virtual void paint_fore(QPainter &p, ViewItemPaintParams &pp);
 
 private:
        void paint_caps(QPainter &p, QLineF *const lines,
index 065715aa7a996fd0c01f7aaf3763788a95f0658e..960cefa6b20b6c3d4e027f57751eb361ed3e26fb 100644 (file)
@@ -106,7 +106,7 @@ const ViewItemOwner::item_list& Signal::child_items() const
        return items_;
 }
 
-void Signal::paint_back(QPainter &p, const ViewItemPaintParams &pp)
+void Signal::paint_back(QPainter &p, ViewItemPaintParams &pp)
 {
        if (base_->enabled())
                Trace::paint_back(p, pp);
index 2bb8da1b9b2a99a74d4d089fb0765755e19df184..40ba52ea59ada1e232a08a6bfe95f4432c347d94 100644 (file)
@@ -76,7 +76,7 @@ public:
         */
        const item_list& child_items() const;
 
-       void paint_back(QPainter &p, const ViewItemPaintParams &pp);
+       void paint_back(QPainter &p, ViewItemPaintParams &pp);
 
        virtual void populate_popup_form(QWidget *parent, QFormLayout *form);
 
index aa0201b6368781ce9aa17efb8e26b5a5f85c8807..20a4cad427338ab92bb9ce36b663954155a746c2 100644 (file)
@@ -79,7 +79,7 @@ QRectF SignalScaleHandle::hit_box_rect(const ViewItemPaintParams &pp) const
                text_height, text_height);
 }
 
-void SignalScaleHandle::paint_fore(QPainter &p, const ViewItemPaintParams &pp)
+void SignalScaleHandle::paint_fore(QPainter &p, ViewItemPaintParams &pp)
 {
        if (!enabled())
                return;
index 6374662558653fa6af1bebcea90998a6e4d2e56b..193d352fd130ffa6d49a9958259e2444527fe40f 100644 (file)
@@ -81,7 +81,7 @@ public:
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with.
         */
-       void paint_fore(QPainter &p, const ViewItemPaintParams &pp);
+       void paint_fore(QPainter &p, ViewItemPaintParams &pp);
 
 private:
        Signal &owner_;
index 88616bf20fb2cdb1a06367aeb8ee77250fc2c55b..eaa03b942294e62c4500f7b59bdbccb1a4b3ef8d 100644 (file)
@@ -154,7 +154,7 @@ void TimeMarker::paint_label(QPainter &p, const QRect &rect, bool hover)
        p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter, get_text());
 }
 
-void TimeMarker::paint_fore(QPainter &p, const ViewItemPaintParams &pp)
+void TimeMarker::paint_fore(QPainter &p, ViewItemPaintParams &pp)
 {
        if (!enabled())
                return;
index 9dd43886ee4bcc7e699495ef4c3d273e73f92fa2..dba52fa4efa5642a76c9c1150750d664bcadfd59 100644 (file)
@@ -108,7 +108,7 @@ public:
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with.
         */
-       void paint_fore(QPainter &p, const ViewItemPaintParams &pp) override;
+       void paint_fore(QPainter &p, ViewItemPaintParams &pp) override;
 
        virtual pv::widgets::Popup* create_popup(QWidget *parent) override;
 
index 66f13edb12dac9b4cf4795af5916c026f1713772..f6d4164e0794fbad801dffabcdef01572e064e2c 100644 (file)
@@ -151,7 +151,7 @@ QRectF Trace::label_rect(const QRectF &rect) const
                label_size.height());
 }
 
-void Trace::paint_back(QPainter &p, const ViewItemPaintParams &pp)
+void Trace::paint_back(QPainter &p, ViewItemPaintParams &pp)
 {
        const View *view = owner_->view();
        assert(view);
@@ -168,7 +168,7 @@ void Trace::paint_back(QPainter &p, const ViewItemPaintParams &pp)
                pp.width(), extents.second - extents.first);
 }
 
-void Trace::paint_axis(QPainter &p, const ViewItemPaintParams &pp, int y)
+void Trace::paint_axis(QPainter &p, ViewItemPaintParams &pp, int y)
 {
        p.setRenderHint(QPainter::Antialiasing, false);
 
index 882c2d7089d7ea90f59c752a24e8b75a7d919705..f911985023b9f8e26af823d3ad9b11a59507db28 100644 (file)
@@ -95,7 +95,7 @@ protected:
         * @param p The QPainter to paint into.
         * @param pp The painting parameters object to paint with.
         */
-       virtual void paint_back(QPainter &p, const ViewItemPaintParams &pp);
+       virtual void paint_back(QPainter &p, ViewItemPaintParams &pp);
 
        /**
         * Paints a zero axis across the viewport.
@@ -103,7 +103,7 @@ protected:
         * @param pp the painting parameters object to paint with.
         * @param y the y-offset of the axis.
         */
-       void paint_axis(QPainter &p, const ViewItemPaintParams &pp, int y);
+       void paint_axis(QPainter &p, ViewItemPaintParams &pp, int y);
 
        void add_colour_option(QWidget *parent, QFormLayout *form);
 
index 8cb76ebb538e2e3ea8a509cd16ac58fdd8460c50..bac1e82d79c92e1609bd1fcaec5fb4edc6c857cd 100644 (file)
@@ -65,7 +65,7 @@ QPoint TriggerMarker::point(const QRect &rect) const
        return QPoint(get_x(), rect.bottom());
 }
 
-void TriggerMarker::paint_fore(QPainter &p, const ViewItemPaintParams &pp)
+void TriggerMarker::paint_fore(QPainter &p, ViewItemPaintParams &pp)
 {
        if (!enabled())
                return;
index a18372770242970a57beed8e4339ff03d7f22e1c..b1610a5be7a95c2cc7616839b8198c307ae75401 100644 (file)
@@ -74,7 +74,7 @@ public:
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with.
         */
-       void paint_fore(QPainter &p, const ViewItemPaintParams &pp) override;
+       void paint_fore(QPainter &p, ViewItemPaintParams &pp) override;
 
 private:
        pv::util::Timestamp time_;
index 05e14164b338b145160e981fbd395f736d7a6eee..7213f96d28657b5c9c19475048484d66052d9938 100644 (file)
@@ -112,19 +112,19 @@ void ViewItem::paint_label(QPainter &p, const QRect &rect, bool hover)
        (void)hover;
 }
 
-void ViewItem::paint_back(QPainter &p, const ViewItemPaintParams &pp)
+void ViewItem::paint_back(QPainter &p, ViewItemPaintParams &pp)
 {
        (void)p;
        (void)pp;
 }
 
-void ViewItem::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
+void ViewItem::paint_mid(QPainter &p, ViewItemPaintParams &pp)
 {
        (void)p;
        (void)pp;
 }
 
-void ViewItem::paint_fore(QPainter &p, const ViewItemPaintParams &pp)
+void ViewItem::paint_fore(QPainter &p, ViewItemPaintParams &pp)
 {
        (void)p;
        (void)pp;
index 2886ea1e985a00f9e751c2091596fc26a4137747..978cb91cfa36da8b33a22d0a156e8a3f54ff1b7e 100644 (file)
@@ -129,21 +129,21 @@ public:
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with.
         */
-       virtual void paint_back(QPainter &p, const ViewItemPaintParams &pp);
+       virtual void paint_back(QPainter &p, ViewItemPaintParams &pp);
 
        /**
         * Paints the mid-layer of the item with a QPainter
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with.
         */
-       virtual void paint_mid(QPainter &p, const ViewItemPaintParams &pp);
+       virtual void paint_mid(QPainter &p, ViewItemPaintParams &pp);
 
        /**
         * Paints the foreground layer of the item with a QPainter
         * @param p the QPainter to paint into.
         * @param pp the painting parameters object to paint with.
         */
-       virtual void paint_fore(QPainter &p, const ViewItemPaintParams &pp);
+       virtual void paint_fore(QPainter &p, ViewItemPaintParams &pp);
 
 public:
        /**
index 2ed43ba283b4f16c8f9c1a20a22e7138e2b3c63e..a179cef1c6ca572609e12ad10ad3ad2de2eef59e 100644 (file)
@@ -153,6 +153,12 @@ bool Viewport::touch_event(QTouchEvent *event)
 
 void Viewport::paintEvent(QPaintEvent*)
 {
+       typedef void (ViewItem::*LayerPaintFunc)(
+               QPainter &p, ViewItemPaintParams &pp);
+       LayerPaintFunc layer_paint_funcs[] = {
+               &ViewItem::paint_back, &ViewItem::paint_mid,
+               &ViewItem::paint_fore, nullptr};
+
        vector< shared_ptr<RowItem> > row_items(view_.list_by_type<RowItem>());
        assert(none_of(row_items.begin(), row_items.end(),
                [](const shared_ptr<RowItem> &r) { return !r; }));
@@ -168,23 +174,16 @@ void Viewport::paintEvent(QPaintEvent*)
        QPainter p(this);
        p.setRenderHint(QPainter::Antialiasing);
 
-       const ViewItemPaintParams pp(rect(), view_.scale(), view_.offset());
-
-       for (const shared_ptr<TimeItem> t : time_items)
-               t->paint_back(p, pp);
-       for (const shared_ptr<RowItem> r : row_items)
-               r->paint_back(p, pp);
+       for (LayerPaintFunc *paint_func = layer_paint_funcs;
+                       *paint_func; paint_func++) {
+               ViewItemPaintParams time_pp(rect(), view_.scale(), view_.offset());
+               for (const shared_ptr<TimeItem> t : time_items)
+                       (t.get()->*(*paint_func))(p, time_pp);
 
-       for (const shared_ptr<TimeItem> t : time_items)
-               t->paint_mid(p, pp);
-       for (const shared_ptr<RowItem> r : row_items)
-               r->paint_mid(p, pp);
-
-       for (const shared_ptr<RowItem> r : row_items)
-               r->paint_fore(p, pp);
-
-       for (const shared_ptr<TimeItem> t : time_items)
-               t->paint_fore(p, pp);
+               ViewItemPaintParams row_pp(rect(), view_.scale(), view_.offset());
+               for (const shared_ptr<RowItem> r : row_items)
+                       (r.get()->*(*paint_func))(p, row_pp);
+       }
 
        p.end();
 }