From: Joel Holdsworth Date: Wed, 26 Apr 2017 17:09:10 +0000 (-0600) Subject: ViewPort: Make ViewItemPaintParams mutable X-Git-Tag: pulseview-0.4.0~94 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=60938e0430a0d08792ba53b86ca94153baaed74d;p=pulseview.git ViewPort: Make ViewItemPaintParams mutable --- diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index 906bbabb..b9d73126 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -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; diff --git a/pv/view/analogsignal.hpp b/pv/view/analogsignal.hpp index 5ea24039..eef424d5 100644 --- a/pv/view/analogsignal.hpp +++ b/pv/view/analogsignal.hpp @@ -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 > &edges, diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp index 24d03665..05b9dfca 100644 --- a/pv/view/cursorpair.cpp +++ b/pv/view/cursorpair.cpp @@ -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; diff --git a/pv/view/cursorpair.hpp b/pv/view/cursorpair.hpp index 458f5cac..ee91ff42 100644 --- a/pv/view/cursorpair.hpp +++ b/pv/view/cursorpair.hpp @@ -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. diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index f45ecf58..74d0dd65 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -170,13 +170,13 @@ pair 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; diff --git a/pv/view/decodetrace.hpp b/pv/view/decodetrace.hpp index 648bb04a..c4cb6fa5 100644 --- a/pv/view/decodetrace.hpp +++ b/pv/view/decodetrace.hpp @@ -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); diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index 86d45a43..3593a5d0 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -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()) diff --git a/pv/view/logicsignal.hpp b/pv/view/logicsignal.hpp index 27312023..cc62d910 100644 --- a/pv/view/logicsignal.hpp +++ b/pv/view/logicsignal.hpp @@ -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, diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index 065715aa..960cefa6 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -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); diff --git a/pv/view/signal.hpp b/pv/view/signal.hpp index 2bb8da1b..40ba52ea 100644 --- a/pv/view/signal.hpp +++ b/pv/view/signal.hpp @@ -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); diff --git a/pv/view/signalscalehandle.cpp b/pv/view/signalscalehandle.cpp index aa0201b6..20a4cad4 100644 --- a/pv/view/signalscalehandle.cpp +++ b/pv/view/signalscalehandle.cpp @@ -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; diff --git a/pv/view/signalscalehandle.hpp b/pv/view/signalscalehandle.hpp index 63746625..193d352f 100644 --- a/pv/view/signalscalehandle.hpp +++ b/pv/view/signalscalehandle.hpp @@ -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_; diff --git a/pv/view/timemarker.cpp b/pv/view/timemarker.cpp index 88616bf2..eaa03b94 100644 --- a/pv/view/timemarker.cpp +++ b/pv/view/timemarker.cpp @@ -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; diff --git a/pv/view/timemarker.hpp b/pv/view/timemarker.hpp index 9dd43886..dba52fa4 100644 --- a/pv/view/timemarker.hpp +++ b/pv/view/timemarker.hpp @@ -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; diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 66f13edb..f6d4164e 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -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); diff --git a/pv/view/trace.hpp b/pv/view/trace.hpp index 882c2d70..f9119850 100644 --- a/pv/view/trace.hpp +++ b/pv/view/trace.hpp @@ -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); diff --git a/pv/view/triggermarker.cpp b/pv/view/triggermarker.cpp index 8cb76ebb..bac1e82d 100644 --- a/pv/view/triggermarker.cpp +++ b/pv/view/triggermarker.cpp @@ -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; diff --git a/pv/view/triggermarker.hpp b/pv/view/triggermarker.hpp index a1837277..b1610a5b 100644 --- a/pv/view/triggermarker.hpp +++ b/pv/view/triggermarker.hpp @@ -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_; diff --git a/pv/view/viewitem.cpp b/pv/view/viewitem.cpp index 05e14164..7213f96d 100644 --- a/pv/view/viewitem.cpp +++ b/pv/view/viewitem.cpp @@ -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; diff --git a/pv/view/viewitem.hpp b/pv/view/viewitem.hpp index 2886ea1e..978cb91c 100644 --- a/pv/view/viewitem.hpp +++ b/pv/view/viewitem.hpp @@ -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: /** diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 2ed43ba2..a179cef1 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -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 > row_items(view_.list_by_type()); assert(none_of(row_items.begin(), row_items.end(), [](const shared_ptr &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 t : time_items) - t->paint_back(p, pp); - for (const shared_ptr 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 t : time_items) + (t.get()->*(*paint_func))(p, time_pp); - for (const shared_ptr t : time_items) - t->paint_mid(p, pp); - for (const shared_ptr r : row_items) - r->paint_mid(p, pp); - - for (const shared_ptr r : row_items) - r->paint_fore(p, pp); - - for (const shared_ptr t : time_items) - t->paint_fore(p, pp); + ViewItemPaintParams row_pp(rect(), view_.scale(), view_.offset()); + for (const shared_ptr r : row_items) + (r.get()->*(*paint_func))(p, row_pp); + } p.end(); }