[style] 区分封闭与不封闭图元分别做初始化
parent
64e1c4a4e9
commit
64c4646783
|
@ -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<StrokeElementLayerStyle>(); }
|
||||
},
|
||||
for (const auto& style : commonStyles)
|
||||
{
|
||||
FillElementLayerStyle::displayName(),
|
||||
[] { return std::make_unique<FillElementLayerStyle>(); }
|
||||
} };
|
||||
unusedStyles.insert(style);
|
||||
}
|
||||
if (isClosedElement)
|
||||
{
|
||||
for (const auto& style : closedOnlyStyles)
|
||||
{
|
||||
unusedStyles.insert(style);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const auto& style : unclosedOnlyStyles)
|
||||
{
|
||||
unusedStyles.insert(style);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Renderer::BaseStyle> LayerStyleContainer::toBaseStyles() const
|
||||
|
|
|
@ -38,42 +38,6 @@ public:
|
|||
virtual std::unique_ptr<LayerStyle> clone() const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* LayerStyle的容器,在每次数据变更时需要手动调用computeNewHash()方法,否则哈希值不会更新
|
||||
*/
|
||||
class LayerStyleContainer : public Renderer::ElementStyle
|
||||
{
|
||||
using DisplayNameWithSupplier = std::map<QString, std::function<std::unique_ptr<LayerStyle>()>>;
|
||||
private:
|
||||
DisplayNameWithSupplier unusedStyles;
|
||||
DisplayNameWithSupplier usedStyles;
|
||||
std::map<QString, std::shared_ptr<LayerStyle>> styles;
|
||||
size_t hash;
|
||||
public:
|
||||
static LayerStyleContainer fromJson(const QJsonArray& jsonArray);
|
||||
|
||||
LayerStyleContainer();
|
||||
std::vector<Renderer::BaseStyle> toBaseStyles() const override;
|
||||
QJsonArray toJson() const;
|
||||
|
||||
bool empty() const;
|
||||
bool full() const;
|
||||
std::map<QString, std::shared_ptr<LayerStyle>>::iterator begin();
|
||||
std::map<QString, std::shared_ptr<LayerStyle>>::iterator end();
|
||||
|
||||
QStringList unusedStyleNames() const;
|
||||
std::unique_ptr<LayerStyle> makeUnusedStyle(const QString& styleName) const;
|
||||
bool useStyle(const std::shared_ptr<LayerStyle>& style);
|
||||
bool dropStyle(const QString& styleName);
|
||||
float boundingBoxAffectValue() const;
|
||||
size_t getHash() const;
|
||||
|
||||
/**
|
||||
* 需要在每次更改后手动调用
|
||||
*/
|
||||
void computeNewHash();
|
||||
};
|
||||
|
||||
class StrokeElementLayerStyle : public LayerStyle
|
||||
{
|
||||
using PMaterialStyleStroke = std::shared_ptr<MaterialStyleStroke>;
|
||||
|
@ -116,4 +80,51 @@ public:
|
|||
std::unique_ptr<LayerStyle> clone() const override;
|
||||
|
||||
PMaterialStyleFill fillMaterialStyle;
|
||||
};
|
||||
|
||||
/**
|
||||
* LayerStyle的容器,在每次数据变更时需要手动调用computeNewHash()方法,否则哈希值不会更新
|
||||
*/
|
||||
class LayerStyleContainer : public Renderer::ElementStyle
|
||||
{
|
||||
using DisplayNameWithSupplier = std::map<QString, std::function<std::unique_ptr<LayerStyle>()>>;
|
||||
private:
|
||||
|
||||
inline const static DisplayNameWithSupplier commonStyles = { {
|
||||
StrokeElementLayerStyle::displayName(),
|
||||
[] { return std::make_unique<StrokeElementLayerStyle>(); }
|
||||
} };
|
||||
inline const static DisplayNameWithSupplier closedOnlyStyles = { {
|
||||
FillElementLayerStyle::displayName(),
|
||||
[] { return std::make_unique<FillElementLayerStyle>(); }
|
||||
} };
|
||||
inline const static DisplayNameWithSupplier unclosedOnlyStyles = { };
|
||||
|
||||
DisplayNameWithSupplier unusedStyles;
|
||||
DisplayNameWithSupplier usedStyles;
|
||||
std::map<QString, std::shared_ptr<LayerStyle>> styles;
|
||||
size_t hash;
|
||||
public:
|
||||
static LayerStyleContainer fromJson(bool isClosedElement, const QJsonArray& jsonArray);
|
||||
|
||||
LayerStyleContainer(bool isClosedElement);
|
||||
std::vector<Renderer::BaseStyle> toBaseStyles() const override;
|
||||
QJsonArray toJson() const;
|
||||
|
||||
bool empty() const;
|
||||
bool full() const;
|
||||
std::map<QString, std::shared_ptr<LayerStyle>>::iterator begin();
|
||||
std::map<QString, std::shared_ptr<LayerStyle>>::iterator end();
|
||||
|
||||
QStringList unusedStyleNames() const;
|
||||
std::unique_ptr<LayerStyle> makeUnusedStyle(const QString& styleName) const;
|
||||
bool useStyle(const std::shared_ptr<LayerStyle>& style);
|
||||
bool dropStyle(const QString& styleName);
|
||||
float boundingBoxAffectValue() const;
|
||||
size_t getHash() const;
|
||||
|
||||
/**
|
||||
* 需要在每次更改后手动调用
|
||||
*/
|
||||
void computeNewHash();
|
||||
};
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue