Example #1
0
static void streamDebug(QDebug dbg, const QVariant &v)
{

    if((uint)v.userType() == JOBJECTWRAPPER_TYPE) {
        const JObjectWrapper wrapper = v.value<JObjectWrapper>();
        JNIEnv *env = qtjambi_current_environment();
        StaticCache *sc = StaticCache::instance();
        sc->resolveObject();
        jobject java_object =  wrapper.object;
        dbg << qtjambi_to_qstring(env, static_cast<jstring>(env->CallObjectMethod(java_object, sc->Object.toString)));
        return;
    }
    else if (QtJambiVariant::getLastHandler()) {
        QtJambiVariant::getLastHandler()->debugStream(dbg, v);
        return;
    }
    else if (qcoreVariantHandler()) {
        qcoreVariantHandler()->debugStream(dbg, v);
        return;
    }
}
Example #2
0
void ScriptedTutorialTest::testTearDown() {
    QSKIP("Skipped until tearDown argument is set again to scripting::ScriptedTutorial*", SkipAll);

    ScriptedTutorial scriptedTutorial(mTemporaryFile->fileName());

    //ScriptedTutorial* must be registered in order to be used with QSignalSpy.
    //The name must contain the namespace, as it needs the full name used in the
    //signal (and the signal has to be declared using the full namespace so the
    //spied argument can be converted using qvariant_cast).
    int scriptedTutorialStarType =
        qRegisterMetaType<ScriptedTutorial*>("scripting::ScriptedTutorial*");
    QSignalSpy tearDownSpy(&scriptedTutorial,
                           SIGNAL(tearDown(scripting::ScriptedTutorial*)));

    scriptedTutorial.tearDown();

    QCOMPARE(tearDownSpy.count(), 1);
    QVariant argument = tearDownSpy.at(0).at(0);
    QCOMPARE(argument.userType(), scriptedTutorialStarType);
    QCOMPARE(qvariant_cast<ScriptedTutorial*>(argument), &scriptedTutorial);
}
Example #3
0
SValue SValue::property_helper(const QString &name)
{
	qfLogFuncFrame() << name;
	SValue ret;
	QVariant v = d->value.toMap().value(name);
	if(v.userType() == qMetaTypeId<SValue>()) {
		/// je to v pohode vracim object, ktery j*z existuje
		ret = qvariant_cast<SValue>(v);
	}
	else {
		if(v.isValid()) {
			/// objekt existuje, ale neni SValue, tak ji z nej vyrob
			ret.setValue(v);
		}
		else {
			/// objekt neexistuje
		}
		setProperty(name, ret);
	}
	return ret;
}
static bool qAppendVariantToMessage(DBusMessageIter *it, const QDBusType &type,
                                    const QVariant &var)
{
    Q_UNUSED(type);             // type is 'v'

    QVariant arg = var;
    if (var.userType() == QDBusTypeHelper<QVariant>::id())
        arg = QDBusTypeHelper<QVariant>::fromVariant(var); // extract the inner variant
    
    QDBusType t = QDBusType::guessFromVariant(arg);
    if (!t.isValid())
        return false;
    
    // now add this variant
    DBusMessageIter sub;
    dbus_message_iter_open_container(it, DBUS_TYPE_VARIANT, t.dbusSignature(), &sub);
    qVariantToIteratorInternal(&sub, arg, t);
    dbus_message_iter_close_container(it, &sub);

    return true;                // success
}
Example #5
0
static int
qstringlist_new(lua_State *L)
{
  QStringList l;
  if (! lua_isnone(L, 1))
    {
      luaL_checktype(L, 1, LUA_TTABLE);
      int n = lua_objlen(L, 1);
      for (int i=1; i<=n; i++)
        {
          lua_rawgeti(L, 1, i);
          QVariant v = luaQ_toqvariant(L, -1, QMetaType::QString);
          if (v.userType() != QMetaType::QString)
            luaL_error(L, "table element cannot be converted to a QString");
          l += v.toString();
          lua_pop(L, 1);
        }
    }
  luaQ_pushqt(L, QVariant(l));
  return 1;
}
Example #6
0
QString ConversionUtil::toUserString(const QVariant &variant) {

    if (!variant.isValid()) {
        return "(not set)";
    }

    switch (variant.type()) {
        case QVariant::Bool:
            return variant.toBool() ? "true" : "false";
        case QVariant::Int:
            return QString::number(variant.toInt());
        case QVariant::Double:
            return QString::number(variant.toDouble());
        case QVariant::String: {
            QString string = variant.toString();
            return string.isEmpty() ? "(empty string)" : string;
        }
        case QVariant::StringList:
            return variant.toStringList().join("\n");
        case QVariant::DateTime:
            return variant.toDateTime().toString();
        case QVariant::Map: {
            QStringList stringList;
            QVariantMap map = variant.toMap();
            for (const QString &key : map.keys()) {
                stringList << QString("%1: %2").arg(jsString(key), toUserString(map[key]));
            }
            return stringList.isEmpty() ? "(empty)" : stringList.join("\n");
        }
        case QVariant::UserType: {
            MetaTypeRegistry::UserStringConverters converters =
                    MetaTypeRegistry::userStringConverters(QMetaType::typeName(variant.userType()));
            if (converters.typeToUserStringConverter) {
                return converters.typeToUserStringConverter(variant);
            }
        }   // fall-through
        default:
            return "(unknown type)";
    }
}
void tst_qdeclarativelistreference::engineTypes()
{
    QDeclarativeEngine engine;
    QDeclarativeComponent component(&engine, TEST_FILE("engineTypes.qml"));

    QObject *o = component.create();
    QVERIFY(o);

    QDeclarativeProperty p1(o, QLatin1String("myList"));
    QVERIFY(p1.propertyTypeCategory() == QDeclarativeProperty::Normal);

    QDeclarativeProperty p2(o, QLatin1String("myList"), engine.rootContext());
    QVERIFY(p2.propertyTypeCategory() == QDeclarativeProperty::List);
    QVariant v = p2.read();
    QVERIFY(v.userType() == qMetaTypeId<QDeclarativeListReference>());
    QDeclarativeListReference ref = qvariant_cast<QDeclarativeListReference>(v);
    QVERIFY(ref.count() == 2);
    QVERIFY(ref.listElementType());
    QVERIFY(ref.listElementType() != &QObject::staticMetaObject);

    delete o;
}
Example #8
0
void
 DBusIf::signal(QString path, QString interface, QString method,
		QVariant v)
{
	QDBusMessage msg = QDBusMessage::createSignal(path, interface, method);

    // unbox the QVariant-QJSValue to fix the Qt 5.4 QML -> C++ QVariant issues
    if (v.userType() == qMetaTypeId<QJSValue>()) {
        v = v.value<QJSValue>().toVariant();
    }

	if (v.type() == QVariant::List) {
		QVariantList l = v.value < QVariantList > ();
		for (int i = 0; i < l.size(); i++) {
			msg << l[i]; }
	} else
		msg << v;
	QDBusConnection::sessionBus().send(msg);
#if 0
	qDebug() << v;
#endif
}
Example #9
0
bool Nuria::Serializer::readField (void *object, Nuria::MetaField &field, QVariantMap &data) {
	QVariant value = field.read (object);
	QString name = QString::fromLatin1 (field.name ());
	
	if (isAllowedType (value.userType ()) ||
	    this->d->additionalTypes.contains (field.typeName ())) {
		data.insert (name, value);
		return true;
	}
	
	bool ignore = false;
	if (fieldToVariant (value, ignore)) {
		
		if (!ignore) {
			data.insert (name, value);
		}
		
		return true;
	}
	
	return false;
}
Example #10
0
QVariantHash GeoIPDatabase::readMetadata() const
{
    const char *ptr = reinterpret_cast<const char *>(m_data);
    quint32 size = m_size;
    if (m_size > MAX_METADATA_SIZE) {
        ptr += m_size - MAX_METADATA_SIZE;
        size = MAX_METADATA_SIZE;
    }

    const QByteArray data = QByteArray::fromRawData(ptr, size);
    int index = data.lastIndexOf(METADATA_BEGIN_MARK);
    if (index >= 0) {
        if (m_size > MAX_METADATA_SIZE)
            index += (m_size - MAX_METADATA_SIZE); // from begin of all data
        quint32 offset = static_cast<quint32>(index + strlen(METADATA_BEGIN_MARK));
        QVariant metadata = readDataField(offset);
        if (metadata.userType() == QMetaType::QVariantHash)
            return metadata.toHash();
    }

    return QVariantHash();
}
Example #11
0
void tst_qqmllistreference::engineTypes()
{
    QQmlEngine engine;
    QQmlComponent component(&engine, testFileUrl("engineTypes.qml"));

    QObject *o = component.create();
    QVERIFY(o);

    QQmlProperty p1(o, QLatin1String("myList"));
    QVERIFY(p1.propertyTypeCategory() == QQmlProperty::List);

    QQmlProperty p2(o, QLatin1String("myList"), engine.rootContext());
    QVERIFY(p2.propertyTypeCategory() == QQmlProperty::List);
    QVariant v = p2.read();
    QVERIFY(v.userType() == qMetaTypeId<QQmlListReference>());
    QQmlListReference ref = qvariant_cast<QQmlListReference>(v);
    QVERIFY(ref.count() == 2);
    QVERIFY(ref.listElementType());
    QVERIFY(ref.listElementType() != &QObject::staticMetaObject);

    delete o;
}
Example #12
0
bool Grantlee::variantIsTrue( const QVariant &variant )
{

  if ( !variant.isValid() )
    return false;
  switch ( variant.userType() ) {
  case QVariant::Bool: {
    return variant.toBool();
  }
  case QVariant::Int: {
    return ( variant.toInt() > 0 );
  }
  case QVariant::Double: {
    return ( variant.toDouble() > 0 );
  }
  case QMetaType::Float: {
    return ( variant.toFloat() > 0 );
  }
  case QMetaType::QObjectStar: {
    QObject *obj = variant.value<QObject *>();
    if ( !obj )
      return false;

    if ( obj->property( "__true__" ).isValid() ) {
      return obj->property( "__true__" ).toBool();
    }
    return true;
  }
  case QVariant::List: {
    return ( variant.toList().size() > 0 );
  }
  case QVariant::Hash: {
    return ( variant.toHash().size() > 0 );
  }
  }

  return !getSafeString( variant ).get().isEmpty();
}
Example #13
0
bool QTestFunction::indexHasIncidents(const QModelIndex &function, IncidentType type)
{
    if (!function.isValid())
        return false;
    const QAbstractItemModel *m = function.model();
    if (!m->hasChildren(function))
        return false;

    const int rows = m->rowCount(function);
    for (int row = 0; row < rows; ++row) {
        const QModelIndex child = m->index(row, 0, function);

        QVariant tag = child.data(Qt::UserRole + 1);
        if (tag.type() != QVariant::UserType
            || tag.userType() != qMetaTypeId<QTestFunction::IncidentType>())
            continue;

        if (tag.value<QTestFunction::IncidentType>() == type)
            return true;
    }

    return false;
}
Example #14
0
QVariant ArgumentsEditor::valueForName(const QString &name,
                                       const QVariant &originalValue,
                                       bool *changed) const
{
    QVariant val;

    *changed = false;

    //Handle string arrays specially
    if (isVariantStringArray(originalValue)) {
        ApiArray array = originalValue.value<ApiArray>();
        return arrayFromEditor(array, changed);
    }

    if (!isVariantEditable(originalValue)) {
        return originalValue;
    }

    for (int topRow = 0; topRow < m_model->rowCount(); ++topRow) {
        QModelIndex nameIdx = m_model->index(topRow, 0, QModelIndex());
        QString argName = nameIdx.data().toString();
        /* we display shaders in a separate widget so
         * the ordering might be different */
        if (argName == name) {
            if (originalValue.userType() == QMetaType::type("ApiArray")) {
                ApiArray array = originalValue.value<ApiArray>();
                val = arrayFromIndex(nameIdx, array, changed);
            } else {
                QModelIndex valIdx = m_model->index(topRow, 1, QModelIndex());
                val = valIdx.data();
                if (val != originalValue)
                    *changed = true;
            }
        }
    }
    return val;
}
int MultiSortFilterProxy::Compare(const QVariant& left,
                                  const QVariant& right) const {
  // Copied from the QSortFilterProxyModel::lessThan implementation, but returns
  // -1, 0 or 1 instead of true or false.
  switch (left.userType()) {
    case QVariant::Invalid:
      return (right.type() != QVariant::Invalid) ? -1 : 0;
    case QVariant::Int:
      return DoCompare(left.toInt(), right.toInt());
    case QVariant::UInt:
      return DoCompare(left.toUInt(), right.toUInt());
    case QVariant::LongLong:
      return DoCompare(left.toLongLong(), right.toLongLong());
    case QVariant::ULongLong:
      return DoCompare(left.toULongLong(), right.toULongLong());
    case QMetaType::Float:
      return DoCompare(left.toFloat(), right.toFloat());
    case QVariant::Double:
      return DoCompare(left.toDouble(), right.toDouble());
    case QVariant::Char:
      return DoCompare(left.toChar(), right.toChar());
    case QVariant::Date:
      return DoCompare(left.toDate(), right.toDate());
    case QVariant::Time:
      return DoCompare(left.toTime(), right.toTime());
    case QVariant::DateTime:
      return DoCompare(left.toDateTime(), right.toDateTime());
    case QVariant::String:
    default:
      if (isSortLocaleAware())
        return left.toString().localeAwareCompare(right.toString());
      else
        return left.toString().compare(right.toString(), sortCaseSensitivity());
  }

  return 0;
}
Example #16
0
QByteArray CustomBindingParser::compile(const QList<QQmlCustomParserProperty> &properties)
{
    QByteArray result;
    QDataStream ds(&result, QIODevice::WriteOnly);

    ds << properties.count();
    for (int i = 0; i < properties.count(); ++i) {
        const QQmlCustomParserProperty &prop = properties.at(i);
        ds << prop.name();

        Q_ASSERT(prop.assignedValues().count() == 1);
        QVariant value = prop.assignedValues().first();

        Q_ASSERT(value.userType() == qMetaTypeId<QQmlScript::Variant>());
        QQmlScript::Variant v = qvariant_cast<QQmlScript::Variant>(value);
        Q_ASSERT(v.type() == QQmlScript::Variant::Script);
        int bindingId = bindingIdentifier(v, prop.name());
        ds << bindingId;

        ds << prop.location().line;
    }

    return result;
}
Example #17
0
    QString to_source_f<QVariant>::operator()( QVariant const & x ) const
    {
	switch( x.userType() )
	{
#define DO(VT,T) \
	    case QVariant::VT: \
		return qboard::toSource( x.value<T>() ); break;

	    DO(Int,int);
	    DO(Double,int);
	    DO(String,QString);
	    DO(Point,QPoint);
	    DO(PointF,QPointF);
	    DO(Rect,QRect);
	    DO(RectF,QRectF);
	    DO(Size,QSize);
	    DO(SizeF,QSizeF);
	    DO(Color,QColor);
	  default:
	      break;
#undef DO
	};
	return QString("undefined");
    }
