aba64e484187edcdd13a48fee8a124534f2219e0
[profile/ivi/qtdeclarative.git] / src / declarative / particles / qsgmodelparticle_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the Declarative module of the Qt Toolkit.
8 **
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
14 ** this package.
15 **
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.
23 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef DATAPARTICLE_H
43 #define DATAPARTICLE_H
44 #include "qsgparticlepainter_p.h"
45 #include <QPointer>
46 #include <QSet>
47 QT_BEGIN_HEADER
48
49 QT_BEGIN_NAMESPACE
50
51 QT_MODULE(Declarative)
52 class QSGVisualDataModel;
53 class QSGModelParticleAttached;
54
55 class QSGModelParticle : public QSGParticlePainter
56 {
57     Q_OBJECT
58
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")
64 public:
65     explicit QSGModelParticle(QSGItem *parent = 0);
66     QVariant model() const;
67     void setModel(const QVariant &);
68
69     QDeclarativeComponent *delegate() const;
70     void setDelegate(QDeclarativeComponent *);
71
72     int modelCount() const;
73
74     bool fade() const { return m_fade; }
75
76     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
77
78     static QSGModelParticleAttached *qmlAttachedProperties(QObject *object);
79 signals:
80     void modelChanged();
81     void delegateChanged();
82     void modelCountChanged();
83     void fadeChanged();
84
85 public slots:
86     void freeze(QSGItem* item);
87     void unfreeze(QSGItem* item);
88
89     void setFade(bool arg){if (arg == m_fade) return; m_fade = arg; emit fadeChanged();}
90 protected:
91     virtual void reset();
92     virtual void commit(int gIdx, int pIdx);
93     virtual void initialize(int gIdx, int pIdx);
94     void prepareNextFrame();
95 private slots:
96     void updateCount();
97     void processPending();
98 private:
99     bool m_ownModel;
100     QDeclarativeComponent* m_comp;
101     QSGVisualDataModel *m_model;
102     QVariant m_dataSource;
103     QList<QSGItem*> m_deletables;
104     QList< QSGParticleData* > m_requests;
105     bool m_fade;
106
107     QList<QSGItem*> m_pendingItems;
108     QList<int> m_available;
109     QSet<QSGItem*> m_stasis;
110     qreal m_lastT;
111     int m_activeCount;
112     int m_modelCount;
113 };
114
115 class QSGModelParticleAttached : public QObject
116 {
117     Q_OBJECT
118     Q_PROPERTY(QSGModelParticle* particle READ particle CONSTANT)
119 public:
120     QSGModelParticleAttached(QObject* parent)
121         : QObject(parent), m_mp(0)
122     {;}
123     QSGModelParticle* particle() {return m_mp;}
124     void detach(){emit detached();}
125     void attach(){emit attached();}
126 private:
127     QSGModelParticle* m_mp;
128     friend class QSGModelParticle;
129 Q_SIGNALS:
130     void detached();
131     void attached();
132 };
133
134 QT_END_NAMESPACE
135
136 QML_DECLARE_TYPEINFO(QSGModelParticle, QML_HAS_ATTACHED_PROPERTIES)
137
138 QT_END_HEADER
139 #endif // DATAPARTICLE_H