|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.core.QMimeData
public class QMimeData
The QMimeData
class provides a container for data that records information about its MIME type. QMimeData
is used to describe information that can be stored in the clipboard
, and transferred via the drag and drop mechanism. QMimeData
objects associate the data that they hold with the corresponding MIME types to ensure that information can be safely transferred between applications, and copied around within the same application.
QMimeData
objects are usually created using new and supplied to QDrag
or QClipboard
objects. This is to enable Qt to manage the memory that they use.
A single QMimeData
object can store the same data using several different formats at the same time. The formats()
function returns a list of the available formats in order of preference. The data()
function returns the raw data associated with a MIME type, and setData()
allows you to set the data for a MIME type.
For the most common MIME types, QMimeData
provides convenience functions to access the data:
hasText() | text() | setText() | text/plain |
hasHtml() | html() | setHtml() | text/html |
hasUrls() | urls() | setUrls() | text/uri-list |
hasImage() | imageData() | setImageData() | image/ * |
hasColor() | colorData() | setColorData() | application/x-color |
void MyWidget::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasUrls()) event->acceptProposedAction(); } void MyWidget::dropEvent(QDropEvent *event) { if (event->mimeData()->hasUrls()) { foreach (QUrl url, event->mimeData()->urls()) { ... } } }There are three approaches for storing custom data in a
QMimeData
object: QMimeData
object as a QByteArray
using setData()
. For example:QByteArray csvData = ...; QMimeData *mimeData = new QMimeData; mimeData->setData("text/csv", csvData);
QMimeData
and reimplement hasFormat()
, formats()
, and retrieveData()
.QMimeData
and add extra data in it, and use a qobject_cast() in the receiver's drop event handler. For example:void MyWidget::dropEvent(QDropEvent *event) { const MyMimeData *myData = qobject_cast<const MyMimeData *>(event->mimeData()); if (myData) { // access myData's data directly (not through QMimeData's API) } }
formats()
will also return custom formats available in the MIME data, using the x-qt-windows-mime subtype to indicate that they represent data in non-standard formats. The formats will take the following form:application/x-qt-windows-mime;value="<custom type>"The following are examples of custom MIME types:
application/x-qt-windows-mime;value="FileGroupDescriptor" application/x-qt-windows-mime;value="FileContents"The value declaration of each format describes the way in which the data is encoded.
On Windows, the MIME format does not always map directly to the clipboard formats. Qt provides QWindowsMime to map clipboard formats to open-standard MIME formats. Similarly, the QMacPasteboardMime maps MIME to Mac flavors.
QClipboard
, QDragEnterEvent
, QDragMoveEvent
, QDropEvent
, QDrag
, QWindowsMime, QMacPasteboardMime, and Drag and Drop.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Constructor Summary | |
---|---|
QMimeData()
Constructs a new MIME data object with no data in it. |
Method Summary | |
---|---|
void |
clear()
Removes all the MIME type and data entries in the object. |
java.lang.Object |
colorData()
Returns a color if the data stored in the object represents a color (MIME type application/x-color); otherwise returns a null variant. |
QByteArray |
data(java.lang.String mimetype)
Returns the data stored in the object in the format described by the MIME type specified by mimeType. |
java.util.List |
formats()
Returns a list of formats supported by the object. |
static QMimeData |
fromNativePointer(QNativePointer nativePointer)
|
boolean |
hasColor()
Returns true if the object can return a color (MIME type application/x-color); otherwise returns false. |
boolean |
hasFormat(java.lang.String mimetype)
Returns true if the object can return data for the MIME type specified by mimeType; otherwise returns false. |
boolean |
hasHtml()
Returns true if the object can return HTML (MIME type text/html); otherwise returns false. |
boolean |
hasImage()
Returns true if the object can return an image; otherwise returns false. |
boolean |
hasText()
Returns true if the object can return plain text (MIME type text/plain); otherwise returns false. |
boolean |
hasUrls()
Returns true if the object can return a list of urls; otherwise returns false. |
java.lang.String |
html()
Returns a string if the data stored in the object is HTML (MIME type text/html); otherwise returns an empty string. |
java.lang.Object |
imageData()
Returns a QVariant storing a QImage if the object can return an image; otherwise returns a null variant. |
void |
removeFormat(java.lang.String mimetype)
Removes the data entry for mimeType in the object. |
protected java.lang.Object |
retrieveData(java.lang.String mimetype,
int preferredType)
Returns a variant with the given type containing data for the MIME type specified by mimeType. |
void |
setColorData(java.lang.Object color)
Sets the color data in the object to the given color. |
void |
setData(java.lang.String mimetype,
QByteArray data)
Sets the data associated with the MIME type given by mimeType to the specified data. |
void |
setHtml(java.lang.String html)
Sets html as the HTML (MIME type text/html) used to represent the data. |
void |
setImageData(java.lang.Object image)
Sets the data in the object to the given image. |
void |
setText(java.lang.String text)
Sets text as the plain text (MIME type text/plain) used to represent the data. |
void |
setUrls(java.util.List urls)
Sets the URLs stored in the MIME data object to those specified by urls. |
java.lang.String |
text()
Returns a plain text (MIME type text/plain) representation of the data. |
java.util.List |
urls()
Returns a list of URLs contained within the MIME data object. |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QMimeData()
Method Detail |
---|
public final void clear()
public final java.lang.Object colorData()
A QVariant
is used because QMimeData
belongs to the QtCore library, whereas QColor
belongs to QtGui. To convert the QVariant
to a QColor
, simply use qvariant_cast(). For example:
The following code example is written in c++.
if (event->mimeData()->hasColor()) { QColor color = qvariant_cast<QColor>(event->mimeData()->colorData()); ... }
hasColor()
, setColorData()
, and data()
.
public final QByteArray data(java.lang.String mimetype)
setData()
.
public final boolean hasColor()
setColorData()
, colorData()
, and hasFormat()
.
public final boolean hasHtml()
setHtml()
, html()
, and hasFormat()
.
public final boolean hasImage()
setImageData()
, imageData()
, and hasFormat()
.
public final boolean hasText()
setText()
, text()
, hasHtml()
, and hasFormat()
.
public final boolean hasUrls()
URLs correspond to the MIME type text/uri-list.
setUrls()
, urls()
, and hasFormat()
.
public final java.lang.String html()
setHtml()
, hasHtml()
, and setData()
.
public final java.lang.Object imageData()
QVariant
storing a QImage
if the object can return an image; otherwise returns a null variant. A QVariant
is used because QMimeData
belongs to the QtCore library, whereas QImage
belongs to QtGui. To convert the QVariant
to a QImage
, simply use qvariant_cast(). For example:
The following code example is written in c++.
if (event->mimeData()->hasImage()) { QImage image = qvariant_cast<QImage>(event->mimeData()->imageData()); ... }
setImageData()
, and hasImage()
.
public final void removeFormat(java.lang.String mimetype)
public final void setColorData(java.lang.Object color)
Colors correspond to the MIME type application/x-color.
colorData()
, hasColor()
, and setData()
.
public final void setData(java.lang.String mimetype, QByteArray data)
For the most common types of data, you can call the higher-level functions setText()
, setHtml()
, setUrls()
, setImageData()
, and setColorData()
instead.
data()
, and hasFormat()
.
public final void setHtml(java.lang.String html)
html()
, hasHtml()
, setText()
, and setData()
.
public final void setImageData(java.lang.Object image)
A QVariant
is used because QMimeData
belongs to the QtCore library, whereas QImage
belongs to QtGui. The conversion from QImage
to QVariant
is implicit. For example:
The following code example is written in c++.
mimeData->setImageData(QImage("beautifulfjord.png"));
imageData()
, hasImage()
, and setData()
.
public final void setText(java.lang.String text)
text()
, hasText()
, setHtml()
, and setData()
.
public final void setUrls(java.util.List urls)
URLs correspond to the MIME type text/uri-list.
urls()
, hasUrls()
, and setData()
.
public final java.lang.String text()
setText()
, hasText()
, html()
, and data()
.
public final java.util.List urls()
URLs correspond to the MIME type text/uri-list.
setUrls()
, hasUrls()
, and data()
.
public java.util.List formats()
For the most common types of data, you can call the higher-level functions hasText()
, hasHtml()
, hasUrls()
, hasImage()
, and hasColor()
instead.
hasFormat()
, setData()
, and data()
.
public boolean hasFormat(java.lang.String mimetype)
For the most common types of data, you can call the higher-level functions hasText()
, hasHtml()
, hasUrls()
, hasImage()
, and hasColor()
instead.
formats()
, setData()
, and data()
.
protected java.lang.Object retrieveData(java.lang.String mimetype, int preferredType)
This function is called by the general data()
getter and by the convenience getters (text()
, html()
, urls()
, imageData()
, and colorData()
). You can reimplement it if you want to store your data using a custom data structure (instead of a QByteArray
, which is what setData()
provides). You would then also need to reimplement hasFormat()
and formats()
.
data()
.
public static QMimeData fromNativePointer(QNativePointer nativePointer)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |