Orderly destruction of canvas elements
Driven from the object destroyed signal, ensure children and corresponding QQ items are also destroyed when the property is removed.
This commit is contained in:
parent
e4b5a699d8
commit
8e6500ae47
10 changed files with 62 additions and 0 deletions
|
@ -89,6 +89,7 @@ FGCanvasElement::FGCanvasElement(FGCanvasGroup* pr, LocalProp* prop) :
|
|||
this, &FGCanvasElement::onVisibleChanged);
|
||||
connect(prop, &LocalProp::childAdded, this, &FGCanvasElement::onChildAdded);
|
||||
connect(prop, &LocalProp::childRemoved, this, &FGCanvasElement::onChildRemoved);
|
||||
connect(prop, &LocalProp::destroyed, this, &FGCanvasElement::onPropDestroyed);
|
||||
|
||||
if (pr) {
|
||||
pr->markChildZIndicesDirty();
|
||||
|
@ -97,6 +98,12 @@ FGCanvasElement::FGCanvasElement(FGCanvasGroup* pr, LocalProp* prop) :
|
|||
requestPolish();
|
||||
}
|
||||
|
||||
void FGCanvasElement::onPropDestroyed()
|
||||
{
|
||||
doDestroy();
|
||||
const_cast<FGCanvasGroup*>(_parent)->removeChild(this);
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
void FGCanvasElement::requestPolish()
|
||||
{
|
||||
|
@ -304,6 +311,10 @@ bool FGCanvasElement::onChildRemoved(LocalProp *prop)
|
|||
return false;
|
||||
}
|
||||
|
||||
void FGCanvasElement::doDestroy()
|
||||
{
|
||||
}
|
||||
|
||||
QColor FGCanvasElement::fillColor() const
|
||||
{
|
||||
return _fillColor;
|
||||
|
|
|
@ -73,6 +73,8 @@ protected:
|
|||
virtual bool onChildAdded(LocalProp* prop);
|
||||
virtual bool onChildRemoved(LocalProp* prop);
|
||||
|
||||
virtual void doDestroy();
|
||||
|
||||
const LocalProp* _propertyRoot;
|
||||
const FGCanvasGroup* _parent;
|
||||
|
||||
|
@ -83,6 +85,10 @@ protected:
|
|||
virtual void markStyleDirty();
|
||||
|
||||
QVariant getCascadedStyle(const char* name, QVariant defaultValue = QVariant()) const;
|
||||
|
||||
private slots:
|
||||
void onPropDestroyed();
|
||||
|
||||
private:
|
||||
|
||||
void onCenterChanged(QVariant value);
|
||||
|
|
|
@ -190,6 +190,16 @@ bool FGCanvasGroup::onChildRemoved(LocalProp *prop)
|
|||
return false;
|
||||
}
|
||||
|
||||
void FGCanvasGroup::removeChild(FGCanvasElement *child)
|
||||
{
|
||||
auto it = std::find(_children.begin(), _children.end(), child);
|
||||
if (it != _children.end()) {
|
||||
int index = std::distance(_children.begin(), it);
|
||||
_children.erase(it);
|
||||
emit childRemoved(index);
|
||||
}
|
||||
}
|
||||
|
||||
int FGCanvasGroup::indexOfChildWithProp(LocalProp* prop) const
|
||||
{
|
||||
auto it = std::find_if(_children.begin(), _children.end(), [prop](FGCanvasElement* child)
|
||||
|
@ -211,6 +221,17 @@ void FGCanvasGroup::markStyleDirty()
|
|||
}
|
||||
}
|
||||
|
||||
void FGCanvasGroup::doDestroy()
|
||||
{
|
||||
delete _quick;
|
||||
|
||||
FGCanvasElementVec children = std::move(_children);
|
||||
_children.clear();
|
||||
for (auto c : children) {
|
||||
delete c;
|
||||
}
|
||||
}
|
||||
|
||||
void FGCanvasGroup::markCachedSymbolDirty()
|
||||
{
|
||||
_cachedSymbolDirty = true;
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
CanvasItem* quickItem() const override
|
||||
{ return _quick; }
|
||||
|
||||
void removeChild(FGCanvasElement* child);
|
||||
signals:
|
||||
void childAdded();
|
||||
void childRemoved(int index);
|
||||
|
@ -39,6 +40,8 @@ protected:
|
|||
bool onChildRemoved(LocalProp *prop) override;
|
||||
|
||||
virtual void markStyleDirty() override;
|
||||
|
||||
void doDestroy() override;
|
||||
private:
|
||||
void markCachedSymbolDirty();
|
||||
int indexOfChildWithProp(LocalProp *prop) const;
|
||||
|
|
|
@ -466,6 +466,11 @@ CanvasItem *FGCanvasPath::quickItem() const
|
|||
return _quickPath;
|
||||
}
|
||||
|
||||
void FGCanvasPath::doDestroy()
|
||||
{
|
||||
delete _quickPath;
|
||||
}
|
||||
|
||||
void FGCanvasPath::markPathDirty()
|
||||
{
|
||||
_pathDirty = true;
|
||||
|
|
|
@ -40,6 +40,8 @@ protected:
|
|||
CanvasItem* createQuickItem(QQuickItem *parent) override;
|
||||
CanvasItem* quickItem() const override;
|
||||
|
||||
void doDestroy() override;
|
||||
|
||||
private:
|
||||
void markPathDirty();
|
||||
void markStrokeDirty();
|
||||
|
|
|
@ -252,6 +252,12 @@ void FGCanvasText::markStyleDirty()
|
|||
markFontDirty();
|
||||
}
|
||||
|
||||
void FGCanvasText::doDestroy()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
delete _quickItem;
|
||||
}
|
||||
|
||||
bool FGCanvasText::onChildAdded(LocalProp *prop)
|
||||
{
|
||||
if (FGCanvasElement::onChildAdded(prop)) {
|
||||
|
|
|
@ -38,6 +38,9 @@ protected:
|
|||
void doPolish() override;
|
||||
|
||||
virtual void markStyleDirty() override;
|
||||
|
||||
void doDestroy() override;
|
||||
|
||||
private:
|
||||
bool onChildAdded(LocalProp *prop) override;
|
||||
|
||||
|
|
|
@ -242,6 +242,10 @@ void FGQCanvasImage::markStyleDirty()
|
|||
{
|
||||
}
|
||||
|
||||
void FGQCanvasImage::doDestroy()
|
||||
{
|
||||
delete _quickItem;
|
||||
}
|
||||
|
||||
CanvasItem *FGQCanvasImage::createQuickItem(QQuickItem *parent)
|
||||
{
|
||||
|
|
|
@ -38,6 +38,7 @@ protected:
|
|||
|
||||
virtual void markStyleDirty() override;
|
||||
|
||||
void doDestroy() override;
|
||||
|
||||
void doPolish() override;
|
||||
private slots:
|
||||
|
|
Loading…
Add table
Reference in a new issue