Qt 4.8
Classes | Macros | Functions
qdeclarativemetatype.cpp File Reference
#include <QtDeclarative/qdeclarativeprivate.h>
#include "private/qdeclarativemetatype_p.h"
#include "private/qdeclarativeproxymetaobject_p.h"
#include "private/qdeclarativecustomparser_p.h"
#include "private/qdeclarativeguard_p.h"
#include "private/qdeclarativeengine_p.h"
#include "private/qdeclarativeitemsmodule_p.h"
#include "private/qdeclarativeutilmodule_p.h"
#include <QtCore/qdebug.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qbitarray.h>
#include <QtCore/qreadwritelock.h>
#include <qfileinfo.h>
#include <qdir.h>
#include <qmetatype.h>
#include <qobjectdefs.h>
#include <qdatetime.h>
#include <qbytearray.h>
#include <qreadwritelock.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qvector.h>
#include <qlocale.h>
#include <QtCore/qcryptographichash.h>
#include <QtScript/qscriptvalue.h>
#include <ctype.h>
#include <qbitarray.h>
#include <qurl.h>
#include <qvariant.h>
#include <qsize.h>
#include <qpoint.h>
#include <qrect.h>
#include <qline.h>
#include <qvector3d.h>
#include <QtGui/qfont.h>
#include <QtGui/qpixmap.h>
#include <QtGui/qbrush.h>
#include <QtGui/qcolor.h>
#include <QtGui/qpalette.h>
#include <QtGui/qicon.h>
#include <QtGui/qimage.h>
#include <QtGui/qpolygon.h>
#include <QtGui/qregion.h>
#include <QtGui/qbitmap.h>
#include <QtGui/qcursor.h>
#include <QtGui/qsizepolicy.h>
#include <QtGui/qkeysequence.h>
#include <QtGui/qpen.h>
#include <QtGui/qtextformat.h>
#include <QtGui/qmatrix.h>
#include <QtGui/qtransform.h>
#include <QtGui/qmatrix4x4.h>
#include <QtGui/qvector2d.h>
#include <QtGui/qvector3d.h>
#include <QtGui/qvector4d.h>
#include <QtGui/qquaternion.h>

Go to the source code of this file.

Classes

struct  QDeclarativeMetaTypeData
 
struct  QDeclarativeMetaTypeData::ModuleInfo
 
struct  QDeclarativeRegisteredComponentData
 
class  QDeclarativeTypePrivate
 

Macros

#define NS(x)   QT_PREPEND_NAMESPACE(x)
 

Functions

static void clone (QMetaObjectBuilder &builder, const QMetaObject *mo, const QMetaObject *ignoreStart, const QMetaObject *ignoreEnd)
 
 for (int ii=mo->methodOffset();ii< mo->methodCount();++ii)
 
 Q_DECLARE_METATYPE (QScriptValue)
 
int registerAutoParentFunction (QDeclarativePrivate::RegisterAutoParent &autoparent)
 
int registerComponent (const QDeclarativePrivate::RegisterComponent &data)
 
int registerInterface (const QDeclarativePrivate::RegisterInterface &interface)
 
int registerType (const QDeclarativePrivate::RegisterType &type)
 

Macro Definition Documentation

◆ NS

#define NS (   x)    QT_PREPEND_NAMESPACE(x)

Definition at line 90 of file qdeclarativemetatype.cpp.

Referenced by QDeclarativeMetaType::copy().

Function Documentation

◆ clone()

static void clone ( QMetaObjectBuilder builder,
const QMetaObject mo,
const QMetaObject ignoreStart,
const QMetaObject ignoreEnd 
)
static

Definition at line 293 of file qdeclarativemetatype.cpp.

Referenced by QDeclarativeTypePrivate::init(), QStandardItem::isDropEnabled(), and QTestEvent::~QTestEvent().

295 {
296  // Clone Q_CLASSINFO
297  for (int ii = mo->classInfoOffset(); ii < mo->classInfoCount(); ++ii) {
298  QMetaClassInfo info = mo->classInfo(ii);
299 
300  int otherIndex = ignoreEnd->indexOfClassInfo(info.name());
301  if (otherIndex >= ignoreStart->classInfoOffset() + ignoreStart->classInfoCount()) {
302  // Skip
303  } else {
304  builder.addClassInfo(info.name(), info.value());
305  }
306  }
307 
308  // Clone int ii;; ii < mo->propertyCount(); ++ii) {
309  QMetaProperty property = mo->property(ii);
310 
311  int otherIndex = ignoreEnd->indexOfProperty(property.name());
312  if (otherIndex >= ignoreStart->propertyOffset() + ignoreStart->propertyCount()) {
313  builder.addProperty(QByteArray("__qml_ignore__") + property.name(), QByteArray("void"));
314  // Skip
315  } else {
316  builder.addProperty(property);
317  }
318  }
static mach_timebase_info_data_t info
QMetaClassInfo classInfo(int index) const
Returns the meta-data for the item of class information with the given index.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int propertyCount() const
Returns the number of properties in this class, including the number of properties provided by each b...
const char * value() const
Returns the value of this item.
int indexOfProperty(const char *name) const
Finds property name and returns its index; otherwise returns -1.
QMetaPropertyBuilder addProperty(const QByteArray &name, const QByteArray &type, int notifierId=-1)
Adds a new readable/writable property to this class with the specified name and type.
const char * name() const
Returns the name of this item.
int classInfoCount() const
Returns the number of items of class information in this class.
The QMetaClassInfo class provides additional information about a class.
Definition: qmetaobject.h:224
int classInfoOffset() const
Returns the class information offset for this class; i.e.
const char * property
Definition: qwizard.cpp:138
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
int addClassInfo(const QByteArray &name, const QByteArray &value)
Adds name and value as an item of class information to this class.
int propertyOffset() const
Returns the property offset for this class; i.e.
int indexOfClassInfo(const char *name) const
Finds class information item name and returns its index; otherwise returns -1.
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.

