Qt 4.8
Public Functions | Static Public Functions | Private Types | Private Functions | Properties | List of all members
QXbmHandler Class Reference

#include <qxbmhandler_p.h>

Inheritance diagram for QXbmHandler:
QImageIOHandler

Public Functions

bool canRead () const
 Returns true if an image can be read from the device (i. More...
 
QByteArray name () const
 Use format() instead. More...
 
QVariant option (ImageOption option) const
 Returns the value assigned to option as a QVariant. More...
 
 QXbmHandler ()
 
bool read (QImage *image)
 Read an image from the device, and stores it in image. More...
 
void setOption (ImageOption option, const QVariant &value)
 Sets the option option with the value value. More...
 
bool supportsOption (ImageOption option) const
 Returns true if the QImageIOHandler supports the option option; otherwise returns false. More...
 
bool write (const QImage &image)
 Writes the image image to the assigned device. More...
 
- Public Functions inherited from QImageIOHandler
virtual int currentImageNumber () const
 For image formats that support animation, this function returns the sequence number of the current image in the animation. More...
 
virtual QRect currentImageRect () const
 Returns the rect of the current image. More...
 
QIODevicedevice () const
 Returns the device currently assigned to the QImageIOHandler. More...
 
QByteArray format () const
 Returns the format that is currently assigned to QImageIOHandler. More...
 
virtual int imageCount () const
 For image formats that support animation, this function returns the number of images in the animation. More...
 
virtual bool jumpToImage (int imageNumber)
 For image formats that support animation, this function jumps to the image whose sequence number is imageNumber. More...
 
virtual bool jumpToNextImage ()
 For image formats that support animation, this function jumps to the next image. More...
 
virtual int loopCount () const
 For image formats that support animation, this function returns the number of times the animation should loop. More...
 
virtual int nextImageDelay () const
 For image formats that support animation, this function returns the number of milliseconds to wait until reading the next image. More...
 
 QImageIOHandler ()
 Constructs a QImageIOHandler object. More...
 
void setDevice (QIODevice *device)
 Sets the device of the QImageIOHandler to device. More...
 
void setFormat (const QByteArray &format)
 Sets the format of the QImageIOHandler to format. More...
 
void setFormat (const QByteArray &format) const
 Sets the format of the QImageIOHandler to format. More...
 
virtual ~QImageIOHandler ()
 Destructs the QImageIOHandler object. More...
 

Static Public Functions

static bool canRead (QIODevice *device)
 

Private Types

enum  State { Ready, ReadHeader, Error }
 

Private Functions

bool readHeader ()
 

Properties

QString fileName
 
int height
 
State state
 
int width
 

Additional Inherited Members

- Public Types inherited from QImageIOHandler
enum  ImageOption {
  Size, ClipRect, Description, ScaledClipRect,
  ScaledSize, CompressionRatio, Gamma, Quality,
  Name, SubType, IncrementalReading, Endianness,
  Animation, BackgroundColor, ImageFormat
}
 This enum describes the different options supported by QImageIOHandler. More...
 
- Protected Functions inherited from QImageIOHandler
 QImageIOHandler (QImageIOHandlerPrivate &dd)
 Constructs a QImageIOHandler object, using the private member dd. More...
 
- Protected Variables inherited from QImageIOHandler
QScopedPointer< QImageIOHandlerPrivated_ptr
 

Detailed Description

Definition at line 62 of file qxbmhandler_p.h.

Enumerations

◆ State

enum QXbmHandler::State
private
Enumerator
Ready 
ReadHeader 
Error 

Definition at line 80 of file qxbmhandler_p.h.

Constructors and Destructors

◆ QXbmHandler()

QXbmHandler::QXbmHandler ( )

Definition at line 257 of file qxbmhandler.cpp.

258  : state(Ready)
259 {
260 }

Functions

◆ canRead() [1/2]

bool QXbmHandler::canRead ( ) const
virtual

Returns true if an image can be read from the device (i.

e., the image format is supported, the device can be read from and the initial header information suggests that the image can be read); otherwise returns false.

When reimplementing canRead(), make sure that the I/O device (device()) is left in its original state (e.g., by using peek() rather than read()).

See also
read(), QIODevice::peek()

Implements QImageIOHandler.

Definition at line 271 of file qxbmhandler.cpp.

Referenced by createReadHandlerHelper().

272 {
273  if (state == Ready && !canRead(device()))
274  return false;
275 
276  if (state != Error) {
277  setFormat("xbm");
278  return true;
279  }
280 
281  return false;
282 }
void setFormat(const QByteArray &format)
Sets the format of the QImageIOHandler to format.
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
bool canRead() const
Returns true if an image can be read from the device (i.

◆ canRead() [2/2]

bool QXbmHandler::canRead ( QIODevice device)
static

Definition at line 284 of file qxbmhandler.cpp.

285 {
286  QImage image;
287 
288  // it's impossible to tell whether we can load an XBM or not when
289  // it's from a sequential device, as the only way to do it is to
290  // attempt to parse the whole image.
291  if (device->isSequential())
292  return false;
293 
294  qint64 oldPos = device->pos();
295  bool success = read_xbm_image(device, &image);
296  device->seek(oldPos);
297 
298  return success;
299 }
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
Definition: qiodevice.cpp:624
static bool read_xbm_image(QIODevice *device, QImage *outImage)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
__int64 qint64
Definition: qglobal.h:942
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
Definition: qiodevice.cpp:454
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
Definition: qiodevice.cpp:659

◆ name()

QByteArray QXbmHandler::name ( ) const
virtual

Use format() instead.

Reimplemented from QImageIOHandler.

Definition at line 354 of file qxbmhandler.cpp.

355 {
356  return "xbm";
357 }

◆ option()

QVariant QXbmHandler::option ( ImageOption  option) const
virtual

Returns the value assigned to option as a QVariant.

The type of the value depends on the option. For example, option(Size) returns a QSize variant.

See also
setOption(), supportsOption()

Reimplemented from QImageIOHandler.

Definition at line 332 of file qxbmhandler.cpp.

333 {
334  if (option == Name) {
335  return fileName;
336  } else if (option == Size) {
337  if (state == Error)
338  return QVariant();
339  if (state == Ready && !const_cast<QXbmHandler*>(this)->readHeader())
340  return QVariant();
341  return QSize(width, height);
342  } else if (option == ImageFormat) {
343  return QImage::Format_MonoLSB;
344  }
345  return QVariant();
346 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool readHeader()
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
QString fileName
Definition: qxbmhandler_p.h:88
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ read()

bool QXbmHandler::read ( QImage image)
virtual

Read an image from the device, and stores it in image.

Returns true if the image is successfully read; otherwise returns false.

For image formats that support incremental loading, and for animation formats, the image handler can assume that image points to the previous frame.

See also
canRead()

Implements QImageIOHandler.

Definition at line 301 of file qxbmhandler.cpp.

302 {
303  if (state == Error)
304  return false;
305 
306  if (state == Ready && !readHeader()) {
307  state = Error;
308  return false;
309  }
310 
311  if (!read_xbm_body(device(), width, height, image)) {
312  state = Error;
313  return false;
314  }
315 
316  state = Ready;
317  return true;
318 }
bool readHeader()
static bool read_xbm_body(QIODevice *device, int w, int h, QImage *outImage)
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.

◆ readHeader()

bool QXbmHandler::readHeader ( )
private

Definition at line 262 of file qxbmhandler.cpp.

Referenced by option(), and read().

263 {
264  state = Error;
266  return false;
267  state = ReadHeader;
268  return true;
269 }
static bool read_xbm_header(QIODevice *device, int &w, int &h)
Definition: qxbmhandler.cpp:66
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.

◆ setOption()

void QXbmHandler::setOption ( ImageOption  option,
const QVariant value 
)
virtual

Sets the option option with the value value.

See also
option(), ImageOption

Reimplemented from QImageIOHandler.

Definition at line 348 of file qxbmhandler.cpp.

349 {
350  if (option == Name)
351  fileName = value.toString();
352 }
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
QString fileName
Definition: qxbmhandler_p.h:88

◆ supportsOption()

bool QXbmHandler::supportsOption ( ImageOption  option) const
virtual

Returns true if the QImageIOHandler supports the option option; otherwise returns false.

For example, if the QImageIOHandler supports the Size option, supportsOption(Size) must return true.

See also
setOption(), option()

Reimplemented from QImageIOHandler.

Definition at line 325 of file qxbmhandler.cpp.

326 {
327  return option == Name
328  || option == Size
329  || option == ImageFormat;
330 }
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.

◆ write()

bool QXbmHandler::write ( const QImage image)
virtual

Writes the image image to the assigned device.

Returns true on success; otherwise returns false.

The default implementation does nothing, and simply returns false.

Reimplemented from QImageIOHandler.

Definition at line 320 of file qxbmhandler.cpp.

321 {
322  return write_xbm_image(image, device(), fileName);
323 }
static bool write_xbm_image(const QImage &sourceImage, QIODevice *device, const QString &fileName)
QString fileName
Definition: qxbmhandler_p.h:88
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.

Properties

◆ fileName

QString QXbmHandler::fileName
private

Definition at line 88 of file qxbmhandler_p.h.

Referenced by option(), setOption(), and write().

◆ height

int QXbmHandler::height
private

Definition at line 87 of file qxbmhandler_p.h.

Referenced by option(), read(), and readHeader().

◆ state

State QXbmHandler::state
private

Definition at line 85 of file qxbmhandler_p.h.

Referenced by canRead(), option(), read(), and readHeader().

◆ width

int QXbmHandler::width
private

Definition at line 86 of file qxbmhandler_p.h.

Referenced by option(), read(), and readHeader().


The documentation for this class was generated from the following files: