Qt 4.8
qdeclarativexmllistmodel.cpp
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 #include "private/qdeclarativexmllistmodel_p.h"
43 
44 #include <qdeclarativecontext.h>
45 #include <qdeclarativeengine_p.h>
46 
47 #include <QDebug>
48 #include <QStringList>
49 #include <QMap>
50 #include <QApplication>
51 #include <QThread>
52 #include <QXmlQuery>
53 #include <QXmlResultItems>
54 #include <QXmlNodeModelIndex>
55 #include <QBuffer>
56 #include <QNetworkRequest>
57 #include <QNetworkReply>
58 #include <QTimer>
59 #include <QMutex>
60 
61 #include <private/qobject_p.h>
62 
64 
66 
67 
69 
70 #define XMLLISTMODEL_CLEAR_ID 0
71 
150 {
151  int queryId;
156  QList<void*> roleQueryErrorId; // the ptr to send back if there is an error
160 };
161 
162 
165 {
166  Q_OBJECT
167 public:
169 
170  void processJobs();
171  virtual bool event(QEvent *e);
172 
173 private:
175 };
176 
177 
179 {
180  Q_OBJECT
181 public:
184 
186  void abort(int id);
187 
188  void processJobs();
189 
190  static QDeclarativeXmlQueryEngine *instance(QDeclarativeEngine *engine);
191 
192 signals:
193  void queryCompleted(const QDeclarativeXmlQueryResult &);
194  void error(void*, const QString&);
195 
196 protected:
197  void run();
198 
199 private:
200  void processQuery(XmlQueryJob *job);
201  void doQueryJob(XmlQueryJob *job, QDeclarativeXmlQueryResult *currentResult);
202  void doSubQueryJob(XmlQueryJob *job, QDeclarativeXmlQueryResult *currentResult);
203  void getValuesOfKeyRoles(const XmlQueryJob& currentJob, QStringList *values, QXmlQuery *query) const;
204  void addIndexToRangeList(QList<QDeclarativeXmlListRange> *ranges, int index) const;
205 
211 
214 
217 };
220 
221 
223  : m_queryEngine(e)
224 {
225 }
226 
228 {
230 }
231 
233 {
234  if (e->type() == QEvent::User) {
236  return true;
237  } else {
238  return QObject::event(e);
239  }
240 }
241 
242 
243 
245 : QThread(eng), m_threadObject(0), m_queryIds(XMLLISTMODEL_CLEAR_ID + 1), m_engine(eng), m_eventLoopQuitHack(0)
246 {
247  qRegisterMetaType<QDeclarativeXmlQueryResult>("QDeclarativeXmlQueryResult");
248 
250  m_eventLoopQuitHack->moveToThread(this);
251  connect(m_eventLoopQuitHack, SIGNAL(destroyed(QObject*)), SLOT(quit()), Qt::DirectConnection);
253 }
254 
256 {
260 
262  wait();
263 }
264 
266  {
267  QMutexLocker m1(&m_mutex);
268  m_queryIds.ref();
269  if (m_queryIds <= 0)
270  m_queryIds = 1;
271  }
272 
273  XmlQueryJob job;
274  job.queryId = m_queryIds;
275  job.data = data;
276  job.query = QLatin1String("doc($src)") + query;
277  job.namespaces = namespaces;
278  job.keyRoleResultsCache = keyRoleResultsCache;
279 
280  for (int i=0; i<roleObjects->count(); i++) {
281  if (!roleObjects->at(i)->isValid()) {
282  job.roleQueries << QString();
283  continue;
284  }
285  job.roleQueries << roleObjects->at(i)->query();
286  job.roleQueryErrorId << static_cast<void*>(roleObjects->at(i));
287  if (roleObjects->at(i)->isKey())
288  job.keyRoleQueries << job.roleQueries.last();
289  }
290 
291  {
292  QMutexLocker ml(&m_mutex);
293  m_jobs.append(job);
294  if (m_threadObject)
296  }
297 
298  return job.queryId;
299 }
300 
302 {
303  QMutexLocker ml(&m_mutex);
304  if (id != -1)
306 }
307 
309 {
310  m_mutex.lock();
312  m_mutex.unlock();
313 
314  processJobs();
315  exec();
316 
317  delete m_threadObject;
318  m_threadObject = 0;
319 }
320 
322 {
323  QMutexLocker locker(&m_mutex);
324 
325  while (true) {
326  if (m_jobs.isEmpty())
327  return;
328 
329  XmlQueryJob currentJob = m_jobs.takeLast();
330  while (m_cancelledJobs.remove(currentJob.queryId)) {
331  if (m_jobs.isEmpty())
332  return;
333  currentJob = m_jobs.takeLast();
334  }
335 
336  locker.unlock();
337  processQuery(&currentJob);
338  locker.relock();
339  }
340 }
341 
343 {
345  QDeclarativeXmlQueryEngine *queryEng = queryEngines.value(engine);
346  if (!queryEng) {
347  queryEng = new QDeclarativeXmlQueryEngine(engine);
348  queryEngines.insert(engine, queryEng);
349  }
351 
352  return queryEng;
353 }
354 
356 {
358  result.queryId = job->queryId;
359  doQueryJob(job, &result);
360  doSubQueryJob(job, &result);
361 
362  {
363  QMutexLocker ml(&m_mutex);
364  if (m_cancelledJobs.contains(job->queryId)) {
366  } else {
367  emit queryCompleted(result);
368  }
369  }
370 }
371 
373 {
374  Q_ASSERT(currentJob->queryId != -1);
375 
376  QString r;
377  QXmlQuery query;
378  QBuffer buffer(&currentJob->data);
379  buffer.open(QIODevice::ReadOnly);
380  query.bindVariable(QLatin1String("src"), &buffer);
381  query.setQuery(currentJob->namespaces + currentJob->query);
382  query.evaluateTo(&r);
383 
384  //always need a single root element
385  QByteArray xml = "<dummy:items xmlns:dummy=\"http://qtsotware.com/dummy\">\n" + r.toUtf8() + "</dummy:items>";
386  QBuffer b(&xml);
388 
389  QString namespaces = QLatin1String("declare namespace dummy=\"http://qtsotware.com/dummy\";\n") + currentJob->namespaces;
390  QString prefix = QLatin1String("doc($inputDocument)/dummy:items") +
391  currentJob->query.mid(currentJob->query.lastIndexOf(QLatin1Char('/')));
392 
393  //figure out how many items we are dealing with
394  int count = -1;
395  {
396  QXmlResultItems result;
397  QXmlQuery countquery;
398  countquery.bindVariable(QLatin1String("inputDocument"), &b);
399  countquery.setQuery(namespaces + QLatin1String("count(") + prefix + QLatin1Char(')'));
400  countquery.evaluateTo(&result);
401  QXmlItem item(result.next());
402  if (item.isAtomicValue())
403  count = item.toAtomicValue().toInt();
404  }
405 
406  currentJob->data = xml;
407  currentJob->prefix = namespaces + prefix + QLatin1Char('/');
408  currentResult->size = (count > 0 ? count : 0);
409 }
410 
412 {
413  const QStringList &keysQueries = currentJob.keyRoleQueries;
414  QString keysQuery;
415  if (keysQueries.count() == 1)
416  keysQuery = currentJob.prefix + keysQueries[0];
417  else if (keysQueries.count() > 1)
418  keysQuery = currentJob.prefix + QLatin1String("concat(") + keysQueries.join(QLatin1String(",")) + QLatin1String(")");
419 
420  if (!keysQuery.isEmpty()) {
421  query->setQuery(keysQuery);
422  QXmlResultItems resultItems;
423  query->evaluateTo(&resultItems);
424  QXmlItem item(resultItems.next());
425  while (!item.isNull()) {
426  values->append(item.toAtomicValue().toString());
427  item = resultItems.next();
428  }
429  }
430 }
431 
433  if (ranges->isEmpty())
434  ranges->append(qMakePair(index, 1));
435  else if (ranges->last().first + ranges->last().second == index)
436  ranges->last().second += 1;
437  else
438  ranges->append(qMakePair(index, 1));
439 }
440 
442 {
443  Q_ASSERT(currentJob->queryId != -1);
444 
445  QBuffer b(&currentJob->data);
447 
448  QXmlQuery subquery;
449  subquery.bindVariable(QLatin1String("inputDocument"), &b);
450 
451  QStringList keyRoleResults;
452  getValuesOfKeyRoles(*currentJob, &keyRoleResults, &subquery);
453 
454  // See if any values of key roles have been inserted or removed.
455 
456  if (currentJob->keyRoleResultsCache.isEmpty()) {
457  currentResult->inserted << qMakePair(0, currentResult->size);
458  } else {
459  if (keyRoleResults != currentJob->keyRoleResultsCache) {
460  QStringList temp;
461  for (int i=0; i<currentJob->keyRoleResultsCache.count(); i++) {
462  if (!keyRoleResults.contains(currentJob->keyRoleResultsCache[i]))
463  addIndexToRangeList(&currentResult->removed, i);
464  else
465  temp << currentJob->keyRoleResultsCache[i];
466  }
467 
468  for (int i=0; i<keyRoleResults.count(); i++) {
469  if (temp.count() == i || keyRoleResults[i] != temp[i]) {
470  temp.insert(i, keyRoleResults[i]);
471  addIndexToRangeList(&currentResult->inserted, i);
472  }
473  }
474  }
475  }
476  currentResult->keyRoleResultsCache = keyRoleResults;
477 
478  // Get the new values for each role.
479  //### we might be able to condense even further (query for everything in one go)
480  const QStringList &queries = currentJob->roleQueries;
481  for (int i = 0; i < queries.size(); ++i) {
482  QList<QVariant> resultList;
483  if (!queries[i].isEmpty()) {
484  subquery.setQuery(currentJob->prefix + QLatin1String("(let $v := string(") + queries[i] + QLatin1String(") return if ($v) then ") + queries[i] + QLatin1String(" else \"\")"));
485  if (subquery.isValid()) {
486  QXmlResultItems resultItems;
487  subquery.evaluateTo(&resultItems);
488  QXmlItem item(resultItems.next());
489  while (!item.isNull()) {
490  resultList << item.toAtomicValue(); //### we used to trim strings
491  item = resultItems.next();
492  }
493  } else {
494  emit error(currentJob->roleQueryErrorId.at(i), queries[i]);
495  }
496  }
497  //### should warn here if things have gone wrong.
498  while (resultList.count() < currentResult->size)
499  resultList << QVariant();
500  currentResult->data << resultList;
501  b.seek(0);
502  }
503 
504  //this method is much slower, but works better for incremental loading
505  /*for (int j = 0; j < m_size; ++j) {
506  QList<QVariant> resultList;
507  for (int i = 0; i < m_roleObjects->size(); ++i) {
508  QDeclarativeXmlListModelRole *role = m_roleObjects->at(i);
509  subquery.setQuery(m_prefix.arg(j+1) + role->query());
510  if (role->isStringList()) {
511  QStringList data;
512  subquery.evaluateTo(&data);
513  resultList << QVariant(data);
514  //qDebug() << data;
515  } else {
516  QString s;
517  subquery.evaluateTo(&s);
518  if (role->isCData()) {
519  //un-escape
520  s.replace(QLatin1String("&lt;"), QLatin1String("<"));
521  s.replace(QLatin1String("&gt;"), QLatin1String(">"));
522  s.replace(QLatin1String("&amp;"), QLatin1String("&"));
523  }
524  resultList << s.trimmed();
525  //qDebug() << s;
526  }
527  b.seek(0);
528  }
529  m_modelData << resultList;
530  }*/
531 }
532 
534 {
536 public:
538  : isComponentComplete(true), size(-1), highestRole(Qt::UserRole)
539  , reply(0), status(QDeclarativeXmlListModel::Null), progress(0.0)
540  , queryId(-1), roleObjects(), redirectCount(0) {}
541 
542 
543  void notifyQueryStarted(bool remoteSource) {
545  progress = remoteSource ? qreal(0.0) : qreal(1.0);
547  errorString.clear();
548  emit q->progressChanged(progress);
549  emit q->statusChanged(status);
550  }
551 
552  void deleteReply() {
554  if (reply) {
555  QObject::disconnect(reply, 0, q, 0);
556  reply->deleteLater();
557  reply = 0;
558  }
559  }
560 
566  int size;
570 
575  int queryId;
578 
580  static void clear_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list);
583 };
584 
585 
587 {
589  if (_this && role) {
590  int i = _this->d_func()->roleObjects.count();
591  _this->d_func()->roleObjects.append(role);
592  if (_this->d_func()->roleNames.contains(role->name())) {
593  qmlInfo(role) << QObject::tr("\"%1\" duplicates a previous role name and will be disabled.").arg(role->name());
594  return;
595  }
596  _this->d_func()->roles.insert(i, _this->d_func()->highestRole);
597  _this->d_func()->roleNames.insert(i, role->name());
598  ++_this->d_func()->highestRole;
599  }
600 }
601 
602 //### clear needs to invalidate any cached data (in data table) as well
603 // (and the model should emit the appropriate signals)
605 {
606  QDeclarativeXmlListModel *_this = static_cast<QDeclarativeXmlListModel *>(list->object);
607  _this->d_func()->roles.clear();
608  _this->d_func()->roleNames.clear();
609  _this->d_func()->roleObjects.clear();
610 }
611 
714 {
715 }
716 
718 {
719 }
720 
730 {
735  return list;
736 }
737 
739 {
742  for (int i = 0; i < roles.size(); ++i) {
743  int role = roles.at(i);
744  int roleIndex = d->roles.indexOf(role);
745  rv.insert(role, roleIndex == -1 ? QVariant() : d->data.value(roleIndex).value(index));
746  }
747  return rv;
748 }
749 
751 {
753  int roleIndex = d->roles.indexOf(role);
754  return (roleIndex == -1) ? QVariant() : d->data.value(roleIndex).value(index);
755 }
756 
765 {
767  return d->size;
768 }
769 
771 {
773  return d->roles;
774 }
775 
777 {
779  int index = d->roles.indexOf(role);
780  if (index == -1)
781  return QString();
782  return d->roleNames.at(index);
783 }
784 
795 {
797  return d->src;
798 }
799 
801 {
803  if (d->src != src) {
804  d->src = src;
805  if (d->xml.isEmpty()) // src is only used if d->xml is not set
806  reload();
808  }
809 }
810 
823 {
825  return d->xml;
826 }
827 
829 {
831  if (d->xml != xml) {
832  d->xml = xml;
833  reload();
834  emit xmlChanged();
835  }
836 }
837 
847 {
849  return d->query;
850 }
851 
853 {
855  if (!query.startsWith(QLatin1Char('/'))) {
856  qmlInfo(this) << QCoreApplication::translate("QDeclarativeXmlRoleList", "An XmlListModel query must start with '/' or \"//\"");
857  return;
858  }
859 
860  if (d->query != query) {
861  d->query = query;
862  reload();
863  emit queryChanged();
864  }
865 }
866 
889 {
891  return d->namespaces;
892 }
893 
895 {
897  if (d->namespaces != declarations) {
898  d->namespaces = declarations;
899  reload();
901  }
902 }
903 
930 {
932 
934  if (index < 0 || index >= count())
935  return sengine->undefinedValue();
936 
937  QScriptValue sv = sengine->newObject();
938  for (int i=0; i<d->roleObjects.count(); i++)
939  sv.setProperty(d->roleObjects[i]->name(), sengine->toScriptValue(d->data.value(i).value(index)));
940  return sv;
941 }
942 
962 {
964  return d->status;
965 }
966 
986 {
988  return d->progress;
989 }
990 
1001 {
1003  return d->errorString;
1004 }
1005 
1007 {
1009  d->isComponentComplete = false;
1010 
1014  connect(queryEngine, SIGNAL(error(void*,QString)),
1015  SLOT(queryError(void*,QString)));
1016 }
1017 
1019 {
1021  d->isComponentComplete = true;
1022  reload();
1023 }
1024 
1042 {
1044 
1045  if (!d->isComponentComplete)
1046  return;
1047 
1049  d->queryId = -1;
1050 
1051  if (d->size < 0)
1052  d->size = 0;
1053 
1054  if (d->reply) {
1055  d->reply->abort();
1056  d->deleteReply();
1057  }
1058 
1059  if (!d->xml.isEmpty()) {
1060  d->queryId = QDeclarativeXmlQueryEngine::instance(qmlEngine(this))->doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects, d->keyRoleResultsCache);
1061  d->notifyQueryStarted(false);
1062 
1063  } else if (d->src.isEmpty()) {
1064  d->queryId = XMLLISTMODEL_CLEAR_ID;
1065  d->notifyQueryStarted(false);
1066  QTimer::singleShot(0, this, SLOT(dataCleared()));
1067 
1068  } else {
1069  d->notifyQueryStarted(true);
1070  QNetworkRequest req(d->src);
1071  req.setRawHeader("Accept", "application/xml,*/*");
1072  d->reply = qmlContext(this)->engine()->networkAccessManager()->get(req);
1073  QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(requestFinished()));
1074  QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)),
1075  this, SLOT(requestProgress(qint64,qint64)));
1076  }
1077 }
1078 
1079 #define XMLLISTMODEL_MAX_REDIRECT 16
1080 
1082 {
1084 
1085  d->redirectCount++;
1086  if (d->redirectCount < XMLLISTMODEL_MAX_REDIRECT) {
1087  QVariant redirect = d->reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
1088  if (redirect.isValid()) {
1089  QUrl url = d->reply->url().resolved(redirect.toUrl());
1090  d->deleteReply();
1091  setSource(url);
1092  return;
1093  }
1094  }
1095  d->redirectCount = 0;
1096 
1097  if (d->reply->error() != QNetworkReply::NoError) {
1098  d->errorString = d->reply->errorString();
1099  d->deleteReply();
1100 
1101  int count = this->count();
1102  d->data.clear();
1103  d->size = 0;
1104  if (count > 0) {
1105  emit itemsRemoved(0, count);
1106  emit countChanged();
1107  }
1108 
1109  d->status = Error;
1110  d->queryId = -1;
1111  emit statusChanged(d->status);
1112  } else {
1113  QByteArray data = d->reply->readAll();
1114  if (data.isEmpty()) {
1115  d->queryId = XMLLISTMODEL_CLEAR_ID;
1116  QTimer::singleShot(0, this, SLOT(dataCleared()));
1117  } else {
1118  d->queryId = QDeclarativeXmlQueryEngine::instance(qmlEngine(this))->doQuery(d->query, d->namespaces, data, &d->roleObjects, d->keyRoleResultsCache);
1119  }
1120  d->deleteReply();
1121 
1122  d->progress = 1.0;
1123  emit progressChanged(d->progress);
1124  }
1125 }
1126 
1128 {
1130  if (d->status == Loading && total > 0) {
1131  d->progress = qreal(received)/total;
1132  emit progressChanged(d->progress);
1133  }
1134 }
1135 
1137 {
1141  r.size = 0;
1142  r.removed << qMakePair(0, count());
1143  r.keyRoleResultsCache = d->keyRoleResultsCache;
1144  queryCompleted(r);
1145 }
1146 
1148 {
1149  // Be extra careful, object may no longer exist, it's just an ID.
1151  for (int i=0; i<d->roleObjects.count(); i++) {
1152  if (d->roleObjects.at(i) == static_cast<QDeclarativeXmlListModelRole*>(object)) {
1153  qmlInfo(d->roleObjects.at(i)) << QObject::tr("invalid query: \"%1\"").arg(error);
1154  return;
1155  }
1156  }
1157  qmlInfo(this) << QObject::tr("invalid query: \"%1\"").arg(error);
1158 }
1159 
1161 {
1163  if (result.queryId != d->queryId)
1164  return;
1165 
1166  int origCount = d->size;
1167  bool sizeChanged = result.size != d->size;
1168 
1169  d->size = result.size;
1170  d->data = result.data;
1171  d->keyRoleResultsCache = result.keyRoleResultsCache;
1172  d->status = Ready;
1173  d->errorString.clear();
1174  d->queryId = -1;
1175 
1176  bool hasKeys = false;
1177  for (int i=0; i<d->roleObjects.count(); i++) {
1178  if (d->roleObjects[i]->isKey()) {
1179  hasKeys = true;
1180  break;
1181  }
1182  }
1183  if (!hasKeys) {
1184  if (!(origCount == 0 && d->size == 0)) {
1185  emit itemsRemoved(0, origCount);
1186  emit itemsInserted(0, d->size);
1187  emit countChanged();
1188  }
1189 
1190  } else {
1191  for (int i=0; i<result.removed.count(); i++)
1192  emit itemsRemoved(result.removed[i].first, result.removed[i].second);
1193  for (int i=0; i<result.inserted.count(); i++)
1194  emit itemsInserted(result.inserted[i].first, result.inserted[i].second);
1195 
1196  if (sizeChanged)
1197  emit countChanged();
1198  }
1199 
1200  emit statusChanged(d->status);
1201 }
1202 
1204 
1205 #include <qdeclarativexmllistmodel.moc>
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
#define XMLLISTMODEL_MAX_REDIRECT
QDeclarativeXmlQueryEngine(QDeclarativeEngine *eng)
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
void evaluateTo(QXmlResultItems *result) const
Starts the evaluation and makes it available in result.
Definition: qxmlquery.cpp:815
QDeclarativeXmlListModel(QObject *parent=0)
virtual QList< int > roles() const
Returns the list of roles for which the list model interface provides data.
void setNamespaceDeclarations(const QString &)
double qreal
Definition: qglobal.h:1193
static void append_role(QDeclarativeListProperty< QDeclarativeXmlListModelRole > *list, QDeclarativeXmlListModelRole *role)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
EventRef event
static QDeclarativeXmlQueryEngine * instance(QDeclarativeEngine *engine)
Q_INVOKABLE QString errorString() const
QDeclarativeParserStatus ** d
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
QDeclarativeXmlQueryThreadObject(QDeclarativeXmlQueryEngine *)
The QAtomicInt class provides platform-independent atomic operations on integers. ...
Definition: qatomic.h:55
Q_INVOKABLE QScriptValue get(int index) const
QList< QDeclarativeXmlListModelRole * > roleObjects
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
void bindVariable(const QXmlName &name, const QXmlItem &value)
Binds the variable name to the value so that $name can be used from within the query to refer to the ...
Definition: qxmlquery.cpp:528
bool open(OpenMode openMode)
Reimplemented Function
Definition: qbuffer.cpp:338
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
#define error(msg)
QXmlItem next()
Returns the next result in the sequence produced by lazy evaluation of the associated query...
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
bool remove(const T &value)
Definition: qset.h:89
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QScriptValue toScriptValue(const T &value)
Creates a QScriptValue with the given value.
The QXmlResultItems class iterates through the results of evaluating an XQuery in QXmlQuery...
#define SLOT(a)
Definition: qobjectdefs.h:226
The QXmlItem class contains either an XML node or an atomic value.
void setQuery(const QString &sourceCode, const QUrl &documentURI=QUrl())
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qxmlquery.cpp:441
T1 first
Definition: qpair.h:65
void unlock()
Unlocks this mutex locker.
Definition: qmutex.h:117
T2 second
Definition: qpair.h:66
static QHash< QDeclarativeEngine *, QDeclarativeXmlQueryEngine * > queryEngines
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
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool isValid() const
Returns true if this query is valid.
Definition: qxmlquery.cpp:885
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
bool ref()
Atomically increments the value of this QAtomicInt.
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
virtual bool event(QEvent *e)
This virtual function receives events to an object and should return true if the event e was recogniz...
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
QDeclarativeXmlQueryThreadObject * m_threadObject
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QPair< int, int > QDeclarativeXmlListRange
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
void addIndexToRangeList(QList< QDeclarativeXmlListRange > *ranges, int index) const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QDeclarativeListProperty< QDeclarativeXmlListModelRole > roles
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
Q_DECLARATIVE_EXPORT QDeclarativeContext * qmlContext(const QObject *)
void itemsRemoved(int index, int count)
Emit this signal when count items are removed at index.
#define Q_D(Class)
Definition: qglobal.h:2482
QDeclarativeXmlQueryEngine * m_queryEngine
void quit()
Tells the thread&#39;s event loop to exit with return code 0 (success).
Definition: qthread.cpp:614
bool seek(qint64 off)
Reimplemented Function
Definition: qbuffer.cpp:384
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
#define Q_Q(Class)
Definition: qglobal.h:2483
virtual QString toString(int role) const
Returns a string description of the specified role.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
void relock()
Relocks an unlocked mutex locker.
Definition: qmutex.h:125
void queryError(void *object, const QString &error)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QScriptEngine class provides an environment for evaluating Qt Script code.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
static bool isEmpty(const char *str)
virtual void classBegin()
Invoked after class creation, but before any properties have been set.
bool contains(const T &value) const
Definition: qset.h:91
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QStringList keyRoleResultsCache
const_iterator insert(const T &value)
Definition: qset.h:179
void run()
The starting point for the thread.
static QVector< Declaration > declarations(const QVector< StyleRule > &styleRules, const QString &part, quint64 pseudoClass=PseudoClass_Unspecified)
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QVariant toAtomicValue() const
If this QXmlItem represents an atomic value, it is converted to an appropriate QVariant and returned...
QScriptValue newObject()
Creates a QtScript object of class Object.
#define XMLLISTMODEL_CLEAR_ID
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
The QListModelInterface class can be subclassed to provide C++ models to QDeclarativeGraphics Views...
QString query() const
__int64 qint64
Definition: qglobal.h:942
void progressChanged(qreal progress)
quint16 values[128]
void queryCompleted(const QDeclarativeXmlQueryResult &)
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
QUrl toUrl() const
Returns the variant as a QUrl if the variant has type() Url ; otherwise returns an invalid QUrl...
Definition: qvariant.cpp:2528
void doSubQueryJob(XmlQueryJob *job, QDeclarativeXmlQueryResult *currentResult)
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
static void clear_role(QDeclarativeListProperty< QDeclarativeXmlListModelRole > *list)
#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
QString namespaceDeclarations() const
QList< void * > roleQueryErrorId
QDeclarativeListProperty< QDeclarativeXmlListModelRole > roleObjects()
int doQuery(QString query, QString namespaces, QByteArray data, QList< QDeclarativeXmlListModelRole *> *roleObjects, QStringList keyRoleResultsCache)
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
QString join(const QString &sep) const
Joins all the string list&#39;s strings into a single string with each element separated by the given sep...
Definition: qstringlist.h:162
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
void setRawHeader(const QByteArray &headerName, const QByteArray &value)
Sets the header headerName to be of value headerValue.
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
virtual void componentComplete()
Invoked after the root component that caused this instantiation has completed construction.
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
The QDeclarativeEngine class provides an environment for instantiating QML components.
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
void start(Priority=InheritPriority)
Begins execution of the thread by calling run().
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
void doQueryJob(XmlQueryJob *job, QDeclarativeXmlQueryResult *currentResult)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
bool wait(unsigned long time=ULONG_MAX)
Blocks the thread until either of these conditions is met:
void itemsInserted(int index, int count)
Emit this signal when count items are inserted at index.
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59
int exec()
Enters the event loop and waits until exit() is called, returning the value that was passed to exit()...
Definition: qthread.cpp:551
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
if(void) toggleToolbarShown
Definition: qnamespace.h:54
void statusChanged(QDeclarativeXmlListModel::Status)
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
quint16 index
QDeclarativeXmlListModel::Status status
QFuture< T > run(Function function,...)
QDeclarativeEngine * engine() const
Return the context&#39;s QDeclarativeEngine, or 0 if the context has no QDeclarativeEngine or the QDeclar...
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QDeclarativeInfo qmlInfo(const QObject *me)
virtual int count() const
Returns the number of data entries in the model.
QNetworkAccessManager * networkAccessManager() const
Returns a common QNetworkAccessManager which can be used by any QML element instantiated by this engi...
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
#define signals
Definition: qobjectdefs.h:69
virtual QHash< int, QVariant > data(int index, const QList< int > &roles=(QList< int >())) const
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
void error(void *, const QString &)
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void queryCompleted(const QDeclarativeXmlQueryResult &)
The QXmlQuery class performs XQueries on XML data, or on non-XML data modeled to look like XML...
Definition: qxmlquery.h:79
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void getValuesOfKeyRoles(const XmlQueryJob &currentJob, QStringList *values, QXmlQuery *query) const
QList< QPair< int, int > > removed
QList< QList< QVariant > > data