]> sigrok.org Git - pulseview.git/commitdiff
RowItem: Bundled painting parameters into RowItemPaintParams
authorJoel Holdsworth <redacted>
Sun, 23 Nov 2014 19:53:59 +0000 (19:53 +0000)
committerJoel Holdsworth <redacted>
Tue, 9 Dec 2014 18:24:56 +0000 (18:24 +0000)
13 files changed:
CMakeLists.txt
pv/view/analogsignal.cpp
pv/view/analogsignal.hpp
pv/view/decodetrace.cpp
pv/view/decodetrace.hpp
pv/view/logicsignal.cpp
pv/view/logicsignal.hpp
pv/view/rowitem.cpp
pv/view/rowitem.hpp
pv/view/rowitempaintparams.cpp [new file with mode: 0644]
pv/view/rowitempaintparams.hpp [new file with mode: 0644]
pv/view/viewport.cpp
test/CMakeLists.txt

index a66a95bd871e9ecb3e06e495ce0e16826e1fefbd..40878efacec8a37dd1d23a6adc304677b2c42b89 100644 (file)
@@ -175,6 +175,7 @@ set(pulseview_SOURCES
        pv/view/logicsignal.cpp
        pv/view/rowitem.cpp
        pv/view/rowitemowner.cpp
+       pv/view/rowitempaintparams.cpp
        pv/view/ruler.cpp
        pv/view/selectableitem.cpp
        pv/view/signal.cpp
index 8a19cc210180abeedaedeb6305e96942b046686a..a7a69218bb4f12a25c97185068f8148cee959d01 100644 (file)
@@ -87,16 +87,15 @@ std::pair<int, int> AnalogSignal::v_extents() const
        return make_pair(-NominalHeight / 2, NominalHeight / 2);
 }
 
-void AnalogSignal::paint_back(QPainter &p, int left, int right)
+void AnalogSignal::paint_back(QPainter &p, const RowItemPaintParams &pp)
 {
        if (channel_->enabled())
-               paint_axis(p, get_visual_y(), left, right);
+               paint_axis(p, get_visual_y(), pp.left(), pp.right());
 }
 
-void AnalogSignal::paint_mid(QPainter &p, int left, int right)
+void AnalogSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp)
 {
        assert(data_);
-       assert(right >= left);
        assert(owner_);
 
        const int y = get_visual_y();
@@ -126,7 +125,7 @@ void AnalogSignal::paint_mid(QPainter &p, int left, int right)
        const int64_t last_sample = snapshot->get_sample_count() - 1;
        const double samples_per_pixel = samplerate * scale;
        const double start = samplerate * (offset - start_time);
-       const double end = start + samples_per_pixel * (right - left);
+       const double end = start + samples_per_pixel * pp.width();
 
        const int64_t start_sample = min(max((int64_t)floor(start),
                (int64_t)0), last_sample);
@@ -134,11 +133,11 @@ void AnalogSignal::paint_mid(QPainter &p, int left, int right)
                (int64_t)0), last_sample);
 
        if (samples_per_pixel < EnvelopeThreshold)
