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

Method addAxis

qcustomplot/qcustomplot.cpp:16959–17004  ·  view source on GitHub ↗

! Adds a new axis to the axis rect side specified with \a type, and returns it. If \a axis is 0, a new QCPAxis instance is created internally. QCustomPlot owns the returned axis, so if you want to remove an axis, use \ref removeAxis instead of deleting it manually. You may inject QCPAxis instances (or subclasses of QCPAxis) by setting \a axis to an axis that was previously created outsi

Source from the content-addressed store, hash-verified

16957 \see addAxes, setupFullAxesBox
16958*/
16959QCPAxis *QCPAxisRect::addAxis(QCPAxis::AxisType type, QCPAxis *axis)
16960{
16961 QCPAxis *newAxis = axis;
16962 if (!newAxis)
16963 {
16964 newAxis = new QCPAxis(this, type);
16965 } else // user provided existing axis instance, do some sanity checks
16966 {
16967 if (newAxis->axisType() != type)
16968 {
16969 qDebug() << Q_FUNC_INFO << "passed axis has different axis type than specified in type parameter";
16970 return 0;
16971 }
16972 if (newAxis->axisRect() != this)
16973 {
16974 qDebug() << Q_FUNC_INFO << "passed axis doesn't have this axis rect as parent axis rect";
16975 return 0;
16976 }
16977 if (axes().contains(newAxis))
16978 {
16979 qDebug() << Q_FUNC_INFO << "passed axis is already owned by this axis rect";
16980 return 0;
16981 }
16982 }
16983 if (mAxes[type].size() > 0) // multiple axes on one side, add half-bar axis ending to additional axes with offset
16984 {
16985 bool invert = (type == QCPAxis::atRight) || (type == QCPAxis::atBottom);
16986 newAxis->setLowerEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, !invert));
16987 newAxis->setUpperEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, invert));
16988 }
16989 mAxes[type].append(newAxis);
16990
16991 // reset convenience axis pointers on parent QCustomPlot if they are unset:
16992 if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this)
16993 {
16994 switch (type)
16995 {
16996 case QCPAxis::atBottom: { if (!mParentPlot->xAxis) mParentPlot->xAxis = newAxis; break; }
16997 case QCPAxis::atLeft: { if (!mParentPlot->yAxis) mParentPlot->yAxis = newAxis; break; }
16998 case QCPAxis::atTop: { if (!mParentPlot->xAxis2) mParentPlot->xAxis2 = newAxis; break; }
16999 case QCPAxis::atRight: { if (!mParentPlot->yAxis2) mParentPlot->yAxis2 = newAxis; break; }
17000 }
17001 }
17002
17003 return newAxis;
17004}
17005
17006/*!
17007 Adds a new axis with \ref addAxis to each axis rect side specified in \a types. This may be an

Callers

nothing calls this directly

Calls 7

axisRectMethod · 0.80
containsMethod · 0.80
setLowerEndingMethod · 0.80
setUpperEndingMethod · 0.80
appendMethod · 0.80
axisRectCountMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected