CopperSpice API
1.9.2
|
The QMimeData class provides a container for data and the associated MIME type. More...
Public Methods | |
QMimeData () | |
~QMimeData () | |
void | clear () |
QVariant | colorData () const |
QByteArray | data (const QString &mimeType) const |
virtual QStringList | formats () const |
bool | hasColor () const |
virtual bool | hasFormat (const QString &mimeType) const |
bool | hasHtml () const |
bool | hasImage () const |
bool | hasText () const |
bool | hasUrls () const |
QString | html () const |
QVariant | imageData () const |
void | removeFormat (const QString &mimeType) |
void | setColorData (const QVariant &color) |
void | setData (const QString &mimeType, const QByteArray &data) |
void | setHtml (const QString &html) |
void | setImageData (const QVariant &image) |
void | setText (const QString &text) |
void | setUrls (const QList< QUrl > &urls) |
QString | text () const |
QList< QUrl > | urls () const |
Public Methods inherited from QObject | |
QObject (QObject *parent=nullptr) | |
~QObject () | |
bool | blockSignals (bool block) |
const QList< QObject * > & | children () const |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QString > | dynamicPropertyNames () const |
virtual bool | event (QEvent *event) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
template<class T > | |
QList< T > | findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
bool | inherits (const QString &className) const |
void | installEventFilter (QObject *filterObj) |
bool | isWidgetType () const |
bool | isWindowType () const |
void | killTimer (int id) |
const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | property (const QString &name) const |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const QString &name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
QThread * | thread () const |
Protected Methods | |
virtual QVariant | retrieveData (const QString &mimeType, QVariant::Type preferredType) const |
Protected Methods inherited from QObject | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signalMethod) const |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signalMethod) const |
bool | isSignalConnected (const QMetaMethod &signalMethod) const |
int | receivers (const QString &signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Additional Inherited Members | |
Public Signals inherited from QObject | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
Public Slots inherited from QObject | |
void | deleteLater () |
Static Public Methods inherited from QObject | |
static bool | connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ()) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...)) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod) |
static QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
Properties inherited from QObject | |
objectName | |
Related Functions inherited from QObject | |
T | qobject_cast (QObject *object) |
QObjectList | |
The QMimeData class provides a container for data and the associated 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 CopperSpice 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.
QMimeData provides various methods to access data for the most common MIME types.
Tester | Getter | Setter | MIME Types |
---|---|---|---|
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 |
For example, if your write a widget that accepts URL drags, you would end up writing code like this:
There are three approaches for storing custom data in a QMimeData object.
Custom data can be stored directly in a QMimeData object as a QByteArray using setData().
If the drag and drop operation occurs within a single application, we can subclass QMimeData and add extra data in it, and use a qobject_cast() in the receiver's drop event handler.
On Windows, 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.
The following are examples of custom MIME types.
The value
declaration of each format describes the way in which the data is encoded.
QMimeData::QMimeData | ( | ) |
Constructs a new MIME data object with no data in it.
QMimeData::~QMimeData | ( | ) |
Destroys the MIME data object.
void QMimeData::clear | ( | ) |
Removes all the MIME type and data entries in the object.
QVariant QMimeData::colorData | ( | ) | const |
Returns a color if the data stored in the object represents a color (MIME type application/x-color
), otherwise returns a null variant.
A QVariant is used because QMimeData is in the CsCore library, whereas QColor is part of CsGui. To convert the QVariant to a QColor, simply use qvariant_cast().
QByteArray QMimeData::data | ( | const QString & | mimeType | ) | const |
Returns the data stored in the object in the format described by the MIME type specified by mimeType.
|
virtual |
Returns a list of formats supported by the object. This is a list of MIME types for which the object can return suitable data. The formats in the list are in a priority order.
For the most common types of data, you can call the higher-level functions hasText(), hasHtml(), hasUrls(), hasImage(), and hasColor() instead.
bool QMimeData::hasColor | ( | ) | const |
Returns true if the object can return a color (MIME type application/x-color
), otherwise returns false.
|
virtual |
Returns true if the object can return data for the MIME type specified by mimeType, otherwise returns false.
For the most common types of data, you can call the higher-level functions hasText(), hasHtml(), hasUrls(), hasImage(), and hasColor() instead.
bool QMimeData::hasHtml | ( | ) | const |
Returns true if the object can return HTML (MIME type text/html
), otherwise returns false.
bool QMimeData::hasImage | ( | ) | const |
Returns true if the object can return an image, otherwise returns false.
bool QMimeData::hasText | ( | ) | const |
Returns true if the object can return plain text (MIME type text/plain
), otherwise returns false.
bool QMimeData::hasUrls | ( | ) | const |
Returns true if the object can return a list of urls, otherwise returns false.
URLs correspond to the MIME type text/uri-list
.
QString QMimeData::html | ( | ) | const |
QVariant QMimeData::imageData | ( | ) | const |
Returns a QVariant storing a QImage if the object can return an image, otherwise returns a null variant. A QVariant is used because QMimeData is in the CsCore library, whereas QImage is part of CsGui. To convert the QVariant to a QImage, simply use qvariant_cast().
void QMimeData::removeFormat | ( | const QString & | mimeType | ) |
Removes the data entry for mimeType in the object.
|
protectedvirtual |
Returns a variant with the given preferredType containing data for the MIME type specified by mimeType. If the object does not support the MIME type or variant type given, a null variant is returned instead.
This method 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().
void QMimeData::setColorData | ( | const QVariant & | color | ) |
Sets the color data in the object to the given color.
Colors correspond to the MIME type application/x-color
.
void QMimeData::setData | ( | const QString & | mimeType, |
const QByteArray & | data | ||
) |
Sets the data associated with the MIME type given by mimeType to the specified data. For the most common types of data, you can call the higher-level functions setText(), setHtml(), setUrls(), setImageData(), and setColorData() instead.
void QMimeData::setHtml | ( | const QString & | html | ) |
void QMimeData::setImageData | ( | const QVariant & | image | ) |
Sets the data in the object to the given image. A QVariant is used because QMimeData is in the CsCore library, whereas QImage is part of CsGui. The conversion from QImage to QVariant is implicit.
void QMimeData::setText | ( | const QString & | text | ) |
QString QMimeData::text | ( | ) | const |