Qt 4.8
qdeclarativelistmodel_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QDECLARATIVELISTMODEL_H
43 #define QDECLARATIVELISTMODEL_H
44 
45 #include <qdeclarative.h>
46 #include <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 <private/qlistmodelinterface_p.h>
54 #include <QtScript/qscriptvalue.h>
55 
57 
59 
60 QT_MODULE(Declarative)
61 
62 class FlatListModel;
63 class NestedListModel;
65 struct ModelNode;
68 {
69  Q_OBJECT
70  int count;
71 
72 public:
73  QDeclarativeListModel(QObject *parent=0);
75 
76  virtual QList<int> roles() const;
77  virtual QString toString(int role) const;
78  virtual int count() const;
79  virtual QVariant data(int index, int role) const;
80 
81  Q_INVOKABLE void clear();
82  Q_INVOKABLE void remove(int index);
83  Q_INVOKABLE void append(const QScriptValue&);
84  Q_INVOKABLE void insert(int index, const QScriptValue&);
85  Q_INVOKABLE QScriptValue get(int index) const;
86  Q_INVOKABLE void set(int index, const QScriptValue&);
87  Q_INVOKABLE void setProperty(int index, const QString& property, const QVariant& value);
88  Q_INVOKABLE void move(int from, int to, int count);
89  Q_INVOKABLE void sync();
90 
92 
93 Q_SIGNALS:
94  void countChanged();
95 
96 private:
99  friend class FlatListModel;
100  friend class FlatListScriptClass;
101  friend struct ModelNode;
102 
103  // Constructs a flat list model for a worker agent
105 
106  void set(int index, const QScriptValue&, QList<int> *roles);
107  void setProperty(int index, const QString& property, const QVariant& value, QList<int> *roles);
108 
109  bool flatten();
110  bool inWorkerThread() const;
111 
112  inline bool canMove(int from, int to, int n) const { return !(from+n > count() || to+n > count() || from < 0 || to < 0 || n < 0); }
113 
117 };
118 
119 // ### FIXME
121 {
122 Q_OBJECT
123 };
124 
126 {
127 public:
129  void setCustomData(QObject *, const QByteArray &);
130 
131 private:
133  {
134  enum { Push, Pop, Value, Set } type;
135  int dataIdx;
136  };
138  {
141  ListInstruction *instructions() const;
142  };
143  bool compileProperty(const QDeclarativeCustomParserProperty &prop, QList<ListInstruction> &instr, QByteArray &data);
144 
145  bool definesEmptyList(const QString &);
146 
148 };
149 
150 
152 
155 
157 
158 #endif // QDECLARATIVELISTMODEL_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
virtual QVariant data(int index, int role) const =0
Returns the data at the given index for the specified roles.
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QML_DECLARE_TYPE(TYPE)
Definition: qdeclarative.h:56
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
virtual int count() const =0
Returns the number of data entries in the model.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_INVOKABLE
Definition: qobjectdefs.h:90
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
virtual QString toString(int role) const =0
Returns a string description of the specified role.
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static const char * data(const QByteArray &arr)
The QListModelInterface class can be subclassed to provide C++ models to QDeclarativeGraphics Views...
#define Q_DECLARATIVE_PRIVATE_EXPORT
The QDeclarativeCustomParser class allows you to add new arbitrary types to QML.
#define Q_OBJECT
Definition: qobjectdefs.h:157
virtual QList< int > roles() const =0
Returns the list of roles for which the list model interface provides data.
QDeclarativeListModelWorkerAgent * m_agent
const char * property
Definition: qwizard.cpp:138
quint16 index
bool canMove(int from, int to, int n) const
#define QT_END_HEADER
Definition: qglobal.h:137
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57