⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmimedata.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
*/QList<QUrl> QMimeData::urls() const{    Q_D(const QMimeData);    QVariant data = d->retrieveTypedData(QLatin1String("text/uri-list"), QVariant::List);    QList<QUrl> urls;    if (data.type() == QVariant::Url)        urls.append(data.toUrl());    else if (data.type() == QVariant::List) {        QList<QVariant> list = data.toList();        for (int i = 0; i < list.size(); ++i) {            if (list.at(i).type() == QVariant::Url)                urls.append(list.at(i).toUrl());        }    }    return urls;}/*!    Sets the URLs stored in the MIME data object to those specified by \a urls.    URLs correspond to the MIME type \c text/uri-list.    \sa hasUrls(), setData()*/void QMimeData::setUrls(const QList<QUrl> &urls){    Q_D(QMimeData);    QList<QVariant> list;    for (int i = 0; i < urls.size(); ++i)        list.append(urls.at(i));    d->setData(QLatin1String("text/uri-list"), list);}/*!    Returns true if the object can return a list of urls; otherwise    returns false.    URLs correspond to the MIME type \c text/uri-list.    \sa setUrls(), urls(), hasFormat()*/bool QMimeData::hasUrls() const{    return hasFormat(QLatin1String("text/uri-list"));}/*!    Returns a plain text (MIME type \c text/plain) representation of    the data.    \sa hasText(), html(), data()*/QString QMimeData::text() const{    Q_D(const QMimeData);    QVariant data = d->retrieveTypedData(QLatin1String("text/plain"), QVariant::String);    return data.toString();}/*!    Sets \a text as the plain text (MIME type \c text/plain) used to    represent the data.    \sa hasText(), setHtml(), setData()*/void QMimeData::setText(const QString &text){    Q_D(QMimeData);    d->setData(QLatin1String("text/plain"), text);}/*!    Returns true if the object can return plain text (MIME type \c    text/plain); otherwise returns false.    \sa setText(), text(), hasHtml(), hasFormat()*/bool QMimeData::hasText() const{    return hasFormat(QLatin1String("text/plain"));}/*!    Returns a string if the data stored in the object is HTML (MIME    type \c text/html); otherwise returns an empty string.    \sa hasHtml(), setData()*/QString QMimeData::html() const{    Q_D(const QMimeData);    QVariant data = d->retrieveTypedData(QLatin1String("text/html"), QVariant::String);    return data.toString();}/*!    Sets \a html as the HTML (MIME type \c text/html) used to    represent the data.    \sa hasHtml(), setText(), setData()*/void QMimeData::setHtml(const QString &html){    Q_D(QMimeData);    d->setData(QLatin1String("text/html"), html);}/*!    Returns true if the object can return HTML (MIME type \c    text/html); otherwise returns false.    \sa setHtml(), html(), hasFormat()*/bool QMimeData::hasHtml() const{    return hasFormat(QLatin1String("text/html"));}/*!    Returns a 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 \l QtCore    library, whereas QImage belongs to \l QtGui. To convert the    QVariant to a QImage, simply use qvariant_cast(). For example:    \code        if (event->mimeData()->hasImage()) {            QImage image = qvariant_cast<QImage>(event->mimeData()->imageData());            ...        }    \endcode    \sa hasImage()*/QVariant QMimeData::imageData() const{    Q_D(const QMimeData);    return d->retrieveTypedData(QLatin1String("application/x-qt-image"), QVariant::Image);}/*!    Sets the data in the object to the given \a image.    A QVariant is used because QMimeData belongs to the \l QtCore    library, whereas QImage belongs to \l QtGui. The conversion    from QImage to QVariant is implicit. For example:    \code        mimeData->setImageData(QImage("beautifulfjord.png"));    \endcode    \sa hasImage(), setData()*/void QMimeData::setImageData(const QVariant &image){    Q_D(QMimeData);    d->setData(QLatin1String("application/x-qt-image"), image);}/*!    Returns true if the object can return an image; otherwise returns    false.    \sa setImageData(), imageData(), hasFormat()*/bool QMimeData::hasImage() const{    return hasFormat(QLatin1String("application/x-qt-image"));}/*!    Returns a color if the data stored in the object represents a    color (MIME type \c application/x-color); otherwise returns a    null variant.    A QVariant is used because QMimeData belongs to the \l QtCore    library, whereas QColor belongs to \l QtGui. To convert the    QVariant to a QColor, simply use qvariant_cast(). For example:    \code        if (event->mimeData()->hasColor()) {            QColor color = qvariant_cast<QColor>(event->mimeData()->colorData());            ...        }    \endcode    \sa hasColor(), setColorData(), data()*/QVariant QMimeData::colorData() const{    Q_D(const QMimeData);    return d->retrieveTypedData(QLatin1String("application/x-color"), QVariant::Color);}/*!    Sets the color data in the object to the given \a color.    Colors correspond to the MIME type \c application/x-color.    \sa hasColor(), setData()*/void QMimeData::setColorData(const QVariant &color){    Q_D(QMimeData);    d->setData(QLatin1String("application/x-color"), color);}/*!    Returns true if the object can return a color (MIME type \c    application/x-color); otherwise returns false.    \sa setColorData(), colorData(), hasFormat()*/bool QMimeData::hasColor() const{    return hasFormat(QLatin1String("application/x-color"));}/*!    Returns the data stored in the object in the format described by    the MIME type specified by \a mimeType.*/QByteArray QMimeData::data(const QString &mimeType) const{    Q_D(const QMimeData);    QVariant data = d->retrieveTypedData(mimeType, QVariant::ByteArray);    return data.toByteArray();}/*!    Sets the data associated with the MIME type given by \a mimeType    to the specified \a data.    For the most common types of data, you can call the higher-level    functions setText(), setHtml(), setUrls(), setImageData(), and    setColorData() instead.    \sa hasFormat()*/void QMimeData::setData(const QString &mimeType, const QByteArray &data){    Q_D(QMimeData);    d->setData(mimeType, QVariant(data));}/*!    Returns true if the object can return data for the MIME type    specified by \a 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.    \sa formats(), setData(), data()*/bool QMimeData::hasFormat(const QString &mimeType) const{    return formats().contains(mimeType);}/*!    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.    \sa hasFormat(), setData(), data()*/QStringList QMimeData::formats() const{    Q_D(const QMimeData);    QStringList list;    for (int i=0; i<d->dataList.size(); i++)        list += d->dataList.at(i).format;    return list;}/*!    Returns a variant with the given \a type containing data for the    MIME type specified by \a mimeType. If the object does not    support the MIME type or variant type given, a null variant is    returned instead.    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().    \sa data()*/QVariant QMimeData::retrieveData(const QString &mimeType, QVariant::Type type) const{    Q_UNUSED(type);    Q_D(const QMimeData);    return d->getData(mimeType);}/*!    Removes all the MIME type and data entries in the object.*/void QMimeData::clear(){    Q_D(QMimeData);    d->dataList.clear();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -