
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQ3MimeSourceFactory class is an extensible provider of mime-typed data.More...
| Header: | #include <Q3MimeSourceFactory> |
| 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) |
| void | addFactory(Q3MimeSourceFactory * f) |
| Q3MimeSourceFactory * | defaultFactory() |
| void | removeFactory(Q3MimeSourceFactory * f) |
| void | setDefaultFactory(Q3MimeSourceFactory * factory) |
| Q3MimeSourceFactory * | takeDefaultFactory() |
TheQ3MimeSourceFactory class is an extensible provider of mime-typed data.
AQ3MimeSourceFactory 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 asQ3ImageDrag::canDecode() andQ3ImageDrag::decode().
The baseQ3MimeSourceFactory can be used in two ways: as an abstraction of a collection of files or as specifically stored data. For it to access files, callsetFilePath() before accessing data. For stored data, callsetData() for each item (there are also convenience functions, e.g.setText(),setImage() andsetPixmap(), that simply callsetData() with appropriate parameters).
The rich text widgets,QTextEdit andQTextBrowser, useQ3MimeSourceFactory to resolve references such as images or links within rich text documents. They either access the default factory (seedefaultFactory()) or their own. Other classes that are capable of displaying rich text (such asQLabel,QWhatsThis orQMessageBox) 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:
staticconstchar* myimage_data[]={"...",..."..."};
To be able to use this image within some rich text, for example inside aQLabel, you must create aQImage 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 textQLabel with
QLabel* label=newQLabel("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);
Constructs aQ3MimeSourceFactory that has no file path and no stored content.
[virtual]Q3MimeSourceFactory::~Q3MimeSourceFactory()Destroys theQ3MimeSourceFactory, deleting all stored content.
[static]void Q3MimeSourceFactory::addFactory(Q3MimeSourceFactory * f)Adds theQ3MimeSourceFactoryf to the list of available mimesource factories. If thedefaultFactory() can't resolve adata() it iterates over the list of installed mimesource factories until the data can be resolved.
See alsoremoveFactory().
Adds another search path,p to the existing search paths.
See alsosetFilePath().
[virtual]constQMimeSource * Q3MimeSourceFactory::data(constQString & abs_name) constReturns a reference to the data associated withabs_name. The return value remains valid only until the next data() orsetData() call, so you should immediately decode the result.
If there is no data associated withabs_name in the factory's store, the factory tries to access the local filesystem. Ifabs_name isn't an absolute file name, the factory will search for it in all defined paths (seesetFilePath()).
The factory understands all the image formats supported byQImageReader. 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 tosetExtensionType(). If the extension mechanism is not sufficient for your problem domain, you can inheritQ3MimeSourceFactory 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 alsosetData().
This is an overloaded function.
A convenience function. See data(constQString& abs_name). The file name is given inabs_or_rel_name and the path is incontext.
[static]Q3MimeSourceFactory * Q3MimeSourceFactory::defaultFactory()Returns the application-wide default mime source factory. This factory is used by rich text rendering classes such asQSimpleRichText,QWhatsThis andQMessageBox to resolve named references within rich text documents. It serves also as the initial factory for the more complex render widgets,QTextEdit andQTextBrowser.
See alsosetDefaultFactory().
[virtual]QStringList Q3MimeSourceFactory::filePath() constReturns the currently set search paths.
See alsosetFilePath().
[virtual]QString Q3MimeSourceFactory::makeAbsolute(constQString & abs_or_rel_name, constQString & context) constConverts the absolute or relative data item nameabs_or_rel_name to an absolute name, interpreted within the context (path) of the data item namedcontext (this must be an absolute name).
[static]void Q3MimeSourceFactory::removeFactory(Q3MimeSourceFactory * f)Removes the mimesource factoryf from the list of available mimesource factories.
See alsoaddFactory().
[virtual]void Q3MimeSourceFactory::setData(constQString & abs_name,QMimeSource * data)Setsdata to be the data item associated with the absolute nameabs_name. Note that the ownership ofdata 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 alsodata().
[static]void Q3MimeSourceFactory::setDefaultFactory(Q3MimeSourceFactory * factory)Sets the defaultfactory, destroying any previously set mime source provider. The ownership of the factory is transferred to Qt.
See alsodefaultFactory().
[virtual]void Q3MimeSourceFactory::setExtensionType(constQString & ext, constchar * mimetype)Sets the mime-type to be associated with the file name extension,ext tomimetype. This determines the mime-type for files found via the paths set bysetFilePath().
[virtual]void Q3MimeSourceFactory::setFilePath(constQStringList & path)Sets the list of directories that will be searched when named data is requested to those given in the string listpath.
See alsofilePath().
Sets the list of directories that will be searched when named data is requested to those given in the string listpath.
See alsofilePath().
[virtual]void Q3MimeSourceFactory::setImage(constQString & abs_name, constQImage & image)Setsimage to be the data item associated with the absolute nameabs_name.
Equivalent tosetData(abs_name, newQ3ImageDrag(image)).
[virtual]void Q3MimeSourceFactory::setPixmap(constQString & abs_name, constQPixmap & pixmap)Setspixmap to be the data item associated with the absolute nameabs_name.
[virtual]void Q3MimeSourceFactory::setText(constQString & abs_name, constQString & text)Setstext to be the data item associated with the absolute nameabs_name.
Equivalent tosetData(abs_name, newQ3TextDrag(text)).
[static]Q3MimeSourceFactory * Q3MimeSourceFactory::takeDefaultFactory()Sets thedefaultFactory() to 0 and returns the previous one.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.