Ejemplo n.º 1
0
void ReadAttributes(QObject* obj,QDomElement& el) {
    QDomElement prop = el.firstChildElement("property");
    while (prop.isElement()) {
        QString propName = prop.attribute("name");
        int propIndx = obj->metaObject()->indexOfProperty(propName.toLatin1().constData());
        if (propIndx>=0 && propIndx<obj->metaObject()->propertyCount()) {
            QMetaProperty metaProperty(obj->metaObject()->property(propIndx));
            QString valueStr = prop.attribute("value");
            if (metaProperty.type()==QVariant::String) {
                metaProperty.write(obj,valueStr);
            } else if (metaProperty.type()==QVariant::Int) {
                metaProperty.write(obj,valueStr.toInt());
            } else if (metaProperty.type()==QVariant::UInt) {
                metaProperty.write(obj,valueStr.toUInt());
            } else if (metaProperty.type()==QVariant::Double) {
                metaProperty.write(obj,valueStr.toDouble());
            } else if (metaProperty.type()==QVariant::Bool) {
                metaProperty.write(obj,bool(valueStr.toInt()));
            } else if (metaProperty.type()==QVariant::Point) {
                QStringList sl = valueStr.split(";");
                metaProperty.write(obj,QPoint(sl.first().toInt(),sl.last().toInt()));
            } else if (metaProperty.type()==QVariant::PointF) {
                QStringList sl = valueStr.split(";");
                metaProperty.write(obj,QPoint(sl.first().toDouble(),sl.last().toDouble()));
            } else if (metaProperty.type()==QVariant::Size) {
                QStringList sl = valueStr.split(";");
                metaProperty.write(obj,QSize(sl.first().toInt(),sl.last().toInt()));
            } else if (metaProperty.type()==QVariant::SizeF) {
                QStringList sl = valueStr.split(";");
                metaProperty.write(obj,QSizeF(sl.first().toDouble(),sl.last().toDouble()));
            }
        }
        prop = prop.nextSiblingElement("property");
    }
}
Ejemplo n.º 2
0
QPair<QString, ServerNodeInstance> QmlGraphicsItemNodeInstance::anchor(const QString &name) const
{
    if (!isValidAnchorName(name) || !hasAnchor(name))
        return GraphicsObjectNodeInstance::anchor(name);

    QObject *targetObject = 0;
    QString targetName;

    if (name == "anchors.fill") {
        targetObject = anchors()->fill();
    } else if (name == "anchors.centerIn") {
        targetObject = anchors()->centerIn();
    } else {
        QDeclarativeProperty metaProperty(object(), name, context());
        if (!metaProperty.isValid())
            return GraphicsObjectNodeInstance::anchor(name);

        QDeclarativeAnchorLine anchorLine = metaProperty.read().value<QDeclarativeAnchorLine>();
        if (anchorLine.anchorLine != QDeclarativeAnchorLine::Invalid) {
            targetObject = anchorLine.item;
            targetName = propertyNameForAnchorLine(anchorLine.anchorLine);
        }

    }

    if (targetObject && nodeInstanceServer()->hasInstanceForObject(targetObject)) {
        return qMakePair(targetName, nodeInstanceServer()->instanceForObject(targetObject));
    } else {
        return GraphicsObjectNodeInstance::anchor(name);
    }
}
Ejemplo n.º 3
0
void Mash::acceptMashStepChange(QMetaProperty prop, QVariant /*val*/)
{
   int i;
   MashStep* stepSender = qobject_cast<MashStep*>(sender());
   if( stepSender == 0 )
      return;
   
   // If one of our mash steps changed, our calculated properties
   // may also change, so we need to emit some signals.
   i = mashSteps().indexOf(stepSender);
   if( i >= 0 )
   {
      emit changed(metaProperty("totalMashWater_l"), QVariant());
      emit changed(metaProperty("totalTime"), QVariant());
   }
}
Ejemplo n.º 4
0
static void WriteAttributes(QObject* obj,QDomElement& el,QDomDocument& doc) {
    el.setAttribute("type",obj->metaObject()->className());
    for(int i = 0; i < obj->metaObject()->propertyCount(); ++i) {
        QMetaProperty metaProperty(obj->metaObject()->property(i));
        {
            QDomElement prop = doc.createElement("property");
            prop.setAttribute("name",QString(metaProperty.name()));
            QVariant value = metaProperty.read(obj);
            QString strValue;
            if (metaProperty.type()==QVariant::String) {
                strValue = value.toString();
            } else if (metaProperty.type()==QVariant::Int) {
                strValue = value.toString();
            } else if (metaProperty.type()==QVariant::UInt) {
                strValue = value.toString();
            } else if (metaProperty.type()==QVariant::Double) {
                strValue = value.toString();
            } else if (metaProperty.type()==QVariant::Bool) {
                strValue = value.toBool() ? "1" : "0";
            } else if (metaProperty.type()==QVariant::Point) {
                strValue = QString::number(value.toPoint().x())+";"
                           + QString::number(value.toPoint().y());
            } else if (metaProperty.type()==QVariant::PointF) {
                strValue = QString::number(value.toPointF().x())+";"
                           + QString::number(value.toPointF().y());
            } else if (metaProperty.type()==QVariant::Size) {
                strValue = QString::number(value.toSize().width())+";"
                           + QString::number(value.toSize().height());
            } else if (metaProperty.type()==QVariant::SizeF) {
                strValue = QString::number(value.toSizeF().width())+";"
                           + QString::number(value.toSizeF().height());
            } else {
                QByteArray ar;
                QDataStream ds(&ar,QIODevice::WriteOnly);
                ds << value;
                strValue = ar.toBase64().data();
            }
            prop.setAttribute("value",strValue);
            el.appendChild(prop);
        }
    }
}
Ejemplo n.º 5
0
QVariantMap Serializer::objectToVariant(const QObject *object)
{
    QVariantMap result;
    const QDataSuite::MetaObject metaObject = QDataSuite::MetaObject::metaObject(object);
    int count = metaObject.propertyCount();
    for (int i = 1; i < count; ++i) {
        QDataSuite::MetaProperty metaProperty(metaObject.property(i), metaObject);

        if (!metaProperty.isReadable()
                || !metaProperty.isStored()
                || metaProperty.isRelationProperty())
            continue;

        result[QLatin1String(metaProperty.name())] = object->property(metaProperty.name());
    }

    QList<QByteArray> dynamicPropertyNames = object->dynamicPropertyNames();
    foreach(const QByteArray dynamicPropertyName, dynamicPropertyNames) {
        result[QString(dynamicPropertyName)] = object->property(dynamicPropertyName);
    }
Ejemplo n.º 6
0
Country::Country(const QString& string) {
    const QMetaProperty mp(metaProperty("val"));
    QMetaEnum qmen = mp.enumerator();
    m_Val = static_cast<CountryType>(qmen.keyToValue(string.toAscii()));
}
Ejemplo n.º 7
0
QString Country::toString() const {
    const QMetaProperty mp(metaProperty("val"));
    QMetaEnum qmen = mp.enumerator();
    return qmen.valueToKey(m_Val);
}