X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fviewport.cpp;h=a179cef1c6ca572609e12ad10ad3ad2de2eef59e;hp=2d10f2a054fadb31dc47783d3395460c54fb2c0a;hb=60938e0430a0d08792ba53b86ca94153baaed74d;hpb=6f925ba9d6faf1077b73c5a5808259576081716a
diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp
index 2d10f2a0..a179cef1 100644
--- a/pv/view/viewport.cpp
+++ b/pv/view/viewport.cpp
@@ -17,9 +17,9 @@
* along with this program; if not, see .
*/
+#include
#include
#include
-#include
#include
#include "signal.hpp"
@@ -37,10 +37,7 @@ using std::abs;
using std::back_inserter;
using std::copy;
using std::dynamic_pointer_cast;
-using std::max;
-using std::min;
-using std::none_of;
-using std::numeric_limits;
+using std::none_of; // Used in assert()s.
using std::shared_ptr;
using std::stable_sort;
using std::vector;
@@ -62,8 +59,7 @@ shared_ptr Viewport::get_mouse_over_item(const QPoint &pt)
const ViewItemPaintParams pp(rect(), view_.scale(), view_.offset());
const vector< shared_ptr > items(this->items());
for (auto i = items.rbegin(); i != items.rend(); i++)
- if ((*i)->enabled() &&
- (*i)->hit_box_rect(pp).contains(pt))
+ if ((*i)->enabled() && (*i)->hit_box_rect(pp).contains(pt))
return *i;
return nullptr;
}
@@ -157,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; }));
@@ -172,24 +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 (const shared_ptr t : time_items)
- t->paint_mid(p, pp);
- for (const shared_ptr r : row_items)
- r->paint_mid(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 r : row_items)
- r->paint_fore(p, pp);
-
- p.setRenderHint(QPainter::Antialiasing, false);
- 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();
}