Qt 4.8
Signals | Public Functions | Static Public Functions | Protected Functions | Private Functions | Properties | Static Private Attributes | List of all members
QDeclarativeXmlQueryEngine Class Reference
Inheritance diagram for QDeclarativeXmlQueryEngine:
QThread QObject

Signals

void error (void *, const QString &)
 
void queryCompleted (const QDeclarativeXmlQueryResult &)
 
- Signals inherited from QThread
void finished ()
 This signal is emitted when the thread has finished executing. More...
 
void started ()
 This signal is emitted when the thread starts executing. More...
 
void terminated ()
 This signal is emitted when the thread is terminated. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

void abort (int id)
 
int doQuery (QString query, QString namespaces, QByteArray data, QList< QDeclarativeXmlListModelRole *> *roleObjects, QStringList keyRoleResultsCache)
 
void processJobs ()
 
 QDeclarativeXmlQueryEngine (QDeclarativeEngine *eng)
 
 ~QDeclarativeXmlQueryEngine ()
 
- Public Functions inherited from QThread
void exit (int retcode=0)
 Tells the thread's event loop to exit with a return code. More...
 
bool isFinished () const
 Returns true if the thread is finished; otherwise returns false. More...
 
bool isRunning () const
 Returns true if the thread is running; otherwise returns false. More...
 
Priority priority () const
 Returns the priority for a running thread. More...
 
 QThread (QObject *parent=0)
 Constructs a new QThread to manage a new thread. More...
 
void setPriority (Priority priority)
 This function sets the priority for a running thread. More...
 
void setStackSize (uint stackSize)
 Sets the maximum stack size for the thread to stackSize. More...
 
uint stackSize () const
 Returns the maximum stack size for the thread (if set with setStackSize()); otherwise returns zero. More...
 
bool wait (unsigned long time=ULONG_MAX)
 Blocks the thread until either of these conditions is met: More...
 
 ~QThread ()
 Destroys the QThread. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Static Public Functions

static QDeclarativeXmlQueryEngineinstance (QDeclarativeEngine *engine)
 
- Static Public Functions inherited from QThread
static QThreadcurrentThread ()
 Returns a pointer to a QThread which manages the currently executing thread. More...
 
static Qt::HANDLE currentThreadId ()
 Returns the thread handle of the currently executing thread. More...
 
static int idealThreadCount ()
 Returns the ideal number of threads that can be run on the system. More...
 
static void yieldCurrentThread ()
 Yields execution of the current thread to another runnable thread, if any. More...
 
- Static Public Functions inherited from QObject
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 receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
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. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 

Protected Functions

void run ()
 The starting point for the thread. More...
 
- Protected Functions inherited from QThread
int exec ()
 Enters the event loop and waits until exit() is called, returning the value that was passed to exit(). More...
 
 QThread (QThreadPrivate &dd, QObject *parent=0)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Functions

void addIndexToRangeList (QList< QDeclarativeXmlListRange > *ranges, int index) const
 
void doQueryJob (XmlQueryJob *job, QDeclarativeXmlQueryResult *currentResult)
 
void doSubQueryJob (XmlQueryJob *job, QDeclarativeXmlQueryResult *currentResult)
 
void getValuesOfKeyRoles (const XmlQueryJob &currentJob, QStringList *values, QXmlQuery *query) const
 
void processQuery (XmlQueryJob *job)
 

Properties

QSet< int > m_cancelledJobs
 
QDeclarativeEnginem_engine
 
QObjectm_eventLoopQuitHack
 
QList< XmlQueryJobm_jobs
 
QMutex m_mutex
 
QAtomicInt m_queryIds
 
QDeclarativeXmlQueryThreadObjectm_threadObject
 

Static Private Attributes

static QHash< QDeclarativeEngine *, QDeclarativeXmlQueryEngine * > queryEngines
 
static QMutex queryEnginesMutex
 

Additional Inherited Members

