From 583a306bb66601d4aa1ecc0429cc9e02aa6f9246 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 17 Jun 2009 10:42:15 +0200 Subject: add tests for QAbstractState::{entered,exited}() signals --- tests/auto/qstatemachine/tst_qstatemachine.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 963b6b9..6404e15 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -1155,6 +1155,10 @@ void tst_QStateMachine::stateEntryAndExit() QVERIFY(machine.configuration().isEmpty()); globalTick = 0; QVERIFY(!machine.isRunning()); + QSignalSpy s1EnteredSpy(s1, SIGNAL(entered())); + QSignalSpy s1ExitedSpy(s1, SIGNAL(exited())); + QSignalSpy s2EnteredSpy(s2, SIGNAL(entered())); + QSignalSpy s2ExitedSpy(s2, SIGNAL(exited())); machine.start(); QTRY_COMPARE(startedSpy.count(), 1); @@ -1180,6 +1184,11 @@ void tst_QStateMachine::stateEntryAndExit() // s2 is exited QCOMPARE(s2->events.at(1).first, 4); QCOMPARE(s2->events.at(1).second, TestState::Exit); + + QCOMPARE(s1EnteredSpy.count(), 1); + QCOMPARE(s1ExitedSpy.count(), 1); + QCOMPARE(s2EnteredSpy.count(), 1); + QCOMPARE(s2ExitedSpy.count(), 1); } // Two top-level states, one has two child states { -- cgit v0.12 From 4cacc45d10e59bb8915b8d76c359df7a8ad0a846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 17 Jun 2009 10:25:03 +0200 Subject: Prevented infinite recursion in GL graphics system. If creating a QGLWidget triggers the creation of a QPixmap then we might end up in an infinite recursion due to QPixmap trying to access qt_gl_share_widget(). This can happen via setWindowIcon for example. Adding an initializing flag to QGLGlobalShareWidget and preventing QGLFramebufferObject::hasOpenGLFramebufferObjects() and ::hasOpenGLFramebufferBlit() from creating a QGLWidget every time they are called with no active GL context. Reviewed-by: Trond --- src/opengl/qglframebufferobject.cpp | 6 ++---- src/opengl/qpixmapdata_gl.cpp | 7 +++++-- src/opengl/qwindowsurface_gl.cpp | 7 +++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp index 7f229e2..eacf5bb 100644 --- a/src/opengl/qglframebufferobject.cpp +++ b/src/opengl/qglframebufferobject.cpp @@ -935,8 +935,7 @@ QPaintEngine *QGLFramebufferObject::paintEngine() const */ bool QGLFramebufferObject::hasOpenGLFramebufferObjects() { - if (!QGLContext::currentContext()) - QGLWidget dmy; // needed to detect and init the QGLExtensions object + QGLExtensions::init(); return (QGLExtensions::glExtensions & QGLExtensions::FramebufferObject); } @@ -1098,8 +1097,7 @@ bool QGLFramebufferObject::isBound() const */ bool QGLFramebufferObject::hasOpenGLFramebufferBlit() { - if (!QGLContext::currentContext()) - QGLWidget dmy; // needed to detect and init the QGLExtensions object + QGLExtensions::init(); return (QGLExtensions::glExtensions & QGLExtensions::FramebufferBlit); } diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp index 5e73ef5..f745aae 100644 --- a/src/opengl/qpixmapdata_gl.cpp +++ b/src/opengl/qpixmapdata_gl.cpp @@ -114,8 +114,11 @@ QGLPixmapData::~QGLPixmapData() QGLWidget *shareWidget = qt_gl_share_widget(); if (!shareWidget) return; - QGLShareContextScope ctx(shareWidget->context()); - glDeleteTextures(1, &m_textureId); + + if (m_textureId) { + QGLShareContextScope ctx(shareWidget->context()); + glDeleteTextures(1, &m_textureId); + } } bool QGLPixmapData::isValid() const diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp index 50d0ae7..3a7a07e 100644 --- a/src/opengl/qwindowsurface_gl.cpp +++ b/src/opengl/qwindowsurface_gl.cpp @@ -184,11 +184,13 @@ QGLGraphicsSystem::QGLGraphicsSystem() class QGLGlobalShareWidget { public: - QGLGlobalShareWidget() : widget(0) {} + QGLGlobalShareWidget() : widget(0), initializing(false) {} QGLWidget *shareWidget() { - if (!widget && !cleanedUp) { + if (!initializing && !widget && !cleanedUp) { + initializing = true; widget = new QGLWidget; + initializing = false; } return widget; } @@ -204,6 +206,7 @@ public: private: QGLWidget *widget; + bool initializing; }; bool QGLGlobalShareWidget::cleanedUp = false; -- cgit v0.12 From 368c3c936fc12ef5249d72ffa5541df3b8558e4d Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 17 Jun 2009 10:59:50 +0200 Subject: bring back QAbstractTransition::triggered() signal It's been requested by several users. Since we have QAbstractState::{entered,exited}() signals, we should have this one as well. --- src/corelib/statemachine/qabstracttransition.cpp | 15 +++++++++++++++ src/corelib/statemachine/qabstracttransition.h | 6 ++++++ src/corelib/statemachine/qabstracttransition_p.h | 1 + src/corelib/statemachine/qstatemachine.cpp | 1 + tests/auto/qstatemachine/tst_qstatemachine.cpp | 2 ++ 5 files changed, 25 insertions(+) diff --git a/src/corelib/statemachine/qabstracttransition.cpp b/src/corelib/statemachine/qabstracttransition.cpp index 3be3b73..670aa7d 100644 --- a/src/corelib/statemachine/qabstracttransition.cpp +++ b/src/corelib/statemachine/qabstracttransition.cpp @@ -67,6 +67,8 @@ QT_BEGIN_NAMESPACE targetStates() function returns the targets of the transition. The machine() function returns the state machine that the transition is part of. + The triggered() signal is emitted when the transition has been triggered. + Transitions can cause animations to be played. Use the addAnimation() function to add an animation to the transition. @@ -139,6 +141,12 @@ QState *QAbstractTransitionPrivate::sourceState() const return qobject_cast(parent); } +void QAbstractTransitionPrivate::emitTriggered() +{ + Q_Q(QAbstractTransition); + emit q->triggered(); +} + /*! Constructs a new QAbstractTransition object with the given \a sourceState. */ @@ -333,6 +341,13 @@ QList QAbstractTransition::animations() const */ /*! + \fn QAbstractTransition::triggered() + + This signal is emitted when the transition has been triggered (after + onTransition() has been called). +*/ + +/*! \reimp */ bool QAbstractTransition::event(QEvent *e) diff --git a/src/corelib/statemachine/qabstracttransition.h b/src/corelib/statemachine/qabstracttransition.h index 83899ce..9ba1f11 100644 --- a/src/corelib/statemachine/qabstracttransition.h +++ b/src/corelib/statemachine/qabstracttransition.h @@ -89,6 +89,12 @@ public: QList animations() const; #endif +Q_SIGNALS: +#if !defined(Q_MOC_RUN) && !defined(qdoc) +private: // can only be emitted by QAbstractTransition +#endif + void triggered(); + protected: virtual bool eventTest(QEvent *event) = 0; diff --git a/src/corelib/statemachine/qabstracttransition_p.h b/src/corelib/statemachine/qabstracttransition_p.h index f0b9bb3..784832d 100644 --- a/src/corelib/statemachine/qabstracttransition_p.h +++ b/src/corelib/statemachine/qabstracttransition_p.h @@ -78,6 +78,7 @@ public: void callOnTransition(QEvent *e); QState *sourceState() const; QStateMachine *machine() const; + void emitTriggered(); QList > targetStates; diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 7a34e4b..04cce50 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -498,6 +498,7 @@ void QStateMachinePrivate::executeTransitionContent(QEvent *event, const QListcallOnTransition(event); + QAbstractTransitionPrivate::get(t)->emitTriggered(); } } diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 6404e15..9bccb97 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -1157,6 +1157,7 @@ void tst_QStateMachine::stateEntryAndExit() QVERIFY(!machine.isRunning()); QSignalSpy s1EnteredSpy(s1, SIGNAL(entered())); QSignalSpy s1ExitedSpy(s1, SIGNAL(exited())); + QSignalSpy tTriggeredSpy(t, SIGNAL(triggered())); QSignalSpy s2EnteredSpy(s2, SIGNAL(entered())); QSignalSpy s2ExitedSpy(s2, SIGNAL(exited())); machine.start(); @@ -1187,6 +1188,7 @@ void tst_QStateMachine::stateEntryAndExit() QCOMPARE(s1EnteredSpy.count(), 1); QCOMPARE(s1ExitedSpy.count(), 1); + QCOMPARE(tTriggeredSpy.count(), 1); QCOMPARE(s2EnteredSpy.count(), 1); QCOMPARE(s2ExitedSpy.count(), 1); } -- cgit v0.12