1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVELISTMODEL_H
43 #define QDECLARATIVELISTMODEL_H
45 #include <QtDeclarative/qdeclarative.h>
46 #include <QtDeclarative/private/qdeclarativecustomparser_p.h>
48 #include <QtCore/QObject>
49 #include <QtCore/QStringList>
50 #include <QtCore/QHash>
51 #include <QtCore/QList>
52 #include <QtCore/QVariant>
53 #include <QtQuick1/private/qlistmodelinterface_p.h>
60 class FlatListModel_1;
61 class NestedListModel_1;
62 class QDeclarative1ListModelWorkerAgent;
64 class FlatListScriptClass_1;
65 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarative1ListModel : public QListModelInterface
68 Q_PROPERTY(int count READ count NOTIFY countChanged)
71 QDeclarative1ListModel(QObject *parent=0);
72 ~QDeclarative1ListModel();
74 virtual QList<int> roles() const;
75 virtual QString toString(int role) const;
76 virtual int count() const;
77 virtual QVariant data(int index, int role) const;
79 Q_INVOKABLE void clear();
80 Q_INVOKABLE void remove(int index);
81 Q_INVOKABLE void append(const QScriptValue&);
82 Q_INVOKABLE void insert(int index, const QScriptValue&);
83 Q_INVOKABLE QScriptValue get(int index) const;
84 Q_INVOKABLE void set(int index, const QScriptValue&);
85 Q_INVOKABLE void setProperty(int index, const QString& property, const QVariant& value);
86 Q_INVOKABLE void move(int from, int to, int count);
87 Q_INVOKABLE void sync();
89 QDeclarative1ListModelWorkerAgent *agent();
95 friend class QDeclarative1ListModelParser;
96 friend class QDeclarative1ListModelWorkerAgent;
97 friend class FlatListModel_1;
98 friend class FlatListScriptClass_1;
99 friend struct ModelNode;
101 // Constructs a flat list model for a worker agent
102 QDeclarative1ListModel(const QDeclarative1ListModel *orig, QDeclarative1ListModelWorkerAgent *parent);
104 void set(int index, const QScriptValue&, QList<int> *roles);
105 void setProperty(int index, const QString& property, const QVariant& value, QList<int> *roles);
108 bool inWorkerThread() const;
110 inline bool canMove(int from, int to, int n) const { return !(from+n > count() || to+n > count() || from < 0 || to < 0 || n < 0); }
112 QDeclarative1ListModelWorkerAgent *m_agent;
113 NestedListModel_1 *m_nested;
114 FlatListModel_1 *m_flat;
118 class QDeclarative1ListElement : public QObject
123 class QDeclarative1ListModelParser : public QDeclarativeCustomParser
126 QByteArray compile(const QList<QDeclarativeCustomParserProperty> &);
127 void setCustomData(QObject *, const QByteArray &);
130 struct ListInstruction
132 enum { Push, Pop, Value, Set } type;
139 ListInstruction *instructions() const;
141 bool compileProperty(const QDeclarativeCustomParserProperty &prop, QList<ListInstruction> &instr, QByteArray &data);
143 bool definesEmptyList(const QString &);
145 QByteArray listElementTypeName;
150 QML_DECLARE_TYPE(QDeclarative1ListModel)
151 QML_DECLARE_TYPE(QDeclarative1ListElement)
155 #endif // QDECLARATIVELISTMODEL_H