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
qaccessiblebridgeutils.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
4#include <QtCore/qmath.h>
5
7
9
10static bool performAction(QAccessibleInterface *iface, const QString &actionName)
11{
12 if (QAccessibleActionInterface *actionIface = iface->actionInterface()) {
13 if (actionIface->actionNames().contains(actionName)) {
14 actionIface->doAction(actionName);
15 return true;
16 }
17 }
18 return false;
19}
20
21QStringList effectiveActionNames(QAccessibleInterface *iface)
22{
23 QStringList actions;
24 if (QAccessibleActionInterface *actionIface = iface->actionInterface())
25 actions = actionIface->actionNames();
26
27 if (iface->valueInterface()) {
28 if (!actions.contains(QAccessibleActionInterface::increaseAction()))
29 actions << QAccessibleActionInterface::increaseAction();
30 if (!actions.contains(QAccessibleActionInterface::decreaseAction()))
31 actions << QAccessibleActionInterface::decreaseAction();
32 }
33 return actions;
34}
35
36bool performEffectiveAction(QAccessibleInterface *iface, const QString &actionName)
37{
38 if (!iface)
39 return false;
40 if (performAction(iface, actionName))
41 return true;
42 if (actionName != QAccessibleActionInterface::increaseAction()
43 && actionName != QAccessibleActionInterface::decreaseAction())
44 return false;
45
46 QAccessibleValueInterface *valueIface = iface->valueInterface();
47 if (!valueIface)
48 return false;
49 bool success;
50 const QVariant currentVariant = valueIface->currentValue();
51 double stepSize = valueIface->minimumStepSize().toDouble(&success);
52 if (!success || qFuzzyIsNull(stepSize)) {
53 const double min = valueIface->minimumValue().toDouble(&success);
54 if (!success)
55 return false;
56 const double max = valueIface->maximumValue().toDouble(&success);
57 if (!success)
58 return false;
59 stepSize = (max - min) / 10; // this is pretty arbitrary, we just need to provide something
60 const int typ = currentVariant.userType();
61 if (typ != QMetaType::Float && typ != QMetaType::Double) {
62 // currentValue is an integer. Round it up to ensure stepping in case it was below 1
63 stepSize = qCeil(stepSize);
64 }
65 }
66 const double current = currentVariant.toDouble(&success);
67 if (!success)
68 return false;
69 if (actionName == QAccessibleActionInterface::decreaseAction())
70 stepSize = -stepSize;
71 valueIface->setCurrentValue(current + stepSize);
72 return true;
73}
74
75} //namespace
76
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
double toDouble(bool *ok=nullptr) const
Returns the variant as a double if the variant has userType() \l QMetaType::Double,...
QStringList effectiveActionNames(QAccessibleInterface *iface)
static bool performAction(QAccessibleInterface *iface, const QString &actionName)
bool performEffectiveAction(QAccessibleInterface *iface, const QString &actionName)
Combined button and popup list for selecting options.
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
int qCeil(T v)
Definition qmath.h:36