summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-03-08 23:38:41 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-03-08 23:38:41 (GMT)
commitd4abbfdd1959a65ecfb997c962aa8ea132c77eaf (patch)
tree75701bef894bcfb24fa2b13955082beeb58fde4a /src/declarative
parentbaed547d0bccabf3ec92cafb54b6642d81c854f0 (diff)
downloadQt-d4abbfdd1959a65ecfb997c962aa8ea132c77eaf.zip
Qt-d4abbfdd1959a65ecfb997c962aa8ea132c77eaf.tar.gz
Qt-d4abbfdd1959a65ecfb997c962aa8ea132c77eaf.tar.bz2
Use one thread for all instances.
Task-number: QT-2831
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index 53e08b0..49dbb27 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -61,9 +61,6 @@
QT_BEGIN_NAMESPACE
-
-
-
typedef QPair<int, int> QDeclarativeXmlListRange;
/*!
@@ -114,9 +111,6 @@ class QDeclarativeXmlQuery : public QThread
{
Q_OBJECT
public:
- QDeclarativeXmlQuery(QObject *parent=0)
- : QThread(parent), m_quit(false), m_restart(false), m_abort(false), m_queryId(0) {
- }
~QDeclarativeXmlQuery() {
m_mutex.lock();
m_quit = true;
@@ -126,6 +120,11 @@ public:
wait();
}
+ static QDeclarativeXmlQuery *instance() {
+ static QDeclarativeXmlQuery *query = new QDeclarativeXmlQuery;
+ return query;
+ }
+
void abort() {
QMutexLocker locker(&m_mutex);
m_abort = true;
@@ -164,6 +163,11 @@ public:
return m_removedItemRanges;
}
+private:
+ QDeclarativeXmlQuery(QObject *parent=0)
+ : QThread(parent), m_quit(false), m_restart(false), m_abort(false), m_queryId(0) {
+ }
+
Q_SIGNALS:
void queryCompleted(int queryId, int size);
@@ -213,6 +217,8 @@ private:
QList<QDeclarativeXmlListRange> m_removedItemRanges;
};
+//Q_GLOBAL_STATIC(QDeclarativeXmlQuery, QDeclarativeXmlQuery::instance());
+
void QDeclarativeXmlQuery::doQueryJob()
{
QString r;
@@ -404,7 +410,6 @@ public:
QNetworkReply *reply;
QDeclarativeXmlListModel::Status status;
qreal progress;
- QDeclarativeXmlQuery qmlXmlQuery;
int queryId;
QList<QDeclarativeXmlListModelRole *> roleObjects;
static void append_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list, QDeclarativeXmlListModelRole *role);
@@ -488,8 +493,7 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla
QDeclarativeXmlListModel::QDeclarativeXmlListModel(QObject *parent)
: QListModelInterface(*(new QDeclarativeXmlListModelPrivate), parent)
{
- Q_D(QDeclarativeXmlListModel);
- connect(&d->qmlXmlQuery, SIGNAL(queryCompleted(int,int)),
+ connect(QDeclarativeXmlQuery::instance(), SIGNAL(queryCompleted(int,int)),
this, SLOT(queryCompleted(int,int)));
}
@@ -722,7 +726,7 @@ void QDeclarativeXmlListModel::reload()
if (!d->isComponentComplete)
return;
- d->qmlXmlQuery.abort();
+ QDeclarativeXmlQuery::instance()->abort();
d->queryId = -1;
int count = d->size;
@@ -754,7 +758,7 @@ void QDeclarativeXmlListModel::reload()
}
if (!d->xml.isEmpty()) {
- d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects);
+ d->queryId = QDeclarativeXmlQuery::instance()->doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects);
d->progress = 1.0;
d->status = Ready;
emit progressChanged(d->progress);
@@ -785,7 +789,7 @@ void QDeclarativeXmlListModel::requestFinished()
} else {
d->status = Ready;
QByteArray data = d->reply->readAll();
- d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, data, &d->roleObjects);
+ d->queryId = QDeclarativeXmlQuery::instance()->doQuery(d->query, d->namespaces, data, &d->roleObjects);
disconnect(d->reply, 0, this, 0);
d->reply->deleteLater();
d->reply = 0;
@@ -811,10 +815,10 @@ void QDeclarativeXmlListModel::queryCompleted(int id, int size)
return;
bool sizeChanged = size != d->size;
d->size = size;
- d->data = d->qmlXmlQuery.modelData();
+ d->data = QDeclarativeXmlQuery::instance()->modelData();
- QList<QDeclarativeXmlListRange> removed = d->qmlXmlQuery.removedItemRanges();
- QList<QDeclarativeXmlListRange> inserted = d->qmlXmlQuery.insertedItemRanges();
+ QList<QDeclarativeXmlListRange> removed = QDeclarativeXmlQuery::instance()->removedItemRanges();
+ QList<QDeclarativeXmlListRange> inserted = QDeclarativeXmlQuery::instance()->insertedItemRanges();
for (int i=0; i<removed.count(); i++)
emit itemsRemoved(removed[i].first, removed[i].second);