--- a/qtmobility/src/versit/qversitreader.cpp Fri Apr 16 15:51:22 2010 +0300
+++ b/qtmobility/src/versit/qversitreader.cpp Mon May 03 13:18:40 2010 +0300
@@ -47,6 +47,7 @@
#include <QTextCodec>
#include <QMutexLocker>
+#include <QBuffer>
QTM_USE_NAMESPACE
@@ -95,14 +96,6 @@
*/
/*!
- * \fn QVersitReader::resultsAvailable(QList<QVersitDocument>& results)
- * \deprecated
- * The signal is emitted by the reader as it reads from the device when it has made more Versit
- * documents available.
- * \a results is the complete list of documents read so far.
- */
-
-/*!
* \fn QVersitReader::resultsAvailable()
* The signal is emitted by the reader as it reads from the device when it has made more Versit
* documents available.
@@ -111,12 +104,24 @@
/*! Constructs a new reader. */
QVersitReader::QVersitReader() : d(new QVersitReaderPrivate)
{
- connect(d, SIGNAL(stateChanged(QVersitReader::State)),
- this, SIGNAL(stateChanged(QVersitReader::State)),Qt::DirectConnection);
- connect(d, SIGNAL(resultsAvailable(QList<QVersitDocument>&)),
- this, SIGNAL(resultsAvailable(QList<QVersitDocument>&)), Qt::DirectConnection);
- connect(d, SIGNAL(resultsAvailable(QList<QVersitDocument>&)),
- this, SIGNAL(resultsAvailable()), Qt::DirectConnection);
+ d->init(this);
+}
+
+/*! Constructs a new reader that reads from \a inputDevice. */
+QVersitReader::QVersitReader(QIODevice *inputDevice) : d(new QVersitReaderPrivate)
+{
+ d->init(this);
+ d->mIoDevice = inputDevice;
+}
+
+/*! Constructs a new reader that reads from \a inputData. */
+QVersitReader::QVersitReader(const QByteArray &inputData) : d(new QVersitReaderPrivate)
+{
+ d->init(this);
+ d->mInputBytes.reset(new QBuffer);
+ d->mInputBytes->setData(inputData);
+ d->mInputBytes->open(QIODevice::ReadOnly);
+ d->mIoDevice = d->mInputBytes.data();
}
/*!
@@ -131,19 +136,37 @@
/*!
* Sets the device used for reading the input to be the given \a device.
- * Does not take ownership of the device.
+ * Does not take ownership of the device. This overrides any byte array input source set with
+ * setData().
*/
void QVersitReader::setDevice(QIODevice* device)
{
+ d->mInputBytes.reset(0);
d->mIoDevice = device;
}
/*!
- * Returns the device used for reading input.
+ * Returns the device used for reading input, or 0 if no device has been set (or if the input source
+ * was set with setData().
*/
QIODevice* QVersitReader::device() const
{
- return d->mIoDevice;
+ if (d->mInputBytes.isNull())
+ return d->mIoDevice;
+ else
+ return 0;
+}
+
+/*!
+ * Sets the data to read from to the byte array input source, \a inputData.
+ * This overrides any device set with setDevice().
+ */
+void QVersitReader::setData(const QByteArray &inputData)
+{
+ if (d->mInputBytes.isNull())
+ d->mInputBytes.reset(new QBuffer);
+ d->mInputBytes->setData(inputData);
+ d->mIoDevice = d->mInputBytes.data();
}
/*!
@@ -168,6 +191,22 @@
}
/*!
+ * Returns the state of the reader.
+ */
+QVersitReader::State QVersitReader::state() const
+{
+ return d->state();
+}
+
+/*!
+ * Returns the error encountered by the last operation.
+ */
+QVersitReader::Error QVersitReader::error() const
+{
+ return d->error();
+}
+
+/*!
* Starts reading the input asynchronously.
* Returns false if the input device has not been set or opened or
* if there is another asynchronous read operation already pending.
@@ -226,20 +265,4 @@
return d->mVersitDocuments;
}
-/*!
- * Returns the state of the reader.
- */
-QVersitReader::State QVersitReader::state() const
-{
- return d->state();
-}
-
-/*!
- * Returns the error encountered by the last operation.
- */
-QVersitReader::Error QVersitReader::error() const
-{
- return d->error();
-}
-
#include "moc_qversitreader.cpp"