KDeclarative

MimeDataWrapper.cpp
1/*
2 SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#include "MimeDataWrapper.h"
8#include <QMimeData>
9#include <QUrl>
10
11MimeDataWrapper::MimeDataWrapper(const QMimeData *data, QObject *parent)
12 : QObject(parent)
13 , m_data(data)
14{
15}
16
18{
19 return m_data->text();
20}
21
23{
24 return m_data->html();
25}
26
28{
29 if (m_data->hasUrls() && !m_data->urls().isEmpty()) {
30 return m_data->urls().constFirst();
31 }
32 return QUrl();
33}
34
35bool MimeDataWrapper::hasUrls() const
36{
37 return m_data->hasUrls();
38}
39
41{
42 QJsonArray varUrls;
43 const auto urls = m_data->urls();
44 for (const QUrl &url : urls) {
45 varUrls.append(url.toString());
46 }
47 return varUrls;
48}
49
51{
52 if (m_data->hasColor()) {
53 return m_data->colorData();
54 } else {
55 return QVariant();
56 }
57}
58
60{
61 return m_data->formats();
62}
63
64QByteArray MimeDataWrapper::getDataAsByteArray(const QString &format)
65{
66 return m_data->data(format);
67}
68
70{
71 // In case it comes from a DeclarativeMimeData
72 return m_data->property("source");
73}
74
76{
77 return const_cast<QMimeData *>(m_data);
78}
79
80#include "moc_MimeDataWrapper.cpp"
QMimeData * mimeData
QUrl url
Url contained in the mimedata.
QString text
A plain text (MIME type text/plain) representation of the data.
QStringList formats
Mimetypes provided by the mime data instance.
QString html
A string if the data stored in the object is HTML (MIME type text/html); otherwise returns an empty s...
QVariant source
The graphical item on the scene that started the drag event.
QVariant color
A color if the data stored in the object represents a color (MIME type application/x-color); otherwis...
QJsonArray urls
A list of URLs contained within the MIME data object.
void append(const QJsonValue &value)
QVariant colorData() const const
QByteArray data(const QString &mimeType) const const
virtual QStringList formats() const const
bool hasColor() const const
bool hasUrls() const const
QString html() const const
QString text() const const
QList< QUrl > urls() const const
QVariant property(const char *name) const const
QString toString(FormattingOptions options) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.