diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index 5610888..e198184 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -255,6 +255,9 @@ Source Files\Editor\Layer + + Source Files + @@ -308,6 +311,9 @@ Header Files\Editor\Layer + + Header Files + diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp index 7240d46..3351b34 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp @@ -90,9 +90,9 @@ void LayerStyleContainer::computeNewHash() } } -LayerStyleContainer LayerStyleContainer::fromJson(const QJsonArray& jsonArray) +LayerStyleContainer LayerStyleContainer::fromJson(bool isClosedElement, const QJsonArray& jsonArray) { - LayerStyleContainer container; + LayerStyleContainer container(isClosedElement); for (const auto& style : jsonArray) { container.useStyle(LayerStyle::fromJson(style.toObject())); @@ -100,16 +100,26 @@ LayerStyleContainer LayerStyleContainer::fromJson(const QJsonArray& jsonArray) return container; } -LayerStyleContainer::LayerStyleContainer() : hash(0) +LayerStyleContainer::LayerStyleContainer(bool isClosedElement) : hash(0) { - unusedStyles = { { - StrokeElementLayerStyle::displayName(), - [] { return std::make_unique(); } - }, + for (const auto& style : commonStyles) { - FillElementLayerStyle::displayName(), - [] { return std::make_unique(); } - } }; + unusedStyles.insert(style); + } + if (isClosedElement) + { + for (const auto& style : closedOnlyStyles) + { + unusedStyles.insert(style); + } + } + else + { + for (const auto& style : unclosedOnlyStyles) + { + unusedStyles.insert(style); + } + } } std::vector LayerStyleContainer::toBaseStyles() const diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.h b/ArchitectureColoredPainting/src/Editor/LayerStyle.h index 3d9b023..9274732 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.h +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.h @@ -38,42 +38,6 @@ public: virtual std::unique_ptr clone() const = 0; }; -/** - * LayerStyle的容器,在每次数据变更时需要手动调用computeNewHash()方法,否则哈希值不会更新 - */ -class LayerStyleContainer : public Renderer::ElementStyle -{ - using DisplayNameWithSupplier = std::map()>>; -private: - DisplayNameWithSupplier unusedStyles; - DisplayNameWithSupplier usedStyles; - std::map> styles; - size_t hash; -public: - static LayerStyleContainer fromJson(const QJsonArray& jsonArray); - - LayerStyleContainer(); - std::vector toBaseStyles() const override; - QJsonArray toJson() const; - - bool empty() const; - bool full() const; - std::map>::iterator begin(); - std::map>::iterator end(); - - QStringList unusedStyleNames() const; - std::unique_ptr makeUnusedStyle(const QString& styleName) const; - bool useStyle(const std::shared_ptr& style); - bool dropStyle(const QString& styleName); - float boundingBoxAffectValue() const; - size_t getHash() const; - - /** - * 需要在每次更改后手动调用 - */ - void computeNewHash(); -}; - class StrokeElementLayerStyle : public LayerStyle { using PMaterialStyleStroke = std::shared_ptr; @@ -116,4 +80,51 @@ public: std::unique_ptr clone() const override; PMaterialStyleFill fillMaterialStyle; +}; + +/** + * LayerStyle的容器,在每次数据变更时需要手动调用computeNewHash()方法,否则哈希值不会更新 + */ +class LayerStyleContainer : public Renderer::ElementStyle +{ + using DisplayNameWithSupplier = std::map()>>; +private: + + inline const static DisplayNameWithSupplier commonStyles = { { + StrokeElementLayerStyle::displayName(), + [] { return std::make_unique(); } + } }; + inline const static DisplayNameWithSupplier closedOnlyStyles = { { + FillElementLayerStyle::displayName(), + [] { return std::make_unique(); } + } }; + inline const static DisplayNameWithSupplier unclosedOnlyStyles = { }; + + DisplayNameWithSupplier unusedStyles; + DisplayNameWithSupplier usedStyles; + std::map> styles; + size_t hash; +public: + static LayerStyleContainer fromJson(bool isClosedElement, const QJsonArray& jsonArray); + + LayerStyleContainer(bool isClosedElement); + std::vector toBaseStyles() const override; + QJsonArray toJson() const; + + bool empty() const; + bool full() const; + std::map>::iterator begin(); + std::map>::iterator end(); + + QStringList unusedStyleNames() const; + std::unique_ptr makeUnusedStyle(const QString& styleName) const; + bool useStyle(const std::shared_ptr& style); + bool dropStyle(const QString& styleName); + float boundingBoxAffectValue() const; + size_t getHash() const; + + /** + * 需要在每次更改后手动调用 + */ + void computeNewHash(); }; \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index e83ae7e..f131f27 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -73,14 +73,12 @@ FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *element } } -LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent) - : LayerWrapper(json, parent) +LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager* elementManager, FolderLayerWrapper* parent) + : LayerWrapper(json, parent), + wrappedElement(elementManager->getElementById(json.value("element").toInt())), + styles(LayerStyleContainer::fromJson(wrappedElement->isClosed(), json.value("styles").toArray())) { qDebug() << json.value("name").toString() << " " << this; - int elementIndex = json.value("element").toInt(); - wrappedElement = elementManager->getElementById(elementIndex); - QJsonArray stylesArray = json.value("styles").toArray(); - styles = LayerStyleContainer::fromJson(stylesArray); } void LayerWrapper::SimpleProperty::apply(PixelPath&cache) diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index b767d35..3b82b86 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -107,7 +107,6 @@ class LeafLayerWrapper : public LayerWrapper public: ~LeafLayerWrapper() = default; void refresh(LayerWrapper* layer = nullptr) override; - LeafLayerWrapper() = default; LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent); QJsonObject toJson() const override; void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override;