Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
5#include <QQuickWindow>
6#include <QDebug>
33 , m_system(nullptr)
34 , m_count(0)
35 , m_pleaseReset(true)
36 , m_window(nullptr)
37 , m_windowChanged(false)
38 , m_groupIdsNeedRecalculation(false)
39{
40}
41
43{
44 if (change == QQuickItem::ItemSceneChange) {
45 if (m_window)
47 m_window = data.window;
48 m_windowChanged = true;
49 if (m_window)
51 }
53}
54
56{
57 if (!m_system && qobject_cast<QQuickParticleSystem*>(parentItem()))
58 setSystem(qobject_cast<QQuickParticleSystem*>(parentItem()));
60}
61
62void QQuickParticlePainter::recalculateGroupIds() const
63{
64 if (!m_system) {
65 m_groupIds.clear();
66 return;
67 }
68
69 m_groupIdsNeedRecalculation = false;
70 m_groupIds.clear();
71
72 const auto groupList = groups();
73 for (const QString &str : groupList) {
76 // invalid data, not finished setting up, or whatever. Fallback: do not cache.
77 m_groupIdsNeedRecalculation = true;
78 } else {
79 m_groupIds.append(groupId);
80 }
81 }
82}
83
85{
86 if (m_system != arg) {
87 m_system = arg;
88 m_groupIdsNeedRecalculation = true;
89 if (m_system){
91 reset();
92 }
94 }
95}
96
98{
99 if (m_groups != arg) {
100 m_groups = arg;
101 m_groupIdsNeedRecalculation = true;
102 //Note: The system watches this as it has to recalc things when groups change. It will request a reset if necessary
104 }
105}
106
108{
109 initialize(d->groupId, d->index);
110 if (m_pleaseReset)
111 return;
112 m_pendingCommits << qMakePair(d->groupId, d->index);
113}
114
116{
117 if (m_pleaseReset)
118 return;
119 m_pendingCommits << qMakePair(d->groupId, d->index);
120}
121
123{
124 m_pendingCommits.clear();
125 m_pleaseReset = true;
126}
127
128void QQuickParticlePainter::setCount(int c)//### TODO: some resizeing so that particles can reallocate on size change instead of recreate
129{
130 Q_ASSERT(c >= 0); //XXX
131 if (c == m_count)
132 return;
133 m_count = c;
135 reset();
136}
137
139{
140 if (!m_system || !parentItem())
141 return;
142 QPointF lastOffset = m_systemOffset;
143 m_systemOffset = -1 * this->mapFromItem(m_system, QPointF(0.0, 0.0));
144 if (lastOffset != m_systemOffset && !resetPending){
145 //Reload all particles//TODO: Necessary?
146 foreach (const QString &g, m_groups){
147 int gId = m_system->groupIds[g];
148 foreach (QQuickParticleData* d, m_system->groupData[gId]->data)
149 reload(d);
150 }
151 }
152}
155{
157 foreach (intPair p, m_pendingCommits)
158 commit(p.first, p.second);
159 m_pendingCommits.clear();
160}
161
163
164#include "moc_qquickparticlepainter_p.cpp"
T value(const Key &key) const noexcept
Definition qhash.h:1044
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
\inmodule QtCore\reentrant
Definition qpoint.h:214
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
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:143
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 clear()
Definition qset.h:61
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
void append(const T &t)
T * data() noexcept
QString str
[2]
Combined button and popup list for selecting options.
@ DirectConnection
std::pair< T1, T2 > QPair
static bool initialize()
Definition qctf.cpp:67
#define SLOT(a)
Definition qobjectdefs.h:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
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]
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]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
\inmodule QtQuick
Definition qquickitem.h:158