◆ for()

for ( int  ii = mo->methodOffset(); ii < mo->methodCount(); ++ii)

Definition at line 321 of file qdeclarativemetatype.cpp.

Referenced by QMacPixmapData::copy(), dither_to_Mono(), QX11PixmapData::fromImage(), getGlyphData(), QTreeView::keyboardSearch(), QTextLineItemIterator::next(), QHeaderView::sectionsInserted(), QByteArray::toHex(), QX11PixmapData::toImage(), and QTextEngine::width().

321  {
322  QMetaMethod method = mo->method(ii);
323 
324  // More complex - need to search name
325  QByteArray name = method.signature();
326  int parenIdx = name.indexOf('(');
327  if (parenIdx != -1) name = name.left(parenIdx);
328 
329 
330  bool found = false;
331 
332  for (int ii = ignoreStart->methodOffset() + ignoreStart->methodCount();
333  !found && ii < ignoreEnd->methodOffset() + ignoreEnd->methodCount();
334  ++ii) {
335 
336  QMetaMethod other = ignoreEnd->method(ii);
337  QByteArray othername = other.signature();
338  int parenIdx = othername.indexOf('(');
339  if (parenIdx != -1) othername = othername.left(parenIdx);
340 
341  found = name == othername;
342  }
343 
344  QMetaMethodBuilder m = builder.addMethod(method);
345  if (found) // SKIP
347  }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void setAccess(QMetaMethod::Access value)
Sets the access specification of this method (private, protected, or public) to value.
The QMetaMethodBuilder class enables modifications to a method definition on a meta object builder...
const char * name
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56

◆ Q_DECLARE_METATYPE()

Q_DECLARE_METATYPE ( QScriptValue  )

◆ registerAutoParentFunction()

int registerAutoParentFunction ( QDeclarativePrivate::RegisterAutoParent autoparent)

Definition at line 589 of file qdeclarativemetatype.cpp.

Referenced by QDeclarativePrivate::qmlregister().

590 {
591  QWriteLocker lock(metaTypeDataLock());
592  QDeclarativeMetaTypeData *data = metaTypeData();
593 
594  data->parentFunctions.append(autoparent.function);
595 
596  return data->parentFunctions.count() - 1;
597 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QList< QDeclarativePrivate::AutoParentFunction > parentFunctions
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static const char * data(const QByteArray &arr)
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
static QReadWriteLock lock
Definition: proxyconf.cpp:399

◆ registerComponent()

int registerComponent ( const QDeclarativePrivate::RegisterComponent data)

Definition at line 679 of file qdeclarativemetatype.cpp.

680 {
681  if (data.typeName) {
682  for (int ii = 0; data.typeName[ii]; ++ii) {
683  if (!isalnum(data.typeName[ii])) {
684  qWarning("qmlRegisterType(): Invalid QML type name \"%s\"", data.typeName);
685  return 0;
686  }
687  }
688  } else {
689  qWarning("qmlRegisterType(): No QML type name for \"%s\"", data.url.toString().toLatin1().constData());
690  return 0;
691  }
692 
693  QWriteLocker lock(registeredComponentDataLock());
694  QString path;
695  // Relative paths are relative to application working directory
696  if (data.url.isRelative() || data.url.scheme() == QLatin1String("file")) // Workaround QTBUG-11929
697  path = QUrl::fromLocalFile(QDir::currentPath()+QLatin1String("/")).resolved(data.url).toString();
698  else
699  path = data.url.toString();
700  QDeclarativeRegisteredComponentData *d = registeredComponentData();
703  path,
704  data.majorVersion,
705  data.minorVersion
706  );
707 
708  QDeclarativeDirComponents* comps = d->registeredComponents.value(QByteArray(data.uri), 0);
709  if (!comps)
710  d->registeredComponents.insert(QByteArray(data.uri), comps = new QDeclarativeDirComponents);
711 
712  // Types added later should take precedence, like registerType
713  comps->prepend(comp);
714 
715  return 1;
716 }
double d
Definition: qnumeric_p.h:62
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString currentPath()
Returns the absolute path of the application&#39;s current directory.
Definition: qdir.cpp:1875
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition: qurl.cpp:5880
QMap< QByteArray, QDeclarativeDirComponents * > registeredComponents
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
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
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
static QReadWriteLock lock
Definition: proxyconf.cpp:399
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374