Example #18
0
 QString format(const QVariant &t) {
     switch (t.userType()) {
     case QVariant::LongLong:
     case QVariant::ULongLong:
     case QVariant::Int:
     case QVariant::UInt:
         return format(t.toLongLong());
         break;
     case QVariant::String:
         return format(t.toString());
         break;
     case QVariant::Double:
         return format(t.toDouble());
         break;
     case QMetaType::Float:
         return format(t.toFloat());
     case QMetaType::Bool:
         return format(t.toBool());
     case QMetaType::QVariantMap:
         return format(t.toMap());
     default:
         throw std::exception();
     }
 }
bool ResultsTree::GroupSortProxyModel::QVariantCompare::operator() (QVariant l, QVariant r)
{
	// CODE COPIED FROM QSortFilterProxyModel::lessThan
	
	switch (l.userType()) {
		case QVariant::Invalid:
			return (r.type() != QVariant::Invalid);
		case QVariant::Int:
			return l.toInt() < r.toInt();
		case QVariant::UInt:
			return l.toUInt() < r.toUInt();
		case QVariant::LongLong:
			return l.toLongLong() < r.toLongLong();
		case QVariant::ULongLong:
			return l.toULongLong() < r.toULongLong();
		case QMetaType::Float:
			return l.toFloat() < r.toFloat();
		case QVariant::Double:
			return l.toDouble() < r.toDouble();
		case QVariant::Char:
			return l.toChar() < r.toChar();
		case QVariant::Date:
			return l.toDate() < r.toDate();
		case QVariant::Time:
			return l.toTime() < r.toTime();
		case QVariant::DateTime:
			return l.toDateTime() < r.toDateTime();
		case QVariant::String:
		default:
			//if (d->sort_localeaware)
				return l.toString().localeAwareCompare(r.toString()) < 0;
			/*else
				return l.toString().compare(r.toString(), d->sort_casesensitivity) < 0;*/
	}
	return false;
}
Example #20
0
bool QtVariantContext::isFalse(const QString& key) const
{
	QVariant value = this->value(key);
	switch (value.userType()) {
	case QMetaType::QChar:
	case QMetaType::Double:
	case QMetaType::Float:
	case QMetaType::Int:
	case QMetaType::UInt:
	case QMetaType::LongLong:
	case QMetaType::ULongLong:
	case QVariant::Bool:
		return !value.toBool();
	case QVariant::List:
	case QVariant::StringList:
		return value.toList().isEmpty();
	case QVariant::Hash:
		return value.toHash().isEmpty();
	case QVariant::Map:
		return value.toMap().isEmpty();
	default:
		return value.toString().isEmpty();
	}
}
Example #21
0
static bool
isVariantEditable(const QVariant &var)
{
    if (var.canConvert<ApiArray>()) {
        ApiArray array = var.value<ApiArray>();
        QVector<QVariant> vals = array.values();
        if (vals.isEmpty())
            return false;
        else
            return isVariantEditable(vals.first());
    }
    switch (var.userType()) {
    case QVariant::Bool:
    case QVariant::Int:
    case QVariant::UInt:
    case QVariant::LongLong:
    case QVariant::ULongLong:
    case QMetaType::Float:
    case QVariant::Double:
        return true;
    default:
        return false;
    }
}
Example #22
0
void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags)
{
    Q_D(QDeclarativeBinding);

    if (!d->enabled || !d->context() || !d->context()->isValid()) 
        return;

    if (!d->updating) {
        d->updating = true;
        bool wasDeleted = false;
        d->deleted = &wasDeleted;

        if (d->property.propertyType() == qMetaTypeId<QDeclarativeBinding *>()) {

            int idx = d->property.index();
            Q_ASSERT(idx != -1);

            QDeclarativeBinding *t = this;
            int status = -1;
            void *a[] = { &t, 0, &status, &flags };
            QMetaObject::metacall(d->property.object(),
                                  QMetaObject::WriteProperty,
                                  idx, a);

            if (wasDeleted)
                return;

        } else {
            QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(d->context()->engine);

            bool isUndefined = false;
            QVariant value;

            QScriptValue scriptValue = d->scriptValue(0, &isUndefined);
            if (wasDeleted)
                return;

            if (d->property.propertyTypeCategory() == QDeclarativeProperty::List) {
                value = ep->scriptValueToVariant(scriptValue, qMetaTypeId<QList<QObject *> >());
            } else if (scriptValue.isNull() && 
                       d->property.propertyTypeCategory() == QDeclarativeProperty::Object) {
                value = QVariant::fromValue((QObject *)0);
            } else {
                value = ep->scriptValueToVariant(scriptValue, d->property.propertyType());
                if (value.userType() == QMetaType::QObjectStar && !qvariant_cast<QObject*>(value)) {
                    // If the object is null, we extract the predicted type.  While this isn't
                    // 100% reliable, in many cases it gives us better error messages if we
                    // assign this null-object to an incompatible property
                    int type = ep->objectClass->objectType(scriptValue);
                    QObject *o = 0;
                    value = QVariant(type, (void *)&o);
                }
            }


            if (d->error.isValid()) {

            } else if (isUndefined && d->property.isResettable()) {

                d->property.reset();

            } else if (isUndefined && d->property.propertyType() == qMetaTypeId<QVariant>()) {

                QDeclarativePropertyPrivate::write(d->property, QVariant(), flags);

            } else if (isUndefined) {

                QUrl url = QUrl(d->url);
                int line = d->line;
                if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>"));

                d->error.setUrl(url);
                d->error.setLine(line);
                d->error.setColumn(-1);
                d->error.setDescription(QLatin1String("Unable to assign [undefined] to ") +
                                        QLatin1String(QMetaType::typeName(d->property.propertyType())) +
                                        QLatin1String(" ") + d->property.name());

            } else if (!scriptValue.isRegExp() && scriptValue.isFunction()) {

                QUrl url = QUrl(d->url);
                int line = d->line;
                if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>"));

                d->error.setUrl(url);
                d->error.setLine(line);
                d->error.setColumn(-1);
                d->error.setDescription(QLatin1String("Unable to assign a function to a property."));

            } else if (d->property.object() &&
                       !QDeclarativePropertyPrivate::write(d->property, value, flags)) {

                if (wasDeleted)
                    return;

                QUrl url = QUrl(d->url);
                int line = d->line;
                if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>"));

                const char *valueType = 0;
                if (value.userType() == QVariant::Invalid) valueType = "null";
                else valueType = QMetaType::typeName(value.userType());

                d->error.setUrl(url);
                d->error.setLine(line);
                d->error.setColumn(-1);
                d->error.setDescription(QLatin1String("Unable to assign ") +
                                        QLatin1String(valueType) +
                                        QLatin1String(" to ") +
                                        QLatin1String(QMetaType::typeName(d->property.propertyType())));
            }

            if (wasDeleted)
                return;

            if (d->error.isValid()) {
               if (!d->addError(ep)) ep->warning(this->error());
            } else {
                d->removeError();
            }
        }

        d->updating = false;
        d->deleted = 0;
    } else {
        qmlInfo(d->property.object()) << tr("Binding loop detected for property \"%1\"").arg(d->property.name());
    }
}
Example #23
0
void MainWindow::updatePropertyTable(int nodeID) {
    if(nodeID == -2)
        nodeID = Data::instance()->getFocusedID();
    QTableWidget *table = ui->tableWidget;
    if (nodeID >= 0 && Data::instance()->nodesInMesh()->contains(nodeID)) {
        deleteTable();
        oldfocus = nodeID;
        Node *n = Data::instance()->getNodeByID(nodeID);
        QMap<QString, Node::Parameter> *map = n->getParams();
        table->setRowCount(map->size() + 6);
        int i = 0;
        // create the entries all nodes have
        QTableWidgetItem *name = new QTableWidgetItem(),
                *ID = new QTableWidgetItem(),
                *type = new QTableWidgetItem(),
                *category = new QTableWidgetItem();

        // set the data
        ID->setData(0, nodeID);
        name->setData(0, n->getName());
        type->setData(0, n->getType());
        category->setData(0,n->getCategory());
        // asign to table:

        // NodeID
        table->setItem(i, 0, new QTableWidgetItem("NodeID"));
        table->setItem(i, 1, ID);
        table->item(i, 0)->setFlags(table->item(0, 0)->flags() ^
                                    (Qt::ItemIsEnabled | Qt::ItemIsSelectable));
        i++;

        // Node Class
        table->setItem(i, 0, new QTableWidgetItem("Node Class"));
        table->setItem(i, 1, type);
        table->item(i, 0)->setFlags(table->item(i, 0)->flags() ^
                                    (Qt::ItemIsEnabled | Qt::ItemIsSelectable));
        i++;

        //Node Category
        table->setItem(i, 0, new QTableWidgetItem("Node Category"));
        table->setItem(i, 1, category);
        table->item(i, 0)->setFlags(table->item(i, 0)->flags() ^
                                    (Qt::ItemIsEnabled | Qt::ItemIsSelectable));
        i++;


        // input Gates

        bool moreThanOne = n->getInputGates()->size() > 1;
        if (!n->getInputGates()->isEmpty()) {
            QString types;
            for (Gate *g : *n->getInputGates())
                for (QString s : g->getTypes()) types += s + ", ";
            types.chop(2);
            QTableWidgetItem *in = new QTableWidgetItem();
            in->setText(types);
            in->setFlags(in->flags() ^ (Qt::ItemIsEditable | Qt::ItemIsSelectable));
            table->setItem(i, 0, new QTableWidgetItem(
                               "Input" + QString((moreThanOne ? "s" : ""))));
            table->setItem(i, 1, in);
            table->item(i, 1)->setToolTip(types);
            i++;
        }

        // output gates
        moreThanOne = n->getOutputGates()->size() > 1;
        if (!n->getOutputGates()->isEmpty()) {
            QString types;
            for (Gate *g : *n->getOutputGates())
                for (QString s : g->getTypes()) types += s + ", ";
            types.chop(2);
            QTableWidgetItem *out = new QTableWidgetItem;
            out->setText(types);
            out->setFlags(out->flags() ^ (Qt::ItemIsEditable | Qt::ItemIsSelectable));
            table->setItem(i, 0, new QTableWidgetItem(
                               "Output" + QString((moreThanOne ? "s" : ""))));
            table->setItem(i, 1, out);
            table->item(i, 1)->setToolTip(types);
            i++;
        }
        table->setItem(i, 0, new QTableWidgetItem("Node Name"));
        table->setItem(i, 1, name);
        i++;

        // make name editable
        name->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable |
                       Qt::ItemIsSelectable);

        // avoid editing keys, and nodeID/type
        ID->setFlags(ID->flags() ^ (Qt::ItemIsEditable | Qt::ItemIsSelectable |
                                    Qt::ItemIsEnabled));
        type->setFlags(type->flags() ^ (Qt::ItemIsEditable | Qt::ItemIsSelectable |
                                        Qt::ItemIsEnabled));

        for (int j = 0; j < i; j++)
            table->item(j, 0)->setFlags(table->item(j, 0)->flags() ^
                                        (Qt::ItemIsEditable | Qt::ItemIsSelectable));
        QStringList keys = map->keys();
        int count = i;
        for (int j = 0; j < keys.size(); j++) {
            count++;
            // create key item
            QString key = keys.value(j);
            QTableWidgetItem *key_item = new QTableWidgetItem((*map)[key].name);
            key_item->setData(Qt::UserRole, key);
            key_item->setFlags(key_item->flags() ^
                               (Qt::ItemIsEditable | Qt::ItemIsSelectable));
            key_item->setToolTip((*map)[key].descr);
            table->setItem(i + j, 0, key_item);

            // create value item
            QVariant value = map->value(key).value;
            QTableWidgetItem *value_item = new QTableWidgetItem();
            value_item->setToolTip((*map)[key].descr);
            // QSpinBox *spinner;
            switch (value.userType()) {
            case QVariant::Bool:
                // value_item->setData(0, value);
                value_item->setCheckState(value.toBool() ? Qt::Checked
                                                         : Qt::Unchecked);
                table->setItem(i + j, 1, value_item);
                break;
            default:
                value_item->setData(Qt::UserRole, value);
                value_item->setText(value.toString());
                table->setItem(i + j, 1, value_item);
                if (key.contains("file")) {
                    connect(table, SIGNAL(cellDoubleClicked(int, int)), this,
                            SLOT(onFilebuttonClicked(int, int)));
                }
                break;
            }
        }
Example #24
0
bool QDeclarativePropertyPrivate::write(QObject *object, const QDeclarativePropertyCache::Data &property, 
                                            const QVariant &value, QDeclarativeContextData *context, 
                                            WriteFlags flags)
{
    int coreIdx = property.coreIndex;
    int status = -1;    //for dbus

    if (property.flags & QDeclarativePropertyCache::Data::IsEnumType) {
        QMetaProperty prop = object->metaObject()->property(property.coreIndex);
        QVariant v = value;
        // Enum values come through the script engine as doubles
        if (value.userType() == QVariant::Double) { 
            double integral;
            double fractional = modf(value.toDouble(), &integral);
            if (qFuzzyIsNull(fractional))
                v.convert(QVariant::Int);
        }
        return writeEnumProperty(prop, coreIdx, object, v, flags);
    }

    int propertyType = property.propType;
    int variantType = value.userType();

    QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(context);

    if (propertyType == QVariant::Url) {

        QUrl u;
        bool found = false;
        if (variantType == QVariant::Url) {
            u = value.toUrl();
            found = true;
        } else if (variantType == QVariant::ByteArray) {
            u = QUrl(QString::fromUtf8(value.toByteArray()));
            found = true;
        } else if (variantType == QVariant::String) {
            u = QUrl(value.toString());
            found = true;
        }

        if (!found)
            return false;

        if (context && u.isRelative() && !u.isEmpty())
            u = context->resolvedUrl(u);
        int status = -1;
        void *argv[] = { &u, 0, &status, &flags };
        QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, argv);

    } else if (variantType == propertyType) {

        void *a[] = { (void *)value.constData(), 0, &status, &flags };
        QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a);

    } else if (qMetaTypeId<QVariant>() == propertyType) {

        void *a[] = { (void *)&value, 0, &status, &flags };
        QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a);

    } else if (property.flags & QDeclarativePropertyCache::Data::IsQObjectDerived) {

        const QMetaObject *valMo = rawMetaObjectForType(enginePriv, value.userType());
        
        if (!valMo)
            return false;

        QObject *o = *(QObject **)value.constData();
        const QMetaObject *propMo = rawMetaObjectForType(enginePriv, propertyType);

        if (o) valMo = o->metaObject();

        if (canConvert(valMo, propMo)) {
            void *args[] = { &o, 0, &status, &flags };
            QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, 
                                  args);
        } else if (!o && canConvert(propMo, valMo)) {
            // In the case of a null QObject, we assign the null if there is 
            // any change that the null variant type could be up or down cast to 
            // the property type.
            void *args[] = { &o, 0, &status, &flags };
            QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, 
                                  args);
        } else {
            return false;
        }

    } else if (property.flags & QDeclarativePropertyCache::Data::IsQList) {

        const QMetaObject *listType = 0;
        if (enginePriv) {
            listType = enginePriv->rawMetaObjectForType(enginePriv->listType(property.propType));
        } else {
            QDeclarativeType *type = QDeclarativeMetaType::qmlType(QDeclarativeMetaType::listType(property.propType));
            if (!type) return false;
            listType = type->baseMetaObject();
        }
        if (!listType) return false;

        QDeclarativeListProperty<void> prop;
        void *args[] = { &prop, 0 };
        QMetaObject::metacall(object, QMetaObject::ReadProperty, coreIdx, args);

        if (!prop.clear) return false;

        prop.clear(&prop);

        if (value.userType() == qMetaTypeId<QList<QObject *> >()) {
            const QList<QObject *> &list = qvariant_cast<QList<QObject *> >(value);

            for (int ii = 0; ii < list.count(); ++ii) {
                QObject *o = list.at(ii);
                if (o && !canConvert(o->metaObject(), listType))
                    o = 0;
                prop.append(&prop, (void *)o);
            }
        } else {
            QObject *o = enginePriv?enginePriv->toQObject(value):QDeclarativeMetaType::toQObject(value);
            if (o && !canConvert(o->metaObject(), listType))
                o = 0;
            prop.append(&prop, (void *)o);
        }

    } else {
        Q_ASSERT(variantType != propertyType);

        QVariant v = value;
        if (v.convert((QVariant::Type)propertyType)) {
            void *a[] = { (void *)v.constData(), 0, &status, &flags};
            QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a);
        } else if ((uint)propertyType >= QVariant::UserType && variantType == QVariant::String) {
            QDeclarativeMetaType::StringConverter con = QDeclarativeMetaType::customStringConverter(propertyType);
            if (!con)
                return false;

            QVariant v = con(value.toString());
            if (v.userType() == propertyType) {
                void *a[] = { (void *)v.constData(), 0, &status, &flags};
                QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a);
            }
        } else if (variantType == QVariant::String) {
            bool ok = false;
            QVariant v = QDeclarativeStringConverters::variantFromString(value.toString(), propertyType, &ok);
            if (!ok)
                return false;

            void *a[] = { (void *)v.constData(), 0, &status, &flags};
            QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a);
        } else {
            return false;
        }
    }

    return true;
}
Example #25
0
static QString variantToTextValue(const QVariant &value, const QString &typeNs, const QString &type)
{
    switch (value.userType()) {
    case QVariant::Char:
    // fall-through
    case QVariant::String:
        return value.toString();
    case QVariant::Url:
        // xmlpatterns/data/qatomicvalue.cpp says to do this:
        return value.toUrl().toString();
    case QVariant::ByteArray: {
        const QByteArray data = value.toByteArray();
        if (typeNs == KDSoapNamespaceManager::xmlSchema1999() || typeNs == KDSoapNamespaceManager::xmlSchema2001()) {
            if (type == QLatin1String("hexBinary")) {
                const QByteArray hb = data.toHex();
                return QString::fromLatin1(hb.constData(), hb.size());
            }
        }
        // default to base64Binary, like variantToXMLType() does.
        const QByteArray b64 = value.toByteArray().toBase64();
        return QString::fromLatin1(b64.constData(), b64.size());
    }
    case QVariant::Int:
    // fall-through
    case QVariant::LongLong:
    // fall-through
    case QVariant::UInt:
        return QString::number(value.toLongLong());
    case QVariant::ULongLong:
        return QString::number(value.toULongLong());
    case QVariant::Bool:
    case QMetaType::Float:
    case QVariant::Double:
        return value.toString();
    case QVariant::Time: {
        const QTime time = value.toTime();
        if (time.msec()) {
            // include milli-seconds
            return time.toString(QLatin1String("hh:mm:ss.zzz"));
        } else {
            return time.toString(Qt::ISODate);
        }
    }
    case QVariant::Date:
        return value.toDate().toString(Qt::ISODate);
    case QVariant::DateTime: // http://www.w3.org/TR/xmlschema-2/#dateTime
        return KDDateTime(value.toDateTime()).toDateString();
    case QVariant::Invalid:
        qDebug() << "ERROR: Got invalid QVariant in a KDSoapValue";
        return QString();
    default:
        if (value.canConvert<KDDateTime>()) {
            return value.value<KDDateTime>().toDateString();
        }

        if (value.userType() == qMetaTypeId<float>()) {
            return QString::number(value.value<float>());
        }

        qDebug() << QString::fromLatin1("QVariants of type %1 are not supported in "
                                        "KDSoap, see the documentation").arg(QLatin1String(value.typeName()));
        return value.toString();
    }
}
/*!
    \qmlmethod QtLocation::Map::fitViewportToGeoShape(QGeoShape shape)

    Fits the current viewport to the boundary of the shape. The camera is positioned
    in the center of the shape, and at the largest integral zoom level possible which
    allows the whole shape to be visible on screen

*/
void QDeclarativeGeoMap::fitViewportToGeoShape(const QVariant &variantShape)
{
    if (!map_ || !mappingManagerInitialized_)
        return;

    QGeoShape shape;

    if (variantShape.userType() == qMetaTypeId<QGeoRectangle>())
        shape = variantShape.value<QGeoRectangle>();
    else if (variantShape.userType() == qMetaTypeId<QGeoCircle>())
        shape = variantShape.value<QGeoCircle>();
    else if (variantShape.userType() == qMetaTypeId<QGeoShape>())
        shape = variantShape.value<QGeoShape>();

    if (!shape.isValid())
        return;

    double bboxWidth;
    double bboxHeight;
    QGeoCoordinate centerCoordinate;

    switch (shape.type()) {
    case QGeoShape::RectangleType:
    {
        QGeoRectangle rect = shape;
        QDoubleVector2D topLeftPoint = map_->coordinateToScreenPosition(rect.topLeft(), false);
        QDoubleVector2D botRightPoint = map_->coordinateToScreenPosition(rect.bottomRight(), false);
        bboxWidth = qAbs(topLeftPoint.x() - botRightPoint.x());
        bboxHeight = qAbs(topLeftPoint.y() - botRightPoint.y());
        centerCoordinate = rect.center();
        break;
    }
    case QGeoShape::CircleType:
    {
        QGeoCircle circle = shape;
        centerCoordinate = circle.center();
        QGeoCoordinate edge = centerCoordinate.atDistanceAndAzimuth(circle.radius(), 90);
        QDoubleVector2D centerPoint = map_->coordinateToScreenPosition(centerCoordinate, false);
        QDoubleVector2D edgePoint = map_->coordinateToScreenPosition(edge, false);
        bboxWidth = qAbs(centerPoint.x() - edgePoint.x()) * 2;
        bboxHeight = bboxWidth;
        break;
    }
    case QGeoShape::UnknownType:
        //Fallthrough to default
    default:
        return;
    }

    // position camera to the center of bounding box
    setProperty("center", QVariant::fromValue(centerCoordinate));

    //If the shape is empty we just change centerposition, not zoom
    if (bboxHeight == 0 && bboxWidth == 0)
        return;

    // adjust zoom
    double bboxWidthRatio = bboxWidth / (bboxWidth + bboxHeight);
    double mapWidthRatio = width() / (width() + height());
    double zoomRatio;

    if (bboxWidthRatio > mapWidthRatio)
        zoomRatio = bboxWidth / width();
    else
        zoomRatio = bboxHeight / height();

    qreal newZoom = log10(zoomRatio) / log10(0.5);
    newZoom = floor(qMax(minimumZoomLevel(), (map_->mapController()->zoom() + newZoom)));
    setProperty("zoomLevel", QVariant::fromValue(newZoom));
}
Example #27
0
/*!
    \internal
    convert \a value to \a type, store the result in \a ptr
*/
bool QJSEngine::convertV2(const QJSValue &value, int type, void *ptr)
{
    QV4::ExecutionEngine *v4 = QJSValuePrivate::engine(&value);
    QV4::Value scratch;
    QV4::Value *val = QJSValuePrivate::valueForData(&value, &scratch);
    if (v4) {
        QV4::Scope scope(v4);
        QV4::ScopedValue v(scope, *val);
        return scope.engine->metaTypeFromJS(v, type, ptr);
    }

    if (!val) {
        QVariant *variant = QJSValuePrivate::getVariant(&value);
        Q_ASSERT(variant);

        if (variant->userType() == QMetaType::QString) {
            QString string = variant->toString();
            // have a string based value without engine. Do conversion manually
            if (type == QMetaType::Bool) {
                *reinterpret_cast<bool*>(ptr) = string.length() != 0;
                return true;
            }
            if (type == QMetaType::QString) {
                *reinterpret_cast<QString*>(ptr) = string;
                return true;
            }
            double d = QV4::RuntimeHelpers::stringToNumber(string);
            switch (type) {
            case QMetaType::Int:
                *reinterpret_cast<int*>(ptr) = QV4::Primitive::toInt32(d);
                return true;
            case QMetaType::UInt:
                *reinterpret_cast<uint*>(ptr) = QV4::Primitive::toUInt32(d);
                return true;
            case QMetaType::LongLong:
                *reinterpret_cast<qlonglong*>(ptr) = QV4::Primitive::toInteger(d);
                return true;
            case QMetaType::ULongLong:
                *reinterpret_cast<qulonglong*>(ptr) = QV4::Primitive::toInteger(d);
                return true;
            case QMetaType::Double:
                *reinterpret_cast<double*>(ptr) = d;
                return true;
            case QMetaType::Float:
                *reinterpret_cast<float*>(ptr) = d;
                return true;
            case QMetaType::Short:
                *reinterpret_cast<short*>(ptr) = QV4::Primitive::toInt32(d);
                return true;
            case QMetaType::UShort:
                *reinterpret_cast<unsigned short*>(ptr) = QV4::Primitive::toUInt32(d);
                return true;
            case QMetaType::Char:
                *reinterpret_cast<char*>(ptr) = QV4::Primitive::toInt32(d);
                return true;
            case QMetaType::UChar:
                *reinterpret_cast<unsigned char*>(ptr) = QV4::Primitive::toUInt32(d);
                return true;
            case QMetaType::QChar:
                *reinterpret_cast<QChar*>(ptr) = QV4::Primitive::toUInt32(d);
                return true;
            default:
                return false;
            }
        } else {
            return QMetaType::convert(&variant->data_ptr(), variant->userType(), ptr, type);
        }
    }

    Q_ASSERT(val);

    switch (type) {
        case QMetaType::Bool:
            *reinterpret_cast<bool*>(ptr) = val->toBoolean();
            return true;
        case QMetaType::Int:
            *reinterpret_cast<int*>(ptr) = val->toInt32();
            return true;
        case QMetaType::UInt:
            *reinterpret_cast<uint*>(ptr) = val->toUInt32();
            return true;
        case QMetaType::LongLong:
            *reinterpret_cast<qlonglong*>(ptr) = val->toInteger();
            return true;
        case QMetaType::ULongLong:
            *reinterpret_cast<qulonglong*>(ptr) = val->toInteger();
            return true;
        case QMetaType::Double:
            *reinterpret_cast<double*>(ptr) = val->toNumber();
            return true;
        case QMetaType::QString:
            *reinterpret_cast<QString*>(ptr) = val->toQStringNoThrow();
            return true;
        case QMetaType::Float:
            *reinterpret_cast<float*>(ptr) = val->toNumber();
            return true;
        case QMetaType::Short:
            *reinterpret_cast<short*>(ptr) = val->toInt32();
            return true;
        case QMetaType::UShort:
            *reinterpret_cast<unsigned short*>(ptr) = val->toUInt16();
            return true;
        case QMetaType::Char:
            *reinterpret_cast<char*>(ptr) = val->toInt32();
            return true;
        case QMetaType::UChar:
            *reinterpret_cast<unsigned char*>(ptr) = val->toUInt16();
            return true;
        case QMetaType::QChar:
            *reinterpret_cast<QChar*>(ptr) = val->toUInt16();
            return true;
        default:
            return false;
    }
}
Example #28
0
void QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, QVariant &where) const
{
    if (!isValid || !canMakeCalls()) {   // can't make calls
        where.clear();
        return;
    }

    // is this metatype registered?
    const char *expectedSignature = "";
    if (mp.type() != 0xff) {
        expectedSignature = QDBusMetaType::typeToSignature(where.userType());
        if (expectedSignature == 0) {
            qWarning("QDBusAbstractInterface: type %s must be registered with QtDBus before it can be "
                     "used to read property %s.%s",
                     mp.typeName(), qPrintable(interface), mp.name());
            lastError = QDBusError(QDBusError::Failed,
                                   QString::fromLatin1("Unregistered type %1 cannot be handled")
                                   .arg(QLatin1String(mp.typeName())));
            where.clear();
            return;
        }
    }

    // try to read this property
    QDBusMessage msg = QDBusMessage::createMethodCall(service, path,
                                                      QLatin1String(DBUS_INTERFACE_PROPERTIES),
                                                      QLatin1String("Get"));
    QDBusMessagePrivate::setParametersValidated(msg, true);
    msg << interface << QString::fromUtf8(mp.name());
    QDBusMessage reply = connection.call(msg, QDBus::Block);

    if (reply.type() != QDBusMessage::ReplyMessage) {
        lastError = reply;
        where.clear();
        return;
    }
    if (reply.signature() != QLatin1String("v")) {
        QString errmsg = QLatin1String("Invalid signature `%1' in return from call to "
                                       DBUS_INTERFACE_PROPERTIES);
        lastError = QDBusError(QDBusError::InvalidSignature, errmsg.arg(reply.signature()));
        where.clear();
        return;
    }

    QByteArray foundSignature;
    const char *foundType = 0;
    QVariant value = qvariant_cast<QDBusVariant>(reply.arguments().at(0)).variant();

    if (value.userType() == where.userType() || mp.type() == 0xff
        || (expectedSignature[0] == 'v' && expectedSignature[1] == '\0')) {
        // simple match
        where = value;
        return;
    }

    if (value.userType() == qMetaTypeId<QDBusArgument>()) {
        QDBusArgument arg = qvariant_cast<QDBusArgument>(value);

        foundType = "user type";
        foundSignature = arg.currentSignature().toLatin1();
        if (foundSignature == expectedSignature) {
            // signatures match, we can demarshall
            QDBusMetaType::demarshall(arg, where.userType(), where.data());
            return;
        }
    } else {
        foundType = value.typeName();
        foundSignature = QDBusMetaType::typeToSignature(value.userType());
    }

    // there was an error...
    QString errmsg = QLatin1String("Unexpected `%1' (%2) when retrieving property `%3.%4' "
                                   "(expected type `%5' (%6))");
    lastError = QDBusError(QDBusError::InvalidSignature,
                           errmsg.arg(QString::fromLatin1(foundType),
                                      QString::fromLatin1(foundSignature),
                                      interface,
                                      QString::fromUtf8(mp.name()),
                                      QString::fromLatin1(mp.typeName()),
                                      QString::fromLatin1(expectedSignature)));
    where.clear();
    return;
}
Example #29
0
QT_BEGIN_NAMESPACE

