summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukáš Lalinský <lalinsky@gmail.com>2008-12-08 23:26:39 +0100
committerLukáš Lalinský <lalinsky@gmail.com>2008-12-08 23:26:39 +0100
commitad3633057235f3bc2bb9c1b47e9308df40622ac4 (patch)
treecf46e5ed4f75e0bade234ee6263314f133072bcd
parent52d99697c9865ea094b76cf5f644538875a9406b (diff)
downloaddbmodel-ad3633057235f3bc2bb9c1b47e9308df40622ac4.tar.gz
dbmodel-ad3633057235f3bc2bb9c1b47e9308df40622ac4.tar.bz2
Draw grid points in batches
-rw-r--r--src/diagramdocument.cpp32
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();
}
}