Qt 4.8
qdeclarativevisualitemmodel_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 QDECLARATIVEVISUALDATAMODEL_H
43 #define QDECLARATIVEVISUALDATAMODEL_H
44 
45 #include <qdeclarative.h>
46 
47 #include <QtCore/qobject.h>
48 #include <QtCore/qabstractitemmodel.h>
49 
51 
53 
55 
56 QT_MODULE(Declarative)
57 
58 class QDeclarativeItem;
62 
64 {
65  Q_OBJECT
66 
67  int count;
68 
69 public:
71 
72  enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02 };
73  Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag)
74 
75  virtual int count() const = 0;
76  virtual bool isValid() const = 0;
77  virtual QDeclarativeItem *item(int index, bool complete=true) = 0;
78  virtual ReleaseFlags release(QDeclarativeItem *item) = 0;
79  virtual bool completePending() const = 0;
80  virtual void completeItem() = 0;
81  virtual QString stringValue(int, const QString &) = 0;
82  virtual void setWatchedRoles(QList<QByteArray> roles) = 0;
83 
84  virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const = 0;
85 
86 Q_SIGNALS:
87  void countChanged();
88  void itemsInserted(int index, int count);
89  void itemsRemoved(int index, int count);
90  void itemsMoved(int from, int to, int count);
91  void itemsChanged(int index, int count);
92  void modelReset();
93  void createdItem(int index, QDeclarativeItem *item);
94  void destroyingItem(QDeclarativeItem *item);
95 
96 protected:
98  : QObject(dd, parent) {}
99 
100 private:
102 };
103 
107 {
108  Q_OBJECT
110 
112  Q_CLASSINFO("DefaultProperty", "children")
113 
114 public:
117 
118  virtual int count() const;
119  virtual bool isValid() const;
120  virtual QDeclarativeItem *item(int index, bool complete=true);
121  virtual ReleaseFlags release(QDeclarativeItem *item);
122  virtual bool completePending() const;
123  virtual void completeItem();
124  virtual QString stringValue(int index, const QString &role);
126 
127  virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const;
128 
130 
131  static QDeclarativeVisualItemModelAttached *qmlAttachedProperties(QObject *obj);
132 
133 Q_SIGNALS:
134  void childrenChanged();
135 
136 private:
138 };
139 
140 
142 {
143  Q_OBJECT
145 
146  QVariant model;
148  QString part;
149  QObject *parts;
150  QVariant rootIndex;
151  Q_CLASSINFO("DefaultProperty", "delegate")
152 public:
154  QDeclarativeVisualDataModel(QDeclarativeContext *, QObject *parent=0);
155  virtual ~QDeclarativeVisualDataModel();
156 
157  QVariant model() const;
158  void setModel(const QVariant &);
159 
160  QDeclarativeComponent *delegate() const;
161  void setDelegate(QDeclarativeComponent *);
162 
163  QVariant rootIndex() const;
164  void setRootIndex(const QVariant &root);
165 
166  Q_INVOKABLE QVariant modelIndex(int idx) const;
167  Q_INVOKABLE QVariant parentModelIndex() const;
168 
169  QString part() const;
170  void setPart(const QString &);
171 
172  int count() const;
173  bool isValid() const { return delegate() != 0; }
174  QDeclarativeItem *item(int index, bool complete=true);
175  QDeclarativeItem *item(int index, const QByteArray &, bool complete=true);
176  ReleaseFlags release(QDeclarativeItem *item);
177  bool completePending() const;
178  void completeItem();
179  virtual QString stringValue(int index, const QString &role);
180  virtual void setWatchedRoles(QList<QByteArray> roles);
181 
182  int indexOf(QDeclarativeItem *item, QObject *objectContext) const;
183 
184  QObject *parts();
185 
186 Q_SIGNALS:
187  void createdPackage(int index, QDeclarativePackage *package);
188  void destroyingPackage(QDeclarativePackage *package);
189  void rootIndexChanged();
190 
191 private Q_SLOTS:
192  void _q_itemsChanged(int, int, const QList<int> &);
193  void _q_itemsInserted(int index, int count);
194  void _q_itemsRemoved(int index, int count);
195  void _q_itemsMoved(int from, int to, int count);
196  void _q_rowsInserted(const QModelIndex &,int,int);
197  void _q_rowsRemoved(const QModelIndex &,int,int);
198  void _q_rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int);
199  void _q_dataChanged(const QModelIndex&,const QModelIndex&);
200  void _q_layoutChanged();
201  void _q_modelReset();
202  void _q_createdPackage(int index, QDeclarativePackage *package);
203  void _q_destroyingPackage(QDeclarativePackage *package);
204 
205 private:
207 };
208 
210 {
211  Q_OBJECT
212 
213 public:
215  : QObject(parent), m_index(0) {}
217  attachedProperties.remove(parent());
218  }
219 
220  int index;
221  int index() const { return m_index; }
222  void setIndex(int idx) {
223  if (m_index != idx) {
224  m_index = idx;
225  emit indexChanged();
226  }
227  }
228 
230  QDeclarativeVisualItemModelAttached *rv = attachedProperties.value(obj);
231  if (!rv) {
233  attachedProperties.insert(obj, rv);
234  }
235  return rv;
236  }
237 
238 Q_SIGNALS:
239  void indexChanged();
240 
241 public:
242  int m_index;
243 
245 };
246 
247 
249 
254 
256 
257 #endif // QDECLARATIVEVISUALDATAMODEL_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
virtual bool isValid() const =0
virtual ReleaseFlags release(QDeclarativeItem *item)=0
#define Q_CLASSINFO(name, value)
This macro associates extra information to the class, which is available using QObject::metaObject()...
Definition: qobjectdefs.h:78
#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
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_INVOKABLE
Definition: qobjectdefs.h:90
virtual bool completePending() const =0
virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const =0
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_SLOTS
Definition: qobjectdefs.h:71
virtual QString stringValue(int, const QString &)=0
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
virtual void setWatchedRoles(QList< QByteArray >)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
#define QML_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition: qdeclarative.h:73
QDeclarativeVisualModel(QObjectPrivate &dd, QObject *parent=0)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QDeclarativeComponent class encapsulates a QML component definition.
The QDeclarativeItem class provides the most basic of all visual items in QML.
#define emit
Definition: qobjectdefs.h:76
#define Q_OBJECT
Definition: qobjectdefs.h:157
#define Q_DECLARE_METATYPE(TYPE)
This macro makes the type Type known to QMetaType as long as it provides a public default constructor...
Definition: qmetatype.h:265
static QHash< QObject *, QDeclarativeVisualItemModelAttached * > attachedProperties
virtual QDeclarativeItem * item(int index, bool complete=true)=0
virtual void setWatchedRoles(QList< QByteArray > roles)=0
The QModelIndex class is used to locate data in a data model.
virtual int count() const =0
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
The QDeclarativeContext class defines a context within a QML engine.
quint16 index
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
static QDeclarativeVisualItemModelAttached * properties(QObject *obj)
#define QT_END_HEADER
Definition: qglobal.h:137
virtual void completeItem()=0
The QDeclarativeListProperty class allows applications to expose list-like properties to QML...