! Removes the specified \a layer and returns true on success. All layerables (e.g. plottables and items) on the removed layer will be moved to the layer below \a layer. If \a layer is the bottom layer, the layerables are moved to the layer above. In both cases, the total rendering order of all layerables in the QCustomPlot is preserved. If \a layer is the current layer (\ref setCur
| 14798 | \see layer, addLayer, moveLayer |
| 14799 | */ |
| 14800 | bool QCustomPlot::removeLayer(QCPLayer *layer) |
| 14801 | { |
| 14802 | if (!mLayers.contains(layer)) |
| 14803 | { |
| 14804 | qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast<quintptr>(layer); |
| 14805 | return false; |
| 14806 | } |
| 14807 | if (mLayers.size() < 2) |
| 14808 | { |
| 14809 | qDebug() << Q_FUNC_INFO << "can't remove last layer"; |
| 14810 | return false; |
| 14811 | } |
| 14812 | |
| 14813 | // append all children of this layer to layer below (if this is lowest layer, prepend to layer above) |
| 14814 | int removedIndex = layer->index(); |
| 14815 | bool isFirstLayer = removedIndex==0; |
| 14816 | QCPLayer *targetLayer = isFirstLayer ? mLayers.at(removedIndex+1) : mLayers.at(removedIndex-1); |
| 14817 | QList<QCPLayerable*> children = layer->children(); |
| 14818 | if (isFirstLayer) // prepend in reverse order (such that relative order stays the same) |
| 14819 | std::reverse(children.begin(), children.end()); |
| 14820 | foreach (QCPLayerable *child, children) |
| 14821 | child->moveToLayer(targetLayer, isFirstLayer); // prepend if isFirstLayer, otherwise append |
| 14822 | |
| 14823 | // if removed layer is current layer, change current layer to layer below/above: |
| 14824 | if (layer == mCurrentLayer) |
| 14825 | setCurrentLayer(targetLayer); |
| 14826 | |
| 14827 | // invalidate the paint buffer that was responsible for this layer: |
| 14828 | if (QSharedPointer<QCPAbstractPaintBuffer> pb = layer->mPaintBuffer.toStrongRef()) |
| 14829 | pb->setInvalidated(); |
| 14830 | |
| 14831 | // remove layer: |
| 14832 | delete layer; |
| 14833 | mLayers.removeOne(layer); |
| 14834 | updateLayerIndices(); |
| 14835 | return true; |
| 14836 | } |
| 14837 | |
| 14838 | /*! |
| 14839 | Moves the specified \a layer either above or below \a otherLayer. Whether it's placed above or |
nothing calls this directly
no test coverage detected