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

Method removeLayer

qcustomplot/qcustomplot.cpp:14105–14143  ·  view source on GitHub ↗

! 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

Source from the content-addressed store, hash-verified

14103 \see layer, addLayer, moveLayer
14104*/
14105bool QCustomPlot::removeLayer(QCPLayer *layer)
14106{
14107 if (!mLayers.contains(layer))
14108 {
14109 qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast<quintptr>(layer);
14110 return false;
14111 }
14112 if (mLayers.size() < 2)
14113 {
14114 qDebug() << Q_FUNC_INFO << "can't remove last layer";
14115 return false;
14116 }
14117
14118 // append all children of this layer to layer below (if this is lowest layer, prepend to layer above)
14119 int removedIndex = layer->index();
14120 bool isFirstLayer = removedIndex==0;
14121 QCPLayer *targetLayer = isFirstLayer ? mLayers.at(removedIndex+1) : mLayers.at(removedIndex-1);
14122 QList<QCPLayerable*> children = layer->children();
14123 if (isFirstLayer) // prepend in reverse order (so order relative to each other stays the same)
14124 {
14125 for (int i=children.size()-1; i>=0; --i)
14126 children.at(i)->moveToLayer(targetLayer, true);
14127 } else // append normally
14128 {
14129 for (int i=0; i<children.size(); ++i)
14130 children.at(i)->moveToLayer(targetLayer, false);
14131 }
14132 // if removed layer is current layer, change current layer to layer below/above:
14133 if (layer == mCurrentLayer)
14134 setCurrentLayer(targetLayer);
14135 // invalidate the paint buffer that was responsible for this layer:
14136 if (!layer->mPaintBuffer.isNull())
14137 layer->mPaintBuffer.data()->setInvalidated();
14138 // remove layer:
14139 delete layer;
14140 mLayers.removeOne(layer);
14141 updateLayerIndices();
14142 return true;
14143}
14144
14145/*!
14146 Moves the specified \a layer either above or below \a otherLayer. Whether it's placed above or

Callers

nothing calls this directly

Calls 6

containsMethod · 0.80
atMethod · 0.80
moveToLayerMethod · 0.80
setInvalidatedMethod · 0.80
dataMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected