#include "qimagereader.h"
#include "qbytearray.h"
-#ifdef QIMAGEREADER_DEBUG
-#include "qdebug.h"
-#endif
#include "qfile.h"
#include "qimage.h"
#include "qimageiohandler.h"
#include "qsize.h"
#include "qcolor.h"
#include "qvariant.h"
+#include "qapplication.h"
// factory loader
#include "qcoreapplication.h"
#include "qkathandler_p.h"
#include "qpnghandler_p.h"
+#ifdef QIMAGEREADER_DEBUG
+# include "qdebug.h"
+#endif
+
QT_BEGIN_NAMESPACE
static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
// error
QImageReader::ImageReaderError imageReaderError;
- QString errorString;
};
/*!
// check some preconditions
if (!device) {
imageReaderError = QImageReader::DeviceError;
- errorString = QCoreApplication::translate("QImageReader", "Invalid device");
return false;
}
if (!device->isOpen() && !device->open(QIODevice::ReadOnly)) {
imageReaderError = QImageReader::FileNotFoundError;
- errorString = QCoreApplication::translate("QImageReader", "File not found");
return false;
}
// assign a handler
if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat)) == 0) {
imageReaderError = QImageReader::UnsupportedFormatError;
- errorString = QCoreApplication::translate("QImageReader", "Unsupported image format");
return false;
}
return true;
// read the image
if (!d->handler->read(image)) {
- d->imageReaderError = InvalidDataError;
- d->errorString = QCoreApplication::translate("QImageReader", "Unable to read image data");
+ d->imageReaderError = QImageReader::InvalidDataError;
return false;
}
*/
QString QImageReader::errorString() const
{
- if (d->errorString.isEmpty())
- return QCoreApplication::translate("QImageReader", "Unknown error");
- return d->errorString;
+ switch (d->imageReaderError) {
+ case QImageReader::UnknownError: {
+ return QApplication::translate("QImageReader", "Unknown error");
+ }
+ case QImageReader::FileNotFoundError: {
+ return QApplication::translate("QImageReader", "File not found");
+ }
+ case QImageReader::DeviceError: {
+ return QApplication::translate("QImageReader", "Device not readable");
+ }
+ case QImageReader::UnsupportedFormatError: {
+ return QApplication::translate("QImageReader", "Unsupported image format");
+ }
+ case QImageReader::InvalidDataError: {
+ return QApplication::translate("QImageReader", "Unable to read image data");
+ }
+ }
+ Q_UNREACHABLE();
+ return QString();
}
/*!
#include "qset.h"
#include "qvariant.h"
#include "qfileinfo.h"
+#include "qapplication.h"
// factory loader
#include "qcoreapplication.h"
// error
QImageWriter::ImageWriterError imageWriterError;
- QString errorString;
};
/*!
quality(100),
compression(1),
gamma(0.0),
- imageWriterError(QImageWriter::UnknownError),
- errorString(QT_TRANSLATE_NOOP(QImageWriter, QLatin1String("Unknown error")))
+ imageWriterError(QImageWriter::UnknownError)
{
}
{
if (d->device && !d->handler && (d->handler = createWriteHandlerHelper(d->device, d->format)) == 0) {
d->imageWriterError = QImageWriter::UnsupportedFormatError;
- d->errorString = QT_TRANSLATE_NOOP(QImageWriter, QLatin1String("Unsupported image format"));
return false;
}
if (d->device && !d->device->isOpen())
d->device->open(QIODevice::WriteOnly);
if (!d->device || !d->device->isWritable()) {
d->imageWriterError = QImageWriter::DeviceError;
- d->errorString = QT_TRANSLATE_NOOP(QImageWriter, QLatin1String("Device not writable"));
return false;
}
return true;
*/
QString QImageWriter::errorString() const
{
- return d->errorString;
+ switch (d->imageWriterError) {
+ case QImageWriter::UnknownError: {
+ return QApplication::translate("QImageWriter", "Unknown error");
+ }
+ case QImageWriter::DeviceError: {
+ return QApplication::translate("QImageWriter", "Device not writable");
+ }
+ case QImageWriter::UnsupportedFormatError: {
+ return QApplication::translate("QImageWriter", "Unsupported image format");
+ }
+ }
+ Q_UNREACHABLE();
+ return QString();
}
/*!
{
if (!d->handler && (d->handler = createWriteHandlerHelper(d->device, d->format)) == 0) {
d->imageWriterError = QImageWriter::UnsupportedFormatError;
- d->errorString = QT_TRANSLATE_NOOP(QImageWriter, QLatin1String("Unsupported image format"));
return false;
}