! \internal Draws the main grid lines and possibly a zero line with the specified painter. This is a helper function called by \ref draw. */
| 7265 | This is a helper function called by \ref draw. |
| 7266 | */ |
| 7267 | void QCPGrid::drawGridLines(QCPPainter *painter) const |
| 7268 | { |
| 7269 | if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } |
| 7270 | |
| 7271 | const int tickCount = mParentAxis->mTickVector.size(); |
| 7272 | double t; // helper variable, result of coordinate-to-pixel transforms |
| 7273 | if (mParentAxis->orientation() == Qt::Horizontal) |
| 7274 | { |
| 7275 | // draw zeroline: |
| 7276 | int zeroLineIndex = -1; |
| 7277 | if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) |
| 7278 | { |
| 7279 | applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); |
| 7280 | painter->setPen(mZeroLinePen); |
| 7281 | double epsilon = mParentAxis->range().size()*1E-6; // for comparing double to zero |
| 7282 | for (int i=0; i<tickCount; ++i) |
| 7283 | { |
| 7284 | if (qAbs(mParentAxis->mTickVector.at(i)) < epsilon) |
| 7285 | { |
| 7286 | zeroLineIndex = i; |
| 7287 | t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x |
| 7288 | painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); |
| 7289 | break; |
| 7290 | } |
| 7291 | } |
| 7292 | } |
| 7293 | // draw grid lines: |
| 7294 | applyDefaultAntialiasingHint(painter); |
| 7295 | painter->setPen(mPen); |
| 7296 | for (int i=0; i<tickCount; ++i) |
| 7297 | { |
| 7298 | if (i == zeroLineIndex) continue; // don't draw a gridline on top of the zeroline |
| 7299 | t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x |
| 7300 | painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); |
| 7301 | } |
| 7302 | } else |
| 7303 | { |
| 7304 | // draw zeroline: |
| 7305 | int zeroLineIndex = -1; |
| 7306 | if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) |
| 7307 | { |
| 7308 | applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); |
| 7309 | painter->setPen(mZeroLinePen); |
| 7310 | double epsilon = mParentAxis->mRange.size()*1E-6; // for comparing double to zero |
| 7311 | for (int i=0; i<tickCount; ++i) |
| 7312 | { |
| 7313 | if (qAbs(mParentAxis->mTickVector.at(i)) < epsilon) |
| 7314 | { |
| 7315 | zeroLineIndex = i; |
| 7316 | t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // y |
| 7317 | painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); |
| 7318 | break; |
| 7319 | } |
| 7320 | } |
| 7321 | } |
| 7322 | // draw grid lines: |
| 7323 | applyDefaultAntialiasingHint(painter); |
| 7324 | painter->setPen(mPen); |