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

The QPictureIO class contains parameters for loading and saving pictures. More...

#include <qpicture.h>

Public Functions

QString description () const
 Returns the picture description string. More...
 
QString fileName () const
 Returns the file name currently set. More...
 
const char * format () const
 Returns the picture format string or 0 if no format has been explicitly set. More...
 
float gamma () const
 Returns the gamma value at which the picture will be viewed. More...
 
QIODeviceioDevice () const
 Returns the IO device currently set. More...
 
const char * parameters () const
 Returns the picture's parameters string. More...
 
const QPicturepicture () const
 Returns the picture currently set. More...
 
 QPictureIO ()
 Constructs a QPictureIO object with all parameters set to zero. More...
 
 QPictureIO (QIODevice *ioDevice, const char *format)
 Constructs a QPictureIO object with the I/O device ioDevice and a format tag. More...
 
 QPictureIO (const QString &fileName, const char *format)
 Constructs a QPictureIO object with the file name fileName and a format tag. More...
 
int quality () const
 Returns the quality of the written picture, related to the compression ratio. More...
 
bool read ()
 Reads an picture into memory and returns true if the picture was successfully read; otherwise returns false. More...
 
void setDescription (const QString &)
 Sets the picture description string for picture handlers that support picture descriptions to description. More...
 
void setFileName (const QString &)
 Sets the name of the file to read or write an picture from to fileName. More...
 
void setFormat (const char *)
 Sets the picture format to format for the picture to be read or written. More...
 
void setGamma (float)
 Sets the gamma value at which the picture will be viewed to gamma. More...
 
void setIODevice (QIODevice *)
 Sets the IO device to be used for reading or writing an picture. More...
 
void setParameters (const char *)
 Sets the picture's parameter string to parameters. More...
 
void setPicture (const QPicture &)
 Sets the picture to picture. More...
 
void setQuality (int)
 Sets the quality of the written picture to q, related to the compression ratio. More...
 
void setStatus (int)
 Sets the picture IO status to status. More...
 
int status () const
 Returns the picture's IO status. More...
 
bool write ()
 Writes an picture to an IO device and returns true if the picture was successfully written; otherwise returns false. More...
 
 ~QPictureIO ()
 Destroys the object and all related data. More...
 

Static Public Functions

static void defineIOHandler (const char *format, const char *header, const char *flags, picture_io_handler read_picture, picture_io_handler write_picture)
 Defines a picture I/O handler for the picture format called format, which is recognized using the regular expression defined in header, read using readPicture and written using writePicture. More...
 
static QList< QByteArrayinputFormats ()
 Returns a sorted list of picture formats that are supported for picture input. More...
 
static QList< QByteArrayoutputFormats ()
 Returns a sorted list of picture formats that are supported for picture output. More...
 
static QByteArray pictureFormat (const QString &fileName)
 Returns a string that specifies the picture format of the file fileName, or null if the file cannot be read or if the format is not recognized. More...
 
static QByteArray pictureFormat (QIODevice *)
 Returns a string that specifies the picture format of the picture read from IO device d, or 0 if the device cannot be read or if the format is not recognized. More...
 

Private Functions

void init ()
 Contains initialization common to all QPictureIO constructors. More...
 

Properties

QPictureIODatad
 

Detailed Description

The QPictureIO class contains parameters for loading and saving pictures.

QPictureIO contains a QIODevice object that is used for picture data I/O. The programmer can install new picture file formats in addition to those that Qt provides.

You don't normally need to use this class; QPicture::load(), QPicture::save().

See also
QPicture QPixmap QFile

Definition at line 136 of file qpicture.h.

Constructors and Destructors

◆ QPictureIO() [1/3]

QPictureIO::QPictureIO ( )

Constructs a QPictureIO object with all parameters set to zero.

Definition at line 1401 of file qpicture.cpp.

1402 {
1403  init();
1404 }
void init()
Contains initialization common to all QPictureIO constructors.
Definition: qpicture.cpp:1434

◆ QPictureIO() [2/3]

QPictureIO::QPictureIO ( QIODevice ioDevice,
const char *  format 
)

Constructs a QPictureIO object with the I/O device ioDevice and a format tag.

Definition at line 1411 of file qpicture.cpp.

