KDeclarative

MimeDataWrapper.cpp
1 /*
2  Copyright (C) 2015 by Aleix Pol Gonzalez <[email protected]>
3 
4  Permission is hereby granted, free of charge, to any person obtaining a copy
5  of this software and associated documentation files (the "Software"), to deal
6  in the Software without restriction, including without limitation the rights
7  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  copies of the Software, and to permit persons to whom the Software is
9  furnished to do so, subject to the following conditions:
10 
11  The above copyright notice and this permission notice shall be included in
12  all copies or substantial portions of the Software.
13 
14  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  THE SOFTWARE.
21 */
22 
23 #include "MimeDataWrapper.h"
24 #include <QMimeData>
25 #include <QUrl>
26 
27 MimeDataWrapper::MimeDataWrapper(const QMimeData* data, QObject* parent)
28  : QObject(parent)
29  , m_data(data)
30 {}
31 
33 {
34  return m_data->text();
35 }
36 
38 {
39  return m_data->html();
40 }
41 
43 {
44  if ( m_data->hasUrls() && !m_data->urls().isEmpty()) {
45  return m_data->urls().first();
46  }
47  return QUrl();
48 }
49 
50 bool MimeDataWrapper::hasUrls() const
51 {
52  return m_data->hasUrls();
53 }
54 
56 {
57  QJsonArray varUrls;
58  const auto urls = m_data->urls();
59  for (const QUrl &url : urls) {
60  varUrls.append(url.toString());
61  }
62  return varUrls;
63 }
64 
66 {
67  if (m_data->hasColor())
68  return m_data->colorData();
69  else
70  return QVariant();
71 }
72 
74 {
75  return m_data->formats();
76 }
77 
78 
79 QByteArray MimeDataWrapper::getDataAsByteArray(const QString& format)
80 {
81  return m_data->data(format);
82 }
83 
85 {
86 // In case it comes from a DeclarativeMimeData
87  return m_data->property("source");
88 }
89 
91 {
92  return const_cast<QMimeData*>(m_data);
93 }
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 Wed Aug 5 2020 22:37:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.