Qt 4.8
Public Functions | Properties | Friends | List of all members
QDeclarativeImports Class Reference

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

#include <qdeclarativeimport_p.h>

Public Functions

bool addImport (QDeclarativeImportDatabase *, const QString &uri, const QString &prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, const QDeclarativeDirComponents &qmldircomponentsnetwork, QString *errorString)
 Adds information to imports such that subsequent calls to resolveType() will resolve types qualified by prefix by considering types found at the given uri. More...
 
QUrl baseUrl () const
 Returns the base URL to be used for all relative file imports added. More...
 
QDeclarativeImportsoperator= (const QDeclarativeImports &)
 
void populateCache (QDeclarativeTypeNameCache *cache, QDeclarativeEngine *) const
 
 QDeclarativeImports ()
 
 QDeclarativeImports (QDeclarativeTypeLoader *)
 
 QDeclarativeImports (const QDeclarativeImports &)
 
bool resolveType (const QByteArray &type, QDeclarativeType **type_return, QUrl *url_return, int *version_major, int *version_minor, QDeclarativeImportedNamespace **ns_return, QString *errorString=0) const
 The given (namespace qualified) type is resolved to either. More...
 
bool resolveType (QDeclarativeImportedNamespace *, const QByteArray &type, QDeclarativeType **type_return, QUrl *url_return, int *version_major, int *version_minor) const
 Searching only in the namespace ns (previously returned in a call to resolveType(), type is found and returned to either a QDeclarativeType stored at type_return, or a component located at url_return. More...
 
void setBaseUrl (const QUrl &url)
 Sets the base URL to be used for all relative file imports added. More...
 
 ~QDeclarativeImports ()
 

Properties

QDeclarativeImportsPrivated
 

Friends

class QDeclarativeImportDatabase
 

Detailed Description

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

Warning
This function is not part of the public interface.

Definition at line 73 of file qdeclarativeimport_p.h.

Constructors and Destructors

◆ QDeclarativeImports() [1/3]

QDeclarativeImports::QDeclarativeImports ( )

Definition at line 142 of file qdeclarativeimport.cpp.

◆ QDeclarativeImports() [2/3]

QDeclarativeImports::QDeclarativeImports ( QDeclarativeTypeLoader typeLoader)

Definition at line 146 of file qdeclarativeimport.cpp.

147  : d(new QDeclarativeImportsPrivate(typeLoader)){
148 }
QDeclarativeImportsPrivate * d

◆ QDeclarativeImports() [3/3]

QDeclarativeImports::QDeclarativeImports ( const QDeclarativeImports copy)

Definition at line 126 of file qdeclarativeimport.cpp.

127 : d(copy.d)
128 {
129  ++d->ref;
130 }
QDeclarativeImportsPrivate * d

◆ ~QDeclarativeImports()

QDeclarativeImports::~QDeclarativeImports ( )

Definition at line 150 of file qdeclarativeimport.cpp.

151 {
152  if (--d->ref == 0)
153  delete d;
154 }
QDeclarativeImportsPrivate * d

Functions

◆ addImport()

bool QDeclarativeImports::addImport ( QDeclarativeImportDatabase importDb,
const QString uri,
const QString prefix,
int  vmaj,
int  vmin,
QDeclarativeScriptParser::Import::Type  importType,
const QDeclarativeDirComponents qmldircomponentsnetwork,
QString errorString 
)

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

Warning
This function is not part of the public interface.

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().

Definition at line 827 of file qdeclarativeimport.cpp.

Referenced by QDeclarativeTypeData::resolveTypes().

832 {
833  if (qmlImportTrace())
834  qDebug().nospace() << "QDeclarativeImports(" << qPrintable(baseUrl().toString()) << ")" << "::addImport: "
835  << uri << " " << vmaj << '.' << vmin << " "
836  << (importType==QDeclarativeScriptParser::Import::Library? "Library" : "File")
837  << " as " << prefix;
838 
839  return d->add(qmldircomponentsnetwork, uri, prefix, vmaj, vmin, importType, importDb, errorString);
840 }
bool add(const QDeclarativeDirComponents &qmldircomponentsnetwork, const QString &uri_arg, const QString &prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, QDeclarativeImportDatabase *database, QString *errorString)
Q_CORE_EXPORT void qDebug(const char *,...)
static QString toString(Register *reg, int type, bool *ok=0)
QUrl baseUrl() const
Returns the base URL to be used for all relative file imports added.
QDeclarativeImportsPrivate * d
#define qPrintable(string)
Definition: qglobal.h:1750

◆ baseUrl()

QUrl QDeclarativeImports::baseUrl ( ) const

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

Definition at line 167 of file qdeclarativeimport.cpp.

Referenced by QDeclarativeTypeData::compile(), resolveType(), and QDeclarativeTypeData::resolveTypes().

168 {
169  return d->base;
170 }
QDeclarativeImportsPrivate * d

◆ operator=()

QDeclarativeImports & QDeclarativeImports::operator= ( const QDeclarativeImports copy)

Definition at line 133 of file qdeclarativeimport.cpp.

134 {
135  ++copy.d->ref;
136  if (--d->ref == 0)
137  delete d;
138  d = copy.d;
139  return *this;
140 }
QDeclarativeImportsPrivate * d

◆ populateCache()

void QDeclarativeImports::populateCache ( QDeclarativeTypeNameCache cache,
QDeclarativeEngine engine 
) const

Definition at line 201 of file qdeclarativeimport.cpp.

Referenced by QDeclarativeCompiler::compileTree().

202 {
204 
206  iter != d->set.end(); ++iter) {
207 
208  QDeclarativeTypeNameCache::Data *d = cache->data(iter.key());
209  if (d) {
210  if (!d->typeNamespace)
211  cacheForNamespace(engine, *(*iter), d->typeNamespace);
212  } else {
213  QDeclarativeTypeNameCache *nc = cacheForNamespace(engine, *(*iter), 0);
214  cache->add(iter.key(), nc);
215  nc->release();
216  }
217  }
218 
219  cacheForNamespace(engine, set, cache);
220 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
void add(const QString &, int)
QHash< QString, QDeclarativeImportedNamespace *> set
QDeclarativeImportsPrivate * d
static QDeclarativeTypeNameCache * cacheForNamespace(QDeclarativeEngine *engine, const QDeclarativeImportedNamespace &set, QDeclarativeTypeNameCache *cache)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
QDeclarativeTypeNameCache * typeNamespace
QDeclarativeImportedNamespace unqualifiedset
Data * data(const QString &) const

◆ resolveType() [1/2]

bool QDeclarativeImports::resolveType ( const QByteArray type,
QDeclarativeType **  type_return,
QUrl url_return,
int *  vmaj,
int *  vmin,
QDeclarativeImportedNamespace **  ns_return,
QString errorString = 0 
) const

The given (namespace qualified) type is resolved to either.

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

See also
addImport()

Definition at line 239 of file qdeclarativeimport.cpp.

Referenced by QDeclarativeCompiler::buildDynamicMeta(), QDeclarativeCompiler::buildProperty(), QDeclarativeCompiler::buildPropertyInNamespace(), QDeclarativeCompiler::evaluateEnum(), QDeclarativeCompiler::resolveType(), QDeclarativeTypeData::resolveTypes(), and QDeclarativeCompiler::testQualifiedEnumAssignment().

242 {
244  if (ns) {
245  if (ns_return)
246  *ns_return = ns;
247  return true;
248  }
249  if (type_return || url_return) {
250  if (d->find(type,vmaj,vmin,type_return,url_return, errorString)) {
251  if (qmlImportTrace()) {
252  if (type_return && *type_return && url_return && !url_return->isEmpty())
253  qDebug().nospace() << "QDeclarativeImports(" << qPrintable(baseUrl().toString()) << ")" << "::resolveType: "
254  << type << " => " << (*type_return)->typeName() << " " << *url_return;
255  if (type_return && *type_return)
256  qDebug().nospace() << "QDeclarativeImports(" << qPrintable(baseUrl().toString()) << ")" << "::resolveType: "
257  << type << " => " << (*type_return)->typeName();
258  if (url_return && !url_return->isEmpty())
259  qDebug().nospace() << "QDeclarativeImports(" << qPrintable(baseUrl().toString()) << ")" << "::resolveType: "
260  << type << " => " << *url_return;
261  }
262  return true;
263  }
264  }
265  return false;
266 }
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
Q_CORE_EXPORT void qDebug(const char *,...)
static QString toString(Register *reg, int type, bool *ok=0)
QUrl baseUrl() const
Returns the base URL to be used for all relative file imports added.
QDeclarativeImportsPrivate * d
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
QDeclarativeImportedNamespace * findNamespace(const QString &type)
bool find(const QByteArray &type, int *vmajor, int *vminor, QDeclarativeType **type_return, QUrl *url_return, QString *errorString)
#define qPrintable(string)
Definition: qglobal.h:1750

◆ resolveType() [2/2]

bool QDeclarativeImports::resolveType ( QDeclarativeImportedNamespace ns,
const QByteArray type,
QDeclarativeType **  type_return,
QUrl url_return,
int *  vmaj,
int *  vmin 
) const

Searching only in the namespace ns (previously returned in a call to resolveType(), type is found and returned to either a QDeclarativeType stored at type_return, or a component located at url_return.

Warning
This function is not part of the public interface.

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

Definition at line 281 of file qdeclarativeimport.cpp.

284 {
286  return ns->find(d->typeLoader,type,vmaj,vmin,type_return,url_return);
287 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool find(QDeclarativeTypeLoader *typeLoader, const QByteArray &type, int *vmajor, int *vminor, QDeclarativeType **type_return, QUrl *url_return, QUrl *base=0, QString *errorString=0)
QDeclarativeImportsPrivate * d
QDeclarativeTypeLoader * typeLoader

◆ setBaseUrl()

void QDeclarativeImports::setBaseUrl ( const QUrl url)

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

Definition at line 159 of file qdeclarativeimport.cpp.

Referenced by QDeclarativeTypeData::dataReceived().

160 {
161  d->base = url;
162 }
QDeclarativeImportsPrivate * d

Friends and Related Functions

◆ QDeclarativeImportDatabase

Definition at line 104 of file qdeclarativeimport_p.h.

Properties

◆ d

QDeclarativeImportsPrivate* QDeclarativeImports::d
private

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