diff options
author | Lukáš Lalinský <lalinsky@gmail.com> | 2008-12-08 23:26:39 +0100 |
---|---|---|
committer | Lukáš Lalinský <lalinsky@gmail.com> | 2008-12-08 23:26:39 +0100 |
commit | ad3633057235f3bc2bb9c1b47e9308df40622ac4 (patch) | |
tree | cf46e5ed4f75e0bade234ee6263314f133072bcd | |
parent | 52d99697c9865ea094b76cf5f644538875a9406b (diff) | |
download | dbmodel-ad3633057235f3bc2bb9c1b47e9308df40622ac4.tar.gz dbmodel-ad3633057235f3bc2bb9c1b47e9308df40622ac4.tar.bz2 |
Draw grid points in batches
-rw-r--r-- | src/diagramdocument.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
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(); } } |