-               paint_trace(p, snapshot, y, left,
+               paint_trace(p, snapshot, y, pp.left(),
                        start_sample, end_sample,
                        pixels_offset, samples_per_pixel);
        else
-               paint_envelope(p, snapshot, y, left,
+               paint_envelope(p, snapshot, y, pp.left(),
                        start_sample, end_sample,
                        pixels_offset, samples_per_pixel);
 }
index 5295fe32eed6f6229d62b3abb5a79f632a393787..c048371eeadd1973149017bd7f21f06abf79a1a7 100644 (file)
@@ -64,18 +64,16 @@ public:
        /**
         * Paints the background layer of the signal with a QPainter
         * @param p the QPainter to paint into.
-        * @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 pp the painting parameters object to paint with..
         **/
-       void paint_back(QPainter &p, int left, int right);
+       void paint_back(QPainter &p, const RowItemPaintParams &pp);
 
        /**
         * Paints the mid-layer of the signal with a QPainter
         * @param p the QPainter to paint into.
-        * @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 pp the painting parameters object to paint with..
         **/
-       void paint_mid(QPainter &p, int left, int right);
+       void paint_mid(QPainter &p, const RowItemPaintParams &pp);
 
 private:
        void paint_trace(QPainter &p,
index 0fbd16fd22b5e636a6b71d1ef3c27cea3d01fe40..7ed66b3e12c351d7cae7763cd3f3b4710c913a18 100644 (file)
@@ -166,13 +166,13 @@ pair<int, int> DecodeTrace::v_extents() const
        return make_pair(-row_height / 2, row_height * 7 / 2);
 }
 
-void DecodeTrace::paint_back(QPainter &p, int left, int right)
+void DecodeTrace::paint_back(QPainter &p, const RowItemPaintParams &pp)
 {
-       Trace::paint_back(p, left, right);
-       paint_axis(p, get_visual_y(), left, right);
+       Trace::paint_back(p, pp);
+       paint_axis(p, get_visual_y(), pp.left(), pp.right());
 }
 
-void DecodeTrace::paint_mid(QPainter &p, int left, int right)
+void DecodeTrace::paint_mid(QPainter &p, const RowItemPaintParams &pp)
 {
        using namespace pv::data::decode;
 
@@ -185,14 +185,16 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right)
        const QString err = decoder_stack_->error_message();
        if (!err.isEmpty())
        {
-               draw_unresolved_period(p, annotation_height, left, right);
-               draw_error(p, err, left, right);
+               draw_unresolved_period(
+                       p, annotation_height, pp.left(), pp.right());
+               draw_error(p, err, pp);
                return;
        }
 
        // Iterate through the rows
        int y = get_visual_y();
-       pair<uint64_t, uint64_t> sample_range = get_sample_range(left, right);
+       pair<uint64_t, uint64_t> sample_range = get_sample_range(
+               pp.left(), pp.right());
 
        assert(decoder_stack_);
        const vector<Row> rows(decoder_stack_->get_visible_rows());
@@ -214,8 +216,7 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right)
                if (!annotations.empty()) {
                        for (const Annotation &a : annotations)
                                draw_annotation(a, p, get_text_colour(),
-                                       annotation_height, left, right, y,
-                                       base_colour);
+                                       annotation_height, pp, y, base_colour);
                        y += row_height_;
 
                        visible_rows_.push_back(rows[i]);
@@ -223,15 +224,13 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right)
        }
 
        // Draw the hatching
-       draw_unresolved_period(p, annotation_height, left, right);
+       draw_unresolved_period(p, annotation_height, pp.left(), pp.right());
 }
 
