本文整理汇总了C++中QMetaObjectBuilder::addClassInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ QMetaObjectBuilder::addClassInfo方法的具体用法?C++ QMetaObjectBuilder::addClassInfo怎么用?C++ QMetaObjectBuilder::addClassInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMetaObjectBuilder
的用法示例。
在下文中一共展示了QMetaObjectBuilder::addClassInfo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create_dynamic_metaobject
// Create a dynamic meta-object for a Python type by introspecting its
// attributes. Note that it leaks if the type is deleted.
static int create_dynamic_metaobject(pyqtWrapperType *pyqt_wt)
{
PyTypeObject *pytype = (PyTypeObject *)pyqt_wt;
qpycore_metaobject *qo = new qpycore_metaobject;
QMetaObjectBuilder builder;
// Get any class info.
QList<ClassInfo> class_info_list = qpycore_get_class_info_list();
// Get any enums/flags.
QList<EnumsFlags> enums_flags_list = qpycore_get_enums_flags_list();
// Get the super-type's meta-object.
builder.setSuperClass(get_qmetaobject((pyqtWrapperType *)pytype->tp_base));
// Get the name of the type. Dynamic types have simple names.
builder.setClassName(pytype->tp_name);
// Go through the class hierarchy getting all PyQt properties, slots and
// signals.
QList<const qpycore_pyqtSignal *> psigs;
QMap<uint, PropertyData> pprops;
if (trawl_hierarchy(pytype, qo, builder, psigs, pprops) < 0)
return -1;
qo->nr_signals = psigs.count();
// Initialise the header section of the data table. Note that Qt v4.5
// introduced revision 2 which added constructors. However the design is
// broken in that the static meta-call function doesn't provide enough
// information to determine which Python sub-class of a Qt class is to be
// created. So we stick with revision 1 (and don't allow pyqtSlot() to
// decorate __init__).
// Set up any class information.
for (int i = 0; i < class_info_list.count(); ++i)
{
const ClassInfo &ci = class_info_list.at(i);
builder.addClassInfo(ci.first, ci.second);
}
// Set up any enums/flags.
for (int i = 0; i < enums_flags_list.count(); ++i)
{
const EnumsFlags &ef = enums_flags_list.at(i);
QByteArray scoped_name(pytype->tp_name);
scoped_name.append("::");
scoped_name.append(ef.name);
QMetaEnumBuilder enum_builder = builder.addEnumerator(scoped_name);
enum_builder.setIsFlag(ef.isFlag);
QHash<QByteArray, int>::const_iterator it = ef.keys.constBegin();
while (it != ef.keys.constEnd())
{
enum_builder.addKey(it.key(), it.value());
++it;
}
}
// Add the signals to the meta-object.
for (int g = 0; g < qo->nr_signals; ++g)
{
const qpycore_pyqtSignal *ps = psigs.at(g);
QMetaMethodBuilder signal_builder = builder.addSignal(
ps->parsed_signature->signature.mid(1));
if (ps->parameter_names)
signal_builder.setParameterNames(*ps->parameter_names);
signal_builder.setRevision(ps->revision);
}
// Add the slots to the meta-object.
for (int s = 0; s < qo->pslots.count(); ++s)
{
const Chimera::Signature *slot_signature = qo->pslots.at(s)->slotSignature();
const QByteArray &sig = slot_signature->signature;
QMetaMethodBuilder slot_builder = builder.addSlot(sig);
// Add any type.
if (slot_signature->result)
slot_builder.setReturnType(slot_signature->result->name());
slot_builder.setRevision(slot_signature->revision);
}
// Add the properties to the meta-object.
QMapIterator<uint, PropertyData> it(pprops);
for (int p = 0; it.hasNext(); ++p)
//.........这里部分代码省略.........
示例2: create_dynamic_metaobject
//.........这里部分代码省略.........
#endif
int data_len = header_size + class_info_list.count() * 2 +
qo->nr_signals * 5 + qo->pslots.count() * 5 +
pprops.count() * (has_notify_signal ? 4 : 3) + 1;
uint *data = new uint[data_len];
int i_offset = header_size;
int g_offset = i_offset + class_info_list.count() * 2;
int s_offset = g_offset + qo->nr_signals * 5;
int p_offset = s_offset + qo->pslots.count() * 5;
int n_offset = p_offset + pprops.count() * 3;
int empty = 0;
for (int i = 0; i < data_len; ++i)
data[i] = 0;
// The revision number.
data[0] = revision;
#endif
// Set up any class information.
if (class_info_list.count() > 0)
{
#if QT_VERSION < 0x050000
data[2] = class_info_list.count();
data[3] = i_offset;
#endif
for (int i = 0; i < class_info_list.count(); ++i)
{
const ClassInfo &ci = class_info_list.at(i);
#if QT_VERSION >= 0x050000
builder.addClassInfo(ci.first, ci.second);
#else
data[i_offset + (i * 2) + 0] = qo->str_data.size();
qo->str_data.append(ci.first.constData());
qo->str_data.append('\0');
data[i_offset + (i * 2) + 1] = qo->str_data.size();
qo->str_data.append(ci.second.constData());
qo->str_data.append('\0');
#endif
}
}
#if QT_VERSION < 0x050000
// Set up the methods count and offset.
if (qo->nr_signals || qo->pslots.count())
{
data[4] = qo->nr_signals + qo->pslots.count();
data[5] = g_offset;
// We might need an empty string.
empty = qo->str_data.size();
qo->str_data.append('\0');
}
// Set up the properties count and offset.
if (pprops.count())
{
data[6] = pprops.count();
data[7] = p_offset;
}
#if QT_VERSION >= 0x040600
示例3: clone
static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
const QMetaObject *ignoreStart, const QMetaObject *ignoreEnd)
{
// Set classname
builder.setClassName(ignoreEnd->className());
// Clone Q_CLASSINFO
for (int ii = mo->classInfoOffset(); ii < mo->classInfoCount(); ++ii) {
QMetaClassInfo info = mo->classInfo(ii);
int otherIndex = ignoreEnd->indexOfClassInfo(info.name());
if (otherIndex >= ignoreStart->classInfoOffset() + ignoreStart->classInfoCount()) {
// Skip
} else {
builder.addClassInfo(info.name(), info.value());
}
}
// Clone Q_PROPERTY
for (int ii = mo->propertyOffset(); ii < mo->propertyCount(); ++ii) {
QMetaProperty property = mo->property(ii);
int otherIndex = ignoreEnd->indexOfProperty(property.name());
if (otherIndex >= ignoreStart->propertyOffset() + ignoreStart->propertyCount()) {
builder.addProperty(QByteArray("__qml_ignore__") + property.name(), QByteArray("void"));
// Skip
} else {
builder.addProperty(property);
}
}
// Clone Q_METHODS
for (int ii = mo->methodOffset(); ii < mo->methodCount(); ++ii) {
QMetaMethod method = mo->method(ii);
// More complex - need to search name
QByteArray name = method.name();
bool found = false;
for (int ii = ignoreStart->methodOffset() + ignoreStart->methodCount();
!found && ii < ignoreEnd->methodOffset() + ignoreEnd->methodCount();
++ii) {
QMetaMethod other = ignoreEnd->method(ii);
found = name == other.name();
}
QMetaMethodBuilder m = builder.addMethod(method);
if (found) // SKIP
m.setAccess(QMetaMethod::Private);
}
// Clone Q_ENUMS
for (int ii = mo->enumeratorOffset(); ii < mo->enumeratorCount(); ++ii) {
QMetaEnum enumerator = mo->enumerator(ii);
int otherIndex = ignoreEnd->indexOfEnumerator(enumerator.name());
if (otherIndex >= ignoreStart->enumeratorOffset() + ignoreStart->enumeratorCount()) {
// Skip
} else {
builder.addEnumerator(enumerator);
}
}
}