![]() |
Qt 6.x
The Qt SDK
|
The QQmlTypeLoader class abstracts loading files and their dependencies over the network. More...
#include <qqmltypeloader_p.h>
Classes | |
class | Blob |
Public Types | |
enum | Mode { PreferSynchronous , Asynchronous , Synchronous } |
using | ChecksumCache = QHash< quintptr, QByteArray > |
Public Member Functions | |
QQmlTypeLoader (QQmlEngine *) | |
Constructs a new type loader that uses the given engine. | |
~QQmlTypeLoader () | |
Destroys the type loader, first clearing the cache of any information about loaded files. | |
QQmlImportDatabase * | importDatabase () const |
ChecksumCache * | checksumCache () |
const ChecksumCache * | checksumCache () const |
QQmlRefPointer< QQmlTypeData > | getType (const QUrl &unNormalizedUrl, Mode mode=PreferSynchronous) |
Returns a QQmlTypeData for the specified url. | |
QQmlRefPointer< QQmlTypeData > | getType (const QByteArray &, const QUrl &url, Mode mode=PreferSynchronous) |
Returns a QQmlTypeData for the given data with the provided base url. | |
QQmlRefPointer< QQmlScriptBlob > | getScript (const QUrl &unNormalizedUrl) |
Return a QQmlScriptBlob for url. | |
QQmlRefPointer< QQmlQmldirData > | getQmldir (const QUrl &) |
Returns a QQmlQmldirData for url. | |
QString | absoluteFilePath (const QString &path) |
Returns the absolute filename of path via a directory cache. | |
bool | fileExists (const QString &path, const QString &file) |
bool | directoryExists (const QString &path) |
Returns true if the path is a directory via a directory cache. | |
const QQmlTypeLoaderQmldirContent | qmldirContent (const QString &filePath) |
Return a QQmlTypeLoaderQmldirContent for absoluteFilePath. | |
void | setQmldirContent (const QString &filePath, const QString &content) |
void | clearCache () |
Clears cached information about loaded files, including any type data, scripts and qmldir information. | |
void | trimCache () |
bool | isTypeLoaded (const QUrl &url) const |
bool | isScriptLoaded (const QUrl &url) const |
void | lock () |
void | unlock () |
void | load (QQmlDataBlob *, Mode=PreferSynchronous) |
Load the provided blob from the network or filesystem. | |
void | loadWithStaticData (QQmlDataBlob *, const QByteArray &, Mode=PreferSynchronous) |
Load the provided blob with data. | |
void | loadWithCachedUnit (QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit, Mode mode=PreferSynchronous) |
QQmlEngine * | engine () const |
Return the QQmlEngine associated with this loader. | |
void | initializeEngine (QQmlEngineExtensionInterface *, const char *) |
void | initializeEngine (QQmlExtensionInterface *, const char *) |
void | invalidate () |
quintptr | profiler () const |
void | setProfiler (quintptr) |
Static Public Member Functions | |
static QUrl | normalize (const QUrl &unNormalizedUrl) |
Friends | |
class | QQmlDataBlob |
class | QQmlTypeLoaderThread |
struct | PlainLoader |
struct | CachedLoader |
struct | StaticLoader |
The QQmlTypeLoader class abstracts loading files and their dependencies over the network.
The QQmlTypeLoader class is provided for the exclusive use of the QQmlTypeLoader class.
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.
Once data is received, the QQmlDataBlob::dataReceived() method is invoked on the blob. The derived class should use this callback to process the received data. Processing of the data can result in an error being set (QQmlDataBlob::setError()), or one or more dependencies being created (QQmlDataBlob::addDependency()). Dependencies are other QQmlDataBlob's that are required before processing can fully complete.
To complete processing, the QQmlDataBlob::done() callback is invoked. done() is called when one of these three preconditions are met.
\list 1
Thus QQmlDataBlob::done() will always eventually be called, even if the blob has an error set.
Definition at line 41 of file qqmltypeloader_p.h.
using QQmlTypeLoader::ChecksumCache = QHash<quintptr, QByteArray> |
Definition at line 45 of file qqmltypeloader_p.h.
enum QQmlTypeLoader::Mode |
Enumerator | |
---|---|
PreferSynchronous | |
Asynchronous | |
Synchronous |
Definition at line 46 of file qqmltypeloader_p.h.
QQmlTypeLoader::QQmlTypeLoader | ( | QQmlEngine * | engine | ) |
Constructs a new type loader that uses the given engine.
Definition at line 901 of file qqmltypeloader.cpp.
QQmlTypeLoader::~QQmlTypeLoader | ( | ) |
Destroys the type loader, first clearing the cache of any information about loaded files.
Definition at line 913 of file qqmltypeloader.cpp.
References clearCache(), and invalidate().
Returns the absolute filename of path via a directory cache.
Returns a empty string if the path does not exist.
Why a directory cache? QML checks for files in many paths with invalid directories. By caching whether a directory exists we avoid many stats. We also cache the files' existence in the directory, for the same reason.
Definition at line 1065 of file qqmltypeloader.cpp.
References QFileInfo::absoluteFilePath(), absoluteFilePath(), QString::at(), Qt::CaseInsensitive, QCache< Key, T >::contains(), QDir::exists(), QFile::exists(), fileName, QCache< Key, T >::insert(), QFileInfo::isFile(), QCache< Key, T >::object(), QString::size(), and QQmlFile::urlToLocalFileOrQrc().
Referenced by absoluteFilePath(), and QQmlImports::addFileImport().
|
inline |
Definition at line 126 of file qqmltypeloader_p.h.
|
inline |
Definition at line 127 of file qqmltypeloader_p.h.
void QQmlTypeLoader::clearCache | ( | ) |
Clears cached information about loaded files, including any type data, scripts and qmldir information.
Definition at line 1301 of file qqmltypeloader.cpp.
References QHash< Key, T >::begin(), QStringHash< T >::clear(), QHash< Key, T >::clear(), QCache< Key, T >::clear(), QHash< Key, T >::end(), QQmlMetaType::freeUnusedTypesAndCaches(), iter, qDeleteAll(), and TYPELOADER_MINIMUM_TRIM_THRESHOLD.
Referenced by ~QQmlTypeLoader().
bool QQmlTypeLoader::directoryExists | ( | const QString & | path | ) |
Returns true if the path is a directory via a directory cache.
Cache is shared with absoluteFilePath().
Definition at line 1190 of file qqmltypeloader.cpp.
References QCache< Key, T >::contains(), QDir::exists(), QFileInfo::exists(), files, QCache< Key, T >::insert(), QFileInfo::isDir(), and QCache< Key, T >::object().
Referenced by QQmlImports::addFileImport().
QQmlEngine * QQmlTypeLoader::engine | ( | ) | const |
Return the QQmlEngine associated with this loader.
Definition at line 350 of file qqmltypeloader.cpp.
Referenced by QQmlDataBlob::QQmlDataBlob(), QQmlImports::addFileImport(), importDatabase(), initializeEngine(), and initializeEngine().
Definition at line 1126 of file qqmltypeloader.cpp.
References Qt::CaseInsensitive, QCache< Key, T >::contains(), file, QCache< Key, T >::insert(), QChar::Null, QCache< Key, T >::object(), Q_ASSERT, and QQmlFile::urlToLocalFileOrQrc().
Referenced by QQmlImportInstance::resolveType().
QQmlRefPointer< QQmlQmldirData > QQmlTypeLoader::getQmldir | ( | const QUrl & | url | ) |
Returns a QQmlQmldirData for url.
The QQmlQmldirData may be cached.
Definition at line 1038 of file qqmltypeloader.cpp.
References QHash< Key, T >::insert(), QString::isEmpty(), QUrl::isRelative(), QDir::isRelativePath(), load(), Q_ASSERT, url, QQmlFile::urlToLocalFileOrQrc(), and QHash< Key, T >::value().
QQmlRefPointer< QQmlScriptBlob > QQmlTypeLoader::getScript | ( | const QUrl & | unNormalizedUrl | ) |
Return a QQmlScriptBlob for url.
The QQmlScriptData may be cached.
Definition at line 1004 of file qqmltypeloader.cpp.
References QQmlTypeLoader::Blob::aotCacheMode(), error, QQmlMetaType::findCachedCompilationUnit(), QHash< Key, T >::insert(), QString::isEmpty(), QUrl::isRelative(), QDir::isRelativePath(), load(), loadWithCachedUnit(), QQmlMetaType::NoError, normalize(), Q_ASSERT, QQmlMetaType::RejectAll, QQmlTypeLoader::Blob::setCachedUnitStatus(), url, QQmlDataBlob::url(), QQmlFile::urlToLocalFileOrQrc(), and QHash< Key, T >::value().
QQmlRefPointer< QQmlTypeData > QQmlTypeLoader::getType | ( | const QByteArray & | data, |
const QUrl & | url, | ||
Mode | mode = PreferSynchronous |
||
) |
Returns a QQmlTypeData for the given data with the provided base url.
The QQmlTypeData will not be cached.
Definition at line 991 of file qqmltypeloader.cpp.
References loadWithStaticData(), and url.
QQmlRefPointer< QQmlTypeData > QQmlTypeLoader::getType | ( | const QUrl & | unNormalizedUrl, |
Mode | mode = PreferSynchronous |
||
) |
Returns a QQmlTypeData for the specified url.
The QQmlTypeData may be cached.
Definition at line 939 of file qqmltypeloader.cpp.
References QQmlTypeLoader::Blob::aotCacheMode(), error, QQmlMetaType::findCachedCompilationUnit(), QHash< Key, T >::insert(), QQmlDataBlob::isCompleteOrError(), QString::isEmpty(), QUrl::isRelative(), QDir::isRelativePath(), QQmlFile::isSynchronous(), QQmlThread::isThisThread(), load(), loadWithCachedUnit(), QQmlMetaType::NoError, normalize(), PreferSynchronous, Q_ASSERT, QQmlMetaType::RejectAll, QQmlTypeLoader::Blob::setCachedUnitStatus(), QHash< Key, T >::size(), Synchronous, trimCache(), url, QQmlDataBlob::url(), QQmlFile::urlToLocalFileOrQrc(), QHash< Key, T >::value(), and QQmlThread::waitForNextMessage().
Referenced by QV4::Function::Function(), QQmlPropertyCacheCreator< ObjectContainer >::createMetaObject(), QtObject::createQmlObject(), instanceOfQObject(), QQmlPrivate::AOTCompiledContext::loadTypeLookup(), QQmlComponentPrivate::loadUrl(), QQmlPropertyCacheCreator< ObjectContainer >::metaTypeForParameter(), and QQmlComponent::setData().
QQmlImportDatabase * QQmlTypeLoader::importDatabase | ( | ) | const |
Definition at line 923 of file qqmltypeloader.cpp.
References engine(), QQmlEnginePrivate::get(), and QQmlEnginePrivate::importDatabase.
Referenced by QQmlTypeLoader::Blob::updateQmldir().
void QQmlTypeLoader::initializeEngine | ( | QQmlEngineExtensionInterface * | iface, |
const char * | uri | ||
) |
Definition at line 373 of file qqmltypeloader.cpp.
References doInitializeEngine(), and engine().
void QQmlTypeLoader::initializeEngine | ( | QQmlExtensionInterface * | iface, |
const char * | uri | ||
) |
Definition at line 378 of file qqmltypeloader.cpp.
References doInitializeEngine(), and engine().
void QQmlTypeLoader::invalidate | ( | ) |
Definition at line 82 of file qqmltypeloader.cpp.
Referenced by ~QQmlTypeLoader().
bool QQmlTypeLoader::isScriptLoaded | ( | const QUrl & | url | ) | const |
Definition at line 1383 of file qqmltypeloader.cpp.
References QHash< Key, T >::contains(), and url.
bool QQmlTypeLoader::isTypeLoaded | ( | const QUrl & | url | ) | const |
Definition at line 1377 of file qqmltypeloader.cpp.
References QHash< Key, T >::contains(), and url.
void QQmlTypeLoader::load | ( | QQmlDataBlob * | blob, |
Mode | mode = PreferSynchronous |
||
) |
Load the provided blob from the network or filesystem.
The loader must be locked.
Definition at line 196 of file qqmltypeloader.cpp.
References PlainLoader.
Referenced by getQmldir(), getScript(), and getType().
void QQmlTypeLoader::loadWithCachedUnit | ( | QQmlDataBlob * | blob, |
const QQmlPrivate::CachedQmlUnit * | unit, | ||
Mode | mode = PreferSynchronous |
||
) |
Definition at line 211 of file qqmltypeloader.cpp.
References CachedLoader.
Referenced by getScript(), and getType().
void QQmlTypeLoader::loadWithStaticData | ( | QQmlDataBlob * | blob, |
const QByteArray & | data, | ||
Mode | mode = PreferSynchronous |
||
) |
Load the provided blob with data.
The blob's URL is not used by the data loader in this case.
The loader must be locked.
Definition at line 206 of file qqmltypeloader.cpp.
References StaticLoader.
Referenced by getType().
|
inline |
Definition at line 150 of file qqmltypeloader_p.h.
Definition at line 928 of file qqmltypeloader.cpp.
Referenced by createQQmlType(), createQQmlType(), QQmlMetaType::findCompositeType(), getScript(), getType(), QV4::ExecutionEngine::loadModule(), QV4::ExecutionEngine::moduleForUrl(), QQmlMetaType::qmlType(), QQmlMetaType::registerCompositeSingletonType(), QQmlMetaType::registerCompositeType(), and QQmlMetaType::typeForUrl().
|
inline |
Definition at line 163 of file qqmltypeloader_p.h.
const QQmlTypeLoaderQmldirContent QQmlTypeLoader::qmldirContent | ( | const QString & | filePathIn | ) |
Return a QQmlTypeLoaderQmldirContent for absoluteFilePath.
The QQmlTypeLoaderQmldirContent may be cached.
filePath is a local file path.
It can also be a remote path for a remote directory import, but it will have been cached by now in this case.
Definition at line 1230 of file qqmltypeloader.cpp.
References CASE_MISMATCH_ERROR, ERROR, file, QString::fromUtf8(), QStringHash< T >::insert(), QString::isEmpty(), NOT_READABLE_ERROR, QFile::open(), QQml_isFileCaseCorrect(), QIODevice::readAll(), QIODeviceBase::ReadOnly, QUrl::scheme(), QString::size(), url, QQmlFile::urlToLocalFileOrQrc(), and QStringHash< T >::value().
Definition at line 164 of file qqmltypeloader_p.h.
Definition at line 1282 of file qqmltypeloader.cpp.
References QQmlTypeLoaderQmldirContent::hasContent(), QStringHash< T >::insert(), url, and QStringHash< T >::value().
void QQmlTypeLoader::trimCache | ( | ) |
Definition at line 1331 of file qqmltypeloader.cpp.
References QHash< Key, T >::begin(), QQmlRefCount::count(), QQmlMetaType::countInternalCompositeTypeSelfReferences(), QHash< Key, T >::end(), QHash< Key, T >::erase(), QQmlMetaType::freeUnusedTypesAndCaches(), QQmlDataBlob::isComplete(), QQmlDataBlob::isError(), iter, Q_ASSERT, and QQmlMetaType::unregisterInternalCompositeType().
Referenced by getType().
|
inline |
Definition at line 151 of file qqmltypeloader_p.h.
|
friend |
Definition at line 225 of file qqmltypeloader_p.h.
Referenced by loadWithCachedUnit().
|
friend |
Definition at line 224 of file qqmltypeloader_p.h.
Referenced by load().
|
friend |
Definition at line 172 of file qqmltypeloader_p.h.
|
friend |
Definition at line 173 of file qqmltypeloader_p.h.
|
friend |
Definition at line 226 of file qqmltypeloader_p.h.
Referenced by loadWithStaticData().