Make sure to neither load nor store invalid qeasing-curves

Remove set-value-spinbox.
Do not convert single-segment-qeasing-curves to bezier if they would become invalid.
Do not store invalid qeasing-curves in the keyframe ModelNode.
Make sure that a conversion does not produce nans

Change-Id: I0688de55bf6b0ef6fe69d70d9192d852c8d6b895
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Knud Dollereder
2020-03-16 16:43:58 +01:00
parent db23f3e10b
commit 6cc080e055
4 changed files with 21 additions and 12 deletions

View File

@@ -106,13 +106,6 @@ QToolBar *CurveEditor::createToolBar(CurveEditorModel *model)
Q_UNUSED(tangentStepAction);
Q_UNUSED(tangentDefaultAction);
auto *valueBox = new QHBoxLayout;
valueBox->addWidget(new QLabel(tr("Value")));
valueBox->addWidget(new QDoubleSpinBox);
auto *valueWidget = new QWidget;
valueWidget->setLayout(valueBox);
bar->addWidget(valueWidget);
auto *durationBox = new QHBoxLayout;
auto *startSpin = new QSpinBox;
auto *endSpin = new QSpinBox;

View File

@@ -150,7 +150,18 @@ CurveSegment::CurveSegment(const Keyframe &left, const Keyframe &right)
bool CurveSegment::isValid() const
{
return m_left.position() != m_right.position();
if (m_left.position() == m_right.position())
return false;
if (interpolation() == Keyframe::Interpolation::Undefined)
return false;
if (interpolation() == Keyframe::Interpolation::Easing
|| interpolation() == Keyframe::Interpolation::Bezier) {
if (qFuzzyCompare(m_left.position().y(), m_right.position().y()))
return false;
}
return true;
}
bool CurveSegment::containsX(double x) const
@@ -263,6 +274,10 @@ QEasingCurve CurveSegment::easingCurve() const
auto mapPosition = [this](const QPointF &position) {
QPointF min = m_left.position();
QPointF max = m_right.position();
if (qFuzzyCompare(min.y(), max.y()))
return QPointF((position.x() - min.x()) / (max.x() - min.x()),
(position.y() - min.y()) / (max.y()));
return QPointF((position.x() - min.x()) / (max.x() - min.x()),
(position.y() - min.y()) / (max.y() - min.y()));
};
@@ -270,8 +285,7 @@ QEasingCurve CurveSegment::easingCurve() const
QEasingCurve curve;
curve.addCubicBezierSegment(mapPosition(m_left.rightHandle()),
mapPosition(m_right.leftHandle()),
mapPosition(m_right.position()));
QPointF(1., 1.));
return curve;
}

View File

@@ -30,8 +30,8 @@
#include "qmltimeline.h"
#include <bindingproperty.h>
#include <variantproperty.h>
#include <theme.h>
#include <variantproperty.h>
namespace QmlDesigner {
@@ -204,6 +204,7 @@ std::vector<DesignTools::Keyframe> resolveSmallCurves(
for (auto &&frame : frames) {
if (frame.hasData() && !out.empty()) {
QEasingCurve curve = frame.data().toEasingCurve();
// One-segment-curve: Since (0,0) is implicit => 3
if (curve.toCubicSpline().count() == 3) {
DesignTools::Keyframe &previous = out.back();
#if 0

View File

@@ -355,7 +355,8 @@ void TimelineWidget::updateAnimationCurve(DesignTools::PropertyTreeItem *item)
if (previous.isValid()) {
if (frame.interpolation() == DesignTools::Keyframe::Interpolation::Bezier) {
DesignTools::CurveSegment segment(previous, frame);
attachEasingCurve(pos.x(), segment.easingCurve(), group);
if (segment.isValid())
attachEasingCurve(pos.x(), segment.easingCurve(), group);
} else if (frame.interpolation()
== DesignTools::Keyframe::Interpolation::Easing) {
QVariant data = frame.data();