Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QQmlImports Class Referencefinal

The QQmlImports class encapsulates one QML document's import statements. More...

#include <qqmlimport_p.h>

+ Inheritance diagram for QQmlImports:
+ Collaboration diagram for QQmlImports:

Classes

struct  CompositeSingletonReference
 
struct  ScriptReference
 

Public Types

enum  ImportVersion { FullyVersioned , PartiallyVersioned , Unversioned }
 
enum  ImportFlag : quint8 { ImportNoFlag = 0x0 , ImportIncomplete = 0x1 }
 

Public Member Functions

 QQmlImports (QQmlTypeLoader *loader)
 
 ~QQmlImports ()
 
void setBaseUrl (const QUrl &url, const QString &urlString=QString())
 Sets the base URL to be used for all relative file imports added.
 
QUrl baseUrl () const
 
bool resolveType (const QHashedStringRef &type, QQmlType *type_return, QTypeRevision *version_return, QQmlImportNamespace **ns_return, QList< QQmlError > *errors=nullptr, QQmlType::RegistrationType registrationType=QQmlType::AnyRegistrationType, bool *typeRecursionDetected=nullptr) const
 
QTypeRevision addImplicitImport (QQmlImportDatabase *importDb, QString *localQmldir, QList< QQmlError > *errors)
 
bool addInlineComponentImport (QQmlImportInstance *const importInstance, const QString &name, const QUrl importUrl)
 
QTypeRevision addFileImport (QQmlImportDatabase *importDb, const QString &uri, const QString &prefix, QTypeRevision version, ImportFlags flags, quint16 precedence, QString *localQmldir, QList< QQmlError > *errors)
 
QTypeRevision addLibraryImport (QQmlImportDatabase *importDb, const QString &uri, const QString &prefix, QTypeRevision version, const QString &qmldirIdentifier, const QString &qmldirUrl, ImportFlags flags, quint16 precedence, QList< QQmlError > *errors)
 
QTypeRevision updateQmldirContent (QQmlImportDatabase *importDb, const QString &uri, const QString &prefix, const QString &qmldirIdentifier, const QString &qmldirUrl, QList< QQmlError > *errors)
 
void populateCache (QQmlTypeNameCache *cache) const
 
QList< ScriptReferenceresolvedScripts () const
 
QList< CompositeSingletonReferenceresolvedCompositeSingletons () const
 
- Public Member Functions inherited from QQmlRefCounted< QQmlImports >
void release () const
 
- Public Member Functions inherited from QQmlRefCount
 QQmlRefCount ()
 
void addref () const
 
int count () const
 

Static Public Member Functions

static QStringList completeQmldirPaths (const QString &uri, const QStringList &basePaths, QTypeRevision version)
 Forms complete paths to a qmldir file, from a base URL, a module URI and version specification.
 
static QString versionString (QTypeRevision version, ImportVersion importVersion)
 
static bool isLocal (const QString &url)
 
static bool isLocal (const QUrl &url)
 
static QUrl urlFromLocalFileOrQrcOrUrl (const QString &)
 
static void setDesignerSupportRequired (bool b)
 
static QTypeRevision validVersion (QTypeRevision version=QTypeRevision())
 

Friends

class QQmlImportDatabase
 

Additional Inherited Members

- Protected Member Functions inherited from QQmlRefCounted< QQmlImports >
 ~QQmlRefCounted ()
 

Detailed Description

The QQmlImports class encapsulates one QML document's import statements.

Definition at line 118 of file qqmlimport_p.h.

Member Enumeration Documentation

◆ ImportFlag

Enumerator
ImportNoFlag 
ImportIncomplete 

Definition at line 124 of file qqmlimport_p.h.

◆ ImportVersion

Enumerator
FullyVersioned 
PartiallyVersioned 
Unversioned 

Definition at line 122 of file qqmlimport_p.h.

Constructor & Destructor Documentation

◆ QQmlImports()

QQmlImports::QQmlImports ( QQmlTypeLoader loader)
inline

Definition at line 130 of file qqmlimport_p.h.

◆ ~QQmlImports()

QQmlImports::~QQmlImports ( )
inline

Definition at line 131 of file qqmlimport_p.h.

Member Function Documentation

◆ addFileImport()

QTypeRevision QQmlImports::addFileImport ( QQmlImportDatabase database,
const QString uri,
const QString prefix,
QTypeRevision  version,
ImportFlags  flags,
quint16  precedence,
QString localQmldir,
QList< QQmlError > *  errors 
)

Adds information to database such that subsequent calls to resolveType() will resolve types qualified by prefix by considering types found at the given uri.

The uri is either a directory (if importType is FileImport), or a URI resolved using paths added via addImportPath() (if importType is LibraryImport).

The prefix may be empty, in which case the import location is considered for unqualified types.

The base URL must already have been set with Import::setBaseUrl().

