Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickparticlepainter.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
5
7#include <QQuickWindow>
8#include <QDebug>
34 : QQuickItem(parent)
35 , m_system(nullptr)
36 , m_count(0)
37 , m_pleaseReset(true)
38 , m_window(nullptr)
39 , m_windowChanged(false)
40 , m_groupIdsNeedRecalculation(false)
41{
42}
43
60
62{
63 if (!m_system && qobject_cast<QQuickParticleSystem*>(parentItem()))
64 setSystem(qobject_cast<QQuickParticleSystem*>(parentItem()));
66}
67
68void QQuickParticlePainter::recalculateGroupIds() const
69{
70 if (!m_system) {
71 m_groupIds.clear();
72 return;
73 }
74
75 m_groupIdsNeedRecalculation = false;
76 m_groupIds.clear();
77
78 const auto groupList = groups();
79 for (const QString &str : groupList) {
82 // invalid data, not finished setting up, or whatever. Fallback: do not cache.
83 m_groupIdsNeedRecalculation = true;
84 } else {
85 m_groupIds.append(groupId);
86 }
87 }
88}
89
91{
92 if (m_system != arg) {
93 m_system = arg;
94 m_groupIdsNeedRecalculation = true;
95 if (m_system){
97 reset();
98 }
100 }
101}
102
104{
105 if (m_groups != arg) {
106 m_groups = arg;
107 m_groupIdsNeedRecalculation = true;
108 //Note: The system watches this as it has to recalc things when groups change. It will request a reset if necessary
110 }
111}
112
114{
115 initialize(d->groupId, d->index);
116 if (m_pleaseReset)
117 return;
118 m_pendingCommits << qMakePair(d->groupId, d->index);
119}
120
122{
123 if (m_pleaseReset)
124 return;
125 m_pendingCommits << qMakePair(d->groupId, d->index);
126}
127
129{
130 m_pendingCommits.clear();
131 m_pleaseReset = true;
132}
133
134void QQuickParticlePainter::setCount(int c)//### TODO: some resizeing so that particles can reallocate on size change instead of recreate
135{
136 Q_ASSERT(c >= 0); //XXX
137 if (c == m_count)
138 return;
139 m_count = c;
141 reset();
142}
143
145{
146 if (!m_system || !parentItem())
147 return;
148 QPointF lastOffset = m_systemOffset;
149 m_systemOffset = -1 * this->mapFromItem(m_system, QPointF(0.0, 0.0));
150 if (lastOffset != m_systemOffset && !resetPending){
151 //Reload all particles//TODO: Necessary?
152 foreach (const QString &g, m_groups){
153 int gId = m_system->groupIds[g];
154 foreach (QQuickParticleData* d, m_system->groupData[gId]->data)
155 reload(d);
156 }
157 }
158}
159typedef QPair<int,int> intPair;
161{
163 foreach (intPair p, m_pendingCommits)
164 commit(p.first, p.second);
165 m_pendingCommits.clear();
166}
167
169
170#include "moc_qquickparticlepainter_p.cpp"
T value(const Key &key) const noexcept
Definition qhash.h:1054
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
\inmodule QtCore\reentrant
Definition qpoint.h:217
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
Q_INVOKABLE QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const
Maps the given point in item's coordinate system to the equivalent point within this item's coordinat...
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
QQuickItem * parentItem() const
virtual void itemChange(ItemChange, const ItemChangeData &)
Called when change occurs for this item.
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
Definition qquickitem.h:144
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
void itemChange(ItemChange, const ItemChangeData &) override
Called when change occurs for this item.
void setGroups(const QStringList &arg)
QQuickParticlePainter(QQuickItem *parent=nullptr)
\qmltype ParticlePainter \instantiates QQuickParticlePainter \inqmlmodule QtQuick....
void setSystem(QQuickParticleSystem *arg)
void load(QQuickParticleData *)
void systemChanged(QQuickParticleSystem *arg)
void groupsChanged(const QStringList &arg)
void reload(QQuickParticleData *)
void calcSystemOffset(bool resetPending=false)
QQuickParticleSystem * m_system
void registerParticlePainter(QQuickParticlePainter *p)
QVarLengthArray< QQuickParticleGroupData *, 32 > groupData
QHash< QString, int > groupIds
void sceneGraphInvalidated()
\qmlsignal QtQuick::Window::sceneGraphInitialized()
void clear()
Definition qset.h:61
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
void append(const T &t)
T * data() noexcept
QString str
[2]
Combined button and popup list for selecting options.
@ DirectConnection
static bool initialize()
Definition qctf.cpp:94
GLint GLint GLint GLint GLsizei GLsizei GLsizei GLboolean commit
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLboolean GLboolean g
const GLubyte * c
GLfloat GLfloat p
[1]
QT_BEGIN_NAMESPACE constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
Definition qpair.h:19
QPair< int, int > intPair
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
SSL_CTX int void * arg
#define Q_EMIT
#define emit
QObject::connect nullptr
myObject disconnect()
[26]
\inmodule QtQuick
Definition qquickitem.h:159