QmlDesigner: Add some functions to QmlTimelineKeyframeGroup

Also adding some QTC_ASSERTS.

Change-Id: I7dcdac517e850b9b0c7ec9ba7a76effc31766ad9
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2018-11-02 14:34:35 +01:00
parent 406cb164f9
commit c95b21ca17
2 changed files with 52 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ namespace QmlDesigner {
class AbstractViewAbstractVieweGroup;
class QmlObjectNode;
class QmlTimeline;
class QMLDESIGNERCORE_EXPORT QmlTimelineKeyframeGroup : public QmlModelNodeFacade
{
@@ -75,6 +76,11 @@ public:
int indexOfKeyframe(const ModelNode &frame) const;
void slideKeyframe(int sourceIndex, int targetIndex);
bool isRecording() const;
void toogleRecording(bool b) const;
QmlTimeline timeline() const;
};
} //QmlDesigner

View File

@@ -72,17 +72,23 @@ ModelNode QmlTimelineKeyframeGroup::target() const
void QmlTimelineKeyframeGroup::setTarget(const ModelNode &target)
{
QTC_ASSERT(isValid(), return);
modelNode().bindingProperty("target").setExpression(target.id());
}
PropertyName QmlTimelineKeyframeGroup::propertyName() const
{
QTC_ASSERT(isValid(), return {});
return modelNode().variantProperty("property").value().toString().toUtf8();
}
void QmlTimelineKeyframeGroup::setPropertyName(const PropertyName &propertyName)
{
QTC_ASSERT(isValid(), return);
modelNode().variantProperty("property").setValue(QString::fromUtf8(propertyName));
}
@@ -106,6 +112,8 @@ int QmlTimelineKeyframeGroup::getSupposedTargetIndex(qreal newFrame) const
int QmlTimelineKeyframeGroup::indexOfKeyframe(const ModelNode &frame) const
{
QTC_ASSERT(isValid(), return -1);
return modelNode().defaultNodeListProperty().indexOf(frame);
}
@@ -117,8 +125,38 @@ void QmlTimelineKeyframeGroup::slideKeyframe(int /*sourceIndex*/, int /*targetIn
*/
}
bool QmlTimelineKeyframeGroup::isRecording() const
{
QTC_ASSERT(isValid(), return false);
return modelNode().hasAuxiliaryData("REC@Internal");
}
void QmlTimelineKeyframeGroup::toogleRecording(bool record) const
{
QTC_ASSERT(isValid(), return);
if (!record) {
if (isRecording())
modelNode().removeAuxiliaryData("REC@Internal");
} else {
modelNode().setAuxiliaryData("REC@Internal", true);
}
}
QmlTimeline QmlTimelineKeyframeGroup::timeline() const
{
QTC_ASSERT(isValid(), return {});
if (modelNode().hasParentProperty())
return modelNode().parentProperty().parentModelNode();
return {};
}
void QmlTimelineKeyframeGroup::setValue(const QVariant &value, qreal currentFrame)
{
QTC_ASSERT(isValid(), return);
for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) {
if (qFuzzyCompare(childNode.variantProperty("frame").value().toReal(), currentFrame)) {
@@ -143,6 +181,8 @@ void QmlTimelineKeyframeGroup::setValue(const QVariant &value, qreal currentFram
QVariant QmlTimelineKeyframeGroup::value(qreal frame) const
{
QTC_ASSERT(isValid(), return {});
for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) {
if (qFuzzyCompare(childNode.variantProperty("frame").value().toReal(), frame)) {
return childNode.variantProperty("value").value();
@@ -154,6 +194,8 @@ QVariant QmlTimelineKeyframeGroup::value(qreal frame) const
TypeName QmlTimelineKeyframeGroup::valueType() const
{
QTC_ASSERT(isValid(), return {});
const ModelNode targetNode = target();
if (targetNode.isValid() && targetNode.hasMetaInfo())
@@ -174,6 +216,8 @@ bool QmlTimelineKeyframeGroup::hasKeyframe(qreal frame)
qreal QmlTimelineKeyframeGroup::minActualKeyframe() const
{
QTC_ASSERT(isValid(), return -1);
qreal min = std::numeric_limits<double>::max();
for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) {
QVariant value = childNode.variantProperty("frame").value();
@@ -186,6 +230,8 @@ qreal QmlTimelineKeyframeGroup::minActualKeyframe() const
qreal QmlTimelineKeyframeGroup::maxActualKeyframe() const
{
QTC_ASSERT(isValid(), return -1);
qreal max = std::numeric_limits<double>::min();
for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) {
QVariant value = childNode.variantProperty("frame").value();