本文整理汇总了C++中QMetaMethod::access方法的典型用法代码示例。如果您正苦于以下问题:C++ QMetaMethod::access方法的具体用法?C++ QMetaMethod::access怎么用?C++ QMetaMethod::access使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMetaMethod
的用法示例。
在下文中一共展示了QMetaMethod::access方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generateInterfaceXml
static QString generateInterfaceXml(const QMetaObject *mo, int flags, int methodOffset, int propOffset)
{
QString retval;
// start with properties:
if (flags & (QDBusConnection::ExportScriptableProperties |
QDBusConnection::ExportNonScriptableProperties)) {
for (int i = propOffset; i < mo->propertyCount(); ++i) {
static const char *accessvalues[] = {0, "read", "write", "readwrite"};
QMetaProperty mp = mo->property(i);
if (!((mp.isScriptable() && (flags & QDBusConnection::ExportScriptableProperties)) ||
(!mp.isScriptable() && (flags & QDBusConnection::ExportNonScriptableProperties))))
continue;
int access = 0;
if (mp.isReadable())
access |= 1;
if (mp.isWritable())
access |= 2;
int typeId = mp.userType();
if (!typeId)
continue;
const char *signature = QDBusMetaType::typeToSignature(typeId);
if (!signature)
continue;
retval += QString::fromLatin1(" <property name=\"%1\" type=\"%2\" access=\"%3\"")
.arg(QLatin1String(mp.name()))
.arg(QLatin1String(signature))
.arg(QLatin1String(accessvalues[access]));
if (QDBusMetaType::signatureToType(signature) == QVariant::Invalid) {
const char *typeName = QMetaType::typeName(typeId);
retval += QString::fromLatin1(">\n <annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"%3\"/>\n </property>\n")
.arg(typeNameToXml(typeName));
} else {
retval += QLatin1String("/>\n");
}
}
}
// now add methods:
for (int i = methodOffset; i < mo->methodCount(); ++i) {
QMetaMethod mm = mo->method(i);
bool isSignal;
if (mm.methodType() == QMetaMethod::Signal)
// adding a signal
isSignal = true;
else if (mm.access() == QMetaMethod::Public && (mm.methodType() == QMetaMethod::Slot || mm.methodType() == QMetaMethod::Method))
isSignal = false;
else
continue; // neither signal nor public slot
if (isSignal && !(flags & (QDBusConnection::ExportScriptableSignals |
QDBusConnection::ExportNonScriptableSignals)))
continue; // we're not exporting any signals
if (!isSignal && (!(flags & (QDBusConnection::ExportScriptableSlots | QDBusConnection::ExportNonScriptableSlots)) &&
!(flags & (QDBusConnection::ExportScriptableInvokables | QDBusConnection::ExportNonScriptableInvokables))))
continue; // we're not exporting any slots or invokables
QString xml = QString::fromLatin1(" <%1 name=\"%2\">\n")
.arg(isSignal ? QLatin1String("signal") : QLatin1String("method"))
.arg(QString::fromLatin1(mm.name()));
// check the return type first
int typeId = mm.returnType();
if (typeId != QMetaType::UnknownType && typeId != QMetaType::Void) {
const char *typeName = QDBusMetaType::typeToSignature(typeId);
if (typeName) {
xml += QString::fromLatin1(" <arg type=\"%1\" direction=\"out\"/>\n")
.arg(typeNameToXml(typeName));
// do we need to describe this argument?
if (QDBusMetaType::signatureToType(typeName) == QVariant::Invalid)
xml += QString::fromLatin1(" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"%1\"/>\n")
.arg(typeNameToXml(QMetaType::typeName(typeId)));
} else
continue;
}
else if (typeId == QMetaType::UnknownType)
continue; // wasn't a valid type
QList<QByteArray> names = mm.parameterNames();
QVector<int> types;
int inputCount = qDBusParametersForMethod(mm, types);
if (inputCount == -1)
continue; // invalid form
if (isSignal && inputCount + 1 != types.count())
continue; // signal with output arguments?
if (isSignal && types.at(inputCount) == QDBusMetaTypeId::message())
continue; // signal with QDBusMessage argument?
if (isSignal && mm.attributes() & QMetaMethod::Cloned)
continue; // cloned signal?
int j;
bool isScriptable = mm.attributes() & QMetaMethod::Scriptable;
//.........这里部分代码省略.........
示例2: sName
ServiceHost::ServiceHost(const QMetaObject &metaObject,
const QString &sExtensionName,
const QString &sBaseUrl,
const QString &sSharePath )
: HttpServerExtension ( sExtensionName, sSharePath )
{
m_oMetaObject = metaObject;
m_sBaseUrl = sBaseUrl;
// --------------------------------------------------------------
// Read in all callable methods and cache information about them
// --------------------------------------------------------------
for (int nIdx = 0; nIdx < m_oMetaObject.methodCount(); nIdx++)
{
QMetaMethod method = m_oMetaObject.method( nIdx );
if ((method.methodType() == QMetaMethod::Slot ) &&
(method.access() == QMetaMethod::Public ))
{
QString sName( method.signature() );
// ------------------------------------------------------
// Ignore the following methods...
// ------------------------------------------------------
if (sName == "deleteLater()")
continue;
// ------------------------------------------------------
MethodInfo oInfo;
oInfo.m_nMethodIndex = nIdx;
oInfo.m_sName = sName.section( '(', 0, 0 );
oInfo.m_oMethod = method;
oInfo.m_eRequestType = (RequestType)(RequestTypeGet |
RequestTypePost |
RequestTypeHead);
QString sMethodClassInfo = oInfo.m_sName + "_Method";
int nClassIdx =
m_oMetaObject.indexOfClassInfo(sMethodClassInfo.toAscii());
if (nClassIdx >=0)
{
QString sRequestType =
m_oMetaObject.classInfo(nClassIdx).value();
if (sRequestType == "POST")
oInfo.m_eRequestType = RequestTypePost;
else if (sRequestType == "GET" )
oInfo.m_eRequestType = (RequestType)(RequestTypeGet |
RequestTypeHead);
}
m_Methods.insert( oInfo.m_sName, oInfo );
}
}
}
示例3: exportItem
QString AsemanQtTools::exportItem(const QString &module, int major, int minor, const QString &component, bool store)
{
QString result;
aseman_qt_tools_indexCache << component;
QMetaObject meta = T::staticMetaObject;
QString inherits = fixType(meta.superClass()? meta.superClass()->className() : "");
bool isModel = component.toLower().contains("model");
result += QString("# %1\n\n").arg(component);
QString headers;
headers += QString(" * [Component details](#component-details)\n");
QString details = QString("\n### Component details:\n\n");
details += QString("|Detail|Value|\n"
"|------|-----|\n");
details += QString("|%1|%2 %3.%4|\n").arg("Import").arg(module).arg(major).arg(minor);
details += QString("|%1|<font color='#074885'>%2</font>|\n").arg("Component").arg(component);
details += QString("|%1|<font color='#074885'>%2</font>|\n").arg("C++ class").arg(meta.className());
details += QString("|%1|<font color='#074885'>%2</font>|\n").arg("Inherits").arg(inherits);
details += QString("|%1|<font color='#074885'>%2</font>|\n").arg("Model").arg(isModel?"Yes":"No");
QString resultProperties;
QStringList propertiesSignals;
for(int i=0; i<meta.propertyCount(); i++)
{
QMetaProperty property = meta.property(i);
const QString &propertyName = property.name();
const QString &propertyType = fixType(property.typeName());
propertiesSignals << property.notifySignal().name();
QString text = QString("* <font color='#074885'><b>%1</b></font>: %2").arg(propertyName).arg(propertyType);
if(!property.isWritable())
text += " (readOnly)";
text += "\n";
if(meta.propertyOffset()<=i)
resultProperties += text;
}
QString enumResults;
for(int i=meta.enumeratorOffset(); i<meta.enumeratorCount(); i++)
{
QMetaEnum enumerator = meta.enumerator(i);
const QString &enumName = enumerator.name();
enumResults += QString("\n##### %1\n\n").arg(enumName);
enumResults += QString("|Key|Value|\n"
"|---|-----|\n");
for(int j=0; j<enumerator.keyCount(); j++)
enumResults += QString("|%1|%2|\n").arg(enumerator.key(j)).arg(enumerator.value(j));
}
QString resultSlots;
QString resultSignals;
for(int i=meta.methodOffset(); i<meta.methodCount(); i++)
{
QMetaMethod method = meta.method(i);
if(method.access() != QMetaMethod::Public)
continue;
const QString &methodName = method.name();
if(propertiesSignals.contains(methodName))
continue;
const QString &methodType = fixType(method.typeName());
QString args;
const QList<QByteArray> ¶mNames = method.parameterNames();
const QList<QByteArray> ¶mTypes = method.parameterTypes();
for(int j=0; j<paramNames.count(); j++)
{
if(j != 0)
args += ", ";
args += fixType(paramTypes[j]) + " " + paramNames[j];
}
QString text = QString(" * %1 <font color='#074885'><b>%2</b></font>(%3)\n").arg(methodType).arg(methodName).arg(args);
switch(static_cast<int>(method.methodType()))
{
case QMetaMethod::Slot:
resultSlots += text;
break;
case QMetaMethod::Signal:
resultSignals += text;
break;
}
}
if(!resultProperties.isEmpty())
{
headers += QString(" * [Normal Properties](#normal-properties)\n");
resultProperties = QString("\n### Normal Properties\n\n") + resultProperties;
}
if(!enumResults.isEmpty())
{
headers += QString(" * [Enumerator](#enumerator)\n");
//.........这里部分代码省略.........
示例4: append
void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaObject *metaObject,
int revision,
Data::Flag propertyFlags, Data::Flag methodFlags, Data::Flag signalFlags)
{
Q_UNUSED(revision);
allowedRevisionCache.append(0);
QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine);
int methodCount = metaObject->methodCount();
// QObject::staticMetaObject.methodCount() to block the destroyed signal and the deleteLater() slot
int methodOffset = qMax(QObject::staticMetaObject.methodCount(), metaObject->methodOffset());
methodIndexCache.resize(methodCount);
for (int ii = methodOffset; ii < methodCount; ++ii) {
QMetaMethod m = metaObject->method(ii);
if (m.access() == QMetaMethod::Private)
continue;
QString methodName = QString::fromUtf8(m.methodSignature());
int parenIdx = methodName.indexOf(QLatin1Char('('));
Q_ASSERT(parenIdx != -1);
methodName = methodName.left(parenIdx);
RData *data = new RData;
data->identifier = enginePriv->objectClass->createPersistentIdentifier(methodName);
methodIndexCache[ii] = data;
data->load(m);
if (m.methodType() == QMetaMethod::Slot || m.methodType() == QMetaMethod::Method)
data->flags |= methodFlags;
else if (m.methodType() == QMetaMethod::Signal)
data->flags |= signalFlags;
data->metaObjectOffset = allowedRevisionCache.count() - 1;
if (stringCache.contains(methodName)) {
RData *old = stringCache[methodName];
// We only overload methods in the same class, exactly like C++
if (old->flags & Data::IsFunction && old->coreIndex >= methodOffset)
data->relatedIndex = old->coreIndex;
data->overrideIndexIsProperty = !bool(old->flags & Data::IsFunction);
data->overrideIndex = old->coreIndex;
stringCache[methodName]->release();
identifierCache[data->identifier.identifier]->release();
}
stringCache.insert(methodName, data);
identifierCache.insert(data->identifier.identifier, data);
data->addref();
data->addref();
}
int propCount = metaObject->propertyCount();
int propOffset = metaObject->propertyOffset();
indexCache.resize(propCount);
for (int ii = propOffset; ii < propCount; ++ii) {
QMetaProperty p = metaObject->property(ii);
if (!p.isScriptable())
continue;
QString propName = QString::fromUtf8(p.name());
RData *data = new RData;
data->identifier = enginePriv->objectClass->createPersistentIdentifier(propName);
indexCache[ii] = data;
data->load(p, engine);
data->flags |= propertyFlags;
data->metaObjectOffset = allowedRevisionCache.count() - 1;
if (stringCache.contains(propName)) {
RData *old = stringCache[propName];
data->overrideIndexIsProperty = !bool(old->flags & Data::IsFunction);
data->overrideIndex = old->coreIndex;
stringCache[propName]->release();
identifierCache[data->identifier.identifier]->release();
}
stringCache.insert(propName, data);
identifierCache.insert(data->identifier.identifier, data);
data->addref();
data->addref();
}
}
示例5: QTreeWidgetItem
QTreeWidgetItem* GCF::Components::ScriptableObjectExplorerData::loadObjectInfo(QTreeWidget* treeWidget, QTreeWidgetItem* item, QObject* object, QString name, bool showChildren)
{
if(!object)
return 0;
if(!treeWidget && !item)
return 0;
static QColor eventColor = Qt::black;
static QColor propertyColor = Qt::black;
static QColor methodColor = Qt::black;
if(name.isEmpty())
name = object->objectName();
if(name.isEmpty())
return 0;
// add the object item
QTreeWidgetItem* objectItem = 0;
if(item)
objectItem = new QTreeWidgetItem(item, OBJECT_ITEM);
else
objectItem = new QTreeWidgetItem(treeWidget, OBJECT_ITEM);
objectItem->setText(0, name);
objectItem->setData(0, Qt::UserRole, qVariantFromValue<QObject*>(object));
objectItem->setText(1, name);
objectItem->setIcon(0, objectPm);
objectItems.append(objectItem);
QTreeWidgetItem* eventItem = new QTreeWidgetItem(objectItem, QStringList() << "Events");
QTreeWidgetItem* methodItem = new QTreeWidgetItem(objectItem, QStringList() << "Methods");
QTreeWidgetItem* propertyItem = new QTreeWidgetItem(objectItem, QStringList() << "Properties");
QTreeWidgetItem* childrenItem = new QTreeWidgetItem(objectItem, QStringList() << "Children");
eventItem->setIcon(0, eventPmDir);
methodItem->setIcon(0, methodPmDir);
propertyItem->setIcon(0, propertyPmDir);
childrenItem->setIcon(0, propertyPmDir);
// add items.
const QMetaObject* mo = object->metaObject();
for(int j=QObject::staticMetaObject.methodCount(); j<mo->methodCount(); j++)
{
QMetaMethod m = mo->method(j);
QTreeWidgetItem* item = 0;
switch(m.methodType())
{
case QMetaMethod::Signal: {
item = new QTreeWidgetItem(eventItem, EVENT_ITEM);
item->setIcon(0, eventPm);
QString event = formattedName(m.signature());
item->setText(0, event);
item->setData(0, Qt::ForegroundRole, eventColor);
} break;
case QMetaMethod::Method:
case QMetaMethod::Slot:
default: {
if(m.access() != QMetaMethod::Public)
break;
item = new QTreeWidgetItem(methodItem, METHOD_ITEM);
item->setIcon(0, methodPm);
QString methodName = QString(m.signature()).section('(', 0, 0);
item->setText(0, methodName);
item->setData(0, Qt::ForegroundRole, methodColor);
} break;
}
if(item)
item->setData(0, Qt::UserRole, qVariantFromValue<QMetaMethod>(m));
}
for(int j=QObject::staticMetaObject.propertyCount(); j<mo->propertyCount(); j++)
{
QMetaProperty prop = mo->property(j);
QTreeWidgetItem* item = new QTreeWidgetItem(propertyItem, PROPERTY_ITEM);
item->setIcon(0, propertyPm);
item->setData(0, Qt::UserRole, qVariantFromValue<QMetaProperty>(prop));
item->setData(0, Qt::ForegroundRole, propertyColor);
item->setText(0, prop.name());
}
if(showChildren)
{
QObjectList children = object->children();
for(int i=0; i<children.count(); i++)
{
QObject* childObject = children[i];
QString childName = QString("%1.%2").arg(name).arg(childObject->objectName());
loadObjectInfo(treeWidget, childrenItem, childObject, childName, showChildren);
}
}
objectItem->setExpanded(false);
if(eventItem->childCount())
eventItem->setExpanded(false);
else
delete eventItem;
//.........这里部分代码省略.........