bool QSvgIconEngine::read(QDataStream &in) { d = new QSvgIconEnginePrivate; d->svgBuffers = new QHash<int, QByteArray>; if (in.version() >= QDataStream::Qt_4_4) { int isCompressed; QHash<int, QString> fileNames; // For memoryoptimization later in >> fileNames >> isCompressed >> *d->svgBuffers; #ifndef QT_NO_COMPRESS if (!isCompressed) { foreach(int key, d->svgBuffers->keys()) d->svgBuffers->insert(key, qCompress(d->svgBuffers->value(key))); }
void tst_QPicture::serialization() { QDataStream stream; const int thisVersion = stream.version(); for (int version = QDataStream::Qt_1_0; version <= thisVersion; ++version) { const QDataStream::Version versionEnum = static_cast<QDataStream::Version>(version); { // streaming of null pictures ensureSerializesCorrectly(QPicture(), versionEnum); } { // picture with a simple line, checking bitwise equality QPicture picture; QPainter painter(&picture); painter.drawLine(10, 20, 30, 40); ensureSerializesCorrectly(picture, versionEnum); } } { // Test features that were added after Qt 4.5, as that was hard-coded as the major // version for a while, which was incorrect. In this case, we'll test font hints. QPicture picture; QPainter painter; QFont font; font.setStyleName("Blah"); font.setHintingPreference(QFont::PreferFullHinting); painter.begin(&picture); painter.setFont(font); painter.drawText(20, 20, "Hello"); painter.end(); Picture customPicture; painter.begin(&customPicture); picture.play(&painter); const QFont actualFont = ((PaintEngine*)customPicture.paintEngine())->font(); painter.end(); QCOMPARE(actualFont.styleName(), QStringLiteral("Blah")); QCOMPARE(actualFont.hintingPreference(), QFont::PreferFullHinting); } }
void tst_QFont::serialize() { QFETCH(QFont, font); QFETCH(QDataStream::Version, minimumStreamVersion); QDataStream stream; const int thisVersion = stream.version(); for (int version = minimumStreamVersion; version <= thisVersion; ++version) { QBuffer buffer; buffer.open(QIODevice::WriteOnly); stream.setDevice(&buffer); stream.setVersion(version); stream << font; buffer.close(); buffer.open(QIODevice::ReadOnly); QFont readFont; stream >> readFont; QVERIFY2(readFont == font, qPrintable(QString::fromLatin1("Fonts do not compare equal for QDataStream version ") + QString::fromLatin1("%1:\nactual: %2\nexpected: %3").arg(version).arg(readFont.toString()).arg(font.toString()))); } }
void convertUiToUib( QDomDocument& doc, QDataStream& out ) { QByteArray introBlock; QByteArray actionsBlock; QByteArray buddiesBlock; QByteArray connectionsBlock; QByteArray functionsBlock; QByteArray imagesBlock; QByteArray menubarBlock; QByteArray slotsBlock; QByteArray tabstopsBlock; QByteArray toolbarsBlock; QByteArray variablesBlock; QByteArray widgetBlock; QDomElement actionsElem; QDomElement connectionsElem; QDomElement imagesElem; QDomElement menubarElem; QDomElement tabstopsElem; QDomElement toolbarsElem; QDomElement widgetElem; QMap<int, QStringList> buddies; UibStrTable strings; UibIndexMap objects; int widgetNo = -1; QCString className; Q_INT16 defaultMargin = -32768; Q_INT16 defaultSpacing = -32768; Q_UINT8 introFlags = 0; QDomElement elem = doc.firstChild().toElement().firstChild().toElement(); while ( !elem.isNull() ) { QString tag = elem.tagName(); switch ( tag[0].latin1() ) { case 'a': if ( tag == "actions" ) actionsElem = elem; break; case 'c': if ( tag == "class" ) { className = elem.firstChild().toText().data().latin1(); } else if ( tag == "connections" ) { connectionsElem = elem; } break; case 'f': if ( tag == "functions" ) { QDataStream out2( functionsBlock, IO_WriteOnly ); QDomElement f = elem.firstChild().toElement(); while ( !f.isNull() ) { if ( f.tagName() == "function" ) { packStringSplit( strings, out2, f.attribute("name").latin1(), '(' ); packString( strings, out2, f.firstChild().toText().data() ); } f = f.nextSibling().toElement(); } } break; case 'i': if ( tag == "images" ) { QDataStream out2( imagesBlock, IO_WriteOnly ); QDomElement f = elem.firstChild().toElement(); while ( !f.isNull() ) { if ( f.tagName() == "image" ) { QString name = f.attribute( "name" ); QDomElement g = f.firstChild().toElement(); if ( g.tagName() == "data" ) { QString format = g.attribute( "format", "PNG" ); QString hex = g.firstChild().toText().data(); int n = hex.length() / 2; QByteArray data( n ); for ( int i = 0; i < n; i++ ) data[i] = (char) hex.mid( 2 * i, 2 ) .toUInt( 0, 16 ); packString( strings, out2, name ); packString( strings, out2, format ); packUInt32( out2, g.attribute("length").toInt() ); packByteArray( out2, data ); } } f = f.nextSibling().toElement(); } } break; case 'l': if ( tag == "layoutdefaults" ) { QString margin = elem.attribute( "margin" ); if ( !margin.isEmpty() ) defaultMargin = margin.toInt(); QString spacing = elem.attribute( "spacing" ); if ( !spacing.isEmpty() ) defaultSpacing = spacing.toInt(); } break; case 'm': if ( tag == "menubar" ) menubarElem = elem; break; case 'p': if ( tag == "pixmapinproject" ) introFlags |= Intro_Pixmapinproject; break; case 's': if ( tag == "slots" ) { QDataStream out2( slotsBlock, IO_WriteOnly ); QDomElement f = elem.firstChild().toElement(); while ( !f.isNull() ) { if ( f.tagName() == "slot" ) { QString language = f.attribute( "language", "C++" ); QString slot = UibHack::normalize( f.firstChild().toText().data() ); packString( strings, out2, language ); packStringSplit( strings, out2, slot, '(' ); } f = f.nextSibling().toElement(); } } break; case 't': if ( tag == "tabstops" ) { tabstopsElem = elem; } else if ( tag == "toolbars" ) { toolbarsElem = elem; } break; case 'v': if ( tag == "variable" ) { QDataStream out2( variablesBlock, IO_WriteOnly | IO_Append ); packString( strings, out2, elem.firstChild().toText().data() ); } else if ( tag == "variables" ) { QDataStream out2( variablesBlock, IO_WriteOnly ); QDomElement f = elem.firstChild().toElement(); while ( !f.isNull() ) { if ( f.tagName() == "variable" ) packString( strings, out2, f.firstChild().toText().data() ); f = f.nextSibling().toElement(); } } break; case 'w': if ( tag == "widget" ) widgetElem = elem; } elem = elem.nextSibling().toElement(); } { QDataStream out2( widgetBlock, IO_WriteOnly ); widgetNo = outputObject( buddies, objects, strings, out2, widgetElem, "QWidget" ); } if ( !tabstopsElem.isNull() ) { QDataStream out2( tabstopsBlock, IO_WriteOnly ); QDomElement f = tabstopsElem.firstChild().toElement(); while ( !f.isNull() ) { if ( f.tagName() == "tabstop" ) { QString widgetName = f.firstChild().toText().data(); int no = objects.find( widgetName ); if ( no != -1 ) packUInt16( out2, no ); } f = f.nextSibling().toElement(); } } if ( !actionsElem.isNull() ) { QDataStream out2( actionsBlock, IO_WriteOnly ); outputObject( buddies, objects, strings, out2, actionsElem ); } if ( !menubarElem.isNull() ) { QDataStream out2( menubarBlock, IO_WriteOnly ); outputObject( buddies, objects, strings, out2, menubarElem, "QMenuBar" ); } if ( !toolbarsElem.isNull() ) { QDataStream out2( toolbarsBlock, IO_WriteOnly ); QDomElement f = toolbarsElem.firstChild().toElement(); while ( !f.isNull() ) { if ( f.tagName() == "toolbar" ) outputObject( buddies, objects, strings, out2, f, "QToolBar" ); f = f.nextSibling().toElement(); } } if ( !buddies.isEmpty() ) { QDataStream out2( buddiesBlock, IO_WriteOnly ); QMap<int, QStringList>::ConstIterator a = buddies.begin(); while ( a != buddies.end() ) { QStringList::ConstIterator b = (*a).begin(); while ( b != (*a).end() ) { int no = objects.find( *b ); if ( no != -1 ) { packUInt16( out2, a.key() ); packUInt16( out2, no ); } ++b; } ++a; } } if ( !connectionsElem.isNull() ) { QString prevLanguage = "C++"; int prevSenderNo = 0; QString prevSignal = "clicked()"; int prevReceiverNo = 0; QString prevSlot = "accept()"; QDataStream out2( connectionsBlock, IO_WriteOnly ); QDomElement f = connectionsElem.firstChild().toElement(); while ( !f.isNull() ) { if ( f.tagName() == "connection" ) { QMap<QString, QString> argMap; QDomElement g = f.firstChild().toElement(); while ( !g.isNull() ) { argMap[g.tagName()] = g.firstChild().toText().data(); g = g.nextSibling().toElement(); } QString language = f.attribute( "language", "C++" ); int senderNo = objects.find( argMap["sender"], widgetNo ); int receiverNo = objects.find( argMap["receiver"], widgetNo ); QString signal = UibHack::normalize( argMap["signal"] ); QString slot = UibHack::normalize( argMap["slot"] ); Q_UINT8 connectionFlags = 0; if ( language != prevLanguage ) connectionFlags |= Connection_Language; if ( senderNo != prevSenderNo ) connectionFlags |= Connection_Sender; if ( signal != prevSignal ) connectionFlags |= Connection_Signal; if ( receiverNo != prevReceiverNo ) connectionFlags |= Connection_Receiver; if ( slot != prevSlot ) connectionFlags |= Connection_Slot; out2 << connectionFlags; if ( connectionFlags & Connection_Language ) packString( strings, out2, language ); if ( connectionFlags & Connection_Sender ) packUInt16( out2, senderNo ); if ( connectionFlags & Connection_Signal ) packStringSplit( strings, out2, signal, '(' ); if ( connectionFlags & Connection_Receiver ) packUInt16( out2, receiverNo ); if ( connectionFlags & Connection_Slot ) packStringSplit( strings, out2, slot, '(' ); prevLanguage = language; prevSenderNo = senderNo; prevSignal = signal; prevReceiverNo = receiverNo; prevSlot = slot; } else if ( f.tagName() == "slot" ) { // ### } f = f.nextSibling().toElement(); } } { QDataStream out2( introBlock, IO_WriteOnly ); out2 << introFlags; out2 << defaultMargin; out2 << defaultSpacing; packUInt16( out2, objects.count() ); packCString( strings, out2, className ); } out << UibMagic; out << (Q_UINT8) '\n'; out << (Q_UINT8) '\r'; out << (Q_UINT8) out.version(); outputBlock( out, Block_Strings, strings.block() ); outputBlock( out, Block_Intro, introBlock ); outputBlock( out, Block_Images, imagesBlock ); outputBlock( out, Block_Widget, widgetBlock ); outputBlock( out, Block_Slots, slotsBlock ); outputBlock( out, Block_Tabstops, tabstopsBlock ); outputBlock( out, Block_Actions, actionsBlock ); outputBlock( out, Block_Menubar, menubarBlock ); outputBlock( out, Block_Toolbars, toolbarsBlock ); outputBlock( out, Block_Variables, variablesBlock ); outputBlock( out, Block_Functions, functionsBlock ); outputBlock( out, Block_Buddies, buddiesBlock ); outputBlock( out, Block_Connections, connectionsBlock ); out << (Q_UINT8) Block_End; }