From 6cc080e055ed5c172367df0ce4c4be6eb812a471 Mon Sep 17 00:00:00 2001 From: Knud Dollereder Date: Mon, 16 Mar 2020 16:43:58 +0100 Subject: [PATCH] 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 --- .../components/curveeditor/curveeditor.cpp | 7 ------- .../components/curveeditor/curvesegment.cpp | 20 ++++++++++++++++--- .../animationcurveeditormodel.cpp | 3 ++- .../timelineeditor/timelinewidget.cpp | 3 ++- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp b/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp index f5b2ffae1b0..84788fbdead 100644 --- a/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/curveeditor.cpp @@ -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; diff --git a/src/plugins/qmldesigner/components/curveeditor/curvesegment.cpp b/src/plugins/qmldesigner/components/curveeditor/curvesegment.cpp index 0bcb64e0357..26a1dffc3ee 100644 --- a/src/plugins/qmldesigner/components/curveeditor/curvesegment.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/curvesegment.cpp @@ -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; } diff --git a/src/plugins/qmldesigner/components/timelineeditor/animationcurveeditormodel.cpp b/src/plugins/qmldesigner/components/timelineeditor/animationcurveeditormodel.cpp index 35b89f6f170..023200f494d 100644 --- a/src/plugins/qmldesigner/components/timelineeditor/animationcurveeditormodel.cpp +++ b/src/plugins/qmldesigner/components/timelineeditor/animationcurveeditormodel.cpp @@ -30,8 +30,8 @@ #include "qmltimeline.h" #include -#include #include +#include namespace QmlDesigner { @@ -204,6 +204,7 @@ std::vector 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 diff --git a/src/plugins/qmldesigner/components/timelineeditor/timelinewidget.cpp b/src/plugins/qmldesigner/components/timelineeditor/timelinewidget.cpp index d80749ad082..508db1051b6 100644 --- a/src/plugins/qmldesigner/components/timelineeditor/timelinewidget.cpp +++ b/src/plugins/qmldesigner/components/timelineeditor/timelinewidget.cpp @@ -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();