summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview/qgraphicsitemanimation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/graphicsview/qgraphicsitemanimation.cpp')
-rw-r--r--src/widgets/graphicsview/qgraphicsitemanimation.cpp62
1 files changed, 35 insertions, 27 deletions
diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.cpp b/src/widgets/graphicsview/qgraphicsitemanimation.cpp
index 0a6fccf559..585539de94 100644
--- a/src/widgets/graphicsview/qgraphicsitemanimation.cpp
+++ b/src/widgets/graphicsview/qgraphicsitemanimation.cpp
@@ -116,7 +116,6 @@ public:
qreal step;
struct Pair {
- Pair(qreal a, qreal b) : step(a), value(b) {}
bool operator <(const Pair &other) const
{ return step < other.step; }
bool operator==(const Pair &other) const
@@ -124,21 +123,22 @@ public:
qreal step;
qreal value;
};
- QList<Pair> xPosition;
- QList<Pair> yPosition;
- QList<Pair> rotation;
- QList<Pair> verticalScale;
- QList<Pair> horizontalScale;
- QList<Pair> verticalShear;
- QList<Pair> horizontalShear;
- QList<Pair> xTranslation;
- QList<Pair> yTranslation;
-
- qreal linearValueForStep(qreal step, QList<Pair> *source, qreal defaultValue = 0);
- void insertUniquePair(qreal step, qreal value, QList<Pair> *binList, const char* method);
+ QVector<Pair> xPosition;
+ QVector<Pair> yPosition;
+ QVector<Pair> rotation;
+ QVector<Pair> verticalScale;
+ QVector<Pair> horizontalScale;
+ QVector<Pair> verticalShear;
+ QVector<Pair> horizontalShear;
+ QVector<Pair> xTranslation;
+ QVector<Pair> yTranslation;
+
+ qreal linearValueForStep(qreal step, QVector<Pair> *source, qreal defaultValue = 0);
+ void insertUniquePair(qreal step, qreal value, QVector<Pair> *binList, const char* method);
};
+Q_DECLARE_TYPEINFO(QGraphicsItemAnimationPrivate::Pair, Q_PRIMITIVE_TYPE);
-qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QList<Pair> *source, qreal defaultValue)
+qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QVector<Pair> *source, qreal defaultValue)
{
if (source->isEmpty())
return defaultValue;
@@ -168,20 +168,18 @@ qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QList<Pair>
return valueBefore + (valueAfter - valueBefore) * ((step - stepBefore) / (stepAfter - stepBefore));
}
-void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QList<Pair> *binList, const char* method)
+void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QVector<Pair> *binList, const char* method)
{
if (!check_step_valid(step, method))
return;
- Pair pair(step, value);
+ const Pair pair = { step, value };
- QList<Pair>::iterator result = std::lower_bound(binList->begin(), binList->end(), pair);
- if ((result != binList->end()) && !(pair < *result))
+ const QVector<Pair>::iterator result = std::lower_bound(binList->begin(), binList->end(), pair);
+ if (result == binList->end() || pair < *result)
+ binList->insert(result, pair);
+ else
result->value = value;
- else {
- *binList << pair;
- std::sort(binList->begin(), binList->end());
- }
}
/*!
@@ -284,7 +282,9 @@ void QGraphicsItemAnimation::setPosAt(qreal step, const QPointF &pos)
QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::posList() const
{
QList<QPair<qreal, QPointF> > list;
- for (int i = 0; i < d->xPosition.size(); ++i)
+ const int xPosCount = d->xPosition.size();
+ list.reserve(xPosCount);
+ for (int i = 0; i < xPosCount; ++i)
list << QPair<qreal, QPointF>(d->xPosition.at(i).step, QPointF(d->xPosition.at(i).value, d->yPosition.at(i).value));
return list;
@@ -338,7 +338,9 @@ void QGraphicsItemAnimation::setRotationAt(qreal step, qreal angle)
QList<QPair<qreal, qreal> > QGraphicsItemAnimation::rotationList() const
{
QList<QPair<qreal, qreal> > list;
- for (int i = 0; i < d->rotation.size(); ++i)
+ const int numRotations = d->rotation.size();
+ list.reserve(numRotations);
+ for (int i = 0; i < numRotations; ++i)
list << QPair<qreal, qreal>(d->rotation.at(i).step, d->rotation.at(i).value);
return list;
@@ -386,7 +388,9 @@ void QGraphicsItemAnimation::setTranslationAt(qreal step, qreal dx, qreal dy)
QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::translationList() const
{
QList<QPair<qreal, QPointF> > list;
- for (int i = 0; i < d->xTranslation.size(); ++i)
+ const int numTranslations = d->xTranslation.size();
+ list.reserve(numTranslations);
+ for (int i = 0; i < numTranslations; ++i)
list << QPair<qreal, QPointF>(d->xTranslation.at(i).step, QPointF(d->xTranslation.at(i).value, d->yTranslation.at(i).value));
return list;
@@ -435,7 +439,9 @@ void QGraphicsItemAnimation::setScaleAt(qreal step, qreal sx, qreal sy)
QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::scaleList() const
{
QList<QPair<qreal, QPointF> > list;
- for (int i = 0; i < d->horizontalScale.size(); ++i)
+ const int numScales = d->horizontalScale.size();
+ list.reserve(numScales);
+ for (int i = 0; i < numScales; ++i)
list << QPair<qreal, QPointF>(d->horizontalScale.at(i).step, QPointF(d->horizontalScale.at(i).value, d->verticalScale.at(i).value));
return list;
@@ -483,7 +489,9 @@ void QGraphicsItemAnimation::setShearAt(qreal step, qreal sh, qreal sv)
QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::shearList() const
{
QList<QPair<qreal, QPointF> > list;
- for (int i = 0; i < d->horizontalShear.size(); ++i)
+ const int numShears = d->horizontalShear.size();
+ list.reserve(numShears);
+ for (int i = 0; i < numShears; ++i)
list << QPair<qreal, QPointF>(d->horizontalShear.at(i).step, QPointF(d->horizontalShear.at(i).value, d->verticalShear.at(i).value));
return list;