From fa91d80b709d2ea1b4c908727bcf2f43a84334a8 Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Wed, 15 Mar 2023 16:36:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84Element=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/GraphicElement.cpp | 20 +++++++++++++++++-- .../src/Editor/GraphicElement.h | 5 ++++- 2 files changed, 22 insertions(+), 3 deletions(-) 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;