Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
|
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. | |
void | injectScript (const QUrl &relativeUrl, const QV4::Value &value) |
QQmlRefPointer< QQmlScriptBlob > | injectedScript (const QUrl &relativeUrl) |
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 | |
template<typename Engine , typename EnginePrivate = QQmlEnginePrivate, typename = std::enable_if_t<std::is_same_v<Engine, QQmlEngine>>> | |
static QQmlTypeLoader * | get (Engine *engine) |
template<typename Engine , typename = std::enable_if_t<std::is_same_v<Engine, QQmlEnginePrivate>>> | |
static QQmlTypeLoader * | get (Engine *engine) |
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 42 of file qqmltypeloader_p.h.
using QQmlTypeLoader::ChecksumCache = QHash<quintptr, QByteArray> |
Definition at line 46 of file qqmltypeloader_p.h.
enum QQmlTypeLoader::Mode |
Enumerator | |
---|---|
PreferSynchronous | |
Asynchronous | |
Synchronous |
Definition at line 47 of file qqmltypeloader_p.h.
QQmlTypeLoader::QQmlTypeLoader | ( | QQmlEngine * | engine | ) |
Constructs a new type loader that uses the given engine.
Definition at line 907 of file qqmltypeloader.cpp.
QQmlTypeLoader::~QQmlTypeLoader | ( | ) |
Destroys the type loader, first clearing the cache of any information about loaded files.
Definition at line 919 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 1093 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 144 of file qqmltypeloader_p.h.
|
inline |
Definition at line 145 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 1329 of file qqmltypeloader.cpp.
References QHash< Key, T >::begin(), QStringHash< T >::clear(), QHash< Key, T >::clear(), QCache< Key, T >::clear(), QQmlThread::discardMessages(), QHash< Key, T >::end(), 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 1218 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 1154 of file qqmltypeloader.cpp.
References Qt::CaseInsensitive, QCache< Key, T >::contains(), file, QCache< Key, T >::insert(), QCache< Key, T >::object(), Q_ASSERT, and QQmlFile::urlToLocalFileOrQrc().
Referenced by QQmlImportInstance::resolveType().
|
inlinestatic |
Definition at line 130 of file qqmltypeloader_p.h.
Referenced by QQmlPropertyCacheCreator< ObjectContainer >::createMetaObject(), QQmlCustomParser::evaluateEnum(), QV4::QQmlContextWrapper::getPropertyAndBase(), QQmlContext::importedScript(), QQmlPropertyPrivate::initProperty(), QQmlPropertyCacheCreator< ObjectContainer >::propertyCacheForObject(), QQmlCustomParser::resolveType(), and QV4::QQmlTypeWrapper::virtualGet().
|
inlinestatic |
Definition at line 138 of file qqmltypeloader_p.h.
References engine.
QQmlRefPointer< QQmlQmldirData > QQmlTypeLoader::getQmldir | ( | const QUrl & | url | ) |
Returns a QQmlQmldirData for url.
The QQmlQmldirData may be cached.
Definition at line 1066 of file qqmltypeloader.cpp.
References QHash< Key, T >::insert(), QUrl::isRelative(), QDir::isRelativePath(), load(), Q_ASSERT, url, QQmlFile::urlToLocalFileOrQrc(), and QHash< Key, T >::value().
Referenced by QQmlApplicationEnginePrivate::startLoad().
QQmlRefPointer< QQmlScriptBlob > QQmlTypeLoader::getScript | ( | const QUrl & | unNormalizedUrl | ) |
Return a QQmlScriptBlob for url.
The QQmlScriptData may be cached.
Definition at line 1032 of file qqmltypeloader.cpp.
References error, QQmlMetaType::findCachedCompilationUnit(), QHash< Key, T >::insert(), QDir::isRelativePath(), load(), loadWithCachedUnit(), QQmlMetaType::NoError, normalize(), Q_ASSERT, QQmlMetaType::RejectAll, 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 999 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 945 of file qqmltypeloader.cpp.
References QQmlTypeLoader::Blob::aotCacheMode(), error, QQmlMetaType::findCachedCompilationUnit(), QHash< Key, T >::insert(), QQmlDataBlob::isCompleteOrError(), 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 QQmlPropertyCacheCreator< ObjectContainer >::createMetaObject().
QQmlImportDatabase * QQmlTypeLoader::importDatabase | ( | ) | const |
Definition at line 929 of file qqmltypeloader.cpp.
References engine(), and QQmlEnginePrivate::get().
Referenced by QQmlImports::addFileImport().
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().
QQmlRefPointer< QQmlScriptBlob > QQmlTypeLoader::injectedScript | ( | const QUrl & | relativeUrl | ) |
Definition at line 1020 of file qqmltypeloader.cpp.
References QHash< Key, T >::constEnd(), QHash< Key, T >::constFind(), and it.
void QQmlTypeLoader::injectScript | ( | const QUrl & | relativeUrl, |
const QV4::Value & | value ) |
Definition at line 1009 of file qqmltypeloader.cpp.
References QQmlDataBlob::Complete, and QHash< Key, T >::insert().
void QQmlTypeLoader::invalidate | ( | ) |
Definition at line 82 of file qqmltypeloader.cpp.
Referenced by ~QQmlTypeLoader().
bool QQmlTypeLoader::isScriptLoaded | ( | const QUrl & | url | ) | const |
Definition at line 1415 of file qqmltypeloader.cpp.
References QHash< Key, T >::contains(), and url.
bool QQmlTypeLoader::isTypeLoaded | ( | const QUrl & | url | ) | const |
Definition at line 1409 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 171 of file qqmltypeloader_p.h.
Definition at line 934 of file qqmltypeloader.cpp.
Referenced by createQQmlType(), QQmlMetaType::findCompositeType(), getScript(), getType(), QV4::ExecutionEngine::loadModule(), QV4::ExecutionEngine::moduleForUrl(), QQmlMetaType::obtainCompilationUnit(), QQmlMetaType::qmlType(), QQmlMetaType::registerCompositeType(), singletonInstanceInfo(), and QQmlMetaType::typeForUrl().
|
inline |
Definition at line 184 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 1258 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 185 of file qqmltypeloader_p.h.
Referenced by QQmlProfilerAdapter::QQmlProfilerAdapter().
Definition at line 1310 of file qqmltypeloader.cpp.
References QQmlTypeLoaderQmldirContent::hasContent(), QStringHash< T >::insert(), url, and QStringHash< T >::value().
void QQmlTypeLoader::trimCache | ( | ) |
Definition at line 1363 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 172 of file qqmltypeloader_p.h.
|
friend |
Definition at line 246 of file qqmltypeloader_p.h.
Referenced by loadWithCachedUnit().
|
friend |
Definition at line 245 of file qqmltypeloader_p.h.
Referenced by load().
|
friend |
Definition at line 193 of file qqmltypeloader_p.h.
|
friend |
Definition at line 194 of file qqmltypeloader_p.h.
|
friend |
Definition at line 247 of file qqmltypeloader_p.h.
Referenced by loadWithStaticData().