diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2019-03-24 07:17:34 +0300 |
---|---|---|
committer | Rebecca Worledge <rebecca.worledge@theqtcompany.com> | 2019-03-31 03:13:22 +0000 |
commit | 8dec198137716db33e2070b24d318d219d916f59 (patch) | |
tree | ece9b042b33c2f6521c01fc53066867aad24cdd6 | |
parent | c265782b178eb6654706c1ecc89f100b6c6c8a39 (diff) |
Minor refactoring to optimize and simplify the code a little bit
Change-Id: Ic9604fbd1672b2df9dddda24b330759f6df7be60
Reviewed-by: Rebecca Worledge <rebecca.worledge@theqtcompany.com>
-rw-r--r-- | src/bodymovin/bmbase.cpp | 14 | ||||
-rw-r--r-- | src/bodymovin/bmbase_p.h | 4 | ||||
-rw-r--r-- | src/bodymovin/bmgroup.cpp | 4 | ||||
-rw-r--r-- | src/bodymovin/bmlayer.cpp | 8 | ||||
-rw-r--r-- | src/bodymovin/bmshapelayer.cpp | 2 | ||||
-rw-r--r-- | src/imports/rasterrenderer/batchrenderer.cpp | 25 |
6 files changed, 25 insertions, 32 deletions
diff --git a/src/bodymovin/bmbase.cpp b/src/bodymovin/bmbase.cpp index 3aa8ca8..5fb7ac2 100644 --- a/src/bodymovin/bmbase.cpp +++ b/src/bodymovin/bmbase.cpp @@ -49,7 +49,7 @@ BMBase::BMBase(const BMBase &other) for (BMBase *child : other.m_children) { BMBase *clone = child->clone(); clone->setParent(this); - addChild(clone); + appendChild(clone); } } @@ -93,12 +93,14 @@ void BMBase::setType(int type) m_type = type; } -void BMBase::addChild(BMBase *child, bool priority) +void BMBase::prependChild(BMBase *child) { - if (priority) - m_children.push_front(child); - else - m_children.push_back(child); + m_children.push_front(child); +} + +void BMBase::appendChild(BMBase *child) +{ + m_children.push_back(child); } QList<BMBase *> &BMBase::children() diff --git a/src/bodymovin/bmbase_p.h b/src/bodymovin/bmbase_p.h index efbd4c0..2e9f12c 100644 --- a/src/bodymovin/bmbase_p.h +++ b/src/bodymovin/bmbase_p.h @@ -76,7 +76,9 @@ public: BMBase *parent() const; void setParent(BMBase *parent); - void addChild(BMBase *child, bool priority = false); + + void prependChild(BMBase *child); + void appendChild(BMBase *child); QList<BMBase *>& children(); virtual BMBase *findChild(const QString &childName); diff --git a/src/bodymovin/bmgroup.cpp b/src/bodymovin/bmgroup.cpp index 126a181..2a9a133 100644 --- a/src/bodymovin/bmgroup.cpp +++ b/src/bodymovin/bmgroup.cpp @@ -68,9 +68,9 @@ void BMGroup::construct(const QJsonObject &definition) // Transform affects how group contents are drawn. // It must be traversed first when drawing if (shape->type() == BM_SHAPE_TRANS_IX) - addChild(shape, true); + prependChild(shape); else - addChild(shape); + appendChild(shape); } } } diff --git a/src/bodymovin/bmlayer.cpp b/src/bodymovin/bmlayer.cpp index 5cf781c..57a88ff 100644 --- a/src/bodymovin/bmlayer.cpp +++ b/src/bodymovin/bmlayer.cpp @@ -56,7 +56,7 @@ BMLayer::BMLayer(const BMLayer &other) if (other.m_effects) { m_effects = new BMBase; for (BMBase *effect : other.m_effects->children()) - m_effects->addChild(effect->clone()); + m_effects->appendChild(effect->clone()); } //m_transformAtFirstFrame = other.m_transformAtFirstFrame; } @@ -249,7 +249,7 @@ void BMLayer::parseEffects(const QJsonArray &definition, BMBase *effectRoot) { BMBase *slider = new BMBase; slider->parse(effect); - effectRoot->addChild(slider); + effectRoot->appendChild(slider); break; } case 5: @@ -257,7 +257,7 @@ void BMLayer::parseEffects(const QJsonArray &definition, BMBase *effectRoot) if (effect.value(QLatin1String("en")).toInt()) { BMBase *group = new BMBase; group->parse(effect); - effectRoot->addChild(group); + effectRoot->appendChild(group); parseEffects(effect.value(QLatin1String("ef")).toArray(), group); } break; @@ -266,7 +266,7 @@ void BMLayer::parseEffects(const QJsonArray &definition, BMBase *effectRoot) { BMFillEffect *fill = new BMFillEffect; fill->construct(effect); - effectRoot->addChild(fill); + effectRoot->appendChild(fill); break; } default: diff --git a/src/bodymovin/bmshapelayer.cpp b/src/bodymovin/bmshapelayer.cpp index 4d50fd2..a1aee1f 100644 --- a/src/bodymovin/bmshapelayer.cpp +++ b/src/bodymovin/bmshapelayer.cpp @@ -78,7 +78,7 @@ BMShapeLayer::BMShapeLayer(const QJsonObject &definition) itemIt--; BMShape *shape = BMShape::construct((*itemIt).toObject(), this); if (shape) - addChild(shape); + appendChild(shape); } if (m_maskProperties.length()) diff --git a/src/imports/rasterrenderer/batchrenderer.cpp b/src/imports/rasterrenderer/batchrenderer.cpp index ca7b00e..39745f3 100644 --- a/src/imports/rasterrenderer/batchrenderer.cpp +++ b/src/imports/rasterrenderer/batchrenderer.cpp @@ -269,24 +269,13 @@ int BatchRenderer::parse(BMBase* rootElement, QByteArray jsonSource) BMLayer *layer = BMLayer::construct(jsonLayer); if (layer) { layer->setParent(rootElement); - rootElement->addChild(layer); - } - } - - // Mask layers must be rendered before the layers they affect to - // although they appear before in layer hierarchy. For this reason - // move a mask after the affected layers, so it will be rendered first - QList<BMBase *> &layers = rootElement->children(); - int moveTo = -1; - for (int i = 0; i < layers.count(); i++) { - BMLayer *layer = static_cast<BMLayer*>(layers.at(i)); - if (layer->isClippedLayer()) - moveTo = i; - if (layer->isMaskLayer()) { - qCDebug(lcLottieQtBodymovinParser()) << "Move mask layer" - << layers.at(i)->name() - << "before" << layers.at(moveTo)->name(); - layers.move(i, moveTo); + // Mask layers must be rendered before the layers they affect to + // although they appear before in layer hierarchy. For this reason + // move a mask after the affected layers, so it will be rendered first + if (layer->isMaskLayer()) + rootElement->prependChild(layer); + else + rootElement->appendChild(layer); } } |