- Public Types inherited from QThread
enum  Priority {
  IdlePriority, LowestPriority, LowPriority, NormalPriority,
  HighPriority, HighestPriority, TimeCriticalPriority, InheritPriority
}
 This enum type indicates how the operating system should schedule newly created threads. More...
 
- Public Slots inherited from QThread
void quit ()
 Tells the thread's event loop to exit with return code 0 (success). More...
 
void start (Priority=InheritPriority)
 Begins execution of the thread by calling run(). More...
 
void terminate ()
 Terminates the execution of the thread. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Static Protected Functions inherited from QThread
static void msleep (unsigned long)
 Forces the current thread to sleep for msecs milliseconds. More...
 
static void setTerminationEnabled (bool enabled=true)
 Enables or disables termination of the current thread based on the enabled parameter. More...
 
static void sleep (unsigned long)
 Forces the current thread to sleep for secs seconds. More...
 
static void usleep (unsigned long)
 Forces the current thread to sleep for usecs microseconds. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 178 of file qdeclarativexmllistmodel.cpp.

Constructors and Destructors

◆ QDeclarativeXmlQueryEngine()

QDeclarativeXmlQueryEngine::QDeclarativeXmlQueryEngine ( QDeclarativeEngine eng)

Definition at line 244 of file qdeclarativexmllistmodel.cpp.

Referenced by instance().

246 {
247  qRegisterMetaType<QDeclarativeXmlQueryResult>("QDeclarativeXmlQueryResult");
248 
250  m_eventLoopQuitHack->moveToThread(this);
251  connect(m_eventLoopQuitHack, SIGNAL(destroyed(QObject*)), SLOT(quit()), Qt::DirectConnection);
253 }
QThread(QObject *parent=0)
Constructs a new QThread to manage a new thread.
Definition: qthread.cpp:433
#define SLOT(a)
Definition: qobjectdefs.h:226
QDeclarativeXmlQueryThreadObject * m_threadObject
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void quit()
Tells the thread&#39;s event loop to exit with return code 0 (success).
Definition: qthread.cpp:614
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
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
#define XMLLISTMODEL_CLEAR_ID
void start(Priority=InheritPriority)
Begins execution of the thread by calling run().
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ ~QDeclarativeXmlQueryEngine()

QDeclarativeXmlQueryEngine::~QDeclarativeXmlQueryEngine ( )

Definition at line 255 of file qdeclarativexmllistmodel.cpp.

256 {
260 
262  wait();
263 }
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
static QHash< QDeclarativeEngine *, QDeclarativeXmlQueryEngine * > queryEngines
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
bool wait(unsigned long time=ULONG_MAX)
Blocks the thread until either of these conditions is met:
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145

Functions

◆ abort()

void QDeclarativeXmlQueryEngine::abort ( int  id)

Definition at line 301 of file qdeclarativexmllistmodel.cpp.

Referenced by QDeclarativeXmlListModel::reload().

302 {
303  QMutexLocker ml(&m_mutex);
304  if (id != -1)
306 }
const_iterator insert(const T &value)
Definition: qset.h:179
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ addIndexToRangeList()

void QDeclarativeXmlQueryEngine::addIndexToRangeList ( QList< QDeclarativeXmlListRange > *  ranges,
int  index 
) const
private

Definition at line 432 of file qdeclarativexmllistmodel.cpp.

Referenced by doSubQueryJob().

432  {
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 }
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
quint16 index

◆ doQuery()

int QDeclarativeXmlQueryEngine::doQuery ( QString  query,
QString  namespaces,
QByteArray  data,
QList< QDeclarativeXmlListModelRole *> *  roleObjects,
QStringList  keyRoleResultsCache 
)

Definition at line 265 of file qdeclarativexmllistmodel.cpp.

Referenced by QDeclarativeXmlListModel::reload(), and QDeclarativeXmlListModel::requestFinished().