-void DecodeTrace::paint_fore(QPainter &p, int left, int right)
+void DecodeTrace::paint_fore(QPainter &p, const RowItemPaintParams &pp)
 {
        using namespace pv::data::decode;
 
-       (void)right;
-
        assert(row_height_);
 
        for (size_t i = 0; i < visible_rows_.size(); i++)
@@ -244,15 +243,15 @@ void DecodeTrace::paint_fore(QPainter &p, int left, int right)
                if (i != 0)
                {
                        const QPointF points[] = {
-                               QPointF(left, y - ArrowSize),
-                               QPointF(left + ArrowSize, y),
-                               QPointF(left, y + ArrowSize)
+                               QPointF(pp.left(), y - ArrowSize),
+                               QPointF(pp.left() + ArrowSize, y),
+                               QPointF(pp.left(), y + ArrowSize)
                        };
                        p.drawPolygon(points, countof(points));
                }
 
-               const QRect r(left + ArrowSize * 2, y - row_height_ / 2,
-                       right - left, row_height_);
+               const QRect r(pp.left() + ArrowSize * 2, y - row_height_ / 2,
+                       pp.right() - pp.left(), row_height_);
                const QString h(visible_rows_[i].title());
                const int f = Qt::AlignLeft | Qt::AlignVCenter |
                        Qt::TextDontClip;
@@ -337,7 +336,7 @@ QMenu* DecodeTrace::create_context_menu(QWidget *parent)
 }
 
 void DecodeTrace::draw_annotation(const pv::data::decode::Annotation &a,
-       QPainter &p, QColor text_color, int h, int left, int right, int y,
+       QPainter &p, QColor text_color, int h, const RowItemPaintParams &pp, int y,
        size_t base_colour) const
 {
        double samples_per_pixel, pixels_offset;
@@ -353,7 +352,7 @@ void DecodeTrace::draw_annotation(const pv::data::decode::Annotation &a,
        const QColor &fill = Colours[colour];
        const QColor &outline = OutlineColours[colour];
 
-       if (start > right + DrawPadding || end < left - DrawPadding)
+       if (start > pp.right() + DrawPadding || end < pp.left() - DrawPadding)
                return;
 
        if (a.start_sample() == a.end_sample())
@@ -441,7 +440,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 RowItemPaintParams &pp)
 {
        const int y = get_visual_y();
 
@@ -449,7 +448,7 @@ void DecodeTrace::draw_error(QPainter &p, const QString &message,
        p.setBrush(ErrorBgColour);
 
        const QRectF bounding_rect =
-               QRectF(left, INT_MIN / 2 + y, right - left, INT_MAX);
+               QRectF(pp.width(), INT_MIN / 2 + y, pp.width(), INT_MAX);
        const QRectF text_rect = p.boundingRect(bounding_rect,
                Qt::AlignCenter, message);
        const float r = text_rect.height() / 4;
index e3d8d68c04feb45e50c8780f8f480dfa45b001b1..71876f5ca418062160aa636067d0f1edce1dcbd6 100644 (file)
@@ -99,26 +99,23 @@ public:
        /**
         * Paints the background layer of the trace with a QPainter
         * @param p the QPainter to paint into.
-        * @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 pp the painting parameters object to paint with..
         **/
-       void paint_back(QPainter &p, int left, int right);
+       void paint_back(QPainter &p, const RowItemPaintParams &pp);
 
        /**
         * Paints the mid-layer of the trace with a QPainter
         * @param p the QPainter to paint into.
-        * @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 pp the painting parameters object to paint with.
         **/
-       void paint_mid(QPainter &p, int left, int right);
+       void paint_mid(QPainter &p, const RowItemPaintParams &pp);
 
        /**
         * Paints the foreground layer of the trace with a QPainter
         * @param p the QPainter to paint into.
-        * @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 pp the painting parameters object to paint with.
         **/
-       void paint_fore(QPainter &p, int left, int right);
+       void paint_fore(QPainter &p, const RowItemPaintParams &pp);
 
        void populate_popup_form(QWidget *parent, QFormLayout *form);
 
@@ -128,7 +125,7 @@ public:
 
 private:
        void draw_annotation(const pv::data::decode::Annotation &a, QPainter &p,
-               QColor text_colour, int text_height, int left, int right, int y,
+               QColor text_colour, int text_height, const RowItemPaintParams &pp, int y,
                size_t base_colour) const;
 
        void draw_instant(const pv::data::decode::Annotation &a, QPainter &p,
@@ -140,7 +137,7 @@ private:
                double end, int y) const;
 
        void draw_error(QPainter &p, const QString &message,
-               int left, int right);
+               const RowItemPaintParams &pp);
 
        void draw_unresolved_period(QPainter &p, int h, int left,
                int right) const;
index fc81a4a92668663b26a9cf2ad7fa0113f72258f4..af992c6bac175391ffd7a3941f59c1a1ae036266 100644 (file)
@@ -145,13 +145,13 @@ std::pair<int, int> LogicSignal::v_extents() const
        return make_pair(-SignalHeight - SignalMargin, SignalMargin);
 }
 
-void LogicSignal::paint_back(QPainter &p, int left, int right)
+void LogicSignal::paint_back(QPainter &p, const RowItemPaintParams &pp)
 {
        if (channel_->enabled())
-               paint_axis(p, get_visual_y(), left, right);
+               paint_axis(p, get_visual_y(), pp.left(), pp.right());
 }
 
-void LogicSignal::paint_mid(QPainter &p, int left, int right)
+void LogicSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp)
 {
        using pv::view::View;
 
@@ -161,7 +161,6 @@ void LogicSignal::paint_mid(QPainter &p, int left, int right)
 
        assert(channel_);
        assert(data_);
-       assert(right >= left);
        assert(owner_);
 
        const int y = get_visual_y();
@@ -199,7 +198,7 @@ void LogicSignal::paint_mid(QPainter &p, int left, int right)
        const int64_t last_sample = snapshot->get_sample_count() - 1;
        const double samples_per_pixel = samplerate * scale;
        const double start = samplerate * (offset - start_time);
-       const double end = start + samples_per_pixel * (right - left);
+       const double end = start + samples_per_pixel * pp.width();
 
        snapshot->get_subsampled_edges(edges,
                min(max((int64_t)floor(start), (int64_t)0), last_sample),
@@ -214,7 +213,7 @@ void LogicSignal::paint_mid(QPainter &p, int left, int right)
 
        for (auto i = edges.cbegin() + 1; i != edges.cend() - 1; i++) {
                const float x = ((*i).first / samples_per_pixel -
-                       pixels_offset) + left;
+                       pixels_offset) + pp.left();
                *line++ = QLineF(x, high_offset, x, low_offset);
        }
 
@@ -228,18 +227,16 @@ void LogicSignal::paint_mid(QPainter &p, int left, int right)
 
        p.setPen(HighColour);
        paint_caps(p, cap_lines, edges, true, samples_per_pixel,
-               pixels_offset, left, high_offset);
+               pixels_offset, pp.left(), high_offset);
        p.setPen(LowColour);
        paint_caps(p, cap_lines, edges, false, samples_per_pixel,
-               pixels_offset, left, low_offset);
+               pixels_offset, pp.left(), low_offset);
 
        delete[] cap_lines;
 }
 