1412 {
1413  init();
1414  d->iodev = ioDevice;
1415  d->frmt = format;
1416 }
void init()
Contains initialization common to all QPictureIO constructors.
Definition: qpicture.cpp:1434
QIODevice * iodev
Definition: qpicture.cpp:1389
QIODevice * ioDevice() const
Returns the IO device currently set.
Definition: qpicture.cpp:1623
QPictureIOData * d
Definition: qpicture.h:183
QByteArray frmt
Definition: qpicture.cpp:1388
const char * format() const
Returns the picture format string or 0 if no format has been explicitly set.
Definition: qpicture.cpp:1616

◆ QPictureIO() [3/3]

QPictureIO::QPictureIO ( const QString fileName,
const char *  format 
)

Constructs a QPictureIO object with the file name fileName and a format tag.

Definition at line 1423 of file qpicture.cpp.

1424 {
1425  init();
1426  d->frmt = format;
1427  d->fname = fileName;
1428 }
void init()
Contains initialization common to all QPictureIO constructors.
Definition: qpicture.cpp:1434
QString fileName() const
Returns the file name currently set.
Definition: qpicture.cpp:1630
QPictureIOData * d
Definition: qpicture.h:183
QByteArray frmt
Definition: qpicture.cpp:1388
const char * format() const
Returns the picture format string or 0 if no format has been explicitly set.
Definition: qpicture.cpp:1616

◆ ~QPictureIO()

QPictureIO::~QPictureIO ( )

Destroys the object and all related data.

Definition at line 1448 of file qpicture.cpp.

1449 {
1450  if (d->parameters)
1451  delete [] (char*)d->parameters;
1452  delete d;
1453 }
const char * parameters
Definition: qpicture.cpp:1392
QPictureIOData * d
Definition: qpicture.h:183

Functions

◆ defineIOHandler()

void QPictureIO::defineIOHandler ( const char *  format,
const char *  header,
const char *  flags,
picture_io_handler  readPicture,
picture_io_handler  writePicture 
)
static

Defines a picture I/O handler for the picture format called format, which is recognized using the regular expression defined in header, read using readPicture and written using writePicture.

flags is a string of single-character flags for this format. The only flag defined currently is T (upper case), so the only legal value for flags are "T" and the empty string. The "T" flag means that the picture file is a text file, and Qt should treat all newline conventions as equivalent. (XPM files and some PPM files are text files for example.)

format is used to select a handler to write a QPicture; header is used to select a handler to read an picture file.

If readPicture is a null pointer, the QPictureIO will not be able to read pictures in format. If writePicture is a null pointer, the QPictureIO will not be able to write pictures in format. If both are null, the QPictureIO object is valid but useless.

Example:

void readSVG(QPictureIO *picture)
{
// read the picture using the picture->ioDevice()
}
void writeSVG(QPictureIO *picture)
{
// write the picture using the picture->ioDevice()
}
// add the SVG picture handler
// ...

Before the regular expression test, all the 0 bytes in the file header are converted to 1 bytes. This is done because when Qt was ASCII-based, QRegExp could not handle 0 bytes in strings.

The regexp is only applied on the first 14 bytes of the file.

(Note that if one handlerIO supports writing a format and another supports reading it, Qt supports both reading and writing. If two handlers support the same operation, Qt chooses one arbitrarily.)

Definition at line 1578 of file qpicture.cpp.

1583 {
1585  if (QPHList *list = pictureHandlers()) {
1586  QPictureHandler *p;
1587  p = new QPictureHandler(format, header, QByteArray(flags), readPicture, writePicture);
1588  list->prepend(p);
1589  }
1590 }
void qt_init_picture_handlers()
Definition: qpicture.cpp:1517
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ description()

QString QPictureIO::description ( ) const

Returns the picture description string.

See also
setDescription()

Definition at line 1638 of file qpicture.cpp.

1638 { return d->descr; }
QPictureIOData * d
Definition: qpicture.h:183

◆ fileName()

QString QPictureIO::fileName ( ) const

Returns the file name currently set.

See also
setFileName()

Definition at line 1630 of file qpicture.cpp.

1630 { return d->fname; }
QPictureIOData * d
Definition: qpicture.h:183

◆ format()

const char * QPictureIO::format ( ) const

Returns the picture format string or 0 if no format has been explicitly set.

Definition at line 1616 of file qpicture.cpp.

1616 { return d->frmt; }
QPictureIOData * d
Definition: qpicture.h:183
QByteArray frmt
Definition: qpicture.cpp:1388

◆ gamma()

float QPictureIO::gamma ( ) const

Returns the gamma value at which the picture will be viewed.

