MCPcopy Create free account
hub / github.com/CieNTi/serial_port_plotter / drawGridLines

Method drawGridLines

qcustomplot/qcustomplot.cpp:7274–7339  ·  view source on GitHub ↗

! \internal Draws the main grid lines and possibly a zero line with the specified painter. This is a helper function called by \ref draw. */

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

setPenMethod · 0.80
rangeMethod · 0.80
atMethod · 0.80
coordToPixelMethod · 0.80
drawLineMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected