diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index 6be59ff..02af86d 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -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>* // } //} //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; } diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.h b/ArchitectureColoredPainting/src/Editor/GraphicElement.h index 6e63e92..f375c63 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.h +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.h @@ -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>*) const = 0; virtual void paint(QPainter* painter, QTransform transform, const std::vector> &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;