42 #include "private/qdeclarativexmllistmodel_p.h" 48 #include <QStringList> 50 #include <QApplication> 53 #include <QXmlResultItems> 54 #include <QXmlNodeModelIndex> 56 #include <QNetworkRequest> 57 #include <QNetworkReply> 61 #include <private/qobject_p.h> 70 #define XMLLISTMODEL_CLEAR_ID 0 247 qRegisterMetaType<QDeclarativeXmlQueryResult>(
"QDeclarativeXmlQueryResult");
250 m_eventLoopQuitHack->moveToThread(
this);
280 for (
int i=0; i<roleObjects->
count(); i++) {
287 if (roleObjects->
at(i)->
isKey())
385 QByteArray xml =
"<dummy:items xmlns:dummy=\"http://qtsotware.com/dummy\">\n" + r.
toUtf8() +
"</dummy:items>";
402 if (item.isAtomicValue())
406 currentJob->
data = xml;
408 currentResult->
size = (count > 0 ? count : 0);
415 if (keysQueries.
count() == 1)
416 keysQuery = currentJob.
prefix + keysQueries[0];
417 else if (keysQueries.
count() > 1)
425 while (!item.isNull()) {
426 values->
append(item.toAtomicValue().toString());
427 item = resultItems.
next();
468 for (
int i=0; i<keyRoleResults.
count(); i++) {
469 if (temp.
count() == i || keyRoleResults[i] != temp[i]) {
470 temp.
insert(i, keyRoleResults[i]);
481 for (
int i = 0; i < queries.
size(); ++i) {
489 while (!item.isNull()) {
490 resultList << item.toAtomicValue();
491 item = resultItems.
next();
498 while (resultList.
count() < currentResult->
size)
500 currentResult->
data << resultList;
538 : isComponentComplete(true), size(-1), highestRole(
Qt::
UserRole)
540 , queryId(-1), roleObjects(), redirectCount(0) {}
545 progress = remoteSource ?
qreal(0.0) :
qreal(1.0);
548 emit q->progressChanged(progress);
556 reply->deleteLater();
592 if (_this->d_func()->roleNames.contains(role->
name())) {
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;
608 _this->d_func()->roleNames.clear();
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));
753 int roleIndex =
d->roles.indexOf(role);
754 return (roleIndex == -1) ?
QVariant() :
d->data.value(roleIndex).value(index);
779 int index =
d->roles.indexOf(role);
782 return d->roleNames.at(index);
805 if (
d->xml.isEmpty())
860 if (
d->query != query) {
891 return d->namespaces;
897 if (
d->namespaces != declarations) {
934 if (index < 0 || index >=
count())
938 for (
int i=0; i<
d->roleObjects.count(); i++)
1003 return d->errorString;
1009 d->isComponentComplete =
false;
1021 d->isComponentComplete =
true;
1045 if (!
d->isComponentComplete)
1059 if (!
d->xml.isEmpty()) {
1061 d->notifyQueryStarted(
false);
1063 }
else if (
d->src.isEmpty()) {
1065 d->notifyQueryStarted(
false);
1069 d->notifyQueryStarted(
true);
1079 #define XMLLISTMODEL_MAX_REDIRECT 16 1089 QUrl url =
d->reply->url().resolved(redirect.
toUrl());
1095 d->redirectCount = 0;
1098 d->errorString =
d->reply->errorString();
1130 if (
d->status ==
Loading && total > 0) {
1131 d->progress =
qreal(received)/total;
1151 for (
int i=0; i<
d->roleObjects.count(); i++) {
1166 int origCount =
d->size;
1167 bool sizeChanged = result.
size !=
d->size;
1169 d->size = result.
size;
1170 d->data = result.
data;
1173 d->errorString.clear();
1176 bool hasKeys =
false;
1177 for (
int i=0; i<
d->roleObjects.count(); i++) {
1178 if (
d->roleObjects[i]->isKey()) {
1184 if (!(origCount == 0 &&
d->size == 0)) {
1205 #include <qdeclarativexmllistmodel.moc> The QVariant class acts like a union for the most common Qt data types.
#define XMLLISTMODEL_MAX_REDIRECT
QDeclarativeXmlQueryEngine(QDeclarativeEngine *eng)
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
void setXml(const QString &)
void evaluateTo(QXmlResultItems *result) const
Starts the evaluation and makes it available in result.
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 &)
QList< XmlQueryJob > m_jobs
static void append_role(QDeclarativeListProperty< QDeclarativeXmlListModelRole > *list, QDeclarativeXmlListModelRole *role)
#define QT_END_NAMESPACE
This macro expands to.
void lock()
Locks the mutex.
void notifyQueryStarted(bool remoteSource)
The QMutex class provides access serialization between threads.
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.
QDeclarativeXmlQueryThreadObject(QDeclarativeXmlQueryEngine *)
QDeclarativeXmlListModelPrivate()
The QAtomicInt class provides platform-independent atomic operations on integers. ...
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 ...
bool open(OpenMode openMode)
Reimplemented Function
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
QStringList keyRoleResultsCache
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.
bool remove(const T &value)
The QByteArray class provides an array of bytes.
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...
QObject * m_eventLoopQuitHack
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...
void unlock()
Unlocks this mutex locker.
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.
void insert(int i, const T &t)
Inserts value at index position i in the list.
static LibLoadStatus status
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.
int count(const T &t) const
Returns the number of occurrences of value in the list.
bool ref()
Atomically increments the value of this QAtomicInt.
The QBuffer class provides a QIODevice interface for a QByteArray.
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.
The QString class provides a Unicode character string.
QDeclarativeXmlQueryThreadObject * m_threadObject
T * qobject_cast(QObject *object)
QPair< int, int > QDeclarativeXmlListRange
The QHash class is a template class that provides a hash-table-based dictionary.
void addIndexToRangeList(QList< QDeclarativeXmlListRange > *ranges, int index) const
The QObject class is the base class of all Qt objects.
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...
Q_DECLARATIVE_EXPORT QDeclarativeContext * qmlContext(const QObject *)
void itemsRemoved(int index, int count)
Emit this signal when count items are removed at index.
QDeclarativeXmlQueryEngine * m_queryEngine
void quit()
Tells the thread's event loop to exit with return code 0 (success).
bool seek(qint64 off)
Reimplemented Function
const T value(const Key &key) const
Returns the value associated with the key.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
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 ...
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
void relock()
Relocks an unlocked mutex locker.
void queryError(void *object, const QString &error)
QStringList keyRoleQueries
void append(const T &t)
Inserts value at the end of the list.
The QScriptEngine class provides an environment for evaluating Qt Script code.
#define QT_BEGIN_NAMESPACE
This macro expands to.
void requestProgress(qint64, qint64)
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
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...
void namespaceDeclarationsChanged()
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QSet< int > m_cancelledJobs
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
QStringList keyRoleResultsCache
const_iterator insert(const T &value)
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...
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.
The QListModelInterface class can be subclassed to provide C++ models to QDeclarativeGraphics Views...
void progressChanged(qreal progress)
void processQuery(XmlQueryJob *job)
void queryCompleted(const QDeclarativeXmlQueryResult &)
void setQuery(const QString &)
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...
void doSubQueryJob(XmlQueryJob *job, QDeclarativeXmlQueryResult *currentResult)
void unlock()
Unlocks the mutex.
static void clear_role(QDeclarativeListProperty< QDeclarativeXmlListModelRole > *list)
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.
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.
QString join(const QString &sep) const
Joins all the string list's strings into a single string with each element separated by the given sep...
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...
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's property with the given name to the given value.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
#define Q_DECLARE_PUBLIC(Class)
virtual void componentComplete()
Invoked after the root component that caused this instantiation has completed construction.
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
static QMutex queryEnginesMutex
The QDeclarativeEngine class provides an environment for instantiating QML components.
void clear()
Clears the contents of the string and makes it empty.
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
QList< QList< QVariant > > data
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
void doQueryJob(XmlQueryJob *job, QDeclarativeXmlQueryResult *currentResult)
QObject * parent() const
Returns a pointer to the parent object.
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)
bool singleShot
This static function calls a slot after a given time interval.
int exec()
Enters the event loop and waits until exit() is called, returning the value that was passed to exit()...
T & last()
Returns a reference to the last item in the list.
QStringList keyRoleResultsCache
int size() const
Returns the number of items in the list.
if(void) toggleToolbarShown
void statusChanged(QDeclarativeXmlListModel::Status)
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
~QDeclarativeXmlQueryEngine()
QDeclarativeXmlListModel::Status status
QFuture< T > run(Function function,...)
QDeclarativeEngine * engine() const
Return the context'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.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
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...
virtual QHash< int, QVariant > data(int index, const QList< int > &roles=(QList< int >())) const
~QDeclarativeXmlListModel()
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
The QThread class provides a platform-independent way to manage threads.
The QScriptValue class acts as a container for the Qt Script data types.
void error(void *, const QString &)
void setSource(const QUrl &)
void deleteLater()
Schedules this object for deletion.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
void queryCompleted(const QDeclarativeXmlQueryResult &)
QDeclarativeEngine * m_engine
The QXmlQuery class performs XQueries on XML data, or on non-XML data modeled to look like XML...
The QList class is a template class that provides lists.
void getValuesOfKeyRoles(const XmlQueryJob ¤tJob, QStringList *values, QXmlQuery *query) const
QList< QPair< int, int > > removed
QList< QList< QVariant > > data