265  {
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 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
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 QString class provides a Unicode character string.
Definition: qstring.h:83
QDeclarativeXmlQueryThreadObject * m_threadObject
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QStringList keyRoleResultsCache
static const char * data(const QByteArray &arr)
QList< void * > roleQueryErrorId
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284

◆ doQueryJob()

void QDeclarativeXmlQueryEngine::doQueryJob ( XmlQueryJob job,
QDeclarativeXmlQueryResult currentResult 
)
private

Definition at line 372 of file qdeclarativexmllistmodel.cpp.

Referenced by processQuery().

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);
387  b.open(QIODevice::ReadOnly);
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 }
void evaluateTo(QXmlResultItems *result) const
Starts the evaluation and makes it available in result.
Definition: qxmlquery.cpp:815
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
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
QXmlItem next()
Returns the next result in the sequence produced by lazy evaluation of the associated query...
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QXmlResultItems class iterates through the results of evaluating an XQuery in QXmlQuery...
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
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
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
QVariant toAtomicValue() const
If this QXmlItem represents an atomic value, it is converted to an appropriate QVariant and returned...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
The QXmlQuery class performs XQueries on XML data, or on non-XML data modeled to look like XML...
Definition: qxmlquery.h:79

◆ doSubQueryJob()

void QDeclarativeXmlQueryEngine::doSubQueryJob ( XmlQueryJob job,
QDeclarativeXmlQueryResult currentResult 
)
private

Definition at line 441 of file qdeclarativexmllistmodel.cpp.

Referenced by processQuery().

442 {
443  Q_ASSERT(currentJob->queryId != -1);
444 
445  QBuffer b(&currentJob->data);
446  b.open(QIODevice::ReadOnly);
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 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void evaluateTo(QXmlResultItems *result) const
Starts the evaluation and makes it available in result.
Definition: qxmlquery.cpp:815
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
QXmlItem next()
Returns the next result in the sequence produced by lazy evaluation of the associated query...
The QXmlResultItems class iterates through the results of evaluating an XQuery in QXmlQuery...
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
QList< QPair< int, int > > inserted
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
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
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
void addIndexToRangeList(QList< QDeclarativeXmlListRange > *ranges, int index) const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static bool isEmpty(const char *str)
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
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
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void error(void *, const QString &)
The QXmlQuery class performs XQueries on XML data, or on non-XML data modeled to look like XML...
Definition: qxmlquery.h:79
void getValuesOfKeyRoles(const XmlQueryJob &currentJob, QStringList *values, QXmlQuery *query) const
QList< QPair< int, int > > removed
QList< QList< QVariant > > data

◆ error

void QDeclarativeXmlQueryEngine::error ( void *  ,
const QString  
)
signal

Referenced by doSubQueryJob().

◆ getValuesOfKeyRoles()

void QDeclarativeXmlQueryEngine::getValuesOfKeyRoles ( const XmlQueryJob currentJob,
QStringList values,
QXmlQuery query 
) const
private

Definition at line 411 of file qdeclarativexmllistmodel.cpp.

Referenced by doSubQueryJob().

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 }
void evaluateTo(QXmlResultItems *result) const
Starts the evaluation and makes it available in result.
Definition: qxmlquery.cpp:815
QXmlItem next()
Returns the next result in the sequence produced by lazy evaluation of the associated query...
The QXmlResultItems class iterates through the results of evaluating an XQuery in QXmlQuery...
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
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
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
if(void) toggleToolbarShown

◆ instance()

QDeclarativeXmlQueryEngine * QDeclarativeXmlQueryEngine::instance ( QDeclarativeEngine engine)
static

Definition at line 342 of file qdeclarativexmllistmodel.cpp.

Referenced by QDeclarativeXmlListModel::classBegin(), QDeclarativeXmlListModel::reload(), and QDeclarativeXmlListModel::requestFinished().

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 }
QDeclarativeXmlQueryEngine(QDeclarativeEngine *eng)
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
static QHash< QDeclarativeEngine *, QDeclarativeXmlQueryEngine * > queryEngines
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296

◆ processJobs()

void QDeclarativeXmlQueryEngine::processJobs ( )

Definition at line 321 of file qdeclarativexmllistmodel.cpp.

