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 QtDeclarative 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 QDECLARATIVELISTMODELWORKERAGENT_P_H
43 #define QDECLARATIVELISTMODELWORKERAGENT_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "qdeclarative.h"
58 #include <QtScript/qscriptvalue.h>
59 #include <QtGui/qevent.h>
61 #include <QWaitCondition>
67 QT_MODULE(Declarative)
69 class QDeclarativeListModel;
70 class FlatListScriptClass;
72 class QDeclarativeListModelWorkerAgent : public QObject
75 Q_PROPERTY(int count READ count)
78 QDeclarativeListModelWorkerAgent(QDeclarativeListModel *);
79 ~QDeclarativeListModelWorkerAgent();
81 void setScriptEngine(QScriptEngine *eng);
82 QScriptEngine *scriptEngine() const;
89 Q_INVOKABLE void clear();
90 Q_INVOKABLE void remove(int index);
91 Q_INVOKABLE void append(const QScriptValue &);
92 Q_INVOKABLE void insert(int index, const QScriptValue&);
93 Q_INVOKABLE QScriptValue get(int index) const;
94 Q_INVOKABLE void set(int index, const QScriptValue &);
95 Q_INVOKABLE void setProperty(int index, const QString& property, const QVariant& value);
96 Q_INVOKABLE void move(int from, int to, int count);
97 Q_INVOKABLE void sync();
101 VariantRef() : a(0) {}
102 VariantRef(const VariantRef &r) : a(r.a) { if (a) a->addref(); }
103 VariantRef(QDeclarativeListModelWorkerAgent *_a) : a(_a) { if (a) a->addref(); }
104 ~VariantRef() { if (a) a->release(); }
106 VariantRef &operator=(const VariantRef &o) {
107 if (o.a) o.a->addref();
108 if (a) a->release(); a = o.a;
112 QDeclarativeListModelWorkerAgent *a;
115 virtual bool event(QEvent *);
118 friend class QDeclarativeWorkerScriptEnginePrivate;
119 friend class FlatListScriptClass;
120 QScriptEngine *m_engine;
123 enum { Inserted, Removed, Moved, Changed } type;
124 int index; // Inserted/Removed/Moved/Changed
125 int count; // Inserted/Removed/Moved/Changed
131 QList<Change> changes;
134 void insertChange(int index, int count);
135 void removeChange(int index, int count);
136 void moveChange(int index, int count, int to);
137 void changedChange(int index, int count, const QList<int> &roles);
141 struct Sync : public QEvent {
142 Sync() : QEvent(QEvent::User) {}
144 QDeclarativeListModel *list;
147 void changedData(int index, int count, const QList<int> &roles);
150 QDeclarativeListModel *m_orig;
151 QDeclarativeListModel *m_copy;
153 QWaitCondition syncDone;
158 Q_DECLARE_METATYPE(QDeclarativeListModelWorkerAgent::VariantRef)
162 #endif // QDECLARATIVEWORKERSCRIPT_P_H