Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Q3MimeSourceFactory Class Reference

The Q3MimeSourceFactory class is an extensible provider of mime-typed data. More...

 #include <Q3MimeSourceFactory>

This class is part of the Qt 3 support library. It is provided to keep old source code working. We strongly advise against using it in new code. See Porting to Qt 4 for more information.

Public Functions

Q3MimeSourceFactory ()
virtual ~Q3MimeSourceFactory ()
void addFilePath ( const QString & p )
virtual const QMimeSource * data ( const QString & abs_name ) const
const QMimeSource * data ( const QString & abs_or_rel_name, const QString & context ) const
virtual QStringList filePath () const
virtual QString makeAbsolute ( const QString & abs_or_rel_name, const QString & context ) const
virtual void setData ( const QString & abs_name, QMimeSource * data )
virtual void setExtensionType ( const QString & ext, const char * mimetype )
virtual void setFilePath ( const QStringList & path )
void setFilePath ( const QString & path )
virtual void setImage ( const QString & abs_name, const QImage & image )
virtual void setPixmap ( const QString & abs_name, const QPixmap & pixmap )
virtual void setText ( const QString & abs_name, const QString & text )

Static Public Members

void addFactory ( Q3MimeSourceFactory * f )
Q3MimeSourceFactory * defaultFactory ()
void removeFactory ( Q3MimeSourceFactory * f )
void setDefaultFactory ( Q3MimeSourceFactory * factory )
Q3MimeSourceFactory * takeDefaultFactory ()

Detailed Description

The Q3MimeSourceFactory class is an extensible provider of mime-typed data.

A Q3MimeSourceFactory provides an abstract interface to a collection of information. Each piece of information is represented by a QMimeSource object which can be examined and converted to concrete data types by functions such as Q3ImageDrag::canDecode() and Q3ImageDrag::decode().

The base Q3MimeSourceFactory can be used in two ways: as an abstraction of a collection of files or as specifically stored data. For it to access files, call setFilePath() before accessing data. For stored data, call setData() for each item (there are also convenience functions, e.g. setText(), setImage() and setPixmap(), that simply call setData() with appropriate parameters).

The rich text widgets, QTextEdit and QTextBrowser, use Q3MimeSourceFactory to resolve references such as images or links within rich text documents. They either access the default factory (see defaultFactory()) or their own. Other classes that are capable of displaying rich text (such as QLabel, QWhatsThis or QMessageBox) always use the default factory.

A factory can also be used as a container to store data associated with a name. This technique is useful whenever rich text contains images that are stored in the program itself, not loaded from the hard disk. Your program may, for example, define some image data as:

 static const char* myimage_data[]={
 "...",
 ...
 "..."};

To be able to use this image within some rich text, for example inside a QLabel, you must create a QImage from the raw data and insert it into the factory with a unique name:

 Q3MimeSourceFactory::defaultFactory()->setImage("myimage", QImage(myimage_data));

Now you can create a rich text QLabel with

 QLabel* label = new QLabel(
     "Rich text with embedded image:<img source=\"myimage\">"
     "Isn't that <em>cute</em>?");

When no longer needed, you can clear the data from the factory:

 delete label;
 Q3MimeSourceFactory::defaultFactory()->setData("myimage", 0);

Member Function Documentation

Q3MimeSourceFactory::Q3MimeSourceFactory ()

Constructs a Q3MimeSourceFactory that has no file path and no stored content.

Q3MimeSourceFactory::~Q3MimeSourceFactory () [virtual]

Destroys the Q3MimeSourceFactory, deleting all stored content.

void Q3MimeSourceFactory::addFactory ( Q3MimeSourceFactory * f ) [static]

Adds the Q3MimeSourceFactory f to the list of available mimesource factories. If the defaultFactory() can't resolve a data() it iterates over the list of installed mimesource factories until the data can be resolved.

See also removeFactory().

void Q3MimeSourceFactory::addFilePath ( const QString & p )

Adds another search path, p to the existing search paths.

See also setFilePath().

const QMimeSource * Q3MimeSourceFactory::data ( const QString & abs_name ) const [virtual]

Returns a reference to the data associated with abs_name. The return value remains valid only until the next data() or setData() call, so you should immediately decode the result.

If there is no data associated with abs_name in the factory's store, the factory tries to access the local filesystem. If abs_name isn't an absolute file name, the factory will search for it in all defined paths (see setFilePath()).

