MaterialStyle加入深拷贝方法clone
parent
b981056674
commit
6508f54333
|
@ -18,7 +18,7 @@ LayerStyleDialog::LayerStyleDialog(
|
||||||
|
|
||||||
if (existedStyle)
|
if (existedStyle)
|
||||||
{
|
{
|
||||||
this->modifyingStyle = std::make_unique<LayerStyle>(existedStyle->clonePtr());
|
this->modifyingStyle = existedStyle->clonePtr();
|
||||||
|
|
||||||
this->styleContainer = nullptr;
|
this->styleContainer = nullptr;
|
||||||
this->styleWidget = modifyingStyle->getInputWidget();
|
this->styleWidget = modifyingStyle->getInputWidget();
|
||||||
|
|
|
@ -54,9 +54,9 @@ StrokeElementLayerStyle::StrokeElementLayerStyle(const StrokeElementLayerStyle&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<LayerStyle> StrokeElementLayerStyle::clonePtr() const
|
std::unique_ptr<LayerStyle> StrokeElementLayerStyle::clonePtr() const
|
||||||
{
|
{
|
||||||
return std::make_shared<LayerStyle>(StrokeElementLayerStyle(*this));
|
return std::make_unique<StrokeElementLayerStyle>(StrokeElementLayerStyle(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Renderer::BaseStyle> FillElementLayerStyle::toBaseStyles() const
|
std::vector<Renderer::BaseStyle> FillElementLayerStyle::toBaseStyles() const
|
||||||
|
@ -97,7 +97,7 @@ FillElementLayerStyle::FillElementLayerStyle(const FillElementLayerStyle& other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<LayerStyle> FillElementLayerStyle::clonePtr() const
|
std::unique_ptr<LayerStyle> FillElementLayerStyle::clonePtr() const
|
||||||
{
|
{
|
||||||
return std::make_shared<LayerStyle>(FillElementLayerStyle(*this));
|
return std::make_unique<FillElementLayerStyle>(FillElementLayerStyle(*this));
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
virtual QWidget* getInputWidget() const = 0;
|
virtual QWidget* getInputWidget() const = 0;
|
||||||
virtual QWidget* getListDisplayWidget() const = 0;
|
virtual QWidget* getListDisplayWidget() const = 0;
|
||||||
virtual ~LayerStyle() {};
|
virtual ~LayerStyle() {};
|
||||||
virtual std::shared_ptr<LayerStyle> clonePtr() const = 0;
|
virtual std::unique_ptr<LayerStyle> clonePtr() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class StrokeElementLayerStyle : public Renderer::ElementStyle, public LayerStyle
|
class StrokeElementLayerStyle : public Renderer::ElementStyle, public LayerStyle
|
||||||
|
@ -38,7 +38,7 @@ public:
|
||||||
StrokeElementLayerStyle(const StrokeElementLayerStyle& other);
|
StrokeElementLayerStyle(const StrokeElementLayerStyle& other);
|
||||||
~StrokeElementLayerStyle() = default;
|
~StrokeElementLayerStyle() = default;
|
||||||
std::vector<std::shared_ptr<Renderer::MaterialStyleStroke>> materialStyles;
|
std::vector<std::shared_ptr<Renderer::MaterialStyleStroke>> materialStyles;
|
||||||
std::shared_ptr<LayerStyle> clonePtr() const override;
|
std::unique_ptr<LayerStyle> clonePtr() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FillElementLayerStyle : public Renderer::ElementStyle, public LayerStyle
|
class FillElementLayerStyle : public Renderer::ElementStyle, public LayerStyle
|
||||||
|
@ -52,5 +52,5 @@ public:
|
||||||
FillElementLayerStyle(const FillElementLayerStyle& other);
|
FillElementLayerStyle(const FillElementLayerStyle& other);
|
||||||
~FillElementLayerStyle() = default;
|
~FillElementLayerStyle() = default;
|
||||||
std::vector<std::shared_ptr<Renderer::MaterialStyleFill>> materialStyles;
|
std::vector<std::shared_ptr<Renderer::MaterialStyleFill>> materialStyles;
|
||||||
std::shared_ptr<LayerStyle> clonePtr() const override;
|
std::unique_ptr<LayerStyle> clonePtr() const override;
|
||||||
};
|
};
|
|
@ -23,6 +23,7 @@ namespace Renderer
|
||||||
public:
|
public:
|
||||||
virtual MaterialStyleType type() const = 0;
|
virtual MaterialStyleType type() const = 0;
|
||||||
virtual std::vector<GLfloat> encoded() const = 0;
|
virtual std::vector<GLfloat> encoded() const = 0;
|
||||||
|
virtual std::unique_ptr<MaterialStyle> clone() const = 0;
|
||||||
virtual bool operator==(const MaterialStyle&) const = 0;
|
virtual bool operator==(const MaterialStyle&) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,11 @@ std::vector<GLfloat> Renderer::FillPlain::encoded() const
|
||||||
glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(color.redF(), color.greenF(), color.blueF(), color.alphaF())))};
|
glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(color.redF(), color.greenF(), color.blueF(), color.alphaF())))};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<MaterialFill> Renderer::FillPlain::clone() const
|
||||||
|
{
|
||||||
|
return std::make_unique<FillPlain>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
bool Renderer::FillPlain::operator==(const MaterialFill& m) const
|
bool Renderer::FillPlain::operator==(const MaterialFill& m) const
|
||||||
{
|
{
|
||||||
return type() == m.type()
|
return type() == m.type()
|
||||||
|
@ -42,6 +47,11 @@ std::vector<GLfloat> Renderer::MaterialStyleFill::encoded() const
|
||||||
return materialFill->encoded();
|
return materialFill->encoded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<MaterialStyle> Renderer::MaterialStyleFill::clone() const
|
||||||
|
{
|
||||||
|
return std::make_unique<MaterialStyleFill>(materialFill->clone());
|
||||||
|
}
|
||||||
|
|
||||||
bool Renderer::MaterialStyleFill::operator==(const MaterialStyle& m) const
|
bool Renderer::MaterialStyleFill::operator==(const MaterialStyle& m) const
|
||||||
{
|
{
|
||||||
return type() == m.type() && *materialFill == *static_cast<const MaterialStyleFill&>(m).materialFill;
|
return type() == m.type() && *materialFill == *static_cast<const MaterialStyleFill&>(m).materialFill;
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace Renderer
|
||||||
public:
|
public:
|
||||||
virtual MaterialFillType type() const = 0;
|
virtual MaterialFillType type() const = 0;
|
||||||
virtual std::vector<GLfloat> encoded() const = 0;
|
virtual std::vector<GLfloat> encoded() const = 0;
|
||||||
|
virtual std::unique_ptr<MaterialFill> clone() const = 0;
|
||||||
virtual bool operator==(const MaterialFill&) const = 0;
|
virtual bool operator==(const MaterialFill&) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ namespace Renderer
|
||||||
FillPlain(QColor color, float metallic, float roughness);
|
FillPlain(QColor color, float metallic, float roughness);
|
||||||
virtual MaterialFillType type() const override;
|
virtual MaterialFillType type() const override;
|
||||||
virtual std::vector<GLfloat> encoded() const override;
|
virtual std::vector<GLfloat> encoded() const override;
|
||||||
|
virtual std::unique_ptr<MaterialFill> clone() const override;
|
||||||
virtual bool operator==(const MaterialFill&) const override;
|
virtual bool operator==(const MaterialFill&) const override;
|
||||||
|
|
||||||
QColor color;
|
QColor color;
|
||||||
|
@ -32,6 +34,7 @@ namespace Renderer
|
||||||
MaterialStyleFill(std::shared_ptr<MaterialFill> materialFill);
|
MaterialStyleFill(std::shared_ptr<MaterialFill> materialFill);
|
||||||
virtual MaterialStyleType type() const override;
|
virtual MaterialStyleType type() const override;
|
||||||
virtual std::vector<GLfloat> encoded() const override;
|
virtual std::vector<GLfloat> encoded() const override;
|
||||||
|
virtual std::unique_ptr<MaterialStyle> clone() const override;
|
||||||
virtual bool operator==(const MaterialStyle&) const override;
|
virtual bool operator==(const MaterialStyle&) const override;
|
||||||
//protected:
|
//protected:
|
||||||
std::shared_ptr<MaterialFill> materialFill;
|
std::shared_ptr<MaterialFill> materialFill;
|
||||||
|
|
|
@ -18,6 +18,11 @@ MaterialStrokeType Renderer::StrokePlain::type() const
|
||||||
return MaterialStrokeType::kPlain;
|
return MaterialStrokeType::kPlain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<MaterialStroke> Renderer::StrokePlain::clone() const
|
||||||
|
{
|
||||||
|
return std::make_unique<StrokePlain>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<GLfloat> Renderer::StrokePlain::encoded() const
|
std::vector<GLfloat> Renderer::StrokePlain::encoded() const
|
||||||
{
|
{
|
||||||
return { glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(material.toVec().second, 0.f, 0.f))),
|
return { glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(material.toVec().second, 0.f, 0.f))),
|
||||||
|
@ -58,6 +63,11 @@ std::vector<GLfloat> Renderer::StrokeRadialGradient::encoded() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<MaterialStroke> Renderer::StrokeRadialGradient::clone() const
|
||||||
|
{
|
||||||
|
return std::make_unique<StrokeRadialGradient>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
bool Renderer::StrokeRadialGradient::operator==(const MaterialStroke& m) const
|
bool Renderer::StrokeRadialGradient::operator==(const MaterialStroke& m) const
|
||||||
{
|
{
|
||||||
return type() == m.type()
|
return type() == m.type()
|
||||||
|
@ -70,12 +80,6 @@ Renderer::MaterialStyleStroke::MaterialStyleStroke(float width, StrokeType strok
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::MaterialStyleStroke::MaterialStyleStroke(const MaterialStyleStroke& s)
|
|
||||||
:halfWidth(s.halfWidth), strokeType(s.strokeType), endType(s.endType), materialStroke(std::make_shared<MaterialStroke>(*s.materialStroke))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
MaterialStyleType Renderer::MaterialStyleStroke::type() const
|
MaterialStyleType Renderer::MaterialStyleStroke::type() const
|
||||||
{
|
{
|
||||||
return MaterialStyleType::kStroke;
|
return MaterialStyleType::kStroke;
|
||||||
|
@ -93,6 +97,11 @@ std::vector<GLfloat> Renderer::MaterialStyleStroke::encoded() const
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<MaterialStyle> Renderer::MaterialStyleStroke::clone() const
|
||||||
|
{
|
||||||
|
return std::make_unique<MaterialStyleStroke>(halfWidth*2, strokeType, endType, materialStroke->clone());
|
||||||
|
}
|
||||||
|
|
||||||
bool Renderer::MaterialStyleStroke::operator==(const MaterialStyle& m) const
|
bool Renderer::MaterialStyleStroke::operator==(const MaterialStyle& m) const
|
||||||
{
|
{
|
||||||
return type() == m.type() && *materialStroke == *static_cast<const MaterialStyleStroke&>(m).materialStroke;
|
return type() == m.type() && *materialStroke == *static_cast<const MaterialStyleStroke&>(m).materialStroke;
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace Renderer
|
||||||
public:
|
public:
|
||||||
virtual MaterialStrokeType type() const = 0;
|
virtual MaterialStrokeType type() const = 0;
|
||||||
virtual std::vector<GLfloat> encoded() const = 0;
|
virtual std::vector<GLfloat> encoded() const = 0;
|
||||||
|
virtual std::unique_ptr<MaterialStroke> clone() const = 0;
|
||||||
virtual bool operator==(const MaterialStroke&) const = 0;
|
virtual bool operator==(const MaterialStroke&) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,7 +21,9 @@ namespace Renderer
|
||||||
StrokePlain(QColor color, float metallic, float roughness);
|
StrokePlain(QColor color, float metallic, float roughness);
|
||||||
StrokePlain(const Material& material);
|
StrokePlain(const Material& material);
|
||||||
virtual MaterialStrokeType type() const override;
|
virtual MaterialStrokeType type() const override;
|
||||||
|
virtual std::unique_ptr<MaterialStroke> clone() const override;
|
||||||
virtual std::vector<GLfloat> encoded() const override;
|
virtual std::vector<GLfloat> encoded() const override;
|
||||||
|
|
||||||
virtual bool operator==(const MaterialStroke&) const override;
|
virtual bool operator==(const MaterialStroke&) const override;
|
||||||
|
|
||||||
Material material;
|
Material material;
|
||||||
|
@ -32,6 +35,7 @@ namespace Renderer
|
||||||
StrokeRadialGradient(const std::map<float, Material>& materialMap, bool gradual);
|
StrokeRadialGradient(const std::map<float, Material>& materialMap, bool gradual);
|
||||||
virtual MaterialStrokeType type() const override;
|
virtual MaterialStrokeType type() const override;
|
||||||
virtual std::vector<GLfloat> encoded() const override;
|
virtual std::vector<GLfloat> encoded() const override;
|
||||||
|
virtual std::unique_ptr<MaterialStroke> clone() const override;
|
||||||
virtual bool operator==(const MaterialStroke&) const override;
|
virtual bool operator==(const MaterialStroke&) const override;
|
||||||
|
|
||||||
std::map<float, Material> materialMap;
|
std::map<float, Material> materialMap;
|
||||||
|
@ -45,9 +49,9 @@ namespace Renderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MaterialStyleStroke(float width, StrokeType strokeType, StrokeEndType endType, std::shared_ptr<MaterialStroke> materialStroke);
|
MaterialStyleStroke(float width, StrokeType strokeType, StrokeEndType endType, std::shared_ptr<MaterialStroke> materialStroke);
|
||||||
MaterialStyleStroke(const MaterialStyleStroke&);
|
|
||||||
virtual MaterialStyleType type() const override;
|
virtual MaterialStyleType type() const override;
|
||||||
virtual std::vector<GLfloat> encoded() const override;
|
virtual std::vector<GLfloat> encoded() const override;
|
||||||
|
virtual std::unique_ptr<MaterialStyle> clone() const override;
|
||||||
virtual bool operator==(const MaterialStyle&) const override;
|
virtual bool operator==(const MaterialStyle&) const override;
|
||||||
float getHalfWidth() const;
|
float getHalfWidth() const;
|
||||||
//protected:
|
//protected:
|
||||||
|
|
Loading…
Reference in New Issue