Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QWindowsMimeConverter Class Referenceabstract

The QWindowsMimeConverter class maps open-standard MIME to Window Clipboard formats. More...

#include <qwindowsmimeconverter.h>

+ Inheritance diagram for QWindowsMimeConverter:
+ Collaboration diagram for QWindowsMimeConverter:

Public Member Functions

 QWindowsMimeConverter ()
 Constructs a QWindowsMimeConverter instance.
 
virtual ~QWindowsMimeConverter ()
 Constructs a QWindowsMimeConverter instance.
 
virtual bool canConvertFromMime (const FORMATETC &formatetc, const QMimeData *mimeData) const =0
 Returns true if the converter can convert from the mimeData to the format specified in formatetc.
 
virtual bool convertFromMime (const FORMATETC &formatetc, const QMimeData *mimeData, STGMEDIUM *pmedium) const =0
 Convert the mimeData to the format specified in formatetc.
 
virtual QList< FORMATETCformatsForMime (const QString &mimeType, const QMimeData *mimeData) const =0
 Returns a QList of FORMATETC structures representing the different windows clipboard formats that can be provided for the mimeType from the mimeData.
 
virtual bool canConvertToMime (const QString &mimeType, IDataObject *pDataObj) const =0
 Returns true if the converter can convert to the mimeType from the available formats in pDataObj.
 
virtual QVariant convertToMime (const QString &mimeType, IDataObject *pDataObj, QMetaType preferredType) const =0
 Returns a QVariant containing the converted data for mimeType from pDataObj.
 
virtual QString mimeForFormat (const FORMATETC &formatetc) const =0
 Returns the mime type that will be created form the format specified in formatetc, or an empty string if this converter does not support formatetc.
 

Static Public Member Functions

static int registerMimeType (const QString &mimeType)
 Registers the MIME type mimeType, and returns an ID number identifying the format on Windows.
 

Detailed Description

The QWindowsMimeConverter class maps open-standard MIME to Window Clipboard formats.

\inmodule QtGui

Qt's drag-and-drop and clipboard facilities use the MIME standard. On X11, this maps trivially to the Xdnd protocol, but on Windows although some applications use MIME types to describe clipboard formats, others use arbitrary non-standardized naming conventions, or unnamed built-in formats of Windows.

By instantiating subclasses of QWindowsMimeConverter that provide conversions between Windows Clipboard and MIME formats, you can convert proprietary clipboard formats to MIME formats.

Construct an instance of your converter implementation after instantiating QGuiApplication:

int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
JsonMimeConverter jsonConverter;
}
\macro qGuiApp
int main()
[0]
QApplication app(argc, argv)
[0]

Destroying the instance will unregister the converter and remove support for the conversion. It is also valid to heap-allocate the converter instance; Qt takes ownership and will delete the converter object during QGuiApplication shut-down.

Qt has predefined support for the following Windows Clipboard formats:

\table \header

  • Windows Format
  • Equivalent MIME type \row
  • CF_UNICODETEXT
  • text/plain \row
  • CF_TEXT
  • text/plain \row
  • CF_DIB
  • {image/xyz}, where xyz is a \l{QImageWriter::supportedImageFormats()}{Qt image format} \row
  • CF_HDROP
  • text/uri-list \row
  • CF_INETURL
  • text/uri-list \row
  • CF_HTML
  • text/html \endtable

An example use of this class would be to map the Windows Metafile clipboard format (CF_METAFILEPICT) to and from the MIME type {image/x-wmf}. This conversion might simply be adding or removing a header, or even just passing on the data. See \l{Drag and Drop} for more information on choosing and definition MIME types.

You can check if a MIME type is convertible using canConvertFromMime() and can perform conversions with convertToMime() and convertFromMime().

Definition at line 21 of file qwindowsmimeconverter.h.

Constructor & Destructor Documentation

◆ QWindowsMimeConverter()

QWindowsMimeConverter::QWindowsMimeConverter ( )

Constructs a QWindowsMimeConverter instance.

The instance is automatically registered, and will be called to convert data during clipboard or drag'n'drop operations.

Call this constructor after QGuiApplication has been created.

Definition at line 134 of file qwindowsmimeconverter.cpp.

References QGuiApplicationPrivate::platformIntegration(), and Q_ASSERT.

+ Here is the call graph for this function:

◆ ~QWindowsMimeConverter()

QWindowsMimeConverter::~QWindowsMimeConverter ( )
virtual

Constructs a QWindowsMimeConverter instance.

