Qt 4.8
Public Functions | Public Variables | List of all members
QDeclarativeImportedNamespace Class Reference

Public Functions

bool find (QDeclarativeTypeLoader *typeLoader, const QByteArray &type, int *vmajor, int *vminor, QDeclarativeType **type_return, QUrl *url_return, QUrl *base=0, QString *errorString=0)
 
bool find_helper (QDeclarativeTypeLoader *typeLoader, int i, const QByteArray &type, int *vmajor, int *vminor, QDeclarativeType **type_return, QUrl *url_return, QUrl *base=0, bool *typeRecursionDetected=0)
 

Public Variables

QList< bool > isLibrary
 
QList< int > majversions
 
QList< int > minversions
 
QList< QDeclarativeDirComponentsqmlDirComponents
 
QStringList uris
 
QStringList urls
 

Detailed Description

Definition at line 72 of file qdeclarativeimport.cpp.

Functions

◆ find()

bool QDeclarativeImportedNamespace::find ( QDeclarativeTypeLoader typeLoader,
const QByteArray type,
int *  vmajor,
int *  vminor,
QDeclarativeType **  type_return,
QUrl url_return,
QUrl base = 0,
QString errorString = 0 
)

Definition at line 681 of file qdeclarativeimport.cpp.

Referenced by QDeclarativeImportsPrivate::find(), and QDeclarativeImports::resolveType().

683 {
684  bool typeRecursionDetected = false;
685  for (int i=0; i<urls.count(); ++i) {
686  if (find_helper(typeLoader, i, type, vmajor, vminor, type_return, url_return, base, &typeRecursionDetected)) {
687  if (qmlCheckTypes()) {
688  // check for type clashes
689  for (int j = i+1; j<urls.count(); ++j) {
690  if (find_helper(typeLoader, j, type, vmajor, vminor, 0, 0, base)) {
691  if (errorString) {
692  QString u1 = urls.at(i);
693  QString u2 = urls.at(j);
694  if (base) {
695  QString b = base->toString();
696  int slash = b.lastIndexOf(QLatin1Char('/'));
697  if (slash >= 0) {
698  b = b.left(slash+1);
699  QString l = b.left(slash);
700  if (u1.startsWith(b))
701  u1 = u1.mid(b.count());
702  else if (u1 == l)
703  u1 = QDeclarativeImportDatabase::tr("local directory");
704  if (u2.startsWith(b))
705  u2 = u2.mid(b.count());
706  else if (u2 == l)
707  u2 = QDeclarativeImportDatabase::tr("local directory");
708  }
709  }
710 
711  if (u1 != u2)
712  *errorString
713  = QDeclarativeImportDatabase::tr("is ambiguous. Found in %1 and in %2")
714  .arg(u1).arg(u2);
715  else
716  *errorString
717  = QDeclarativeImportDatabase::tr("is ambiguous. Found in %1 in version %2.%3 and %4.%5")
718  .arg(u1)
719  .arg(majversions.at(i)).arg(minversions.at(i))
720  .arg(majversions.at(j)).arg(minversions.at(j));
721  }
722  return false;
723  }
724  }
725  }
726  return true;
727  }
728  }
729  if (errorString) {
730  if (typeRecursionDetected)
731  *errorString = QDeclarativeImportDatabase::tr("is instantiated recursively");
732  else
733  *errorString = QDeclarativeImportDatabase::tr("is not a type");
734  }
735  return false;
736 }
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int count() const
Definition: qstring.h:103
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
bool find_helper(QDeclarativeTypeLoader *typeLoader, int i, const QByteArray &type, int *vmajor, int *vminor, QDeclarativeType **type_return, QUrl *url_return, QUrl *base=0, bool *typeRecursionDetected=0)
QFactoryLoader * l
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ find_helper()

bool QDeclarativeImportedNamespace::find_helper ( QDeclarativeTypeLoader typeLoader,
int  i,
const QByteArray type,
int *  vmajor,
int *  vminor,
QDeclarativeType **  type_return,
QUrl url_return,
QUrl base = 0,
bool *  typeRecursionDetected = 0 
)