The factory understands all the image formats supported by QImageReader. Any other mime types are determined by the file name extension. The default settings are

 setExtensionType("html", "text/html;charset=iso8859-1");
 setExtensionType("htm", "text/html;charset=iso8859-1");
 setExtensionType("txt", "text/plain");
 setExtensionType("xml", "text/xml;charset=UTF-8");

The effect of these is that file names ending in "txt" will be treated as text encoded in the local encoding; those ending in "xml" will be treated as text encoded in Unicode UTF-8 encoding. The text/html type is treated specially, since the encoding can be specified in the html file itself. "html" or "htm" will be treated as text encoded in the encoding specified by the html meta tag, if none could be found, the charset of the mime type will be used. The text subtype ("html", "plain", or "xml") does not affect the factory, but users of the factory may behave differently. We recommend creating "xml" files where practical. These files can be viewed regardless of the runtime encoding and can encode any Unicode characters without resorting to encoding definitions inside the file.

Any file data that is not recognized will be retrieved as a QMimeSource providing the "application/octet-stream" mime type, meaning uninterpreted binary data.

You can add further extensions or change existing ones with subsequent calls to setExtensionType(). If the extension mechanism is not sufficient for your problem domain, you can inherit Q3MimeSourceFactory and reimplement this function to perform some more specialized mime-type detection. The same applies if you want to use the mime source factory to access URL referenced data over a network.

See also setData().

const QMimeSource * Q3MimeSourceFactory::data ( const QString & abs_or_rel_name, const QString & context ) const

This is an overloaded function.

A convenience function. See data(const QString& abs_name). The file name is given in abs_or_rel_name and the path is in context.

Q3MimeSourceFactory * Q3MimeSourceFactory::defaultFactory () [static]

Returns the application-wide default mime source factory. This factory is used by rich text rendering classes such as QSimpleRichText, QWhatsThis and QMessageBox to resolve named references within rich text documents. It serves also as the initial factory for the more complex render widgets, QTextEdit and QTextBrowser.

See also setDefaultFactory().

QStringList Q3MimeSourceFactory::filePath () const [virtual]

Returns the currently set search paths.

See also setFilePath().

QString Q3MimeSourceFactory::makeAbsolute ( const QString & abs_or_rel_name, const QString & context ) const [virtual]

Converts the absolute or relative data item name abs_or_rel_name to an absolute name, interpreted within the context (path) of the data item named context (this must be an absolute name).

void Q3MimeSourceFactory::removeFactory ( Q3MimeSourceFactory * f ) [static]

Removes the mimesource factory f from the list of available mimesource factories.

See also addFactory().

void Q3MimeSourceFactory::setData ( const QString & abs_name, QMimeSource * data ) [virtual]

Sets data to be the data item associated with the absolute name abs_name. Note that the ownership of data is transferred to the factory: do not delete or access the pointer after passing it to this function.

Passing 0 for data removes previously stored data.

See also data().

void Q3MimeSourceFactory::setDefaultFactory ( Q3MimeSourceFactory * factory ) [static]

Sets the default factory, destroying any previously set mime source provider. The ownership of the factory is transferred to Qt.

See also defaultFactory().

void Q3MimeSourceFactory::setExtensionType ( const QString & ext, const char * mimetype ) [virtual]

Sets the mime-type to be associated with the file name extension, ext to mimetype. This determines the mime-type for files found via the paths set by setFilePath().

void Q3MimeSourceFactory::setFilePath ( const QStringList & path ) [virtual]

Sets the list of directories that will be searched when named data is requested to those given in the string list path.

See also filePath().

void Q3MimeSourceFactory::setFilePath ( const QString & path )

Sets the list of directories that will be searched when named data is requested to those given in the string list path.

See also filePath().

void Q3MimeSourceFactory::setImage ( const QString & abs_name, const QImage & image ) [virtual]

Sets image to be the data item associated with the absolute name abs_name.

Equivalent to setData(abs_name, new Q3ImageDrag(image)).

void Q3MimeSourceFactory::setPixmap ( const QString & abs_name, const QPixmap & pixmap ) [virtual]

Sets pixmap to be the data item associated with the absolute name abs_name.

void Q3MimeSourceFactory::setText ( const QString & abs_name, const QString & text ) [virtual]

Sets text to be the data item associated with the absolute name abs_name.

Equivalent to setData(abs_name, new Q3TextDrag(text)).

Q3MimeSourceFactory * Q3MimeSourceFactory::takeDefaultFactory () [static]

Sets the defaultFactory() to 0 and returns the previous one.

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.8
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web