添加了所有Layer的styles成员

dev-wuyize
karlis 2023-03-23 22:36:22 +08:00
parent a55a38385e
commit a3d39b32e5
6 changed files with 25 additions and 25 deletions

View File

@ -141,7 +141,7 @@ bool SimpleElement::isClosed() const
void GroupElement::paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles)
{
sourceLayer->paint(painter, transform, true);
sourceLayer->paint(painter, transform, true, styles);
}
bool GroupElement::isClosed() const

View File

@ -61,10 +61,10 @@ bool LayerManager::combine() const
for (auto &layer : selectedLayers)
if (layer->getParent() != prevCommonFather)
return false;
auto newCommonFather = new FolderLayerWrapper();
newCommonFather->setParent(static_cast<FolderLayerWrapper*>(prevCommonFather));
for (auto &layer : selectedLayers)
layer->setParent(newCommonFather);
//auto newCommonFather = new FolderLayerWrapper();
//newCommonFather->setParent(static_cast<FolderLayerWrapper*>(prevCommonFather));
//for (auto &layer : selectedLayers)
// layer->setParent(newCommonFather);
return true;
}
bool LayerManager::changeParent(FolderLayerWrapper *newParent) const

View File

@ -59,6 +59,7 @@ FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *element
qDebug() << json.value("name").toString() << " " << this;
QJsonArray childrenJson = json.value("children").toArray();
QJsonValue referencedJson = json.value("referenced-by");
styles = new LayerStyleContainer(LayerStyleContainer::TYPE_ALL);
if (!referencedJson.isNull())
{
auto p = reinterpret_cast<GroupElement *>(elementManager->getElementById(referencedJson.toInt()));
@ -79,11 +80,11 @@ FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *element
LeafLayerWrapper::LeafLayerWrapper(QJsonObject json, ElementManager* elementManager, FolderLayerWrapper* parent)
: LayerWrapper(json, parent, elementManager),
wrappedElement(elementManager->getElementById(json.value("element").toInt())),
styles(LayerStyleContainer::fromJson(
wrappedElement->isClosed() ? LayerStyleContainer::TYPE_CLOSED : LayerStyleContainer::TYPE_UNCLOSED,
json.value("styles").toArray()))
wrappedElement(elementManager->getElementById(json.value("element").toInt()))
{
styles = new LayerStyleContainer(LayerStyleContainer::fromJson(
wrappedElement->isClosed() ? LayerStyleContainer::TYPE_CLOSED : LayerStyleContainer::TYPE_UNCLOSED,
json.value("styles").toArray()));
qDebug() << json.value("name").toString() << " " << this;
if(wrappedElement != nullptr)
wrappedElement->referencedCount++;
@ -157,7 +158,7 @@ void LeafLayerWrapper::refresh(LayerWrapper* layer)
cache.clear();
if (wrappedElement != nullptr)
{
cache.addPath(wrappedElement->getPaintObject(this->styles));
cache.addPath(wrappedElement->getPaintObject(*this->styles));
}
LayerWrapper::refresh();
}
@ -291,7 +292,7 @@ QJsonObject LeafLayerWrapper::toJson() const
QJsonObject json = LayerWrapper::toJson();
json.insert("element", elementManager->getElementIndex(wrappedElement));
json.insert("is-folder", false);
json.insert("styles", styles.toJson());
json.insert("styles", styles->toJson());
return json;
}
@ -303,7 +304,7 @@ int FolderLayerWrapper::getReferencedBy()const
return -1;
}
void LayerWrapper::paint(QPainter* painter, QTransform transform, bool force)
void LayerWrapper::paint(QPainter* painter, QTransform transform, bool force, LayerStyleContainer styles)
{
// if (this->selected)
// {
@ -315,26 +316,24 @@ void LayerWrapper::paint(QPainter* painter, QTransform transform, bool force)
// }
}
void FolderLayerWrapper::paint(QPainter* painter, QTransform transform, bool force)
void FolderLayerWrapper::paint(QPainter* painter, QTransform transform, bool force, LayerStyleContainer styles)
{
if (hidden && !force)
return;
LayerWrapper::paint(painter, transform, force);
transform = property.transform * transform;
for (auto it = children.rbegin(); it != children.rend(); ++it)
(*it)->paint(painter, transform, force);
(*it)->paint(painter, transform, force, styles | *this->styles);
}
void LeafLayerWrapper::paint(QPainter* painter, QTransform transform, bool force)
void LeafLayerWrapper::paint(QPainter* painter, QTransform transform, bool force, LayerStyleContainer styles)
{
if (hidden && !force)
return;
LayerWrapper::paint(painter, transform, force);
transform = property.transform * transform;
//qDebug() << transform;
if (wrappedElement != nullptr)
{
wrappedElement->paint(painter, transform, styles);
wrappedElement->paint(painter, transform, styles | *this->styles);
}
}
@ -454,7 +453,8 @@ bool LeafLayerWrapper::referencingGroupElement() const
bool LayerWrapper::canApplyStyles() const
{
return typeid(*this) == typeid(LeafLayerWrapper) && !referencingGroupElement();
return true;
//return typeid(*this) == typeid(LeafLayerWrapper) && !referencingGroupElement();
}
void LayerWrapper::paintVisualBounding(QPainter* painter) const