Referenced by QDeclarativeXmlQueryThreadObject::event(), and run().

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 }
bool remove(const T &value)
Definition: qset.h:89
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492

◆ processQuery()

void QDeclarativeXmlQueryEngine::processQuery ( XmlQueryJob job)
private

Definition at line 355 of file qdeclarativexmllistmodel.cpp.

Referenced by processJobs().

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 }
bool remove(const T &value)
Definition: qset.h:89
bool contains(const T &value) const
Definition: qset.h:91
#define emit
Definition: qobjectdefs.h:76
void doSubQueryJob(XmlQueryJob *job, QDeclarativeXmlQueryResult *currentResult)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void doQueryJob(XmlQueryJob *job, QDeclarativeXmlQueryResult *currentResult)
void queryCompleted(const QDeclarativeXmlQueryResult &)

◆ queryCompleted

void QDeclarativeXmlQueryEngine::queryCompleted ( const QDeclarativeXmlQueryResult )
signal

Referenced by processQuery().

◆ run()

void QDeclarativeXmlQueryEngine::run ( void  )
protectedvirtual

The starting point for the thread.

After calling start(), the newly created thread calls this function. The default implementation simply calls exec().

You can reimplement this function to facilitate advanced thread management. Returning from this method will end the execution of the thread.

See also
start() wait()

Reimplemented from QThread.

Definition at line 308 of file qdeclarativexmllistmodel.cpp.

309 {
310  m_mutex.lock();
312  m_mutex.unlock();
313 
314  processJobs();
315  exec();
316 
317  delete m_threadObject;
318  m_threadObject = 0;
319 }
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
QDeclarativeXmlQueryThreadObject * m_threadObject
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
int exec()
Enters the event loop and waits until exit() is called, returning the value that was passed to exit()...
Definition: qthread.cpp:551

Properties

◆ m_cancelledJobs

QSet<int> QDeclarativeXmlQueryEngine::m_cancelledJobs
private

Definition at line 209 of file qdeclarativexmllistmodel.cpp.

Referenced by abort(), processJobs(), and processQuery().

◆ m_engine

QDeclarativeEngine* QDeclarativeXmlQueryEngine::m_engine
private

Definition at line 212 of file qdeclarativexmllistmodel.cpp.

Referenced by ~QDeclarativeXmlQueryEngine().

◆ m_eventLoopQuitHack

QObject* QDeclarativeXmlQueryEngine::m_eventLoopQuitHack
private

◆ m_jobs

QList<XmlQueryJob> QDeclarativeXmlQueryEngine::m_jobs
private

Definition at line 208 of file qdeclarativexmllistmodel.cpp.

Referenced by doQuery(), and processJobs().

◆ m_mutex

QMutex QDeclarativeXmlQueryEngine::m_mutex
private

Definition at line 206 of file qdeclarativexmllistmodel.cpp.

Referenced by abort(), doQuery(), processJobs(), processQuery(), and run().

◆ m_queryIds

QAtomicInt QDeclarativeXmlQueryEngine::m_queryIds
private

Definition at line 210 of file qdeclarativexmllistmodel.cpp.

Referenced by doQuery().

◆ m_threadObject

QDeclarativeXmlQueryThreadObject* QDeclarativeXmlQueryEngine::m_threadObject
private

Definition at line 207 of file qdeclarativexmllistmodel.cpp.

Referenced by doQuery(), and run().

◆ queryEngines

QHash< QDeclarativeEngine *, QDeclarativeXmlQueryEngine * > QDeclarativeXmlQueryEngine::queryEngines
staticprivate

Definition at line 215 of file qdeclarativexmllistmodel.cpp.

Referenced by instance(), and ~QDeclarativeXmlQueryEngine().

◆ queryEnginesMutex

QMutex QDeclarativeXmlQueryEngine::queryEnginesMutex
staticprivate

Definition at line 216 of file qdeclarativexmllistmodel.cpp.

Referenced by instance(), and ~QDeclarativeXmlQueryEngine().


The documentation for this class was generated from the following file: