完善Element序列化

dev-LayerStyle
karlis 2023-03-15 16:36:46 +08:00
parent 3b87644e21
commit fa91d80b70
2 changed files with 22 additions and 3 deletions

View File

@ -23,6 +23,7 @@ void SimpleElement::loadSvgFile(const QString& filePath)
SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource)
{
painterPath.clear();
filePath = jsonSource["data"].toObject()["include"].toString();
//loadSvgFile("D:\\Projects\\BigC\\svg\\3.svg");
loadSvgFile("../"/*TODO: 改成json文件所在文件夹路径*/ + jsonSource.value("data").toObject().value("include").toString());
}
@ -95,10 +96,25 @@ PixelPath GroupElement::getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*
// }
//}
//TODO : 添加细节
QJsonObject GraphicElement::toJson() const
QJsonObject SimpleElement::toJson() const
{
QJsonObject result;
result.insert("name", name);
QJsonObject data;
data["include"] = filePath;
result["type"] = "svg-file";
result["data"] = data;
result["name"] = name;
return result;
}
QJsonObject GroupElement::toJson() const
{
QJsonObject result;
QJsonObject data;
data["reference-layer"] = "0.0";
result["type"] = "group";
result["data"] = data;
result["name"] = name;
return result;
}

View File

@ -25,7 +25,7 @@ public:
QString name = "";
int index;
// TODO: ¸ÄΪBitmapPath
virtual QJsonObject toJson() const;
virtual QJsonObject toJson() const = 0;
virtual PixelPath getPaintObject() const = 0;
virtual PixelPath getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*) const = 0;
virtual void paint(QPainter* painter, QTransform transform, const std::vector<std::shared_ptr<LayerStyle>> &styles) = 0;
@ -37,9 +37,11 @@ public:
QJsonObject jsonSource;
// TODO: ¸ÄΪComposedPainterPath
QPainterPath painterPath;
QString filePath;
void loadSvgFile(const QString& filePath);
public:
QJsonObject toJson() const override;
SimpleElement(QJsonObject jsonSource);
SimpleElement(QString filePath);
~SimpleElement() = default;
@ -54,6 +56,7 @@ public:
FolderLayerWrapper* sourceLayer;
public:
QJsonObject toJson() const override;
GroupElement() = default;
GroupElement(FolderLayerWrapper* mSourceLayer);
~GroupElement() = default;