返回介绍

QMimeSourceFactory Class

发布于 2019-10-04 15:01:38 字数 10494 浏览 937 评论 0 收藏 0

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

#include <qmime.h>

List of all member functions.

Public Members

  • QMimeSourceFactory ()
  • virtual ~QMimeSourceFactory ()
  • virtual const QMimeSource * data ( constQString&abs_name ) const
  • virtual QString makeAbsolute ( constQString&abs_or_rel_name, constQString&context ) const
  • const QMimeSource * data ( constQString&abs_or_rel_name, constQString&context ) const
  • virtual void setText ( constQString&abs_name, constQString&text )
  • virtual void setImage ( constQString&abs_name, constQImage&image )
  • virtual void setPixmap ( constQString&abs_name, constQPixmap&pixmap )
  • virtual void setData ( constQString&abs_name, QMimeSource*data )
  • virtual void setFilePath ( constQStringList&path )
  • virtual QStringList filePath () const
  • void addFilePath ( constQString&p )
  • virtual void setExtensionType ( constQString&ext, constchar*mimetype )

Static Public Members

  • QMimeSourceFactory * defaultFactory ()
  • void setDefaultFactory ( QMimeSourceFactory*factory )
  • QMimeSourceFactory * takeDefaultFactory ()
  • void addFactory ( QMimeSourceFactory*f )
  • void removeFactory ( QMimeSourceFactory*f )

Detailed Description

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

A QMimeSourceFactory 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 QImageDrag::canDecode() and QImageDrag::decode().

The base QMimeSourceFactory 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 QMimeSourceFactory to resolve references such as images or links within rich text documents. They either access the default factory (see defaultFactory()) or their own (see QTextEdit::setMimeSourceFactory()). 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:

    QMimeSourceFactory::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>?" );
    

See also Environment Classes and Input/Output and Networking.


Member Function Documentation

QMimeSourceFactory::QMimeSourceFactory ()

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

QMimeSourceFactory::~QMimeSourceFactory () [virtual]

Destroys the QMimeSourceFactory, deleting all stored content.

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

Adds the QMimeSourceFactory 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 QMimeSourceFactory::addFilePath ( constQString&p )

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

See also setFilePath().

constQMimeSource* QMimeSourceFactory::data ( constQString&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 QImageIO. 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 "html" or "htm" will be treated as text encoded in the iso8859-1 encoding, those 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 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 QMimeSourceFactory 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.

constQMimeSource* QMimeSourceFactory::data ( constQString&abs_or_rel_name, constQString&context ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above 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.

QMimeSourceFactory* QMimeSourceFactory::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().

Examples: action/application.cpp and application/application.cpp.

QStringList QMimeSourceFactory::filePath () const [virtual]

Returns the currently set search paths.

QString QMimeSourceFactory::makeAbsolute ( constQString&abs_or_rel_name, constQString&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 QMimeSourceFactory::removeFactory ( QMimeSourceFactory*f ) [static]

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

See also addFactory().

void QMimeSourceFactory::setData ( constQString&abs_name, QMimeSource*data ) [virtual]

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

The ownership of data is transferred to the factory: do not delete or access the pointer after passing it to this function.

void QMimeSourceFactory::setDefaultFactory ( QMimeSourceFactory*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 QMimeSourceFactory::setExtensionType ( constQString&ext, constchar*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 QMimeSourceFactory::setFilePath ( constQStringList&path ) [virtual]

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

See also filePath().

void QMimeSourceFactory::setImage ( constQString&abs_name, constQImage&image ) [virtual]

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

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

void QMimeSourceFactory::setPixmap ( constQString&abs_name, constQPixmap&pixmap ) [virtual]

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

void QMimeSourceFactory::setText ( constQString&abs_name, constQString&text ) [virtual]

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

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

QMimeSourceFactory* QMimeSourceFactory::takeDefaultFactory () [static]

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文