Exemplo n.º 1
0
bool UiExtractor::checkProperty(QObject *obj, const QString &prop) const
{
  const QMetaObject *mo = obj->metaObject();
  const QMetaProperty mp = mo->property(mo->indexOfProperty(prop.toLatin1()));

  // TODO come up with some more aggressive filtering
  if (mp.isValid() && mp.isDesignable(obj) && mp.isStored(obj) && mp.isWritable()) {
    const QVariant value = mp.read(obj);

    // try to figure out the default by resetting to it
    if (mp.isResettable()) {
      mp.reset(obj);
      if (mp.read(obj) == value) {
        return false;
      }
      mp.write(obj, value);
      return true;
    }

    // some guessing for non-resettable properties
    if (value.isNull() || !value.isValid()) {
      return false;
    }

    if (value.type() == QVariant::String) {
      return !value.toString().isEmpty();
    } else if (value.type() == QVariant::Locale) {
      return value.value<QLocale>() != QLocale::system();
    }

    return true;
  }

  return false;
}
Exemplo n.º 2
0
void AbstractParam::resetValue() {
    const QMetaObject *mo = metaObject();
    int i = mo->indexOfProperty("value");
    if (i >= 0) {
        QMetaProperty mp = mo->property(i);
        if (mp.isResettable()) {
            mp.reset(this);
        }
    }
}
Exemplo n.º 3
0
void ObjectEndPoint::propertyCall(const QServicePackage& p)
{
    if(p.d->responseType == QServicePackage::NotAResponse) {
        //service side
        Q_ASSERT(d->endPointType == ObjectEndPoint::Service);

        QByteArray data = p.d->payload.toByteArray();
        QDataStream stream(&data, QIODevice::ReadOnly);
        int metaIndex = -1;
        QVariant arg;
        int callType;
        stream >> metaIndex;
        stream >> arg;
        stream >> callType;
        const QMetaObject::Call c = (QMetaObject::Call) callType;

        QVariant result;
        QMetaProperty property = service->metaObject()->property(metaIndex);
        if (property.isValid()) {
            switch(c) {
                case QMetaObject::ReadProperty:
                    result = property.read(service);
                    break;
                case QMetaObject::WriteProperty:
                    property.write(service, arg);
                    break;
                case QMetaObject::ResetProperty:
                    property.reset(service);
                    break;
                default:
                    break;

            }
        } 

        if (c == QMetaObject::ReadProperty) {
            QServicePackage response = p.createResponse();
            if (property.isValid()) {
                response.d->responseType = QServicePackage::Success;
                response.d->payload = result;
            } else {
                response.d->responseType = QServicePackage::Failed;
            }
            dispatch->writePackage(response);
        }
    } else {