diff --git a/src/core/Mapping.h b/src/core/Mapping.h index f0a0894..502d26f 100644 --- a/src/core/Mapping.h +++ b/src/core/Mapping.h @@ -111,6 +111,9 @@ public: /// The type of the mapping (expressed as a string). virtual QString getType() const = 0; + // Return copy of this mapping. + virtual Mapping* clone() const = 0; + /// Returns true iff paint is compatible with mapping. virtual bool paintIsCompatible(Paint::ptr paint) const = 0; @@ -174,6 +177,12 @@ public: uid id=NULL_UID) : Mapping(paint, shape, id) {} + // Return copy of this mapping. + virtual Mapping* clone() const { + MShape::ptr shape(_shape->clone()); + return new ColorMapping(_paint, shape); + } + /// Returns true iff the mapping possesses an input (source) shape. virtual bool hasInputShape() const { return false; } @@ -206,6 +215,13 @@ public: Q_ASSERT(shape->getType() == inputShape->getType()); } + // Return copy of this mapping. + virtual Mapping* clone() const { + MShape::ptr shape(_shape->clone()); + MShape::ptr inputShape(_inputShape->clone()); + return new TextureMapping(_paint, shape, inputShape); + } + /// Returns true iff the mapping possesses an input (source) shape. virtual bool hasInputShape() const { return true; } diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 893803f..974a082 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1407,31 +1407,14 @@ void MainWindow::duplicateMapping(uid mappingId) // Current Mapping Mapping::ptr currentMapping = mappingManager->getMappingById(mappingId); - // Get Mapping Paint and Shape - Paint::ptr paintPtr = currentMapping->getPaint(); - - // Create new shape base on the current - MShape::ptr shape(currentMapping->getShape()->clone()); - - // Create a new input shape too - MShape::ptr inputShape; - if (currentMapping->hasInputShape()) - inputShape.reset(currentMapping->getInputShape()->clone()); - // Create new duplicated mapping item - Mapping::ptr clonedMappingPtr; - if (paintPtr->getType() == "color") // Color paint - //clonedMapping = new ColorMapping(paintPtr, shapePtr); - clonedMappingPtr = Mapping::ptr(new ColorMapping(paintPtr, shape)); - else // Or Texture Paint - //clonedMapping = new TextureMapping(paintPtr, shapePtr, inputShape); - clonedMappingPtr = Mapping::ptr(new TextureMapping(paintPtr, shape, inputShape)); // Scale the duplicated shapes if (shape->getType() == "mesh") shape->translate(QPointF(20, 20)); else shape->translate(QPointF(0, 20)); + Mapping::ptr clonedMappingPtr(currentMapping->clone()); // Get duplicated mapping id uid cloneId = mappingManager->addMapping(clonedMappingPtr);