修改getReferencedBy为动态
parent
4bfdb0d9f6
commit
c92a3553ce
|
@ -46,3 +46,25 @@ QJsonObject ElementManager::toJson() const
|
||||||
result.insert("elements", elementsJson);
|
result.insert("elements", elementsJson);
|
||||||
return result;
|
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;
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ using std::vector;
|
||||||
class LayerManager;
|
class LayerManager;
|
||||||
class GraphicElement;
|
class GraphicElement;
|
||||||
class Renderer::ElementRenderer;
|
class Renderer::ElementRenderer;
|
||||||
|
class FolderLayerWrapper;
|
||||||
|
|
||||||
class ElementManager
|
class ElementManager
|
||||||
{
|
{
|
||||||
|
@ -24,4 +25,6 @@ class ElementManager
|
||||||
* only used in initialization
|
* only used in initialization
|
||||||
*/
|
*/
|
||||||
GraphicElement *getElementById(int index);
|
GraphicElement *getElementById(int index);
|
||||||
|
int getElementIndex(GraphicElement* pElement);
|
||||||
|
int getLayerReferencedBy(const FolderLayerWrapper* layer);
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,9 +30,10 @@ PixelPath LayerWrapper::getCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: undone
|
// TODO: undone
|
||||||
LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent)
|
LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager)
|
||||||
{
|
{
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
|
this->elementManager = elementManager;
|
||||||
this->qTreeWidgetItem = new QTreeWidgetItem();
|
this->qTreeWidgetItem = new QTreeWidgetItem();
|
||||||
auto transformJson = json.value("transform").toObject();
|
auto transformJson = json.value("transform").toObject();
|
||||||
property.name = json.value("name").toString();
|
property.name = json.value("name").toString();
|
||||||
|
@ -44,7 +45,7 @@ LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent)
|
FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent)
|
||||||
: LayerWrapper(json, parent)
|
: LayerWrapper(json, parent, elementManager)
|
||||||
{
|
{
|
||||||
qDebug() << json.value("name").toString() << " " << this;
|
qDebug() << json.value("name").toString() << " " << this;
|
||||||
QJsonArray childrenJson = json.value("children").toArray();
|
QJsonArray childrenJson = json.value("children").toArray();
|
||||||
|
@ -205,8 +206,8 @@ QJsonObject FolderLayerWrapper::toJson() const
|
||||||
childrenJson.push_back(child->toJson());
|
childrenJson.push_back(child->toJson());
|
||||||
json.insert("children", childrenJson);
|
json.insert("children", childrenJson);
|
||||||
json.insert("is-folder", true);
|
json.insert("is-folder", true);
|
||||||
if(this->referencedBy != -1)
|
if(this->getReferencedBy() != -1)
|
||||||
json.insert("referenced-by", this->referencedBy);
|
json.insert("referenced-by", this->getReferencedBy());
|
||||||
else
|
else
|
||||||
json.insert("referenced-by", QJsonValue());
|
json.insert("referenced-by", QJsonValue());
|
||||||
return json;
|
return json;
|
||||||
|
@ -219,3 +220,11 @@ QJsonObject LeafLayerWrapper::toJson() const
|
||||||
json.insert("is-folder", false);
|
json.insert("is-folder", false);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FolderLayerWrapper::getReferencedBy()const
|
||||||
|
{
|
||||||
|
if (this->elementManager != nullptr)
|
||||||
|
return this->elementManager->getLayerReferencedBy(this);
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ class LayerWrapper
|
||||||
protected:
|
protected:
|
||||||
FolderLayerWrapper* parent;
|
FolderLayerWrapper* parent;
|
||||||
QPointF referencePoint;
|
QPointF referencePoint;
|
||||||
|
ElementManager* elementManager;
|
||||||
// vector<LayerStyle> styles;
|
// vector<LayerStyle> styles;
|
||||||
// TODO: 将cache移到子类,对Leaf用ComposedPainterPath,对Folder用FolderBitmapPath
|
// TODO: 将cache移到子类,对Leaf用ComposedPainterPath,对Folder用FolderBitmapPath
|
||||||
PixelPath cache;
|
PixelPath cache;
|
||||||
|
@ -51,7 +52,7 @@ class LayerWrapper
|
||||||
// TODO: 将QPainterPath改为BitmapPath/QImage,或者直接将其删除,绘制时直接使用BitmapPath的paint方法
|
// TODO: 将QPainterPath改为BitmapPath/QImage,或者直接将其删除,绘制时直接使用BitmapPath的paint方法
|
||||||
virtual PixelPath getCache();
|
virtual PixelPath getCache();
|
||||||
FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles
|
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;
|
LayerWrapper() = default;
|
||||||
// TODO : export Function
|
// TODO : export Function
|
||||||
// virtual LayerWrapper *addChild() = 0; // Leaf Child Only
|
// virtual LayerWrapper *addChild() = 0; // Leaf Child Only
|
||||||
|
@ -84,6 +85,7 @@ class FolderLayerWrapper : public LayerWrapper
|
||||||
void delSelf() override;
|
void delSelf() override;
|
||||||
QTreeWidgetItem* getQTreeItem() override;
|
QTreeWidgetItem* getQTreeItem() override;
|
||||||
QJsonObject toJson() const override;
|
QJsonObject toJson() const override;
|
||||||
|
int getReferencedBy()const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LeafLayerWrapper : public LayerWrapper
|
class LeafLayerWrapper : public LayerWrapper
|
||||||
|
|
Loading…
Reference in New Issue