Qt 4.8
qdeclarativexmllistmodel_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 QDECLARATIVEXMLLISTMODEL_H
43 #define QDECLARATIVEXMLLISTMODEL_H
44 
45 #include <qdeclarative.h>
46 #include <qdeclarativeinfo.h>
47 
48 #include <QtCore/qurl.h>
49 #include <QtCore/qstringlist.h>
50 #include <QtScript/qscriptvalue.h>
51 
52 #include <private/qlistmodelinterface_p.h>
53 
55 
57 
58 QT_MODULE(Declarative)
59 
63 
65  int queryId;
66  int size;
71 };
72 
74 {
75  Q_OBJECT
78 
80  qreal progress;
81  QUrl source;
82  QString xml;
83  QString query;
84  QString namespaceDeclarations;
86  int count;
87  Q_CLASSINFO("DefaultProperty", "roles")
88 
89 public:
90  QDeclarativeXmlListModel(QObject *parent = 0);
92 
93  virtual QHash<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const;
94  virtual QVariant data(int index, int role) const;
95  virtual int count() const;
96  virtual QList<int> roles() const;
97  virtual QString toString(int role) const;
98 
100 
101  QUrl source() const;
102  void setSource(const QUrl&);
103 
104  QString xml() const;
105  void setXml(const QString&);
106 
107  QString query() const;
108  void setQuery(const QString&);
109 
110  QString namespaceDeclarations() const;
111  void setNamespaceDeclarations(const QString&);
112 
113  Q_INVOKABLE QScriptValue get(int index) const;
114 
115  enum Status { Null, Ready, Loading, Error };
116  Status status() const;
117  qreal progress() const;
118 
120 
121  virtual void classBegin();
122  virtual void componentComplete();
123 
124 Q_SIGNALS:
125  void statusChanged(QDeclarativeXmlListModel::Status);
126  void progressChanged(qreal progress);
127  void countChanged();
128  void sourceChanged();
129  void xmlChanged();
130  void queryChanged();
131  void namespaceDeclarationsChanged();
132 
133 public Q_SLOTS:
134  // ### need to use/expose Expiry to guess when to call this?
135  // ### property to auto-call this on reasonable Expiry?
136  // ### LastModified/Age also useful to guess.
137  // ### Probably also applies to other network-requesting types.
138  void reload();
139 
140 private Q_SLOTS:
141  void requestFinished();
142  void requestProgress(qint64,qint64);
143  void dataCleared();
144  void queryCompleted(const QDeclarativeXmlQueryResult &);
145  void queryError(void* object, const QString& error);
146 
147 private:
150 };
151 
153 {
154  Q_OBJECT
157  bool isKey;
158 public:
159  QDeclarativeXmlListModelRole() : m_isKey(false) {}
161 
162  QString name() const { return m_name; }
163  void setName(const QString &name) {
164  if (name == m_name)
165  return;
166  m_name = name;
167  emit nameChanged();
168  }
169 
170  QString query() const { return m_query; }
171  void setQuery(const QString &query)
172  {
173  if (query.startsWith(QLatin1Char('/'))) {
174  qmlInfo(this) << tr("An XmlRole query must not start with '/'");
175  return;
176  }
177  if (m_query == query)
178  return;
179  m_query = query;
180  emit queryChanged();
181  }
182 
183  bool isKey() const { return m_isKey; }
184  void setIsKey(bool b) {
185  if (m_isKey == b)
186  return;
187  m_isKey = b;
188  emit isKeyChanged();
189  }
190 
191  bool isValid() {
192  return !m_name.isEmpty() && !m_query.isEmpty();
193  }
194 
195 Q_SIGNALS:
196  void nameChanged();
197  void queryChanged();
198  void isKeyChanged();
199 
200 private:
203  bool m_isKey;
204 };
205 
207 
210 
212 
213 #endif // QDECLARATIVEXMLLISTMODEL_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
Error
Definition: qaudio.h:58
#define Q_CLASSINFO(name, value)
This macro associates extra information to the class, which is available using QObject::metaObject()...
Definition: qobjectdefs.h:78
double qreal
Definition: qglobal.h:1193
#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 error(msg)
#define Q_INVOKABLE
Definition: qobjectdefs.h:90
QList< QPair< int, int > > inserted
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
#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
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
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
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
static QString toString(Register *reg, int type, bool *ok=0)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setQuery(const QString &query)
The QDeclarativeParserStatus class provides updates on the QML parser state.
const char * name
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QListModelInterface class can be subclassed to provide C++ models to QDeclarativeGraphics Views...
__int64 qint64
Definition: qglobal.h:942
#define Q_OBJECT
Definition: qobjectdefs.h:157
#define Q_INTERFACES(x)
This macro tells Qt which interfaces the class implements.
Definition: qobjectdefs.h:79
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
static const char * get(QDBusError::ErrorType code)
Definition: qdbuserror.cpp:141
The QDeclarativeContext class defines a context within a QML engine.
quint16 index
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
QDeclarativeInfo qmlInfo(const QObject *me)
#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
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
The QDeclarativeListProperty class allows applications to expose list-like properties to QML...
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QList< QPair< int, int > > removed
QList< QList< QVariant > > data