Qt 4.8
qmetaobjectbuilder.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "private/qmetaobjectbuilder_p.h"
43 
45 
78 // copied from moc's generator.cpp
80 {
81  if (!name)
82  return 0;
83 
84  if (strcmp(name, "QVariant") == 0)
85  return 0xffffffff;
86  if (strcmp(name, "QCString") == 0)
87  return QMetaType::QByteArray;
88  if (strcmp(name, "Q_LLONG") == 0)
89  return QMetaType::LongLong;
90  if (strcmp(name, "Q_ULLONG") == 0)
91  return QMetaType::ULongLong;
92  if (strcmp(name, "QIconSet") == 0)
93  return QMetaType::QIcon;
94 
95  uint tp = QMetaType::type(name);
96  return tp < QMetaType::User ? tp : 0;
97 }
98 
99 /*
100  Returns true if the type is a QVariant types.
101 */
102 bool isVariantType(const char* type)
103 {
104  return qvariant_nameToType(type) != 0;
105 }
106 
107 // copied from qmetaobject_p.h
108 // do not touch without touching the moc as well
110  Invalid = 0x00000000,
111  Readable = 0x00000001,
112  Writable = 0x00000002,
113  Resettable = 0x00000004,
114  EnumOrFlag = 0x00000008,
115  StdCppSet = 0x00000100,
116 // Override = 0x00000200,
117  Constant = 0x00000400,
118  Final = 0x00000800,
119  Designable = 0x00001000,
120  ResolveDesignable = 0x00002000,
121  Scriptable = 0x00004000,
122  ResolveScriptable = 0x00008000,
123  Stored = 0x00010000,
124  ResolveStored = 0x00020000,
125  Editable = 0x00040000,
126  ResolveEditable = 0x00080000,
127  User = 0x00100000,
128  ResolveUser = 0x00200000,
129  Notify = 0x00400000,
130  Revisioned = 0x00800000
131 };
132 
136  AccessPublic = 0x02,
137  AccessMask = 0x03, //mask
138 
139  MethodMethod = 0x00,
140  MethodSignal = 0x04,
141  MethodSlot = 0x08,
144 
146  MethodCloned = 0x20,
149 };
150 
151 struct QMetaObjectPrivate
152 {
153  int revision;
154  int className;
156  int methodCount, methodData;
160  int flags;
161 };
162 
163 static inline const QMetaObjectPrivate *priv(const uint* data)
164 { return reinterpret_cast<const QMetaObjectPrivate*>(data); }
165 // end of copied lines from qmetaobject.cpp
166 
168 {
169 public:
172  const QByteArray& _signature,
173  const QByteArray& _returnType = QByteArray(),
175  : signature(QMetaObject::normalizedSignature(_signature.constData())),
176  returnType(QMetaObject::normalizedType(_returnType)),
177  attributes(((int)_access) | (((int)_methodType) << 2))
178  {
179  }
180 
186 
188  {
189  return (QMetaMethod::MethodType)((attributes & MethodTypeMask) >> 2);
190  }
191 
193  {
194  return (QMetaMethod::Access)(attributes & AccessMask);
195  }
196 
198  {
199  attributes = ((attributes & ~AccessMask) | (int)value);
200  }
201 };
202 
204 {
205 public:
207  (const QByteArray& _name, const QByteArray& _type, int notifierIdx=-1)
208  : name(_name),
210  flags(Readable | Writable | Scriptable), notifySignal(-1)
211  {
212  if (notifierIdx >= 0) {
213  flags |= Notify;
214  notifySignal = notifierIdx;
215  }
216  }
217 
220  int flags;
222 
223  bool flag(int f) const
224  {
225  return ((flags & f) != 0);
226  }
227 
228  void setFlag(int f, bool value)
229  {
230  if (value)
231  flags |= f;
232  else
233  flags &= ~f;
234  }
235 };
236 
238 {
239 public:
241  : name(_name), isFlag(false)
242  {
243  }
244 
246  bool isFlag;
249 };
250 
252 {
253 public:
255  : flags(0)
256  {
257  superClass = &QObject::staticMetaObject;
258  staticMetacallFunction = 0;
259  }
260 
270 #ifdef Q_NO_DATA_RELOCATION
271  QList<QMetaObjectAccessor> relatedMetaObjects;
272 #else
274 #endif
275  int flags;
276 };
277 
282 {
284 }
285 
298  (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members)
299 {
301  addMetaObject(prototype, members);
302 }
303 
308 {
309  delete d;
310 }
311 
319 {
320  return d->className;
321 }
322 
330 {
331  d->className = name;
332 }
333 
342 {
343  return d->superClass;
344 }
345 
354 {
355  Q_ASSERT(meta);
356  d->superClass = meta;
357 }
358 
366 {
367  return (QMetaObjectBuilder::MetaObjectFlags)d->flags;
368 }
369 
377 {
378  d->flags = flags;
379 }
380 
389 {
390  return d->methods.size();
391 }
392 
399 {
400  return d->constructors.size();
401 }
402 
410 {
411  return d->properties.size();
412 }
413 
422 {
423  return d->enumerators.size();
424 }
425 
434 {
435  return d->classInfoNames.size();
436 }
437 
450 {
451  return d->relatedMetaObjects.size();
452 }
453 
463 {
464  int index = d->methods.size();
465  d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Method, signature));
466  return QMetaMethodBuilder(this, index);
467 }
468 
480  (const QByteArray& signature, const QByteArray& returnType)
481 {
482  int index = d->methods.size();
483  d->methods.append(QMetaMethodBuilderPrivate
484  (QMetaMethod::Method, signature, returnType));
485  return QMetaMethodBuilder(this, index);
486 }
487 
500 {
501  QMetaMethodBuilder method;
502  if (prototype.methodType() == QMetaMethod::Method)
503  method = addMethod(prototype.signature());
504  else if (prototype.methodType() == QMetaMethod::Signal)
505  method = addSignal(prototype.signature());
506  else if (prototype.methodType() == QMetaMethod::Slot)
507  method = addSlot(prototype.signature());
508  else if (prototype.methodType() == QMetaMethod::Constructor)
509  method = addConstructor(prototype.signature());
510  method.setReturnType(prototype.typeName());
511  method.setParameterNames(prototype.parameterNames());
512  method.setTag(prototype.tag());
513  method.setAccess(prototype.access());
514  method.setAttributes(prototype.attributes());
515  return method;
516 }
517 
527 {
528  int index = d->methods.size();
529  d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Slot, signature));
530  return QMetaMethodBuilder(this, index);
531 }
532 
542 {
543  int index = d->methods.size();
544  d->methods.append(QMetaMethodBuilderPrivate
546  return QMetaMethodBuilder(this, index);
547 }
548 
559 {
560  int index = d->constructors.size();
561  d->constructors.append(QMetaMethodBuilderPrivate(QMetaMethod::Constructor, signature));
562  return QMetaMethodBuilder(this, -(index + 1));
563 }
564 
577 {
579  QMetaMethodBuilder ctor = addConstructor(prototype.signature());
580  ctor.setReturnType(prototype.typeName());
581  ctor.setParameterNames(prototype.parameterNames());
582  ctor.setTag(prototype.tag());
583  ctor.setAccess(prototype.access());
584  ctor.setAttributes(prototype.attributes());
585  return ctor;
586 }
587 
598  (const QByteArray& name, const QByteArray& type, int notifierId)
599 {
600  int index = d->properties.size();
601  d->properties.append(QMetaPropertyBuilderPrivate(name, type, notifierId));
602  return QMetaPropertyBuilder(this, index);
603 }
604 
614 {
615  QMetaPropertyBuilder property = addProperty(prototype.name(), prototype.typeName());
616  property.setReadable(prototype.isReadable());
617  property.setWritable(prototype.isWritable());
618  property.setResettable(prototype.isResettable());
619  property.setDesignable(prototype.isDesignable());
620  property.setScriptable(prototype.isScriptable());
621  property.setStored(prototype.isStored());
622  property.setEditable(prototype.isEditable());
623  property.setUser(prototype.isUser());
624  property.setStdCppSet(prototype.hasStdCppSet());
625  property.setEnumOrFlag(prototype.isEnumType());
626  property.setConstant(prototype.isConstant());
627  property.setFinal(prototype.isFinal());
628  if (prototype.hasNotifySignal()) {
629  // Find an existing method for the notify signal, or add a new one.
630  QMetaMethod method = prototype.notifySignal();
631  int index = indexOfMethod(method.signature());
632  if (index == -1)
633  index = addMethod(method).index();
634  d->properties[property._index].notifySignal = index;
635  d->properties[property._index].setFlag(Notify, true);
636  }
637  return property;
638 }
639 
649 {
650  int index = d->enumerators.size();
651  d->enumerators.append(QMetaEnumBuilderPrivate(name));
652  return QMetaEnumBuilder(this, index);
653 }
654 
665 {
666  QMetaEnumBuilder en = addEnumerator(prototype.name());
667  en.setIsFlag(prototype.isFlag());
668  int count = prototype.keyCount();
669  for (int index = 0; index < count; ++index)
670  en.addKey(prototype.key(index), prototype.value(index));
671  return en;
672 }
673 
682 {
683  int index = d->classInfoNames.size();
684  d->classInfoNames += name;
685  d->classInfoValues += value;
686  return index;
687 }
688 
700 #ifdef Q_NO_DATA_RELOCATION
702 #else
704 #endif
705 {
706  Q_ASSERT(meta);
707  int index = d->relatedMetaObjects.size();
708  d->relatedMetaObjects.append(meta);
709  return index;
710 }
711 
720  (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members)
721 {
722  Q_ASSERT(prototype);
723  int index;
724 
725  if ((members & ClassName) != 0)
726  d->className = prototype->className();
727 
728  if ((members & SuperClass) != 0)
729  d->superClass = prototype->superClass();
730 
731  if ((members & (Methods | Signals | Slots)) != 0) {
732  for (index = prototype->methodOffset(); index < prototype->methodCount(); ++index) {
733  QMetaMethod method = prototype->method(index);
734  if (method.methodType() != QMetaMethod::Signal) {
735  if (method.access() == QMetaMethod::Public && (members & PublicMethods) == 0)
736  continue;
737  if (method.access() == QMetaMethod::Private && (members & PrivateMethods) == 0)
738  continue;
739  if (method.access() == QMetaMethod::Protected && (members & ProtectedMethods) == 0)
740  continue;
741  }
742  if (method.methodType() == QMetaMethod::Method && (members & Methods) != 0) {
743  addMethod(method);
744  } else if (method.methodType() == QMetaMethod::Signal &&
745  (members & Signals) != 0) {
746  addMethod(method);
747  } else if (method.methodType() == QMetaMethod::Slot &&
748  (members & Slots) != 0) {
749  addMethod(method);
750  }
751  }
752  }
753 
754  if ((members & Constructors) != 0) {
755  for (index = 0; index < prototype->constructorCount(); ++index)
756  addConstructor(prototype->constructor(index));
757  }
758 
759  if ((members & Properties) != 0) {
760  for (index = prototype->propertyOffset(); index < prototype->propertyCount(); ++index)
761  addProperty(prototype->property(index));
762  }
763 
764  if ((members & Enumerators) != 0) {
765  for (index = prototype->enumeratorOffset(); index < prototype->enumeratorCount(); ++index)
766  addEnumerator(prototype->enumerator(index));
767  }
768 
769  if ((members & ClassInfos) != 0) {
770  for (index = prototype->classInfoOffset(); index < prototype->classInfoCount(); ++index) {
771  QMetaClassInfo ci = prototype->classInfo(index);
772  addClassInfo(ci.name(), ci.value());
773  }
774  }
775 
776  if ((members & RelatedMetaObjects) != 0) {
777 #ifdef Q_NO_DATA_RELOCATION
778  const QMetaObjectAccessor *objects = 0;
779 #else
780  const QMetaObject **objects;
781  if (priv(prototype->d.data)->revision < 2) {
782  objects = (const QMetaObject **)(prototype->d.extradata);
783  } else
784 #endif
785  {
786  const QMetaObjectExtraData *extra = (const QMetaObjectExtraData *)(prototype->d.extradata);
787  if (extra)
788  objects = extra->objects;
789  else
790  objects = 0;
791  }
792  if (objects) {
793  while (*objects != 0) {
794  addRelatedMetaObject(*objects);
795  ++objects;
796  }
797  }
798  }
799 
800  if ((members & StaticMetacall) != 0) {
801  if (priv(prototype->d.data)->revision >= 6) {
802  const QMetaObjectExtraData *extra =
803  (const QMetaObjectExtraData *)(prototype->d.extradata);
804  if (extra && extra->static_metacall)
805  setStaticMetacallFunction(extra->static_metacall);
806  }
807  }
808 }
809 
816 {
817  if (index >= 0 && index < d->methods.size())
818  return QMetaMethodBuilder(this, index);
819  else
820  return QMetaMethodBuilder();
821 }
822 
829 {
830  if (index >= 0 && index < d->constructors.size())
831  return QMetaMethodBuilder(this, -(index + 1));
832  else
833  return QMetaMethodBuilder();
834 }
835 
842 {
843  if (index >= 0 && index < d->properties.size())
844  return QMetaPropertyBuilder(this, index);
845  else
846  return QMetaPropertyBuilder();
847 }
848 
856 {
857  if (index >= 0 && index < d->enumerators.size())
858  return QMetaEnumBuilder(this, index);
859  else
860  return QMetaEnumBuilder();
861 }
862 
874 {
875  if (index >= 0 && index < d->relatedMetaObjects.size())
876 #ifdef Q_NO_DATA_RELOCATION
877  return &((*(d->relatedMetaObjects[index]))());
878 #else
879  return d->relatedMetaObjects[index];
880 #endif
881  else
882  return 0;
883 }
884 
893 {
894  if (index >= 0 && index < d->classInfoNames.size())
895  return d->classInfoNames[index];
896  else
897  return QByteArray();
898 }
899 
908 {
909  if (index >= 0 && index < d->classInfoValues.size())
910  return d->classInfoValues[index];
911  else
912  return QByteArray();
913 }
914 
924 {
925  if (index >= 0 && index < d->methods.size()) {
926  d->methods.removeAt(index);
927  for (int prop = 0; prop < d->properties.size(); ++prop) {
928  // Adjust the indices of property notify signal references.
929  if (d->properties[prop].notifySignal == index) {
930  d->properties[prop].notifySignal = -1;
931  d->properties[prop].setFlag(Notify, false);
932  } else if (d->properties[prop].notifySignal > index)
933  (d->properties[prop].notifySignal)--;
934  }
935  }
936 }
937 
946 {
947  if (index >= 0 && index < d->constructors.size())
948  d->constructors.removeAt(index);
949 }
950 
958 {
959  if (index >= 0 && index < d->properties.size())
960  d->properties.removeAt(index);
961 }
962 
971 {
972  if (index >= 0 && index < d->enumerators.size())
973  d->enumerators.removeAt(index);
974 }
975 
984 {
985  if (index >= 0 && index < d->classInfoNames.size()) {
986  d->classInfoNames.removeAt(index);
987  d->classInfoValues.removeAt(index);
988  }
989 }
990 
1004 {
1005  if (index >= 0 && index < d->relatedMetaObjects.size())
1006  d->relatedMetaObjects.removeAt(index);
1007 }
1008 
1016 {
1018  for (int index = 0; index < d->methods.size(); ++index) {
1019  if (sig == d->methods[index].signature)
1020  return index;
1021  }
1022  return -1;
1023 }
1024 
1032 {
1034  for (int index = 0; index < d->methods.size(); ++index) {
1035  if (sig == d->methods[index].signature &&
1036  d->methods[index].methodType() == QMetaMethod::Signal)
1037  return index;
1038  }
1039  return -1;
1040 }
1041 
1049 {
1051  for (int index = 0; index < d->methods.size(); ++index) {
1052  if (sig == d->methods[index].signature &&
1053  d->methods[index].methodType() == QMetaMethod::Slot)
1054  return index;
1055  }
1056  return -1;
1057 }
1058 
1066 {
1068  for (int index = 0; index < d->constructors.size(); ++index) {
1069  if (sig == d->constructors[index].signature)
1070  return index;
1071  }
1072  return -1;
1073 }
1074 
1082 {
1083  for (int index = 0; index < d->properties.size(); ++index) {
1084  if (name == d->properties[index].name)
1085  return index;
1086  }
1087  return -1;
1088 }
1089 
1097 {
1098  for (int index = 0; index < d->enumerators.size(); ++index) {
1099  if (name == d->enumerators[index].name)
1100  return index;
1101  }
1102  return -1;
1103 }
1104 
1113 {
1114  for (int index = 0; index < d->classInfoNames.size(); ++index) {
1115  if (name == d->classInfoNames[index])
1116  return index;
1117  }
1118  return -1;
1119 }
1120 
1121 // Align on a specific type boundary.
1122 #define ALIGN(size,type) \
1123  (size) = ((size) + sizeof(type) - 1) & ~(sizeof(type) - 1)
1124 
1125 // Build a string into a QMetaObject representation. Returns the
1126 // position in the string table where the string was placed.
1127 static int buildString
1128  (char *buf, char *str, int *offset, const QByteArray& value, int empty)
1129 {
1130  if (value.size() == 0 && empty >= 0)
1131  return empty;
1132  if (buf) {
1133  memcpy(str + *offset, value.constData(), value.size());
1134  str[*offset + value.size()] = '\0';
1135  }
1136  int posn = *offset;
1137  *offset += value.size() + 1;
1138  return posn;
1139 }
1140 
1141 // Build the parameter array string for a method.
1143  (const QByteArray& signature, const QList<QByteArray>& parameterNames)
1144 {
1145  // If the parameter name list is specified, then concatenate them.
1146  if (!parameterNames.isEmpty()) {
1147  QByteArray names;
1148  bool first = true;
1149  foreach (const QByteArray &name, parameterNames) {
1150  if (first)
1151  first = false;
1152  else
1153  names += (char)',';
1154  names += name;
1155  }
1156  return names;
1157  }
1158 
1159  // Count commas in the signature, excluding those inside template arguments.
1160  int index = signature.indexOf('(');
1161  if (index < 0)
1162  return QByteArray();
1163  ++index;
1164  if (index >= signature.size())
1165  return QByteArray();
1166  if (signature[index] == ')')
1167  return QByteArray();
1168  int count = 1;
1169  int brackets = 0;
1170  while (index < signature.size() && signature[index] != ',') {
1171  char ch = signature[index++];
1172  if (ch == '<')
1173  ++brackets;
1174  else if (ch == '>')
1175  --brackets;
1176  else if (ch == ',' && brackets <= 0)
1177  ++count;
1178  }
1179  return QByteArray(count - 1, ',');
1180 }
1181 
1182 // Build a QMetaObject in "buf" based on the information in "d".
1183 // If "buf" is null, then return the number of bytes needed to
1184 // build the QMetaObject. Returns -1 if the metaobject if
1185 // relocatable is set, but the metaobject contains extradata.
1187  bool relocatable)
1188 {
1189  int size = 0;
1190  int dataIndex;
1191  int enumIndex;
1192  int index;
1193  bool hasNotifySignals = false;
1194 
1195  if (relocatable &&
1197  return -1;
1198 
1199  // Create the main QMetaObject structure at the start of the buffer.
1200  QMetaObject *meta = reinterpret_cast<QMetaObject *>(buf);
1201  size += sizeof(QMetaObject);
1202  ALIGN(size, int);
1203  if (buf) {
1204  if (!relocatable) meta->d.superdata = d->superClass;
1205  meta->d.extradata = 0;
1206  }
1207 
1208  // Populate the QMetaObjectPrivate structure.
1209  QMetaObjectPrivate *pmeta
1210  = reinterpret_cast<QMetaObjectPrivate *>(buf + size);
1211  int pmetaSize = size;
1212  dataIndex = 13; // Number of fields in the QMetaObjectPrivate.
1213  for (index = 0; index < d->properties.size(); ++index) {
1214  if (d->properties[index].notifySignal != -1) {
1215  hasNotifySignals = true;
1216  break;
1217  }
1218  }
1219  if (buf) {
1220  pmeta->revision = 3;
1221  pmeta->flags = d->flags;
1222  pmeta->className = 0; // Class name is always the first string.
1223 
1224  pmeta->classInfoCount = d->classInfoNames.size();
1225  pmeta->classInfoData = dataIndex;
1226  dataIndex += 2 * d->classInfoNames.size();
1227 
1228  pmeta->methodCount = d->methods.size();
1229  pmeta->methodData = dataIndex;
1230  dataIndex += 5 * d->methods.size();
1231 
1232  pmeta->propertyCount = d->properties.size();
1233  pmeta->propertyData = dataIndex;
1234  dataIndex += 3 * d->properties.size();
1235  if (hasNotifySignals)
1236  dataIndex += d->properties.size();
1237 
1238  pmeta->enumeratorCount = d->enumerators.size();
1239  pmeta->enumeratorData = dataIndex;
1240  dataIndex += 4 * d->enumerators.size();
1241 
1242  pmeta->constructorCount = d->constructors.size();
1243  pmeta->constructorData = dataIndex;
1244  dataIndex += 5 * d->constructors.size();
1245  } else {
1246  dataIndex += 2 * d->classInfoNames.size();
1247  dataIndex += 5 * d->methods.size();
1248  dataIndex += 3 * d->properties.size();
1249  if (hasNotifySignals)
1250  dataIndex += d->properties.size();
1251  dataIndex += 4 * d->enumerators.size();
1252  dataIndex += 5 * d->constructors.size();
1253  }
1254 
1255  // Allocate space for the enumerator key names and values.
1256  enumIndex = dataIndex;
1257  for (index = 0; index < d->enumerators.size(); ++index) {
1258  QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1259  dataIndex += 2 * enumerator->keys.size();
1260  }
1261 
1262  // Zero terminator at the end of the data offset table.
1263  ++dataIndex;
1264 
1265  // Find the start of the data and string tables.
1266  int *data = reinterpret_cast<int *>(pmeta);
1267  size += dataIndex * sizeof(int);
1268  char *str = reinterpret_cast<char *>(buf + size);
1269  if (buf) {
1270  if (relocatable) {
1271  meta->d.stringdata = reinterpret_cast<const char *>((quintptr)size);
1272  meta->d.data = reinterpret_cast<uint *>((quintptr)pmetaSize);
1273  } else {
1274  meta->d.stringdata = str;
1275  meta->d.data = reinterpret_cast<uint *>(data);
1276  }
1277  }
1278 
1279  // Reset the current data position to just past the QMetaObjectPrivate.
1280  dataIndex = 13;
1281 
1282  // Add the class name to the string table.
1283  int offset = 0;
1284  buildString(buf, str, &offset, d->className, -1);
1285 
1286  // Add a common empty string, which is used to indicate "void"
1287  // method returns, empty tag strings, etc.
1288  int empty = buildString(buf, str, &offset, QByteArray(), -1);
1289 
1290  // Output the class infos,
1291  for (index = 0; index < d->classInfoNames.size(); ++index) {
1292  int name = buildString(buf, str, &offset, d->classInfoNames[index], empty);
1293  int value = buildString(buf, str, &offset, d->classInfoValues[index], empty);
1294  if (buf) {
1295  data[dataIndex] = name;
1296  data[dataIndex + 1] = value;
1297  }
1298  dataIndex += 2;
1299  }
1300 
1301  // Output the methods in the class.
1302  for (index = 0; index < d->methods.size(); ++index) {
1303  QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1304  int sig = buildString(buf, str, &offset, method->signature, empty);
1305  int params;
1307  (method->signature, method->parameterNames);
1308  params = buildString(buf, str, &offset, names, empty);
1309  int ret = buildString(buf, str, &offset, method->returnType, empty);
1310  int tag = buildString(buf, str, &offset, method->tag, empty);
1311  int attrs = method->attributes;
1312  if (buf) {
1313  data[dataIndex] = sig;
1314  data[dataIndex + 1] = params;
1315  data[dataIndex + 2] = ret;
1316  data[dataIndex + 3] = tag;
1317  data[dataIndex + 4] = attrs;
1318  }
1319  dataIndex += 5;
1320  }
1321 
1322  // Output the properties in the class.
1323  for (index = 0; index < d->properties.size(); ++index) {
1325  int name = buildString(buf, str, &offset, prop->name, empty);
1326  int type = buildString(buf, str, &offset, prop->type, empty);
1327  int flags = prop->flags;
1328 
1329  if (!isVariantType(prop->type)) {
1330  flags |= EnumOrFlag;
1331  } else {
1332  flags |= qvariant_nameToType(prop->type) << 24;
1333  }
1334 
1335  if (buf) {
1336  data[dataIndex] = name;
1337  data[dataIndex + 1] = type;
1338  data[dataIndex + 2] = flags;
1339  }
1340  dataIndex += 3;
1341  }
1342  if (hasNotifySignals) {
1343  for (index = 0; index < d->properties.size(); ++index) {
1345  if (buf) {
1346  if (prop->notifySignal != -1)
1347  data[dataIndex] = prop->notifySignal;
1348  else
1349  data[dataIndex] = 0;
1350  }
1351  ++dataIndex;
1352  }
1353  }
1354 
1355  // Output the enumerators in the class.
1356  for (index = 0; index < d->enumerators.size(); ++index) {
1357  QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1358  int name = buildString(buf, str, &offset, enumerator->name, empty);
1359  int isFlag = (int)(enumerator->isFlag);
1360  int count = enumerator->keys.size();
1361  int enumOffset = enumIndex;
1362  if (buf) {
1363  data[dataIndex] = name;
1364  data[dataIndex + 1] = isFlag;
1365  data[dataIndex + 2] = count;
1366  data[dataIndex + 3] = enumOffset;
1367  }
1368  for (int key = 0; key < count; ++key) {
1369  int keyIndex = buildString(buf, str, &offset, enumerator->keys[key], empty);
1370  if (buf) {
1371  data[enumOffset++] = keyIndex;
1372  data[enumOffset++] = enumerator->values[key];
1373  }
1374  }
1375  dataIndex += 4;
1376  enumIndex += 2 * count;
1377  }
1378 
1379  // Output the constructors in the class.
1380  for (index = 0; index < d->constructors.size(); ++index) {
1381  QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1382  int sig = buildString(buf, str, &offset, method->signature, empty);
1383  int params;
1385  (method->signature, method->parameterNames);
1386  params = buildString(buf, str, &offset, names, empty);
1387  int ret = buildString(buf, str, &offset, method->returnType, empty);
1388  int tag = buildString(buf, str, &offset, method->tag, empty);
1389  int attrs = method->attributes;
1390  if (buf) {
1391  data[dataIndex] = sig;
1392  data[dataIndex + 1] = params;
1393  data[dataIndex + 2] = ret;
1394  data[dataIndex + 3] = tag;
1395  data[dataIndex + 4] = attrs;
1396  }
1397  dataIndex += 5;
1398  }
1399 
1400  // One more empty string to act as a terminator.
1401  buildString(buf, str, &offset, QByteArray(), -1);
1402  size += offset;
1403 
1404  // Output the zero terminator in the data array.
1405  if (buf)
1406  data[enumIndex] = 0;
1407 
1408  // Create the extradata block if we need one.
1409  if (d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction) {
1410  ALIGN(size, QMetaObject **);
1412  QMetaObjectExtraData *extra =
1413  reinterpret_cast<QMetaObjectExtraData *>(buf + size);
1414  size += sizeof(QMetaObjectExtraData);
1415  ALIGN(size, QMetaObject *);
1416 #ifdef Q_NO_DATA_RELOCATION
1417  QMetaObjectAccessor *objects =
1418  reinterpret_cast<QMetaObjectAccessor *>(buf + size);
1419 #else
1420  const QMetaObject **objects =
1421  reinterpret_cast<const QMetaObject **>(buf + size);
1422 #endif
1423  if (buf) {
1424  if (d->relatedMetaObjects.size() > 0) {
1425  extra->objects = objects;
1426  for (index = 0; index < d->relatedMetaObjects.size(); ++index)
1427  objects[index] = d->relatedMetaObjects[index];
1428  objects[index] = 0;
1429  } else {
1430  extra->objects = 0;
1431  }
1433  meta->d.extradata = reinterpret_cast<void *>(extra);
1434  }
1435  if (d->relatedMetaObjects.size() > 0)
1436  size += sizeof(QMetaObject *) * (d->relatedMetaObjects.size() + 1);
1437  }
1438 
1439  // Align the final size and return it.
1440  ALIGN(size, void *);
1441  return size;
1442 }
1443 
1455 {
1456  int size = buildMetaObject(d, 0, false);
1457  char *buf = reinterpret_cast<char *>(qMalloc(size));
1458  memset(buf, 0, size);
1459  buildMetaObject(d, buf, false);
1460  return reinterpret_cast<QMetaObject *>(buf);
1461 }
1462 
1463 /*
1464  \internal
1465 
1466  Converts this meta object builder into relocatable data. This data can
1467  be stored, copied and later passed to fromRelocatableData() to create a
1468  concrete QMetaObject.
1469 
1470  The data is specific to the architecture on which it was created, but is not
1471  specific to the process that created it. Not all meta object builder's can
1472  be converted to data in this way. If \a ok is provided, it will be set to
1473  true if the conversion succeeds, and false otherwise. If a
1474  staticMetacallFunction() or any relatedMetaObject()'s are specified the
1475  conversion to relocatable data will fail.
1476 */
1478 {
1479  int size = buildMetaObject(d, 0, true);
1480  if (size == -1) {
1481  if (ok) *ok = false;
1482  return QByteArray();
1483  }
1484 
1485  QByteArray data;
1486  data.resize(size);
1487  char *buf = data.data();
1488  memset(buf, 0, size);
1489  buildMetaObject(d, buf, true);
1490  if (ok) *ok = true;
1491  return data;
1492 }
1493 
1494 /*
1495  \internal
1496 
1497  Sets the \a data returned from toRelocatableData() onto a concrete
1498  QMetaObject instance, \a output. As the meta object's super class is not
1499  saved in the relocatable data, it must be passed as \a superClass.
1500 */
1502  const QMetaObject *superclass,
1503  const QByteArray &data)
1504 {
1505  if (!output)
1506  return;
1507 
1508  const char *buf = data.constData();
1509  const QMetaObject *dataMo = reinterpret_cast<const QMetaObject *>(buf);
1510 
1511  quintptr stringdataOffset = (quintptr)dataMo->d.stringdata;
1512  quintptr dataOffset = (quintptr)dataMo->d.data;
1513 
1514  output->d.superdata = superclass;
1515  output->d.stringdata = buf + stringdataOffset;
1516  output->d.data = reinterpret_cast<const uint *>(buf + dataOffset);
1517 }
1518 
1537 {
1538  return d->staticMetacallFunction;
1539 }
1540 
1549 {
1550  d->staticMetacallFunction = value;
1551 }
1552 
1553 #ifndef QT_NO_DATASTREAM
1554 
1561 {
1562  int index;
1563 
1564  // Write the class and super class names.
1565  stream << d->className;
1566  if (d->superClass)
1567  stream << QByteArray(d->superClass->className());
1568  else
1569  stream << QByteArray();
1570 
1571  // Write the counts for each type of class member.
1572  stream << d->classInfoNames.size();
1573  stream << d->methods.size();
1574  stream << d->properties.size();
1575  stream << d->enumerators.size();
1576  stream << d->constructors.size();
1577  stream << d->relatedMetaObjects.size();
1578 
1579  // Write the items of class information.
1580  for (index = 0; index < d->classInfoNames.size(); ++index) {
1581  stream << d->classInfoNames[index];
1582  stream << d->classInfoValues[index];
1583  }
1584 
1585  // Write the methods.
1586  for (index = 0; index < d->methods.size(); ++index) {
1587  const QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1588  stream << method->signature;
1589  stream << method->returnType;
1590  stream << method->parameterNames;
1591  stream << method->tag;
1592  stream << method->attributes;
1593  }
1594 
1595  // Write the properties.
1596  for (index = 0; index < d->properties.size(); ++index) {
1597  const QMetaPropertyBuilderPrivate *property = &(d->properties[index]);
1598  stream << property->name;
1599  stream << property->type;
1600  stream << property->flags;
1601  stream << property->notifySignal;
1602  }
1603 
1604  // Write the enumerators.
1605  for (index = 0; index < d->enumerators.size(); ++index) {
1606  const QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1607  stream << enumerator->name;
1608  stream << enumerator->isFlag;
1609  stream << enumerator->keys;
1610  stream << enumerator->values;
1611  }
1612 
1613  // Write the constructors.
1614  for (index = 0; index < d->constructors.size(); ++index) {
1615  const QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1616  stream << method->signature;
1617  stream << method->returnType;
1618  stream << method->parameterNames;
1619  stream << method->tag;
1620  stream << method->attributes;
1621  }
1622 
1623  // Write the related meta objects.
1624 #ifdef Q_NO_DATA_RELOCATION
1625  //### What do we do here?
1626 #else
1627  for (index = 0; index < d->relatedMetaObjects.size(); ++index) {
1628  const QMetaObject *meta = d->relatedMetaObjects[index];
1629  stream << QByteArray(meta->className());
1630  }
1631 #endif
1632 
1633  // Add an extra empty QByteArray for additional data in future versions.
1634  // This should help maintain backwards compatibility, allowing older
1635  // versions to read newer data.
1636  stream << QByteArray();
1637 }
1638 
1639 // Resolve a class name using the name reference map.
1640 static const QMetaObject *resolveClassName
1642  const QByteArray& name)
1643 {
1644  if (name == QByteArray("QObject"))
1645  return &QObject::staticMetaObject;
1646  else
1647  return references.value(name, 0);
1648 }
1649 
1669  const QMap<QByteArray, const QMetaObject *>& references)
1670 {
1671  QByteArray name;
1672  const QMetaObject *cl;
1673  int index;
1674 
1675  // Clear all members in the builder to their default states.
1676  d->className.clear();
1677  d->superClass = &QObject::staticMetaObject;
1678  d->classInfoNames.clear();
1679  d->classInfoValues.clear();
1680  d->methods.clear();
1681  d->properties.clear();
1682  d->enumerators.clear();
1683  d->constructors.clear();
1684  d->relatedMetaObjects.clear();
1685  d->staticMetacallFunction = 0;
1686 
1687  // Read the class and super class names.
1688  stream >> d->className;
1689  stream >> name;
1690  if (name.isEmpty()) {
1691  d->superClass = 0;
1692  } else if ((cl = resolveClassName(references, name)) != 0) {
1693  d->superClass = cl;
1694  } else {
1696  return;
1697  }
1698 
1699  // Read the counts for each type of class member.
1701  int enumeratorCount, constructorCount, relatedMetaObjectCount;
1702  stream >> classInfoCount;
1703  stream >> methodCount;
1704  stream >> propertyCount;
1705  stream >> enumeratorCount;
1706  stream >> constructorCount;
1707  stream >> relatedMetaObjectCount;
1708  if (classInfoCount < 0 || methodCount < 0 ||
1709  propertyCount < 0 || enumeratorCount < 0 ||
1710  constructorCount < 0 || relatedMetaObjectCount < 0) {
1712  return;
1713  }
1714 
1715  // Read the items of class information.
1716  for (index = 0; index < classInfoCount; ++index) {
1717  if (stream.status() != QDataStream::Ok)
1718  return;
1719  QByteArray value;
1720  stream >> name;
1721  stream >> value;
1722  addClassInfo(name, value);
1723  }
1724 
1725  // Read the member methods.
1726  for (index = 0; index < methodCount; ++index) {
1727  if (stream.status() != QDataStream::Ok)
1728  return;
1729  stream >> name;
1730  addMethod(name);
1731  QMetaMethodBuilderPrivate *method = &(d->methods[index]);
1732  stream >> method->returnType;
1733  stream >> method->parameterNames;
1734  stream >> method->tag;
1735  stream >> method->attributes;
1736  if (method->methodType() == QMetaMethod::Constructor) {
1737  // Cannot add a constructor in this set of methods.
1739  return;
1740  }
1741  }
1742 
1743  // Read the properties.
1744  for (index = 0; index < propertyCount; ++index) {
1745  if (stream.status() != QDataStream::Ok)
1746  return;
1747  QByteArray type;
1748  stream >> name;
1749  stream >> type;
1750  addProperty(name, type);
1751  QMetaPropertyBuilderPrivate *property = &(d->properties[index]);
1752  stream >> property->flags;
1753  stream >> property->notifySignal;
1754  if (property->notifySignal < -1 ||
1755  property->notifySignal >= d->methods.size()) {
1756  // Notify signal method index is out of range.
1758  return;
1759  }
1760  if (property->notifySignal >= 0 &&
1761  d->methods[property->notifySignal].methodType() != QMetaMethod::Signal) {
1762  // Notify signal method index does not refer to a signal.
1764  return;
1765  }
1766  }
1767 
1768  // Read the enumerators.
1769  for (index = 0; index < enumeratorCount; ++index) {
1770  if (stream.status() != QDataStream::Ok)
1771  return;
1772  stream >> name;
1773  addEnumerator(name);
1774  QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]);
1775  stream >> enumerator->isFlag;
1776  stream >> enumerator->keys;
1777  stream >> enumerator->values;
1778  if (enumerator->keys.size() != enumerator->values.size()) {
1779  // Mismatch between number of keys and number of values.
1781  return;
1782  }
1783  }
1784 
1785  // Read the constructor methods.
1786  for (index = 0; index < constructorCount; ++index) {
1787  if (stream.status() != QDataStream::Ok)
1788  return;
1789  stream >> name;
1790  addConstructor(name);
1791  QMetaMethodBuilderPrivate *method = &(d->constructors[index]);
1792  stream >> method->returnType;
1793  stream >> method->parameterNames;
1794  stream >> method->tag;
1795  stream >> method->attributes;
1796  if (method->methodType() != QMetaMethod::Constructor) {
1797  // The type must be Constructor.
1799  return;
1800  }
1801  }
1802 
1803  // Read the related meta objects.
1804 #ifdef Q_NO_DATA_RELOCATION
1805  //### What do we do here
1806 #else
1807  for (index = 0; index < relatedMetaObjectCount; ++index) {
1808  if (stream.status() != QDataStream::Ok)
1809  return;
1810  stream >> name;
1811  cl = resolveClassName(references, name);
1812  if (!cl) {
1814  return;
1815  }
1816  addRelatedMetaObject(cl);
1817  }
1818 #endif
1819 
1820  // Read the extra data block, which is reserved for future use.
1821  stream >> name;
1822 }
1823 
1824 #endif // !QT_NO_DATASTREAM
1825 
1836 {
1837  // Positive indices indicate methods, negative indices indicate constructors.
1838  if (_mobj && _index >= 0 && _index < _mobj->d->methods.size())
1839  return &(_mobj->d->methods[_index]);
1840  else if (_mobj && -_index >= 1 && -_index <= _mobj->d->constructors.size())
1841  return &(_mobj->d->constructors[(-_index) - 1]);
1842  else
1843  return 0;
1844 }
1845 
1855 {
1856  if (_index >= 0)
1857  return _index; // Method, signal, or slot
1858  else
1859  return (-_index) - 1; // Constructor
1860 }
1861 
1866 {
1867  QMetaMethodBuilderPrivate *d = d_func();
1868  if (d)
1869  return d->methodType();
1870  else
1871  return QMetaMethod::Method;
1872 }
1873 
1880 {
1881  QMetaMethodBuilderPrivate *d = d_func();
1882  if (d)
1883  return d->signature;
1884  else
1885  return QByteArray();
1886 }
1887 
1895 {
1896  QMetaMethodBuilderPrivate *d = d_func();
1897  if (d)
1898  return d->returnType;
1899  else
1900  return QByteArray();
1901 }
1902 
1911 {
1912  QMetaMethodBuilderPrivate *d = d_func();
1913  if (d)
1915 }
1916 
1923 {
1924  QMetaMethodBuilderPrivate *d = d_func();
1925  if (d)
1926  return d->parameterNames;
1927  else
1928  return QList<QByteArray>();
1929 }
1930 
1937 {
1938  QMetaMethodBuilderPrivate *d = d_func();
1939  if (d)
1940  d->parameterNames = value;
1941 }
1942 
1949 {
1950  QMetaMethodBuilderPrivate *d = d_func();
1951  if (d)
1952  return d->tag;
1953  else
1954  return QByteArray();
1955 }
1956 
1963 {
1964  QMetaMethodBuilderPrivate *d = d_func();
1965  if (d)
1966  d->tag = value;
1967 }
1968 
1978 {
1979  QMetaMethodBuilderPrivate *d = d_func();
1980  if (d)
1981  return d->access();
1982  else
1983  return QMetaMethod::Public;
1984 }
1985 
1994 {
1995  QMetaMethodBuilderPrivate *d = d_func();
1996  if (d && d->methodType() != QMetaMethod::Signal)
1997  d->setAccess(value);
1998 }
1999 
2006 {
2007  QMetaMethodBuilderPrivate *d = d_func();
2008  if (d)
2009  return (d->attributes >> 4);
2010  else
2011  return 0;
2012 }
2013 
2020 {
2021  QMetaMethodBuilderPrivate *d = d_func();
2022  if (d)
2023  d->attributes = ((d->attributes & 0x0f) | (value << 4));
2024 }
2025 
2036 {
2037  if (_mobj && _index >= 0 && _index < _mobj->d->properties.size())
2038  return &(_mobj->d->properties[_index]);
2039  else
2040  return 0;
2041 }
2042 
2063 {
2064  QMetaPropertyBuilderPrivate *d = d_func();
2065  if (d)
2066  return d->name;
2067  else
2068  return QByteArray();
2069 }
2070 
2077 {
2078  QMetaPropertyBuilderPrivate *d = d_func();
2079  if (d)
2080  return d->type;
2081  else
2082  return QByteArray();
2083 }
2084 
2091 {
2092  QMetaPropertyBuilderPrivate *d = d_func();
2093  if (d)
2094  return d->flag(Notify);
2095  else
2096  return false;
2097 }
2098 
2105 {
2106  QMetaPropertyBuilderPrivate *d = d_func();
2107  if (d && d->notifySignal >= 0)
2108  return QMetaMethodBuilder(_mobj, d->notifySignal);
2109  else
2110  return QMetaMethodBuilder();
2111 }
2112 
2119 {
2120  QMetaPropertyBuilderPrivate *d = d_func();
2121  if (d) {
2122  if (value._mobj) {
2123  d->notifySignal = value._index;
2124  d->setFlag(Notify, true);
2125  } else {
2126  d->notifySignal = -1;
2127  d->setFlag(Notify, false);
2128  }
2129  }
2130 }
2131 
2138 {
2139  QMetaPropertyBuilderPrivate *d = d_func();
2140  if (d) {
2141  d->notifySignal = -1;
2142  d->setFlag(Notify, false);
2143  }
2144 }
2145 
2153 {
2154  QMetaPropertyBuilderPrivate *d = d_func();
2155  if (d)
2156  return d->flag(Readable);
2157  else
2158  return false;
2159 }
2160 
2168 {
2169  QMetaPropertyBuilderPrivate *d = d_func();
2170  if (d)
2171  return d->flag(Writable);
2172  else
2173  return false;
2174 }
2175 
2183 {
2184  QMetaPropertyBuilderPrivate *d = d_func();
2185  if (d)
2186  return d->flag(Resettable);
2187  else
2188  return false;
2189 }
2190 
2198 {
2199  QMetaPropertyBuilderPrivate *d = d_func();
2200  if (d)
2201  return d->flag(Designable);
2202  else
2203  return false;
2204 }
2205 
2213 {
2214  QMetaPropertyBuilderPrivate *d = d_func();
2215  if (d)
2216  return d->flag(Scriptable);
2217  else
2218  return false;
2219 }
2220 
2228 {
2229  QMetaPropertyBuilderPrivate *d = d_func();
2230  if (d)
2231  return d->flag(Stored);
2232  else
2233  return false;
2234 }
2235 
2243 {
2244  QMetaPropertyBuilderPrivate *d = d_func();
2245  if (d)
2246  return d->flag(Editable);
2247  else
2248  return false;
2249 }
2250 
2260 {
2261  QMetaPropertyBuilderPrivate *d = d_func();
2262  if (d)
2263  return d->flag(User);
2264  else
2265  return false;
2266 }
2267 
2278 {
2279  QMetaPropertyBuilderPrivate *d = d_func();
2280  if (d)
2281  return d->flag(StdCppSet);
2282  else
2283  return false;
2284 }
2285 
2293 {
2294  QMetaPropertyBuilderPrivate *d = d_func();
2295  if (d)
2296  return d->flag(EnumOrFlag);
2297  else
2298  return false;
2299 }
2300 
2306 {
2307  QMetaPropertyBuilderPrivate *d = d_func();
2308  if (d)
2309  return d->flag(Constant);
2310  else
2311  return false;
2312 }
2313 
2319 {
2320  QMetaPropertyBuilderPrivate *d = d_func();
2321  if (d)
2322  return d->flag(Final);
2323  else
2324  return false;
2325 }
2326 
2333 {
2334  QMetaPropertyBuilderPrivate *d = d_func();
2335  if (d)
2336  d->setFlag(Readable, value);
2337 }
2338 
2345 {
2346  QMetaPropertyBuilderPrivate *d = d_func();
2347  if (d)
2348  d->setFlag(Writable, value);
2349 }
2350 
2357 {
2358  QMetaPropertyBuilderPrivate *d = d_func();
2359  if (d)
2360  d->setFlag(Resettable, value);
2361 }
2362 
2369 {
2370  QMetaPropertyBuilderPrivate *d = d_func();
2371  if (d)
2372  d->setFlag(Designable, value);
2373 }
2374 
2381 {
2382  QMetaPropertyBuilderPrivate *d = d_func();
2383  if (d)
2384  d->setFlag(Scriptable, value);
2385 }
2386 
2393 {
2394  QMetaPropertyBuilderPrivate *d = d_func();
2395  if (d)
2396  d->setFlag(Stored, value);
2397 }
2398 
2405 {
2406  QMetaPropertyBuilderPrivate *d = d_func();
2407  if (d)
2408  d->setFlag(Editable, value);
2409 }
2410 
2417 {
2418  QMetaPropertyBuilderPrivate *d = d_func();
2419  if (d)
2420  d->setFlag(User, value);
2421 }
2422 
2431 {
2432  QMetaPropertyBuilderPrivate *d = d_func();
2433  if (d)
2434  d->setFlag(StdCppSet, value);
2435 }
2436 
2444 {
2445  QMetaPropertyBuilderPrivate *d = d_func();
2446  if (d)
2447  d->setFlag(EnumOrFlag, value);
2448 }
2449 
2456 {
2457  QMetaPropertyBuilderPrivate *d = d_func();
2458  if (d)
2459  d->setFlag(Constant, value);
2460 }
2461 
2468 {
2469  QMetaPropertyBuilderPrivate *d = d_func();
2470  if (d)
2471  d->setFlag(Final, value);
2472 }
2473 
2474 
2485 {
2486  if (_mobj && _index >= 0 && _index < _mobj->d->enumerators.size())
2487  return &(_mobj->d->enumerators[_index]);
2488  else
2489  return 0;
2490 }
2491 
2510 {
2511  QMetaEnumBuilderPrivate *d = d_func();
2512  if (d)
2513  return d->name;
2514  else
2515  return QByteArray();
2516 }
2517 
2525 {
2526  QMetaEnumBuilderPrivate *d = d_func();
2527  if (d)
2528  return d->isFlag;
2529  else
2530  return false;
2531 }
2532 
2539 {
2540  QMetaEnumBuilderPrivate *d = d_func();
2541  if (d)
2542  d->isFlag = value;
2543 }
2544 
2551 {
2552  QMetaEnumBuilderPrivate *d = d_func();
2553  if (d)
2554  return d->keys.size();
2555  else
2556  return 0;
2557 }
2558 
2566 {
2567  QMetaEnumBuilderPrivate *d = d_func();
2568  if (d && index >= 0 && index < d->keys.size())
2569  return d->keys[index];
2570  else
2571  return QByteArray();
2572 }
2573 
2581 {
2582  QMetaEnumBuilderPrivate *d = d_func();
2583  if (d && index >= 0 && index < d->keys.size())
2584  return d->values[index];
2585  else
2586  return -1;
2587 }
2588 
2595 int QMetaEnumBuilder::addKey(const QByteArray& name, int value)
2596 {
2597  QMetaEnumBuilderPrivate *d = d_func();
2598  if (d) {
2599  int index = d->keys.size();
2600  d->keys += name;
2601  d->values += value;
2602  return index;
2603  } else {
2604  return -1;
2605  }
2606 }
2607 
2614 {
2615  QMetaEnumBuilderPrivate *d = d_func();
2616  if (d && index >= 0 && index < d->keys.size()) {
2617  d->keys.removeAt(index);
2618  d->values.removeAt(index);
2619  }
2620 }
2621 
QByteArray key(int index) const
Returns the key with the given index, or an empty QByteArray if no such key exists.
int indexOfClassInfo(const QByteArray &name)
Finds an item of class information with the specified name and returns its index; otherwise returns -...
double d
Definition: qnumeric_p.h:62
Status status() const
Returns the status of the data stream.
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
int keyCount() const
Returns the number of keys.
void setAttributes(int value)
Sets the additional attributes for this method to value.
bool isResettable() const
Returns true if this property can be reset to a default value; otherwise returns false.
bool isFinal() const
void setStored(bool value)
Sets this property to storable if value is true.
void removeClassInfo(int index)
Removes the item of class information at index from this class.
int type
Definition: qmetatype.cpp:239
const QMetaObject * superClass
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
bool isScriptable(const QObject *obj=0) const
Returns true if the property is scriptable for the given object; otherwise returns false...
bool isWritable() const
Returns true if this property is writable; otherwise returns false.
The QMetaEnum class provides meta-data about an enumerator.
Definition: qmetaobject.h:147
const void * extradata
Definition: qobjectdefs.h:472
uint qvariant_nameToType(const char *name)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void removeConstructor(int index)
Removes the constructor at index from this class.
static QByteArray normalizedSignature(const char *method)
Normalizes the signature of the given method.
static void fromRelocatableData(QMetaObject *, const QMetaObject *, const QByteArray &)
QMetaMethodBuilder addSlot(const QByteArray &signature)
Adds a new public slot to this class with the specified signature.
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
MetaObjectFlags flags() const
Returns the flags of the class being constructed by this meta object builder.
bool isStored() const
Returns true if the property is stored; otherwise returns false.
void setStaticMetacallFunction(QMetaObjectBuilder::StaticMetacallFunction value)
Sets the static metacall function to use to construct objects of this class to value.
bool isUser(const QObject *obj=0) const
Returns true if this property is designated as the USER property, i.e., the one that the user can edi...
QMetaMethod::MethodType methodType() const
Returns the type of this method (signal, slot, method, or constructor).
void setTag(const QByteArray &value)
Sets the tag associated with this method to value.
QByteArray name() const
Returns the name associated with this property.
bool hasNotifySignal() const
Returns true if this property has a notify signal; false otherwise.
The QMetaPropertyBuilder class enables modifications to a property definition on a meta object builde...
void removeKey(int index)
Removes the key at index from this enumerator.
int indexOfEnumerator(const QByteArray &name)
Finds an enumerator with the specified name and returns its index; otherwise returns -1...
int indexOfSlot(const QByteArray &signature)
Finds a slot with the specified signature and returns its index; otherwise returns -1...
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
void setClassName(const QByteArray &name)
Sets the name of the class being constructed by this meta object builder.
bool isScriptable() const
Returns true if the property is scriptable; otherwise returns false.
QMetaMethodBuilder method(int index) const
Returns the method at index in this class.
bool isEditable(const QObject *obj=0) const
Returns true if the property is constant; otherwise returns false.
bool isReadable() const
Returns true if this property is readable; otherwise returns false.
int indexOfSignal(const QByteArray &signature)
Finds a signal with the specified signature and returns its index; otherwise returns -1...
void setAccess(QMetaMethod::Access value)
Sets the access specification of this method (private, protected, or public) to value.
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
QMetaEnumBuilderPrivate(const QByteArray &_name)
QMetaEnumBuilderPrivate * d_func() const
Access
This enum describes the access level of a method, following the conventions used in C++...
Definition: qmetaobject.h:66
QMetaMethodBuilder notifySignal() const
Returns the notify signal associated with this property.
void setAccess(QMetaMethod::Access value)
bool isVariantType(const char *type)
const char * key(int index) const
Returns the key with the given index, or 0 if no such key exists.
QByteArray returnType() const
Returns the return type for this method; empty if the method&#39;s return type is void.
void setStatus(Status status)
Sets the status of the data stream to the status given.
Q_CORE_EXPORT void * qMalloc(size_t size)
Definition: qmalloc.cpp:53
void removeProperty(int index)
Removes the property at index from this class.
int enumeratorOffset() const
Returns the enumerator offset for this class; i.e.
QMetaEnumBuilder enumerator(int index) const
Returns the enumerator at index in this class.
int constructorCount() const
Returns the number of constructors in this class.
int propertyCount() const
Returns the number of properties in this class, including the number of properties provided by each b...
QMetaObjectExtraData::StaticMetacallFunction StaticMetacallFunction
Typedef for static metacall functions.
const char * typeName() const
Returns the return type of this method, or an empty string if the return type is void.
const char * stringdata
Definition: qobjectdefs.h:470
#define ALIGN(size, type)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QList< QMetaEnumBuilderPrivate > enumerators
const char * value() const
Returns the value of this item.
The QMetaMethodBuilder class enables modifications to a method definition on a meta object builder...
QMetaMethod::Access access() const
const char * name() const
Returns the name of the enumerator (without the scope).
QStringList keys
const QMetaObject &(* QMetaObjectAccessor)()
Definition: qobjectdefs.h:476
QList< QMetaMethodBuilderPrivate > constructors
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void removeEnumerator(int index)
Removes the enumerator at index from this class.
int indexOfMethod(const QByteArray &signature)
Finds a method with the specified signature and returns its index; otherwise returns -1...
QMetaMethodBuilder constructor(int index) const
Returns the constructor at index in this class.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QByteArray toRelocatableData(bool *=0) const
bool isEnumType() const
Returns true if the property&#39;s type is an enumeration value; otherwise returns false.
static FILE * stream
int methodCount() const
Returns the number of methods in this class, excluding the number of methods in the base class...
QList< QByteArray > parameterNames() const
Returns a list of parameter names.
int methodOffset() const
Returns the method offset for this class; i.e.
const QMetaObject * relatedMetaObject(int index) const
Returns the related meta object at index in this class.
int enumeratorCount() const
Returns the number of enumerators in this class, excluding the number of enumerators in the base clas...
QByteArray classInfoName(int index) const
Returns the name of the item of class information at index in this class.
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.
void setUser(bool value)
Sets the USER flag on this property to value.
QMetaMethod notifySignal() const
Returns the QMetaMethod instance of the property change notifying signal if one was specified...
void removeNotifySignal()
Removes the notify signal from this property.
bool isFinal() const
Returns true if the property is final; otherwise returns false.
int addRelatedMetaObject(const QMetaObject *meta)
Adds meta to this class as a related meta object.
const char * name
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
const QMetaObjectBuilder * _mobj
QList< QByteArray > classInfoValues
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
void setStdCppSet(bool value)
Sets the C++ setter flag on this property to value, which is true if the property has a C++ setter fu...
int enumeratorCount() const
Returns the number of enumerators in this class.
const char * name() const
Returns the name of this item.
void setFlags(MetaObjectFlags)
Sets the flags of the class being constructed by this meta object builder.
static QByteArray buildParameterNames(const QByteArray &signature, const QList< QByteArray > &parameterNames)
bool isDesignable() const
Returns true if this property is designable; otherwise returns false.
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
bool isConstant() const
Returns true if the property is constant; otherwise returns false.
void setFlag(int f, bool value)
int classInfoCount() const
Returns the number of items of class information in this class.
const uint * data
Definition: qobjectdefs.h:471
bool hasStdCppSet() const
Returns true if the property has a C++ setter function that follows Qt&#39;s standard "name" / "setName" ...
const QMetaObject * superClass() const
Returns the meta-object of the superclass, or 0 if there is no such object.
Definition: qobjectdefs.h:494
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
QList< QByteArray > parameterNames
int classInfoCount() const
Returns the number of items of class information in this class, exclusing the number of items of clas...
static const QMetaObject * resolveClassName(const QMap< QByteArray, const QMetaObject *> &references, const QByteArray &name)
int keyCount() const
Returns the number of keys.
void serialize(QDataStream &stream) const
Serializes the contents of the meta object builder onto stream.
StaticMetacallFunction static_metacall
Definition: qobjectdefs.h:488
void setIsFlag(bool value)
Sets this enumerator to be used as a flag if value is true.
bool isResettable() const
Returns true if this property can be reset to a default value; otherwise returns false.
MetaObjectFlags
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
MethodType methodType() const
Returns the type of this method (signal, slot, or method).
static QByteArray prototype(const QList< QByteArray > &parameterTypes, const QList< QByteArray > &parameterNames, bool *ok)
Definition: qaxserver.cpp:685
bool isWritable() const
Returns true if this property is writable; otherwise returns false.
QMetaEnumBuilder addEnumerator(const QByteArray &name)
Adds a new enumerator to this class with the specified name.
static int buildString(char *buf, char *str, int *offset, const QByteArray &value, int empty)
QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction
QMetaMethodBuilder addMethod(const QByteArray &signature)
Adds a new public method to this class with the specified signature.
void setConstant(bool value)
Sets the CONSTANT flag on this property to value.
void setReturnType(const QByteArray &value)
Sets the return type for this method to value.
QList< QMetaMethodBuilderPrivate > methods
bool isFlag() const
Returns true if this enumerator is used as a flag; otherwise returns false.
bool hasStdCppSet() const
Returns true if the property has a C++ setter function that follows Qt&#39;s standard "name" / "setName" ...
QByteArray type() const
Returns the type associated with this property.
const char * name() const
Returns this property&#39;s name.
void setResettable(bool value)
Sets this property to resettable if value is true.
PropertyFlags
Definition: qmetaobject_p.h:61
The QMetaClassInfo class provides additional information about a class.
Definition: qmetaobject.h:224
QList< const QMetaObject * > relatedMetaObjects
bool isEditable() const
Returns true if the property is editable; otherwise returns false.
const char * tag() const
Returns the tag associated with this method.
void addMetaObject(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members=AllMembers)
Adds the contents of prototype to this meta object builder.
QMetaMethodBuilderPrivate * d_func() const
const QMetaObject * superClass() const
Returns the superclass meta object of the class being constructed by this meta object builder...
int key
int classInfoOffset() const
Returns the class information offset for this class; i.e.
QMetaMethodBuilder addConstructor(const QByteArray &signature)
Adds a new constructor to this class with the specified signature.
void resize(int size)
Sets the size of the byte array to size bytes.
const QMetaObject * superdata
Definition: qobjectdefs.h:469
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
bool isStored(const QObject *obj=0) const
Returns true if the property is stored for object; otherwise returns false.
bool isDesignable(const QObject *obj=0) const
Returns true if this property is designable for the given object; otherwise returns false...
const char * property
Definition: qwizard.cpp:138
struct QMetaObject::@38 d
QList< QByteArray > parameterNames() const
Returns the list of parameter names for this method.
QMetaEnum enumerator(int index) const
Returns the meta-data for the enumerator with the given index.
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
int attributes() const
int relatedMetaObjectCount() const
Returns the number of related meta objects that are associated with this class.
bool isReadable() const
Returns true if this property is readable; otherwise returns false.
QByteArray tag() const
Returns the tag associated with this method.
quint16 index
static QByteArray normalizedType(const char *type)
Normalizes a type.
void setFinal(bool value)
Sets the FINAL flag on this property to value.
QMetaMethod constructor(int index) const
Returns the meta-data for the constructor with the given index.
void setEnumOrFlag(bool value)
Sets this property to be of an enumerator or flag type if value is true.
virtual ~QMetaObjectBuilder()
Destroys this meta object builder.
int value(int index) const
Returns the value with the given index; or returns -1 if there is no such value.
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
int addKey(const QByteArray &name, int value)
Adds a new key called name to this enumerator, associated with value.
int addClassInfo(const QByteArray &name, const QByteArray &value)
Adds name and value as an item of class information to this class.
int indexOfConstructor(const QByteArray &signature)
Finds a constructor with the specified signature and returns its index; otherwise returns -1...
QMetaPropertyBuilder property(int index) const
Returns the property at index in this class.
void removeRelatedMetaObject(int index)
Removes the related meta object at index from this class.
QByteArray classInfoValue(int index) const
Returns the value of the item of class information at index in this class.
int attributes() const
Returns the additional attributes for this method.
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
QList< QMetaPropertyBuilderPrivate > properties
int propertyOffset() const
Returns the property offset for this class; i.e.
bool isFlag() const
Returns true if this enumerator is used as a flag; otherwise returns false.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
Access access() const
Returns the access specification of this method (private, protected, or public).
void setWritable(bool value)
Sets this property to writable if value is true.
static const QMetaObjectPrivate * priv(const uint *data)
static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, bool relocatable)
QByteArray name() const
Returns the name of the enumerator (without the scope).
QMetaObject * toMetaObject() const
Converts this meta object builder into a concrete QMetaObject.
void setDesignable(bool value)
Sets this property to designable if value is true.
QMetaPropertyBuilderPrivate * d_func() const
The QMetaEnumBuilder class enables modifications to an enumerator definition on a meta object builder...
bool isUser() const
Returns true if this property is designated as the USER property, i.e., the one that the user can edi...
bool isEnumOrFlag() const
Returns true if the property is an enumerator or flag type; otherwise returns false.
bool hasNotifySignal() const
Returns true if this property has a corresponding change notify signal; otherwise returns false...
QMetaMethodBuilder addSignal(const QByteArray &signature)
Adds a new signal to this class with the specified signature.
void setParameterNames(const QList< QByteArray > &value)
Sets the list of parameter names for this method to value.
void setScriptable(bool value)
Sets this property to scriptable if value is true.
void setSuperClass(const QMetaObject *meta)
Sets the superclass meta object of the class being constructed by this meta object builder to meta...
QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction() const
Returns the static metacall function to use to construct objects of this class.
QMetaMethod::Access access() const
Returns the access specification of this method (private, protected, or public).
int constructorCount() const
Returns the number of constructors in this class.
void removeMethod(int index)
Removes the method at index from this class.
QByteArray className() const
Returns the name of the class being constructed by this meta object builder.
int methodCount() const
Returns the number of methods known to the meta-object system in this class, including the number of ...
void setReadable(bool value)
Sets this property to readable if value is true.
const QMetaObject ** objects
Definition: qobjectdefs.h:483
const char * typeName() const
Returns the name of this property&#39;s type.
void deserialize(QDataStream &stream, const QMap< QByteArray, const QMetaObject *> &references)
Deserializes a meta object builder from stream into this meta object builder.
int index() const
Returns the index of this method within its QMetaObjectBuilder.
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
QByteArray signature() const
Returns the signature of this method.
bool isConstant() const
int propertyCount() const
Returns the number of properties in this class, excluding the number of properties in the base class...
void setEditable(bool value)
Sets this property to editable if value is true.
QMetaObjectBuilder()
Constructs a new QMetaObjectBuilder.
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
MethodFlags
Definition: qmetaobject_p.h:85
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.
QMetaMethod::MethodType methodType() const
QList< QByteArray > classInfoNames
int indexOfProperty(const QByteArray &name)
Finds a property with the specified name and returns its index; otherwise returns -1...
int value(int index) const
Returns the value with the given index; or returns -1 if there is no such value.
void setNotifySignal(const QMetaMethodBuilder &value)
Sets the notify signal associated with this property to value.
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480