See also
setGamma()

Definition at line 1783 of file qpicture.cpp.

1784 {
1785  return d->gamma;
1786 }
QPictureIOData * d
Definition: qpicture.h:183

◆ init()

void QPictureIO::init ( )
private

Contains initialization common to all QPictureIO constructors.

Definition at line 1434 of file qpicture.cpp.

1435 {
1436  d = new QPictureIOData();
1437  d->parameters = 0;
1438  d->quality = -1; // default quality of the current format
1439  d->gamma=0.0f;
1440  d->iostat = 0;
1441  d->iodev = 0;
1442 }
const char * parameters
Definition: qpicture.cpp:1392
QIODevice * iodev
Definition: qpicture.cpp:1389
QPictureIOData * d
Definition: qpicture.h:183

◆ inputFormats()

QList< QByteArray > QPictureIO::inputFormats ( )
static

Returns a sorted list of picture formats that are supported for picture input.

Definition at line 1876 of file qpicture.cpp.

Referenced by QPicture::inputFormatList(), and QPicture::inputFormats().

1877 {
1878  QList<QByteArray> result;
1879 
1881  qt_init_picture_plugins();
1882 
1883  if (QPHList *list = pictureHandlers()) {
1884  for (int i = 0; i < list->size(); ++i) {
1885  QPictureHandler *p = list->at(i);
1886  if (p->read_picture && !p->obsolete && !result.contains(p->format))
1887  result.append(p->format);
1888  }
1889  }
1890  qSort(result);
1891 
1892  return result;
1893 }
void qt_init_picture_handlers()
Definition: qpicture.cpp:1517
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
picture_io_handler read_picture
Definition: qpicture.cpp:1468
QByteArray format
Definition: qpicture.cpp:1465
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177

◆ ioDevice()

QIODevice * QPictureIO::ioDevice ( ) const

Returns the IO device currently set.

See also
setIODevice()

Definition at line 1623 of file qpicture.cpp.

1623 { return d->iodev; }
QIODevice * iodev
Definition: qpicture.cpp:1389
QPictureIOData * d
Definition: qpicture.h:183

◆ outputFormats()

QList< QByteArray > QPictureIO::outputFormats ( )
static

Returns a sorted list of picture formats that are supported for picture output.

Definition at line 1899 of file qpicture.cpp.

Referenced by QPicture::outputFormatList(), and QPicture::outputFormats().

1900 {
1902  qt_init_picture_plugins();
1903 
1904  QList<QByteArray> result;
1905  if (QPHList *list = pictureHandlers()) {
1906  for (int i = 0; i < list->size(); ++i) {
1907  QPictureHandler *p = list->at(i);
1908  if (p->write_picture && !p->obsolete && !result.contains(p->format))
1909  result.append(p->format);
1910  }
1911  }
1912  return result;
1913 }
void qt_init_picture_handlers()
Definition: qpicture.cpp:1517
picture_io_handler write_picture
Definition: qpicture.cpp:1469
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
QByteArray format
Definition: qpicture.cpp:1465

◆ parameters()

const char * QPictureIO::parameters ( ) const

Returns the picture's parameters string.

See also
setParameters()

Definition at line 1739 of file qpicture.cpp.

1740 {
1741  return d->parameters;
1742 }
const char * parameters
Definition: qpicture.cpp:1392
QPictureIOData * d
Definition: qpicture.h:183

◆ picture()

const QPicture & QPictureIO::picture ( ) const

Returns the picture currently set.

See also
setPicture()

Definition at line 1602 of file qpicture.cpp.

Referenced by QPicture::load(), and QPicture::save().

1602 { return d->pi; }
QPictureIOData * d
Definition: qpicture.h:183

◆ pictureFormat() [1/2]

QByteArray QPictureIO::pictureFormat ( const QString fileName)
static

Returns a string that specifies the picture format of the file fileName, or null if the file cannot be read or if the format is not recognized.

Definition at line 1808 of file qpicture.cpp.

Referenced by QPicture::pictureFormat().