Optionally, the qmldir the import resolved to can be returned by providing the localQmldir parameter. Not all imports will have a local qmldir. If there is none, the localQmldir parameter won't be set.

Returns a valid QTypeRevision on success, and an invalid one on failure. In case of failure, the errors array will filled appropriately.

Definition at line 1286 of file qqmlimport.cpp.

References QQmlTypeLoader::absoluteFilePath(), arg, Backslash, baseUrl(), QString::chop(), Colon, QList< T >::constBegin(), QList< T >::constEnd(), dir, QQmlTypeLoader::directoryExists(), QString::endsWith(), QQmlTypeLoader::engine(), error, QQmlTypeLoaderQmldirContent::hasContent(), QQmlImportInstance::Implicit, QV4::CompiledData::Import::ImportFile, ImportIncomplete, QQmlImportNamespace::imports, QQmlEngine::interceptUrl(), QUrl::isEmpty(), QString::isEmpty(), QQmlFile::isLocalFile(), QTypeRevision::isValid(), it, QString::lastIndexOf(), lcQmlImport(), QString::left(), QQmlImportNamespace::prefix, QList< T >::prepend(), Q_ASSERT, qCDebug, QQmlAbstractUrlInterceptor::QmldirFile, qPrintable, QQmlImportInstance::setQmldirContent(), Slash, Slash_qmldir, QString::startsWith(), String_qmldir, toString(), QUrl::toString(), QQmlTypeLoaderQmldirContent::typeNamespace(), url, QQmlFile::urlToLocalFileOrQrc(), and validVersion().

+ Here is the call graph for this function:

◆ addImplicitImport()

QQmlImports::addImplicitImport ( QQmlImportDatabase importDb,
QString localQmldir,
QList< QQmlError > *  errors 
)
inline

Adds an implicit "." file import. This is equivalent to calling addFileImport(), but error messages related to the path or qmldir file not existing are suppressed.

Additionally, this will add the import with lowest instead of highest precedence.

Definition at line 146 of file qqmlimport_p.h.

References baseUrl, QQmlImportInstance::Implicit, lcQmlImport(), Q_ASSERT, qCDebug, qPrintable, and toString().

+ Here is the call graph for this function:

◆ addInlineComponentImport()

bool QQmlImports::addInlineComponentImport ( QQmlImportInstance *const  importInstance,
const QString name,
const QUrl  importUrl 
)

Definition at line 1494 of file qqmlimport.cpp.

References QQmlImportNamespace::imports, QQmlImportInstance::isInlineComponent, QList< T >::push_back(), QQmlImportNamespace::setNeedsSorting(), QUrl::toString(), QQmlImportInstance::uri, QQmlImportInstance::url, QQmlImportInstance::version, and QTypeRevision::zero().

+ Here is the call graph for this function:

◆ addLibraryImport()

◆ baseUrl()

QQmlImports::baseUrl ( ) const
inline

Returns the base URL to be used for all relative file imports added.

Definition at line 138 of file qqmlimport_p.h.

Referenced by addFileImport(), addLibraryImport(), QQmlTypeData::allDependenciesDone(), resolvedCompositeSingletons(), and updateQmldirContent().

+ Here is the caller graph for this function:

◆ completeQmldirPaths()

QStringList QQmlImports::completeQmldirPaths ( const QString uri,
const QStringList basePaths,
QTypeRevision  version 
)
static

Forms complete paths to a qmldir file, from a base URL, a module URI and version specification.

For example, QtQml.Models 2.0:

  • base/QtQml/Models.2.0/qmldir
  • base/QtQml.2.0/Models/qmldir
  • base/QtQml/Models.2/qmldir
  • base/QtQml.2/Models/qmldir
  • base/QtQml/Models/qmldir

Definition at line 418 of file qqmlimport.cpp.

References qQmlResolveImportPaths(), and Slash_qmldir.

Referenced by QQmlImportDatabase::locateLocalQmldir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isLocal() [1/2]

static bool QQmlImports::isLocal ( const QString url)
inlinestatic

Definition at line 201 of file qqmlimport_p.h.

References QString::isEmpty(), url, and QQmlFile::urlToLocalFileOrQrc().

+ Here is the call graph for this function:

◆ isLocal() [2/2]

static bool QQmlImports::isLocal ( const QUrl url)
inlinestatic

Definition at line 206 of file qqmlimport_p.h.

References QString::isEmpty(), url, and QQmlFile::urlToLocalFileOrQrc().

+ Here is the call graph for this function:

◆ populateCache()

void QQmlImports::populateCache ( QQmlTypeNameCache cache) const

Definition at line 236 of file qqmlimport.cpp.

References cache, QFieldList< N, nextMember >::first(), QQmlImportRef::m_qualifier, QQmlImportRef::modules, QFieldList< N, nextMember >::next(), set, and QQmlMetaType::typeModule().

