bool Image::setProperty(P_ID propertyId, const QVariant& v) { bool rv = true; score()->addRefresh(canvasBoundingRect()); switch(propertyId) { case P_AUTOSCALE: setAutoScale(v.toBool()); break; case P_SIZE: setSize(v.toSizeF()); break; case P_SCALE: setScale(v.toSizeF()); break; case P_LOCK_ASPECT_RATIO: setLockAspectRatio(v.toBool()); break; case P_SIZE_IS_SPATIUM: setSizeIsSpatium(v.toBool()); break; default: rv = Element::setProperty(propertyId, v); break; } setGenerated(false); score()->setLayoutAll(true); return rv; }
void LabelPrintEngine::setProperty ( PrintEnginePropertyKey key, const QVariant & value ) { switch(key) { case QPrintEngine::PPK_PrinterName: m_printerName = value.toString(); break; case QPrintEngine::PPK_DocumentName: m_docName = value.toString(); break; case QPrintEngine::PPK_CustomPaperSize: m_paperSize = value.toSizeF(); m_paperRect = QRect(QPoint(0,0),m_paperSize.toSize()); break; case QPrintEngine::PPK_PaperRect: case QPrintEngine::PPK_PageRect: m_paperSize = value.toRect().size(); m_paperRect = value.toRect(); break; case QPrintEngine::PPK_PageSize: // not implemented break; case QPrintEngine::PPK_Resolution: m_resolution = value.toInt(); break; default: break; } }
bool InspectorBase::isDefault(const InspectorItem& ii) { Element* e = inspector->element(); for (int i = 0; i < ii.parent; ++i) e = e->parent(); P_ID id = ii.t; P_TYPE t = propertyType(id); QVariant val = getValue(ii); QVariant def = e->propertyDefault(id); if (t == P_TYPE::SIZE || t == P_TYPE::SCALE || t == P_TYPE::SIZE_MM) { QSizeF sz = def.toSizeF(); qreal v = ii.sv == 0 ? sz.width() : sz.height(); return val.toDouble() == v; } if (t == P_TYPE::POINT || t == P_TYPE::POINT_MM) { QPointF sz = def.toPointF(); qreal v = ii.sv == 0 ? sz.x() : sz.y(); return val.toDouble() == v; } if (t == P_TYPE::FRACTION) { Fraction f = def.value<Fraction>(); int v = ii.sv == 0 ? f.numerator() : f.denominator(); return val.toInt() == v; } return val == def; }
void KSizeFComposedProperty::setValue(KProperty *property, const QVariant &value, bool rememberOldValue) { const QSizeF s( value.toSizeF() ); property->child("width")->setValue(s.width(), rememberOldValue, false); property->child("height")->setValue(s.height(), rememberOldValue, false); }
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 Image::setProperty(Pid propertyId, const QVariant& v) { bool rv = true; score()->addRefresh(canvasBoundingRect()); switch(propertyId) { case Pid::AUTOSCALE: setAutoScale(v.toBool()); break; case Pid::SIZE: setSize(v.toSizeF()); break; case Pid::LOCK_ASPECT_RATIO: setLockAspectRatio(v.toBool()); break; case Pid::SIZE_IS_SPATIUM: { QSizeF s = size2pixel(_size); setSizeIsSpatium(v.toBool()); _size = pixel2size(s); } break; default: rv = Element::setProperty(propertyId, v); break; } setGenerated(false); _dirty = true; triggerLayout(); return rv; }
void KItemListViewAnimation::start(QGraphicsWidget* widget, AnimationType type, const QVariant& endValue) { stop(widget, type); QPropertyAnimation* propertyAnim = nullptr; const int animationDuration = widget->style()->styleHint(QStyle::SH_Widget_Animate) ? 200 : 1; switch (type) { case MovingAnimation: { const QPointF newPos = endValue.toPointF(); if (newPos == widget->pos()) { return; } propertyAnim = new QPropertyAnimation(widget, "pos"); propertyAnim->setDuration(animationDuration); propertyAnim->setEndValue(newPos); break; } case CreateAnimation: { propertyAnim = new QPropertyAnimation(widget, "opacity"); propertyAnim->setEasingCurve(QEasingCurve::InQuart); propertyAnim->setDuration(animationDuration); propertyAnim->setStartValue(0.0); propertyAnim->setEndValue(1.0); break; } case DeleteAnimation: { propertyAnim = new QPropertyAnimation(widget, "opacity"); propertyAnim->setEasingCurve(QEasingCurve::OutQuart); propertyAnim->setDuration(animationDuration); propertyAnim->setStartValue(1.0); propertyAnim->setEndValue(0.0); break; } case ResizeAnimation: { const QSizeF newSize = endValue.toSizeF(); if (newSize == widget->size()) { return; } propertyAnim = new QPropertyAnimation(widget, "size"); propertyAnim->setDuration(animationDuration); propertyAnim->setEndValue(newSize); break; } default: break; } Q_ASSERT(propertyAnim); connect(propertyAnim, &QPropertyAnimation::finished, this, &KItemListViewAnimation::slotFinished); m_animation[type].insert(widget, propertyAnim); propertyAnim->start(); }
void XmlQSizeFSerializator::save(const QVariant &value, QString name) { QSizeF size = value.toSizeF(); QDomElement _node = doc()->createElement(name); _node.setAttribute("Type","QSizeF"); _node.setAttribute("width",QString::number(size.width())); _node.setAttribute("height",QString::number(size.height())); node()->appendChild(_node); }
void PropertyBrowser::applyMapObjectValue(PropertyId id, const QVariant &val) { MapObject *mapObject = static_cast<MapObject*>(mObject); QUndoCommand *command = 0; switch (id) { case NameProperty: case TypeProperty: command = new ChangeMapObject(mMapDocument, mapObject, mIdToProperty[NameProperty]->value().toString(), mIdToProperty[TypeProperty]->value().toString()); break; case VisibleProperty: command = new SetMapObjectVisible(mMapDocument, mapObject, val.toBool()); break; case PositionProperty: { const QPointF oldPos = mapObject->position(); mapObject->setPosition(val.toPointF()); command = new MoveMapObject(mMapDocument, mapObject, oldPos); break; } case SizeProperty: { const QSizeF oldSize = mapObject->size(); mapObject->setSize(val.toSizeF()); command = new ResizeMapObject(mMapDocument, mapObject, oldSize); break; } case RotationProperty: { const qreal oldRotation = mapObject->rotation(); mapObject->setRotation(val.toDouble()); command = new RotateMapObject(mMapDocument, mapObject, oldRotation); break; } case FlippingProperty: { const int flippingFlags = val.toInt(); const bool flippedHorizontally = flippingFlags & 1; const bool flippedVertically = flippingFlags & 2; // You can only change one checkbox at a time if (mapObject->cell().flippedHorizontally != flippedHorizontally) { command = new FlipMapObjects(mMapDocument, QList<MapObject*>() << mapObject, FlipHorizontally); } else if (mapObject->cell().flippedVertically != flippedVertically) { command = new FlipMapObjects(mMapDocument, QList<MapObject*>() << mapObject, FlipVertically); } } default: break; } if (command) mMapDocument->undoStack()->push(command); }
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; }
static void WriteAttributes(QObject* obj,QDomElement& el,QDomDocument& doc) { el.setAttribute("type",obj->metaObject()->className()); for(int i = 0; i < obj->metaObject()->propertyCount(); ++i) { QMetaProperty metaProperty(obj->metaObject()->property(i)); { QDomElement prop = doc.createElement("property"); prop.setAttribute("name",QString(metaProperty.name())); QVariant value = metaProperty.read(obj); QString strValue; if (metaProperty.type()==QVariant::String) { strValue = value.toString(); } else if (metaProperty.type()==QVariant::Int) { strValue = value.toString(); } else if (metaProperty.type()==QVariant::UInt) { strValue = value.toString(); } else if (metaProperty.type()==QVariant::Double) { strValue = value.toString(); } else if (metaProperty.type()==QVariant::Bool) { strValue = value.toBool() ? "1" : "0"; } else if (metaProperty.type()==QVariant::Point) { strValue = QString::number(value.toPoint().x())+";" + QString::number(value.toPoint().y()); } else if (metaProperty.type()==QVariant::PointF) { strValue = QString::number(value.toPointF().x())+";" + QString::number(value.toPointF().y()); } else if (metaProperty.type()==QVariant::Size) { strValue = QString::number(value.toSize().width())+";" + QString::number(value.toSize().height()); } else if (metaProperty.type()==QVariant::SizeF) { strValue = QString::number(value.toSizeF().width())+";" + QString::number(value.toSizeF().height()); } else { QByteArray ar; QDataStream ds(&ar,QIODevice::WriteOnly); ds << value; strValue = ar.toBase64().data(); } prop.setAttribute("value",strValue); el.appendChild(prop); } } }
void CQPropertySizeFEditor:: setValue(QWidget *w, const QVariant &var) { CQPoint2DEdit *edit = qobject_cast<CQPoint2DEdit *>(w); assert(edit); QSizeF s = var.toSizeF(); edit->setValue(QPointF(s.width(), s.height())); }
QString PropertyField::valueToString(QVariant val) { QString text; switch (val.type()) { case QVariant::Double: text = QString("%1").arg(val.toReal(), 0, 'f', 4); break; case QVariant::Size: text = QString("%1 x %2").arg(val.toSize().width()).arg(val.toSize().height()); break; case QVariant::SizeF: text = QString("%1 x %2").arg(val.toSizeF().width()).arg(val.toSizeF().height()); break; case QVariant::Rect: { QRect rect = val.toRect(); text = QString("%1 x %2 %3%4 %5%6").arg(rect.width()) .arg(rect.height()).arg(rect.x() < 0 ? "" : "+").arg(rect.x()) .arg(rect.y() < 0 ? "" : "+").arg(rect.y()); } break; default: text = val.toString(); } return text; }
QString KPropertySizeFDelegate::valueToString(const QVariant& value, const QLocale &locale) const { const QSizeF s(value.toSizeF()); if (s.isNull()) { if (locale.language() == QLocale::C) { return QString(); } return QObject::tr("None", "Null value"); } if (locale.language() == QLocale::C) { return QString::fromLatin1("%1x%2").arg(s.width()).arg(s.height()); } return QObject::tr("%1x%2", "Size") .arg(locale.toString(s.width())) .arg(locale.toString(s.height())); }
bool Lasso::setProperty(P_ID propertyId, const QVariant& v) { switch(propertyId) { case P_ID::LASSO_POS: _rect.moveTo(v.toPointF()); break; case P_ID::LASSO_SIZE: _rect.setSize(v.toSizeF()); break; default: if (!Element::setProperty(propertyId, v)) return false; break; } score()->setUpdateAll(); return true; }
bool TextInputComponent::Initialize() { QVariant value; SI()->RegisterStateListener(StateId_WindowSize, this, value); m_windowSize = value.toSizeF(); // TODO: get these values from State. m_textPen = QPen(QColor(50, 50, 50)); m_bgFill = QBrush(QColor(200, 200, 200)); m_textBgFill = QBrush(QColor(245, 245, 245)); UpdateDimensions(); SetFlag(ComponentFlag_HandlesKeyEvents); return true; }
bool TimeSig::setProperty(P_ID propertyId, const QVariant& v) { switch (propertyId) { case P_ID::SHOW_COURTESY: if (generated()) return false; setShowCourtesySig(v.toBool()); break; case P_ID::NUMERATOR_STRING: setNumeratorString(v.toString()); break; case P_ID::DENOMINATOR_STRING: setDenominatorString(v.toString()); break; case P_ID::GROUPS: setGroups(v.value<Groups>()); break; case P_ID::TIMESIG: setSig(v.value<Fraction>()); break; case P_ID::TIMESIG_GLOBAL: setGlobalSig(v.value<Fraction>()); break; case P_ID::TIMESIG_STRETCH: setStretch(v.value<Fraction>()); break; case P_ID::TIMESIG_TYPE: _timeSigType = (TimeSigType)(v.toInt()); break; case P_ID::SCALE: _scale = v.toSizeF(); break; default: if (!Element::setProperty(propertyId, v)) return false; break; } score()->setLayoutAll(); // TODO setGenerated(false); return true; }
bool InspectorBase::isDefault(int idx) { Element* e = inspector->element(); const InspectorItem& ii = item(idx); P_ID id = ii.t; P_TYPE t = propertyType(id); QVariant val = getValue(idx); QVariant def = e->propertyDefault(id); if (t == T_SIZE || t == T_SCALE) { QSizeF sz = def.toSizeF(); qreal v = ii.sv == 0 ? sz.width() : sz.height(); return val.toDouble() == v; } if (t == T_POINT) { QPointF sz = def.toPointF(); qreal v = ii.sv == 0 ? sz.x() : sz.y(); return val.toDouble() == v; } return val == def; }
void Properties::serializeValueOut( QVariant value, QXmlStreamWriter& stream ) { if ( value.isValid( ) ) { stream.writeAttribute( "t", QString::number( value.type( ) ) ); QString vs; switch ( value.type( ) ) { case QVariant::Type::SizeF: { QSizeF s = value.toSizeF( ); QTextStream vss( &vs ); vss << s.width( ) << " x " << s.height( ); break; } default: vs = value.toString( ); } stream.writeAttribute( "v", vs ); } }
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(); }
void AdvancedPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value) { Q_D(AdvancedPdfPrintEngine); switch (int(key)) { case PPK_CollateCopies: d->collate = value.toBool(); break; case PPK_ColorMode: d->grayscale = (QPrinter::ColorMode(value.toInt()) == QPrinter::GrayScale); break; case PPK_Creator: d->creator = value.toString(); break; case PPK_DocumentName: d->title = value.toString(); break; case PPK_FullPage: d->fullPage = value.toBool(); break; case PPK_CopyCount: // fallthrough case PPK_NumberOfCopies: d->copies = value.toInt(); break; case PPK_Orientation: d->landscape = (QPrinter::Orientation(value.toInt()) == QPrinter::Landscape); break; case PPK_OutputFileName: d->outputFileName = value.toString(); break; case PPK_PageOrder: d->pageOrder = QPrinter::PageOrder(value.toInt()); break; case PPK_PaperSize: d->printerPaperSize = QPrinter::PaperSize(value.toInt()); d->updatePaperSize(); break; case PPK_PaperSource: d->paperSource = QPrinter::PaperSource(value.toInt()); break; case PPK_PrinterName: d->printerName = value.toString(); break; case PPK_PrinterProgram: d->printProgram = value.toString(); break; case PPK_Resolution: d->resolution = value.toInt(); break; case PPK_SelectionOption: d->selectionOption = value.toString(); break; case PPK_FontEmbedding: d->embedFonts = value.toBool(); break; case PPK_Duplex: d->duplex = static_cast<QPrinter::DuplexMode> (value.toInt()); break; case PPK_CustomPaperSize: d->printerPaperSize = QPrinter::Custom; d->customPaperSize = value.toSizeF(); d->updatePaperSize(); break; case PPK_PageMargins: { QList<QVariant> margins(value.toList()); Q_ASSERT(margins.size() == 4); d->leftMargin = margins.at(0).toReal(); d->topMargin = margins.at(1).toReal(); d->rightMargin = margins.at(2).toReal(); d->bottomMargin = margins.at(3).toReal(); d->pageMarginsSet = true; break; } default: break; } }
void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value) { Q_D(QPdfPrintEngine); switch (int(key)) { // The following keys are properties or derived values and so cannot be set case PPK_PageRect: break; case PPK_PaperRect: break; case PPK_PaperSources: break; case PPK_SupportsMultipleCopies: break; case PPK_SupportedResolutions: break; // The following keys are settings that are unsupported by the PDF PrintEngine case PPK_CustomBase: break; // The following keys are properties and settings that are supported by the PDF PrintEngine case PPK_CollateCopies: d->collate = value.toBool(); break; case PPK_ColorMode: d->grayscale = (QPrinter::ColorMode(value.toInt()) == QPrinter::GrayScale); break; case PPK_Creator: d->creator = value.toString(); break; case PPK_DocumentName: d->title = value.toString(); break; case PPK_FullPage: if (value.toBool()) d->m_pageLayout.setMode(QPageLayout::FullPageMode); else d->m_pageLayout.setMode(QPageLayout::StandardMode); break; case PPK_CopyCount: // fallthrough case PPK_NumberOfCopies: d->copies = value.toInt(); break; case PPK_Orientation: d->m_pageLayout.setOrientation(QPageLayout::Orientation(value.toInt())); break; case PPK_OutputFileName: d->outputFileName = value.toString(); break; case PPK_PageOrder: d->pageOrder = QPrinter::PageOrder(value.toInt()); break; case PPK_PageSize: { QPageSize pageSize = QPageSize(QPageSize::PageSizeId(value.toInt())); if (pageSize.isValid()) d->m_pageLayout.setPageSize(pageSize); break; } case PPK_PaperName: { QString name = value.toString(); for (int i = 0; i <= QPageSize::LastPageSize; ++i) { QPageSize pageSize = QPageSize(QPageSize::PageSizeId(i)); if (name == pageSize.name()) { d->m_pageLayout.setPageSize(pageSize); break; } } break; } case PPK_WindowsPageSize: d->m_pageLayout.setPageSize(QPageSize(QPageSize::id(value.toInt()))); break; case PPK_PaperSource: d->paperSource = QPrinter::PaperSource(value.toInt()); break; case PPK_PrinterName: d->printerName = value.toString(); break; case PPK_PrinterProgram: d->printProgram = value.toString(); break; case PPK_Resolution: d->resolution = value.toInt(); break; case PPK_SelectionOption: d->selectionOption = value.toString(); break; case PPK_FontEmbedding: d->embedFonts = value.toBool(); break; case PPK_Duplex: d->duplex = static_cast<QPrint::DuplexMode>(value.toInt()); break; case PPK_CustomPaperSize: d->m_pageLayout.setPageSize(QPageSize(value.toSizeF(), QPageSize::Point)); break; case PPK_PageMargins: { QList<QVariant> margins(value.toList()); Q_ASSERT(margins.size() == 4); d->m_pageLayout.setUnits(QPageLayout::Point); d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(), margins.at(2).toReal(), margins.at(3).toReal())); break; } case PPK_QPageSize: { QPageSize pageSize = value.value<QPageSize>(); if (pageSize.isValid()) d->m_pageLayout.setPageSize(pageSize); break; } case PPK_QPageMargins: { QPair<QMarginsF, QPageLayout::Unit> pair = value.value<QPair<QMarginsF, QPageLayout::Unit> >(); d->m_pageLayout.setUnits(pair.second); d->m_pageLayout.setMargins(pair.first); break; } case PPK_QPageLayout: { QPageLayout pageLayout = value.value<QPageLayout>(); if (pageLayout.isValid()) d->m_pageLayout = pageLayout; break; } // No default so that compiler will complain if new keys added and not handled in this engine } }
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; }
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 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); }
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(", "); }
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; } }