Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdnd.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
4#include "qdnd_p.h"
5
6#include "qguiapplication.h"
7#include <ctype.h>
8#include <qpa/qplatformdrag.h>
9#include <qpa/qplatformintegration.h>
10#include <private/qguiapplication_p.h>
11
13
14// the universe's only drag manager
15QDragManager *QDragManager::m_instance = nullptr;
16
18 : QObject(qApp), m_currentDropTarget(nullptr),
19 m_platformDrag(QGuiApplicationPrivate::platformIntegration()->drag()),
20 m_object(nullptr)
21{
22 Q_ASSERT(!m_instance);
23}
24
26{
27 m_instance = nullptr;
28}
29
31{
32 if (!m_instance && !QGuiApplication::closingDown())
33 m_instance = new QDragManager;
34 return m_instance;
35}
36
38{
39 if (m_object)
40 return m_object->source();
41 return nullptr;
42}
43
45{
46 if (m_currentDropTarget == target)
47 return;
48
49 m_currentDropTarget = target;
50 if (!dropped && m_object) {
51 m_object->d_func()->target = target;
52 emit m_object->targetChanged(target);
53 }
54}
55
57{
58 return m_currentDropTarget;
59}
60
62{
63 if (!o || m_object == o)
64 return Qt::IgnoreAction;
65
66 if (!m_platformDrag || !o->source()) {
67 o->deleteLater();
68 return Qt::IgnoreAction;
69 }
70
71 if (m_object) {
72 qWarning("QDragManager::drag in possibly invalid state");
73 return Qt::IgnoreAction;
74 }
75
76 m_object = o;
77
78 m_object->d_func()->target = nullptr;
79
80 QGuiApplicationPrivate::instance()->notifyDragStarted(m_object.data());
81 const Qt::DropAction result = m_platformDrag->drag(m_object);
82 if (!m_object.isNull() && !m_platformDrag->ownsDragObject())
83 m_object->deleteLater();
84
85 m_object.clear();
86 return result;
87}
88
90
91#include "moc_qdnd_p.cpp"
static bool closingDown()
Returns true if the application objects are being destroyed; otherwise returns false.
QDragManager()
Definition qdnd.cpp:17
void setCurrentTarget(QObject *target, bool dropped=false)
Definition qdnd.cpp:44
QObject * source() const
Definition qdnd.cpp:37
~QDragManager()
Definition qdnd.cpp:25
Qt::DropAction drag(QDrag *)
Definition qdnd.cpp:61
QObject * currentTarget() const
Definition qdnd.cpp:56
static QDragManager * self()
Definition qdnd.cpp:30
\inmodule QtGui
Definition qdrag.h:22
QObject * source() const
Returns the source of the drag object.
Definition qdrag.cpp:168
QObject * target() const
Returns the target of the drag and drop operation.
Definition qdrag.cpp:178
void targetChanged(QObject *newTarget)
This signal is emitted when the target of the drag and drop operation changes, with newTarget the new...
static QGuiApplicationPrivate * instance()
\inmodule QtCore
Definition qobject.h:103
void deleteLater()
\threadsafe
Definition qobject.cpp:2435
virtual bool ownsDragObject() const
Returns bool indicating whether QPlatformDrag takes ownership and therefore responsibility of deletin...
virtual Qt::DropAction drag(QDrag *m_drag)=0
void clear() noexcept
Definition qpointer.h:87
T * data() const noexcept
Definition qpointer.h:73
bool isNull() const noexcept
Definition qpointer.h:84
Combined button and popup list for selecting options.
DropAction
@ IgnoreAction
#define qApp
#define qWarning
Definition qlogging.h:166
GLenum target
GLuint64EXT * result
[6]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
QObject::connect nullptr