◆ registerInterface()

int registerInterface ( const QDeclarativePrivate::RegisterInterface interface)

Definition at line 599 of file qdeclarativemetatype.cpp.

Referenced by QAccessibleHierarchyManager::registerInterface(), QAccessible::updateAccessibility(), and QAccessibleHierarchyManager::~QAccessibleHierarchyManager().

600 {
601  if (interface.version > 0)
602  qFatal("qmlRegisterType(): Cannot mix incompatible QML versions.");
603 
604  QWriteLocker lock(metaTypeDataLock());
605  QDeclarativeMetaTypeData *data = metaTypeData();
606 
607  int index = data->types.count();
608 
609  QDeclarativeType *type = new QDeclarativeType(index, interface);
610 
611  data->types.append(type);
612  data->idToType.insert(type->typeId(), type);
613  data->idToType.insert(type->qListTypeId(), type);
614  // XXX No insertMulti, so no multi-version interfaces?
615  if (!type->qmlTypeName().isEmpty())
616  data->nameToType.insert(type->qmlTypeName(), type);
617 
618  if (data->interfaces.size() <= interface.typeId)
619  data->interfaces.resize(interface.typeId + 16);
620  if (data->lists.size() <= interface.listId)
621  data->lists.resize(interface.listId + 16);
622  data->interfaces.setBit(interface.typeId, true);
623  data->lists.setBit(interface.listId, true);
624 
625  return index;
626 }
int type
Definition: qmetatype.cpp:239
void setBit(int i)
Sets the bit at index position i to 1.
Definition: qbitarray.h:128
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QDeclarativeType * > types
void resize(int size)
Resizes the bit array to size bits.
Definition: qbitarray.cpp:214
static const char * data(const QByteArray &arr)
QByteArray qmlTypeName() const
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
Q_CORE_EXPORT void qFatal(const char *,...)
static QReadWriteLock lock
Definition: proxyconf.cpp:399
quint16 index
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
int size() const
Returns the number of bits stored in the bit array.
Definition: qbitarray.h:73

◆ registerType()

int registerType ( const QDeclarativePrivate::RegisterType type)

Definition at line 628 of file qdeclarativemetatype.cpp.

629 {
630  if (type.elementName) {
631  for (int ii = 0; type.elementName[ii]; ++ii) {
632  if (!isalnum(type.elementName[ii])) {
633  qWarning("qmlRegisterType(): Invalid QML element name \"%s\"", type.elementName);
634  return -1;
635  }
636  }
637  }
638 
639  QWriteLocker lock(metaTypeDataLock());
640  QDeclarativeMetaTypeData *data = metaTypeData();
641  int index = data->types.count();
642 
643  QDeclarativeType *dtype = new QDeclarativeType(index, type);
644 
645  data->types.append(dtype);
646  data->idToType.insert(dtype->typeId(), dtype);
647  if (dtype->qListTypeId()) data->idToType.insert(dtype->qListTypeId(), dtype);
648 
649  if (!dtype->qmlTypeName().isEmpty())
650  data->nameToType.insertMulti(dtype->qmlTypeName(), dtype);
651 
652  data->metaObjectToType.insertMulti(dtype->baseMetaObject(), dtype);
653 
654  if (data->objects.size() <= type.typeId)
655  data->objects.resize(type.typeId + 16);
656  if (data->lists.size() <= type.listId)
657  data->lists.resize(type.listId + 16);
658  data->objects.setBit(type.typeId, true);
659  if (type.listId) data->lists.setBit(type.listId, true);
660 
661  if (type.uri) {
662  QByteArray mod(type.uri);
664  if (it == data->modules.end()) {
665  // New module
667  } else if ((*it).vmajor_max < type.versionMajor || ((*it).vmajor_max == type.versionMajor && (*it).vminor_max < type.versionMinor)) {
668  // Newer module
669  data->modules.insert(mod, QDeclarativeMetaTypeData::ModuleInfo((*it).vmajor_min, (*it).vminor_min, type.versionMajor, type.versionMinor));
670  } else if ((*it).vmajor_min > type.versionMajor || ((*it).vmajor_min == type.versionMajor && (*it).vminor_min > type.versionMinor)) {
671  // Older module
672  data->modules.insert(mod, QDeclarativeMetaTypeData::ModuleInfo(type.versionMajor, type.versionMinor, (*it).vmajor_min, (*it).vminor_min));
673  }
674  }
675 
676  return index;
677 }
void setBit(int i)
Sets the bit at index position i to 1.
Definition: qbitarray.h:128
#define it(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const QMetaObject * baseMetaObject() const
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QDeclarativeType * > types
void resize(int size)
Resizes the bit array to size bits.
Definition: qbitarray.cpp:214
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
QByteArray qmlTypeName() const
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
static QReadWriteLock lock
Definition: proxyconf.cpp:399
quint16 index
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:772
int size() const
Returns the number of bits stored in the bit array.
Definition: qbitarray.h:73
iterator Iterator
Qt-style synonym for QHash::iterator.
Definition: qhash.h:473