Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowsinternalmimedata.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
8#include <QtCore/qdebug.h>
9#include <QtCore/qvariant.h>
10
11/*!
12 \class QWindowsInternalMimeDataBase
13 \brief Base for implementations of QInternalMimeData using a IDataObject COM object.
14
15 In clipboard handling and Drag and drop, static instances
16 of QInternalMimeData implementations are kept and passed to the client.
17
18 QInternalMimeData provides virtuals that query the formats and retrieve
19 mime data on demand when the client invokes functions like QMimeData::hasHtml(),
20 QMimeData::html() on the instance returned. Otherwise, expensive
21 construction of a new QMimeData object containing all possible
22 formats would have to be done in each call to mimeData().
23
24 The base class introduces new virtuals to obtain and release
25 the instances IDataObject from the clipboard or Drag and Drop and
26 does conversion using QWindowsMimeConverter classes.
27
28 \sa QInternalMimeData, QWindowsMimeConverter, QWindowsMimeRegistry
29 \internal
30*/
31
32bool QWindowsInternalMimeData::hasFormat_sys(const QString &mime) const
33{
34 IDataObject *pDataObj = retrieveDataObject();
35 if (!pDataObj)
36 return false;
37
39 const bool has = mc.converterToMime(mime, pDataObj) != nullptr;
40 releaseDataObject(pDataObj);
41 qCDebug(lcQpaMime) << __FUNCTION__ << mime << has;
42 return has;
43}
44
46{
47 IDataObject *pDataObj = retrieveDataObject();
48 if (!pDataObj)
49 return QStringList();
50
52 const QStringList fmts = mc.allMimesForFormats(pDataObj);
53 releaseDataObject(pDataObj);
54 qCDebug(lcQpaMime) << __FUNCTION__ << fmts;
55 return fmts;
56}
57
58QVariant QWindowsInternalMimeData::retrieveData_sys(const QString &mimeType, QMetaType type) const
59{
60 IDataObject *pDataObj = retrieveDataObject();
61 if (!pDataObj)
62 return QVariant();
63
64 QVariant result;
66 if (auto converter = mc.converterToMime(mimeType, pDataObj))
67 result = converter->convertToMime(mimeType, pDataObj, type);
68 releaseDataObject(pDataObj);
70 qCDebug(lcQpaMime) <<__FUNCTION__ << ' ' << mimeType << ' ' << type.name()
71 << " returns " << result.metaType().name()
72 << (result.metaType().id() != QMetaType::QByteArray ? result.toString() : QStringLiteral("<data>"));
73 }
74 return result;
75}
Singleton container for all relevant information.
QWindowsMimeRegistry & mimeConverter() const
static QWindowsContext * instance()
bool hasFormat_sys(const QString &mimetype) const override
QVariant retrieveData_sys(const QString &mimetype, QMetaType preferredType) const override
QStringList formats_sys() const override
Manages the list of QWindowsMimeConverter instances.