Automatically set system if parent is a ParticleSystem
authorAlan Alpert <alan.alpert@nokia.com>
Thu, 9 Jun 2011 05:17:52 +0000 (15:17 +1000)
committerAlan Alpert <alan.alpert@nokia.com>
Thu, 9 Jun 2011 05:17:52 +0000 (15:17 +1000)
src/declarative/particles/qsgparticleaffector.cpp
src/declarative/particles/qsgparticleemitter.cpp
src/declarative/particles/qsgparticlepainter.cpp
src/declarative/particles/qsgparticlesystem.cpp
src/declarative/particles/qsgparticlesystem_p.h

index d4b588a..96c5cfb 100644 (file)
@@ -56,6 +56,8 @@ QSGParticleAffector::QSGParticleAffector(QSGItem *parent) :
 
 void QSGParticleAffector::componentComplete()
 {
+    if(!m_system && qobject_cast<QSGParticleSystem*>(parentItem()))
+        setSystem(qobject_cast<QSGParticleSystem*>(parentItem()));
     if(!m_system)
         qWarning() << "Affector created without a particle system specified";//TODO: useful QML warnings, like line number?
     QSGItem::componentComplete();
index c04c86c..20f3c6b 100644 (file)
@@ -76,6 +76,8 @@ QSGParticleEmitter::~QSGParticleEmitter()
 
 void QSGParticleEmitter::componentComplete()
 {
+    if(!m_system && qobject_cast<QSGParticleSystem*>(parentItem()))
+        setSystem(qobject_cast<QSGParticleSystem*>(parentItem()));
     if(!m_system)
         qWarning() << "Emitter created without a particle system specified";//TODO: useful QML warnings, like line number?
     QSGItem::componentComplete();
index 8814c61..a5e8c0a 100644 (file)
@@ -54,8 +54,10 @@ QSGParticlePainter::QSGParticlePainter(QSGItem *parent) :
 
 void QSGParticlePainter::componentComplete()
 {
+    if(!m_system && qobject_cast<QSGParticleSystem*>(parentItem()))
+        setSystem(qobject_cast<QSGParticleSystem*>(parentItem()));
     if(!m_system)
-        qWarning() << "Particle created without a particle system specified";//TODO: useful QML warnings, like line number?
+        qWarning() << "ParticlePainter created without a particle system specified";//TODO: useful QML warnings, like line number?
     QSGItem::componentComplete();
 }
 
index a2aa377..4a8f75b 100644 (file)
@@ -67,7 +67,9 @@ QSGParticleData::QSGParticleData()
 }
 
 QSGParticleSystem::QSGParticleSystem(QSGItem *parent) :
-    QSGItem(parent), m_particle_count(0), m_running(true) , m_startTime(0), m_overwrite(false)
+    QSGItem(parent), m_particle_count(0), m_running(true)
+  , m_startTime(0), m_overwrite(false)
+  , m_componentComplete(false)
 {
     m_groupIds = QHash<QString, int>();
 }
@@ -111,7 +113,9 @@ void QSGParticleSystem::setRunning(bool arg)
 void QSGParticleSystem::componentComplete()
 {
     QSGItem::componentComplete();
-    reset();
+    m_componentComplete = true;
+    if(!m_emitters.isEmpty() && !m_particles.isEmpty())
+        reset();
 }
 
 void QSGParticleSystem::initializeSystem()
@@ -191,6 +195,8 @@ void QSGParticleSystem::initializeSystem()
 
 void QSGParticleSystem::reset()
 {
+    if(!m_componentComplete)
+        return;//Batch starting reset()s a little
     //Clear guarded pointers which have been deleted
     int cleared = 0;
     cleared += m_emitters.removeAll(0);
index aab3c5d..9730ff3 100644 (file)
@@ -163,6 +163,7 @@ private:
     qint64 m_startTime;
     int m_nextGroupId;
     bool m_overwrite;
+    bool m_componentComplete;
 };
 
 //TODO: Clean up all this into ParticleData