! Removes the specified \a axis from the axis rect and deletes it. Returns true on success, i.e. if \a axis was a valid axis in this axis rect. \see addAxis */
| 17768 | \see addAxis |
| 17769 | */ |
| 17770 | bool QCPAxisRect::removeAxis(QCPAxis *axis) |
| 17771 | { |
| 17772 | // don't access axis->axisType() to provide safety when axis is an invalid pointer, rather go through all axis containers: |
| 17773 | QHashIterator<QCPAxis::AxisType, QList<QCPAxis*> > it(mAxes); |
| 17774 | while (it.hasNext()) |
| 17775 | { |
| 17776 | it.next(); |
| 17777 | if (it.value().contains(axis)) |
| 17778 | { |
| 17779 | if (it.value().first() == axis && it.value().size() > 1) // if removing first axis, transfer axis offset to the new first axis (which at this point is the second axis, if it exists) |
| 17780 | it.value()[1]->setOffset(axis->offset()); |
| 17781 | mAxes[it.key()].removeOne(axis); |
| 17782 | if (qobject_cast<QCustomPlot*>(parentPlot())) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the axis rect is not in any layout and thus QObject-child of QCustomPlot) |
| 17783 | parentPlot()->axisRemoved(axis); |
| 17784 | delete axis; |
| 17785 | return true; |
| 17786 | } |
| 17787 | } |
| 17788 | qDebug() << Q_FUNC_INFO << "Axis isn't in axis rect:" << reinterpret_cast<quintptr>(axis); |
| 17789 | return false; |
| 17790 | } |
| 17791 | |
| 17792 | /*! |
| 17793 | Zooms in (or out) to the passed rectangular region \a pixelRect, given in pixel coordinates. |