QmlDesigner: Implement new functions in QmlObjectNode and QmlTimelineKeyframeGroup

* QmlObjectNode::allInvalidStateOperations
 * QmlTimelineKeyframeGroup::allInvalidTimelineKeyframeGroups

These functions make it easy to find dangling/invalid PropertyChanges and
KeyFrameGroups.

Change-Id: I201a6561a51aba53405e8a8fc92821c467fecb1b
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Thomas Hartmann
2021-10-06 12:56:00 +02:00
committed by Thomas Hartmann
parent 50557abd03
commit 8f974cd1c5
6 changed files with 46 additions and 3 deletions

View File

@@ -128,14 +128,13 @@ public:
virtual bool isBlocked(const PropertyName &propName) const; virtual bool isBlocked(const PropertyName &propName) const;
friend auto qHash(const QmlObjectNode &node) { return qHash(node.modelNode()); } friend auto qHash(const QmlObjectNode &node) { return qHash(node.modelNode()); }
QList<QmlModelState> allDefinedStates() const;
QList<QmlModelStateOperation> allInvalidStateOperations() const;
protected: protected:
NodeInstance nodeInstance() const; NodeInstance nodeInstance() const;
QmlObjectNode nodeForInstance(const NodeInstance &instance) const; QmlObjectNode nodeForInstance(const NodeInstance &instance) const;
QmlItemNode itemForInstance(const NodeInstance &instance) const; QmlItemNode itemForInstance(const NodeInstance &instance) const;
protected:
QList<QmlModelState> allDefinedStates() const;
}; };
QMLDESIGNERCORE_EXPORT QList<ModelNode> toModelNodeList(const QList<QmlObjectNode> &fxObjectNodeList); QMLDESIGNERCORE_EXPORT QList<ModelNode> toModelNodeList(const QList<QmlObjectNode> &fxObjectNodeList);

View File

@@ -50,6 +50,7 @@ public:
QList<QmlModelStateOperation> stateOperations(const ModelNode &node) const; QList<QmlModelStateOperation> stateOperations(const ModelNode &node) const;
QList<QmlPropertyChanges> propertyChanges() const; QList<QmlPropertyChanges> propertyChanges() const;
QList<QmlModelStateOperation> stateOperations() const; QList<QmlModelStateOperation> stateOperations() const;
QList<QmlModelStateOperation> allInvalidStateOperations() const;
bool hasPropertyChanges(const ModelNode &node) const; bool hasPropertyChanges(const ModelNode &node) const;

View File

@@ -72,6 +72,7 @@ public:
static bool isValidKeyframe(const ModelNode &node); static bool isValidKeyframe(const ModelNode &node);
static bool checkKeyframesType(const ModelNode &node); static bool checkKeyframesType(const ModelNode &node);
static QmlTimelineKeyframeGroup keyframeGroupForKeyframe(const ModelNode &node); static QmlTimelineKeyframeGroup keyframeGroupForKeyframe(const ModelNode &node);
static QList<QmlTimelineKeyframeGroup> allInvalidTimelineKeyframeGroups(AbstractView *view);
void moveAllKeyframes(qreal offset); void moveAllKeyframes(qreal offset);
void scaleAllKeyframes(qreal factor); void scaleAllKeyframes(qreal factor);
@@ -84,6 +85,8 @@ public:
void toogleRecording(bool b) const; void toogleRecording(bool b) const;
QmlTimeline timeline() const; QmlTimeline timeline() const;
bool isDangling() const;
}; };
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -523,6 +523,16 @@ QList<QmlModelState> QmlObjectNode::allDefinedStates() const
return returnList; return returnList;
} }
QList<QmlModelStateOperation> QmlObjectNode::allInvalidStateOperations() const
{
QList<QmlModelStateOperation> result;
const auto allStates = allDefinedStates();
for (const auto &state : allStates)
result.append(state.allInvalidStateOperations());
return result;
}
/*! /*!
Removes a variant property of the object specified by \a name from the Removes a variant property of the object specified by \a name from the

View File

@@ -34,6 +34,7 @@
#include "qmlitemnode.h" #include "qmlitemnode.h"
#include "annotation.h" #include "annotation.h"
#include <utils/algorithm.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
namespace QmlDesigner { namespace QmlDesigner {
@@ -136,6 +137,12 @@ QList<QmlModelStateOperation> QmlModelState::stateOperations() const
return returnList; return returnList;
} }
QList<QmlModelStateOperation> QmlModelState::allInvalidStateOperations() const
{
return Utils::filtered(stateOperations(), [](const QmlModelStateOperation &operation) {
return !operation.target().isValid();
});
}
/*! /*!
Adds a change set for \a node to this state, but only if it does not Adds a change set for \a node to this state, but only if it does not

View File

@@ -153,6 +153,13 @@ QmlTimeline QmlTimelineKeyframeGroup::timeline() const
return {}; return {};
} }
bool QmlTimelineKeyframeGroup::isDangling() const
{
QTC_ASSERT(isValid(), return false);
return !target().isValid() || keyframes().isEmpty();
}
void QmlTimelineKeyframeGroup::setValue(const QVariant &value, qreal currentFrame) void QmlTimelineKeyframeGroup::setValue(const QVariant &value, qreal currentFrame)
{ {
QTC_ASSERT(isValid(), return ); QTC_ASSERT(isValid(), return );
@@ -294,6 +301,22 @@ QmlTimelineKeyframeGroup QmlTimelineKeyframeGroup::keyframeGroupForKeyframe(cons
return QmlTimelineKeyframeGroup(); return QmlTimelineKeyframeGroup();
} }
QList<QmlTimelineKeyframeGroup> QmlTimelineKeyframeGroup::allInvalidTimelineKeyframeGroups(AbstractView *view)
{
QList<QmlTimelineKeyframeGroup> ret;
QTC_ASSERT(view, return ret);
QTC_ASSERT(view->model(), return ret);
QTC_ASSERT(view->rootModelNode().isValid(), return ret);
const auto groups = view->rootModelNode().subModelNodesOfType("QtQuick.Timeline.KeyframeGroup");
for (const QmlTimelineKeyframeGroup &group : groups) {
if (group.isDangling())
ret.append(group);
}
return ret;
}
void QmlTimelineKeyframeGroup::moveAllKeyframes(qreal offset) void QmlTimelineKeyframeGroup::moveAllKeyframes(qreal offset)
{ {
for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) { for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) {