diff options
author | Christian Strømme <christian.stromme@qt.io> | 2018-05-31 13:20:10 +0200 |
---|---|---|
committer | Andy Nichols <andy.nichols@qt.io> | 2018-06-01 13:46:05 +0000 |
commit | 54abd625c36789b7e06ddc99709f805e17749754 (patch) | |
tree | 625fbe3eb0adf3913b62243efa5e585e7de38e50 | |
parent | d323e812d8a8da46d55af80dceec6e8ff77c93ce (diff) |
Add property changes for implicitly set start and end times
We were not generating property changes implicit start and end times on
slide or components slides. This change adds a post-processing function
in the parser to generate those.
Change-Id: Ifa0592e159d4d33c13923f7b3806540bd5bb3be6
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r-- | src/runtime/q3dsuipparser.cpp | 1 | ||||
-rw-r--r-- | src/runtime/q3dsuippresentation.cpp | 67 | ||||
-rw-r--r-- | src/runtime/q3dsuippresentation_p.h | 1 |
3 files changed, 69 insertions, 0 deletions
diff --git a/src/runtime/q3dsuipparser.cpp b/src/runtime/q3dsuipparser.cpp index 2b3eff7..9671962 100644 --- a/src/runtime/q3dsuipparser.cpp +++ b/src/runtime/q3dsuipparser.cpp @@ -129,6 +129,7 @@ Q3DSUipPresentation *Q3DSUipParser::createPresentation(const QString &presentati m_presentation->resolveAliases(); m_presentation->updateObjectStateForSubTrees(); + m_presentation->addImplicitPropertyChanges(); qint64 loadTime = elapsedSinceSetSource(); qCDebug(lcPerf, "Presentation %s loaded in %lld ms", qPrintable(m_presentation->sourceFile()), loadTime); diff --git a/src/runtime/q3dsuippresentation.cpp b/src/runtime/q3dsuippresentation.cpp index 40392e0..f6ee5f2 100644 --- a/src/runtime/q3dsuippresentation.cpp +++ b/src/runtime/q3dsuippresentation.cpp @@ -3894,6 +3894,73 @@ void Q3DSUipPresentation::updateObjectStateForSubTrees() }); } +void Q3DSUipPresentation::addImplicitPropertyChanges() +{ + // TODO: There might be other cases where we need to generate the property changes, + // this only deals with the start and end times for now. + forAllObjectsInSubTree(scene(), [](Q3DSGraphObject *obj) { + if ((obj->type() == Q3DSGraphObject::Slide && !obj->parent()) || obj->type() == Q3DSGraphObject::Component) { + const bool isComponent = (obj->type() == Q3DSGraphObject::Component); + Q3DSSlide *master = isComponent ? static_cast<Q3DSComponentNode *>(obj)->masterSlide() : static_cast<Q3DSSlide *>(obj); + Q3DSSlide *slide = static_cast<Q3DSSlide *>(master->firstChild()); + while (slide) { + for (auto o : master->objects()) { + if (!o->isNode()) + continue; + + auto propChanges = slide->propertyChanges(); + const auto foundIt = propChanges.constFind(o); + + struct StartAndEndTime { + qint32 hasStart = false; + qint32 hasEnd = false; + const qint32 defaultStart = 0; + const qint32 defaultEnd = 10000; + } startAndEndTime; + + if (foundIt != propChanges.cend()) { + std::find_if(foundIt.value()->cbegin(), foundIt.value()->cend(), [&startAndEndTime](const Q3DSPropertyChange &change) { + if (startAndEndTime.hasStart && startAndEndTime.hasEnd) + return true; + + if (change.name() == QLatin1String("starttime")) + startAndEndTime.hasStart = true; + else if (change.name() == QLatin1String("endtime")) + startAndEndTime.hasEnd = true; + + return false; + }); + } + + // No prop change for object, then add default values 0s and 10s + if (!startAndEndTime.hasStart) { + const auto propChange = Q3DSPropertyChange::fromVariant(QLatin1String("starttime"), QVariant::fromValue(startAndEndTime.defaultStart)); + if (foundIt != propChanges.constEnd()) { + auto propChangeList = slide->takePropertyChanges(o); + propChangeList->append(propChange); + slide->addPropertyChanges(o, propChangeList); + } else { + slide->addPropertyChanges(o, new Q3DSPropertyChangeList({propChange})); + } + } + + if (!startAndEndTime.hasEnd) { + const auto propChange = Q3DSPropertyChange::fromVariant(QLatin1String("endtime"), QVariant::fromValue(startAndEndTime.defaultEnd)); + if (foundIt != propChanges.constEnd()) { + auto propChangeList = slide->takePropertyChanges(o); + propChangeList->append(propChange); + slide->addPropertyChanges(o, propChangeList); + } else { + slide->addPropertyChanges(o, new Q3DSPropertyChangeList({propChange})); + } + } + } + slide = static_cast<Q3DSSlide *>(slide->nextSibling()); + } + } + }); +} + QHash<QString, bool> &Q3DSUipPresentation::imageTransparencyHash() { return m_imageTransparencyHash; diff --git a/src/runtime/q3dsuippresentation_p.h b/src/runtime/q3dsuippresentation_p.h index 2b1ea62..8ed44f7 100644 --- a/src/runtime/q3dsuippresentation_p.h +++ b/src/runtime/q3dsuippresentation_p.h @@ -2040,6 +2040,7 @@ public: } void resolveAliases(); void updateObjectStateForSubTrees(); + void addImplicitPropertyChanges(); QHash<QString, bool> &imageTransparencyHash(); private: |