Exemple #1
0
/**
 * Ungroups the given \a layer. If the layer itself is a group layer, then this
 * group is ungrouped. Otherwise, if the layer is part of a group layer, then
 * it is removed from the group.
 */
void MapDocument::ungroupLayer(Layer *layer)
{
    if (!layer)
        return;

    GroupLayer *groupLayer = layer->asGroupLayer();
    QList<Layer *> layers;

    if (groupLayer) {
        layers = groupLayer->layers();
    } else if (layer->parentLayer()) {
        layers.append(layer);
        groupLayer = layer->parentLayer();
    } else {
        // No ungrouping possible
        return;
    }

    GroupLayer *targetParent = groupLayer->parentLayer();
    int groupIndex = groupLayer->siblingIndex();

    mUndoStack->beginMacro(tr("Ungroup Layer"));
    mUndoStack->push(new ReparentLayers(this, layers, targetParent, groupIndex + 1));

    if (groupLayer->layerCount() == 0)
        mUndoStack->push(new RemoveLayer(this, groupIndex, targetParent));

    mUndoStack->endMacro();
}
QVariant MapToVariantConverter::toVariant(const GroupLayer &groupLayer,
                                          Map::LayerDataFormat format) const
{
    QVariantMap groupLayerVariant;
    groupLayerVariant[QLatin1String("type")] = QLatin1String("group");

    addLayerAttributes(groupLayerVariant, groupLayer);

    groupLayerVariant[QLatin1String("layers")] = toVariant(groupLayer.layers(),
                                                           format);

    return groupLayerVariant;
}