Compile on Mac
[profile/ivi/qtdeclarative.git] / src / imports / particles / dataparticle.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 "particle.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 DataParticleAttached;
54
55 class DataParticle : public ParticleType
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 DataParticle(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     virtual void load(ParticleData*);
78     virtual void reload(ParticleData*);
79     virtual void setCount(int c);
80     virtual int count();
81
82     static DataParticleAttached *qmlAttachedProperties(QObject *object);
83 signals:
84     void modelChanged();
85     void delegateChanged();
86     void modelCountChanged();
87     void fadeChanged();
88
89 public slots:
90     void freeze(QSGItem* item);
91     void unfreeze(QSGItem* item);
92
93     void setFade(bool arg){if(arg == m_fade) return; m_fade = arg; emit fadeChanged();}
94 protected:
95     virtual void reset();
96     void prepareNextFrame();
97 private slots:
98     void updateCount();
99 private:
100     bool m_ownModel;
101     QDeclarativeComponent* m_comp;
102     QSGVisualDataModel *m_model;
103     QVariant m_dataSource;
104     QList<QPointer<QSGItem> > m_deletables;
105     int m_particleCount;
106     bool m_fade;
107
108     QList<QSGItem*> m_pendingItems;
109     QVector<QSGItem*> m_items;
110     QVector<ParticleData*> m_data;
111     QVector<int> m_idx;
112     QList<int> m_available;
113     QSet<QSGItem*> m_stasis;
114     qreal m_lastT;
115     int m_activeCount;
116     int m_modelCount;
117 };
118
119 class DataParticleAttached : public QObject
120 {
121     Q_OBJECT
122     Q_PROPERTY(DataParticle* particle READ particle CONSTANT);
123 public:
124     DataParticleAttached(QObject* parent)
125         : QObject(parent), m_mp(0)
126     {;}
127     DataParticle* particle() {return m_mp;}
128     void detach(){emit detached();}
129     void attach(){emit attached();}
130 private:
131     DataParticle* m_mp;
132     friend class DataParticle;
133 Q_SIGNALS:
134     void detached();
135     void attached();
136 };
137
138 QT_END_NAMESPACE
139
140 QML_DECLARE_TYPEINFO(DataParticle, QML_HAS_ATTACHED_PROPERTIES)
141
142 QT_END_HEADER
143 #endif // DATAPARTICLE_H