Referenced by QQmlScriptBlob::done().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolvedCompositeSingletons()

QList< QQmlImports::CompositeSingletonReference > QQmlImports::resolvedCompositeSingletons ( ) const

Definition at line 337 of file qqmlimport.cpp.

References baseUrl(), QList< T >::begin(), QList< T >::end(), findCompositeSingletons(), QFieldList< N, nextMember >::first(), QFieldList< N, nextMember >::next(), and set.

+ Here is the call graph for this function:

◆ resolvedScripts()

QList< QQmlImports::ScriptReference > QQmlImports::resolvedScripts ( ) const

Definition at line 372 of file qqmlimport.cpp.

References QList< T >::append(), QFieldList< N, nextMember >::first(), QFieldList< N, nextMember >::next(), QUrl::resolved(), and set.

+ Here is the call graph for this function:

◆ resolveType()

bool QQmlImports::resolveType ( const QHashedStringRef type,
QQmlType type_return,
QTypeRevision version_return,
QQmlImportNamespace **  ns_return,
QList< QQmlError > *  errors = nullptr,
QQmlType::RegistrationType  registrationType = QQmlType::AnyRegistrationType,
bool *  typeRecursionDetected = nullptr 
) const

The given (namespace qualified) type is resolved to either \list

If any return pointer is 0, the corresponding search is not done.

See also
addFileImport(), addLibraryImport

Definition at line 452 of file qqmlimport.cpp.

References QQmlType::isComposite(), QQmlType::isCompositeSingleton(), QQmlType::isInlineComponentType(), QQmlType::isValid(), lcQmlImport(), RESOLVE_TYPE_DEBUG, resolveType(), QQmlType::sourceUrl(), and QQmlType::typeName().

Referenced by QQmlPropertyCacheCreator< ObjectContainer >::createMetaObject(), QQmlCustomParser::evaluateEnum(), QQmlPropertyCacheCreator< ObjectContainer >::metaTypeForParameter(), QQmlPropertyCacheCreator< ObjectContainer >::propertyCacheForObject(), resolveType(), QQmlCustomParser::resolveType(), and LoadHelper::resolveType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setBaseUrl()

void QQmlImports::setBaseUrl ( const QUrl url,
const QString urlString = QString() 
)

Sets the base URL to be used for all relative file imports added.

Definition at line 209 of file qqmlimport.cpp.

References QString::isEmpty(), QUrl::toString(), and url.

+ Here is the call graph for this function:

◆ setDesignerSupportRequired()

void QQmlImports::setDesignerSupportRequired ( bool  b)
static

Definition at line 1515 of file qqmlimport.cpp.

References designerSupportRequired.

◆ updateQmldirContent()

QTypeRevision QQmlImports::updateQmldirContent ( QQmlImportDatabase importDb,
const QString uri,
const QString prefix,
const QString qmldirIdentifier,
const QString qmldirUrl,
QList< QQmlError > *  errors 
)

Definition at line 1428 of file qqmlimport.cpp.

References arg, baseUrl(), error, QQmlImportNamespace::findImport(), QQmlTypeLoaderQmldirContent::hasContent(), QList< T >::isEmpty(), QTypeRevision::isValid(), lcQmlImport(), QQmlMetaType::matchingModuleVersion(), QList< T >::prepend(), Q_ASSERT, qDebug, qPrintable, toString(), and validVersion().

+ Here is the call graph for this function:

◆ urlFromLocalFileOrQrcOrUrl()

QUrl QQmlImports::urlFromLocalFileOrQrcOrUrl ( const QString file)
static

Definition at line 1505 of file qqmlimport.cpp.

References Colon, file, QUrl::fromLocalFile(), QUrl::scheme(), QString::size(), and url.

Referenced by QQmlImportDatabase::locateLocalQmldir(), and QQmlMetaType::registerPluginTypes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validVersion()

QTypeRevision QQmlImports::validVersion ( QTypeRevision  version = QTypeRevision())
static

Definition at line 200 of file qqmlimport.cpp.

References QTypeRevision::fromMinorVersion(), and QTypeRevision::isValid().

Referenced by addFileImport(), addLibraryImport(), QQmlPluginImporter::importDynamicPlugin(), QQmlPluginImporter::importPlugins(), QQmlPluginImporter::importStaticPlugin(), and updateQmldirContent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ versionString()

QString QQmlImports::versionString ( QTypeRevision  version,
ImportVersion  importVersion 
)
static

Definition at line 427 of file qqmlimport.cpp.

References QString::asprintf(), FullyVersioned, QTypeRevision::majorVersion(), QTypeRevision::minorVersion(), and PartiallyVersioned.

Referenced by versionUriList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QQmlImportDatabase

friend class QQmlImportDatabase
friend

Definition at line 218 of file qqmlimport_p.h.


The documentation for this class was generated from the following files: