Coverage Report

Created: 2026-10-14 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/gui/accessible/qaccessiblecache_p.h
Line
Count
Source
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
#ifndef QACCESSIBLECACHE_P
5
#define QACCESSIBLECACHE_P
6
7
//
8
//  W A R N I N G
9
//  -------------
10
//
11
// This file is not part of the Qt API.  It exists purely as an
12
// implementation detail.  This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#include <QtGui/private/qtguiglobal_p.h>
19
#include <QtCore/qobject.h>
20
#include <QtCore/qhash.h>
21
22
#include "qaccessible.h"
23
24
#if QT_CONFIG(accessibility)
25
26
Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QMacAccessibilityElement));
27
28
QT_BEGIN_NAMESPACE
29
30
class Q_GUI_EXPORT QAccessibleObjectDestroyedEvent :public QAccessibleEvent
31
{
32
public:
33
    /* A regular event, used when the object is still alive
34
    */
35
    inline QAccessibleObjectDestroyedEvent(QObject *obj)
36
        : QAccessibleEvent(obj, QAccessible::ObjectDestroyed)
37
0
    {
38
0
    }
39
    /* A regular event, used when there is no object
40
    */
41
    inline QAccessibleObjectDestroyedEvent(QAccessibleInterface *iface)
42
        : QAccessibleEvent(static_cast<QObject *>(nullptr), QAccessible::ObjectDestroyed)
43
0
    {
44
0
        m_uniqueId = QAccessible::uniqueId(iface);
45
0
    }
46
    /* An event with object() == nullptr, and uniqueid set,
47
    used during object destruction */
48
    inline QAccessibleObjectDestroyedEvent(QAccessible::Id uniqueId)
49
0
        : QAccessibleEvent(static_cast<QObject *>(nullptr), QAccessible::ObjectDestroyed)
50
0
    {
51
0
        m_uniqueId = uniqueId;
52
0
    }
53
    ~QAccessibleObjectDestroyedEvent();
54
};
55
56
class Q_GUI_EXPORT QAccessibleCache  :public QObject
57
{
58
    Q_OBJECT
59
60
public:
61
    ~QAccessibleCache() override;
62
    static QAccessibleCache *instance();
63
    QAccessibleInterface *interfaceForId(QAccessible::Id id) const;
64
    QAccessible::Id idForInterface(QAccessibleInterface *iface) const;
65
    QAccessible::Id idForObject(QObject *obj) const;
66
    bool containsObject(QObject *obj) const;
67
    QAccessible::Id insert(QObject *object, QAccessibleInterface *iface) const;
68
    void deleteInterface(QAccessible::Id id, QObject *obj = nullptr);
69
    void sendObjectDestroyedEvent(QObject *obj);
70
#ifdef Q_OS_APPLE
71
    QT_MANGLE_NAMESPACE(QMacAccessibilityElement) *elementForId(QAccessible::Id axid) const;
72
    bool insertElement(QAccessible::Id axid, QT_MANGLE_NAMESPACE(QMacAccessibilityElement) *element) const;
73
#endif
74
75
private Q_SLOTS:
76
    void objectDestroyed(QObject *obj);
77
78
private:
79
    QAccessible::Id acquireId() const;
80
81
    mutable QHash<QAccessible::Id, QAccessibleInterface *> idToInterface;
82
    mutable QHash<QAccessibleInterface *, QAccessible::Id> interfaceToId;
83
    mutable QMultiHash<QObject *, std::pair<QAccessible::Id, const QMetaObject*>> objectToId;
84
85
#ifdef Q_OS_APPLE
86
    void removeAccessibleElement(QAccessible::Id axid);
87
    mutable QHash<QAccessible::Id, QT_MANGLE_NAMESPACE(QMacAccessibilityElement) *> accessibleElements;
88
#endif
89
90
    friend class QAccessible;
91
    friend class QAccessibleInterface;
92
};
93
94
QT_END_NAMESPACE
95
96
#endif // QT_CONFIG(accessibility)
97
98
#endif