The instance is automatically unregistered.

Definition at line 147 of file qwindowsmimeconverter.cpp.

References QGuiApplicationPrivate::platformIntegration(), and Q_ASSERT.

+ Here is the call graph for this function:

Member Function Documentation

◆ canConvertFromMime()

bool QWindowsMimeConverter::canConvertFromMime ( const FORMATETC & formatetc,
const QMimeData * mimeData ) const
pure virtual

Returns true if the converter can convert from the mimeData to the format specified in formatetc.

All subclasses must reimplement this pure virtual function.

Implemented in QWindowsMimeText, QWindowsMimeURI, QWindowsMimeHtml, QWindowsMimeImage, QBuiltInMimes, and QLastResortMimes.

Referenced by QWindowsMimeRegistry::converterFromMime().

+ Here is the caller graph for this function:

◆ canConvertToMime()

bool QWindowsMimeConverter::canConvertToMime ( const QString & mimeType,
IDataObject * pDataObj ) const
pure virtual

Returns true if the converter can convert to the mimeType from the available formats in pDataObj.

All subclasses must reimplement this pure virtual function.

Implemented in QWindowsMimeText, QWindowsMimeURI, QWindowsMimeHtml, QWindowsMimeImage, QBuiltInMimes, and QLastResortMimes.

Referenced by QWindowsMimeRegistry::converterToMime().

+ Here is the caller graph for this function:

◆ convertFromMime()

bool QWindowsMimeConverter::convertFromMime ( const FORMATETC & formatetc,
const QMimeData * mimeData,
STGMEDIUM * pmedium ) const
pure virtual

Convert the mimeData to the format specified in formatetc.

The converted data should then be placed in pmedium structure.

Return true if the conversion was successful.

All subclasses must reimplement this pure virtual function.

Implemented in QWindowsMimeText, QWindowsMimeURI, QWindowsMimeHtml, QWindowsMimeImage, QBuiltInMimes, and QLastResortMimes.

◆ convertToMime()

QVariant QWindowsMimeConverter::convertToMime ( const QString & mimeType,
IDataObject * pDataObj,
QMetaType preferredType ) const
pure virtual

Returns a QVariant containing the converted data for mimeType from pDataObj.

If possible the QVariant should be of the preferredType to avoid needless conversions.

All subclasses must reimplement this pure virtual function.

Implemented in QWindowsMimeHtml, QWindowsMimeImage, QBuiltInMimes, and QLastResortMimes.

◆ formatsForMime()

QList< FORMATETC > QWindowsMimeConverter::formatsForMime ( const QString & mimeType,
const QMimeData * mimeData ) const
pure virtual

Returns a QList of FORMATETC structures representing the different windows clipboard formats that can be provided for the mimeType from the mimeData.

All subclasses must reimplement this pure virtual function.

Implemented in QWindowsMimeText, QWindowsMimeURI, QWindowsMimeHtml, QWindowsMimeImage, QBuiltInMimes, and QLastResortMimes.

Referenced by QWindowsMimeRegistry::allFormatsForMime().

+ Here is the caller graph for this function:

◆ mimeForFormat()

QString QWindowsMimeConverter::mimeForFormat ( const FORMATETC & formatetc) const
pure virtual

Returns the mime type that will be created form the format specified in formatetc, or an empty string if this converter does not support formatetc.

All subclasses must reimplement this pure virtual function.

Implemented in QWindowsMimeText, QWindowsMimeURI, QWindowsMimeHtml, QWindowsMimeImage, QBuiltInMimes, and QLastResortMimes.

Referenced by QWindowsMimeRegistry::allMimesForFormats().

+ Here is the caller graph for this function:

◆ registerMimeType()

int QWindowsMimeConverter::registerMimeType ( const QString & mimeType)
static

Registers the MIME type mimeType, and returns an ID number identifying the format on Windows.

A mime type {application/x-qt-windows-mime;value="WindowsType"} will be registered as the clipboard format for WindowsType.

Definition at line 162 of file qwindowsmimeconverter.cpp.

References mimeType, QGuiApplicationPrivate::platformIntegration(), and Q_ASSERT.

Referenced by QBuiltInMimes::QBuiltInMimes(), QWindowsMimeHtml::QWindowsMimeHtml(), QWindowsMimeURI::QWindowsMimeURI(), QLastResortMimes::canConvertToMime(), QLastResortMimes::convertToMime(), and QLastResortMimes::formatsForMime().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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