Definition at line 289 of file qdeclarativeimport.cpp.

292 {
293  int vmaj = majversions.at(i);
294  int vmin = minversions.at(i);
295 
296  QByteArray qt = uris.at(i).toUtf8();
297  qt += '/';
298  qt += type;
299 
301  if (t) {
302  if (vmajor) *vmajor = vmaj;
303  if (vminor) *vminor = vmin;
304  if (type_return)
305  *type_return = t;
306  return true;
307  }
308 
309  QDeclarativeDirComponents qmldircomponents = qmlDirComponents.at(i);
310 
311  bool typeWasDeclaredInQmldir = false;
312  if (!qmldircomponents.isEmpty()) {
313  const QString typeName = QString::fromUtf8(type);
314  foreach (const QDeclarativeDirParser::Component &c, qmldircomponents) {
315  if (c.typeName == typeName) {
316  typeWasDeclaredInQmldir = true;
317 
318  // importing version -1 means import ALL versions
319  if ((vmaj == -1) || (c.majorVersion < vmaj || (c.majorVersion == vmaj && vmin >= c.minorVersion))) {
320  QUrl url = QUrl(urls.at(i) + QLatin1Char('/') + QString::fromUtf8(type) + QLatin1String(".qml"));
321  QUrl candidate = url.resolved(QUrl(c.fileName));
322  if (c.internal && base) {
323  if (base->resolved(QUrl(c.fileName)) != candidate)
324  continue; // failed attempt to access an internal type
325  }
326  if (base && *base == candidate) {
327  if (typeRecursionDetected)
328  *typeRecursionDetected = true;
329  continue; // no recursion
330  }
331  if (url_return)
332  *url_return = candidate;
333  return true;
334  }
335  }
336  }
337  }
338 
339  if (!typeWasDeclaredInQmldir && !isLibrary.at(i)) {
340  // XXX search non-files too! (eg. zip files, see QT-524)
341  QUrl url = QUrl(urls.at(i) + QLatin1Char('/') + QString::fromUtf8(type) + QLatin1String(".qml"));
343  if (!typeLoader->absoluteFilePath(file).isEmpty()) {
344  if (base && *base == url) { // no recursion
345  if (typeRecursionDetected)
346  *typeRecursionDetected = true;
347  } else {
348  if (url_return)
349  *url_return = url;
350  return true;
351  }
352  }
353  }
354  return false;
355 }
static QString urlToLocalFileOrQrc(const QUrl &url)
int type
Definition: qmetatype.cpp:239
unsigned char c[8]
Definition: qnumeric_p.h:62
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QDeclarativeType * qmlType(const QByteArray &, int, int)
Returns the type (if any) of URI-qualified named name in version specified by version_major and versi...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
const char * typeName
Definition: qmetatype.cpp:239
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
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
QString absoluteFilePath(const QString &path)
Returns the absolute filename of path via a directory cache for files named "qmldir", "*.qml", "*.js" Returns a empty string if the path does not exist.
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819
QList< QDeclarativeDirComponents > qmlDirComponents
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Properties

◆ isLibrary

QList<bool> QDeclarativeImportedNamespace::isLibrary

◆ majversions

QList<int> QDeclarativeImportedNamespace::majversions

Definition at line 77 of file qdeclarativeimport.cpp.

Referenced by QDeclarativeImportsPrivate::add().

◆ minversions

QList<int> QDeclarativeImportedNamespace::minversions

Definition at line 78 of file qdeclarativeimport.cpp.

Referenced by QDeclarativeImportsPrivate::add().

◆ qmlDirComponents

QList<QDeclarativeDirComponents> QDeclarativeImportedNamespace::qmlDirComponents

Definition at line 80 of file qdeclarativeimport.cpp.

Referenced by QDeclarativeImportsPrivate::add().

◆ uris

QStringList QDeclarativeImportedNamespace::uris

Definition at line 75 of file qdeclarativeimport.cpp.

Referenced by QDeclarativeImportsPrivate::add().

◆ urls

QStringList QDeclarativeImportedNamespace::urls

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