From a4e7db378ecd11bc858f76beb33c56ccebef6308 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Tue, 3 Nov 2009 15:59:41 +0100 Subject: Fixed fillRect on QImage::Format_ARGB32 images. With composition mode set to QPainter::CompositionMode_Source, the raster paint engine's fillRect function filled images which had non-premultiplied format with premultiplied colours. This was fixed by converting the premultiplied colour back to non-premultiplied before writing to the image. Task-number: QTBUG-5189 Reviewed-by: Trond --- src/gui/painting/qdrawhelper.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index 53edbb0..41602a1 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -7424,6 +7424,14 @@ QT_RECTFILL(qrgb444) QT_RECTFILL(qargb4444) #undef QT_RECTFILL +inline static void qt_rectfill_nonpremul_quint32(QRasterBuffer *rasterBuffer, + int x, int y, int width, int height, + quint32 color) +{ + qt_rectfill(reinterpret_cast(rasterBuffer->buffer()), + INV_PREMUL(color), x, y, width, height, rasterBuffer->bytesPerLine()); +} + // Map table for destination image format. Contains function pointers // for blends of various types unto the destination @@ -7466,7 +7474,7 @@ DrawHelper qDrawHelper[QImage::NImageFormats] = qt_bitmapblit_quint32, qt_alphamapblit_quint32, qt_alphargbblit_quint32, - qt_rectfill_quint32 + qt_rectfill_nonpremul_quint32 }, // Format_ARGB32_Premultiplied { -- cgit v0.12 From 9f62759028b0bdb8fb7991c349d58a89323b8567 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 3 Nov 2009 11:04:07 +0100 Subject: Change name of QStateMachine::animationsEnabled property to "animated" The name "animated" is consistent with naming in Qt otherwise, as in QTreeView::animated and QMainWindow::animated. Reviewed-by: Kent Hansen --- src/corelib/statemachine/qstatemachine.cpp | 14 +++++++------- src/corelib/statemachine/qstatemachine.h | 6 +++--- src/corelib/statemachine/qstatemachine_p.h | 2 +- tests/auto/qstatemachine/tst_qstatemachine.cpp | 10 +++++----- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 689967a..322e24a 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -164,7 +164,7 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_ANIMATION /*! - \property QStateMachine::animationsEnabled + \property QStateMachine::animated \brief whether animations are enabled @@ -188,7 +188,7 @@ QStateMachinePrivate::QStateMachinePrivate() globalRestorePolicy = QStateMachine::DoNotRestoreProperties; signalEventGenerator = 0; #ifndef QT_NO_ANIMATION - animationsEnabled = true; + animated = true; #endif } @@ -742,7 +742,7 @@ void QStateMachinePrivate::applyProperties(const QList &tr // Find the animations to use for the state change. QList selectedAnimations; - if (animationsEnabled) { + if (animated) { for (int i = 0; i < transitionList.size(); ++i) { QAbstractTransition *transition = transitionList.at(i); @@ -2116,19 +2116,19 @@ void QStateMachine::onExit(QEvent *event) /*! Returns whether animations are enabled for this state machine. */ -bool QStateMachine::animationsEnabled() const +bool QStateMachine::isAnimated() const { Q_D(const QStateMachine); - return d->animationsEnabled; + return d->animated; } /*! Sets whether animations are \a enabled for this state machine. */ -void QStateMachine::setAnimationsEnabled(bool enabled) +void QStateMachine::setAnimated(bool enabled) { Q_D(QStateMachine); - d->animationsEnabled = enabled; + d->animated = enabled; } /*! diff --git a/src/corelib/statemachine/qstatemachine.h b/src/corelib/statemachine/qstatemachine.h index 13b6fe2..f7ceba1 100644 --- a/src/corelib/statemachine/qstatemachine.h +++ b/src/corelib/statemachine/qstatemachine.h @@ -67,7 +67,7 @@ class Q_CORE_EXPORT QStateMachine : public QState Q_PROPERTY(RestorePolicy globalRestorePolicy READ globalRestorePolicy WRITE setGlobalRestorePolicy) Q_ENUMS(RestorePolicy) #ifndef QT_NO_ANIMATION - Q_PROPERTY(bool animationsEnabled READ animationsEnabled WRITE setAnimationsEnabled) + Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated) #endif public: class SignalEvent : public QEvent @@ -133,8 +133,8 @@ public: bool isRunning() const; #ifndef QT_NO_ANIMATION - bool animationsEnabled() const; - void setAnimationsEnabled(bool enabled); + bool isAnimated() const; + void setAnimated(bool enabled); void addDefaultAnimation(QAbstractAnimation *animation); QList defaultAnimations() const; diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index 69b727d..f0d9c7c 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -200,7 +200,7 @@ public: QSet pendingErrorStatesForDefaultEntry; #ifndef QT_NO_ANIMATION - bool animationsEnabled; + bool animated; QPair, QList > initializeAnimation(QAbstractAnimation *abstractAnimation, diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 975b301..0df8d52 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -1340,11 +1340,11 @@ void tst_QStateMachine::assignPropertyWithAnimation() // Single animation { QStateMachine machine; - QVERIFY(machine.animationsEnabled()); - machine.setAnimationsEnabled(false); - QVERIFY(!machine.animationsEnabled()); - machine.setAnimationsEnabled(true); - QVERIFY(machine.animationsEnabled()); + QVERIFY(machine.isAnimated()); + machine.setAnimated(false); + QVERIFY(!machine.isAnimated()); + machine.setAnimated(true); + QVERIFY(machine.isAnimated()); QObject obj; obj.setProperty("foo", 321); obj.setProperty("bar", 654); -- cgit v0.12 From b210026bda1fcd6d38b8a5a556aefe4fb5c4f891 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 3 Nov 2009 12:05:55 +0100 Subject: Change name of DoNotRestoreProperties enum to DontRestoreProperties Using the abbreviated "Dont" is consistent with other negated enum names in Qt. Reviewed-by: Kent Hansen --- src/corelib/statemachine/qstatemachine.cpp | 8 ++++---- src/corelib/statemachine/qstatemachine.h | 2 +- tests/auto/qstatemachine/tst_qstatemachine.cpp | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 322e24a..0d07093 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -159,7 +159,7 @@ QT_BEGIN_NAMESPACE \brief the restore policy for states of this state machine. The default value of this property is - QStateMachine::DoNotRestoreProperties. + QStateMachine::DontRestoreProperties. */ #ifndef QT_NO_ANIMATION @@ -185,7 +185,7 @@ QStateMachinePrivate::QStateMachinePrivate() stop = false; stopProcessingReason = EventQueueEmpty; error = QStateMachine::NoError; - globalRestorePolicy = QStateMachine::DoNotRestoreProperties; + globalRestorePolicy = QStateMachine::DontRestoreProperties; signalEventGenerator = 0; #ifndef QT_NO_ANIMATION animated = true; @@ -1696,7 +1696,7 @@ QStateMachine::~QStateMachine() already been saved by the state machine, it will not be overwritten until the property has been successfully restored. - \value DoNotRestoreProperties The state machine should not save the initial values of properties + \value DontRestoreProperties The state machine should not save the initial values of properties and restore them later. \value RestoreProperties The state machine should save the initial values of properties and restore them later. @@ -1746,7 +1746,7 @@ QStateMachine::RestorePolicy QStateMachine::globalRestorePolicy() const /*! Sets the restore policy of the state machine to \a restorePolicy. The default - restore policy is QAbstractState::DoNotRestoreProperties. + restore policy is QAbstractState::DontRestoreProperties. \sa globalRestorePolicy() */ diff --git a/src/corelib/statemachine/qstatemachine.h b/src/corelib/statemachine/qstatemachine.h index f7ceba1..ff2b667 100644 --- a/src/corelib/statemachine/qstatemachine.h +++ b/src/corelib/statemachine/qstatemachine.h @@ -109,7 +109,7 @@ public: }; enum RestorePolicy { - DoNotRestoreProperties, + DontRestoreProperties, RestoreProperties }; diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 0df8d52..31ab3af 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -162,7 +162,7 @@ private slots: void defaultGlobalRestorePolicy(); void globalRestorePolicySetToRestore(); - void globalRestorePolicySetToDoNotRestore(); + void globalRestorePolicySetToDontRestore(); void noInitialStateForInitialState(); @@ -984,7 +984,7 @@ void tst_QStateMachine::customErrorStateNotInGraph() void tst_QStateMachine::restoreProperties() { QStateMachine machine; - QCOMPARE(machine.globalRestorePolicy(), QStateMachine::DoNotRestoreProperties); + QCOMPARE(machine.globalRestorePolicy(), QStateMachine::DontRestoreProperties); machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties); QObject *object = new QObject(&machine); @@ -2736,10 +2736,10 @@ void tst_QStateMachine::restorePolicyNotInherited() }*/ -void tst_QStateMachine::globalRestorePolicySetToDoNotRestore() +void tst_QStateMachine::globalRestorePolicySetToDontRestore() { QStateMachine machine; - machine.setGlobalRestorePolicy(QStateMachine::DoNotRestoreProperties); + machine.setGlobalRestorePolicy(QStateMachine::DontRestoreProperties); QObject *propertyHolder = new QObject(&machine); propertyHolder->setProperty("a", 1); -- cgit v0.12 From 569e4b636fc91a9d5c6f6e4d65967327786adb3c Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 3 Nov 2009 13:13:35 +0100 Subject: Remove return type of QState::addTransition(QAbstractTransition*) Returning the input argument in a function can lead to confusion and serves no purpose here. Instead, we'll mirror the API from QMenu::addAction() overloads, where the overload that takes a preconstructed object has a void return type. Reviewed-by: Kent Hansen --- src/corelib/statemachine/qstate.cpp | 15 +++++---- src/corelib/statemachine/qstate.h | 2 +- tests/auto/qstatemachine/tst_qstatemachine.cpp | 42 +++++++++++++++++--------- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index bcd8364..ea20619 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -286,15 +286,14 @@ void QState::setErrorState(QAbstractState *state) /*! Adds the given \a transition. The transition has this state as the source. - This state takes ownership of the transition. If the transition is successfully - added, the function will return the \a transition pointer. Otherwise it will return null. + This state takes ownership of the transition. */ -QAbstractTransition *QState::addTransition(QAbstractTransition *transition) +void QState::addTransition(QAbstractTransition *transition) { Q_D(QState); if (!transition) { qWarning("QState::addTransition: cannot add null transition"); - return 0; + return ; } transition->setParent(this); @@ -303,18 +302,17 @@ QAbstractTransition *QState::addTransition(QAbstractTransition *transition) QAbstractState *t = targets.at(i).data(); if (!t) { qWarning("QState::addTransition: cannot add transition to null state"); - return 0; + return ; } if ((QAbstractStatePrivate::get(t)->machine() != d->machine()) && QAbstractStatePrivate::get(t)->machine() && d->machine()) { qWarning("QState::addTransition: cannot add transition " "to a state in a different state machine"); - return 0; + return ; } } if (machine() != 0 && machine()->configuration().contains(this)) QStateMachinePrivate::get(machine())->registerTransitions(this); - return transition; } /*! @@ -379,7 +377,8 @@ QAbstractTransition *QState::addTransition(QAbstractState *target) return 0; } UnconditionalTransition *trans = new UnconditionalTransition(target); - return addTransition(trans); + addTransition(trans); + return trans; } /*! diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h index 7a47447..781382d 100644 --- a/src/corelib/statemachine/qstate.h +++ b/src/corelib/statemachine/qstate.h @@ -76,7 +76,7 @@ public: QAbstractState *errorState() const; void setErrorState(QAbstractState *state); - QAbstractTransition *addTransition(QAbstractTransition *transition); + void addTransition(QAbstractTransition *transition); QSignalTransition *addTransition(QObject *sender, const char *signal, QAbstractState *target); QAbstractTransition *addTransition(QAbstractState *target); void removeTransition(QAbstractTransition *transition); diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 31ab3af..fb6567a 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -286,8 +286,8 @@ void tst_QStateMachine::transitionToRootState() machine.addState(initialState); machine.setInitialState(initialState); - QAbstractTransition *trans = initialState->addTransition(new EventTransition(QEvent::User, &machine)); - QVERIFY(trans != 0); + QAbstractTransition *trans = new EventTransition(QEvent::User, &machine); + initialState->addTransition(trans); QCOMPARE(trans->sourceState(), initialState); QCOMPARE(trans->targetState(), static_cast(&machine)); @@ -310,7 +310,7 @@ void tst_QStateMachine::transitionFromRootState() QState *root = &machine; QState *s1 = new QState(root); EventTransition *trans = new EventTransition(QEvent::User, s1); - QCOMPARE(root->addTransition(trans), static_cast(trans)); + root->addTransition(trans); QCOMPARE(trans->sourceState(), root); QCOMPARE(trans->targetState(), static_cast(s1)); } @@ -1155,7 +1155,7 @@ void tst_QStateMachine::stateEntryAndExit() QCOMPARE(t->targetState(), (QAbstractState*)s2); QCOMPARE(t->targetStates().size(), 1); QCOMPARE(t->targetStates().at(0), (QAbstractState*)s2); - QCOMPARE(s1->addTransition(t), (QAbstractTransition*)t); + s1->addTransition(t); QCOMPARE(t->sourceState(), (QState*)s1); QCOMPARE(t->machine(), &machine); @@ -1173,7 +1173,7 @@ void tst_QStateMachine::stateEntryAndExit() s2->removeTransition(trans); QCOMPARE(trans->sourceState(), (QState*)0); QCOMPARE(trans->targetState(), (QAbstractState*)s3); - QCOMPARE(s2->addTransition(trans), trans); + s2->addTransition(trans); QCOMPARE(trans->sourceState(), (QState*)s2); } @@ -3117,7 +3117,9 @@ void tst_QStateMachine::twoAnimatedTransitions() QState *s2 = new QState(&machine); s2->assignProperty(object, "foo", 5.0); QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2); - s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation); + EventTransition *trans = new EventTransition(QEvent::User, s2); + s1->addTransition(trans); + trans->addAnimation(fooAnimation); QState *s3 = new QState(&machine); QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); @@ -3126,7 +3128,9 @@ void tst_QStateMachine::twoAnimatedTransitions() QState *s4 = new QState(&machine); s4->assignProperty(object, "foo", 2.0); QPropertyAnimation *fooAnimation2 = new QPropertyAnimation(object, "foo", s4); - s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation2); + trans = new EventTransition(QEvent::User, s4); + s3->addTransition(trans); + trans->addAnimation(fooAnimation2); QState *s5 = new QState(&machine); QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit())); @@ -3161,7 +3165,9 @@ void tst_QStateMachine::playAnimationTwice() QState *s2 = new QState(&machine); s2->assignProperty(object, "foo", 5.0); QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2); - s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation); + EventTransition *trans = new EventTransition(QEvent::User, s2); + s1->addTransition(trans); + trans->addAnimation(fooAnimation); QState *s3 = new QState(&machine); QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); @@ -3169,7 +3175,9 @@ void tst_QStateMachine::playAnimationTwice() QState *s4 = new QState(&machine); s4->assignProperty(object, "foo", 2.0); - s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation); + trans = new EventTransition(QEvent::User, s4); + s3->addTransition(trans); + trans->addAnimation(fooAnimation); QState *s5 = new QState(&machine); QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit())); @@ -3213,14 +3221,16 @@ void tst_QStateMachine::nestedTargetStateForAnimation() QState *s2Child2 = new QState(s2); s2Child2->assignProperty(object, "bar", 11.0); - QAbstractTransition *at = s2Child->addTransition(new EventTransition(QEvent::User, s2Child2)); + QAbstractTransition *at = new EventTransition(QEvent::User, s2Child2); + s2Child->addTransition(at); QPropertyAnimation *animation = new QPropertyAnimation(object, "bar", s2); animation->setDuration(2000); connect(animation, SIGNAL(finished()), &counter, SLOT(slot())); at->addAnimation(animation); - at = s1->addTransition(new EventTransition(QEvent::User, s2)); + at = new EventTransition(QEvent::User, s2); + s1->addTransition(at); animation = new QPropertyAnimation(object, "foo", s2); connect(animation, SIGNAL(finished()), &counter, SLOT(slot())); @@ -3299,7 +3309,8 @@ void tst_QStateMachine::animatedGlobalRestoreProperty() QState *s4 = new QState(&machine); QObject::connect(s4, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); - QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2)); + QAbstractTransition *at = new EventTransition(QEvent::User, s2); + s1->addTransition(at); QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", s2); connect(pa, SIGNAL(finished()), &counter, SLOT(slot())); at->addAnimation(pa); @@ -3341,7 +3352,9 @@ void tst_QStateMachine::specificTargetValueOfAnimation() QPropertyAnimation *anim = new QPropertyAnimation(object, "foo"); anim->setEndValue(10.0); - s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(anim); + EventTransition *trans = new EventTransition(QEvent::User, s2); + s1->addTransition(trans); + trans->addAnimation(anim); QState *s3 = new QState(&machine); QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); @@ -3495,7 +3508,8 @@ void tst_QStateMachine::overrideDefaultAnimationWithSpecific() QState *s3 = new QState(&machine); QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); - QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2)); + QAbstractTransition *at = new EventTransition(QEvent::User, s2); + s1->addTransition(at); QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo"); connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot())); -- cgit v0.12 From 2596d721d64ad4d484176888cb166fbc43157ca9 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 3 Nov 2009 13:39:40 +0100 Subject: Change name of modifiersMask property to "modifierMask" "modifierMask" is more correct English. Reviewed-by: Kent Hansen --- src/gui/statemachine/qbasickeyeventtransition.cpp | 24 +++++++++++----------- src/gui/statemachine/qbasickeyeventtransition_p.h | 6 +++--- .../statemachine/qbasicmouseeventtransition.cpp | 16 +++++++-------- .../statemachine/qbasicmouseeventtransition_p.h | 4 ++-- src/gui/statemachine/qkeyeventtransition.cpp | 18 ++++++++-------- src/gui/statemachine/qkeyeventtransition.h | 6 +++--- src/gui/statemachine/qmouseeventtransition.cpp | 18 ++++++++-------- src/gui/statemachine/qmouseeventtransition.h | 6 +++--- 8 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/gui/statemachine/qbasickeyeventtransition.cpp b/src/gui/statemachine/qbasickeyeventtransition.cpp index 445a253..bf10e3d 100644 --- a/src/gui/statemachine/qbasickeyeventtransition.cpp +++ b/src/gui/statemachine/qbasickeyeventtransition.cpp @@ -68,14 +68,14 @@ public: QEvent::Type eventType; int key; - Qt::KeyboardModifiers modifiersMask; + Qt::KeyboardModifiers modifierMask; }; QBasicKeyEventTransitionPrivate::QBasicKeyEventTransitionPrivate() { eventType = QEvent::None; key = 0; - modifiersMask = Qt::NoModifier; + modifierMask = Qt::NoModifier; } QBasicKeyEventTransitionPrivate *QBasicKeyEventTransitionPrivate::get(QBasicKeyEventTransition *q) @@ -106,17 +106,17 @@ QBasicKeyEventTransition::QBasicKeyEventTransition(QEvent::Type type, int key, /*! Constructs a new event transition for events of the given \a type for the - given \a key, with the given \a modifiersMask and \a sourceState. + given \a key, with the given \a modifierMask and \a sourceState. */ QBasicKeyEventTransition::QBasicKeyEventTransition(QEvent::Type type, int key, - Qt::KeyboardModifiers modifiersMask, + Qt::KeyboardModifiers modifierMask, QState *sourceState) : QAbstractTransition(*new QBasicKeyEventTransitionPrivate, sourceState) { Q_D(QBasicKeyEventTransition); d->eventType = type; d->key = key; - d->modifiersMask = modifiersMask; + d->modifierMask = modifierMask; } /*! @@ -163,23 +163,23 @@ void QBasicKeyEventTransition::setKey(int key) } /*! - Returns the keyboard modifiers mask that this key event transition checks + Returns the keyboard modifier mask that this key event transition checks for. */ -Qt::KeyboardModifiers QBasicKeyEventTransition::modifiersMask() const +Qt::KeyboardModifiers QBasicKeyEventTransition::modifierMask() const { Q_D(const QBasicKeyEventTransition); - return d->modifiersMask; + return d->modifierMask; } /*! - Sets the keyboard modifiers mask that this key event transition will check + Sets the keyboard modifier mask that this key event transition will check for. */ -void QBasicKeyEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) +void QBasicKeyEventTransition::setModifierMask(Qt::KeyboardModifiers modifierMask) { Q_D(QBasicKeyEventTransition); - d->modifiersMask = modifiersMask; + d->modifierMask = modifierMask; } /*! @@ -191,7 +191,7 @@ bool QBasicKeyEventTransition::eventTest(QEvent *event) if (event->type() == d->eventType) { QKeyEvent *ke = static_cast(event); return (ke->key() == d->key) - && ((ke->modifiers() & d->modifiersMask) == d->modifiersMask); + && ((ke->modifiers() & d->modifierMask) == d->modifierMask); } return false; } diff --git a/src/gui/statemachine/qbasickeyeventtransition_p.h b/src/gui/statemachine/qbasickeyeventtransition_p.h index 3c2ec7d..87d3dc7 100644 --- a/src/gui/statemachine/qbasickeyeventtransition_p.h +++ b/src/gui/statemachine/qbasickeyeventtransition_p.h @@ -69,7 +69,7 @@ public: QBasicKeyEventTransition(QState *sourceState = 0); QBasicKeyEventTransition(QEvent::Type type, int key, QState *sourceState = 0); QBasicKeyEventTransition(QEvent::Type type, int key, - Qt::KeyboardModifiers modifiersMask, + Qt::KeyboardModifiers modifierMask, QState *sourceState = 0); ~QBasicKeyEventTransition(); @@ -79,8 +79,8 @@ public: int key() const; void setKey(int key); - Qt::KeyboardModifiers modifiersMask() const; - void setModifiersMask(Qt::KeyboardModifiers modifiers); + Qt::KeyboardModifiers modifierMask() const; + void setModifierMask(Qt::KeyboardModifiers modifiers); protected: bool eventTest(QEvent *event); diff --git a/src/gui/statemachine/qbasicmouseeventtransition.cpp b/src/gui/statemachine/qbasicmouseeventtransition.cpp index 694c319..4a977ba 100644 --- a/src/gui/statemachine/qbasicmouseeventtransition.cpp +++ b/src/gui/statemachine/qbasicmouseeventtransition.cpp @@ -69,7 +69,7 @@ public: QEvent::Type eventType; Qt::MouseButton button; - Qt::KeyboardModifiers modifiersMask; + Qt::KeyboardModifiers modifierMask; QPainterPath path; }; @@ -149,23 +149,23 @@ void QBasicMouseEventTransition::setButton(Qt::MouseButton button) } /*! - Returns the keyboard modifiers mask that this mouse event transition checks + Returns the keyboard modifier mask that this mouse event transition checks for. */ -Qt::KeyboardModifiers QBasicMouseEventTransition::modifiersMask() const +Qt::KeyboardModifiers QBasicMouseEventTransition::modifierMask() const { Q_D(const QBasicMouseEventTransition); - return d->modifiersMask; + return d->modifierMask; } /*! - Sets the keyboard modifiers mask that this mouse event transition will check + Sets the keyboard modifier mask that this mouse event transition will check for. */ -void QBasicMouseEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) +void QBasicMouseEventTransition::setModifierMask(Qt::KeyboardModifiers modifierMask) { Q_D(QBasicMouseEventTransition); - d->modifiersMask = modifiersMask; + d->modifierMask = modifierMask; } /*! @@ -195,7 +195,7 @@ bool QBasicMouseEventTransition::eventTest(QEvent *event) if (event->type() == d->eventType) { QMouseEvent *me = static_cast(event); return (me->button() == d->button) - && ((me->modifiers() & d->modifiersMask) == d->modifiersMask) + && ((me->modifiers() & d->modifierMask) == d->modifierMask) && (d->path.isEmpty() || d->path.contains(me->pos())); } return false; diff --git a/src/gui/statemachine/qbasicmouseeventtransition_p.h b/src/gui/statemachine/qbasicmouseeventtransition_p.h index 512e0f8..8684fa3 100644 --- a/src/gui/statemachine/qbasicmouseeventtransition_p.h +++ b/src/gui/statemachine/qbasicmouseeventtransition_p.h @@ -79,8 +79,8 @@ public: Qt::MouseButton button() const; void setButton(Qt::MouseButton button); - Qt::KeyboardModifiers modifiersMask() const; - void setModifiersMask(Qt::KeyboardModifiers modifiers); + Qt::KeyboardModifiers modifierMask() const; + void setModifierMask(Qt::KeyboardModifiers modifiers); QPainterPath path() const; void setPath(const QPainterPath &path); diff --git a/src/gui/statemachine/qkeyeventtransition.cpp b/src/gui/statemachine/qkeyeventtransition.cpp index dee3168..a15e671 100644 --- a/src/gui/statemachine/qkeyeventtransition.cpp +++ b/src/gui/statemachine/qkeyeventtransition.cpp @@ -69,9 +69,9 @@ QT_BEGIN_NAMESPACE */ /*! - \property QKeyEventTransition::modifiersMask + \property QKeyEventTransition::modifierMask - \brief the keyboard modifiers mask that this key event transition checks for + \brief the keyboard modifier mask that this key event transition checks for */ class QKeyEventTransitionPrivate : public QEventTransitionPrivate @@ -133,23 +133,23 @@ void QKeyEventTransition::setKey(int key) } /*! - Returns the keyboard modifiers mask that this key event transition checks + Returns the keyboard modifier mask that this key event transition checks for. */ -Qt::KeyboardModifiers QKeyEventTransition::modifiersMask() const +Qt::KeyboardModifiers QKeyEventTransition::modifierMask() const { Q_D(const QKeyEventTransition); - return d->transition->modifiersMask(); + return d->transition->modifierMask(); } /*! - Sets the keyboard \a modifiers mask that this key event transition will - check for. + Sets the keyboard modifier mask that this key event transition will + check for to \a modifierMask. */ -void QKeyEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) +void QKeyEventTransition::setModifierMask(Qt::KeyboardModifiers modifierMask) { Q_D(QKeyEventTransition); - d->transition->setModifiersMask(modifiersMask); + d->transition->setModifierMask(modifierMask); } /*! diff --git a/src/gui/statemachine/qkeyeventtransition.h b/src/gui/statemachine/qkeyeventtransition.h index 8df8138..ab1c155 100644 --- a/src/gui/statemachine/qkeyeventtransition.h +++ b/src/gui/statemachine/qkeyeventtransition.h @@ -57,7 +57,7 @@ class Q_GUI_EXPORT QKeyEventTransition : public QEventTransition { Q_OBJECT Q_PROPERTY(int key READ key WRITE setKey) - Q_PROPERTY(Qt::KeyboardModifiers modifiersMask READ modifiersMask WRITE setModifiersMask) + Q_PROPERTY(Qt::KeyboardModifiers modifierMask READ modifierMask WRITE setModifierMask) public: QKeyEventTransition(QState *sourceState = 0); QKeyEventTransition(QObject *object, QEvent::Type type, int key, @@ -67,8 +67,8 @@ public: int key() const; void setKey(int key); - Qt::KeyboardModifiers modifiersMask() const; - void setModifiersMask(Qt::KeyboardModifiers modifiers); + Qt::KeyboardModifiers modifierMask() const; + void setModifierMask(Qt::KeyboardModifiers modifiers); protected: void onTransition(QEvent *event); diff --git a/src/gui/statemachine/qmouseeventtransition.cpp b/src/gui/statemachine/qmouseeventtransition.cpp index 86cacf7..dbf9e19 100644 --- a/src/gui/statemachine/qmouseeventtransition.cpp +++ b/src/gui/statemachine/qmouseeventtransition.cpp @@ -70,9 +70,9 @@ QT_BEGIN_NAMESPACE */ /*! - \property QMouseEventTransition::modifiersMask + \property QMouseEventTransition::modifierMask - \brief the keyboard modifiers mask that this mouse event transition checks for + \brief the keyboard modifier mask that this mouse event transition checks for */ class QMouseEventTransitionPrivate : public QEventTransitionPrivate @@ -139,23 +139,23 @@ void QMouseEventTransition::setButton(Qt::MouseButton button) } /*! - Returns the keyboard modifiers mask that this mouse event transition checks + Returns the keyboard modifier mask that this mouse event transition checks for. */ -Qt::KeyboardModifiers QMouseEventTransition::modifiersMask() const +Qt::KeyboardModifiers QMouseEventTransition::modifierMask() const { Q_D(const QMouseEventTransition); - return d->transition->modifiersMask(); + return d->transition->modifierMask(); } /*! - Sets the keyboard \a modifiers mask that this mouse event transition will - check for. + Sets the keyboard modifier mask that this mouse event transition will + check for to \a modifierMask. */ -void QMouseEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) +void QMouseEventTransition::setModifierMask(Qt::KeyboardModifiers modifierMask) { Q_D(QMouseEventTransition); - d->transition->setModifiersMask(modifiersMask); + d->transition->setModifierMask(modifierMask); } /*! diff --git a/src/gui/statemachine/qmouseeventtransition.h b/src/gui/statemachine/qmouseeventtransition.h index 4e324ec..a6687b6 100644 --- a/src/gui/statemachine/qmouseeventtransition.h +++ b/src/gui/statemachine/qmouseeventtransition.h @@ -58,7 +58,7 @@ class Q_GUI_EXPORT QMouseEventTransition : public QEventTransition { Q_OBJECT Q_PROPERTY(Qt::MouseButton button READ button WRITE setButton) - Q_PROPERTY(Qt::KeyboardModifiers modifiersMask READ modifiersMask WRITE setModifiersMask) + Q_PROPERTY(Qt::KeyboardModifiers modifierMask READ modifierMask WRITE setModifierMask) public: QMouseEventTransition(QState *sourceState = 0); QMouseEventTransition(QObject *object, QEvent::Type type, @@ -68,8 +68,8 @@ public: Qt::MouseButton button() const; void setButton(Qt::MouseButton button); - Qt::KeyboardModifiers modifiersMask() const; - void setModifiersMask(Qt::KeyboardModifiers modifiers); + Qt::KeyboardModifiers modifierMask() const; + void setModifierMask(Qt::KeyboardModifiers modifiers); QPainterPath path() const; void setPath(const QPainterPath &path); -- cgit v0.12 From 19421cc33af4f439f4c7aea2de9f449987fbc420 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 3 Nov 2009 13:53:19 +0100 Subject: Change name of QMouseEventTransition::path() to hitTestPath(). Make it clearer what the property actually does. Reviewed-by: Kent Hansen --- src/gui/statemachine/qbasicmouseeventtransition.cpp | 8 ++++---- src/gui/statemachine/qbasicmouseeventtransition_p.h | 4 ++-- src/gui/statemachine/qmouseeventtransition.cpp | 12 ++++++------ src/gui/statemachine/qmouseeventtransition.h | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/gui/statemachine/qbasicmouseeventtransition.cpp b/src/gui/statemachine/qbasicmouseeventtransition.cpp index 4a977ba..fe0dea9 100644 --- a/src/gui/statemachine/qbasicmouseeventtransition.cpp +++ b/src/gui/statemachine/qbasicmouseeventtransition.cpp @@ -169,18 +169,18 @@ void QBasicMouseEventTransition::setModifierMask(Qt::KeyboardModifiers modifierM } /*! - Returns the path for this mouse event transition. + Returns the hit test path for this mouse event transition. */ -QPainterPath QBasicMouseEventTransition::path() const +QPainterPath QBasicMouseEventTransition::hitTestPath() const { Q_D(const QBasicMouseEventTransition); return d->path; } /*! - Sets the path for this mouse event transition. + Sets the hit test path for this mouse event transition. */ -void QBasicMouseEventTransition::setPath(const QPainterPath &path) +void QBasicMouseEventTransition::setHitTestPath(const QPainterPath &path) { Q_D(QBasicMouseEventTransition); d->path = path; diff --git a/src/gui/statemachine/qbasicmouseeventtransition_p.h b/src/gui/statemachine/qbasicmouseeventtransition_p.h index 8684fa3..6754c55 100644 --- a/src/gui/statemachine/qbasicmouseeventtransition_p.h +++ b/src/gui/statemachine/qbasicmouseeventtransition_p.h @@ -82,8 +82,8 @@ public: Qt::KeyboardModifiers modifierMask() const; void setModifierMask(Qt::KeyboardModifiers modifiers); - QPainterPath path() const; - void setPath(const QPainterPath &path); + QPainterPath hitTestPath() const; + void setHitTestPath(const QPainterPath &path); protected: bool eventTest(QEvent *event); diff --git a/src/gui/statemachine/qmouseeventtransition.cpp b/src/gui/statemachine/qmouseeventtransition.cpp index dbf9e19..f5c0cb1 100644 --- a/src/gui/statemachine/qmouseeventtransition.cpp +++ b/src/gui/statemachine/qmouseeventtransition.cpp @@ -159,25 +159,25 @@ void QMouseEventTransition::setModifierMask(Qt::KeyboardModifiers modifierMask) } /*! - Returns the path for this mouse event transition. + Returns the hit test path for this mouse event transition. */ -QPainterPath QMouseEventTransition::path() const +QPainterPath QMouseEventTransition::hitTestPath() const { Q_D(const QMouseEventTransition); - return d->transition->path(); + return d->transition->hitTestPath(); } /*! - Sets the \a path for this mouse event transition. + Sets the hit test path for this mouse event transition to \a path. If a valid path has been set, the transition will only trigger if the mouse event position (QMouseEvent::pos()) is inside the path. \sa QPainterPath::contains() */ -void QMouseEventTransition::setPath(const QPainterPath &path) +void QMouseEventTransition::setHitTestPath(const QPainterPath &path) { Q_D(QMouseEventTransition); - d->transition->setPath(path); + d->transition->setHitTestPath(path); } /*! diff --git a/src/gui/statemachine/qmouseeventtransition.h b/src/gui/statemachine/qmouseeventtransition.h index a6687b6..e7f6a45 100644 --- a/src/gui/statemachine/qmouseeventtransition.h +++ b/src/gui/statemachine/qmouseeventtransition.h @@ -71,8 +71,8 @@ public: Qt::KeyboardModifiers modifierMask() const; void setModifierMask(Qt::KeyboardModifiers modifiers); - QPainterPath path() const; - void setPath(const QPainterPath &path); + QPainterPath hitTestPath() const; + void setHitTestPath(const QPainterPath &path); protected: void onTransition(QEvent *event); -- cgit v0.12 From ddd1c40712a6a50b0574341087118fe4db67c3b2 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 3 Nov 2009 14:19:41 +0100 Subject: Rename QState::polished() signal to "propertiesAssigned" "Polished" was never a very descriptive word, and it already has a meaning attached in the QStyle API. Additionally, "propertiesAssigned" has the benefit of giving the relation to the assignProperty() function as part of the name. Reviewed-by: Kent Hansen --- doc/src/examples/stickman.qdoc | 9 +++--- doc/src/frameworks-technologies/statemachine.qdoc | 10 +++---- doc/src/snippets/statemachine/main5.cpp | 2 +- examples/animation/stickman/lifecycle.cpp | 4 +-- src/corelib/statemachine/qstate.cpp | 16 +++++++---- src/corelib/statemachine/qstate.h | 2 +- src/corelib/statemachine/qstate_p.h | 2 +- src/corelib/statemachine/qstatemachine.cpp | 8 +++--- tests/auto/qstatemachine/tst_qstatemachine.cpp | 34 +++++++++++------------ 9 files changed, 47 insertions(+), 40 deletions(-) diff --git a/doc/src/examples/stickman.qdoc b/doc/src/examples/stickman.qdoc index e70c39b..c9e98d0 100644 --- a/doc/src/examples/stickman.qdoc +++ b/doc/src/examples/stickman.qdoc @@ -55,9 +55,9 @@ Animations are implemented as composite states. Each child state of the animation state represents a frame in the animation by setting the position of each joint in the stickman's skeleton to the positions defined for the particular frame. The frames are then bound together - with animated transitions that trigger on the source state's polished() signal. Thus, the - machine will enter the state representing the next frame in the animation immediately after it - has finished animating into the previous frame. + with animated transitions that trigger on the source state's propertiesAssigned() signal. Thus, + the machine will enter the state representing the next frame in the animation immediately after + it has finished animating into the previous frame. \image stickman-example1.png @@ -67,7 +67,8 @@ \snippet examples/animation/stickman/lifecycle.cpp 1 - The states are then bound together with signal transitions that listen to the polished() signal. + The states are then bound together with signal transitions that listen to the + propertiesAssigned() signal. \snippet examples/animation/stickman/lifecycle.cpp 2 diff --git a/doc/src/frameworks-technologies/statemachine.qdoc b/doc/src/frameworks-technologies/statemachine.qdoc index ac10314..708561d 100644 --- a/doc/src/frameworks-technologies/statemachine.qdoc +++ b/doc/src/frameworks-technologies/statemachine.qdoc @@ -501,9 +501,9 @@ message box will pop up before the geometry of the button has actually been set. To ensure that the message box does not pop up until the geometry actually reaches its final - value, we can use the state's polished() signal. The polished() signal will be emitted when the - the property is assigned its final value, whether this is done immediately or after the animation - has finished playing. + value, we can use the state's propertiesAssigned() signal. The propertiesAssigned() signal will be + emitted when the property is assigned its final value, whether this is done immediately or + after the animation has finished playing. \code \snippet doc/src/snippets/statemachine/main5.cpp 6 \endcode @@ -519,14 +519,14 @@ has been assigned the defined value. If the global restore policy is set to QStateMachine::RestoreProperties, the state will not emit - the polished() signal until these have been executed as well. + the propertiesAssigned() signal until these have been executed as well. \section1 What Happens If A State Is Exited Before The Animation Has Finished If a state has property assignments, and the transition into the state has animations for the properties, the state can potentially be exited before the properties have been assigned to the values defines by the state. This is true in particular when there are transitions out from the - state that do not depend on the state being polished, as described in the previous section. + state that do not depend on the propertiesAssigned signal, as described in the previous section. The State Machine API guarantees that a property assigned by the state machine either: \list diff --git a/doc/src/snippets/statemachine/main5.cpp b/doc/src/snippets/statemachine/main5.cpp index 346cbce..ff25b7b 100644 --- a/doc/src/snippets/statemachine/main5.cpp +++ b/doc/src/snippets/statemachine/main5.cpp @@ -145,7 +145,7 @@ int main(int argv, char **args) connect(s3, SIGNAL(entered()), messageBox, SLOT(exec())); s1->addTransition(button, SIGNAL(clicked()), s2); - s2->addTransition(s2, SIGNAL(polished()), s3); + s2->addTransition(s2, SIGNAL(propertiesAssigned()), s3); //![6] } diff --git a/examples/animation/stickman/lifecycle.cpp b/examples/animation/stickman/lifecycle.cpp index 250fb85..1b6f9cd 100644 --- a/examples/animation/stickman/lifecycle.cpp +++ b/examples/animation/stickman/lifecycle.cpp @@ -194,14 +194,14 @@ QState *LifeCycle::makeState(QState *parentState, const QString &animationFileNa topLevel->setInitialState(frameState); else //! [2] - previousState->addTransition(previousState, SIGNAL(polished()), frameState); + previousState->addTransition(previousState, SIGNAL(propertiesAssigned()), frameState); //! [2] previousState = frameState; } // Loop - previousState->addTransition(previousState, SIGNAL(polished()), topLevel->initialState()); + previousState->addTransition(previousState, SIGNAL(propertiesAssigned()), topLevel->initialState()); return topLevel; diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index ea20619..6d89248 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -139,10 +139,10 @@ void QStatePrivate::emitFinished() emit q->finished(); } -void QStatePrivate::emitPolished() +void QStatePrivate::emitPropertiesAssigned() { Q_Q(QState); - emit q->polished(); + emit q->propertiesAssigned(); } /*! @@ -228,7 +228,7 @@ QList QStatePrivate::transitions() const Instructs this state to set the property with the given \a name of the given \a object to the given \a value when the state is entered. - \sa polished() + \sa propertiesAssigned() */ void QState::assignProperty(QObject *object, const char *name, const QVariant &value) @@ -491,9 +491,15 @@ bool QState::event(QEvent *e) */ /*! - \fn QState::polished() + \fn QState::propertiesAssigned() - This signal is emitted when all properties have been assigned their final value. + This signal is emitted when all properties have been assigned their final value. If the state + assigns a value to one or more properties for which an animation exists (either set on the + transition or as a default animation on the state machine), then the signal will not be emitted + until all such animations have finished playing. + + If there are no relevant animations, or no property assignments defined for the state, then + the signal will be emitted immediately before the state is entered. \sa QState::assignProperty(), QAbstractTransition::addAnimation() */ diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h index 781382d..423f940 100644 --- a/src/corelib/statemachine/qstate.h +++ b/src/corelib/statemachine/qstate.h @@ -94,7 +94,7 @@ public: Q_SIGNALS: void finished(); - void polished(); + void propertiesAssigned(); protected: void onEntry(QEvent *event); diff --git a/src/corelib/statemachine/qstate_p.h b/src/corelib/statemachine/qstate_p.h index 34c8838..7fe6279 100644 --- a/src/corelib/statemachine/qstate_p.h +++ b/src/corelib/statemachine/qstate_p.h @@ -94,7 +94,7 @@ public: QList transitions() const; void emitFinished(); - void emitPolished(); + void emitPropertiesAssigned(); QAbstractState *errorState; QAbstractState *initialState; diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 0d07093..0648d14 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -807,7 +807,7 @@ void QStateMachinePrivate::applyProperties(const QList &tr if (anim->state() == QAbstractAnimation::Running) { // The animation is still running. This can happen if the // animation is a group, and one of its children just finished, - // and that caused a state to emit its polished() signal, and + // and that caused a state to emit its propertiesAssigned() signal, and // that triggered a transition in the machine. // Just stop the animation so it is correctly restarted again. anim->stop(); @@ -829,7 +829,7 @@ void QStateMachinePrivate::applyProperties(const QList &tr } } - // Emit polished signal for entered states that have no animated properties. + // Emit propertiesAssigned signal for entered states that have no animated properties. for (int i = 0; i < enteredStates.size(); ++i) { QState *s = qobject_cast(enteredStates.at(i)); if (s @@ -837,7 +837,7 @@ void QStateMachinePrivate::applyProperties(const QList &tr && !animationsForState.contains(s) #endif ) - QStatePrivate::get(s)->emitPolished(); + QStatePrivate::get(s)->emitPropertiesAssigned(); } } @@ -1100,7 +1100,7 @@ void QStateMachinePrivate::_q_animationFinished() animations.removeOne(anim); if (animations.isEmpty()) { animationsForState.erase(it); - QStatePrivate::get(qobject_cast(state))->emitPolished(); + QStatePrivate::get(qobject_cast(state))->emitPropertiesAssigned(); } } diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index fb6567a..9a2b2ed 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -184,7 +184,7 @@ private slots: void twoAnimatedTransitions(); void playAnimationTwice(); void nestedTargetStateForAnimation(); - void polishedSignalTransitionsReuseAnimationGroup(); + void propertiesAssignedSignalTransitionsReuseAnimationGroup(); void animatedGlobalRestoreProperty(); void specificTargetValueOfAnimation(); @@ -1319,9 +1319,9 @@ void tst_QStateMachine::assignProperty() QCOMPARE(s1->objectName(), QString::fromLatin1("foo")); { - QSignalSpy polishedSpy(s1, SIGNAL(polished())); + QSignalSpy propertiesAssignedSpy(s1, SIGNAL(propertiesAssigned())); machine.start(); - QTRY_COMPARE(polishedSpy.count(), 1); + QTRY_COMPARE(propertiesAssignedSpy.count(), 1); } // nested states @@ -1371,7 +1371,7 @@ void tst_QStateMachine::assignPropertyWithAnimation() QCOMPARE(trans->animations().size(), 1); QCOMPARE(trans->animations().at(0), (QAbstractAnimation*)&anim); QFinalState *s3 = new QFinalState(&machine); - s2->addTransition(s2, SIGNAL(polished()), s3); + s2->addTransition(s2, SIGNAL(propertiesAssigned()), s3); machine.setInitialState(s1); QSignalSpy finishedSpy(&machine, SIGNAL(finished())); @@ -1399,7 +1399,7 @@ void tst_QStateMachine::assignPropertyWithAnimation() anim2.setDuration(150); trans->addAnimation(&anim2); QFinalState *s3 = new QFinalState(&machine); - s2->addTransition(s2, SIGNAL(polished()), s3); + s2->addTransition(s2, SIGNAL(propertiesAssigned()), s3); machine.setInitialState(s1); QSignalSpy finishedSpy(&machine, SIGNAL(finished())); @@ -1427,7 +1427,7 @@ void tst_QStateMachine::assignPropertyWithAnimation() group.addAnimation(new QPropertyAnimation(&obj, "bar")); trans->addAnimation(&group); QFinalState *s3 = new QFinalState(&machine); - s2->addTransition(s2, SIGNAL(polished()), s3); + s2->addTransition(s2, SIGNAL(propertiesAssigned()), s3); machine.setInitialState(s1); QSignalSpy finishedSpy(&machine, SIGNAL(finished())); @@ -1473,10 +1473,10 @@ void tst_QStateMachine::assignPropertyWithAnimation() anim2.setDuration(250); trans->addAnimation(&anim2); - s21->addTransition(s21, SIGNAL(polished()), s22); + s21->addTransition(s21, SIGNAL(propertiesAssigned()), s22); QFinalState *s3 = new QFinalState(&machine); - s22->addTransition(s2, SIGNAL(polished()), s3); + s22->addTransition(s2, SIGNAL(propertiesAssigned()), s3); machine.setInitialState(s1); QSignalSpy finishedSpy(&machine, SIGNAL(finished())); @@ -1513,13 +1513,13 @@ void tst_QStateMachine::assignPropertyWithAnimation() machine.setInitialState(group); machine.start(); QTRY_COMPARE(machine.configuration().contains(s1), true); - QSignalSpy polishedSpy(s2, SIGNAL(polished())); + QSignalSpy propertiesAssignedSpy(s2, SIGNAL(propertiesAssigned())); emitter.emitSignalWithNoArg(); QTRY_COMPARE(machine.configuration().contains(s2), true); - QVERIFY(polishedSpy.isEmpty()); + QVERIFY(propertiesAssignedSpy.isEmpty()); emitter.emitSignalWithNoArg(); // will cause animations from s1-->s2 to abort QTRY_COMPARE(machine.configuration().contains(s3), true); - QVERIFY(polishedSpy.isEmpty()); + QVERIFY(propertiesAssignedSpy.isEmpty()); QCOMPARE(obj.property("foo").toInt(), 911); QCOMPARE(obj.property("bar").toInt(), 789); } @@ -3089,7 +3089,7 @@ void tst_QStateMachine::twoAnimations() QState *s3 = new QState(&machine); QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); - s2->addTransition(s2, SIGNAL(polished()), s3); + s2->addTransition(s2, SIGNAL(propertiesAssigned()), s3); machine.setInitialState(s1); machine.start(); @@ -3241,7 +3241,7 @@ void tst_QStateMachine::nestedTargetStateForAnimation() at->addAnimation(animation); QState *s3 = new QState(&machine); - s2->addTransition(s2Child, SIGNAL(polished()), s3); + s2->addTransition(s2Child, SIGNAL(propertiesAssigned()), s3); QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit())); @@ -3258,7 +3258,7 @@ void tst_QStateMachine::nestedTargetStateForAnimation() QCOMPARE(counter.counter, 2); } -void tst_QStateMachine::polishedSignalTransitionsReuseAnimationGroup() +void tst_QStateMachine::propertiesAssignedSignalTransitionsReuseAnimationGroup() { QStateMachine machine; QObject *object = new QObject(&machine); @@ -3275,9 +3275,9 @@ void tst_QStateMachine::polishedSignalTransitionsReuseAnimationGroup() QParallelAnimationGroup animationGroup; animationGroup.addAnimation(new QPropertyAnimation(object, "foo")); QSignalSpy animationFinishedSpy(&animationGroup, SIGNAL(finished())); - s1->addTransition(s1, SIGNAL(polished()), s2)->addAnimation(&animationGroup); - s2->addTransition(s2, SIGNAL(polished()), s3)->addAnimation(&animationGroup); - s3->addTransition(s3, SIGNAL(polished()), s4); + s1->addTransition(s1, SIGNAL(propertiesAssigned()), s2)->addAnimation(&animationGroup); + s2->addTransition(s2, SIGNAL(propertiesAssigned()), s3)->addAnimation(&animationGroup); + s3->addTransition(s3, SIGNAL(propertiesAssigned()), s4); machine.setInitialState(s1); QSignalSpy machineFinishedSpy(&machine, SIGNAL(finished())); -- cgit v0.12 From edc9acd6a0c082b7d6c7810700e77a9d990014c6 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Tue, 3 Nov 2009 17:41:52 +0100 Subject: Fixed QPainterPath::addRoundedRect() for paths with Qt::WindingFill. QPainterPath::addRoundRect()/addRoundedRect() added the path in counter-clockwise order, while other methods added paths in clockwise order. For Qt::OddEvenFill, the order doesn't matter, but it matters for Qt::WindingFill. Fixed by adding rounded rects in clockwise order like the other shapes. Task-number: QTBUG-1537 Reviewed-by: Trond --- src/gui/painting/qpainterpath.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index c40bcee..8133793 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -3037,11 +3037,11 @@ void QPainterPath::addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadi bool first = d_func()->elements.size() < 2; - arcMoveTo(x, y, rxx2, ryy2, 90); - arcTo(x, y, rxx2, ryy2, 90, 90); - arcTo(x, y+h-ryy2, rxx2, ryy2, 2*90, 90); - arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*90, 90); - arcTo(x+w-rxx2, y, rxx2, ryy2, 0, 90); + arcMoveTo(x, y, rxx2, ryy2, 180); + arcTo(x, y, rxx2, ryy2, 180, -90); + arcTo(x+w-rxx2, y, rxx2, ryy2, 90, -90); + arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 0, -90); + arcTo(x, y+h-ryy2, rxx2, ryy2, 270, -90); closeSubpath(); d_func()->require_moveTo = true; @@ -3094,11 +3094,11 @@ void QPainterPath::addRoundRect(const QRectF &r, int xRnd, int yRnd) bool first = d_func()->elements.size() < 2; - arcMoveTo(x, y, rxx2, ryy2, 90); - arcTo(x, y, rxx2, ryy2, 90, 90); - arcTo(x, y+h-ryy2, rxx2, ryy2, 2*90, 90); - arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*90, 90); - arcTo(x+w-rxx2, y, rxx2, ryy2, 0, 90); + arcMoveTo(x, y, rxx2, ryy2, 180); + arcTo(x, y, rxx2, ryy2, 180, -90); + arcTo(x+w-rxx2, y, rxx2, ryy2, 90, -90); + arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 0, -90); + arcTo(x, y+h-ryy2, rxx2, ryy2, 270, -90); closeSubpath(); d_func()->require_moveTo = true; -- cgit v0.12 From 79c6049ccaae4434add40d35b3e47a83ff4a102a Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Wed, 4 Nov 2009 10:56:40 +1000 Subject: Incorporate API review feedback for math3d classes. Reviewed-by: Sarah Smith --- demos/boxes/scene.cpp | 2 +- demos/boxes/trackball.cpp | 4 +- src/gui/math3d/qgenericmatrix.cpp | 106 ++++++++++++- src/gui/math3d/qgenericmatrix.h | 37 ++++- src/gui/math3d/qmatrix4x4.cpp | 134 +++------------- src/gui/math3d/qmatrix4x4.h | 15 +- src/gui/math3d/qquaternion.cpp | 4 +- src/gui/math3d/qquaternion.h | 2 +- .../qgraphicstransform/tst_qgraphicstransform.cpp | 6 +- tests/auto/qmatrixnxn/tst_qmatrixnxn.cpp | 168 +++------------------ tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp | 4 +- 11 files changed, 197 insertions(+), 285 deletions(-) diff --git a/demos/boxes/scene.cpp b/demos/boxes/scene.cpp index 2b75f19..a06e8a1 100644 --- a/demos/boxes/scene.cpp +++ b/demos/boxes/scene.cpp @@ -870,7 +870,7 @@ void Scene::renderCubemaps() float angle = 2.0f * PI * i / m_cubemaps.size(); - center = m_trackBalls[1].rotation().rotateVector(QVector3D(cos(angle), sin(angle), 0.0f)); + center = m_trackBalls[1].rotation().rotatedVector(QVector3D(cos(angle), sin(angle), 0.0f)); for (int face = 0; face < 6; ++face) { m_cubemaps[i]->begin(face); diff --git a/demos/boxes/trackball.cpp b/demos/boxes/trackball.cpp index 2b1b2e4..76324e6 100644 --- a/demos/boxes/trackball.cpp +++ b/demos/boxes/trackball.cpp @@ -93,7 +93,7 @@ void TrackBall::move(const QPointF& p, const QQuaternion &transformation) QLineF delta(m_lastPos, p); m_angularVelocity = 180*delta.length() / (PI*msecs); m_axis = QVector3D(-delta.dy(), delta.dx(), 0.0f).normalized(); - m_axis = transformation.rotateVector(m_axis); + m_axis = transformation.rotatedVector(m_axis); m_rotation = QQuaternion::fromAxisAndAngle(m_axis, 180 / PI * delta.length()) * m_rotation; } break; @@ -118,7 +118,7 @@ void TrackBall::move(const QPointF& p, const QQuaternion &transformation) m_angularVelocity = angle / msecs; m_axis.normalize(); - m_axis = transformation.rotateVector(m_axis); + m_axis = transformation.rotatedVector(m_axis); m_rotation = QQuaternion::fromAxisAndAngle(m_axis, angle) * m_rotation; } break; diff --git a/src/gui/math3d/qgenericmatrix.cpp b/src/gui/math3d/qgenericmatrix.cpp index d211229..aa98536 100644 --- a/src/gui/math3d/qgenericmatrix.cpp +++ b/src/gui/math3d/qgenericmatrix.cpp @@ -80,7 +80,7 @@ QT_BEGIN_NAMESPACE The contents of the array \a values is assumed to be in row-major order. - \sa toValueArray() + \sa copyDataTo() */ /*! @@ -102,11 +102,11 @@ QT_BEGIN_NAMESPACE Returns true if this matrix is the identity; false otherwise. - \sa setIdentity() + \sa setToIdentity() */ /*! - \fn void QGenericMatrix::setIdentity() + \fn void QGenericMatrix::setToIdentity() Sets this matrix to the identity. @@ -213,9 +213,9 @@ QT_BEGIN_NAMESPACE */ /*! - \fn void QGenericMatrix::toValueArray(T *values) + \fn void QGenericMatrix::copyDataTo(T *values) const - Retrieves the N * M items in this matrix and writes them to \a values + Retrieves the N * M items in this matrix and copies them to \a values in row-major order. */ @@ -243,4 +243,100 @@ QT_BEGIN_NAMESPACE \sa data() */ +#ifndef QT_NO_DATASTREAM + +/*! + \fn QDataStream &operator<<(QDataStream &stream, const QGenericMatrix &matrix) + \relates QGenericMatrix + + Writes the given \a matrix to the given \a stream and returns a + reference to the stream. + + \sa {Format of the QDataStream Operators} +*/ + +/*! + \fn QDataStream &operator>>(QDataStream &stream, QGenericMatrix &matrix) + \relates QGenericMatrix + + Reads a NxM matrix from the given \a stream into the given \a matrix + and returns a reference to the stream. + + \sa {Format of the QDataStream Operators} +*/ + +#endif + +/*! + \typedef QMatrix2x2 + \relates QGenericMatrix + + The QMatrix2x2 type defines a convenient instantiation of the + QGenericMatrix template for 2 columns, 2 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix2x3 + \relates QGenericMatrix + + The QMatrix2x3 type defines a convenient instantiation of the + QGenericMatrix template for 2 columns, 3 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix2x4 + \relates QGenericMatrix + + The QMatrix2x4 type defines a convenient instantiation of the + QGenericMatrix template for 2 columns, 4 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix3x2 + \relates QGenericMatrix + + The QMatrix3x2 type defines a convenient instantiation of the + QGenericMatrix template for 3 columns, 2 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix3x3 + \relates QGenericMatrix + + The QMatrix3x3 type defines a convenient instantiation of the + QGenericMatrix template for 3 columns, 3 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix3x4 + \relates QGenericMatrix + + The QMatrix3x4 type defines a convenient instantiation of the + QGenericMatrix template for 3 columns, 4 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix4x2 + \relates QGenericMatrix + + The QMatrix4x2 type defines a convenient instantiation of the + QGenericMatrix template for 4 columns, 2 rows, and qreal as + the element type. +*/ + +/*! + \typedef QMatrix4x3 + \relates QGenericMatrix + + The QMatrix4x3 type defines a convenient instantiation of the + QGenericMatrix template for 4 columns, 3 rows, and qreal as + the element type. +*/ + QT_END_NAMESPACE diff --git a/src/gui/math3d/qgenericmatrix.h b/src/gui/math3d/qgenericmatrix.h index f178d02..3871754 100644 --- a/src/gui/math3d/qgenericmatrix.h +++ b/src/gui/math3d/qgenericmatrix.h @@ -44,6 +44,7 @@ #include #include +#include QT_BEGIN_HEADER @@ -63,7 +64,7 @@ public: T& operator()(int row, int column); bool isIdentity() const; - void setIdentity(); + void setToIdentity(); void fill(T value); @@ -76,7 +77,7 @@ public: bool operator==(const QGenericMatrix& other) const; bool operator!=(const QGenericMatrix& other) const; - void toValueArray(T *values); + void copyDataTo(T *values) const; T *data() { return m[0]; } const T *data() const { return m[0]; } @@ -113,7 +114,7 @@ private: template Q_INLINE_TEMPLATE QGenericMatrix::QGenericMatrix() { - setIdentity(); + setToIdentity(); } template @@ -164,7 +165,7 @@ Q_OUTOFLINE_TEMPLATE bool QGenericMatrix::isIdentity() const } template -Q_OUTOFLINE_TEMPLATE void QGenericMatrix::setIdentity() +Q_OUTOFLINE_TEMPLATE void QGenericMatrix::setToIdentity() { for (int col = 0; col < N; ++col) { for (int row = 0; row < M; ++row) { @@ -316,7 +317,7 @@ Q_OUTOFLINE_TEMPLATE QGenericMatrix operator/(const QGenericMatrix -Q_OUTOFLINE_TEMPLATE void QGenericMatrix::toValueArray(T *values) +Q_OUTOFLINE_TEMPLATE void QGenericMatrix::copyDataTo(T *values) const { for (int col = 0; col < N; ++col) for (int row = 0; row < M; ++row) @@ -352,6 +353,32 @@ QDebug operator<<(QDebug dbg, const QGenericMatrix &m) #endif +#ifndef QT_NO_DATASTREAM + +template +QDataStream &operator<<(QDataStream &stream, const QGenericMatrix &matrix) +{ + for (int row = 0; row < M; ++row) + for (int col = 0; col < N; ++col) + stream << double(matrix(row, col)); + return stream; +} + +template +QDataStream &operator>>(QDataStream &stream, QGenericMatrix &matrix) +{ + double x; + for (int row = 0; row < M; ++row) { + for (int col = 0; col < N; ++col) { + stream >> x; + matrix(row, col) = T(x); + } + } + return stream; +} + +#endif + QT_END_NAMESPACE Q_DECLARE_METATYPE(QMatrix2x2) diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index 5d624d8..ef2e4ab 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -73,10 +73,10 @@ static const qreal inv_dist_to_plane = 1. / 1024.; If the matrix has a special type (identity, translate, scale, etc), the programmer should follow this constructor with a call to - inferSpecialType() if they wish QMatrix4x4 to optimize further + optimize() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc. - \sa toValueArray(), inferSpecialType() + \sa copyDataTo(), optimize() */ QMatrix4x4::QMatrix4x4(const qreal *values) { @@ -96,10 +96,10 @@ QMatrix4x4::QMatrix4x4(const qreal *values) If the matrix has a special type (identity, translate, scale, etc), the programmer should follow this constructor with a call to - inferSpecialType() if they wish QMatrix4x4 to optimize further + optimize() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc. - \sa inferSpecialType() + \sa optimize() */ #if !defined(QT_NO_MEMBER_TEMPLATES) || defined(Q_QDOC) @@ -176,10 +176,10 @@ QMatrix4x4::QMatrix4x4(const qreal *values, int cols, int rows) If \a matrix has a special type (identity, translate, scale, etc), the programmer should follow this constructor with a call to - inferSpecialType() if they wish QMatrix4x4 to optimize further + optimize() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc. - \sa toAffine(), inferSpecialType() + \sa toAffine(), optimize() */ QMatrix4x4::QMatrix4x4(const QMatrix& matrix) { @@ -208,10 +208,10 @@ QMatrix4x4::QMatrix4x4(const QMatrix& matrix) If \a transform has a special type (identity, translate, scale, etc), the programmer should follow this constructor with a call to - inferSpecialType() if they wish QMatrix4x4 to optimize further + optimize() if they wish QMatrix4x4 to optimize further calls to translate(), scale(), etc. - \sa toTransform(), inferSpecialType() + \sa toTransform(), optimize() */ QMatrix4x4::QMatrix4x4(const QTransform& transform) { @@ -249,7 +249,7 @@ QMatrix4x4::QMatrix4x4(const QTransform& transform) Returns a reference to the element at position (\a row, \a column) in this matrix so that the element can be assigned to. - \sa inferSpecialType(), setColumn(), setRow() + \sa optimize(), setColumn(), setRow() */ /*! @@ -289,11 +289,11 @@ QMatrix4x4::QMatrix4x4(const QTransform& transform) Returns true if this matrix is the identity; false otherwise. - \sa setIdentity() + \sa setToIdentity() */ /*! - \fn void QMatrix4x4::setIdentity() + \fn void QMatrix4x4::setToIdentity() Sets this matrix to the identity. @@ -1027,7 +1027,7 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) if (y == 0.0f) { if (z != 0.0f) { // Rotate around the Z axis. - m.setIdentity(); + m.setToIdentity(); m.m[0][0] = c; m.m[1][1] = c; if (z < 0.0f) { @@ -1042,7 +1042,7 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) } } else if (z == 0.0f) { // Rotate around the Y axis. - m.setIdentity(); + m.setToIdentity(); m.m[0][0] = c; m.m[2][2] = c; if (y < 0.0f) { @@ -1057,7 +1057,7 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) } } else if (y == 0.0f && z == 0.0f) { // Rotate around the X axis. - m.setIdentity(); + m.setToIdentity(); m.m[1][1] = c; m.m[2][2] = c; if (x < 0.0f) { @@ -1135,7 +1135,7 @@ QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) if (y == 0.0f) { if (z != 0.0f) { // Rotate around the Z axis. - m.setIdentity(); + m.setToIdentity(); m.m[0][0] = c; m.m[1][1] = c; if (z < 0.0f) { @@ -1150,7 +1150,7 @@ QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) } } else if (z == 0.0f) { // Rotate around the Y axis. - m.setIdentity(); + m.setToIdentity(); m.m[0][0] = c; m.m[2][2] = 1.0f; if (y < 0.0f) { @@ -1163,7 +1163,7 @@ QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) } } else if (y == 0.0f && z == 0.0f) { // Rotate around the X axis. - m.setIdentity(); + m.setToIdentity(); m.m[1][1] = c; m.m[2][2] = 1.0f; if (x < 0.0f) { @@ -1512,10 +1512,10 @@ QMatrix4x4& QMatrix4x4::flipCoordinates() } /*! - Retrieves the 16 items in this matrix and writes them to \a values + Retrieves the 16 items in this matrix and copies them to \a values in row-major order. */ -void QMatrix4x4::toValueArray(qreal *values) const +void QMatrix4x4::copyDataTo(qreal *values) const { for (int row = 0; row < 4; ++row) for (int col = 0; col < 4; ++col) @@ -1739,7 +1739,7 @@ QRectF QMatrix4x4::mapRect(const QRectF& rect) const Returns a pointer to the raw data of this matrix. - \sa constData(), inferSpecialType() + \sa constData(), optimize() */ /*! @@ -1788,94 +1788,8 @@ QMatrix4x4 QMatrix4x4::orthonormalInverse() const return result; } -#ifndef QT_NO_VECTOR3D -/*! - Decomposes the current rotation matrix into an \a axis of rotation plus - an \a angle. The result can be used to construct an equivalent rotation - matrix using glRotate(). It is assumed that the homogenous coordinate - is 1.0. The returned vector is guaranteed to be normalized. - - \code - qreal angle; - QVector3D axis; - - matrix.extractAxisAngle(angle, axis); - glRotate(angle, axis[0], axis[1], axis[2]); - \endcode - - \sa rotate() -*/ -void QMatrix4x4::extractAxisRotation(qreal &angle, QVector3D &axis) const -{ - // Orientation is dependent on the upper 3x3 matrix; subtract the - // homogeneous scaling element from the trace of the 4x4 matrix - qreal tr = m[0][0] + m[1][1] + m[2][2]; - qreal cosa = qreal(0.5f * (tr - 1.0f)); - angle = acos(cosa) * 180.0f / M_PI; - - // Any axis will work if r is zero (means no rotation) - if (qFuzzyIsNull(angle)) { - axis.setX(1.0f); - axis.setY(0.0f); - axis.setZ(0.0f); - return; - } - - if (angle < 180.0f) { - axis.setX(m[1][2] - m[2][1]); - axis.setY(m[2][0] - m[0][2]); - axis.setZ(m[0][1] - m[1][0]); - axis.normalize(); - return; - } - - // rads == PI - qreal tmp; - - // r00 is maximum - if ((m[0][0] >= m[2][2]) && (m[0][0] >= m[1][1])) { - axis.setX(0.5f * qSqrt(m[0][0] - m[1][1] - m[2][2] + 1.0f)); - tmp = 0.5f / axis.x(); - axis.setY(m[1][0] * tmp); - axis.setZ(m[2][0] * tmp); - } - - // r11 is maximum - if ((m[1][1] >= m[2][2]) && (m[1][1] >= m[0][0])) { - axis.setY(0.5f * qSqrt(m[1][1] - m[0][0] - m[2][2] + 1.0f)); - tmp = 0.5f / axis.y(); - axis.setX(tmp * m[1][0]); - axis.setZ(tmp * m[2][1]); - } - - // r22 is maximum - if ((m[2][2] >= m[1][1]) && (m[2][2] >= m[0][0])) { - axis.setZ(0.5f * qSqrt(m[2][2] - m[0][0] - m[1][1] + 1.0f)); - tmp = 0.5f / axis.z(); - axis.setX(m[2][0]*tmp); - axis.setY(m[2][1]*tmp); - } -} - -/*! - If this is an orthonormal transformation matrix (e.g. only rotations and - translations have been applied to the matrix, no scaling, or shearing) - then the world translational component can be obtained by calling this function. - - This is most useful for camera matrices, where the negation of this vector - is effectively the camera world coordinates. -*/ -QVector3D QMatrix4x4::extractTranslation() const -{ - return QVector3D - (m[0][0] * m[3][0] + m[0][1] * m[3][1] + m[0][2] * m[3][2], - m[1][0] * m[3][0] + m[1][1] * m[3][1] + m[1][2] * m[3][2], - m[2][0] * m[3][0] + m[2][1] * m[3][1] + m[2][2] * m[3][2]); -} -#endif - /*! - Infers the special type of this matrix from its current elements. + Optimize the usage of this matrix from its current elements. Some operations such as translate(), scale(), and rotate() can be performed more efficiently if the matrix being modified is already @@ -1888,13 +1802,13 @@ QVector3D QMatrix4x4::extractTranslation() const the special type and will revert to the safest but least efficient operations thereafter. - By calling inferSpecialType() after directly modifying the matrix, + By calling optimize() after directly modifying the matrix, the programmer can force QMatrix4x4 to recover the special type if the elements appear to conform to one of the known optimized types. \sa operator()(), data(), translate() */ -void QMatrix4x4::inferSpecialType() +void QMatrix4x4::optimize() { // If the last element is not 1, then it can never be special. if (m[3][3] != 1.0f) { @@ -2011,7 +1925,7 @@ QDataStream &operator>>(QDataStream &stream, QMatrix4x4 &matrix) matrix(row, col) = qreal(x); } } - matrix.inferSpecialType(); + matrix.optimize(); return stream; } diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h index ba74b89..daebf9d 100644 --- a/src/gui/math3d/qmatrix4x4.h +++ b/src/gui/math3d/qmatrix4x4.h @@ -63,7 +63,7 @@ class QVariant; class Q_GUI_EXPORT QMatrix4x4 { public: - inline QMatrix4x4() { setIdentity(); } + inline QMatrix4x4() { setToIdentity(); } explicit QMatrix4x4(const qreal *values); inline QMatrix4x4(qreal m11, qreal m12, qreal m13, qreal m14, qreal m21, qreal m22, qreal m23, qreal m24, @@ -87,7 +87,7 @@ public: inline void setRow(int index, const QVector4D& value); inline bool isIdentity() const; - inline void setIdentity(); + inline void setToIdentity(); inline void fill(qreal value); @@ -141,11 +141,6 @@ public: QMatrix4x4& rotate(const QQuaternion& quaternion); #endif -#ifndef QT_NO_VECTOR3D - void extractAxisRotation(qreal &angle, QVector3D &axis) const; - QVector3D extractTranslation() const; -#endif - QMatrix4x4& ortho(const QRect& rect); QMatrix4x4& ortho(const QRectF& rect); QMatrix4x4& ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane); @@ -156,7 +151,7 @@ public: #endif QMatrix4x4& flipCoordinates(); - void toValueArray(qreal *values) const; + void copyDataTo(qreal *values) const; QMatrix toAffine() const; QTransform toTransform() const; @@ -183,7 +178,7 @@ public: inline const qreal *data() const { return m[0]; } inline const qreal *constData() const { return m[0]; } - void inferSpecialType(); + void optimize(); operator QVariant() const; @@ -330,7 +325,7 @@ inline bool QMatrix4x4::isIdentity() const return (m[3][3] == 1.0f); } -inline void QMatrix4x4::setIdentity() +inline void QMatrix4x4::setToIdentity() { m[0][0] = 1.0f; m[0][1] = 0.0f; diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp index d5ec054..626cb3c 100644 --- a/src/gui/math3d/qquaternion.cpp +++ b/src/gui/math3d/qquaternion.cpp @@ -288,7 +288,7 @@ void QQuaternion::normalize() in 3D space. The following code: \code - QVector3D result = q.rotateVector(vector); + QVector3D result = q.rotatedVector(vector); \endcode is equivalent to the following: @@ -297,7 +297,7 @@ void QQuaternion::normalize() QVector3D result = (q * QQuaternion(0, vector) * q.conjugate()).vector(); \endcode */ -QVector3D QQuaternion::rotateVector(const QVector3D& vector) const +QVector3D QQuaternion::rotatedVector(const QVector3D& vector) const { return (*this * QQuaternion(0, vector) * conjugate()).vector(); } diff --git a/src/gui/math3d/qquaternion.h b/src/gui/math3d/qquaternion.h index 7480a5c..5b2454f 100644 --- a/src/gui/math3d/qquaternion.h +++ b/src/gui/math3d/qquaternion.h @@ -95,7 +95,7 @@ public: QQuaternion conjugate() const; - QVector3D rotateVector(const QVector3D& vector) const; + QVector3D rotatedVector(const QVector3D& vector) const; QQuaternion &operator+=(const QQuaternion &quaternion); QQuaternion &operator-=(const QQuaternion &quaternion); diff --git a/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp b/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp index d8ab06e..9b15ab1 100644 --- a/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp +++ b/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp @@ -259,7 +259,7 @@ void tst_QGraphicsTransform::rotation3d() // Check that "rotation" produces the 4x4 form of the 3x3 matrix. // i.e. third row and column are 0 0 1 0. - t.setIdentity(); + t.setToIdentity(); rotation.applyTo(&t); QMatrix4x4 r(expected); if (sizeof(qreal) == sizeof(float) && angle == 268) { @@ -274,7 +274,7 @@ void tst_QGraphicsTransform::rotation3d() rotation.setAxis(QVector3D(0, 0, 0)); rotation.setOrigin(QVector3D(10, 10, 0)); - t.setIdentity(); + t.setToIdentity(); rotation.applyTo(&t); QVERIFY(t.isIdentity()); @@ -337,7 +337,7 @@ void tst_QGraphicsTransform::rotation3dArbitraryAxis() // Check that "rotation" produces the 4x4 form of the 3x3 matrix. // i.e. third row and column are 0 0 1 0. - t.setIdentity(); + t.setToIdentity(); rotation.applyTo(&t); QMatrix4x4 r(expected); QVERIFY(qFuzzyCompare(t, r)); diff --git a/tests/auto/qmatrixnxn/tst_qmatrixnxn.cpp b/tests/auto/qmatrixnxn/tst_qmatrixnxn.cpp index ff5e00f..d6d217f2 100644 --- a/tests/auto/qmatrixnxn/tst_qmatrixnxn.cpp +++ b/tests/auto/qmatrixnxn/tst_qmatrixnxn.cpp @@ -151,14 +151,8 @@ private slots: void convertGeneric(); - void extractAxisRotation_data(); - void extractAxisRotation(); - - void extractTranslation_data(); - void extractTranslation(); - - void inferSpecialType_data(); - void inferSpecialType(); + void optimize_data(); + void optimize(); void columnsAndRows(); @@ -515,13 +509,13 @@ void tst_QMatrixNxN::create2x2() m5 = m3; QVERIFY(isSame(m5, uniqueValues2)); - m5.setIdentity(); + m5.setToIdentity(); QVERIFY(isIdentity(m5)); QMatrix2x2 m6(uniqueValues2); QVERIFY(isSame(m6, uniqueValues2)); qreal vals[4]; - m6.toValueArray(vals); + m6.copyDataTo(vals); for (int index = 0; index < 4; ++index) QCOMPARE(vals[index], uniqueValues2[index]); } @@ -550,13 +544,13 @@ void tst_QMatrixNxN::create3x3() m5 = m3; QVERIFY(isSame(m5, uniqueValues3)); - m5.setIdentity(); + m5.setToIdentity(); QVERIFY(isIdentity(m5)); QMatrix3x3 m6(uniqueValues3); QVERIFY(isSame(m6, uniqueValues3)); qreal vals[9]; - m6.toValueArray(vals); + m6.copyDataTo(vals); for (int index = 0; index < 9; ++index) QCOMPARE(vals[index], uniqueValues3[index]); } @@ -585,13 +579,13 @@ void tst_QMatrixNxN::create4x4() m5 = m3; QVERIFY(isSame(m5, uniqueValues4)); - m5.setIdentity(); + m5.setToIdentity(); QVERIFY(isIdentity(m5)); QMatrix4x4 m6(uniqueValues4); QVERIFY(isSame(m6, uniqueValues4)); qreal vals[16]; - m6.toValueArray(vals); + m6.copyDataTo(vals); for (int index = 0; index < 16; ++index) QCOMPARE(vals[index], uniqueValues4[index]); @@ -627,13 +621,13 @@ void tst_QMatrixNxN::create4x3() m5 = m3; QVERIFY(isSame(m5, uniqueValues4x3)); - m5.setIdentity(); + m5.setToIdentity(); QVERIFY(isIdentity(m5)); QMatrix4x3 m6(uniqueValues4x3); QVERIFY(isSame(m6, uniqueValues4x3)); qreal vals[12]; - m6.toValueArray(vals); + m6.copyDataTo(vals); for (int index = 0; index < 12; ++index) QCOMPARE(vals[index], uniqueValues4x3[index]); } @@ -802,7 +796,7 @@ void tst_QMatrixNxN::transposed4x3() QMatrix4x3 m3(uniqueValues4x3); QMatrix3x4 m4 = m3.transposed(); qreal values[12]; - m4.toValueArray(values); + m4.copyDataTo(values); for (int index = 0; index < 12; ++index) QCOMPARE(values[index], transposedValues3x4[index]); } @@ -1296,7 +1290,7 @@ void tst_QMatrixNxN::multiply4x3() QGenericMatrix<3, 3, qreal> m4; m4 = m1 * m2; qreal values[9]; - m4.toValueArray(values); + m4.copyDataTo(values); for (int index = 0; index < 9; ++index) QCOMPARE(values[index], ((const qreal *)m3Values)[index]); } @@ -1898,7 +1892,7 @@ void tst_QMatrixNxN::inverted4x4() } // Test again, after inferring the special matrix type. - m1.inferSpecialType(); + m1.optimize(); m2 = m1.inverted(&inv); QVERIFY(isSame(m2, (const qreal *)m2Values)); QCOMPARE(inv, invertible); @@ -1913,12 +1907,12 @@ void tst_QMatrixNxN::orthonormalInverse4x4() m2.rotate(45.0, 1.0, 0.0, 0.0); m2.translate(10.0, 0.0, 0.0); - // Use inferSpecialType() to drop the internal flags that + // Use optimize() to drop the internal flags that // mark the matrix as orthonormal. This will force inverted() // to compute m3.inverted() the long way. We can then compare // the result to what the faster algorithm produces on m2. QMatrix4x4 m3 = m2; - m3.inferSpecialType(); + m3.optimize(); bool invertible; QVERIFY(qFuzzyCompare(m2.inverted(&invertible), m3.inverted())); QVERIFY(invertible); @@ -1926,7 +1920,7 @@ void tst_QMatrixNxN::orthonormalInverse4x4() QMatrix4x4 m4; m4.rotate(45.0, 0.0, 1.0, 0.0); QMatrix4x4 m5 = m4; - m5.inferSpecialType(); + m5.optimize(); QVERIFY(qFuzzyCompare(m4.inverted(), m5.inverted())); QMatrix4x4 m6; @@ -1934,7 +1928,7 @@ void tst_QMatrixNxN::orthonormalInverse4x4() m1.translate(-20.0, 20.0, 15.0); m1.rotate(25, 1.0, 0.0, 0.0); QMatrix4x4 m7 = m6; - m7.inferSpecialType(); + m7.optimize(); QVERIFY(qFuzzyCompare(m6.inverted(), m7.inverted())); } @@ -2081,7 +2075,7 @@ void tst_QMatrixNxN::scale4x4() m8.scale(x); QVERIFY(isSame(m8, (const qreal *)resultValues)); - m8.inferSpecialType(); + m8.optimize(); m8.scale(1.0f); QVERIFY(isSame(m8, (const qreal *)resultValues)); @@ -2412,7 +2406,7 @@ void tst_QMatrixNxN::rotate4x4() if (x != 0 || y != 0 || z != 0) { QQuaternion q = QQuaternion::fromAxisAndAngle(QVector3D(x, y, z), angle); - QVector3D vq = q.rotateVector(v1); + QVector3D vq = q.rotatedVector(v1); QVERIFY(fuzzyCompare(vq.x(), v1x)); QVERIFY(fuzzyCompare(vq.y(), v1y)); QVERIFY(fuzzyCompare(vq.z(), v1z)); @@ -2509,7 +2503,7 @@ void tst_QMatrixNxN::normalMatrix() // Perform the test again, after inferring special matrix types. // This tests the optimized paths in the normalMatrix() function. - m1.inferSpecialType(); + m1.optimize(); n1 = m1.normalMatrix(); if (invertible) @@ -2850,120 +2844,6 @@ void tst_QMatrixNxN::convertGeneric() QVERIFY(isSame(m11, conv4x4)); } -void tst_QMatrixNxN::extractAxisRotation_data() -{ - QTest::addColumn("x"); - QTest::addColumn("y"); - QTest::addColumn("z"); - QTest::addColumn("angle"); - - QTest::newRow("1, 0, 0, 0 deg") << 1.0f << 0.0f << 0.0f << 0.0f; - QTest::newRow("1, 0, 0, 90 deg") << 1.0f << 0.0f << 0.0f << 90.0f; - QTest::newRow("1, 0, 0, 270 deg") << 1.0f << 0.0f << 0.0f << 270.0f; - QTest::newRow("1, 0, 0, 45 deg") << 1.0f << 0.0f << 0.0f << 45.0f; - QTest::newRow("1, 0, 0, 120 deg") << 1.0f << 0.0f << 0.0f << 120.0f; - QTest::newRow("1, 0, 0, 300 deg") << 1.0f << 0.0f << 0.0f << 300.0f; - - QTest::newRow("0, 1, 0, 90 deg") << 0.0f << 1.0f << 0.0f << 90.0f; - QTest::newRow("0, 1, 0, 270 deg") << 0.0f << 1.0f << 0.0f << 270.0f; - QTest::newRow("0, 1, 0, 45 deg") << 0.0f << 1.0f << 0.0f << 45.0f; - QTest::newRow("0, 1, 0, 120 deg") << 0.0f << 1.0f << 0.0f << 120.0f; - QTest::newRow("0, 1, 0, 300 deg") << 0.0f << 1.0f << 0.0f << 300.0f; - - QTest::newRow("0, 0, 1, 90 deg") << 0.0f << 0.0f << 1.0f << 90.0f; - QTest::newRow("0, 0, 1, 270 deg") << 0.0f << 0.0f << 1.0f << 270.0f; - QTest::newRow("0, 0, 1, 45 deg") << 0.0f << 0.0f << 1.0f << 45.0f; - QTest::newRow("0, 0, 1, 120 deg") << 0.0f << 0.0f << 1.0f << 120.0f; - QTest::newRow("0, 0, 1, 300 deg") << 0.0f << 0.0f << 1.0f << 300.0f; - - QTest::newRow("1, 1, 1, 90 deg") << 1.0f << 1.0f << 1.0f << 90.0f; - QTest::newRow("1, 1, 1, 270 deg") << 1.0f << 1.0f << 1.0f << 270.0f; - QTest::newRow("1, 1, 1, 45 deg") << 1.0f << 1.0f << 1.0f << 45.0f; - QTest::newRow("1, 1, 1, 120 deg") << 1.0f << 1.0f << 1.0f << 120.0f; - QTest::newRow("1, 1, 1, 300 deg") << 1.0f << 1.0f << 1.0f << 300.0f; -} - -void tst_QMatrixNxN::extractAxisRotation() -{ - QFETCH(float, x); - QFETCH(float, y); - QFETCH(float, z); - QFETCH(float, angle); - - QMatrix4x4 m; - QVector3D origAxis(x, y, z); - - m.rotate(angle, x, y, z); - - origAxis.normalize(); - QVector3D extractedAxis; - qreal extractedAngle; - - m.extractAxisRotation(extractedAngle, extractedAxis); - - if (angle > 180) { - QVERIFY(fuzzyCompare(360.0f - angle, extractedAngle)); - QVERIFY(fuzzyCompare(extractedAxis, -origAxis)); - } else { - QVERIFY(fuzzyCompare(angle, extractedAngle)); - QVERIFY(fuzzyCompare(extractedAxis, origAxis)); - } -} - -void tst_QMatrixNxN::extractTranslation_data() -{ - QTest::addColumn("rotation"); - QTest::addColumn("x"); - QTest::addColumn("y"); - QTest::addColumn("z"); - - static QMatrix4x4 m1; - - QTest::newRow("identity, 100, 50, 25") - << m1 << 100.0f << 50.0f << 250.0f; - - m1.rotate(45.0, 1.0, 0.0, 0.0); - QTest::newRow("rotX 45 + 100, 50, 25") << m1 << 100.0f << 50.0f << 25.0f; - - m1.setIdentity(); - m1.rotate(45.0, 0.0, 1.0, 0.0); - QTest::newRow("rotY 45 + 100, 50, 25") << m1 << 100.0f << 50.0f << 25.0f; - - m1.setIdentity(); - m1.rotate(75, 0.0, 0.0, 1.0); - m1.rotate(25, 1.0, 0.0, 0.0); - m1.rotate(45, 0.0, 1.0, 0.0); - QTest::newRow("rotZ 75, rotX 25, rotY 45, 100, 50, 25") << m1 << 100.0f << 50.0f << 25.0f; -} - -void tst_QMatrixNxN::extractTranslation() -{ - QFETCH(QMatrix4x4, rotation); - QFETCH(float, x); - QFETCH(float, y); - QFETCH(float, z); - - rotation.translate(x, y, z); - - QVector3D vec = rotation.extractTranslation(); - - QVERIFY(fuzzyCompare(vec.x(), x)); - QVERIFY(fuzzyCompare(vec.y(), y)); - QVERIFY(fuzzyCompare(vec.z(), z)); - - QMatrix4x4 lookAt; - QVector3D eye(1.5f, -2.5f, 2.5f); - lookAt.lookAt(eye, - QVector3D(10.0f, 10.0f, 10.0f), - QVector3D(0.0f, 1.0f, 0.0f)); - - QVector3D extEye = lookAt.extractTranslation(); - - QVERIFY(fuzzyCompare(eye.x(), -extEye.x())); - QVERIFY(fuzzyCompare(eye.y(), -extEye.y())); - QVERIFY(fuzzyCompare(eye.z(), -extEye.z())); -} - // Copy of "flagBits" in qmatrix4x4.h. enum { Identity = 0x0001, // Identity matrix @@ -2981,7 +2861,7 @@ struct Matrix4x4 }; // Test the inferring of special matrix types. -void tst_QMatrixNxN::inferSpecialType_data() +void tst_QMatrixNxN::optimize_data() { QTest::addColumn("mValues"); QTest::addColumn("flagBits"); @@ -3029,13 +2909,13 @@ void tst_QMatrixNxN::inferSpecialType_data() QTest::newRow("below") << (void *)belowValues << (int)General; } -void tst_QMatrixNxN::inferSpecialType() +void tst_QMatrixNxN::optimize() { QFETCH(void *, mValues); QFETCH(int, flagBits); QMatrix4x4 m((const qreal *)mValues); - m.inferSpecialType(); + m.optimize(); QCOMPARE(reinterpret_cast(&m)->flagBits, flagBits); } @@ -3362,7 +3242,7 @@ void tst_QMatrixNxN::mapVector() QFETCH(void *, mValues); QMatrix4x4 m1((const qreal *)mValues); - m1.inferSpecialType(); + m1.optimize(); QVector3D v(3.5f, -1.0f, 2.5f); diff --git a/tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp b/tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp index 71f45ff..f80b579 100644 --- a/tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp +++ b/tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp @@ -220,7 +220,7 @@ void tst_QMatrix4x4::mapVector3D() QVector3D v(10.5f, -2.0f, 3.0f); QVector3D result; - m1.inferSpecialType(); + m1.optimize(); QBENCHMARK { result = m1 * v; @@ -244,7 +244,7 @@ void tst_QMatrix4x4::mapVector2D() QPointF v(10.5f, -2.0f); QPointF result; - m1.inferSpecialType(); + m1.optimize(); QBENCHMARK { result = m1 * v; -- cgit v0.12 From ce14a4a0bc290018e597d0a4f8e9f279c63d4cc0 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Wed, 4 Nov 2009 13:31:37 +1000 Subject: Remove QMatrix4x4& return values in response to API review feedback Reviewed-by: Sarah Smith --- src/gui/math3d/qmatrix4x4.cpp | 103 +++++++++++++++-------------------- src/gui/math3d/qmatrix4x4.h | 36 ++++++------ tests/auto/qvariant/tst_qvariant.cpp | 6 +- 3 files changed, 65 insertions(+), 80 deletions(-) diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index ef2e4ab..2c3d616 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -694,11 +694,11 @@ QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor) /*! Multiplies this matrix by another that scales coordinates by - the components of \a vector. Returns this matrix. + the components of \a vector. \sa translate(), rotate() */ -QMatrix4x4& QMatrix4x4::scale(const QVector3D& vector) +void QMatrix4x4::scale(const QVector3D& vector) { qreal vx = vector.x(); qreal vy = vector.y(); @@ -732,7 +732,6 @@ QMatrix4x4& QMatrix4x4::scale(const QVector3D& vector) m[2][3] *= vz; flagBits = General; } - return *this; } #endif @@ -740,11 +739,11 @@ QMatrix4x4& QMatrix4x4::scale(const QVector3D& vector) \overload Multiplies this matrix by another that scales coordinates by the - components \a x, and \a y. Returns this matrix. + components \a x, and \a y. \sa translate(), rotate() */ -QMatrix4x4& QMatrix4x4::scale(qreal x, qreal y) +void QMatrix4x4::scale(qreal x, qreal y) { if (flagBits == Identity) { m[0][0] = x; @@ -768,18 +767,17 @@ QMatrix4x4& QMatrix4x4::scale(qreal x, qreal y) m[1][3] *= y; flagBits = General; } - return *this; } /*! \overload Multiplies this matrix by another that scales coordinates by the - components \a x, \a y, and \a z. Returns this matrix. + components \a x, \a y, and \a z. \sa translate(), rotate() */ -QMatrix4x4& QMatrix4x4::scale(qreal x, qreal y, qreal z) +void QMatrix4x4::scale(qreal x, qreal y, qreal z) { if (flagBits == Identity) { m[0][0] = x; @@ -810,18 +808,17 @@ QMatrix4x4& QMatrix4x4::scale(qreal x, qreal y, qreal z) m[2][3] *= z; flagBits = General; } - return *this; } /*! \overload Multiplies this matrix by another that scales coordinates by the - given \a factor. Returns this matrix. + given \a factor. \sa translate(), rotate() */ -QMatrix4x4& QMatrix4x4::scale(qreal factor) +void QMatrix4x4::scale(qreal factor) { if (flagBits == Identity) { m[0][0] = factor; @@ -852,17 +849,16 @@ QMatrix4x4& QMatrix4x4::scale(qreal factor) m[2][3] *= factor; flagBits = General; } - return *this; } #ifndef QT_NO_VECTOR3D /*! Multiplies this matrix by another that translates coordinates by - the components of \a vector. Returns this matrix. + the components of \a vector. \sa scale(), rotate() */ -QMatrix4x4& QMatrix4x4::translate(const QVector3D& vector) +void QMatrix4x4::translate(const QVector3D& vector) { qreal vx = vector.x(); qreal vy = vector.y(); @@ -895,7 +891,6 @@ QMatrix4x4& QMatrix4x4::translate(const QVector3D& vector) else if (flagBits != (Rotation | Translation)) flagBits = General; } - return *this; } #endif @@ -904,11 +899,11 @@ QMatrix4x4& QMatrix4x4::translate(const QVector3D& vector) \overload Multiplies this matrix by another that translates coordinates - by the components \a x, and \a y. Returns this matrix. + by the components \a x, and \a y. \sa scale(), rotate() */ -QMatrix4x4& QMatrix4x4::translate(qreal x, qreal y) +void QMatrix4x4::translate(qreal x, qreal y) { if (flagBits == Identity) { m[3][0] = x; @@ -935,18 +930,17 @@ QMatrix4x4& QMatrix4x4::translate(qreal x, qreal y) else if (flagBits != (Rotation | Translation)) flagBits = General; } - return *this; } /*! \overload Multiplies this matrix by another that translates coordinates - by the components \a x, \a y, and \a z. Returns this matrix. + by the components \a x, \a y, and \a z. \sa scale(), rotate() */ -QMatrix4x4& QMatrix4x4::translate(qreal x, qreal y, qreal z) +void QMatrix4x4::translate(qreal x, qreal y, qreal z) { if (flagBits == Identity) { m[3][0] = x; @@ -976,20 +970,19 @@ QMatrix4x4& QMatrix4x4::translate(qreal x, qreal y, qreal z) else if (flagBits != (Rotation | Translation)) flagBits = General; } - return *this; } #ifndef QT_NO_VECTOR3D /*! Multiples this matrix by another that rotates coordinates through - \a angle degrees about \a vector. Returns this matrix. + \a angle degrees about \a vector. \sa scale(), translate() */ -QMatrix4x4& QMatrix4x4::rotate(qreal angle, const QVector3D& vector) +void QMatrix4x4::rotate(qreal angle, const QVector3D& vector) { - return rotate(angle, vector.x(), vector.y(), vector.z()); + rotate(angle, vector.x(), vector.y(), vector.z()); } #endif @@ -998,14 +991,14 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, const QVector3D& vector) \overload Multiplies this matrix by another that rotates coordinates through - \a angle degrees about the vector (\a x, \a y, \a z). Returns this matrix. + \a angle degrees about the vector (\a x, \a y, \a z). \sa scale(), translate() */ -QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) +void QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) { if (angle == 0.0f) - return *this; + return; QMatrix4x4 m(1); // The "1" says to not load the identity. qreal c, s, ic; if (angle == 90.0f || angle == -270.0f) { @@ -1102,18 +1095,17 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) flagBits = flags | Rotation; else flagBits = Rotation; - return *this; } /*! \internal */ -QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) +void QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) { // Used by QGraphicsRotation::applyTo() to perform a rotation // and projection back to 2D in a single step. if (angle == 0.0f) - return *this; + return; QMatrix4x4 m(1); // The "1" says to not load the identity. qreal c, s, ic; if (angle == 90.0f || angle == -270.0f) { @@ -1206,7 +1198,6 @@ QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) flagBits = flags | Rotation; else flagBits = Rotation; - return *this; } #ifndef QT_NO_QUATERNION @@ -1214,11 +1205,11 @@ QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) /*! Multiples this matrix by another that rotates coordinates according to a specified \a quaternion. The \a quaternion is assumed to have - been normalized. Returns this matrix. + been normalized. \sa scale(), translate(), QQuaternion */ -QMatrix4x4& QMatrix4x4::rotate(const QQuaternion& quaternion) +void QMatrix4x4::rotate(const QQuaternion& quaternion) { // Algorithm from: // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q54 @@ -1254,7 +1245,6 @@ QMatrix4x4& QMatrix4x4::rotate(const QQuaternion& quaternion) flagBits = flags | Rotation; else flagBits = Rotation; - return *this; } #endif @@ -1265,17 +1255,16 @@ QMatrix4x4& QMatrix4x4::rotate(const QQuaternion& quaternion) Multiplies this matrix by another that applies an orthographic projection for a window with boundaries specified by \a rect. The near and far clipping planes will be -1 and 1 respectively. - Returns this matrix. \sa frustum(), perspective() */ -QMatrix4x4& QMatrix4x4::ortho(const QRect& rect) +void QMatrix4x4::ortho(const QRect& rect) { // Note: rect.right() and rect.bottom() subtract 1 in QRect, // which gives the location of a pixel within the rectangle, // instead of the extent of the rectangle. We want the extent. // QRectF expresses the extent properly. - return ortho(rect.x(), rect.x() + rect.width(), rect.y() + rect.height(), rect.y(), -1.0f, 1.0f); + ortho(rect.x(), rect.x() + rect.width(), rect.y() + rect.height(), rect.y(), -1.0f, 1.0f); } /*! @@ -1284,28 +1273,27 @@ QMatrix4x4& QMatrix4x4::ortho(const QRect& rect) Multiplies this matrix by another that applies an orthographic projection for a window with boundaries specified by \a rect. The near and far clipping planes will be -1 and 1 respectively. - Returns this matrix. \sa frustum(), perspective() */ -QMatrix4x4& QMatrix4x4::ortho(const QRectF& rect) +void QMatrix4x4::ortho(const QRectF& rect) { - return ortho(rect.left(), rect.right(), rect.bottom(), rect.top(), -1.0f, 1.0f); + ortho(rect.left(), rect.right(), rect.bottom(), rect.top(), -1.0f, 1.0f); } /*! Multiplies this matrix by another that applies an orthographic projection for a window with lower-left corner (\a left, \a bottom), upper-right corner (\a right, \a top), and the specified \a nearPlane - and \a farPlane clipping planes. Returns this matrix. + and \a farPlane clipping planes. \sa frustum(), perspective() */ -QMatrix4x4& QMatrix4x4::ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane) +void QMatrix4x4::ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane) { // Bail out if the projection volume is zero-sized. if (left == right || bottom == top || nearPlane == farPlane) - return *this; + return; // Construct the projection. qreal width = right - left; @@ -1324,7 +1312,7 @@ QMatrix4x4& QMatrix4x4::ortho(qreal left, qreal right, qreal bottom, qreal top, (2.0f / width, 2.0f / invheight, -1.0f)); - return *this; + return; } #endif QMatrix4x4 m(1); @@ -1347,22 +1335,22 @@ QMatrix4x4& QMatrix4x4::ortho(qreal left, qreal right, qreal bottom, qreal top, // Apply the projection. *this *= m; - return *this; + return; } /*! Multiplies this matrix by another that applies a perspective frustum projection for a window with lower-left corner (\a left, \a bottom), upper-right corner (\a right, \a top), and the specified \a nearPlane - and \a farPlane clipping planes. Returns this matrix. + and \a farPlane clipping planes. \sa ortho(), perspective() */ -QMatrix4x4& QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane) +void QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane) { // Bail out if the projection volume is zero-sized. if (left == right || bottom == top || nearPlane == farPlane) - return *this; + return; // Construct the projection. QMatrix4x4 m(1); @@ -1388,7 +1376,6 @@ QMatrix4x4& QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top // Apply the projection. *this *= m; - return *this; } /*! @@ -1396,22 +1383,21 @@ QMatrix4x4& QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top projection. The field of view will be \a angle degrees within a window with a given \a aspect ratio. The projection will have the specified \a nearPlane and \a farPlane clipping planes. - Returns this matrix. \sa ortho(), frustum() */ -QMatrix4x4& QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane) +void QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane) { // Bail out if the projection volume is zero-sized. if (nearPlane == farPlane || aspect == 0.0f) - return *this; + return; // Construct the projection. QMatrix4x4 m(1); qreal radians = (angle / 2.0f) * M_PI / 180.0f; qreal sine = qSin(radians); if (sine == 0.0f) - return *this; + return; qreal cotan = qCos(radians) / sine; qreal clip = farPlane - nearPlane; m.m[0][0] = cotan / aspect; @@ -1433,7 +1419,6 @@ QMatrix4x4& QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, // Apply the projection. *this *= m; - return *this; } #ifndef QT_NO_VECTOR3D @@ -1443,9 +1428,8 @@ QMatrix4x4& QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, transformation. The \a center value indicates the center of the view that the \a eye is looking at. The \a up value indicates which direction should be considered up with respect to the \a eye. - Returns this matrix. */ -QMatrix4x4& QMatrix4x4::lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up) +void QMatrix4x4::lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up) { QVector3D forward = (center - eye).normalized(); QVector3D side = QVector3D::crossProduct(forward, up).normalized(); @@ -1471,7 +1455,7 @@ QMatrix4x4& QMatrix4x4::lookAt(const QVector3D& eye, const QVector3D& center, co m.m[3][3] = 1.0f; *this *= m; - return translate(-eye); + translate(-eye); } #endif @@ -1480,11 +1464,11 @@ QMatrix4x4& QMatrix4x4::lookAt(const QVector3D& eye, const QVector3D& center, co Flips between right-handed and left-handed coordinate systems by multiplying the y and z co-ordinates by -1. This is normally used to create a left-handed orthographic view without scaling - the viewport as ortho() does. Returns this matrix. + the viewport as ortho() does. \sa ortho() */ -QMatrix4x4& QMatrix4x4::flipCoordinates() +void QMatrix4x4::flipCoordinates() { if (flagBits == Scale || flagBits == (Scale | Translation)) { m[1][1] = -m[1][1]; @@ -1508,7 +1492,6 @@ QMatrix4x4& QMatrix4x4::flipCoordinates() m[2][3] = -m[2][3]; flagBits = General; } - return *this; } /*! diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h index daebf9d..4193bdc 100644 --- a/src/gui/math3d/qmatrix4x4.h +++ b/src/gui/math3d/qmatrix4x4.h @@ -127,29 +127,29 @@ public: friend inline bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2); #ifndef QT_NO_VECTOR3D - QMatrix4x4& scale(const QVector3D& vector); - QMatrix4x4& translate(const QVector3D& vector); - QMatrix4x4& rotate(qreal angle, const QVector3D& vector); + void scale(const QVector3D& vector); + void translate(const QVector3D& vector); + void rotate(qreal angle, const QVector3D& vector); #endif - QMatrix4x4& scale(qreal x, qreal y); - QMatrix4x4& scale(qreal x, qreal y, qreal z); - QMatrix4x4& scale(qreal factor); - QMatrix4x4& translate(qreal x, qreal y); - QMatrix4x4& translate(qreal x, qreal y, qreal z); - QMatrix4x4& rotate(qreal angle, qreal x, qreal y, qreal z = 0.0f); + void scale(qreal x, qreal y); + void scale(qreal x, qreal y, qreal z); + void scale(qreal factor); + void translate(qreal x, qreal y); + void translate(qreal x, qreal y, qreal z); + void rotate(qreal angle, qreal x, qreal y, qreal z = 0.0f); #ifndef QT_NO_QUATERNION - QMatrix4x4& rotate(const QQuaternion& quaternion); + void rotate(const QQuaternion& quaternion); #endif - QMatrix4x4& ortho(const QRect& rect); - QMatrix4x4& ortho(const QRectF& rect); - QMatrix4x4& ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane); - QMatrix4x4& frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane); - QMatrix4x4& perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane); + void ortho(const QRect& rect); + void ortho(const QRectF& rect); + void ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane); + void frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane); + void perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane); #ifndef QT_NO_VECTOR3D - QMatrix4x4& lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up); + void lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up); #endif - QMatrix4x4& flipCoordinates(); + void flipCoordinates(); void copyDataTo(qreal *values) const; @@ -203,7 +203,7 @@ private: QMatrix4x4 orthonormalInverse() const; - QMatrix4x4& projectedRotate(qreal angle, qreal x, qreal y, qreal z); + void projectedRotate(qreal angle, qreal x, qreal y, qreal z); friend class QGraphicsRotation; }; diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp index e2a606f..3d68a73 100644 --- a/tests/auto/qvariant/tst_qvariant.cpp +++ b/tests/auto/qvariant/tst_qvariant.cpp @@ -1432,8 +1432,10 @@ void tst_QVariant::matrix4x4() QVariant variant; QMatrix4x4 matrix = qVariantValue(variant); QVERIFY(matrix.isIdentity()); - qVariantSetValue(variant, QMatrix4x4().scale(2.0)); - QCOMPARE(QMatrix4x4().scale(2.0), qVariantValue(variant)); + QMatrix4x4 m; + m.scale(2.0f); + qVariantSetValue(variant, m); + QCOMPARE(m, qVariantValue(variant)); void *mmatrix = QMetaType::construct(QVariant::Matrix4x4, 0); QVERIFY(mmatrix); -- cgit v0.12