View File

@ -39,6 +39,7 @@ class LayerWrapper
QTreeWidgetItem* qTreeWidgetItem;
bool selected;
bool hidden;
LayerStyleContainer* styles;
struct SimpleProperty
{
QString name = "";
@ -61,7 +62,7 @@ class LayerWrapper
FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles
LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager=nullptr);
LayerWrapper() = default;
virtual void paint(QPainter* painter, QTransform transform=QTransform(), bool force = false);
virtual void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false, LayerStyleContainer styles = LayerStyleContainer(LayerStyleContainer::TYPE_ALL));
// TODO : export Function
// virtual LayerWrapper *addChild() = 0; // Leaf Child Only
// virtual LayerWrapper *addParent() = 0; // Folder Parent Only
@ -102,7 +103,7 @@ class FolderLayerWrapper : public LayerWrapper
QTreeWidgetItem* getQTreeItem() override;
QJsonObject toJson() const override;
int getReferencedBy()const;
void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false) override;
void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false, LayerStyleContainer styles = LayerStyleContainer(LayerStyleContainer::TYPE_ALL)) override;
void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
void refreshTreeItem() override;
size_t referencedCount(bool excludeSelf = false) const override;
@ -114,14 +115,13 @@ class LeafLayerWrapper : public LayerWrapper
{
public:
GraphicElement *wrappedElement;
LayerStyleContainer styles;
public:
~LeafLayerWrapper();
void refresh(LayerWrapper* layer = nullptr) override;
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
QJsonObject toJson() const override;
void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false) override;
void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false, LayerStyleContainer styles = LayerStyleContainer(LayerStyleContainer::TYPE_ALL)) override;
void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
QTreeWidgetItem* getQTreeItem() override;
void refreshTreeItem() override;

View File

@ -102,7 +102,7 @@ void InfoDisplayWidget::refresh()
if (this->displayLayer->canApplyStyles())
{
ui.styleList->setDisabled(false);
ui.styleList->setStyleContainer(&static_cast<LeafLayerWrapper*>(this->displayLayer)->styles);
ui.styleList->setStyleContainer(static_cast<LayerWrapper*>(this->displayLayer)->styles);
}
else
{

View File

@ -113,7 +113,7 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo
QTransform transformInverted = leafTransform.inverted();
//++zIndexCount;
auto baseStyles = leafLayer->styles.toBaseStyles();
auto baseStyles = leafLayer->styles->toBaseStyles();
qDebug() << baseStyles.size();
for (auto& baseStyle : std::views::reverse(baseStyles)) {
double lineWidth = 0;