-void LogicSignal::paint_fore(QPainter &p, int left, int right)
+void LogicSignal::paint_fore(QPainter &p, const RowItemPaintParams &pp)
 {
-       (void)left;
-
        // Draw the trigger marker
        if (!trigger_match_)
                return;
@@ -262,7 +259,7 @@ void LogicSignal::paint_fore(QPainter &p, int left, int right)
                const int pad = TriggerMarkerPadding;
                const QSize size = pixmap->size();
                const QPoint point(
-                       right - size.width() - pad * 2,
+                       pp.right() - size.width() - pad * 2,
                        y - (SignalHeight + size.height()) / 2);
 
                p.setPen(QPen(Qt::NoPen));
index 11f81770ce174d0abbe45a063c834fe13a90a67e..c4588903ba83d3a5e6731d0b0a24c778620e4aa8 100644 (file)
@@ -84,26 +84,23 @@ public:
        /**
         * Paints the background layer of the signal with a QPainter
         * @param p the QPainter to paint into.
-        * @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 pp the painting parameters object to paint with..
         **/
-       void paint_back(QPainter &p, int left, int right);
+       void paint_back(QPainter &p, const RowItemPaintParams &pp);
 
        /**
         * Paints the mid-layer of the signal with a QPainter
         * @param p the QPainter to paint into.
-        * @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 pp the painting parameters object to paint with..
         **/
-       void paint_mid(QPainter &p, int left, int right);
+       void paint_mid(QPainter &p, const RowItemPaintParams &pp);
 
        /**
         * Paints the foreground layer of the signal with a QPainter
         * @param p the QPainter to paint into.
-        * @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 pp the painting parameters object to paint with.
         **/
-       virtual void paint_fore(QPainter &p, int left, int right);
+       virtual void paint_fore(QPainter &p, const RowItemPaintParams &pp);
 
 private:
        void paint_caps(QPainter &p, QLineF *const lines,
index 6e87de1019514a9a2ffa2727f0c1d5a63ea6f270..597c4a138ec53fa4ecde9d924d4307be529abb4c 100644 (file)
@@ -120,25 +120,22 @@ QPoint RowItem::point() const
        return QPoint(0, visual_v_offset());
 }
 
-void RowItem::paint_back(QPainter &p, int left, int right)
+void RowItem::paint_back(QPainter &p, const RowItemPaintParams &pp)
 {
        (void)p;
-       (void)left;
-       (void)right;
+       (void)pp;
 }
 
-void RowItem::paint_mid(QPainter &p, int left, int right)
+void RowItem::paint_mid(QPainter &p, const RowItemPaintParams &pp)
 {
        (void)p;
-       (void)left;
-       (void)right;
+       (void)pp;
 }
 
-void RowItem::paint_fore(QPainter &p, int left, int right)
+void RowItem::paint_fore(QPainter &p, const RowItemPaintParams &pp)
 {
        (void)p;
-       (void)left;
-       (void)right;
+       (void)pp;
 }
 
 void RowItem::hover_point_changed()
index d6233e8ce58fb3dbe57f024ade9f9bc14a1ec678..39c6f04030d1d214b688aa7ffedbbb0a8530f023 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <QPropertyAnimation>
 
+#include "rowitempaintparams.hpp"
 #include "selectableitem.hpp"
 
 namespace pv {
@@ -112,26 +113,23 @@ public:
        /**
         * Paints the background layer of the trace with a QPainter
         * @param p the QPainter to paint into.
-        * @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 pp the painting parameters object to paint with.
         **/
-       virtual void paint_back(QPainter &p, int left, int right);
+       virtual void paint_back(QPainter &p, const RowItemPaintParams &pp);
 
        /**
         * Paints the mid-layer of the trace with a QPainter
         * @param p the QPainter to paint into.
-        * @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 pp the painting parameters object to paint with.
         **/
-       virtual void paint_mid(QPainter &p, int left, int right);
+       virtual void paint_mid(QPainter &p, const RowItemPaintParams &pp);
 
        /**
         * Paints the foreground layer of the trace with a QPainter
         * @param p the QPainter to paint into.
-        * @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 pp the painting parameters object to paint with.
         **/
-       virtual void paint_fore(QPainter &p, int left, int right);
+       virtual void paint_fore(QPainter &p, const RowItemPaintParams &pp);
 
        /**
         * Paints the signal label.
diff --git a/pv/view/rowitempaintparams.cpp b/pv/view/rowitempaintparams.cpp
new file mode 100644 (file)
index 0000000..013c2a2
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <cassert>
+
+#include "rowitempaintparams.hpp"
+
+namespace pv {
+namespace view {
+
+RowItemPaintParams::RowItemPaintParams(int left, int right) :
+       left_(left),
+       right_(right) {
+       assert(left <= right);
+}
+
+} // namespace view
+} // namespace pv
diff --git a/pv/view/rowitempaintparams.hpp b/pv/view/rowitempaintparams.hpp
new file mode 100644 (file)
index 0000000..062b3cd
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#ifndef PULSEVIEW_PV_VIEW_ROWITEMPAINTPARAMS_H
+#define PULSEVIEW_PV_VIEW_ROWITEMPAINTPARAMS_H
+
+namespace pv {
+namespace view {
+
+class RowItemPaintParams
+{
+public:
+       RowItemPaintParams(int left, int right);
+
+       int left() const {
+               return left_;
+       }
+
+       int right() const {
+               return right_;
+       }
+
+       int width() const {
+               return right_ - left_;
+       }
+
+private:
+       int left_;
+       int right_;
+};
+
+} // namespace view
+} // namespace pv
+
+#endif // PULSEVIEW_PV_VIEW_ROWITEMPAINTPARAMS_H
index a94ada93faac055aae26761941e515b3318288a7..bc010b4bd02fa3cd11270397c87e2588df2af461 100644 (file)
@@ -22,6 +22,7 @@
 #include <cmath>
 #include <algorithm>
 
+#include "rowitempaintparams.hpp"
 #include "signal.hpp"
 #include "view.hpp"
 #include "viewport.hpp"
@@ -69,18 +70,20 @@ void Viewport::paintEvent(QPaintEvent*)
        if (view_.cursors_shown())
                view_.cursors().draw_viewport_background(p, rect());
 
+       const RowItemPaintParams pp(0, width());
+
        // Plot the signal
        for (const shared_ptr<RowItem> r : row_items)
        {
                assert(r);
-               r->paint_back(p, 0, width());
+               r->paint_back(p, pp);
        }
 
        for (const shared_ptr<RowItem> r : row_items)
-               r->paint_mid(p, 0, width());
+               r->paint_mid(p, pp);
 
        for (const shared_ptr<RowItem> r : row_items)
-               r->paint_fore(p, 0, width());
+               r->paint_fore(p, pp);
 
        if (view_.cursors_shown())
                view_.cursors().draw_viewport_foreground(p, rect());
index 10f26ddc678e6d7bc5b40b77e63f803666f1168b..891d22cbb11425c0535e4daf0fdbc9ba514995c1 100644 (file)
@@ -47,6 +47,7 @@ set(pulseview_TEST_SOURCES
        ${PROJECT_SOURCE_DIR}/pv/view/logicsignal.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/rowitem.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/rowitemowner.cpp
+       ${PROJECT_SOURCE_DIR}/pv/view/rowitempaintparams.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/ruler.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/selectableitem.cpp
        ${PROJECT_SOURCE_DIR}/pv/view/signal.cpp