Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / qtquick1 / util / qdeclarativelistmodel_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVELISTMODEL_H
43 #define QDECLARATIVELISTMODEL_H
44
45 #include <QtDeclarative/qdeclarative.h>
46 #include <QtDeclarative/private/qdeclarativecustomparser_p.h>
47
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>
54
55 QT_BEGIN_HEADER
56
57 QT_BEGIN_NAMESPACE
58
59
60 class FlatListModel_1;
61 class NestedListModel_1;
62 class QDeclarative1ListModelWorkerAgent;
63 struct ModelNode;
64 class FlatListScriptClass_1;
65 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarative1ListModel : public QListModelInterface
66 {
67     Q_OBJECT
68     Q_PROPERTY(int count READ count NOTIFY countChanged)
69
70 public:
71     QDeclarative1ListModel(QObject *parent=0);
72     ~QDeclarative1ListModel();
73
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;
78
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();
88
89     QDeclarative1ListModelWorkerAgent *agent();
90
91 Q_SIGNALS:
92     void countChanged();
93
94 private:
95     friend class QDeclarative1ListModelParser;
96     friend class QDeclarative1ListModelWorkerAgent;
97     friend class FlatListModel_1;
98     friend class FlatListScriptClass_1;
99     friend struct ModelNode;
100
101     // Constructs a flat list model for a worker agent
102     QDeclarative1ListModel(const QDeclarative1ListModel *orig, QDeclarative1ListModelWorkerAgent *parent);
103
104     void set(int index, const QScriptValue&, QList<int> *roles);
105     void setProperty(int index, const QString& property, const QVariant& value, QList<int> *roles);
106
107     bool flatten();
108     bool inWorkerThread() const;
109
110     inline bool canMove(int from, int to, int n) const { return !(from+n > count() || to+n > count() || from < 0 || to < 0 || n < 0); }
111
112     QDeclarative1ListModelWorkerAgent *m_agent;
113     NestedListModel_1 *m_nested;
114     FlatListModel_1 *m_flat;
115 };
116
117 // ### FIXME
118 class QDeclarative1ListElement : public QObject
119 {
120 Q_OBJECT
121 };
122
123 class QDeclarative1ListModelParser : public QDeclarativeCustomParser
124 {
125 public:
126     QByteArray compile(const QList<QDeclarativeCustomParserProperty> &);
127     void setCustomData(QObject *, const QByteArray &);
128
129 private:
130     struct ListInstruction
131     {
132         enum { Push, Pop, Value, Set } type;
133         int dataIdx;
134     };
135     struct ListModelData
136     {
137         int dataOffset;
138         int instrCount;
139         ListInstruction *instructions() const;
140     };
141     bool compileProperty(const QDeclarativeCustomParserProperty &prop, QList<ListInstruction> &instr, QByteArray &data);
142
143     bool definesEmptyList(const QString &);
144
145     QByteArray listElementTypeName;
146 };
147
148 QT_END_NAMESPACE
149
150 QML_DECLARE_TYPE(QDeclarative1ListModel)
151 QML_DECLARE_TYPE(QDeclarative1ListElement)
152
153 QT_END_HEADER
154
155 #endif // QDECLARATIVELISTMODEL_H