Cleanup: Merge QQmlDataLoader and QQmlTypeLoader

There exists only one sub-class of QQmlDataLoader and there are no virtual
functions.

This also clears up a confusion reported in Jira that suggested QQmlDataLoader
should get a virtual destructor as it is being subclassed and somebody might
have a pointer only to a QQmlDataLoader and deleting that would not do proper
polymorphic destruction.

Change-Id: I34611be5a95522bc85a87fb7df97b6d1de7a3d37
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Reviewed-by: Christopher Adams <chris.adams@jollamobile.com>
This commit is contained in:
Simon Hausmann 2014-12-08 15:48:17 +01:00 committed by Simon Hausmann
parent 3adcf75c6c
commit 3228864f7b
3 changed files with 129 additions and 150 deletions

View File

@ -675,9 +675,9 @@ void QQmlComponentPrivate::loadUrl(const QUrl &newUrl, QQmlComponent::Compilatio
emit q->progressChanged(progress);
}
QQmlDataLoader::Mode loaderMode = (mode == QQmlComponent::Asynchronous)
? QQmlDataLoader::Asynchronous
: QQmlDataLoader::PreferSynchronous;
QQmlTypeLoader::Mode loaderMode = (mode == QQmlComponent::Asynchronous)
? QQmlTypeLoader::Asynchronous
: QQmlTypeLoader::PreferSynchronous;
QQmlTypeData *data = QQmlEnginePrivate::get(engine)->typeLoader.getType(url, loaderMode);

View File

