本文整理汇总了C++中QBuffer::buffer方法的典型用法代码示例。如果您正苦于以下问题:C++ QBuffer::buffer方法的具体用法?C++ QBuffer::buffer怎么用?C++ QBuffer::buffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBuffer
的用法示例。
在下文中一共展示了QBuffer::buffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveOdf
void KoPAMasterPage::saveOdf( KoShapeSavingContext & context ) const
{
KoPASavingContext &paContext = static_cast<KoPASavingContext&>( context );
KoGenStyle pageLayoutStyle = pageLayout().saveOdf();
pageLayoutStyle.setAutoStyleInStylesDotXml( true );
pageLayoutStyle.addAttribute( "style:page-usage", "all" );
QString pageLayoutName( paContext.mainStyles().insert( pageLayoutStyle, "pm" ) );
KoGenStyle pageMaster( KoGenStyle::MasterPageStyle );
pageMaster.addAttribute( "style:page-layout-name", pageLayoutName );
pageMaster.addAttribute( "style:display-name", name() );
pageMaster.addAttribute( "draw:style-name", saveOdfPageStyle( paContext ) );
KoXmlWriter &savedWriter = paContext.xmlWriter();
QBuffer buffer;
buffer.open( QIODevice::WriteOnly );
KoXmlWriter xmlWriter( &buffer );
paContext.setXmlWriter( xmlWriter );
saveOdfPageContent( paContext );
paContext.setXmlWriter( savedWriter );
QString contentElement = QString::fromUtf8( buffer.buffer(), buffer.buffer().size() );
pageMaster.addChildElement( paContext.masterPageElementName(), contentElement );
paContext.addMasterPage( this, paContext.mainStyles().insert( pageMaster, "Default" ) );
}
示例2: style
const QString Filterkpr2odf::createMasterPageStyle(const KXmlNode & objects, const KXmlElement & masterBackground)
{
//KXmlElement header( m_mainDoc.namedItem( "DOC" ).namedItem( "HEADER" ).toElement() );
//KXmlElement footer( m_mainDoc.namedItem( "DOC" ).namedItem( "FOOTER" ).toElement() );
// set that we work on master
m_sticky = true;
KOdfGenericStyle style(KOdfGenericStyle::MasterPageStyle, "");
style.addAttribute("style:page-layout-name", createPageLayout());
style.addAttribute("draw:style-name", createPageStyle(masterBackground));
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
KXmlWriter xmlWriter(&buffer);
convertObjects(&xmlWriter, objects);
m_sticky = false;
QString contentElement = QString::fromUtf8(buffer.buffer(), buffer.buffer().size());
style.addChildElement("master", contentElement);
return m_styles.insert(style, "Default");
}
示例3: writeReadElement
Element* MTest::writeReadElement(Element* element)
{
//
// write element
//
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
Xml xml(&buffer);
xml.header();
element->write(xml);
buffer.close();
//
// read element
//
// printf("%s\n", buffer.buffer().data());
QDomDocument doc;
int line, column;
QString err;
if (!doc.setContent(buffer.buffer(), &err, &line, &column)) {
printf("writeReadElement: error reading paste data at line %d column %d: %s\n",
line, column, qPrintable(err));
printf("%s\n", buffer.buffer().data());
return 0;
}
docName = "--";
QDomElement e = doc.documentElement();
QString tag(e.tagName());
element = Element::name2Element(e.tagName(), score);
element->read(e);
return element;
}
示例4: QVERIFY
void PSDUtilsTest::test_psdwrite_quint8()
{
QBuffer buf;
buf.open(QBuffer::ReadWrite);
quint8 i = 3;
QVERIFY(psdwrite(&buf, i));
QCOMPARE(buf.buffer().size(), 1);
QCOMPARE(buf.buffer().at(0), '\3');
}
示例5: test_psdwrite_qstring
void PSDUtilsTest::test_psdwrite_qstring()
{
QBuffer buf;
buf.open(QBuffer::ReadWrite);
QString s = "8BPS";
QVERIFY(psdwrite(&buf, s));
QCOMPARE(buf.buffer().size(), 4);
QCOMPARE(buf.buffer().at(0), '8');
QCOMPARE(buf.buffer().at(1), 'B');
QCOMPARE(buf.buffer().at(2), 'P');
QCOMPARE(buf.buffer().at(3), 'S');
}
示例6: test_psdpad
void PSDUtilsTest::test_psdpad()
{
QBuffer buf;
buf.open(QBuffer::ReadWrite);
QVERIFY(psdpad(&buf, 6));
QCOMPARE(buf.buffer().size(), 6);
QCOMPARE(buf.buffer().at(0), '\0');
QCOMPARE(buf.buffer().at(1), '\0');
QCOMPARE(buf.buffer().at(2), '\0');
QCOMPARE(buf.buffer().at(3), '\0');
QCOMPARE(buf.buffer().at(4), '\0');
QCOMPARE(buf.buffer().at(5), '\0');
}
示例7: verifyDeserialise
bool DataBlobVerify::verifyDeserialise() const {
_serialise();
static FactoryGeneric<DataBlob> factory(true);
DataBlob* copy = factory.create( _blob->type() );
QByteArray tmp( _buffer.data() );
QBuffer buffer2( &tmp );
buffer2.open( QBuffer::ReadOnly );
copy->deserialise( buffer2, QSysInfo::ByteOrder );
QBuffer copyBuffer;
copyBuffer.open(QBuffer::WriteOnly);
copy->serialise( copyBuffer );
if( copyBuffer.buffer().size() == 0 ) return false;
return copyBuffer.buffer() == _buffer.buffer();
}
示例8: saveOdf
KOdfGenericStyle KWPageStyle::saveOdf() const
{
KOdfGenericStyle pageLayout = d->pageLayout.saveOdf();
pageLayout.setAutoStyleInStylesDotXml(true);
pageLayout.addAttribute("style:page-usage", "all");
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
KXmlWriter writer(&buffer);
if (d->columns.columns > 1) {
writer.startElement("style:columns");
writer.addAttribute("fo:column-count", d->columns.columns);
writer.addAttributePt("fo:column-gap", d->columns.columnSpacing);
writer.endElement();
}
//<style:footnote-sep style:adjustment="left" style:width="0.5pt" style:rel-width="20%" style:line-style="solid"/>
//writer.startElement("style:footnote-sep");
// TODO
//writer.addAttribute("style:adjustment",)
//writer.addAttribute("style:width",)
//writer.addAttribute("style:rel-width",)
//writer.addAttribute("style:line-style",)
//writer.endElement();
// TODO save background
QString contentElement = QString::fromUtf8(buffer.buffer(), buffer.buffer().size());
pageLayout.addChildElement("columnsEnzo", contentElement);
if (headerPolicy() != KWord::HFTypeNone) {
pageLayout.addProperty("style:dynamic-spacing", d->fixedHeaderSize, KOdfGenericStyle::PageHeaderType);
pageLayout.addPropertyPt("fo:min-height", d->headerMinimumHeight, KOdfGenericStyle::PageHeaderType);
saveInsets(d->headerMargin, pageLayout, "fo:margin", KOdfGenericStyle::PageHeaderType);
saveInsets(d->headerInsets, pageLayout, "fo:padding", KOdfGenericStyle::PageHeaderType);
}
if (footerPolicy() != KWord::HFTypeNone) {
pageLayout.addProperty("style:dynamic-spacing", d->fixedFooterSize, KOdfGenericStyle::PageFooterType);
pageLayout.addPropertyPt("fo:min-height", d->footerMinimumHeight, KOdfGenericStyle::PageFooterType);
saveInsets(d->footerMargin, pageLayout, "fo:margin", KOdfGenericStyle::PageFooterType);
saveInsets(d->footerInsets, pageLayout, "fo:padding", KOdfGenericStyle::PageFooterType);
}
// TODO see how we should save margins if we use the 'closest to binding' stuff.
return pageLayout;
}
示例9: readPointerAtPositionWriteRead
void tst_QRingBuffer::readPointerAtPositionWriteRead()
{
//create some data
QBuffer inData;
inData.open(QIODevice::ReadWrite);
inData.putChar(0x42);
inData.putChar(0x23);
inData.write("Qt rocks!");
for (int i = 0; i < 5000; i++)
inData.write(QString("Number %1").arg(i).toUtf8());
inData.reset();
QVERIFY(inData.size() > 0);
//put the inData in the QRingBuffer
QRingBuffer ringBuffer;
qint64 remaining = inData.size();
while (remaining > 0) {
// write in chunks of 50 bytes
// this ensures there will be multiple QByteArrays inside the QRingBuffer
// since QRingBuffer is then only using individual arrays of around 4000 bytes
qint64 thisWrite = qMin(remaining, qint64(50));
char *pos = ringBuffer.reserve(thisWrite);
inData.read(pos, thisWrite);
remaining -= thisWrite;
}
// was data put into it?
QVERIFY(ringBuffer.size() > 0);
QCOMPARE(qint64(ringBuffer.size()), inData.size());
//read from the QRingBuffer in loop, put back into another QBuffer
QBuffer outData;
outData.open(QIODevice::ReadWrite);
remaining = ringBuffer.size();
while (remaining > 0) {
qint64 thisRead;
// always try to read as much as possible
const char *buf = ringBuffer.readPointerAtPosition(ringBuffer.size() - remaining, thisRead);
outData.write(buf, thisRead);
remaining -= thisRead;
}
outData.reset();
QVERIFY(outData.size() > 0);
// was the data read from the QRingBuffer the same as the one written into it?
QCOMPARE(outData.size(), inData.size());
QVERIFY(outData.buffer().startsWith(inData.buffer()));
}
示例10: cipher
void TestSymmetricCipher::testAes256CbcEncryption()
{
// http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
QByteArray key = QByteArray::fromHex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
QByteArray iv = QByteArray::fromHex("000102030405060708090a0b0c0d0e0f");
QByteArray plainText = QByteArray::fromHex("6bc1bee22e409f96e93d7e117393172a");
plainText.append(QByteArray::fromHex("ae2d8a571e03ac9c9eb76fac45af8e51"));
QByteArray cipherText = QByteArray::fromHex("f58c4c04d6e5f1ba779eabfb5f7bfbd6");
cipherText.append(QByteArray::fromHex("9cfc4e967edb808d679f777bc6702c7d"));
bool ok;
SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Encrypt);
QVERIFY(cipher.init(key, iv));
QCOMPARE(cipher.blockSize(), 16);
QCOMPARE(cipher.process(plainText, &ok),
cipherText);
QVERIFY(ok);
QBuffer buffer;
SymmetricCipherStream stream(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
SymmetricCipher::Encrypt);
QVERIFY(stream.init(key, iv));
buffer.open(QIODevice::WriteOnly);
QVERIFY(stream.open(QIODevice::WriteOnly));
QVERIFY(stream.reset());
buffer.reset();
buffer.buffer().clear();
QCOMPARE(stream.write(plainText.left(16)), qint64(16));
QCOMPARE(buffer.data(), cipherText.left(16));
QVERIFY(stream.reset());
// make sure padding is written
QCOMPARE(buffer.data().size(), 32);
buffer.reset();
buffer.buffer().clear();
QCOMPARE(stream.write(plainText.left(10)), qint64(10));
QVERIFY(buffer.data().isEmpty());
QVERIFY(stream.reset());
buffer.reset();
buffer.buffer().clear();
QCOMPARE(stream.write(plainText.left(10)), qint64(10));
stream.close();
QCOMPARE(buffer.data().size(), 16);
}
示例11: dataExport
void dataExport() {
QFETCH(QString, fileIn);
QFETCH(QString, fileOut);
QFETCH(QString, exportPrefix);
QFETCH(QList<QLandmark>, waypoints);
QFETCH(QList<QList<QLandmark> >, tracks);
QFETCH(QList<QList<QLandmark> >, routes);
m_handler->setWaypoints(waypoints);
m_handler->setTracks(tracks);
m_handler->setRoutes(routes);
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
QVERIFY(m_handler->exportData(&buffer, exportPrefix));
QByteArray dataExported = buffer.buffer();
buffer.close();
QFile file(fileOut);
file.open(QIODevice::ReadOnly);
QByteArray testData = file.readAll();
file.close();
QCOMPARE(dataExported, testData);
}
示例12: t
QString FLUtil::sha1( const QString & str ) {
QBuffer b;
b.open( IO_WriteOnly );
QTextStream t( &b );
t << str;
b.close();
FLSha1 sha1;
sha1.Update(( unsigned char * ) b.buffer().data(), b.buffer().size() );
sha1.Final();
char strC[ 255 ];
strC[ 0 ] = '\0';
sha1.ReportHash( strC );
return strC;
}
示例13: packageDataWritten
void HttpInfoReceiver::packageDataWritten( qint64 bytes )
{
if ( fetcher->httpRequestAborted )
return;
fetcher->packageData->close();
fetcher->packageData->open( QIODevice::ReadOnly );
while ( true )
{
lineString += fetcher->packageData->readLine( bytes );
if ( !lineString.contains( "\n" ))
{
goto out_recv_data;
}
reader->readLine( lineString );
lineString = "";
}
out_recv_data:
fetcher->packageData->close();
//if downloading a package list clear buffer
QBuffer *buf = qobject_cast<QBuffer *>(fetcher->packageData);
if ( buf )
buf->buffer().clear();
fetcher->packageData->open( QIODevice::WriteOnly );
}
示例14: testPadding
void TestSymmetricCipher::testPadding()
{
QByteArray key = QByteArray::fromHex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
QByteArray iv = QByteArray::fromHex("000102030405060708090a0b0c0d0e0f");
QByteArray plainText = QByteArray::fromHex("6bc1bee22e409f96e93d");
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
SymmetricCipherStream streamEnc(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
SymmetricCipher::Encrypt);
QVERIFY(streamEnc.init(key, iv));
streamEnc.open(QIODevice::WriteOnly);
streamEnc.write(plainText);
streamEnc.close();
buffer.reset();
// make sure padding is written
QCOMPARE(buffer.buffer().size(), 16);
SymmetricCipherStream streamDec(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
SymmetricCipher::Decrypt);
QVERIFY(streamDec.init(key, iv));
streamDec.open(QIODevice::ReadOnly);
QByteArray decrypted = streamDec.readAll();
QCOMPARE(decrypted, plainText);
}
示例15: read_xml
KoFilter::ConversionStatus VmlDrawingReader::read_xml()
{
unsigned index = 0;
KoXmlWriter *oldBody = 0;
while (!atEnd()) {
readNext();
if (isEndElement() && qualifiedName() == "xml") {
break;
}
if (isStartElement()) {
if (name() == "shapetype") {
TRY_READ(shapetype)
}
else if (name() == "shape") {
oldBody = body; // Body protetion starts
QBuffer frameBuf;
KoXmlWriter frameWriter(&frameBuf);
body = &frameWriter;
TRY_READ(shape) //from vml
m_content[m_currentVMLProperties.currentShapeId] = m_currentVMLProperties.imagedataPath;
pushCurrentDrawStyle(new KoGenStyle(KoGenStyle::GraphicAutoStyle, "graphic"));
createFrameStart();
popCurrentDrawStyle();
m_frames[m_currentVMLProperties.currentShapeId] = QString::fromUtf8(frameBuf.buffer(), frameBuf.buffer().size()).append(">");
body = oldBody; // Body protection ends
++index;
}
}
}
return KoFilter::OK;
}