static void copyArgument(void *to, int id, const QVariant &arg)
{
    if (id == arg.userType()) {
        switch (id) {
        case QVariant::Bool:
            *reinterpret_cast<bool *>(to) = arg.toBool();
            return;

        case QMetaType::UChar:
            *reinterpret_cast<uchar *>(to) = arg.value<uchar>();
            return;

        case QMetaType::Short:
            *reinterpret_cast<short *>(to) = arg.value<short>();
            return;

        case QMetaType::UShort:
            *reinterpret_cast<ushort *>(to) = arg.value<ushort>();
            return;

        case QVariant::Int:
            *reinterpret_cast<int *>(to) = arg.toInt();
            return;

        case QVariant::UInt:
            *reinterpret_cast<uint *>(to) = arg.toUInt();
            return;

        case QVariant::LongLong:
            *reinterpret_cast<qlonglong *>(to) = arg.toLongLong();
            return;

        case QVariant::ULongLong:
            *reinterpret_cast<qulonglong *>(to) = arg.toULongLong();
            return;

        case QVariant::Double:
            *reinterpret_cast<double *>(to) = arg.toDouble();
            return;

        case QVariant::String:
            *reinterpret_cast<QString *>(to) = arg.toString();
            return;

        case QVariant::ByteArray:
            *reinterpret_cast<QByteArray *>(to) = arg.toByteArray();
            return;

        case QVariant::StringList:
            *reinterpret_cast<QStringList *>(to) = arg.toStringList();
            return;
        }

        if (id == QDBusMetaTypeId::variant) {
            *reinterpret_cast<QDBusVariant *>(to) = arg.value<QDBusVariant>();
            return;
        } else if (id == QDBusMetaTypeId::objectpath) {
            *reinterpret_cast<QDBusObjectPath *>(to) = arg.value<QDBusObjectPath>();
            return;
        } else if (id == QDBusMetaTypeId::signature) {
            *reinterpret_cast<QDBusSignature *>(to) = arg.value<QDBusSignature>();
            return;
        }

        // those above are the only types possible
        // the demarshaller code doesn't demarshall anything else
        qFatal("Found a decoded basic type in a D-Bus reply that shouldn't be there");
    }

    // if we got here, it's either an un-dermarshalled type or a mismatch
    if (arg.userType() != QDBusMetaTypeId::argument) {
        // it's a mismatch
        //qWarning?
        return;
    }

    // is this type registered?
    const char *userSignature = QDBusMetaType::typeToSignature(id);
    if (!userSignature || !*userSignature) {
        // type not registered
        //qWarning?
        return;
    }

    // is it the same signature?
    QDBusArgument dbarg = arg.value<QDBusArgument>();
    if (dbarg.currentSignature() != QLatin1String(userSignature)) {
        // not the same signature, another mismatch
        //qWarning?
        return;
    }

    // we can demarshall
    QDBusMetaType::demarshall(dbarg, id, to);
}
QVariant QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp) const
{
    if (!connection.isConnected())    // not connected
        return QVariant();

    // is this metatype registered?
    int mid;
    const char *expectedSignature;
    if (mp.type() == QVariant::LastType) {
        // We're asking to read a QVariant
        mid = qMetaTypeId<QDBusVariant>();
        expectedSignature = "v";
    } else {
        mid = QMetaType::type(mp.typeName());
        expectedSignature = QDBusMetaType::typeToSignature(mid);
        if (expectedSignature == 0) {
            qWarning("QDBusAbstractInterface: type %s must be registered with QtDBus before it can be "
                     "used to read property %s.%s",
                     mp.typeName(), qPrintable(interface), mp.name());
            return QVariant();
        }
    }

    // try to read this property
    QDBusMessage msg = QDBusMessage::createMethodCall(service, path,
                                                      QLatin1String(DBUS_INTERFACE_PROPERTIES),
                                                      QLatin1String("Get"));
    msg << interface << QString::fromUtf8(mp.name());
    QDBusMessage reply = connection.call(msg, QDBus::Block);

    if (reply.type() != QDBusMessage::ReplyMessage) {
        lastError = reply;
        return QVariant();
    }
    if (reply.signature() != QLatin1String("v")) {
        QString errmsg = QLatin1String("Invalid signature `%1' in return from call to "
                                       DBUS_INTERFACE_PROPERTIES);
        lastError = QDBusError(QDBusError::InvalidSignature, errmsg.arg(reply.signature()));
        return QVariant();
    }

    QByteArray foundSignature;
    const char *foundType = 0;
    QVariant value = qvariant_cast<QDBusVariant>(reply.arguments().at(0)).variant();

    if (value.userType() == mid)
        return value;       // simple match

    if (value.userType() == qMetaTypeId<QDBusArgument>()) {
        QDBusArgument arg = qvariant_cast<QDBusArgument>(value);

        foundType = "user type";
        foundSignature = arg.currentSignature().toLatin1();
        if (foundSignature == expectedSignature) {
            void *null = 0;
            QVariant result(mid, null);
            QDBusMetaType::demarshall(arg, mid, result.data());

            if (mp.type() == QVariant::LastType)
                // special case: QVariant
                return qvariant_cast<QDBusVariant>(result).variant();
            return result;
        }
    } else {
        foundType = value.typeName();
        foundSignature = QDBusMetaType::typeToSignature(value.userType());
    }

    // there was an error...
    QString errmsg = QLatin1String("Unexpected `%1' (%2) when retrieving property `%3.%4' "
                                   "(expected type `%5' (%6))");
    lastError = QDBusError(QDBusError::InvalidSignature,
                           errmsg.arg(QString::fromLatin1(foundType),
                                      QString::fromLatin1(foundSignature),
                                      interface,
                                      QString::fromUtf8(mp.name()),
                                      QString::fromLatin1(mp.typeName()),
                                      QString::fromLatin1(expectedSignature)));
    return QVariant();
}