From 32a0e0cc616fa9c34ecb6f839b933588f7d4ff3e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 2 Sep 2014 14:37:10 +0200 Subject: [PATCH] QCommonStyle: replace a QPolygon with a QPoint[] (I) No need to allocate dynamic memory for a fixed-size point array when QPainter has a (QPoint*,int) overload. Change-Id: I50c69103bba47e9f6de4f5616e8f40fee522ddc2 Reviewed-by: Friedemann Kleint --- src/widgets/styles/qcommonstyle.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index cc24c79c09..27431a4401 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -321,22 +321,24 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q if (const QStyleOptionHeader *header = qstyleoption_cast(opt)) { QPen oldPen = p->pen(); if (header->sortIndicator & QStyleOptionHeader::SortUp) { - QPolygon pa(3); p->setPen(QPen(opt->palette.light(), 0)); p->drawLine(opt->rect.x() + opt->rect.width(), opt->rect.y(), opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height()); p->setPen(QPen(opt->palette.dark(), 0)); - pa.setPoint(0, opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height()); - pa.setPoint(1, opt->rect.x(), opt->rect.y()); - pa.setPoint(2, opt->rect.x() + opt->rect.width(), opt->rect.y()); - p->drawPolyline(pa); + const QPoint points[] = { + QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height()), + QPoint(opt->rect.x(), opt->rect.y()), + QPoint(opt->rect.x() + opt->rect.width(), opt->rect.y()), + }; + p->drawPolyline(points, sizeof points / sizeof *points); } else if (header->sortIndicator & QStyleOptionHeader::SortDown) { - QPolygon pa(3); p->setPen(QPen(opt->palette.light(), 0)); - pa.setPoint(0, opt->rect.x(), opt->rect.y() + opt->rect.height()); - pa.setPoint(1, opt->rect.x() + opt->rect.width(), opt->rect.y() + opt->rect.height()); - pa.setPoint(2, opt->rect.x() + opt->rect.width() / 2, opt->rect.y()); - p->drawPolyline(pa); + const QPoint points[] = { + QPoint(opt->rect.x(), opt->rect.y() + opt->rect.height()), + QPoint(opt->rect.x() + opt->rect.width(), opt->rect.y() + opt->rect.height()), + QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y()), + }; + p->drawPolyline(points, sizeof points / sizeof *points); p->setPen(QPen(opt->palette.dark(), 0)); p->drawLine(opt->rect.x(), opt->rect.y() + opt->rect.height(), opt->rect.x() + opt->rect.width() / 2, opt->rect.y());