@ -79,8 +79,8 @@
#ifdef DATABLOB_DEBUG
#define ASSERT_MAINTHREAD() do { if(m_thread->isThisThread()) qFatal("QQmlDataLoader: Caller not in main thread"); } while(false)
#define ASSERT_LOADTHREAD() do { if(!m_thread->isThisThread()) qFatal("QQmlDataLoader: Caller not in load thread"); } while(false)
#define ASSERT_MAINTHREAD() do { if (m_thread->isThisThread()) qFatal("QQmlTypeLoader: Caller not in main thread"); } while (false)
#define ASSERT_LOADTHREAD() do { if (!m_thread->isThisThread()) qFatal("QQmlTypeLoader: Caller not in load thread"); } while (false)
#define ASSERT_CALLBACK() do { if(!m_manager || !m_manager->m_thread->isThisThread()) qFatal("QQmlDataBlob: An API call was made outside a callback"); } while(false)
#else
@ -108,14 +108,14 @@ namespace {
// This is a lame object that we need to ensure that slots connected to
// QNetworkReply get called in the correct thread (the loader thread).
// As QQmlDataLoader lives in the main thread, and we can't use
// As QQmlTypeLoader lives in the main thread, and we can't use
// Qt::DirectConnection connections from a QNetworkReply (because then
// sender() wont work), we need to insert this object in the middle.
class QQmlDataLoaderNetworkReplyProxy : public QObject
class QQmlTypeLoaderNetworkReplyProxy : public QObject
{
Q_OBJECT
public:
QQmlDataLoaderNetworkReplyProxy(QQmlDataLoader *l);
QQmlTypeLoaderNetworkReplyProxy(QQmlTypeLoader *l);
public slots:
void finished();
@ -123,17 +123,17 @@ public slots:
void manualFinished(QNetworkReply*);
private:
QQmlDataLoader *l;
QQmlTypeLoader *l;
};
class QQmlDataLoaderThread : public QQmlThread
class QQmlTypeLoaderThread : public QQmlThread
{
typedef QQmlDataLoaderThread This;
typedef QQmlTypeLoaderThread This;
public:
QQmlDataLoaderThread(QQmlDataLoader *loader);
QQmlTypeLoaderThread(QQmlTypeLoader *loader);
QNetworkAccessManager *networkAccessManager() const;
QQmlDataLoaderNetworkReplyProxy *networkReplyProxy() const;
QQmlTypeLoaderNetworkReplyProxy *networkReplyProxy() const;
void load(QQmlDataBlob *b);
void loadAsync(QQmlDataBlob *b);
@ -156,18 +156,18 @@ private:
void callDownloadProgressChangedMain(QQmlDataBlob *b, qreal p);
void initializeEngineMain(QQmlExtensionInterface *iface, const char *uri);
QQmlDataLoader *m_loader;
QQmlTypeLoader *m_loader;
mutable QNetworkAccessManager *m_networkAccessManager;
mutable QQmlDataLoaderNetworkReplyProxy *m_networkReplyProxy;
mutable QQmlTypeLoaderNetworkReplyProxy *m_networkReplyProxy;
};
QQmlDataLoaderNetworkReplyProxy::QQmlDataLoaderNetworkReplyProxy(QQmlDataLoader *l)
QQmlTypeLoaderNetworkReplyProxy::QQmlTypeLoaderNetworkReplyProxy(QQmlTypeLoader *l)
: l(l)
{
}
void QQmlDataLoaderNetworkReplyProxy::finished()
void QQmlTypeLoaderNetworkReplyProxy::finished()
{
Q_ASSERT(sender());
Q_ASSERT(qobject_cast<QNetworkReply *>(sender()));
@ -175,7 +175,7 @@ void QQmlDataLoaderNetworkReplyProxy::finished()
l->networkReplyFinished(reply);
}
void QQmlDataLoaderNetworkReplyProxy::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
void QQmlTypeLoaderNetworkReplyProxy::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
Q_ASSERT(sender());
Q_ASSERT(qobject_cast<QNetworkReply *>(sender()));
@ -184,7 +184,7 @@ void QQmlDataLoaderNetworkReplyProxy::downloadProgress(qint64 bytesReceived, qin
}
// This function is for when you want to shortcut the signals and call directly
void QQmlDataLoaderNetworkReplyProxy::manualFinished(QNetworkReply *reply)
void QQmlTypeLoaderNetworkReplyProxy::manualFinished(QNetworkReply *reply)
{
qint64 replySize = reply->size();
l->networkReplyProgress(reply, replySize, replySize);
@ -194,12 +194,12 @@ void QQmlDataLoaderNetworkReplyProxy::manualFinished(QNetworkReply *reply)
/*!
\class QQmlDataBlob
\brief The QQmlDataBlob encapsulates a data request that can be issued to a QQmlDataLoader.
\brief The QQmlDataBlob encapsulates a data request that can be issued to a QQmlTypeLoader.
\internal
QQmlDataBlob's are loaded by a QQmlDataLoader. The user creates the QQmlDataBlob
and then calls QQmlDataLoader::load() or QQmlDataLoader::loadWithStaticData() to load it.
The QQmlDataLoader invokes callbacks on the QQmlDataBlob as data becomes available.
QQmlDataBlob's are loaded by a QQmlTypeLoader. The user creates the QQmlDataBlob
and then calls QQmlTypeLoader::load() or QQmlTypeLoader::loadWithStaticData() to load it.
The QQmlTypeLoader invokes callbacks on the QQmlDataBlob as data becomes available.
*/
/*!
@ -208,7 +208,7 @@ The QQmlDataLoader invokes callbacks on the QQmlDataBlob as data becomes availab
This enum describes the status of the data blob.
\list
\li Null The blob has not yet been loaded by a QQmlDataLoader
\li Null The blob has not yet been loaded by a QQmlTypeLoader
\li Loading The blob is loading network data. The QQmlDataBlob::setData() callback has not yet been
invoked or has not yet returned.
\li WaitingForDependencies The blob is waiting for dependencies to be done before continueing. This status
@ -252,7 +252,7 @@ QQmlDataBlob::~QQmlDataBlob()
Sets the manager, and does stuff like selection which needs access to the manager.
Must be called before loading can occur.
*/
void QQmlDataBlob::startLoading(QQmlDataLoader *manager)
void QQmlDataBlob::startLoading(QQmlTypeLoader *manager)
{
Q_ASSERT(status() == QQmlDataBlob::Null);
Q_ASSERT(m_manager == 0);
@ -725,86 +725,86 @@ void QQmlDataBlob::ThreadData::setProgress(quint8 v)
}
}
QQmlDataLoaderThread::QQmlDataLoaderThread(QQmlDataLoader *loader)
QQmlTypeLoaderThread::QQmlTypeLoaderThread(QQmlTypeLoader *loader)
: m_loader(loader), m_networkAccessManager(0), m_networkReplyProxy(0)
{
// Do that after initializing all the members.
startup();
}
QNetworkAccessManager *QQmlDataLoaderThread::networkAccessManager() const
QNetworkAccessManager *QQmlTypeLoaderThread::networkAccessManager() const
{
Q_ASSERT(isThisThread());
if (!m_networkAccessManager) {
m_networkAccessManager = QQmlEnginePrivate::get(m_loader->engine())->createNetworkAccessManager(0);
m_networkReplyProxy = new QQmlDataLoaderNetworkReplyProxy(m_loader);
m_networkReplyProxy = new QQmlTypeLoaderNetworkReplyProxy(m_loader);
}
return m_networkAccessManager;
}
QQmlDataLoaderNetworkReplyProxy *QQmlDataLoaderThread::networkReplyProxy() const
QQmlTypeLoaderNetworkReplyProxy *QQmlTypeLoaderThread::networkReplyProxy() const
{
Q_ASSERT(isThisThread());
Q_ASSERT(m_networkReplyProxy); // Must call networkAccessManager() first
return m_networkReplyProxy;
}
void QQmlDataLoaderThread::load(QQmlDataBlob *b)
void QQmlTypeLoaderThread::load(QQmlDataBlob *b)
{
b->addref();
callMethodInThread(&This::loadThread, b);
}
void QQmlDataLoaderThread::loadAsync(QQmlDataBlob *b)
void QQmlTypeLoaderThread::loadAsync(QQmlDataBlob *b)
{
b->addref();
postMethodToThread(&This::loadThread, b);
}
void QQmlDataLoaderThread::loadWithStaticData(QQmlDataBlob *b, const QByteArray &d)
void QQmlTypeLoaderThread::loadWithStaticData(QQmlDataBlob *b, const QByteArray &d)
{
b->addref();
callMethodInThread(&This::loadWithStaticDataThread, b, d);
}
void QQmlDataLoaderThread::loadWithStaticDataAsync(QQmlDataBlob *b, const QByteArray &d)
void QQmlTypeLoaderThread::loadWithStaticDataAsync(QQmlDataBlob *b, const QByteArray &d)
{
b->addref();
postMethodToThread(&This::loadWithStaticDataThread, b, d);
}
void QQmlDataLoaderThread::loadWithCachedUnit(QQmlDataBlob *b, const QQmlPrivate::CachedQmlUnit *unit)
void QQmlTypeLoaderThread::loadWithCachedUnit(QQmlDataBlob *b, const QQmlPrivate::CachedQmlUnit *unit)
{
b->addref();
callMethodInThread(&This::loadWithCachedUnitThread, b, unit);
}
void QQmlDataLoaderThread::loadWithCachedUnitAsync(QQmlDataBlob *b, const QQmlPrivate::CachedQmlUnit *unit)
void QQmlTypeLoaderThread::loadWithCachedUnitAsync(QQmlDataBlob *b, const QQmlPrivate::CachedQmlUnit *unit)
{
b->addref();
postMethodToThread(&This::loadWithCachedUnitThread, b, unit);
}
void QQmlDataLoaderThread::callCompleted(QQmlDataBlob *b)
void QQmlTypeLoaderThread::callCompleted(QQmlDataBlob *b)
{
b->addref();
postMethodToMain(&This::callCompletedMain, b);
}
void QQmlDataLoaderThread::callDownloadProgressChanged(QQmlDataBlob *b, qreal p)
void QQmlTypeLoaderThread::callDownloadProgressChanged(QQmlDataBlob *b, qreal p)
{
b->addref();
postMethodToMain(&This::callDownloadProgressChangedMain, b, p);
}
void QQmlDataLoaderThread::initializeEngine(QQmlExtensionInterface *iface,
void QQmlTypeLoaderThread::initializeEngine(QQmlExtensionInterface *iface,
const char *uri)
{
callMethodInMain(&This::initializeEngineMain, iface, uri);
}
void QQmlDataLoaderThread::shutdownThread()
void QQmlTypeLoaderThread::shutdownThread()
{
delete m_networkAccessManager;
m_networkAccessManager = 0;
@ -812,45 +812,45 @@ void QQmlDataLoaderThread::shutdownThread()
m_networkReplyProxy = 0;
}
void QQmlDataLoaderThread::loadThread(QQmlDataBlob *b)
void QQmlTypeLoaderThread::loadThread(QQmlDataBlob *b)
{
m_loader->loadThread(b);
b->release();
}
void QQmlDataLoaderThread::loadWithStaticDataThread(QQmlDataBlob *b, const QByteArray &d)
void QQmlTypeLoaderThread::loadWithStaticDataThread(QQmlDataBlob *b, const QByteArray &d)
{
m_loader->loadWithStaticDataThread(b, d);
b->release();
}
void QQmlDataLoaderThread::loadWithCachedUnitThread(QQmlDataBlob *b, const QQmlPrivate::CachedQmlUnit *unit)
void QQmlTypeLoaderThread::loadWithCachedUnitThread(QQmlDataBlob *b, const QQmlPrivate::CachedQmlUnit *unit)
{
m_loader->loadWithCachedUnitThread(b, unit);
b->release();
}
void QQmlDataLoaderThread::callCompletedMain(QQmlDataBlob *b)
void QQmlTypeLoaderThread::callCompletedMain(QQmlDataBlob *b)
{
QML_MEMORY_SCOPE_URL(b->url());
#ifdef DATABLOB_DEBUG
qWarning("QQmlDataLoaderThread: %s completed() callback", qPrintable(b->url().toString()));
qWarning("QQmlTypeLoaderThread: %s completed() callback", qPrintable(b->url().toString()));
#endif
b->completed();
b->release();
}
void QQmlDataLoaderThread::callDownloadProgressChangedMain(QQmlDataBlob *b, qreal p)
void QQmlTypeLoaderThread::callDownloadProgressChangedMain(QQmlDataBlob *b, qreal p)
{
#ifdef DATABLOB_DEBUG
qWarning("QQmlDataLoaderThread: %s downloadProgressChanged(%f) callback",
qWarning("QQmlTypeLoaderThread: %s downloadProgressChanged(%f) callback",
qPrintable(b->url().toString()), p);
#endif
b->downloadProgressChanged(p);
b->release();
}
void QQmlDataLoaderThread::initializeEngineMain(QQmlExtensionInterface *iface,
void QQmlTypeLoaderThread::initializeEngineMain(QQmlExtensionInterface *iface,
const char *uri)
{
Q_ASSERT(m_loader->engine()->thread() == QThread::currentThread());
@ -858,14 +858,14 @@ void QQmlDataLoaderThread::initializeEngineMain(QQmlExtensionInterface *iface,
}
/*!
\class QQmlDataLoader
\brief The QQmlDataLoader class abstracts loading files and their dependencies over the network.
\class QQmlTypeLoader
\brief The QQmlTypeLoader class abstracts loading files and their dependencies over the network.
\internal
The QQmlDataLoader class is provided for the exclusive use of the QQmlTypeLoader class.
The QQmlTypeLoader class is provided for the exclusive use of the QQmlTypeLoader class.
Clients create QQmlDataBlob instances and submit them to the QQmlDataLoader class
through the QQmlDataLoader::load() or QQmlDataLoader::loadWithStaticData() methods.
Clients create QQmlDataBlob instances and submit them to the QQmlTypeLoader class
through the QQmlTypeLoader::load() or QQmlTypeLoader::loadWithStaticData() methods.
The loader then fetches the data over the network or from the local file system in an efficient way.
QQmlDataBlob is an abstract class, so should always be specialized.
@ -887,21 +887,7 @@ one of these three preconditions are met.
Thus QQmlDataBlob::done() will always eventually be called, even if the blob has an error set.
*/
/*!
Create a new QQmlDataLoader for \a engine.
*/
QQmlDataLoader::QQmlDataLoader(QQmlEngine *engine)
: m_engine(engine), m_thread(new QQmlDataLoaderThread(this))
{
}
/*! \internal */
QQmlDataLoader::~QQmlDataLoader()
{
invalidate();
}
void QQmlDataLoader::invalidate()
void QQmlTypeLoader::invalidate()
{
for (NetworkReplies::Iterator iter = m_networkReplies.begin(); iter != m_networkReplies.end(); ++iter)
(*iter)->release();
@ -914,12 +900,12 @@ void QQmlDataLoader::invalidate()
}
}
void QQmlDataLoader::lock()
void QQmlTypeLoader::lock()
{
m_thread->lock();
}
void QQmlDataLoader::unlock()
void QQmlTypeLoader::unlock()
{
m_thread->unlock();
}
@ -929,10 +915,10 @@ Load the provided \a blob from the network or filesystem.
The loader must be locked.
*/
void QQmlDataLoader::load(QQmlDataBlob *blob, Mode mode)
void QQmlTypeLoader::load(QQmlDataBlob *blob, Mode mode)
{
#ifdef DATABLOB_DEBUG
qWarning("QQmlDataLoader::load(%s): %s thread", qPrintable(blob->m_url.toString()),
qWarning("QQmlTypeLoader::load(%s): %s thread", qPrintable(blob->m_url.toString()),
m_thread->isThisThread()?"Compile":"Engine");
#endif
blob->startLoading(this);
@ -961,10 +947,10 @@ Load the provided \a blob with \a data. The blob's URL is not used by the data
The loader must be locked.
*/
void QQmlDataLoader::loadWithStaticData(QQmlDataBlob *blob, const QByteArray &data, Mode mode)
void QQmlTypeLoader::loadWithStaticData(QQmlDataBlob *blob, const QByteArray &data, Mode mode)
{
#ifdef DATABLOB_DEBUG
qWarning("QQmlDataLoader::loadWithStaticData(%s, data): %s thread", qPrintable(blob->m_url.toString()),
qWarning("QQmlTypeLoader::loadWithStaticData(%s, data): %s thread", qPrintable(blob->m_url.toString()),
m_thread->isThisThread()?"Compile":"Engine");
#endif
@ -989,10 +975,10 @@ void QQmlDataLoader::loadWithStaticData(QQmlDataBlob *blob, const QByteArray &da
}
}
void QQmlDataLoader::loadWithCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit, Mode mode)
void QQmlTypeLoader::loadWithCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit, Mode mode)
{
#ifdef DATABLOB_DEBUG
qWarning("QQmlDataLoader::loadWithUnitFcatory(%s, data): %s thread", qPrintable(blob->m_url.toString()),
qWarning("QQmlTypeLoader::loadWithUnitFcatory(%s, data): %s thread", qPrintable(blob->m_url.toString()),
m_thread->isThisThread()?"Compile":"Engine");
#endif
@ -1017,21 +1003,21 @@ void QQmlDataLoader::loadWithCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::C
}
}
void QQmlDataLoader::loadWithStaticDataThread(QQmlDataBlob *blob, const QByteArray &data)
void QQmlTypeLoader::loadWithStaticDataThread(QQmlDataBlob *blob, const QByteArray &data)
{
ASSERT_LOADTHREAD();
setData(blob, data);
}
void QQmlDataLoader::loadWithCachedUnitThread(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit)
void QQmlTypeLoader::loadWithCachedUnitThread(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit)
{
ASSERT_LOADTHREAD();
setCachedUnit(blob, unit);
}
void QQmlDataLoader::loadThread(QQmlDataBlob *blob)
void QQmlTypeLoader::loadThread(QQmlDataBlob *blob)
{
ASSERT_LOADTHREAD();
@ -1086,7 +1072,7 @@ void QQmlDataLoader::loadThread(QQmlDataBlob *blob)
} else {
QNetworkReply *reply = m_thread->networkAccessManager()->get(QNetworkRequest(blob->m_url));
QQmlDataLoaderNetworkReplyProxy *nrp = m_thread->networkReplyProxy();
QQmlTypeLoaderNetworkReplyProxy *nrp = m_thread->networkReplyProxy();
blob->addref();
m_networkReplies.insert(reply, blob);
@ -1108,7 +1094,7 @@ void QQmlDataLoader::loadThread(QQmlDataBlob *blob)
#define DATALOADER_MAXIMUM_REDIRECT_RECURSION 16
void QQmlDataLoader::networkReplyFinished(QNetworkReply *reply)
void QQmlTypeLoader::networkReplyFinished(QNetworkReply *reply)
{
Q_ASSERT(m_thread->isThisThread());
@ -1147,7 +1133,7 @@ void QQmlDataLoader::networkReplyFinished(QNetworkReply *reply)
blob->release();
}
void QQmlDataLoader::networkReplyProgress(QNetworkReply *reply,
void QQmlTypeLoader::networkReplyProgress(QNetworkReply *reply,
qint64 bytesReceived, qint64 bytesTotal)
{
Q_ASSERT(m_thread->isThisThread());
@ -1167,7 +1153,7 @@ void QQmlDataLoader::networkReplyProgress(QNetworkReply *reply,
/*!
Return the QQmlEngine associated with this loader
*/
QQmlEngine *QQmlDataLoader::engine() const
QQmlEngine *QQmlTypeLoader::engine() const
{
return m_engine;
}
@ -1176,7 +1162,7 @@ QQmlEngine *QQmlDataLoader::engine() const
Call the initializeEngine() method on \a iface. Used by QQmlImportDatabase to ensure it
gets called in the correct thread.
*/
void QQmlDataLoader::initializeEngine(QQmlExtensionInterface *iface,
void QQmlTypeLoader::initializeEngine(QQmlExtensionInterface *iface,
const char *uri)
{
Q_ASSERT(m_thread->isThisThread() || engine()->thread() == QThread::currentThread());
@ -1190,7 +1176,7 @@ void QQmlDataLoader::initializeEngine(QQmlExtensionInterface *iface,
}
void QQmlDataLoader::setData(QQmlDataBlob *blob, const QByteArray &data)
void QQmlTypeLoader::setData(QQmlDataBlob *blob, const QByteArray &data)
{
QML_MEMORY_SCOPE_URL(blob->url());
QQmlDataBlob::Data d;
@ -1198,7 +1184,7 @@ void QQmlDataLoader::setData(QQmlDataBlob *blob, const QByteArray &data)
setData(blob, d);
}
void QQmlDataLoader::setData(QQmlDataBlob *blob, QQmlFile *file)
void QQmlTypeLoader::setData(QQmlDataBlob *blob, QQmlFile *file)
{
QML_MEMORY_SCOPE_URL(blob->url());
QQmlDataBlob::Data d;
@ -1206,7 +1192,7 @@ void QQmlDataLoader::setData(QQmlDataBlob *blob, QQmlFile *file)
setData(blob, d);
}
void QQmlDataLoader::setData(QQmlDataBlob *blob, const QQmlDataBlob::Data &d)
void QQmlTypeLoader::setData(QQmlDataBlob *blob, const QQmlDataBlob::Data &d)
{
QML_MEMORY_SCOPE_URL(blob->url());
blob->m_inCallback = true;
@ -1224,7 +1210,7 @@ void QQmlDataLoader::setData(QQmlDataBlob *blob, const QQmlDataBlob::Data &d)
blob->tryDone();
}
void QQmlDataLoader::setCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit)
void QQmlTypeLoader::setCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit)
{
QML_MEMORY_SCOPE_URL(blob->url());
blob->m_inCallback = true;
@ -1242,7 +1228,7 @@ void QQmlDataLoader::setCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::Cached
blob->tryDone();
}
void QQmlDataLoader::shutdownThread()
void QQmlTypeLoader::shutdownThread()
{
if (m_thread && !m_thread->isShutdown())
m_thread->shutdown();
@ -1582,7 +1568,7 @@ bool QQmlTypeLoader::QmldirContent::designerSupported() const
Constructs a new type loader that uses the given \a engine.
*/
QQmlTypeLoader::QQmlTypeLoader(QQmlEngine *engine)
: QQmlDataLoader(engine)
: m_engine(engine), m_thread(new QQmlTypeLoaderThread(this))
{
}
@ -1596,6 +1582,8 @@ QQmlTypeLoader::~QQmlTypeLoader()
shutdownThread();
clearCache();
invalidate();
}
QQmlImportDatabase *QQmlTypeLoader::importDatabase()
@ -1621,9 +1609,9 @@ QQmlTypeData *QQmlTypeLoader::getType(const QUrl &url, Mode mode)
// TODO: if (compiledData == 0), is it safe to omit this insertion?
m_typeCache.insert(url, typeData);
if (const QQmlPrivate::CachedQmlUnit *cachedUnit = QQmlMetaType::findCachedCompilationUnit(url)) {
QQmlDataLoader::loadWithCachedUnit(typeData, cachedUnit, mode);
QQmlTypeLoader::loadWithCachedUnit(typeData, cachedUnit, mode);
} else {
QQmlDataLoader::load(typeData, mode);
QQmlTypeLoader::load(typeData, mode);
}
}
@ -1641,7 +1629,7 @@ QQmlTypeData *QQmlTypeLoader::getType(const QByteArray &data, const QUrl &url)
LockHolder<QQmlTypeLoader> holder(this);
QQmlTypeData *typeData = new QQmlTypeData(url, this);
QQmlDataLoader::loadWithStaticData(typeData, data);
QQmlTypeLoader::loadWithStaticData(typeData, data);
return typeData;
}
@ -1664,9 +1652,9 @@ QQmlScriptBlob *QQmlTypeLoader::getScript(const QUrl &url)
m_scriptCache.insert(url, scriptBlob);
if (const QQmlPrivate::CachedQmlUnit *cachedUnit = QQmlMetaType::findCachedCompilationUnit(url)) {
QQmlDataLoader::loadWithCachedUnit(scriptBlob, cachedUnit);
QQmlTypeLoader::loadWithCachedUnit(scriptBlob, cachedUnit);
} else {
QQmlDataLoader::load(scriptBlob);
QQmlTypeLoader::load(scriptBlob);
}
}
@ -1691,7 +1679,7 @@ QQmlQmldirData *QQmlTypeLoader::getQmldir(const QUrl &url)
if (!qmldirData) {
qmldirData = new QQmlQmldirData(url, this);
m_qmldirCache.insert(url, qmldirData);
QQmlDataLoader::load(qmldirData);
QQmlTypeLoader::load(qmldirData);
}
qmldirData->addref();

View File

@ -73,7 +73,7 @@ class QQmlTypeLoader;
class QQmlCompiledData;
class QQmlComponentPrivate;
class QQmlTypeData;
class QQmlDataLoader;
class QQmlTypeLoader;
class QQmlExtensionInterface;
namespace QmlIR {
@ -84,7 +84,7 @@ class Q_QML_PRIVATE_EXPORT QQmlDataBlob : public QQmlRefCount
{
public:
enum Status {
Null, // Prior to QQmlDataLoader::load()
Null, // Prior to QQmlTypeLoader::load()
Loading, // Prior to data being received and dataReceived() being called
WaitingForDependencies, // While there are outstanding addDependency()s
Complete, // Finished
@ -100,7 +100,7 @@ public:
QQmlDataBlob(const QUrl &, Type);
virtual ~QQmlDataBlob();
void startLoading(QQmlDataLoader* manager);
void startLoading(QQmlTypeLoader* manager);
Type type() const;
@ -132,7 +132,7 @@ public:
private:
friend class QQmlDataBlob;
friend class QQmlDataLoader;
friend class QQmlTypeLoader;
inline Data();
Data(const Data &);
Data &operator=(const Data &);
@ -158,8 +158,8 @@ protected:
virtual void downloadProgressChanged(qreal);
virtual void completed();
private:
friend class QQmlDataLoader;
friend class QQmlDataLoaderThread;
friend class QQmlTypeLoader;
friend class QQmlTypeLoaderThread;
void tryDone();
void cancelAllWaitingFor();
@ -199,59 +199,13 @@ private:
QList<QQmlDataBlob *> m_waitingFor;
// Manager that is currently fetching data for me
QQmlDataLoader *m_manager;
QQmlTypeLoader *m_manager;
int m_redirectCount:30;
bool m_inCallback:1;
bool m_isDone:1;
};
class QQmlDataLoaderThread;
class QQmlDataLoader
{
public:
QQmlDataLoader(QQmlEngine *);
~QQmlDataLoader();
void lock();
void unlock();
bool isConcurrent() const { return true; }
enum Mode { PreferSynchronous, Asynchronous };
void load(QQmlDataBlob *, Mode = PreferSynchronous);
void loadWithStaticData(QQmlDataBlob *, const QByteArray &, Mode = PreferSynchronous);
void loadWithCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit, Mode mode = PreferSynchronous);
QQmlEngine *engine() const;
void initializeEngine(QQmlExtensionInterface *, const char *);
void invalidate();
protected:
void shutdownThread();
private:
friend class QQmlDataBlob;
friend class QQmlDataLoaderThread;
friend class QQmlDataLoaderNetworkReplyProxy;
void loadThread(QQmlDataBlob *);
void loadWithStaticDataThread(QQmlDataBlob *, const QByteArray &);
void loadWithCachedUnitThread(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit);
void networkReplyFinished(QNetworkReply *);
void networkReplyProgress(QNetworkReply *, qint64, qint64);
typedef QHash<QNetworkReply *, QQmlDataBlob *> NetworkReplies;
void setData(QQmlDataBlob *, const QByteArray &);
void setData(QQmlDataBlob *, QQmlFile *);
void setData(QQmlDataBlob *, const QQmlDataBlob::Data &);
void setCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit);
QQmlEngine *m_engine;
QQmlDataLoaderThread *m_thread;
NetworkReplies m_networkReplies;
};
class QQmlTypeLoaderThread;
class QQmlBundleData : public QQmlBundle,
public QQmlRefCount
@ -261,10 +215,12 @@ public:
QString fileName;
};
class Q_AUTOTEST_EXPORT QQmlTypeLoader : public QQmlDataLoader
class Q_AUTOTEST_EXPORT QQmlTypeLoader
{
Q_DECLARE_TR_FUNCTIONS(QQmlTypeLoader)
public:
enum Mode { PreferSynchronous, Asynchronous };
class Q_QML_PRIVATE_EXPORT Blob : public QQmlDataBlob
{
public:
@ -354,10 +310,42 @@ public:
bool isTypeLoaded(const QUrl &url) const;
bool isScriptLoaded(const QUrl &url) const;
void lock();
void unlock();
bool isConcurrent() const { return true; }
void load(QQmlDataBlob *, Mode = PreferSynchronous);
void loadWithStaticData(QQmlDataBlob *, const QByteArray &, Mode = PreferSynchronous);
void loadWithCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit, Mode mode = PreferSynchronous);
QQmlEngine *engine() const;
void initializeEngine(QQmlExtensionInterface *, const char *);
void invalidate();
private:
friend class QQmlDataBlob;
friend class QQmlTypeLoaderThread;
friend class QQmlTypeLoaderNetworkReplyProxy;
void shutdownThread();
void addBundleNoLock(const QString &, const QString &);
QString bundleIdForQmldir(const QString &qmldir, const QString &uriHint);
void loadThread(QQmlDataBlob *);
void loadWithStaticDataThread(QQmlDataBlob *, const QByteArray &);
void loadWithCachedUnitThread(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit);
void networkReplyFinished(QNetworkReply *);
void networkReplyProgress(QNetworkReply *, qint64, qint64);
typedef QHash<QNetworkReply *, QQmlDataBlob *> NetworkReplies;
void setData(QQmlDataBlob *, const QByteArray &);
void setData(QQmlDataBlob *, QQmlFile *);
void setData(QQmlDataBlob *, const QQmlDataBlob::Data &);
void setCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit);
template<typename T>
struct TypedCallback
{
@ -383,6 +371,9 @@ private:
typedef QStringHash<QQmlBundleData *> BundleCache;
typedef QStringHash<QString> QmldirBundleIdCache;
QQmlEngine *m_engine;
QQmlTypeLoaderThread *m_thread;
NetworkReplies m_networkReplies;
TypeCache m_typeCache;
ScriptCache m_scriptCache;
QmldirCache m_qmldirCache;