KDeclarative

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

KDE's Doxygen guidelines are available online.