void SizePolicyCustomProperty::setValue(const QVariant &value, bool rememberOldValue) { if(!m_property) return; if(m_property->parent()) { QSizePolicy v = m_property->parent()->value().toSizePolicy(); if(m_property->type() == SizePolicy_HorData) v.setHorData(QSizePolicy::SizeType(value.toInt())); else if(m_property->type() == SizePolicy_VerData) v.setVerData(QSizePolicy::SizeType(value.toInt())); else if(m_property->type() == SizePolicy_HorStretch) v.setHorStretch(value.toInt()); else if(m_property->type() == SizePolicy_VerStretch) v.setVerStretch(value.toInt()); m_property->parent()->setValue(v, true, false); } else { QSizePolicy v = value.toSizePolicy(); m_property->child("hSizeType")->setValue(v.horData(), rememberOldValue, false); m_property->child("vSizeType")->setValue(v.verData(), rememberOldValue, false); m_property->child("hStretch")->setValue(v.horStretch(), rememberOldValue, false); m_property->child("vStretch")->setValue(v.verStretch(), rememberOldValue, false); } }
/*! Attention: this function has to be in sync with Resource::saveProperty() and DomTool::elementToVariant. If you change one, change all. */ QString Uic::setObjectProperty( const QString& objClass, const QString& obj, const QString &prop, const QDomElement &e, bool stdset ) { QString v; if ( e.tagName() == "rect" ) { QDomElement n3 = e.firstChild().toElement(); int x = 0, y = 0, w = 0, h = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "x" ) x = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "y" ) y = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "width" ) w = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "height" ) h = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } v = "QRect( %1, %2, %3, %4 )"; v = v.arg(x).arg(y).arg(w).arg(h); } else if ( e.tagName() == "point" ) { QDomElement n3 = e.firstChild().toElement(); int x = 0, y = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "x" ) x = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "y" ) y = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } v = "QPoint( %1, %2 )"; v = v.arg(x).arg(y); } else if ( e.tagName() == "size" ) { QDomElement n3 = e.firstChild().toElement(); int w = 0, h = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "width" ) w = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "height" ) h = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } v = "QSize( %1, %2 )"; v = v.arg(w).arg(h); } else if ( e.tagName() == "color" ) { QDomElement n3 = e.firstChild().toElement(); int r = 0, g = 0, b = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "red" ) r = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "green" ) g = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "blue" ) b = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } v = "QColor( %1, %2, %3 )"; v = v.arg(r).arg(g).arg(b); } else if ( e.tagName() == "font" ) { QDomElement n3 = e.firstChild().toElement(); QString attrname = e.parentNode().toElement().attribute( "name", "font" ); QString fontname; if ( !obj.isEmpty() ) { fontname = registerObject( obj + "_" + attrname ); out << indent << "QFont " << fontname << "( " << obj << "->font() );" << endl; } else { fontname = registerObject( "f" ); out << indent << "QFont " << fontname << "( font() );" << endl; } while ( !n3.isNull() ) { if ( n3.tagName() == "family" ) out << indent << fontname << ".setFamily( \"" << n3.firstChild().toText().data() << "\" );" << endl; else if ( n3.tagName() == "pointsize" ) out << indent << fontname << ".setPointSize( " << n3.firstChild().toText().data() << " );" << endl; else if ( n3.tagName() == "bold" ) out << indent << fontname << ".setBold( " << mkBool( n3.firstChild().toText().data() ) << " );" << endl; else if ( n3.tagName() == "italic" ) out << indent << fontname << ".setItalic( " << mkBool( n3.firstChild().toText().data() ) << " );" << endl; else if ( n3.tagName() == "underline" ) out << indent << fontname << ".setUnderline( " << mkBool( n3.firstChild().toText().data() ) << " );" << endl; else if ( n3.tagName() == "strikeout" ) out << indent << fontname << ".setStrikeOut( " << mkBool( n3.firstChild().toText().data() ) << " );" << endl; n3 = n3.nextSibling().toElement(); } if ( prop == "font" ) { if ( !obj.isEmpty() ) out << indent << obj << "->setFont( " << fontname << " ); " << endl; else out << indent << "setFont( " << fontname << " ); " << endl; } else { v = fontname; } } else if ( e.tagName() == "string" ) { QString txt = e.firstChild().toText().data(); QString com = getComment( e.parentNode() ); if ( prop == "toolTip" && objClass != "QAction" && objClass != "QActionGroup" ) { if ( !obj.isEmpty() ) trout << indent << "QToolTip::add( " << obj << ", " << trcall( txt, com ) << " );" << endl; else trout << indent << "QToolTip::add( this, " << trcall( txt, com ) << " );" << endl; } else if ( prop == "whatsThis" && objClass != "QAction" && objClass != "QActionGroup" ) { if ( !obj.isEmpty() ) trout << indent << "QWhatsThis::add( " << obj << ", " << trcall( txt, com ) << " );" << endl; else trout << indent << "QWhatsThis::add( this, " << trcall( txt, com ) << " );" << endl; } else { v = trcall( txt, com ); } } else if ( e.tagName() == "cstring" ) { v = "\"%1\""; v = v.arg( e.firstChild().toText().data() ); } else if ( e.tagName() == "number" ) { v = "%1"; v = v.arg( e.firstChild().toText().data() ); } else if ( e.tagName() == "bool" ) { if ( stdset ) v = "%1"; else v = "QVariant( %1, 0 )"; v = v.arg( mkBool( e.firstChild().toText().data() ) ); } else if ( e.tagName() == "pixmap" ) { v = e.firstChild().toText().data(); if ( !pixmapLoaderFunction.isEmpty() ) { v.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "" ) ); v.append( QString( externPixmaps ? "\"" : "" ) + " )" ); } } else if ( e.tagName() == "iconset" ) { v = "QIconSet( %1 )"; QString s = e.firstChild().toText().data(); if ( !pixmapLoaderFunction.isEmpty() ) { s.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "" ) ); s.append( QString( externPixmaps ? "\"" : "" ) + " )" ); } v = v.arg( s ); } else if ( e.tagName() == "image" ) { v = e.firstChild().toText().data() + ".convertToImage()"; } else if ( e.tagName() == "enum" ) { if ( stdset ) v = "%1::%2"; else v = "\"%1\""; QString oc = objClass; QString ev = e.firstChild().toText().data(); if ( oc == "QListView" && ev == "Manual" ) // #### workaround, rename QListView::Manual in 4.0 oc = "QScrollView"; if ( stdset ) v = v.arg( oc ).arg( ev ); else v = v.arg( ev ); } else if ( e.tagName() == "set" ) { QString keys( e.firstChild().toText().data() ); QStringList lst = QStringList::split( '|', keys ); v = "int( "; QStringList::Iterator it = lst.begin(); while ( it != lst.end() ) { v += objClass + "::" + *it; if ( it != lst.fromLast() ) v += " | "; ++it; } v += " )"; } else if ( e.tagName() == "sizepolicy" ) { QDomElement n3 = e.firstChild().toElement(); QSizePolicy sp; while ( !n3.isNull() ) { if ( n3.tagName() == "hsizetype" ) sp.setHorData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "vsizetype" ) sp.setVerData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "horstretch" ) sp.setHorStretch( n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "verstretch" ) sp.setVerStretch( n3.firstChild().toText().data().toInt() ); n3 = n3.nextSibling().toElement(); } QString tmp; if ( !obj.isEmpty() ) tmp = obj + "->"; v = "QSizePolicy( (QSizePolicy::SizeType)%1, (QSizePolicy::SizeType)%2, %3, %4, " + tmp + "sizePolicy().hasHeightForWidth() )"; v = v.arg( (int)sp.horData() ).arg( (int)sp.verData() ).arg( sp.horStretch() ).arg( sp.verStretch() ); } else if ( e.tagName() == "palette" ) { QPalette pal; bool no_pixmaps = e.elementsByTagName( "pixmap" ).count() == 0; QDomElement n; if ( no_pixmaps ) { n = e.firstChild().toElement(); while ( !n.isNull() ) { QColorGroup cg; if ( n.tagName() == "active" ) { cg = loadColorGroup( n ); pal.setActive( cg ); } else if ( n.tagName() == "inactive" ) { cg = loadColorGroup( n ); pal.setInactive( cg ); } else if ( n.tagName() == "disabled" ) { cg = loadColorGroup( n ); pal.setDisabled( cg ); } n = n.nextSibling().toElement(); } } if ( no_pixmaps && pal == QPalette( pal.active().button(), pal.active().background() ) ) { v = "QPalette( QColor( %1, %2, %3 ), QColor( %1, %2, %3 ) )"; v = v.arg( pal.active().button().red() ).arg( pal.active().button().green() ).arg( pal.active().button().blue() ); v = v.arg( pal.active().background().red() ).arg( pal.active().background().green() ).arg( pal.active().background().blue() ); } else { QString palette = "pal"; if ( !pal_used ) { out << indent << "QPalette " << palette << ";" << endl; pal_used = TRUE; } QString cg = "cg"; if ( !cg_used ) { out << indent << "QColorGroup " << cg << ";" << endl; cg_used = TRUE; } n = e.firstChild().toElement(); while ( !n.isNull() && n.tagName() != "active" ) n = n.nextSibling().toElement(); createColorGroupImpl( cg, n ); out << indent << palette << ".setActive( " << cg << " );" << endl; n = e.firstChild().toElement(); while ( !n.isNull() && n.tagName() != "inactive" ) n = n.nextSibling().toElement(); createColorGroupImpl( cg, n ); out << indent << palette << ".setInactive( " << cg << " );" << endl; n = e.firstChild().toElement(); while ( !n.isNull() && n.tagName() != "disabled" ) n = n.nextSibling().toElement(); createColorGroupImpl( cg, n ); out << indent << palette << ".setDisabled( " << cg << " );" << endl; v = palette; } } else if ( e.tagName() == "cursor" ) { v = "QCursor( %1 )"; v = v.arg( e.firstChild().toText().data() ); } else if ( e.tagName() == "date" ) { QDomElement n3 = e.firstChild().toElement(); int y, m, d; y = m = d = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "year" ) y = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "month" ) m = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "day" ) d = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } v = "QDate( %1, %2, %3 )"; v = v.arg(y).arg(m).arg(d); } else if ( e.tagName() == "time" ) { QDomElement n3 = e.firstChild().toElement(); int h, m, s; h = m = s = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "hour" ) h = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "minute" ) m = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "second" ) s = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } v = "QTime( %1, %2, %3 )"; v = v.arg(h).arg(m).arg(s); } else if ( e.tagName() == "datetime" ) { QDomElement n3 = e.firstChild().toElement(); int h, mi, s, y, mo, d; h = mi = s = y = mo = d = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "hour" ) h = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "minute" ) mi = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "second" ) s = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "year" ) y = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "month" ) mo = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "day" ) d = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } v = "QDateTime( QDate( %1, %2, %3 ), QTime( %4, %5, %6 ) )"; v = v.arg(y).arg(mo).arg(d).arg(h).arg(mi).arg(s); } else if ( e.tagName() == "stringlist" ) { QStringList l; QDomElement n3 = e.firstChild().toElement(); QString listname = "l"; if ( !obj.isEmpty() ) { listname = obj + "_stringlist"; listname = registerObject( listname ); out << indent << "QStringList " << listname << ";" << endl; } else { listname = registerObject( listname ); out << indent << "QStringList " << listname << ";" << endl; } while ( !n3.isNull() ) { if ( n3.tagName() == "string" ) out << indent << listname << " << \"" << n3.firstChild().toText().data().simplifyWhiteSpace() << "\";" << endl; n3 = n3.nextSibling().toElement(); } v = listname; } return v; }
/*! Interprets element \a e as variant and returns the result of the interpretation. */ QVariant DomTool::elementToVariant( const QDomElement& e, const QVariant& defValue, QString &comment ) { QVariant v; if ( e.tagName() == "rect" ) { QDomElement n3 = e.firstChild().toElement(); int x = 0, y = 0, w = 0, h = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "x" ) x = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "y" ) y = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "width" ) w = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "height" ) h = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } v = QVariant( QRect( x, y, w, h ) ); } else if ( e.tagName() == "point" ) { QDomElement n3 = e.firstChild().toElement(); int x = 0, y = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "x" ) x = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "y" ) y = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } v = QVariant( QPoint( x, y ) ); } else if ( e.tagName() == "size" ) { QDomElement n3 = e.firstChild().toElement(); int w = 0, h = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "width" ) w = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "height" ) h = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } v = QVariant( QSize( w, h ) ); } else if ( e.tagName() == "color" ) { v = QVariant( readColor( e ) ); } else if ( e.tagName() == "font" ) { QDomElement n3 = e.firstChild().toElement(); QFont f( defValue.toFont() ); while ( !n3.isNull() ) { if ( n3.tagName() == "family" ) f.setFamily( n3.firstChild().toText().data() ); else if ( n3.tagName() == "pointsize" ) f.setPointSize( n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "bold" ) f.setBold( n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "italic" ) f.setItalic( n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "underline" ) f.setUnderline( n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "strikeout" ) f.setStrikeOut( n3.firstChild().toText().data().toInt() ); n3 = n3.nextSibling().toElement(); } v = QVariant( f ); } else if ( e.tagName() == "string" ) { v = QVariant( e.firstChild().toText().data() ); QDomElement n = e; n = n.nextSibling().toElement(); if ( n.tagName() == "comment" ) comment = n.firstChild().toText().data(); } else if ( e.tagName() == "cstring" ) { v = QVariant( QCString( e.firstChild().toText().data() ) ); } else if ( e.tagName() == "number" ) { bool ok = TRUE; v = QVariant( e.firstChild().toText().data().toInt( &ok ) ); if ( !ok ) v = QVariant( e.firstChild().toText().data().toDouble() ); } else if ( e.tagName() == "bool" ) { QString t = e.firstChild().toText().data(); v = QVariant( t == "true" || t == "1", 0 ); } else if ( e.tagName() == "pixmap" ) { v = QVariant( e.firstChild().toText().data() ); } else if ( e.tagName() == "iconset" ) { v = QVariant( e.firstChild().toText().data() ); } else if ( e.tagName() == "image" ) { v = QVariant( e.firstChild().toText().data() ); } else if ( e.tagName() == "enum" ) { v = QVariant( e.firstChild().toText().data() ); } else if ( e.tagName() == "set" ) { v = QVariant( e.firstChild().toText().data() ); } else if ( e.tagName() == "sizepolicy" ) { QDomElement n3 = e.firstChild().toElement(); QSizePolicy sp; while ( !n3.isNull() ) { if ( n3.tagName() == "hsizetype" ) sp.setHorData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "vsizetype" ) sp.setVerData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "horstretch" ) sp.setHorStretch( n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "verstretch" ) sp.setVerStretch( n3.firstChild().toText().data().toInt() ); n3 = n3.nextSibling().toElement(); } v = QVariant( sp ); } else if ( e.tagName() == "cursor" ) { v = QVariant( QCursor( e.firstChild().toText().data().toInt() ) ); } else if ( e.tagName() == "stringlist" ) { QStringList lst; QDomElement n; for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) lst << n.firstChild().toText().data(); v = QVariant( lst ); } else if ( e.tagName() == "date" ) { QDomElement n3 = e.firstChild().toElement(); int y, m, d; y = m = d = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "year" ) y = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "month" ) m = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "day" ) d = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } v = QVariant( QDate( y, m, d ) ); } else if ( e.tagName() == "time" ) { QDomElement n3 = e.firstChild().toElement(); int h, m, s; h = m = s = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "hour" ) h = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "minute" ) m = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "second" ) s = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } v = QVariant( QTime( h, m, s ) ); } else if ( e.tagName() == "datetime" ) { QDomElement n3 = e.firstChild().toElement(); int h, mi, s, y, mo, d ; h = mi = s = y = mo = d = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "hour" ) h = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "minute" ) mi = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "second" ) s = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "year" ) y = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "month" ) mo = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "day" ) d = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } v = QVariant( QDateTime( QDate( y, mo, d ), QTime( h, mi, s ) ) ); } return v; }
bool DomConvenience::elementToVariant(const QDomElement& e, QVariant& v) { bool ok = false; if (e.tagName() == "string") { if (e.hasAttribute("value")) { v = QVariant(e.attribute("value")); ok = true; } else qWarning("%s element without value!", (const char*)e.tagName()); } else if (e.tagName() == "int") { int base = getBase(e); if (e.hasAttribute("value")) v = QVariant(e.attribute("value").toInt(&ok, base)); else qWarning("%s element without value!", (const char*)e.tagName()); } else if (e.tagName() == "uint") { int base = getBase(e); if (e.hasAttribute("value")) v = QVariant(e.attribute("value").toUInt(&ok, base)); else qWarning("%s element without value!", (const char*)e.tagName()); } else if (e.tagName() == "double") { if (e.hasAttribute("value")) v = QVariant(e.attribute("value").toDouble(&ok)); else qWarning("%s element without value!", (const char*)e.tagName()); } else if (e.tagName() == "bool") { if (e.hasAttribute("value")) { QString val = e.attribute("value"); v = QVariant(getBoolFromString(val, ok), 0); if (!ok) qWarning("%s element with bogus value '%s'!", (const char*)e.tagName(), (const char*)val); } else qWarning("%s element without value!", (const char*)e.tagName()); } else if (e.tagName() == "color") { QColor color = getColor(e); ok = color.isValid(); v = color; if (!ok) qWarning("%s element without valid value!", (const char*)e.tagName()); } else if (e.tagName() == "pen") { int base = getBase(e); uint w = 0; Qt::PenStyle s = Qt::SolidLine; Qt::PenCapStyle c = Qt::SquareCap; Qt::PenJoinStyle j = Qt::BevelJoin; QColor color = getColor(e); if (e.hasAttribute("style")) s = (Qt::PenStyle)e.attribute("style").toInt(0, base); if (e.hasAttribute("cap")) c = (Qt::PenCapStyle)e.attribute("cap").toInt(0, base); if (e.hasAttribute("join")) j = (Qt::PenJoinStyle)e.attribute("join").toInt(0, base); ok = color.isValid(); v = QPen(color, w, s, c, j); if (!ok) qWarning("%s element without valid value!", (const char*)e.tagName()); } else if (e.tagName() == "brush") { int base = getBase(e); QColor color = getColor(e); Qt::BrushStyle s = Qt::SolidPattern; if (e.hasAttribute("style")) s = (Qt::BrushStyle)e.attribute("style").toInt(0, base); ok = color.isValid(); v = QBrush(color, s); if (!ok) qWarning("%s element without valid value!", (const char*)e.tagName()); } else if (e.tagName() == "point") { int base = getBase(e); bool coordOk; int x = 0, y = 0; if (e.hasAttribute("x")) x = e.attribute("x").toInt(&coordOk, base); if (e.hasAttribute("y")) y = e.attribute("y").toInt(&coordOk, base); v = QVariant(QPoint(x, y)); ok = true; } else if (e.tagName() == "rect") { int base = getBase(e); bool coordOk; int x = 0, y = 0, width = 0, height = 0; if (e.hasAttribute("x")) x = e.attribute("x").toInt(&coordOk, base); if (e.hasAttribute("y")) y = e.attribute("y").toInt(&coordOk, base); if (e.hasAttribute("width")) width = e.attribute("width").toInt(&coordOk, base); if (e.hasAttribute("height")) height = e.attribute("height").toInt(&coordOk, base); v = QVariant(QRect(x, y, width, height)); ok = true; } else if (e.tagName() == "size") { int base = getBase(e); bool coordOk; int width = 0, height = 0; if (e.hasAttribute("width")) width = e.attribute("width").toInt(&coordOk, base); if (e.hasAttribute("height")) height = e.attribute("height").toInt(&coordOk, base); v = QVariant(QSize(width, height)); ok = true; } else if (e.tagName() == "key") { int key; if (e.hasAttribute("sequence")) { key = QAccel::stringToKey(e.attribute("sequence")); // fix the key code (deal with Qt brain death) key &= ~Qt::UNICODE_ACCEL; #if QT_VERSION >= 300 v = QVariant(QKeySequence(key)); #else v = QVariant(key); #endif ok = true; } } else if (e.tagName() == "font") { QFont f; bool boolOk; if (e.hasAttribute("family")) f.setFamily(e.attribute("family")); if (e.hasAttribute("pointsize")) f.setPointSize(e.attribute("pointsize").toInt()); if (e.hasAttribute("bold")) f.setBold(getBoolFromString(e.attribute("bold"), boolOk)); if (e.hasAttribute("italic")) f.setItalic(getBoolFromString(e.attribute("italic"), boolOk)); if (e.hasAttribute("strikeout")) f.setStrikeOut(getBoolFromString(e.attribute("strikeout"), boolOk)); v = QVariant(f); ok = true; } else if (e.tagName() == "sizepolicy") { QSizePolicy sp; if (e.hasAttribute("hsizetype")) sp.setHorData((QSizePolicy::SizeType)e.attribute("hsizetype").toInt()); if (e.hasAttribute("vsizetype")) sp.setVerData((QSizePolicy::SizeType)e.attribute("vsizetype").toInt()); #if (QT_VERSION >= 300) if (e.hasAttribute("horstretch")) sp.setHorStretch(e.attribute("horstretch").toInt()); if (e.hasAttribute("verstretch")) sp.setHorStretch(e.attribute("verstretch").toInt()); #endif v = QVariant(sp); ok = true; } else if (e.tagName() == "cursor") { if (e.hasAttribute("shape")) v = QVariant(QCursor(e.attribute("shape").toInt(&ok, 10))); else qWarning("%s element without value!", (const char*)e.tagName()); } else if (e.tagName() == "stringlist") { QDomNodeList stringNodeList = e.elementsByTagName("string"); QStringList stringList; QDomElement stringElement; for (uint i = 0; i < stringNodeList.length(); i++) { stringElement = stringNodeList.item(i).toElement(); if (!stringElement.hasAttribute("value")) { qWarning("%s element in %s without value! Ignoring!", (const char*)stringElement.tagName(), (const char*)e.tagName()); continue; } stringList.append(e.attribute("value")); } v = stringList; ok = true; } else if (e.tagName() == "uint64") { QString value = e.attribute("value"); // borrowed more or less from Qt 3.2 (since we have to support older) uint64_t val = 0; const QChar* p = value.unicode(); int l = value.length(); const uint64_t max_mult = UINT64_MAX / 16; if (!p) { qWarning("Invalid value for tag: %s", (const char*)e.tagName()); return false; } while ( l && p->isSpace() ) // skip leading space l--,p++; if ( !l ) return false; if ( *p == '+' ) l--,p++; if ( !l || !ok_in_hex(*p) ) return false; while ( l && ok_in_hex(*p) ) { l--; uint dv; if ( p->isDigit() ) dv = p->digitValue(); else { if ( *p >= 'a' && *p <= 'f' ) dv = *p - 'a' + 10; else dv = *p - 'A' + 10; } if ( val > max_mult || (val == max_mult && dv > UINT64_MAX % 16) ) return false; val = 16 * val + dv; p++; } QByteArray ba; ba.duplicate((const char*)&val, sizeof(uint64_t)); v = ba; ok = true; } else if (e.tagName() == "list") { qWarning("Unimplemented tag: %s", (const char*)e.tagName()); } else if (e.tagName() == "map") { qWarning("Unimplemented tag: %s", (const char*)e.tagName()); } else { qWarning("Unknown tag: %s", (const char*)e.tagName()); } return ok; }
bool DomConvenience::elementToVariant(const QDomElement& e, QVariant& v) { bool ok = false; if (e.tagName() == "string") { if (e.hasAttribute("value")) { v = QVariant(e.attribute("value")); ok = true; } else qWarning("%s element without value!", (const char*)e.tagName()); } else if (e.tagName() == "int") { int base = getBase(e); if (e.hasAttribute("value")) v = QVariant(e.attribute("value").toInt(&ok, base)); else qWarning("%s element without value!", (const char*)e.tagName()); } else if (e.tagName() == "uint") { int base = getBase(e); if (e.hasAttribute("value")) v = QVariant(e.attribute("value").toUInt(&ok, base)); else qWarning("%s element without value!", (const char*)e.tagName()); } else if (e.tagName() == "double") { if (e.hasAttribute("value")) v = QVariant(e.attribute("value").toDouble(&ok)); else qWarning("%s element without value!", (const char*)e.tagName()); } else if (e.tagName() == "bool") { if (e.hasAttribute("value")) { QString val = e.attribute("value"); v = QVariant(getBoolFromString(val, ok), 0); if (!ok) qWarning("%s element with bogus value '%s'!", (const char*)e.tagName(), (const char*)val); } else qWarning("%s element without value!", (const char*)e.tagName()); } else if (e.tagName() == "color") { QColor color = getColor(e); ok = color.isValid(); v = color; if (!ok) qWarning("%s element without valid value!", (const char*)e.tagName()); } else if (e.tagName() == "point") { int base = getBase(e); bool coordOk; int x = 0, y = 0; if (e.hasAttribute("x")) x = e.attribute("x").toInt(&coordOk, base); if (e.hasAttribute("y")) y = e.attribute("y").toInt(&coordOk, base); v = QVariant(QPoint(x, y)); ok = true; } else if (e.tagName() == "rect") { int base = getBase(e); bool coordOk; int x = 0, y = 0, width = 0, height = 0; if (e.hasAttribute("x")) x = e.attribute("x").toInt(&coordOk, base); if (e.hasAttribute("y")) y = e.attribute("y").toInt(&coordOk, base); if (e.hasAttribute("width")) width = e.attribute("width").toInt(&coordOk, base); if (e.hasAttribute("height")) height = e.attribute("height").toInt(&coordOk, base); v = QVariant(QRect(x, y, width, height)); ok = true; } else if (e.tagName() == "size") { int base = getBase(e); bool coordOk; int width = 0, height = 0; if (e.hasAttribute("width")) width = e.attribute("width").toInt(&coordOk, base); if (e.hasAttribute("height")) height = e.attribute("height").toInt(&coordOk, base); v = QVariant(QSize(width, height)); ok = true; } else if (e.tagName() == "key") { int key; if (e.hasAttribute("sequence")) { key = QAccel::stringToKey(e.attribute("sequence")); // fix the key code (deal with Qt brain death) key &= ~Qt::UNICODE_ACCEL; #if QT_VERSION >= 300 v = QVariant(QKeySequence(key)); #else v = QVariant(key); #endif ok = true; } } else if (e.tagName() == "font") { QFont f; bool boolOk; if (e.hasAttribute("family")) f.setFamily(e.attribute("family")); if (e.hasAttribute("pointsize")) f.setPointSize(e.attribute("pointsize").toInt()); if (e.hasAttribute("bold")) f.setBold(getBoolFromString(e.attribute("bold"), boolOk)); if (e.hasAttribute("italic")) f.setItalic(getBoolFromString(e.attribute("italic"), boolOk)); if (e.hasAttribute("strikeout")) f.setStrikeOut(getBoolFromString(e.attribute("strikeout"), boolOk)); v = QVariant(f); ok = true; } else if (e.tagName() == "sizepolicy") { QSizePolicy sp; if (e.hasAttribute("hsizetype")) sp.setHorData((QSizePolicy::SizeType)e.attribute("hsizetype").toInt()); if (e.hasAttribute("vsizetype")) sp.setVerData((QSizePolicy::SizeType)e.attribute("vsizetype").toInt()); #if (QT_VERSION >= 300) if (e.hasAttribute("horstretch")) sp.setHorStretch(e.attribute("horstretch").toInt()); if (e.hasAttribute("verstretch")) sp.setHorStretch(e.attribute("verstretch").toInt()); #endif v = QVariant(sp); ok = true; } else if (e.tagName() == "cursor") { if (e.hasAttribute("shape")) v = QVariant(QCursor(e.attribute("shape").toUInt(&ok, 10))); else qWarning("%s element without value!", (const char*)e.tagName()); } else if (e.tagName() == "stringlist") { QDomNodeList stringNodeList = e.elementsByTagName("string"); QStringList stringList; QDomElement stringElement; for (uint i = 0; i < stringNodeList.length(); i++) { stringElement = stringNodeList.item(i).toElement(); if (!stringElement.hasAttribute("value")) { qWarning("%s element in %s without value! Ignoring!", (const char*)stringElement.tagName(), (const char*)e.tagName()); continue; } stringList.append(e.attribute("value")); } v = stringList; ok = true; } else if (e.tagName() == "list") { qWarning("Unimplemented tag: %s", (const char*)e.tagName()); } else if (e.tagName() == "map") { qWarning("Unimplemented tag: %s", (const char*)e.tagName()); } else { qWarning("Unknown tag: %s", (const char*)e.tagName()); } return ok; }