1809 {
1810  QFile file(fileName);
1812  if (!file.open(QIODevice::ReadOnly))
1813  return format;
1814  format = pictureFormat(&file);
1815  file.close();
1816  return format;
1817 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
const char * format() const
Returns the picture format string or 0 if no format has been explicitly set.
Definition: qpicture.cpp:1616
static QByteArray pictureFormat(const QString &fileName)
Returns a string that specifies the picture format of the file fileName, or null if the file cannot b...
Definition: qpicture.cpp:1808

◆ pictureFormat() [2/2]

QByteArray QPictureIO::pictureFormat ( QIODevice d)
static

Returns a string that specifies the picture format of the picture read from IO device d, or 0 if the device cannot be read or if the format is not recognized.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Make sure that d is at the right position in the device (for example, at the beginning of the file).

See also
QIODevice::at()

Definition at line 1835 of file qpicture.cpp.

1836 {
1837  // if you change this change the documentation for defineIOHandler()
1838  const int buflen = 14;
1839 
1840  char buf[buflen];
1841  char buf2[buflen];
1843  qt_init_picture_plugins();
1844  int pos = d->pos(); // save position
1845  int rdlen = d->read(buf, buflen); // read a few bytes
1846 
1848  if (rdlen != buflen)
1849  return format;
1850 
1851  memcpy(buf2, buf, buflen);
1852 
1853  for (int n = 0; n < rdlen; n++)
1854  if (buf[n] == '\0')
1855  buf[n] = '\001';
1856  if (rdlen > 0) {
1857  buf[rdlen - 1] = '\0';
1858  QString bufStr = QString::fromLatin1(buf);
1859  if (QPHList *list = pictureHandlers()) {
1860  for (int i = 0; i < list->size(); ++i) {
1861  if (list->at(i)->header.indexIn(bufStr) != -1) { // try match with headers
1862  format = list->at(i)->format;
1863  break;
1864  }
1865  }
1866  }
1867  }
1868  d->seek(pos); // restore position
1869  return format;
1870 }
void qt_init_picture_handlers()
Definition: qpicture.cpp:1517
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
const char * format() const
Returns the picture format string or 0 if no format has been explicitly set.
Definition: qpicture.cpp:1616
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
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
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ quality()

int QPictureIO::quality ( ) const

Returns the quality of the written picture, related to the compression ratio.

See also
setQuality() QPicture::save()

Definition at line 1712 of file qpicture.cpp.

1713 {
1714  return d->quality;
1715 }
QPictureIOData * d
Definition: qpicture.h:183

◆ read()

bool QPictureIO::read ( )

Reads an picture into memory and returns true if the picture was successfully read; otherwise returns false.

Before reading an picture you must set an IO device or a file name. If both an IO device and a file name have been set, the IO device will be used.

Setting the picture file format string is optional.

Note that this function does not set the format used to read the picture. If you need that information, use the pictureFormat() static functions.

Example:

QPixmap pixmap;
iio.setFileName("vegeburger.pic");
if (iio.read()) { // OK
QPainter painter(&pixmap);
painter.drawPicture(0, 0, picture);
}
See also
setIODevice() setFileName() setFormat() write() QPixmap::load()

Definition at line 1937 of file qpicture.cpp.

Referenced by QPicture::load().

1938 {
1939  QFile file;
1940  const char *picture_format;
1941  QPictureHandler *h;
1942 
1943  if (d->iodev) { // read from io device
1944  // ok, already open
1945  } else if (!d->fname.isEmpty()) { // read from file
1946  file.setFileName(d->fname);
1947  if (!file.open(QIODevice::ReadOnly))
1948  return false; // cannot open file
1949  d->iodev = &file;
1950  } else { // no file name or io device
1951  return false;
1952  }
1953  if (d->frmt.isEmpty()) {
1954  // Try to guess format
1955  picture_format = pictureFormat(d->iodev); // get picture format
1956  if (!picture_format) {
1957  if (file.isOpen()) { // unknown format
1958  file.close();
1959  d->iodev = 0;
1960  }
1961  return false;
1962  }
1963  } else {
1964  picture_format = d->frmt;
1965  }
1966 
1967  h = get_picture_handler(picture_format);
1968  if (file.isOpen()) {
1969 #if !defined(Q_OS_UNIX)
1970  if (h && h->text_mode) { // reopen in translated mode
1971  file.close();
1973  }
1974  else
1975 #endif
1976  file.seek(0); // position to start
1977  }
1978  d->iostat = 1; // assume error
1979 
1980  if (h && h->read_picture)
1981  (*h->read_picture)(this);
1982 
1983  if (file.isOpen()) { // picture was read using file
1984  file.close();
1985  d->iodev = 0;
1986  }
1987  return d->iostat == 0; // picture successfully read?
1988 }
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
QIODevice * iodev
Definition: qpicture.cpp:1389
bool isOpen() const
Returns true if the device is open; otherwise returns false.
Definition: qiodevice.cpp:530
enum QPictureHandler::TMode text_mode
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
picture_io_handler read_picture
Definition: qpicture.cpp:1468
QPictureIOData * d
Definition: qpicture.h:183
QByteArray frmt
Definition: qpicture.cpp:1388
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
static QByteArray pictureFormat(const QString &fileName)
Returns a string that specifies the picture format of the file fileName, or null if the file cannot b...
Definition: qpicture.cpp:1808
virtual void close()
Calls QFile::flush() and closes the file.
Definition: qfile.cpp:1680
bool seek(qint64 offset)
For random-access devices, this function sets the current position to pos, returning true on success...
Definition: qfile.cpp:1784
void setFileName(const QString &name)
Sets the name of the file.
Definition: qfile.cpp:494
static QPictureHandler * get_picture_handler(const char *format)
Definition: qpicture.cpp:1525

◆ setDescription()

void QPictureIO::setDescription ( const QString description)

Sets the picture description string for picture handlers that support picture descriptions to description.

Currently, no picture format supported by Qt uses the description string.

Definition at line 1796 of file qpicture.cpp.

1797 {
1798  d->descr = description;
1799 }
QPictureIOData * d
Definition: qpicture.h:183
QString description() const
Returns the picture description string.
Definition: qpicture.cpp:1638

◆ setFileName()

void QPictureIO::setFileName ( const QString fileName)

Sets the name of the file to read or write an picture from to fileName.

See also
setIODevice()

Definition at line 1701 of file qpicture.cpp.

1702 {
1703  d->fname = fileName;
1704 }
QString fileName() const
Returns the file name currently set.
Definition: qpicture.cpp:1630
QPictureIOData * d
Definition: qpicture.h:183

◆ setFormat()

void QPictureIO::setFormat ( const char *  format)

Sets the picture format to format for the picture to be read or written.

It is necessary to specify a format before writing an picture, but it is not necessary to specify a format before reading an picture.

If no format has been set, Qt guesses the picture format before reading it. If a format is set the picture will only be read if it has that format.

See also
read() write() format()

Definition at line 1674 of file qpicture.cpp.

1675 {
1676  d->frmt = format;
1677 }
QPictureIOData * d
Definition: qpicture.h:183
QByteArray frmt
Definition: qpicture.cpp:1388
const char * format() const
Returns the picture format string or 0 if no format has been explicitly set.
Definition: qpicture.cpp:1616

◆ setGamma()

void QPictureIO::setGamma ( float  gamma)

Sets the gamma value at which the picture will be viewed to gamma.

If the picture format stores a gamma value for which the picture is intended to be used, then this setting will be used to modify the picture. Setting to 0.0 will disable gamma correction (i.e. any specification in the file will be ignored).

The default value is 0.0.

See also
gamma()

Definition at line 1773 of file qpicture.cpp.

1774 {
1775  d->gamma=gamma;
1776 }
QPictureIOData * d
Definition: qpicture.h:183
float gamma() const
Returns the gamma value at which the picture will be viewed.
Definition: qpicture.cpp:1783

◆ setIODevice()

void QPictureIO::setIODevice ( QIODevice ioDevice)

Sets the IO device to be used for reading or writing an picture.

Setting the IO device allows pictures to be read/written to any block-oriented QIODevice.

If ioDevice is not null, this IO device will override file name settings.

See also
setFileName()

Definition at line 1690 of file qpicture.cpp.

1691 {
1692  d->iodev = ioDevice;
1693 }
QIODevice * iodev
Definition: qpicture.cpp:1389
QIODevice * ioDevice() const
Returns the IO device currently set.
Definition: qpicture.cpp:1623
QPictureIOData * d
Definition: qpicture.h:183

◆ setParameters()

void QPictureIO::setParameters ( const char *  parameters)

Sets the picture's parameter string to parameters.

This is for picture handlers that require special parameters.

Although the current picture formats supported by Qt ignore the parameters string, it may be used in future extensions or by contributions (for example, JPEG).

See also
parameters()

Definition at line 1755 of file qpicture.cpp.

1756 {
1757  if (d->parameters)
1758  delete [] (char*)d->parameters;
1760 }
const char * parameters
Definition: qpicture.cpp:1392
QPictureIOData * d
Definition: qpicture.h:183
const char * parameters() const
Returns the picture&#39;s parameters string.
Definition: qpicture.cpp:1739
Q_CORE_EXPORT char * qstrdup(const char *)

◆ setPicture()

void QPictureIO::setPicture ( const QPicture picture)

Sets the picture to picture.

See also
picture()

Definition at line 1645 of file qpicture.cpp.

1646 {
1647  d->pi = picture;
1648 }
const QPicture & picture() const
Returns the picture currently set.
Definition: qpicture.cpp:1602
QPictureIOData * d
Definition: qpicture.h:183

◆ setQuality()

void QPictureIO::setQuality ( int  q)

Sets the quality of the written picture to q, related to the compression ratio.

q must be in the range -1..100. Specify 0 to obtain small compressed files, 100 for large uncompressed files. (-1 signifies the default compression.)

See also
quality() QPicture::save()

Definition at line 1728 of file qpicture.cpp.

1729 {
1730  d->quality = q;
1731 }
QPictureIOData * d
Definition: qpicture.h:183

◆ setStatus()

void QPictureIO::setStatus ( int  status)

Sets the picture IO status to status.

A non-zero value indicates an error, whereas 0 means that the IO operation was successful.

See also
status()

Definition at line 1656 of file qpicture.cpp.

1657 {
1658  d->iostat = status;
1659 }
QPictureIOData * d
Definition: qpicture.h:183
int status() const
Returns the picture&#39;s IO status.
Definition: qpicture.cpp:1610

◆ status()

int QPictureIO::status ( ) const

Returns the picture's IO status.

A non-zero value indicates an error, whereas 0 means that the IO operation was successful.

See also
setStatus()

Definition at line 1610 of file qpicture.cpp.

1610 { return d->iostat; }
QPictureIOData * d
Definition: qpicture.h:183

◆ write()

bool QPictureIO::write ( )

Writes an picture to an IO device and returns true if the picture was successfully written; otherwise returns false.

Before writing an picture you must set an IO device or a file name. If both an IO device and a file name have been set, the IO device will be used.

The picture will be written using the specified picture format.

Example:

QPainter painter(&picture);
painter.drawPixmap(0, 0, pixmap);
iio.setPicture(picture);
iio.setFileName("vegeburger.pic");
iio.setFormat("PIC");
if (iio.write())
return true; // returned true if written successfully
See also
setIODevice() setFileName() setFormat() read() QPixmap::save()

Definition at line 2006 of file qpicture.cpp.

Referenced by QPicture::save().

2007 {
2008  if (d->frmt.isEmpty())
2009  return false;
2011  if (!h || !h->write_picture) {
2012  qWarning("QPictureIO::write: No such picture format handler: %s",
2013  format());
2014  return false;
2015  }
2016  QFile file;
2017  if (!d->iodev && !d->fname.isEmpty()) {
2018  file.setFileName(d->fname);
2019  bool translate = h->text_mode==QPictureHandler::TranslateInOut;
2020  QIODevice::OpenMode fmode = translate ? QIODevice::WriteOnly | QIODevice::Text : QIODevice::OpenMode(QIODevice::WriteOnly);
2021  if (!file.open(fmode)) // couldn't create file
2022  return false;
2023  d->iodev = &file;
2024  }
2025  d->iostat = 1;
2026  (*h->write_picture)(this);
2027  if (file.isOpen()) { // picture was written using file
2028  file.close();
2029  d->iodev = 0;
2030  }
2031  return d->iostat == 0; // picture successfully written?
2032 }
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
picture_io_handler write_picture
Definition: qpicture.cpp:1469
QIODevice * iodev
Definition: qpicture.cpp:1389
bool isOpen() const
Returns true if the device is open; otherwise returns false.
Definition: qiodevice.cpp:530
enum QPictureHandler::TMode text_mode
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_CORE_EXPORT void qWarning(const char *,...)
QPictureIOData * d
Definition: qpicture.h:183
QByteArray frmt
Definition: qpicture.cpp:1388
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
const char * format() const
Returns the picture format string or 0 if no format has been explicitly set.
Definition: qpicture.cpp:1616
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
virtual void close()
Calls QFile::flush() and closes the file.
Definition: qfile.cpp:1680
void setFileName(const QString &name)
Sets the name of the file.
Definition: qfile.cpp:494
static QPictureHandler * get_picture_handler(const char *format)
Definition: qpicture.cpp:1525

Properties

◆ d

QPictureIOData* QPictureIO::d
private

Definition at line 183 of file qpicture.h.


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