InformationName NodeInstance::setInformation(InformationName name, const QVariant &information, const QVariant &secondInformation, const QVariant &thirdInformation) { switch (name) { case Size: return setInformationSize(information.toSizeF()); case BoundingRect: return setInformationBoundingRect(information.toRectF()); case ContentItemBoundingRect: return setInformationContentItemBoundingRect(information.toRectF()); case Transform: return setInformationTransform(information.value<QTransform>()); case ContentTransform: return setInformationContentTransform(information.value<QTransform>()); case ContentItemTransform: return setInformationContentItemTransform(information.value<QTransform>()); case PenWidth: return setInformationPenWith(information.toInt()); case Position: return setInformationPosition(information.toPointF()); case IsInLayoutable: return setInformationIsInLayoutable(information.toBool()); case SceneTransform: return setInformationSceneTransform(information.value<QTransform>()); case IsResizable: return setInformationIsResizable(information.toBool()); case IsMovable: return setInformationIsMovable(information.toBool()); case IsAnchoredByChildren: return setInformationIsAnchoredByChildren(information.toBool()); case IsAnchoredBySibling: return setInformationIsAnchoredBySibling(information.toBool()); case HasContent: return setInformationHasContent(information.toBool()); case HasAnchor: return setInformationHasAnchor(information.toByteArray(), secondInformation.toBool());break; case Anchor: return setInformationAnchor(information.toByteArray(), secondInformation.toByteArray(), thirdInformation.value<qint32>()); case InstanceTypeForProperty: return setInformationInstanceTypeForProperty(information.toByteArray(), secondInformation.toByteArray()); case HasBindingForProperty: return setInformationHasBindingForProperty(information.toByteArray(), secondInformation.toBool()); case NoName: default: break; } return NoInformationChange; }
bool ImageSortSettings::lessThan(const QVariant& left, const QVariant& right) const { if (left.type() != right.type()) { return false; } switch (left.type()) { case QVariant::Int: return compareByOrder(left.toInt(), right.toInt(), currentSortOrder); case QVariant::UInt: return compareByOrder(left.toUInt(), right.toUInt(), currentSortOrder); case QVariant::LongLong: return compareByOrder(left.toLongLong(), right.toLongLong(), currentSortOrder); case QVariant::ULongLong: return compareByOrder(left.toULongLong(), right.toULongLong(), currentSortOrder); case QVariant::Double: return compareByOrder(left.toDouble(), right.toDouble(), currentSortOrder); case QVariant::Date: return compareByOrder(left.toDate(), right.toDate(), currentSortOrder); case QVariant::DateTime: return compareByOrder(left.toDateTime(), right.toDateTime(), currentSortOrder); case QVariant::Time: return compareByOrder(left.toTime(), right.toTime(), currentSortOrder); case QVariant::Rect: case QVariant::RectF: { QRectF rectLeft = left.toRectF(); QRectF rectRight = right.toRectF(); int result; if ((result = compareByOrder(rectLeft.top(), rectRight.top(), currentSortOrder)) != 0) { return result < 0; } if ((result = compareByOrder(rectLeft.left(), rectRight.left(), currentSortOrder)) != 0) { return result < 0; } QSizeF sizeLeft = rectLeft.size(), sizeRight = rectRight.size(); if ((result = compareByOrder(sizeLeft.width()*sizeLeft.height(), sizeRight.width()*sizeRight.height(), currentSortOrder)) != 0) { return result < 0; } // FIXME: fall through?? If not, add "break" here } default: return naturalCompare(left.toString(), right.toString(), currentSortOrder, sortCaseSensitivity); } }
/*! \internal Reimplemented from QGraphicsItemPrivate. ### Qt 5: Move impl to reimplementation QGraphicsProxyWidget::inputMethodQuery(). */ QVariant QGraphicsProxyWidgetPrivate::inputMethodQueryHelper(Qt::InputMethodQuery query) const { Q_Q(const QGraphicsProxyWidget); if (!widget || !q->hasFocus()) return QVariant(); QWidget *focusWidget = widget->focusWidget(); if (!focusWidget) focusWidget = widget; QVariant v = focusWidget->inputMethodQuery(query); QPointF focusWidgetPos = q->subWidgetRect(focusWidget).topLeft(); switch (v.type()) { case QVariant::RectF: v = v.toRectF().translated(focusWidgetPos); break; case QVariant::PointF: v = v.toPointF() + focusWidgetPos; break; case QVariant::Rect: v = v.toRect().translated(focusWidgetPos.toPoint()); break; case QVariant::Point: v = v.toPoint() + focusWidgetPos.toPoint(); break; default: break; } return v; }
void MDeclarativeScreenPrivate::_q_checkMicroFocusHint() { if (!sipVisible) return; if (QWidget *widget = QApplication::focusWidget()) { QVariant v = widget->inputMethodQuery(Qt::ImMicroFocus); if (!v.toRectF().isValid()) return; QRectF mf = v.toRectF(); if (mf != microFocus) { microFocus = mf; fprintf(stderr, "microfocus changed %f %f %f/%f\n", mf.x(), mf.y(), mf.width(), mf.height()); emit q->microFocusChanged(); } } }
QString write(const QVariant &variant) { if (!variant.isValid()) { qWarning() << "Trying to serialize invalid QVariant"; return QString(); } QString value; switch (variant.type()) { case QMetaType::QPoint: { QPoint p = variant.toPoint(); value = QString("%1,%2").arg(QString::number(p.x()), QString::number(p.y())); break; } case QMetaType::QPointF: { QPointF p = variant.toPointF(); value = QString("%1,%2").arg(QString::number(p.x(), 'f'), QString::number(p.y(), 'f')); break; } case QMetaType::QSize: { QSize s = variant.toSize(); value = QString("%1x%2").arg(QString::number(s.width()), QString::number(s.height())); break; } case QMetaType::QSizeF: { QSizeF s = variant.toSizeF(); value = QString("%1x%2").arg(QString::number(s.width(), 'f'), QString::number(s.height(), 'f')); break; } case QMetaType::QRect: { QRect r = variant.toRect(); value = QString("%1,%2,%3x%4").arg(QString::number(r.x()), QString::number(r.y()), QString::number(r.width()), QString::number(r.height())); break; } case QMetaType::QRectF: { QRectF r = variant.toRectF(); value = QString("%1,%2,%3x%4").arg(QString::number(r.x(), 'f'), QString::number(r.y(), 'f'), QString::number(r.width(), 'f'), QString::number(r.height(), 'f')); break; } default: QVariant strVariant = variant; strVariant.convert(QVariant::String); if (!strVariant.isValid()) qWarning() << Q_FUNC_INFO << "cannot serialize type " << QMetaType::typeName(variant.type()); value = strVariant.toString(); } return value; }
void QtViewportHandler::scaleAnimationValueChanged(QVariant value) { // Resetting the end value, the easing curve or the duration of the scale animation // triggers a recalculation of the animation interval. This might change the current // value of the animated property. // Make sure we only act on animation value changes if the animation is active. if (!scaleAnimationActive()) return; setPageItemRectVisible(value.toRectF()); }
QRectF IrcAbstractChannel::cookedBoundingRect () const { if (qmlItem) { QVariant rectVar; QMetaObject::invokeMethod (qmlItem, "cookedBoundingRect", Q_RETURN_ARG (QVariant, rectVar)); QRectF br = rectVar.toRectF(); return br; } return QRectF (); }
bool QAbstractDiagramGraphicsItem::changeProperty(const QString & name, const QVariant & value) { QDiagramMetaProperty metaProperty = m_metadata->property(m_metadata->indexOfProperty(name)); // Check if property is dynamic if (!metaProperty.isValid()){ // Check if dynamic property has changed if (m_dynamicProperties.value(name) != value){ m_dynamicProperties[name] = value; itemPropertyHasChanged(name, value); } return false; } // Check if static property is read only if (metaProperty.isReadOnly()){ // Property is read only return false; } QVariant currentValue = m_properties.value(name); if (currentValue != value){ if (name == "brush"){ m_brush = brush(value.toString()); } else if (name == "geometry"){ if (value.canConvert(QVariant::RectF)){ prepareGeometryChange(); setPos(value.toRectF().x(), value.toRectF().y()); } else if (value.canConvert(QVariant::Map)){ prepareGeometryChange(); setPos(value.toMap().value("x").toDouble(), value.toMap().value("y").toDouble()); } m_properties[name] = value; itemGeometryHasChanged(value); } else { m_properties[name] = value; } itemPropertyHasChanged(name, value); } return true; }
void PageViewportControllerClientQt::ScaleAnimation::updateCurrentValue(const QVariant& value) { // Resetting the end value, the easing curve or the duration of the scale animation // triggers a recalculation of the animation interval. This might change the current // value of the animated property. // Make sure we only act on animation value changes if the animation is active. if (!m_controllerClient->scaleAnimationActive()) return; QRectF itemRect = value.toRectF(); float itemScale = m_controllerClient->viewportScaleForRect(itemRect); m_controllerClient->setContentRectVisiblePositionAtScale(itemRect.topLeft(), itemScale); }
int Slot::setVariant( PyrSlot *slot, const QVariant &val ) { bool b_val; int type = val.userType(); switch( type ) { case QMetaType::Bool: b_val = val.toBool(); if( b_val ) SetTrue( slot ); else SetFalse( slot ); return errNone; case QMetaType::QPoint: case QMetaType::QPointF: return Slot::setPoint( slot, val.toPointF() ); case QMetaType::QRect: case QMetaType::QRectF: return Slot::setRect( slot, val.toRectF() ); case QMetaType::QString: Slot::setString( slot, val.toString() ); return errNone; case QMetaType::QColor: return Slot::setColor( slot, val.value<QColor>() ); case QMetaType::QPalette: return Slot::setPalette( slot, val.value<QPalette>() ); case QMetaType::Float: case QMetaType::Double: SetFloat( slot, val.value<float>() ); return errNone; case QMetaType::Int: SetInt( slot, val.toInt() ); return errNone; case QMetaType::Void: SetNil( slot ); return errNone; default: if( type == qMetaTypeId<VariantList>() ) { Slot::setVariantList( slot, val.value<VariantList>() ); } else { qcErrorMsg( "the QVariant could not be interpreted!" ); return errFailed; } return errNone; } }
void tvalue2json(rapidjson::Value & output, const QVariant & input, rapidjson::Value::AllocatorType & allocator) { switch(input.type()) { case QVariant::Invalid: { output.SetNull(); break; } case QVariant::Bool: { output.SetBool(input.toBool()); break; } case QVariant::Int: { output.SetInt64(input.toInt()); break; } case QVariant::LongLong: { output.SetInt64(input.toLongLong()); break; } case QVariant::Double: { output.SetDouble(input.toDouble()); break; } case QVariant::String: { QByteArray str = input.toString().toUtf8(); output.SetString(str.data(), str.size(), allocator); break; } case QVariant::StringList: { QStringList list = input.toStringList(); output.SetArray(); output.Reserve(list.size(), allocator); rapidjson::Value temp; for(QStringList::const_iterator it = list.begin(); it != list.end(); ++it) { QByteArray str = it->toUtf8(); temp.SetString(str.data(), str.size(), allocator); output.PushBack(temp, allocator); } break; } case QVariant::List: { QList<QVariant> list = input.toList(); output.SetArray(); output.Reserve(list.size(), allocator); rapidjson::Value temp; for(QList<QVariant>::const_iterator it = list.begin(); it != list.end(); ++it) { tvalue2json(temp, *it, allocator); output.PushBack(temp, allocator); } break; } case QVariant::Map: { output.SetObject(); rapidjson::Value tempK, tempV; QMap<QString, QVariant> qmap = input.toMap(); for(QMap<QString, QVariant>::const_iterator it = qmap.begin(); it != qmap.end(); ++it) { tvalue2json(tempK, it.key(), allocator); tvalue2json(tempV, it.value(), allocator); output.AddMember(tempK, tempV, allocator); } break; } case QVariant::Point: { QPoint pt = input.toPoint(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); break; } case QVariant::PointF: { QPointF pt = input.toPointF(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); break; } case QVariant::Size: { QSize pt = input.toSize(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.width(), allocator); output.PushBack(pt.height(), allocator); break; } case QVariant::SizeF: { QSizeF pt = input.toSizeF(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.width(), allocator); output.PushBack(pt.height(), allocator); break; } case QVariant::Rect: { QRect pt = input.toRect(); output.SetArray(); output.Reserve(4, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); output.PushBack(pt.width(), allocator); output.PushBack(pt.height(), allocator); break; } case QVariant::RectF: { QRectF pt = input.toRectF(); output.SetArray(); output.Reserve(4, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); output.PushBack(pt.width(), allocator); output.PushBack(pt.height(), allocator); break; } case QVariant::Vector2D: { QVector2D pt = input.value<QVector2D>(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); break; } case QVariant::Vector3D: { QVector3D pt = input.value<QVector3D>(); output.SetArray(); output.Reserve(3, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); output.PushBack(pt.z(), allocator); break; } case QVariant::Vector4D: { QVector4D pt = input.value<QVector4D>(); output.SetArray(); output.Reserve(4, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); output.PushBack(pt.z(), allocator); output.PushBack(pt.w(), allocator); break; } case QVariant::Color: { QColor pt = input.value<QColor>(); output.SetArray(); output.Reserve(4, allocator); output.PushBack(pt.red(), allocator); output.PushBack(pt.green(), allocator); output.PushBack(pt.blue(), allocator); output.PushBack(pt.alpha(), allocator); break; } default: { output.SetNull(); assert(false && "shuldn't execute to here."); } } }
bool GCF::Message::encodeVariant(QDataStream& ds, const QVariant& value) { QString typeName; if( value.isValid() ) { typeName = QString(value.typeName()); if( typeName.isEmpty() ) return false; } else typeName = "Invalid"; if( value.type() >= QVariant::UserType ) return false; // Prepare the typename in-case of bool, char, int, double switch(value.type()) { case QVariant::Int: typeName = is32Bit() ? "qint32" : "qint64"; break; case QVariant::Char: typeName = "quint8"; break; case QVariant::UInt: typeName = is32Bit() ? "quint32" : "quint64"; break; default: break; } // Serialize value on to the byte array switch( value.type() ) { case QVariant::Invalid: ds << typeName; ds << qint32(0); break; case QVariant::Bool: ds << typeName; ds << value.toBool(); break; case QVariant::Char: ds << typeName; ds << value.toChar(); break; case QVariant::Color: ds << typeName; ds << value.value<QColor>(); break; case QVariant::Date: ds << typeName; ds << value.toDate(); break; case QVariant::DateTime: ds << typeName; ds << value.toDateTime(); break; case QVariant::Double: ds << typeName; ds << value.toDouble(); break; case QVariant::Int: ds << typeName; if( is32Bit() ) ds << (qint32)value.toInt(); else ds << (qint64)value.toInt(); break; case QVariant::Time: ds << typeName; ds << value.toTime(); break; case QVariant::UInt: ds << typeName; if( is32Bit() ) ds << (quint32)value.toUInt(); else ds << (quint64)value.toUInt(); break; case QVariant::String: ds << typeName; ds << value.toString(); break; case QVariant::Pixmap: ds << typeName; ds << value.value<QPixmap>(); break; case QVariant::ByteArray: ds << typeName; ds << value.toByteArray(); break; case QVariant::BitArray: ds << typeName; ds << value.toBitArray(); break; case QVariant::Image: ds << typeName; ds << value.value<QImage>(); break; case QVariant::Url: ds << typeName; ds << value.toUrl(); break; case QVariant::StringList: ds << typeName; ds << value.toStringList(); break; case QVariant::SizePolicy: ds << typeName; ds << value.value<QSizePolicy>(); break; case QVariant::SizeF: ds << typeName; ds << value.toSizeF(); break; case QVariant::Size: ds << typeName; ds << value.toSize(); break; case QVariant::RegExp: ds << typeName; ds << value.toRegExp(); break; case QVariant::RectF: ds << typeName; ds << value.toRectF(); break; case QVariant::Rect: ds << typeName; ds << value.toRect(); break; case QVariant::Polygon: ds << typeName; ds << value.value<QPolygon>(); break; case QVariant::PointF: ds << typeName; ds << value.toPointF(); break; case QVariant::Point: ds << typeName; ds << value.toPoint(); break; case QVariant::Matrix: ds << typeName; ds << value.value<QMatrix>(); break; case QVariant::LineF: ds << typeName; ds << value.toLineF(); break; case QVariant::Line: ds << typeName; ds << value.toLine(); break; case QVariant::Brush: ds << typeName; ds << value.value<QBrush>(); break; case QVariant::Bitmap: ds << typeName; ds << value.value<QBitmap>(); break; case QVariant::Transform: ds << typeName; ds << value.value<QTransform>(); break; default: // Other types will be supported shortly. // TODO: support user defined types. return false; } return true; }
int Slot::setVariant( PyrSlot *slot, const QVariant &val ) { bool b_val; int type = val.userType(); switch( type ) { case QMetaType::Bool: b_val = val.toBool(); if( b_val ) SetTrue( slot ); else SetFalse( slot ); return errNone; case QMetaType::QPoint: case QMetaType::QPointF: return Slot::setPoint( slot, val.toPointF() ); case QMetaType::QSize: case QMetaType::QSizeF: Slot::setSize( slot, val.toSizeF() ); return errNone; case QMetaType::QRect: case QMetaType::QRectF: return Slot::setRect( slot, val.toRectF() ); case QMetaType::QString: Slot::setString( slot, val.toString() ); return errNone; case QMetaType::QColor: return Slot::setColor( slot, val.value<QColor>() ); case QMetaType::QPalette: return Slot::setPalette( slot, val.value<QPalette>() ); case QMetaType::Float: case QMetaType::Double: SetFloat( slot, val.value<double>() ); return errNone; case QMetaType::Int: SetInt( slot, val.toInt() ); return errNone; case QMetaType::QObjectStar: Slot::setQObject( slot, val.value<QObject*>() ); return errNone; case QMetaType::QWidgetStar: Slot::setQObject( slot, val.value<QWidget*>() ); return errNone; case QMetaType::Void: SetNil( slot ); return errNone; default: if( type == qMetaTypeId<PyrObject*>() ) { SetObject( slot, val.value<PyrObject*>() ); } else if( type == qMetaTypeId<VariantList>() ) { Slot::setVariantList( slot, val.value<VariantList>() ); } else if( type == qMetaTypeId<QcTreeWidget::ItemPtr>() ) { Slot::setTreeWidgetItem( slot, val.value< QtCollider::SafePtr<QcTreeWidget::Item> >() ); } else { qcErrorMsg( "the QVariant could not be interpreted!" ); return errFailed; } return errNone; } }
void ShaderEffectItem::updateEffectState(const QMatrix4x4 &matrix) { for (int i = m_sources.size() - 1; i >= 0; --i) { const ShaderEffectItem::SourceData &source = m_sources.at(i); if (!source.source) continue; glActiveTexture(GL_TEXTURE0 + i); source.source->bind(); } if (m_respectsOpacity) m_program.setUniformValue("qt_Opacity", static_cast<float> (effectiveOpacity())); if (m_respectsMatrix){ m_program.setUniformValue("qt_ModelViewProjectionMatrix", matrix); } QSet<QByteArray>::const_iterator it; for (it = m_uniformNames.begin(); it != m_uniformNames.end(); ++it) { const QByteArray &name = *it; QVariant v = property(name.constData()); switch (v.type()) { case QVariant::Color: m_program.setUniformValue(name.constData(), qvariant_cast<QColor>(v)); break; case QVariant::Double: m_program.setUniformValue(name.constData(), (float) qvariant_cast<double>(v)); break; case QVariant::Transform: m_program.setUniformValue(name.constData(), qvariant_cast<QTransform>(v)); break; case QVariant::Int: m_program.setUniformValue(name.constData(), v.toInt()); break; case QVariant::Bool: m_program.setUniformValue(name.constData(), GLint(v.toBool())); break; case QVariant::Size: case QVariant::SizeF: m_program.setUniformValue(name.constData(), v.toSizeF()); break; case QVariant::Point: case QVariant::PointF: m_program.setUniformValue(name.constData(), v.toPointF()); break; case QVariant::Rect: case QVariant::RectF: { QRectF r = v.toRectF(); m_program.setUniformValue(name.constData(), r.x(), r.y(), r.width(), r.height()); } break; case QVariant::Vector3D: m_program.setUniformValue(name.constData(), qvariant_cast<QVector3D>(v)); break; default: break; } } }
QString VariantHandler::displayString(const QVariant& value) { switch (value.type()) { #ifndef QT_NO_CURSOR case QVariant::Cursor: { const QCursor cursor = value.value<QCursor>(); return Util::enumToString(QVariant::fromValue<int>(cursor.shape()), "Qt::CursorShape"); } #endif case QVariant::Icon: { const QIcon icon = value.value<QIcon>(); if (icon.isNull()) { return QObject::tr("<no icon>"); } QStringList l; foreach (const QSize &size, icon.availableSizes()) { l.push_back(displayString(size)); } return l.join(QLatin1String(", ")); } case QVariant::Line: return QString::fromUtf8("%1 x %2 → %3 x %4"). arg(value.toLine().x1()).arg(value.toLine().y1()). arg(value.toLine().x2()).arg(value.toLine().y2()); case QVariant::LineF: return QString::fromUtf8("%1 x %2 → %3 x %4"). arg(value.toLineF().x1()).arg(value.toLineF().y1()). arg(value.toLineF().x2()).arg(value.toLineF().y2()); case QVariant::Locale: return value.value<QLocale>().name(); case QVariant::Point: return QString::fromLatin1("%1x%2"). arg(value.toPoint().x()). arg(value.toPoint().y()); case QVariant::PointF: return QString::fromLatin1("%1x%2"). arg(value.toPointF().x()). arg(value.toPointF().y()); case QVariant::Rect: return QString::fromLatin1("%1x%2 %3x%4"). arg(value.toRect().x()). arg(value.toRect().y()). arg(value.toRect().width()). arg(value.toRect().height()); case QVariant::RectF: return QString::fromLatin1("%1x%2 %3x%4"). arg(value.toRectF().x()). arg(value.toRectF().y()). arg(value.toRectF().width()). arg(value.toRectF().height()); case QVariant::Region: { const QRegion region = value.value<QRegion>(); if (region.isEmpty()) { return QLatin1String("<empty>"); } if (region.rectCount() == 1) { return displayString(region.rects().first()); } else { return QString::fromLatin1("<%1 rects>").arg(region.rectCount()); } } case QVariant::Palette: { const QPalette pal = value.value<QPalette>(); if (pal == qApp->palette()) { return QLatin1String("<inherited>"); } return QLatin1String("<custom>"); } case QVariant::Size: return QString::fromLatin1("%1x%2"). arg(value.toSize().width()). arg(value.toSize().height()); case QVariant::SizeF: return QString::fromLatin1("%1x%2"). arg(value.toSizeF().width()). arg(value.toSizeF().height()); case QVariant::StringList: return value.toStringList().join(", "); case QVariant::Transform: { const QTransform t = value.value<QTransform>(); return QString::fromLatin1("[%1 %2 %3, %4 %5 %6, %7 %8 %9]"). arg(t.m11()).arg(t.m12()).arg(t.m13()). arg(t.m21()).arg(t.m22()).arg(t.m23()). arg(t.m31()).arg(t.m32()).arg(t.m33()); } default: break; } // types with dynamic type ids if (value.type() == (QVariant::Type)qMetaTypeId<QTextLength>()) { const QTextLength l = value.value<QTextLength>(); QString typeStr; switch (l.type()) { case QTextLength::VariableLength: typeStr = QObject::tr("variable"); break; case QTextLength::FixedLength: typeStr = QObject::tr("fixed"); break; case QTextLength::PercentageLength: typeStr = QObject::tr("percentage"); break; } return QString::fromLatin1("%1 (%2)").arg(l.rawValue()).arg(typeStr); } if (value.userType() == qMetaTypeId<QPainterPath>()) { const QPainterPath path = value.value<QPainterPath>(); if (path.isEmpty()) { return QObject::tr("<empty>"); } return QObject::tr("<%1 elements>").arg(path.elementCount()); } if (value.userType() == qMetaTypeId<QMargins>()) { const QMargins margins = value.value<QMargins>(); return QObject::tr("left: %1, top: %2, right: %3, bottom: %4") .arg(margins.left()).arg(margins.top()) .arg(margins.right()).arg(margins.bottom()); } if (value.canConvert<QObject*>()) { return Util::displayString(value.value<QObject*>()); } #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) if (value.userType() == qMetaTypeId<QSet<QByteArray> >()) { const QSet<QByteArray> set = value.value<QSet<QByteArray> >(); QStringList l; foreach (const QByteArray &b, set) l.push_back(QString::fromUtf8(b)); return l.join(", "); } if (value.userType() == qMetaTypeId<QSurfaceFormat>()) { const QSurfaceFormat format = value.value<QSurfaceFormat>(); QString s; switch (format.renderableType()) { case QSurfaceFormat::DefaultRenderableType: s += "Default"; break; case QSurfaceFormat::OpenGL: s += "OpenGL"; break; case QSurfaceFormat::OpenGLES: s += "OpenGL ES"; break; case QSurfaceFormat::OpenVG: s += "OpenVG"; break; } s += " (" + QString::number(format.majorVersion()) + "." + QString::number(format.minorVersion()); switch (format.profile()) { case QSurfaceFormat::CoreProfile: s += " core"; break; case QSurfaceFormat::CompatibilityProfile: s += " compat"; break; case QSurfaceFormat::NoProfile: break; } s += ")"; s += " RGBA: " + QString::number(format.redBufferSize()) + "/" + QString::number(format.greenBufferSize()) + "/" + QString::number(format.blueBufferSize()) + "/" + QString::number(format.alphaBufferSize()); s += " Depth: " + QString::number(format.depthBufferSize()); s += " Stencil: " + QString::number(format.stencilBufferSize()); s += " Buffer: "; switch (format.swapBehavior()) { case QSurfaceFormat::DefaultSwapBehavior: s += "default"; break; case QSurfaceFormat::SingleBuffer: s += "single"; break; case QSurfaceFormat::DoubleBuffer: s += "double"; break; case QSurfaceFormat::TripleBuffer: s += "triple"; break; default: s += "unknown"; } return s; } if (value.userType() == qMetaTypeId<QSurface::SurfaceClass>()) { const QSurface::SurfaceClass sc = value.value<QSurface::SurfaceClass>(); switch (sc) { case QSurface::Window: return QObject::tr("Window"); #if QT_VERSION > QT_VERSION_CHECK(5, 1, 0) case QSurface::Offscreen: return QObject::tr("Offscreen"); #endif default: return QObject::tr("Unknown Surface Class"); } } if (value.userType() == qMetaTypeId<QSurface::SurfaceType>()) { const QSurface::SurfaceType type = value.value<QSurface::SurfaceType>(); switch (type) { case QSurface::RasterSurface: return QObject::tr("Raster"); case QSurface::OpenGLSurface: return QObject::tr("OpenGL"); default: return QObject::tr("Unknown Surface Type"); } } #endif // enums const QString enumStr = Util::enumToString(value); if (!enumStr.isEmpty()) { return enumStr; } // custom converters const QHash<int, Converter<QString>*>::const_iterator it = s_variantHandlerRepository()->stringConverters.constFind(value.userType()); if (it != s_variantHandlerRepository()->stringConverters.constEnd()) { return (*it.value())(value); } return value.toString(); }
// Apply a simple variant type to a DOM property static bool applySimpleProperty(const QVariant &v, bool translateString, DomProperty *dom_prop) { switch (v.type()) { case QVariant::String: { DomString *str = new DomString(); str->setText(v.toString()); if (!translateString) str->setAttributeNotr(QStringLiteral("true")); dom_prop->setElementString(str); } return true; case QVariant::ByteArray: dom_prop->setElementCstring(QString::fromUtf8(v.toByteArray())); return true; case QVariant::Int: dom_prop->setElementNumber(v.toInt()); return true; case QVariant::UInt: dom_prop->setElementUInt(v.toUInt()); return true; case QVariant::LongLong: dom_prop->setElementLongLong(v.toLongLong()); return true; case QVariant::ULongLong: dom_prop->setElementULongLong(v.toULongLong()); return true; case QVariant::Double: dom_prop->setElementDouble(v.toDouble()); return true; case QVariant::Bool: dom_prop->setElementBool(v.toBool() ? QFormBuilderStrings::instance().trueValue : QFormBuilderStrings::instance().falseValue); return true; case QVariant::Char: { DomChar *ch = new DomChar(); const QChar character = v.toChar(); ch->setElementUnicode(character.unicode()); dom_prop->setElementChar(ch); } return true; case QVariant::Point: { DomPoint *pt = new DomPoint(); const QPoint point = v.toPoint(); pt->setElementX(point.x()); pt->setElementY(point.y()); dom_prop->setElementPoint(pt); } return true; case QVariant::PointF: { DomPointF *ptf = new DomPointF(); const QPointF pointf = v.toPointF(); ptf->setElementX(pointf.x()); ptf->setElementY(pointf.y()); dom_prop->setElementPointF(ptf); } return true; case QVariant::Color: { DomColor *clr = new DomColor(); const QColor color = qvariant_cast<QColor>(v); clr->setElementRed(color.red()); clr->setElementGreen(color.green()); clr->setElementBlue(color.blue()); const int alphaChannel = color.alpha(); if (alphaChannel != 255) clr->setAttributeAlpha(alphaChannel); dom_prop->setElementColor(clr); } return true; case QVariant::Size: { DomSize *sz = new DomSize(); const QSize size = v.toSize(); sz->setElementWidth(size.width()); sz->setElementHeight(size.height()); dom_prop->setElementSize(sz); } return true; case QVariant::SizeF: { DomSizeF *szf = new DomSizeF(); const QSizeF sizef = v.toSizeF(); szf->setElementWidth(sizef.width()); szf->setElementHeight(sizef.height()); dom_prop->setElementSizeF(szf); } return true; case QVariant::Rect: { DomRect *rc = new DomRect(); const QRect rect = v.toRect(); rc->setElementX(rect.x()); rc->setElementY(rect.y()); rc->setElementWidth(rect.width()); rc->setElementHeight(rect.height()); dom_prop->setElementRect(rc); } return true; case QVariant::RectF: { DomRectF *rcf = new DomRectF(); const QRectF rectf = v.toRectF(); rcf->setElementX(rectf.x()); rcf->setElementY(rectf.y()); rcf->setElementWidth(rectf.width()); rcf->setElementHeight(rectf.height()); dom_prop->setElementRectF(rcf); } return true; case QVariant::Font: { DomFont *fnt = new DomFont(); const QFont font = qvariant_cast<QFont>(v); const uint mask = font.resolve(); if (mask & QFont::WeightResolved) { fnt->setElementBold(font.bold()); fnt->setElementWeight(font.weight()); } if (mask & QFont::FamilyResolved) fnt->setElementFamily(font.family()); if (mask & QFont::StyleResolved) fnt->setElementItalic(font.italic()); if (mask & QFont::SizeResolved) fnt->setElementPointSize(font.pointSize()); if (mask & QFont::StrikeOutResolved) fnt->setElementStrikeOut(font.strikeOut()); if (mask & QFont::UnderlineResolved) fnt->setElementUnderline(font.underline()); if (mask & QFont::KerningResolved) fnt->setElementKerning(font.kerning()); if (mask & QFont::StyleStrategyResolved) { const QMetaEnum styleStrategy_enum = metaEnum<QAbstractFormBuilderGadget>("styleStrategy"); fnt->setElementStyleStrategy(QLatin1String(styleStrategy_enum.valueToKey(font.styleStrategy()))); } dom_prop->setElementFont(fnt); } return true; #ifndef QT_NO_CURSOR case QVariant::Cursor: { const QMetaEnum cursorShape_enum = metaEnum<QAbstractFormBuilderGadget>("cursorShape"); dom_prop->setElementCursorShape(QLatin1String(cursorShape_enum.valueToKey(qvariant_cast<QCursor>(v).shape()))); } return true; #endif case QVariant::KeySequence: { DomString *s = new DomString(); s->setText(qvariant_cast<QKeySequence>(v).toString(QKeySequence::PortableText)); dom_prop->setElementString(s); } return true; case QVariant::Locale: { DomLocale *dom = new DomLocale(); const QLocale locale = qvariant_cast<QLocale>(v); const QMetaEnum language_enum = metaEnum<QAbstractFormBuilderGadget>("language"); const QMetaEnum country_enum = metaEnum<QAbstractFormBuilderGadget>("country"); dom->setAttributeLanguage(QLatin1String(language_enum.valueToKey(locale.language()))); dom->setAttributeCountry(QLatin1String(country_enum.valueToKey(locale.country()))); dom_prop->setElementLocale(dom); } return true; case QVariant::SizePolicy: { DomSizePolicy *dom = new DomSizePolicy(); const QSizePolicy sizePolicy = qvariant_cast<QSizePolicy>(v); dom->setElementHorStretch(sizePolicy.horizontalStretch()); dom->setElementVerStretch(sizePolicy.verticalStretch()); const QMetaEnum sizeType_enum = metaEnum<QAbstractFormBuilderGadget>("sizeType"); dom->setAttributeHSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.horizontalPolicy()))); dom->setAttributeVSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.verticalPolicy()))); dom_prop->setElementSizePolicy(dom); } return true; case QVariant::Date: { DomDate *dom = new DomDate(); const QDate date = qvariant_cast<QDate>(v); dom->setElementYear(date.year()); dom->setElementMonth(date.month()); dom->setElementDay(date.day()); dom_prop->setElementDate(dom); } return true; case QVariant::Time: { DomTime *dom = new DomTime(); const QTime time = qvariant_cast<QTime>(v); dom->setElementHour(time.hour()); dom->setElementMinute(time.minute()); dom->setElementSecond(time.second()); dom_prop->setElementTime(dom); } return true; case QVariant::DateTime: { DomDateTime *dom = new DomDateTime(); const QDateTime dateTime = qvariant_cast<QDateTime>(v); dom->setElementHour(dateTime.time().hour()); dom->setElementMinute(dateTime.time().minute()); dom->setElementSecond(dateTime.time().second()); dom->setElementYear(dateTime.date().year()); dom->setElementMonth(dateTime.date().month()); dom->setElementDay(dateTime.date().day()); dom_prop->setElementDateTime(dom); } return true; case QVariant::Url: { DomUrl *dom = new DomUrl(); const QUrl url = v.toUrl(); DomString *str = new DomString(); str->setText(url.toString()); dom->setElementString(str); dom_prop->setElementUrl(dom); } return true; case QVariant::StringList: { DomStringList *sl = new DomStringList; sl->setElementString(qvariant_cast<QStringList>(v)); dom_prop->setElementStringList(sl); } return true; default: break; } return false; }
void QSGPropertyAnimator::updateProperty(QObject *target, const QString& p) { QSGAnimatedProperty *ap = m_controller->registeredProperty(p, target); if (ap && m_duration > 0) { if (m_elapsed > m_startTime && ((m_elapsed < m_startTime + m_loops * m_duration) || (m_loops < 0))) { QVariant value = ap->value(); qreal tx = int(m_elapsed - m_startTime) % int(m_duration); switch (value.type()) { case QMetaType::Double: value = QVariant(m_from.toReal() + (m_to.toReal() - m_from.toReal()) * m_easing.valueForProgress(tx / m_duration)); break; case QMetaType::QColor: { QColor from = qvariant_cast<QColor>(m_from); QColor to = qvariant_cast<QColor>(m_to); QColor result = qvariant_cast<QColor>(value); result.setRed(from.red() + (to.red() - from.red()) * m_easing.valueForProgress(tx / m_duration)); result.setGreen(from.green() + (to.green() - from.green()) * m_easing.valueForProgress(tx / m_duration)); result.setBlue(from.blue() + (to.blue() - from.blue()) * m_easing.valueForProgress(tx / m_duration)); result.setAlpha(from.alpha() + (to.alpha() - from.alpha()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::Int: value = QVariant(m_from.toInt() + (m_to.toInt() - m_from.toInt()) * m_easing.valueForProgress(tx / m_duration)); break; case QMetaType::QSize: { QSize from = m_from.toSize(); QSize to = m_to.toSize(); QSize result = value.toSize(); result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration)); result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QSizeF: { QSizeF from = m_from.toSize(); QSizeF to = m_to.toSize(); QSizeF result = value.toSize(); result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration)); result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QPoint: { QPoint from = m_from.toPoint(); QPoint to = m_to.toPoint(); QPoint result = value.toPoint(); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QPointF: { QPointF from = m_from.toPointF(); QPointF to = m_to.toPointF(); QPointF result = value.toPointF(); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QRect: { QRect from = m_from.toRect(); QRect to = m_to.toRect(); QRect result = value.toRect(); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration)); result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QRectF: { QRectF from = m_from.toRectF(); QRectF to = m_to.toRectF(); QRectF result = value.toRectF(); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration)); result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QVector3D: { QVector3D from = qvariant_cast<QVector3D>(m_from); QVector3D to = qvariant_cast<QVector3D>(m_to); QVector3D result = qvariant_cast<QVector3D>(value); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); result.setZ(from.z() + (to.z() - from.z()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } default: break; } ap->setValue(value); } } }
void KConfigGroup::writeEntry( const char* key, const QVariant &value, WriteConfigFlags flags ) { Q_ASSERT_X(isValid(), "KConfigGroup::writeEntry", "accessing an invalid group"); Q_ASSERT_X(!d->bConst, "KConfigGroup::writeEntry", "writing to a read-only group"); if ( writeEntryGui( this, key, value, flags ) ) return; // GUI type that was handled QByteArray data; // if a type handler is added here you must add a QVConversions definition // to conversion_check.h, or ConversionCheck::to_QVariant will not allow // writeEntry<T> to convert to QVariant. switch( value.type() ) { case QVariant::Invalid: data = ""; break; case QVariant::ByteArray: data = value.toByteArray(); break; case QVariant::String: case QVariant::Int: case QVariant::UInt: case QVariant::Double: case QMetaType::Float: case QVariant::Bool: case QVariant::LongLong: case QVariant::ULongLong: data = value.toString().toUtf8(); break; case QVariant::List: if (!value.canConvert(QVariant::StringList)) qWarning() << "not all types in \"" << key << "\" can convert to QString," " information will be lost"; case QVariant::StringList: writeEntry( key, value.toList(), flags ); return; case QVariant::Point: { QVariantList list; const QPoint rPoint = value.toPoint(); list.insert( 0, rPoint.x() ); list.insert( 1, rPoint.y() ); writeEntry( key, list, flags ); return; } case QVariant::PointF: { QVariantList list; const QPointF point = value.toPointF(); list.insert( 0, point.x() ); list.insert( 1, point.y() ); writeEntry( key, list, flags ); return; } case QVariant::Rect:{ QVariantList list; const QRect rRect = value.toRect(); list.insert( 0, rRect.left() ); list.insert( 1, rRect.top() ); list.insert( 2, rRect.width() ); list.insert( 3, rRect.height() ); writeEntry( key, list, flags ); return; } case QVariant::RectF:{ QVariantList list; const QRectF rRectF = value.toRectF(); list.insert(0, rRectF.left()); list.insert(1, rRectF.top()); list.insert(2, rRectF.width()); list.insert(3, rRectF.height()); writeEntry(key, list, flags); return; } case QVariant::Size:{ QVariantList list; const QSize rSize = value.toSize(); list.insert( 0, rSize.width() ); list.insert( 1, rSize.height() ); writeEntry( key, list, flags ); return; } case QVariant::SizeF:{ QVariantList list; const QSizeF rSizeF = value.toSizeF(); list.insert(0, rSizeF.width()); list.insert(1, rSizeF.height()); writeEntry(key, list, flags); return; } case QVariant::Date: { QVariantList list; const QDate date = value.toDate(); list.insert( 0, date.year() ); list.insert( 1, date.month() ); list.insert( 2, date.day() ); writeEntry( key, list, flags ); return; } case QVariant::DateTime: { QVariantList list; const QDateTime rDateTime = value.toDateTime(); const QTime time = rDateTime.time(); const QDate date = rDateTime.date(); list.insert( 0, date.year() ); list.insert( 1, date.month() ); list.insert( 2, date.day() ); list.insert( 3, time.hour() ); list.insert( 4, time.minute() ); list.insert( 5, time.second() ); writeEntry( key, list, flags ); return; } case QVariant::Color: case QVariant::Font: qWarning() << "KConfigGroup::writeEntry was passed GUI type '" << value.typeName() << "' but kdeui isn't linked! If it is linked to your program, this is a platform bug. " "Please inform the KDE developers"; break; case QVariant::Url: data = QUrl(value.toUrl()).toString().toUtf8(); break; default: qWarning() << "KConfigGroup::writeEntry - unhandled type" << value.typeName() << "in group" << name(); } writeEntry(key, data, flags); }
void PSV_CircularIndicatorItem::initVariables(/*const QMap<PSV::PARAM_EKY, QVariant> &m_param*/) { if(m_param.contains(PSV::boundingRect)) { QVariant vaiant = m_param.value(PSV::boundingRect); m_rect = vaiant.toRectF(); } if(m_param.contains(PSV::toolTip)) { setToolTip(m_param.value(PSV::toolTip).toString()); } if(m_param.contains(PSV::maxValue)) { m_max = m_param.value(PSV::maxValue).toDouble(); } if(m_param.contains(PSV::minValue)) { m_min = m_param.value(PSV::minValue).toDouble(); } if(m_param.contains(PSV::indicatorWidthRatio)) { m_indicatorWidthRatio = m_param.value(PSV::indicatorWidthRatio).toDouble(); } PSV_Public::adjustRange(m_max,m_min); if(m_param.contains(PSV::levelInfos)) { QMap<QString, QVariant> temp_data = m_param.value(PSV::levelInfos).toMap(); QMapIterator<QString, QVariant> iter(temp_data); while(iter.hasNext()) { iter.next(); m_levelInfos.insert(iter.key().toDouble(),iter.value().value<QColor>()); } } else { m_levelInfos.insert(0.6,QColor(Qt::green)); m_levelInfos.insert(0.8,QColor(Qt::yellow)); m_levelInfos.insert(1,QColor(Qt::red)); } m_outerRadius = m_rect.width() > m_rect.height() ? m_rect.height() / 2: m_rect.width() / 2; // m_innerRadius=m_outerRadius/8*7; // m_coverCircleRadius=m_outerRadius/8*4; // m_colorCircleRadius=m_outerRadius/8*5; if(m_param.contains(PSV::value)) { m_value = m_param.value(PSV::value).toDouble(); } if(m_value > m_max || m_value < m_min) { m_value = m_min; } m_currentValue = m_value; if(m_param.contains(PSV::font)) { m_markFont = m_param.value(PSV::font).value<QFont>(); } }
QString GammaRay::Util::variantToString(const QVariant &value) { switch (value.type()) { case QVariant::Icon: { const QIcon icon = value.value<QIcon>(); if (icon.isNull()) return QObject::tr("<no icon>"); QStringList l; foreach (const QSize &size, icon.availableSizes()) l.push_back(variantToString(size)); return l.join(QLatin1String(", ")); } case QVariant::Line: return QString::fromUtf8("%1 x %2 → %3 x %4") .arg(value.toLine().x1()).arg(value.toLine().y1()) .arg(value.toLine().x2()).arg(value.toLine().y2()); case QVariant::LineF: return QString::fromUtf8("%1 x %2 → %3 x %4") .arg(value.toLineF().x1()).arg(value.toLineF().y1()) .arg(value.toLineF().x2()).arg(value.toLineF().y2()); case QVariant::Point: return QString::fromLatin1("%1x%2"). arg(value.toPoint().x()). arg(value.toPoint().y()); case QVariant::PointF: return QString::fromLatin1("%1x%2"). arg(value.toPointF().x()). arg(value.toPointF().y()); case QVariant::Rect: return QString::fromLatin1("%1x%2 %3x%4"). arg(value.toRect().x()). arg(value.toRect().y()). arg(value.toRect().width()). arg(value.toRect().height()); case QVariant::RectF: return QString::fromLatin1("%1x%2 %3x%4"). arg(value.toRectF().x()). arg(value.toRectF().y()). arg(value.toRectF().width()). arg(value.toRectF().height()); case QVariant::Region: { const QRegion region = value.value<QRegion>(); if (region.isEmpty()) { return QLatin1String("<empty>"); } if (region.rectCount() == 1) { return variantToString(region.rects().first()); } else { return QString::fromLatin1("<%1 rects>").arg(region.rectCount()); } } case QVariant::Palette: { const QPalette pal = value.value<QPalette>(); if (pal == qApp->palette()) return QLatin1String("<inherited>"); return QLatin1String("<custom>"); } case QVariant::Size: return QString::fromLatin1("%1x%2"). arg(value.toSize().width()). arg(value.toSize().height()); case QVariant::SizeF: return QString::fromLatin1("%1x%2"). arg(value.toSizeF().width()). arg(value.toSizeF().height()); case QVariant::SizePolicy: return QString::fromLatin1("%1 x %2"). arg(sizePolicyToString(value.value<QSizePolicy>().horizontalPolicy())). arg(sizePolicyToString(value.value<QSizePolicy>().verticalPolicy())); case QVariant::StringList: return value.toStringList().join(", "); case QVariant::Transform: { const QTransform t = value.value<QTransform>(); return QString::fromLatin1("[%1 %2 %3, %4 %5 %6, %7 %8 %9]"). arg(t.m11()).arg(t.m12()).arg(t.m13()). arg(t.m21()).arg(t.m22()).arg(t.m23()). arg(t.m31()).arg(t.m32()).arg(t.m33()); } default: break; } // types with dynamic type ids if (value.type() == qMetaTypeId<QTextLength>()) { const QTextLength l = value.value<QTextLength>(); QString typeStr; switch (l.type()) { case QTextLength::VariableLength: typeStr = QObject::tr("variable"); break; case QTextLength::FixedLength: typeStr = QObject::tr("fixed"); break; case QTextLength::PercentageLength: typeStr = QObject::tr("percentage"); break; } return QString::fromLatin1("%1 (%2)").arg(l.rawValue()).arg(typeStr); } if (value.userType() == qMetaTypeId<QPainterPath>()) { const QPainterPath path = value.value<QPainterPath>(); if (path.isEmpty()) { return QObject::tr("<empty>"); } return QObject::tr("<%1 elements>").arg(path.elementCount()); } if (value.type() == qMetaTypeId<QWidget*>()) { return displayString(value.value<QWidget*>()); } if (value.userType() == qMetaTypeId<QGraphicsEffect*>()) { return addressToString(value.value<QGraphicsEffect*>()); } if (value.userType() == qMetaTypeId<QGraphicsItem*>()) { return addressToString(value.value<QGraphicsItem*>()); } if (value.userType() == qMetaTypeId<QGraphicsItemGroup*>()) { return addressToString(value.value<QGraphicsItemGroup*>()); } if (value.userType() == qMetaTypeId<QGraphicsObject*>()) { return displayString(value.value<QGraphicsObject*>()); } if (value.userType() == qMetaTypeId<QGraphicsWidget*>()) { return displayString(value.value<QGraphicsWidget*>()); } if (value.userType() == qMetaTypeId<const QStyle*>()) { return displayString(value.value<const QStyle*>()); } // enums const QString enumStr = enumToString(value); if (!enumStr.isEmpty()) { return enumStr; } return value.toString(); }
QVariant Property::convert(QVariant &value, QVariant::Type type) { QVariant::Type v_type = value.type(); /// current variant type QVariant c_value; /// converted value QSize size; QSizeF sizef; QRect rect; QRectF rectf; QString string; QStringList str_parts; /// Parts of string when parsing a string c_value = value; // Parse variant switch (v_type) { case QVariant::Size: size = value.toSize(); switch (type) { case QVariant::String: c_value = QVariant(QString("%1,%2").arg(size.width()).arg(size.height())); break; default: break; } break; case QVariant::SizeF: sizef = value.toSizeF(); switch (type) { case QVariant::String: c_value = QVariant(QString("%1,%2").arg(sizef.width()).arg(sizef.height())); break; default: break; } break; case QVariant::Rect: rect = value.toRect(); switch (type) { case QVariant::String: c_value = QVariant(QString("%1,%2,%3,%4").arg(rect.x()).arg(rect.y()).arg(rect.width()).arg(rect.height())); break; default: break; } break; case QVariant::RectF: rectf = value.toRectF(); switch (type) { case QVariant::String: c_value = QVariant(QString("%1,%2,%3,%4").arg(rectf.x()).arg(rectf.y()).arg(rectf.width()).arg(rectf.height())); break; default: break; } break; case QVariant::String: string = value.toString(); str_parts = string.split(","); switch(type) { case QVariant::Rect: rect = QRect(str_parts[0].toInt(), str_parts[1].toInt(), str_parts[2].toInt(), str_parts[3].toInt()); c_value = QVariant(rect); break; case QVariant::RectF: rectf = QRectF(str_parts[0].toFloat(), str_parts[1].toFloat(), str_parts[2].toFloat(), str_parts[3].toFloat()); c_value = QVariant(rectf); break; case QVariant::Size: size = QSize(str_parts[0].toInt(), str_parts[1].toInt()); c_value = QVariant(size); break; case QVariant::SizeF: sizef = QSizeF(str_parts[0].toFloat(), str_parts[1].toFloat()); c_value = QVariant(sizef); break; default: break; } break; default: // No (known) need for processing break; } return c_value; }
VALUE RubyType<QVariant>::toVALUE(const QVariant& v) { #ifdef QROSS_RUBY_VARIANT_DEBUG qrossdebug( QString("RubyType<QVariant>::toVALUE variant.toString=%1 variant.typeid=%2 variant.typeName=%3").arg(v.toString()).arg(v.type()).arg(v.typeName()) ); #endif switch( v.type() ) { case QVariant::Int: return RubyType<int>::toVALUE(v.toInt()); case QVariant::UInt: return RubyType<uint>::toVALUE(v.toUInt()); case QVariant::Double: return RubyType<double>::toVALUE(v.toDouble()); case QVariant::ByteArray: return RubyType<QByteArray>::toVALUE(v.toByteArray()); case QVariant::String: return RubyType<QString>::toVALUE(v.toString()); case QVariant::Bool: return RubyType<bool>::toVALUE(v.toBool()); case QVariant::StringList: return RubyType<QStringList>::toVALUE(v.toStringList()); case QVariant::Map: return RubyType<QVariantMap>::toVALUE(v.toMap()); case QVariant::List: return RubyType<QVariantList>::toVALUE(v.toList()); case QVariant::LongLong: return RubyType<qlonglong>::toVALUE(v.toLongLong()); case QVariant::ULongLong: return RubyType<qlonglong>::toVALUE(v.toULongLong()); case QVariant::Size: return RubyType<QSize>::toVALUE(v.toSize()); case QVariant::SizeF: return RubyType<QSizeF>::toVALUE(v.toSizeF()); case QVariant::Point: return RubyType<QPoint>::toVALUE(v.toPoint()); case QVariant::PointF: return RubyType<QPointF>::toVALUE(v.toPointF()); case QVariant::Rect: return RubyType<QRect>::toVALUE(v.toRect()); case QVariant::RectF: return RubyType<QRectF>::toVALUE(v.toRectF()); case QVariant::Color: return RubyType<QColor>::toVALUE( v.value<QColor>() ); case QVariant::Url: return RubyType<QUrl>::toVALUE(v.toUrl()); case QVariant::Date: return RubyType<QDate>::toVALUE( v.value<QDate>() ); case QVariant::Time: return RubyType<QTime>::toVALUE( v.value<QTime>() ); case QVariant::DateTime: return RubyType<QDateTime>::toVALUE( v.value<QDateTime>() ); case QVariant::Invalid: { #ifdef QROSS_RUBY_VARIANT_DEBUG qrossdebug( QString("RubyType<QVariant>::toVALUE variant=%1 is QVariant::Invalid. Returning Qnil.").arg(v.toString()) ); #endif return Qnil; } // fall through case QVariant::UserType: { #ifdef QROSS_RUBY_VARIANT_DEBUG qrossdebug( QString("RubyType<QVariant>::toVALUE variant=%1 is QVariant::UserType. Trying to cast now.").arg(v.toString()) ); #endif } // fall through default: { if( strcmp(v.typeName(),"float") == 0 ) { #ifdef QROSS_RUBY_VARIANT_DEBUG qrossdebug( QString("RubyType<QVariant>::toVALUE Casting '%1' to double").arg(v.typeName()) ); #endif return RubyType<double>::toVALUE(v.toDouble()); } if( strcmp(v.typeName(),"Qross::VoidList") == 0 ) { VoidList list = v.value<VoidList>(); Qross::MetaTypeHandler* handler = Qross::Manager::self().metaTypeHandler(list.typeName); #ifdef QROSS_RUBY_VARIANT_DEBUG qrossdebug( QString("RubyType<QVariant>::toVALUE Casting '%1' to QList<%2> with %3 items, hasHandler=%4").arg(v.typeName()).arg(list.typeName.constData()).arg(list.count()).arg(handler ? "true" : "false") ); #endif QVariantList l; foreach(void* ptr, list) { if( handler ) { l << handler->callHandler(ptr); } else { QVariant v; v.setValue(ptr); l << v; } } return RubyType<QVariantList>::toVALUE(l); } if( qVariantCanConvert< Qross::Object::Ptr >(v) ) { #ifdef QROSS_RUBY_VARIANT_DEBUG qrossdebug( QString("RubyType<QVariant>::toPyObject Casting '%1' to Qross::Object::Ptr").arg(v.typeName()) ); #endif Qross::Object::Ptr obj = v.value< Qross::Object::Ptr >(); Qross::RubyObject* rbobj = dynamic_cast< Qross::RubyObject* >(obj.data()); if(! obj) { #ifdef QROSS_RUBY_VARIANT_DEBUG qrossdebug( QString("RubyType<QVariant>::toPyObject To Qross::RubyObject* casted '%1' is NULL").arg(v.typeName()) ); #endif return Qnil; } return rbobj->rbObject(); } if( qVariantCanConvert< QWidget* >(v) ) { #ifdef QROSS_RUBY_VARIANT_DEBUG qrossdebug( QString("RubyType<QVariant>::toVALUE Casting '%1' to QWidget").arg(v.typeName()) ); #endif QWidget* widget = qvariant_cast< QWidget* >(v); if(! widget) { #ifdef QROSS_RUBY_VARIANT_DEBUG qrosswarning( QString("RubyType<QVariant>::toVALUE To QWidget casted '%1' is NULL").arg(v.typeName()) ); #endif return Qnil; } return RubyExtension::toVALUE( new RubyExtension(widget), true /*owner*/ ); } if( qVariantCanConvert< QObject* >(v) ) { #ifdef QROSS_RUBY_VARIANT_DEBUG qrossdebug( QString("RubyType<QVariant>::toVALUE Casting '%1' to QObject*").arg(v.typeName()) ); #endif QObject* obj = qvariant_cast< QObject* >(v); if(! obj) { #ifdef QROSS_RUBY_VARIANT_DEBUG qrosswarning( QString("RubyType<QVariant>::toVALUE To QObject casted '%1' is NULL").arg(v.typeName()) ); #endif return Qnil; } return RubyExtension::toVALUE( new RubyExtension(obj), true /*owner*/ ); } if( qVariantCanConvert< void* >(v) ) { return Data_Wrap_Struct( rb_cObject, 0, 0, qvariant_cast<void*>(v)); } //QObject* obj = (*reinterpret_cast< QObject*(*)>( variantargs[0]->toVoidStar() )); //PyObject* qobjectptr = PyLong_FromVoidPtr( (void*) variantargs[0]->toVoidStar() ); #ifdef QROSS_RUBY_VARIANT_DEBUG qrosswarning( QString("RubyType<QVariant>::toVALUE Not possible to convert the QVariant '%1' with type '%2' (%3) to a VALUE.").arg(v.toString()).arg(v.typeName()).arg(v.type()) ); #endif //throw Py::TypeError( QString("Variant of type %1 can not be casted to a Ruby object.").arg(v.typeName()).toLatin1().constData() ); return 0; } }
QString VariantHandler::displayString(const QVariant &value) { switch (value.type()) { #ifndef QT_NO_CURSOR case QVariant::Cursor: { const QCursor cursor = value.value<QCursor>(); return Util::enumToString(QVariant::fromValue<int>(cursor.shape()), "Qt::CursorShape"); } #endif case QVariant::Icon: { const QIcon icon = value.value<QIcon>(); if (icon.isNull()) { return QObject::tr("<no icon>"); } QStringList l; foreach (const QSize &size, icon.availableSizes()) { l.push_back(displayString(size)); } return l.join(QLatin1String(", ")); } case QVariant::Line: return QString::fromUtf8("%1, %2 → %3, %4"). arg(value.toLine().x1()).arg(value.toLine().y1()). arg(value.toLine().x2()).arg(value.toLine().y2()); case QVariant::LineF: return QString::fromUtf8("%1, %2 → %3, %4"). arg(value.toLineF().x1()).arg(value.toLineF().y1()). arg(value.toLineF().x2()).arg(value.toLineF().y2()); case QVariant::Locale: return value.value<QLocale>().name(); case QVariant::Point: return QString::fromLatin1("%1, %2"). arg(value.toPoint().x()). arg(value.toPoint().y()); case QVariant::PointF: return QString::fromLatin1("%1, %2"). arg(value.toPointF().x()). arg(value.toPointF().y()); case QVariant::Rect: return QString::fromLatin1("%1, %2 %3 x %4"). arg(value.toRect().x()). arg(value.toRect().y()). arg(value.toRect().width()). arg(value.toRect().height()); case QVariant::RectF: return QString::fromLatin1("%1, %2 %3 x %4"). arg(value.toRectF().x()). arg(value.toRectF().y()). arg(value.toRectF().width()). arg(value.toRectF().height()); case QVariant::Region: { const QRegion region = value.value<QRegion>(); if (region.isEmpty()) { return QLatin1String("<empty>"); } if (region.rectCount() == 1) { return displayString(region.rects().first()); } else { return QString::fromLatin1("<%1 rects>").arg(region.rectCount()); } } case QVariant::Palette: { const QPalette pal = value.value<QPalette>(); if (pal == qApp->palette()) { return QLatin1String("<inherited>"); } return QLatin1String("<custom>"); } case QVariant::Size: return QString::fromLatin1("%1 x %2"). arg(value.toSize().width()). arg(value.toSize().height()); case QVariant::SizeF: return QString::fromLatin1("%1 x %2"). arg(value.toSizeF().width()). arg(value.toSizeF().height()); case QVariant::StringList: return value.toStringList().join(", "); case QVariant::Transform: { const QTransform t = value.value<QTransform>(); return QString::fromLatin1("[%1 %2 %3, %4 %5 %6, %7 %8 %9]"). arg(t.m11()).arg(t.m12()).arg(t.m13()). arg(t.m21()).arg(t.m22()).arg(t.m23()). arg(t.m31()).arg(t.m32()).arg(t.m33()); } default: break; } // types with dynamic type ids if (value.type() == (QVariant::Type)qMetaTypeId<QTextLength>()) { const QTextLength l = value.value<QTextLength>(); QString typeStr; switch (l.type()) { case QTextLength::VariableLength: typeStr = QObject::tr("variable"); break; case QTextLength::FixedLength: typeStr = QObject::tr("fixed"); break; case QTextLength::PercentageLength: typeStr = QObject::tr("percentage"); break; } return QString::fromLatin1("%1 (%2)").arg(l.rawValue()).arg(typeStr); } if (value.userType() == qMetaTypeId<QPainterPath>()) { const QPainterPath path = value.value<QPainterPath>(); if (path.isEmpty()) { return QObject::tr("<empty>"); } return QObject::tr("<%1 elements>").arg(path.elementCount()); } if (value.userType() == qMetaTypeId<QMargins>()) { const QMargins margins = value.value<QMargins>(); return QObject::tr("left: %1, top: %2, right: %3, bottom: %4") .arg(margins.left()).arg(margins.top()) .arg(margins.right()).arg(margins.bottom()); } if (value.canConvert<QObject*>()) { return Util::displayString(value.value<QObject*>()); } if (value.userType() == qMetaTypeId<QMatrix4x4>()) { return displayMatrix4x4(value.value<QMatrix4x4>()); } if (value.userType() == qMetaTypeId<const QMatrix4x4*>()) { return displayMatrix4x4(value.value<const QMatrix4x4*>()); } #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) if (value.userType() == qMetaTypeId<QSet<QByteArray> >()) { const QSet<QByteArray> set = value.value<QSet<QByteArray> >(); QStringList l; foreach (const QByteArray &b, set) { l.push_back(QString::fromUtf8(b)); } return l.join(", "); }