From ad3633057235f3bc2bb9c1b47e9308df40622ac4 Mon Sep 17 00:00:00 2001 From: Lukáš Lalinský Date: Mon, 8 Dec 2008 23:26:39 +0100 Subject: Draw grid points in batches --- src/diagramdocument.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src/diagramdocument.cpp') diff --git a/src/diagramdocument.cpp b/src/diagramdocument.cpp index 32b492e..d41ecdc 100644 --- a/src/diagramdocument.cpp +++ b/src/diagramdocument.cpp @@ -93,19 +93,33 @@ DiagramDocument::setGridColor(const QColor &color) void DiagramDocument::drawBackground(QPainter *painter, const QRectF &rect) { + const int pointBufferSize = 5000; + static QPoint pointBuffer[pointBufferSize]; if (!d->printing && d->gridVisible) { - qreal gridSize = d->gridSize; - qreal x0 = gridSize * floor(rect.left() / gridSize); - qreal y0 = gridSize * floor(rect.top() / gridSize); - qreal x1 = gridSize * ceil(rect.right() / gridSize); - qreal y1 = gridSize * ceil(rect.bottom() / gridSize); + int gridSize = d->gridSize; + int x0 = gridSize * floor(rect.left() / gridSize); + int y0 = gridSize * floor(rect.top() / gridSize); + int x1 = gridSize * ceil(rect.right() / gridSize); + int y1 = gridSize * ceil(rect.bottom() / gridSize); painter->save(); painter->setPen(d->gridPen); painter->setRenderHint(QPainter::Antialiasing, false); - // FIXME do this in one QPainter::drawPoints call - for (qreal x = x0; x < x1; x += gridSize) - for (qreal y = y0; y < y1; y += gridSize) - painter->drawPoint(x, y); + int pointsUsed = 0; + for (int x = x0; x < x1; x += gridSize) { + for (int y = y0; y < y1; y += gridSize) { + pointBuffer[pointsUsed].setX(x); + pointBuffer[pointsUsed].setY(y); + pointsUsed++; + if (pointsUsed == pointBufferSize) { + painter->drawPoints(pointBuffer, pointsUsed); + pointsUsed = 0; + } + } + } + if (pointsUsed > 0) { + painter->drawPoints(pointBuffer, pointsUsed); + pointsUsed = 0; + } painter->restore(); } } -- cgit v1.2.3-54-g00ecf