QAccessibleComboBox: Cleanup comboBox() calls
Handle comboBox() returning nullptr. Avoid repeated qobject_cast by calling comboBox() once per function. Fixes: QTBUG-115161 Pick-to: 6.5 6.2 Change-Id: I3d102cebe807da379fa4d9ee2aee1e72b8fdf004 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit fc556e3571b7e2d7fe307778b17e6cf0ff9e1bfc) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
416081ef4f
commit
718bb11701
@ -283,17 +283,19 @@ QAccessibleComboBox::QAccessibleComboBox(QWidget *w)
|
|||||||
*/
|
*/
|
||||||
QComboBox *QAccessibleComboBox::comboBox() const
|
QComboBox *QAccessibleComboBox::comboBox() const
|
||||||
{
|
{
|
||||||
return qobject_cast<QComboBox*>(object());
|
return qobject_cast<QComboBox *>(object());
|
||||||
}
|
}
|
||||||
|
|
||||||
QAccessibleInterface *QAccessibleComboBox::child(int index) const
|
QAccessibleInterface *QAccessibleComboBox::child(int index) const
|
||||||
{
|
{
|
||||||
|
if (QComboBox *cBox = comboBox()) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
QAbstractItemView *view = comboBox()->view();
|
QAbstractItemView *view = cBox->view();
|
||||||
//QWidget *parent = view ? view->parentWidget() : 0;
|
//QWidget *parent = view ? view->parentWidget() : 0;
|
||||||
return QAccessible::queryAccessibleInterface(view);
|
return QAccessible::queryAccessibleInterface(view);
|
||||||
} else if (index == 1 && comboBox()->isEditable()) {
|
} else if (index == 1 && cBox->isEditable()) {
|
||||||
return QAccessible::queryAccessibleInterface(comboBox()->lineEdit());
|
return QAccessible::queryAccessibleInterface(cBox->lineEdit());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -301,22 +303,28 @@ QAccessibleInterface *QAccessibleComboBox::child(int index) const
|
|||||||
int QAccessibleComboBox::childCount() const
|
int QAccessibleComboBox::childCount() const
|
||||||
{
|
{
|
||||||
// list and text edit
|
// list and text edit
|
||||||
return comboBox()->isEditable() ? 2 : 1;
|
if (QComboBox *cBox = comboBox())
|
||||||
|
return (cBox->isEditable()) ? 2 : 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QAccessibleInterface *QAccessibleComboBox::childAt(int x, int y) const
|
QAccessibleInterface *QAccessibleComboBox::childAt(int x, int y) const
|
||||||
{
|
{
|
||||||
if (comboBox()->isEditable() && comboBox()->lineEdit()->rect().contains(x, y))
|
if (QComboBox *cBox = comboBox()) {
|
||||||
|
if (cBox->isEditable() && cBox->lineEdit()->rect().contains(x, y))
|
||||||
return child(1);
|
return child(1);
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QAccessibleComboBox::indexOfChild(const QAccessibleInterface *child) const
|
int QAccessibleComboBox::indexOfChild(const QAccessibleInterface *child) const
|
||||||
{
|
{
|
||||||
if (comboBox()->view() == child->object())
|
if (QComboBox *cBox = comboBox()) {
|
||||||
|
if (cBox->view() == child->object())
|
||||||
return 0;
|
return 0;
|
||||||
if (comboBox()->isEditable() && comboBox()->lineEdit() == child->object())
|
if (cBox->isEditable() && cBox->lineEdit() == child->object())
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,8 +333,10 @@ QAccessibleInterface *QAccessibleComboBox::focusChild() const
|
|||||||
// The editable combobox is the focus proxy of its lineedit, so the
|
// The editable combobox is the focus proxy of its lineedit, so the
|
||||||
// lineedit itself never gets focus. But it is the accessible focus
|
// lineedit itself never gets focus. But it is the accessible focus
|
||||||
// child of an editable combobox.
|
// child of an editable combobox.
|
||||||
if (comboBox()->isEditable())
|
if (QComboBox *cBox = comboBox()) {
|
||||||
|
if (cBox->isEditable())
|
||||||
return child(1);
|
return child(1);
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,7 +344,7 @@ QAccessibleInterface *QAccessibleComboBox::focusChild() const
|
|||||||
QString QAccessibleComboBox::text(QAccessible::Text t) const
|
QString QAccessibleComboBox::text(QAccessible::Text t) const
|
||||||
{
|
{
|
||||||
QString str;
|
QString str;
|
||||||
|
if (QComboBox *cBox = comboBox()) {
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case QAccessible::Name:
|
case QAccessible::Name:
|
||||||
#ifndef Q_OS_UNIX // on Linux we use relations for this, name is text (fall through to Value)
|
#ifndef Q_OS_UNIX // on Linux we use relations for this, name is text (fall through to Value)
|
||||||
@ -342,10 +352,10 @@ QString QAccessibleComboBox::text(QAccessible::Text t) const
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case QAccessible::Value:
|
case QAccessible::Value:
|
||||||
if (comboBox()->isEditable())
|
if (cBox->isEditable())
|
||||||
str = comboBox()->lineEdit()->text();
|
str = cBox->lineEdit()->text();
|
||||||
else
|
else
|
||||||
str = comboBox()->currentText();
|
str = cBox->currentText();
|
||||||
break;
|
break;
|
||||||
#ifndef QT_NO_SHORTCUT
|
#ifndef QT_NO_SHORTCUT
|
||||||
case QAccessible::Accelerator:
|
case QAccessible::Accelerator:
|
||||||
@ -357,6 +367,7 @@ QString QAccessibleComboBox::text(QAccessible::Text t) const
|
|||||||
}
|
}
|
||||||
if (str.isEmpty())
|
if (str.isEmpty())
|
||||||
str = QAccessibleWidget::text(t);
|
str = QAccessibleWidget::text(t);
|
||||||
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,10 +375,11 @@ QAccessible::State QAccessibleComboBox::state() const
|
|||||||
{
|
{
|
||||||
QAccessible::State s = QAccessibleWidget::state();
|
QAccessible::State s = QAccessibleWidget::state();
|
||||||
|
|
||||||
|
if (QComboBox *cBox = comboBox()) {
|
||||||
s.expandable = true;
|
s.expandable = true;
|
||||||
s.expanded = isValid() && comboBox()->view()->isVisible();
|
s.expanded = isValid() && cBox->view()->isVisible();
|
||||||
s.editable = comboBox()->isEditable();
|
s.editable = cBox->isEditable();
|
||||||
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,18 +397,19 @@ QString QAccessibleComboBox::localizedActionDescription(const QString &actionNam
|
|||||||
|
|
||||||
void QAccessibleComboBox::doAction(const QString &actionName)
|
void QAccessibleComboBox::doAction(const QString &actionName)
|
||||||
{
|
{
|
||||||
|
if (QComboBox *cBox = comboBox()) {
|
||||||
if (actionName == showMenuAction() || actionName == pressAction()) {
|
if (actionName == showMenuAction() || actionName == pressAction()) {
|
||||||
if (comboBox()->view()->isVisible()) {
|
if (cBox->view()->isVisible()) {
|
||||||
#if defined(Q_OS_ANDROID)
|
#if defined(Q_OS_ANDROID)
|
||||||
const auto list = child(0)->tableInterface();
|
const auto list = child(0)->tableInterface();
|
||||||
if (list && list->selectedRowCount() > 0) {
|
if (list && list->selectedRowCount() > 0) {
|
||||||
comboBox()->setCurrentIndex(list->selectedRows().at(0));
|
cBox->setCurrentIndex(list->selectedRows().at(0));
|
||||||
}
|
}
|
||||||
comboBox()->setFocus();
|
cBox->setFocus();
|
||||||
#endif
|
#endif
|
||||||
comboBox()->hidePopup();
|
cBox->hidePopup();
|
||||||
} else {
|
} else {
|
||||||
comboBox()->showPopup();
|
cBox->showPopup();
|
||||||
#if defined(Q_OS_ANDROID)
|
#if defined(Q_OS_ANDROID)
|
||||||
const auto list = child(0)->tableInterface();
|
const auto list = child(0)->tableInterface();
|
||||||
if (list && list->selectedRowCount() > 0) {
|
if (list && list->selectedRowCount() > 0) {
|
||||||
@ -407,6 +420,7 @@ void QAccessibleComboBox::doAction(const QString &actionName)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList QAccessibleComboBox::keyBindingsForAction(const QString &/*actionName*/) const
|
QStringList QAccessibleComboBox::keyBindingsForAction(const QString &/*actionName*/) const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user