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
7#include <QtCore/qdebug.h>
8#include <QtCore/qvariant.h>
9
10/*!
11 \class QWindowsInternalMimeDataBase
12 \brief Base for implementations of QInternalMimeData using a IDataObject COM object.
13
14 In clipboard handling and Drag and drop, static instances
15 of QInternalMimeData implementations are kept and passed to the client.
16
17 QInternalMimeData provides virtuals that query the formats and retrieve
18 mime data on demand when the client invokes functions like QMimeData::hasHtml(),
19 QMimeData::html() on the instance returned. Otherwise, expensive
20 construction of a new QMimeData object containing all possible
21 formats would have to be done in each call to mimeData().
22
23 The base class introduces new virtuals to obtain and release
24 the instances IDataObject from the clipboard or Drag and Drop and
25 does conversion using QWindowsMimeConverter classes.
26
27 \sa QInternalMimeData, QWindowsMimeConverter, QWindowsMimeRegistry
28 \internal
29*/
30
31bool QWindowsInternalMimeData::hasFormat_sys(const QString &mime) const
32{
33 IDataObject *pDataObj = retrieveDataObject();
34 if (!pDataObj)
35 return false;
36
38 const bool has = mc.converterToMime(mime, pDataObj) != nullptr;
39 releaseDataObject(pDataObj);
40 qCDebug(lcQpaMime) << __FUNCTION__ << mime << has;
41 return has;
42}
43
45{
46 IDataObject *pDataObj = retrieveDataObject();
47 if (!pDataObj)
48 return QStringList();
49
51 const QStringList fmts = mc.allMimesForFormats(pDataObj);
52 releaseDataObject(pDataObj);
53 qCDebug(lcQpaMime) << __FUNCTION__ << fmts;
54 return fmts;
55}
56
57QVariant QWindowsInternalMimeData::retrieveData_sys(const QString &mimeType, QMetaType type) const
58{
59 IDataObject *pDataObj = retrieveDataObject();
60 if (!pDataObj)
61 return QVariant();
62
63 QVariant result;
65 if (auto converter = mc.converterToMime(mimeType, pDataObj))
66 result = converter->convertToMime(mimeType, pDataObj, type);
67 releaseDataObject(pDataObj);
69 qCDebug(lcQpaMime) <<__FUNCTION__ << ' ' << mimeType << ' ' << type.name()
70 << " returns " << result.metaType().name()
71 << (result.metaType().id() != QMetaType::QByteArray ? result.toString() : QStringLiteral("<data>"));
72 }
73 return result;
74}
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.