diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2019-03-24 07:11:39 +0300 |
---|---|---|
committer | Rebecca Worledge <rebecca.worledge@theqtcompany.com> | 2019-04-06 03:58:07 +0000 |
commit | 3492ab012e3b9a135226b46b293883de1253f111 (patch) | |
tree | 664a389d4b5a781b1138cd8701d28ce65bae2932 | |
parent | 8dec198137716db33e2070b24d318d219d916f59 (diff) |
BMBase: protect parent & children properties from being accessed directly
either change children() constness to explicitly mention that.
parent()/setParent() and children() must be used instead
for the sake of consistency and reliability
Change-Id: Ibd19de7853be5f4b6291dfdf753042d646b50488
Reviewed-by: Rebecca Worledge <rebecca.worledge@theqtcompany.com>
-rw-r--r-- | src/bodymovin/bmbase.cpp | 10 | ||||
-rw-r--r-- | src/bodymovin/bmbase_p.h | 10 | ||||
-rw-r--r-- | src/bodymovin/bmgroup.cpp | 6 | ||||
-rw-r--r-- | src/bodymovin/bmshapelayer.cpp | 4 |
4 files changed, 11 insertions, 19 deletions
diff --git a/src/bodymovin/bmbase.cpp b/src/bodymovin/bmbase.cpp index 5fb7ac2..c86e38a 100644 --- a/src/bodymovin/bmbase.cpp +++ b/src/bodymovin/bmbase.cpp @@ -103,11 +103,6 @@ void BMBase::appendChild(BMBase *child) m_children.push_back(child); } -QList<BMBase *> &BMBase::children() -{ - return m_children; -} - BMBase *BMBase::findChild(const QString &childName) { if (name() == childName) @@ -194,11 +189,6 @@ bool BMBase::hidden() const return m_hidden; } -BMBase *BMBase::parent() const -{ - return m_parent; -} - void BMBase::setParent(BMBase *parent) { m_parent = parent; diff --git a/src/bodymovin/bmbase_p.h b/src/bodymovin/bmbase_p.h index 2e9f12c..90818dc 100644 --- a/src/bodymovin/bmbase_p.h +++ b/src/bodymovin/bmbase_p.h @@ -74,12 +74,13 @@ public: virtual bool active(int frame) const; bool hidden() const; - BMBase *parent() const; + inline BMBase *parent() const { return m_parent; } void setParent(BMBase *parent); + const QList<BMBase *> &children() const { return m_children; } void prependChild(BMBase *child); void appendChild(BMBase *child); - QList<BMBase *>& children(); + virtual BMBase *findChild(const QString &childName); virtual void updateProperties(int frame); @@ -97,13 +98,14 @@ protected: QString m_name; QString m_matchName; bool m_autoOrient = false; - BMBase *m_parent = nullptr; - QList<BMBase *> m_children; friend class BMRasterRenderer; friend class BMRenderer; private: + BMBase *m_parent = nullptr; + QList<BMBase *> m_children; + // Handle to the topmost element on which this element resides // Will be resolved when traversing effects BMBase *m_topRoot = nullptr; diff --git a/src/bodymovin/bmgroup.cpp b/src/bodymovin/bmgroup.cpp index 2a9a133..ed13f8c 100644 --- a/src/bodymovin/bmgroup.cpp +++ b/src/bodymovin/bmgroup.cpp @@ -79,7 +79,7 @@ void BMGroup::updateProperties(int frame) { BMShape::updateProperties(frame); - for (BMBase *child : qAsConst(m_children)) { + for (BMBase *child : children()) { if (child->hidden()) continue; @@ -109,7 +109,7 @@ void BMGroup::render(LottieRenderer &renderer) const } else renderer.setTrimmingState(LottieRenderer::Off); - for (BMBase *child : qAsConst(m_children)) { + for (BMBase *child : children()) { if (child->hidden()) continue; child->render(renderer); @@ -135,7 +135,7 @@ void BMGroup::applyTrim(const BMTrimPath &trimmer) // Setting a friendly name helps in testing m_appliedTrim->setName(QStringLiteral("Inherited from") + trimmer.name()); - for (BMBase *child : qAsConst(m_children)) { + for (BMBase *child : children()) { BMShape *shape = static_cast<BMShape*>(child); if (shape->acceptsTrim()) shape->applyTrim(*m_appliedTrim); diff --git a/src/bodymovin/bmshapelayer.cpp b/src/bodymovin/bmshapelayer.cpp index a1aee1f..164f100 100644 --- a/src/bodymovin/bmshapelayer.cpp +++ b/src/bodymovin/bmshapelayer.cpp @@ -104,7 +104,7 @@ void BMShapeLayer::updateProperties(int frame) m_layerTransform->updateProperties(frame); - for (BMBase *child : qAsConst(m_children)) { + for (BMBase *child : children()) { if (child->hidden()) continue; @@ -141,7 +141,7 @@ void BMShapeLayer::render(LottieRenderer &renderer) const m_layerTransform->render(renderer); - for (BMBase *child :qAsConst(m_children)) { + for (BMBase *child : children()) { if (child->hidden()) continue; child->render(renderer); |