1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Declarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef DATAPARTICLE_H
43 #define DATAPARTICLE_H
44 #include "qsgparticlepainter_p.h"
51 QT_MODULE(Declarative)
52 class QSGVisualDataModel;
53 class QSGModelParticleAttached;
55 class QSGModelParticle : public QSGParticlePainter
59 Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
60 Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
61 Q_PROPERTY(int modelCount READ modelCount NOTIFY modelCountChanged)
62 Q_PROPERTY(bool fade READ fade WRITE setFade NOTIFY fadeChanged)
63 Q_CLASSINFO("DefaultProperty", "delegate")
65 explicit QSGModelParticle(QSGItem *parent = 0);
66 QVariant model() const;
67 void setModel(const QVariant &);
69 QDeclarativeComponent *delegate() const;
70 void setDelegate(QDeclarativeComponent *);
72 int modelCount() const;
74 bool fade() const { return m_fade; }
76 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
78 static QSGModelParticleAttached *qmlAttachedProperties(QObject *object);
81 void delegateChanged();
82 void modelCountChanged();
86 void freeze(QSGItem* item);
87 void unfreeze(QSGItem* item);
89 void setFade(bool arg){if (arg == m_fade) return; m_fade = arg; emit fadeChanged();}
92 virtual void commit(int gIdx, int pIdx);
93 virtual void initialize(int gIdx, int pIdx);
94 void prepareNextFrame();
97 void processPending();
100 QDeclarativeComponent* m_comp;
101 QSGVisualDataModel *m_model;
102 QVariant m_dataSource;
103 QList<QSGItem*> m_deletables;
104 QList< QSGParticleData* > m_requests;
107 QList<QSGItem*> m_pendingItems;
108 QList<int> m_available;
109 QSet<QSGItem*> m_stasis;
115 class QSGModelParticleAttached : public QObject
118 Q_PROPERTY(QSGModelParticle* particle READ particle CONSTANT)
120 QSGModelParticleAttached(QObject* parent)
121 : QObject(parent), m_mp(0)
123 QSGModelParticle* particle() {return m_mp;}
124 void detach(){emit detached();}
125 void attach(){emit attached();}
127 QSGModelParticle* m_mp;
128 friend class QSGModelParticle;
136 QML_DECLARE_TYPEINFO(QSGModelParticle, QML_HAS_ATTACHED_PROPERTIES)
139 #endif // DATAPARTICLE_H