[style] 初步完成LayerStyle序列化

dev-LayerStyle
ArgonarioD 2023-03-16 01:56:05 +08:00
parent 8809daaddd
commit 257868fd4c
6 changed files with 36 additions and 0 deletions

View File

@ -197,6 +197,7 @@
<QtMoc Include="src\Editor\EditorWidgetComponent\LayerCreateWidget.h" />
<QtMoc Include="src\Editor\EditorWidgetComponent\LayerStyleDialog.h" />
<QtMoc Include="src\Editor\EditorWidgetComponent\ColorPicker.h" />
<ClInclude Include="src\Editor\util\JsonUtil.hpp" />
<ClInclude Include="src\Editor\ElementManager.h" />
<QtMoc Include="src\Editor\ElementPoolWidget.h" />
<ClInclude Include="src\Editor\GraphicElement.h" />

View File

@ -477,6 +477,9 @@
<ClInclude Include="src\Editor\LayerStyle.h">
<Filter>Header Files\Editor\Style</Filter>
</ClInclude>
<ClInclude Include="src\Editor\util\JsonUtil.hpp">
<Filter>Header Files\Editor\util</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<QtRcc Include="res\MainWindow.qrc">

View File

@ -1,5 +1,6 @@
#include "LayerStyle.h"
#include "./EditorWidgetComponent/StrokeStyleWidget.h"
#include "./util/JsonUtil.hpp"
#include <qtmaterialcheckbox.h>
#include <QHBoxLayout>
#include <QDialogButtonBox>
@ -118,6 +119,16 @@ StrokeElementLayerStyle::StrokeElementLayerStyle(const StrokeElementLayerStyle&
enableEachSideIndependent = other.enableEachSideIndependent;
}
QJsonObject StrokeElementLayerStyle::toJson() const
{
QJsonObject json;
json.insert("type", "stroke");
json.insert("enableEachSideIndependent", enableEachSideIndependent);
json.insert("left", JsonUtil::toQJsonArray<GLfloat>(strokePair.first->encoded()));
json.insert("right", JsonUtil::toQJsonArray<GLfloat>(strokePair.second->encoded()));
return json;
}
std::unique_ptr<LayerStyle> StrokeElementLayerStyle::clone() const
{
return std::make_unique<StrokeElementLayerStyle>(StrokeElementLayerStyle(*this));
@ -161,7 +172,17 @@ FillElementLayerStyle::FillElementLayerStyle(const FillElementLayerStyle& other)
}
}
QJsonObject FillElementLayerStyle::toJson() const
{
return QJsonObject();
}
std::unique_ptr<LayerStyle> FillElementLayerStyle::clone() const
{
return std::make_unique<FillElementLayerStyle>(FillElementLayerStyle(*this));
}
std::unique_ptr<LayerStyle> LayerStyle::fromJson(const QJsonObject& json)
{
return std::unique_ptr<LayerStyle>();
}

View File

@ -5,6 +5,7 @@
#include <QWidget>
#include <QObject>
#include <QListWidget>
#include <QJsonObject>
#include "../Renderer/Painting/ElementStyle.h"
#include "../Renderer/Painting/MaterialStyleStroke.h"
#include "../Renderer/Painting/MaterialStyleFill.h"
@ -23,10 +24,13 @@ class LayerStyle : public Renderer::ElementStyle
{
public:
const static std::vector<std::pair<QString, std::function<std::unique_ptr<LayerStyle>()>>> types;
static std::unique_ptr<LayerStyle> fromJson(const QJsonObject& json);
virtual QString getStyleName() const = 0;
virtual QWidget* getInputWidget() = 0;
virtual QWidget* getListDisplayWidget() const = 0;
virtual ~LayerStyle() {};
virtual QJsonObject toJson() const = 0;
virtual std::unique_ptr<LayerStyle> clone() const = 0;
};
@ -43,6 +47,7 @@ public:
StrokeElementLayerStyle() = default;
StrokeElementLayerStyle(const StrokeElementLayerStyle& other);
~StrokeElementLayerStyle() = default;
QJsonObject toJson() const override;
std::unique_ptr<LayerStyle> clone() const override;
bool enableEachSideIndependent = false;
@ -59,5 +64,6 @@ public:
FillElementLayerStyle(const FillElementLayerStyle& other);
~FillElementLayerStyle() = default;
std::vector<std::shared_ptr<Renderer::MaterialStyleFill>> materialStyles;
QJsonObject toJson() const override;
std::unique_ptr<LayerStyle> clone() const override;
};

View File

@ -240,6 +240,10 @@ QJsonObject LeafLayerWrapper::toJson() const
QJsonObject json = LayerWrapper::toJson();
json.insert("element", wrappedElement->index);
json.insert("is-folder", false);
QJsonArray stylesJson;
for (auto& style : styles)
stylesJson.push_back(style->toJson());
json.insert("styles", stylesJson);
return json;
}

View File

@ -6,6 +6,7 @@
#include <QGraphicsItemGroup>
#include <QGraphicsScene>
#include <QJSonObject>
#include <QJsonArray>
#include <QLine>
#include <QObject>
#include <QPoint>