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
qwindowsuiaprovidercache.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 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 <QtGui/qtguiglobal.h>
5#if QT_CONFIG(accessibility)
6
8#include "qwindowsuiautils.h"
9#include "qwindowscontext.h"
10
12
13using namespace QWindowsUiAutomation;
14
15
16// Private constructor
17QWindowsUiaProviderCache::QWindowsUiaProviderCache()
18{
19}
20
21// shared instance
22QWindowsUiaProviderCache *QWindowsUiaProviderCache::instance()
23{
24 static QWindowsUiaProviderCache providerCache;
25 return &providerCache;
26}
27
28// Returns the provider instance associated with the ID, or nullptr.
29QWindowsUiaBaseProvider *QWindowsUiaProviderCache::providerForId(QAccessible::Id id) const
30{
31 return m_providerTable.value(id);
32}
33
34// Inserts a provider in the cache and associates it with an accessibility ID.
35void QWindowsUiaProviderCache::insert(QAccessible::Id id, QWindowsUiaBaseProvider *provider)
36{
37 remove(id);
38 if (provider) {
39 m_providerTable[id] = provider;
40 m_inverseTable[provider] = id;
41 // Connects the destroyed signal to our slot, to remove deleted objects from the cache.
42 QObject::connect(provider, &QObject::destroyed, this, &QWindowsUiaProviderCache::objectDestroyed, Qt::DirectConnection);
43 }
44}
45
46// Removes deleted provider objects from the cache.
47void QWindowsUiaProviderCache::objectDestroyed(QObject *obj)
48{
49 // We have to use the inverse table to map the object address back to its ID,
50 // since at this point (called from QObject destructor), it has already been
51 // partially destroyed and we cannot treat it as a provider.
52 auto it = m_inverseTable.find(obj);
53 if (it != m_inverseTable.end()) {
54 m_providerTable.remove(*it);
55 m_inverseTable.remove(obj);
56 }
57}
58
59// Removes a provider with a given id from the cache.
60void QWindowsUiaProviderCache::remove(QAccessible::Id id)
61{
62 m_inverseTable.remove(m_providerTable.value(id));
63 m_providerTable.remove(id);
64}
65
67
68#endif // QT_CONFIG(accessibility)
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
iterator end()
Definition qset.h:140
iterator find(const T &value)
Definition qset.h:159
QSet< QString >::iterator it
Combined button and popup list for selecting options.
@ DirectConnection
GLenum GLuint id
[7]
GLhandleARB obj
[2]
settings remove("monkey")