修改getReferencedBy为动态

TaoZhang-Branch
karlis 2023-03-11 18:33:56 +08:00
parent 4bfdb0d9f6
commit c92a3553ce
4 changed files with 41 additions and 5 deletions

View File

@ -45,4 +45,26 @@ QJsonObject ElementManager::toJson() const
QJsonObject result;
result.insert("elements", elementsJson);
return result;
}
int ElementManager::getElementIndex(GraphicElement* pelement)
{
for (int i = 0; i < elements.size(); i++)
if (elements[i] == pelement)
return i;
return -1;
}
int ElementManager::getLayerReferencedBy(const FolderLayerWrapper* layer)
{
for (int i = 0; i < elements.size(); i++)
if (typeid(*elements[i]) == typeid(GroupElement)) {
qDebug() << ((GroupElement*)elements[i])->sourceLayer;
qDebug() << layer;
qDebug() << "------------";
if (((GroupElement*)elements[i])->sourceLayer == layer)
return i;
}
return -1;
}

View File

@ -8,6 +8,7 @@ using std::vector;
class LayerManager;
class GraphicElement;
class Renderer::ElementRenderer;
class FolderLayerWrapper;
class ElementManager
{
@ -24,4 +25,6 @@ class ElementManager
* only used in initialization
*/
GraphicElement *getElementById(int index);
int getElementIndex(GraphicElement* pElement);
int getLayerReferencedBy(const FolderLayerWrapper* layer);
};

View File

@ -30,9 +30,10 @@ PixelPath LayerWrapper::getCache()
}
// TODO: undone
LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent)
LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager)
{
this->parent = parent;
this->elementManager = elementManager;
this->qTreeWidgetItem = new QTreeWidgetItem();
auto transformJson = json.value("transform").toObject();
property.name = json.value("name").toString();
@ -44,7 +45,7 @@ LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent)
}
FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent)
: LayerWrapper(json, parent)
: LayerWrapper(json, parent, elementManager)
{
qDebug() << json.value("name").toString() << " " << this;
QJsonArray childrenJson = json.value("children").toArray();
@ -205,8 +206,8 @@ QJsonObject FolderLayerWrapper::toJson() const
childrenJson.push_back(child->toJson());
json.insert("children", childrenJson);
json.insert("is-folder", true);
if(this->referencedBy != -1)
json.insert("referenced-by", this->referencedBy);
if(this->getReferencedBy() != -1)
json.insert("referenced-by", this->getReferencedBy());
else
json.insert("referenced-by", QJsonValue());
return json;
@ -218,4 +219,12 @@ QJsonObject LeafLayerWrapper::toJson() const
json.insert("element", wrappedElement->index);
json.insert("is-folder", false);
return json;
}
int FolderLayerWrapper::getReferencedBy()const
{
if (this->elementManager != nullptr)
return this->elementManager->getLayerReferencedBy(this);
else
return -1;
}

View File

@ -28,6 +28,7 @@ class LayerWrapper
protected:
FolderLayerWrapper* parent;
QPointF referencePoint;
ElementManager* elementManager;
// vector<LayerStyle> styles;
// TODO: 将cache移到子类对Leaf用ComposedPainterPath对Folder用FolderBitmapPath
PixelPath cache;
@ -51,7 +52,7 @@ class LayerWrapper
// TODO: 将QPainterPath改为BitmapPath/QImage或者直接将其删除绘制时直接使用BitmapPath的paint方法
virtual PixelPath getCache();
FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles
LayerWrapper(QJsonObject json, FolderLayerWrapper*parent);
LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager=nullptr);
LayerWrapper() = default;
// TODO : export Function
// virtual LayerWrapper *addChild() = 0; // Leaf Child Only
@ -84,6 +85,7 @@ class FolderLayerWrapper : public LayerWrapper
void delSelf() override;
QTreeWidgetItem* getQTreeItem() override;
QJsonObject toJson() const override;
int getReferencedBy()const;
};
class LeafLayerWrapper : public LayerWrapper