Simplified duplication by using clone() method.

This commit is contained in:
Sofian Audry
2020-01-12 14:01:34 -05:00
parent 9ab5cb2e6e
commit fb6e52ea05
2 changed files with 17 additions and 18 deletions
+16
View File
@@ -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; }
+1 -18
View File
@@ -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);