! Adds a new layer to this QCustomPlot instance. The new layer will have the name \a name, which must be unique. Depending on \a insertMode, it is positioned either below or above \a otherLayer. Returns true on success, i.e. if there is no other layer named \a name and \a otherLayer is a valid layer inside this QCustomPlot. If \a otherLayer is 0, the highest layer in the QCustomPlo
| 14067 | \see layer, moveLayer, removeLayer |
| 14068 | */ |
| 14069 | bool QCustomPlot::addLayer(const QString &name, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) |
| 14070 | { |
| 14071 | if (!otherLayer) |
| 14072 | otherLayer = mLayers.last(); |
| 14073 | if (!mLayers.contains(otherLayer)) |
| 14074 | { |
| 14075 | qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast<quintptr>(otherLayer); |
| 14076 | return false; |
| 14077 | } |
| 14078 | if (layer(name)) |
| 14079 | { |
| 14080 | qDebug() << Q_FUNC_INFO << "A layer exists already with the name" << name; |
| 14081 | return false; |
| 14082 | } |
| 14083 | |
| 14084 | QCPLayer *newLayer = new QCPLayer(this, name); |
| 14085 | mLayers.insert(otherLayer->index() + (insertMode==limAbove ? 1:0), newLayer); |
| 14086 | updateLayerIndices(); |
| 14087 | setupPaintBuffers(); // associates new layer with the appropriate paint buffer |
| 14088 | return true; |
| 14089 | } |
| 14090 | |
| 14091 | /*! |
| 14092 | Removes the specified \a layer and returns true on success. |