summaryrefslogtreecommitdiffstats
path: root/src/widgets/accessible
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@qt.io>2019-05-13 11:13:17 +0200
committerJan Arve Sæther <jan-arve.saether@qt.io>2019-05-13 10:07:30 +0000
commit3da9d8a4fefc6f4e06320d2ba4c7c5fa8ebd1a10 (patch)
treed07194dc65d878eadbbd01147271893f7573fe44 /src/widgets/accessible
parent45aa3c73f78c6c06874d0f826e1f112976cd522d (diff)
Make sure QAccessibleTableCell is valid before reference
There are some cases (model resets in weird positions) where we would crash due to accessing invalid model indices. Fixes: QTBUG-61416 Fixes: QTBUG-71608 Change-Id: Ibfedcbd921a3145f3e1596ac424a77f2319a5c46 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/widgets/accessible')
-rw-r--r--src/widgets/accessible/itemviews.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/widgets/accessible/itemviews.cpp b/src/widgets/accessible/itemviews.cpp
index 51cfaa7f5e..3bfe215c05 100644
--- a/src/widgets/accessible/itemviews.cpp
+++ b/src/widgets/accessible/itemviews.cpp
@@ -897,11 +897,15 @@ QHeaderView *QAccessibleTableCell::verticalHeader() const
int QAccessibleTableCell::columnIndex() const
{
+ if (!isValid())
+ return -1;
return m_index.column();
}
int QAccessibleTableCell::rowIndex() const
{
+ if (!isValid())
+ return -1;
#if QT_CONFIG(treeview)
if (role() == QAccessible::TreeItem) {
const QTreeView *treeView = qobject_cast<const QTreeView*>(view);
@@ -915,6 +919,8 @@ int QAccessibleTableCell::rowIndex() const
bool QAccessibleTableCell::isSelected() const
{
+ if (!isValid())
+ return false;
return view->selectionModel()->isSelected(m_index);
}
@@ -943,8 +949,10 @@ QStringList QAccessibleTableCell::keyBindingsForAction(const QString &) const
void QAccessibleTableCell::selectCell()
{
+ if (!isValid())
+ return;
QAbstractItemView::SelectionMode selectionMode = view->selectionMode();
- if (!m_index.isValid() || (selectionMode == QAbstractItemView::NoSelection))
+ if (selectionMode == QAbstractItemView::NoSelection)
return;
Q_ASSERT(table());
QAccessibleTableInterface *cellTable = table()->tableInterface();
@@ -971,9 +979,10 @@ void QAccessibleTableCell::selectCell()
void QAccessibleTableCell::unselectCell()
{
-
+ if (!isValid())
+ return;
QAbstractItemView::SelectionMode selectionMode = view->selectionMode();
- if (!m_index.isValid() || (selectionMode == QAbstractItemView::NoSelection))
+ if (selectionMode == QAbstractItemView::NoSelection)
return;
QAccessibleTableInterface *cellTable = table()->tableInterface();
@@ -1014,7 +1023,7 @@ QAccessible::Role QAccessibleTableCell::role() const
QAccessible::State QAccessibleTableCell::state() const
{
QAccessible::State st;
- if (!view)
+ if (!isValid())
return st;
QRect globalRect = view->rect();
@@ -1054,6 +1063,8 @@ QAccessible::State QAccessibleTableCell::state() const
QRect QAccessibleTableCell::rect() const
{
QRect r;
+ if (!isValid())
+ return r;
r = view->visualRect(m_index);
if (!r.isNull()) {
@@ -1065,8 +1076,10 @@ QRect QAccessibleTableCell::rect() const
QString QAccessibleTableCell::text(QAccessible::Text t) const
{
- QAbstractItemModel *model = view->model();
QString value;
+ if (!isValid())
+ return value;
+ QAbstractItemModel *model = view->model();
switch (t) {
case QAccessible::Name:
value = model->data(m_index, Qt::AccessibleTextRole).toString();
@@ -1084,7 +1097,7 @@ QString QAccessibleTableCell::text(QAccessible::Text t) const
void QAccessibleTableCell::setText(QAccessible::Text /*t*/, const QString &text)
{
- if (!(m_index.flags() & Qt::ItemIsEditable))
+ if (!isValid() || !(m_index.flags() & Qt::ItemIsEditable))
return;
view->model()->setData(m_index, text);
}