Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/accessible/itemviews.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | QAbstractItemView *QAccessibleTable::view() const | - | ||||||||||||
7 | { | - | ||||||||||||
8 | return qobject_cast<QAbstractItemView*>(object()); | - | ||||||||||||
9 | } | - | ||||||||||||
10 | - | |||||||||||||
11 | int QAccessibleTable::logicalIndex(const QModelIndex &index) const | - | ||||||||||||
12 | { | - | ||||||||||||
13 | if (!view()->model() || !index.isValid()) | - | ||||||||||||
14 | return -1; | - | ||||||||||||
15 | int vHeader = verticalHeader() ? 1 : 0; | - | ||||||||||||
16 | int hHeader = horizontalHeader() ? 1 : 0; | - | ||||||||||||
17 | return (index.row() + hHeader)*(index.model()->columnCount() + vHeader) + (index.column() + vHeader); | - | ||||||||||||
18 | } | - | ||||||||||||
19 | - | |||||||||||||
20 | QAccessibleTable::QAccessibleTable(QWidget *w) | - | ||||||||||||
21 | : QAccessibleObject(w) | - | ||||||||||||
22 | { | - | ||||||||||||
23 | ((!(view())) ? qt_assert("view()",__FILE__,7682) : qt_noop()); | - | ||||||||||||
24 | - | |||||||||||||
25 | if (qobject_cast<const QTableView*>(view())) { | - | ||||||||||||
26 | m_role = QAccessible::Table; | - | ||||||||||||
27 | } else if (qobject_cast<const QTreeView*>(view())) { | - | ||||||||||||
28 | m_role = QAccessible::Tree; | - | ||||||||||||
29 | } else if (qobject_cast<const QListView*>(view())) { | - | ||||||||||||
30 | m_role = QAccessible::List; | - | ||||||||||||
31 | } else { | - | ||||||||||||
32 | - | |||||||||||||
33 | m_role = QAccessible::Table; | - | ||||||||||||
34 | } | - | ||||||||||||
35 | } | - | ||||||||||||
36 | - | |||||||||||||
37 | bool QAccessibleTable::isValid() const | - | ||||||||||||
38 | { | - | ||||||||||||
39 | return (view() && !qobject_cast<QWidget*>(view())->d_func()->data.in_destructor); | - | ||||||||||||
40 | } | - | ||||||||||||
41 | - | |||||||||||||
42 | QAccessibleTable::~QAccessibleTable() | - | ||||||||||||
43 | { | - | ||||||||||||
44 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(childToId)>::type> _container_((childToId)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QAccessible::Id id = *_container_.i; _container_.control; _container_.control = 0) | - | ||||||||||||
45 | QAccessible::deleteAccessibleInterface(id); | - | ||||||||||||
46 | } | - | ||||||||||||
47 | - | |||||||||||||
48 | QHeaderView *QAccessibleTable::horizontalHeader() const | - | ||||||||||||
49 | { | - | ||||||||||||
50 | QHeaderView *header = 0; | - | ||||||||||||
51 | if (false) { dead code: { } | - | ||||||||||||
52 | - | |||||||||||||
53 | } dead code: else if (const QTableView *tv = qobject_cast<const QTableView*>(view())) {{ } | - | ||||||||||||
54 | header = tv->horizontalHeader(); | - | ||||||||||||
55 | - | |||||||||||||
56 | - | |||||||||||||
57 | } else if (const QTreeView *tv = qobject_cast<const QTreeView*>(view())) { | - | ||||||||||||
58 | header = tv->header(); | - | ||||||||||||
59 | - | |||||||||||||
60 | } | - | ||||||||||||
61 | return header; | - | ||||||||||||
62 | } | - | ||||||||||||
63 | - | |||||||||||||
64 | QHeaderView *QAccessibleTable::verticalHeader() const | - | ||||||||||||
65 | { | - | ||||||||||||
66 | QHeaderView *header = 0; | - | ||||||||||||
67 | if (false) { dead code: { } | - | ||||||||||||
68 | - | |||||||||||||
69 | } dead code: else if (const QTableView *tv = qobject_cast<const QTableView*>(view())) {{ } | - | ||||||||||||
70 | header = tv->verticalHeader(); | - | ||||||||||||
71 | - | |||||||||||||
72 | } | - | ||||||||||||
73 | return header; | - | ||||||||||||
74 | } | - | ||||||||||||
75 | - | |||||||||||||
76 | QAccessibleInterface *QAccessibleTable::cellAt(int row, int column) const | - | ||||||||||||
77 | { | - | ||||||||||||
78 | if (!view()->model()
| 0 | ||||||||||||
79 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
80 | ((!(role() != QAccessible::Tree)) ? qt_assert("role() != QAccessible::Tree",__FILE__,133139) : qt_noop()); | - | ||||||||||||
81 | QModelIndex index = view()->model()->index(row, column, view()->rootIndex()); | - | ||||||||||||
82 | if (!(__builtin_expect(!!(!
| 0 | ||||||||||||
83 | QMessageLogger(__FILE__, 136142, __PRETTY_FUNCTION__).warning() << "QAccessibleTable::cellAt: invalid index: " << index << " for " << view(); | - | ||||||||||||
84 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
85 | } | - | ||||||||||||
86 | return never executed: child(logicalIndex(index));return child(logicalIndex(index)); never executed: return child(logicalIndex(index)); | 0 | ||||||||||||
87 | } | - | ||||||||||||
88 | - | |||||||||||||
89 | QAccessibleInterface *QAccessibleTable::caption() const | - | ||||||||||||
90 | { | - | ||||||||||||
91 | return 0; | - | ||||||||||||
92 | } | - | ||||||||||||
93 | - | |||||||||||||
94 | QString QAccessibleTable::columnDescription(int column) const | - | ||||||||||||
95 | { | - | ||||||||||||
96 | if (!view()->model()) | - | ||||||||||||
97 | return QString(); | - | ||||||||||||
98 | return view()->model()->headerData(column, Qt::Horizontal).toString(); | - | ||||||||||||
99 | } | - | ||||||||||||
100 | - | |||||||||||||
101 | int QAccessibleTable::columnCount() const | - | ||||||||||||
102 | { | - | ||||||||||||
103 | if (!view()->model()) | - | ||||||||||||
104 | return 0; | - | ||||||||||||
105 | return view()->model()->columnCount(); | - | ||||||||||||
106 | } | - | ||||||||||||
107 | - | |||||||||||||
108 | int QAccessibleTable::rowCount() const | - | ||||||||||||
109 | { | - | ||||||||||||
110 | if (!view()->model()) | - | ||||||||||||
111 | return 0; | - | ||||||||||||
112 | return view()->model()->rowCount(); | - | ||||||||||||
113 | } | - | ||||||||||||
114 | - | |||||||||||||
115 | int QAccessibleTable::selectedCellCount() const | - | ||||||||||||
116 | { | - | ||||||||||||
117 | if (!view()->selectionModel()) | - | ||||||||||||
118 | return 0; | - | ||||||||||||
119 | return view()->selectionModel()->selectedIndexes().count(); | - | ||||||||||||
120 | } | - | ||||||||||||
121 | - | |||||||||||||
122 | int QAccessibleTable::selectedColumnCount() const | - | ||||||||||||
123 | { | - | ||||||||||||
124 | if (!view()->selectionModel()) | - | ||||||||||||
125 | return 0; | - | ||||||||||||
126 | return view()->selectionModel()->selectedColumns().count(); | - | ||||||||||||
127 | } | - | ||||||||||||
128 | - | |||||||||||||
129 | int QAccessibleTable::selectedRowCount() const | - | ||||||||||||
130 | { | - | ||||||||||||
131 | if (!view()->selectionModel()) | - | ||||||||||||
132 | return 0; | - | ||||||||||||
133 | return view()->selectionModel()->selectedRows().count(); | - | ||||||||||||
134 | } | - | ||||||||||||
135 | - | |||||||||||||
136 | QString QAccessibleTable::rowDescription(int row) const | - | ||||||||||||
137 | { | - | ||||||||||||
138 | if (!view()->model()) | - | ||||||||||||
139 | return QString(); | - | ||||||||||||
140 | return view()->model()->headerData(row, Qt::Vertical).toString(); | - | ||||||||||||
141 | } | - | ||||||||||||
142 | - | |||||||||||||
143 | QList<QAccessibleInterface *> QAccessibleTable::selectedCells() const | - | ||||||||||||
144 | { | - | ||||||||||||
145 | QList<QAccessibleInterface*> cells; | - | ||||||||||||
146 | if (!view()->selectionModel()) | - | ||||||||||||
147 | return cells; | - | ||||||||||||
148 | const QModelIndexList selectedIndexes = view()->selectionModel()->selectedIndexes(); | - | ||||||||||||
149 | cells.reserve(selectedIndexes.size()); | - | ||||||||||||
150 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(selectedIndexes)>::type> _container_((selectedIndexes)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QModelIndex &index = *_container_.i; _container_.control; _container_.control = 0) | - | ||||||||||||
151 | cells.append(child(logicalIndex(index))); | - | ||||||||||||
152 | return cells; | - | ||||||||||||
153 | } | - | ||||||||||||
154 | - | |||||||||||||
155 | QList<int> QAccessibleTable::selectedColumns() const | - | ||||||||||||
156 | { | - | ||||||||||||
157 | if (!view()->selectionModel()) | - | ||||||||||||
158 | return QList<int>(); | - | ||||||||||||
159 | QList<int> columns; | - | ||||||||||||
160 | const QModelIndexList selectedColumns = view()->selectionModel()->selectedColumns(); | - | ||||||||||||
161 | columns.reserve(selectedColumns.size()); | - | ||||||||||||
162 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(selectedColumns)>::type> _container_((selectedColumns)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QModelIndex &index = *_container_.i; _container_.control; _container_.control = 0) | - | ||||||||||||
163 | columns.append(index.column()); | - | ||||||||||||
164 | - | |||||||||||||
165 | return columns; | - | ||||||||||||
166 | } | - | ||||||||||||
167 | - | |||||||||||||
168 | QList<int> QAccessibleTable::selectedRows() const | - | ||||||||||||
169 | { | - | ||||||||||||
170 | if (!view()->selectionModel()) | - | ||||||||||||
171 | return QList<int>(); | - | ||||||||||||
172 | QList<int> rows; | - | ||||||||||||
173 | const QModelIndexList selectedRows = view()->selectionModel()->selectedRows(); | - | ||||||||||||
174 | rows.reserve(selectedRows.size()); | - | ||||||||||||
175 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(selectedRows)>::type> _container_((selectedRows)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QModelIndex &index = *_container_.i; _container_.control; _container_.control = 0) | - | ||||||||||||
176 | rows.append(index.row()); | - | ||||||||||||
177 | - | |||||||||||||
178 | return rows; | - | ||||||||||||
179 | } | - | ||||||||||||
180 | - | |||||||||||||
181 | QAccessibleInterface *QAccessibleTable::summary() const | - | ||||||||||||
182 | { | - | ||||||||||||
183 | return 0; | - | ||||||||||||
184 | } | - | ||||||||||||
185 | - | |||||||||||||
186 | bool QAccessibleTable::isColumnSelected(int column) const | - | ||||||||||||
187 | { | - | ||||||||||||
188 | if (!view()->selectionModel()) | - | ||||||||||||
189 | return false; | - | ||||||||||||
190 | return view()->selectionModel()->isColumnSelected(column, QModelIndex()); | - | ||||||||||||
191 | } | - | ||||||||||||
192 | - | |||||||||||||
193 | bool QAccessibleTable::isRowSelected(int row) const | - | ||||||||||||
194 | { | - | ||||||||||||
195 | if (!view()->selectionModel()) | - | ||||||||||||
196 | return false; | - | ||||||||||||
197 | return view()->selectionModel()->isRowSelected(row, QModelIndex()); | - | ||||||||||||
198 | } | - | ||||||||||||
199 | - | |||||||||||||
200 | bool QAccessibleTable::selectRow(int row) | - | ||||||||||||
201 | { | - | ||||||||||||
202 | if (!view()->model() || !view()->selectionModel()) | - | ||||||||||||
203 | return false; | - | ||||||||||||
204 | QModelIndex index = view()->model()->index(row, 0, view()->rootIndex()); | - | ||||||||||||
205 | - | |||||||||||||
206 | if (!index.isValid() || view()->selectionBehavior() == QAbstractItemView::SelectColumns) | - | ||||||||||||
207 | return false; | - | ||||||||||||
208 | - | |||||||||||||
209 | switch (view()->selectionMode()) { | - | ||||||||||||
210 | case QAbstractItemView::NoSelection: | - | ||||||||||||
211 | return false; | - | ||||||||||||
212 | case QAbstractItemView::SingleSelection: | - | ||||||||||||
213 | if (view()->selectionBehavior() != QAbstractItemView::SelectRows && columnCount() > 1 ) | - | ||||||||||||
214 | return false; | - | ||||||||||||
215 | view()->clearSelection(); | - | ||||||||||||
216 | break; | - | ||||||||||||
217 | case QAbstractItemView::ContiguousSelection: | - | ||||||||||||
218 | if ((!row || !view()->selectionModel()->isRowSelected(row - 1, view()->rootIndex())) | - | ||||||||||||
219 | && !view()->selectionModel()->isRowSelected(row + 1, view()->rootIndex())) | - | ||||||||||||
220 | view()->clearSelection(); | - | ||||||||||||
221 | break; | - | ||||||||||||
222 | default: | - | ||||||||||||
223 | break; | - | ||||||||||||
224 | } | - | ||||||||||||
225 | - | |||||||||||||
226 | view()->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); | - | ||||||||||||
227 | return true; | - | ||||||||||||
228 | } | - | ||||||||||||
229 | - | |||||||||||||
230 | bool QAccessibleTable::selectColumn(int column) | - | ||||||||||||
231 | { | - | ||||||||||||
232 | if (!view()->model() || !view()->selectionModel()) | - | ||||||||||||
233 | return false; | - | ||||||||||||
234 | QModelIndex index = view()->model()->index(0, column, view()->rootIndex()); | - | ||||||||||||
235 | - | |||||||||||||
236 | if (!index.isValid() || view()->selectionBehavior() == QAbstractItemView::SelectRows) | - | ||||||||||||
237 | return false; | - | ||||||||||||
238 | - | |||||||||||||
239 | switch (view()->selectionMode()) { | - | ||||||||||||
240 | case QAbstractItemView::NoSelection: | - | ||||||||||||
241 | return false; | - | ||||||||||||
242 | case QAbstractItemView::SingleSelection: | - | ||||||||||||
243 | if (view()->selectionBehavior() != QAbstractItemView::SelectColumns && rowCount() > 1) | - | ||||||||||||
244 | return false; | - | ||||||||||||
245 | case QAbstractItemView::ContiguousSelection: | - | ||||||||||||
246 | if ((!column || !view()->selectionModel()->isColumnSelected(column - 1, view()->rootIndex())) | - | ||||||||||||
247 | && !view()->selectionModel()->isColumnSelected(column + 1, view()->rootIndex())) | - | ||||||||||||
248 | view()->clearSelection(); | - | ||||||||||||
249 | break; | - | ||||||||||||
250 | default: | - | ||||||||||||
251 | break; | - | ||||||||||||
252 | } | - | ||||||||||||
253 | - | |||||||||||||
254 | view()->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Columns); | - | ||||||||||||
255 | return true; | - | ||||||||||||
256 | } | - | ||||||||||||
257 | - | |||||||||||||
258 | bool QAccessibleTable::unselectRow(int row) | - | ||||||||||||
259 | { | - | ||||||||||||
260 | if (!view()->model() || !view()->selectionModel()) | - | ||||||||||||
261 | return false; | - | ||||||||||||
262 | - | |||||||||||||
263 | QModelIndex index = view()->model()->index(row, 0, view()->rootIndex()); | - | ||||||||||||
264 | if (!index.isValid()) | - | ||||||||||||
265 | return false; | - | ||||||||||||
266 | - | |||||||||||||
267 | QItemSelection selection(index, index); | - | ||||||||||||
268 | - | |||||||||||||
269 | switch (view()->selectionMode()) { | - | ||||||||||||
270 | case QAbstractItemView::SingleSelection: | - | ||||||||||||
271 | - | |||||||||||||
272 | - | |||||||||||||
273 | if (selectedRowCount() == 1) | - | ||||||||||||
274 | return false; | - | ||||||||||||
275 | break; | - | ||||||||||||
276 | case QAbstractItemView::ContiguousSelection: | - | ||||||||||||
277 | if (selectedRowCount() == 1) | - | ||||||||||||
278 | return false; | - | ||||||||||||
279 | - | |||||||||||||
280 | if ((!row || view()->selectionModel()->isRowSelected(row - 1, view()->rootIndex())) | - | ||||||||||||
281 | && view()->selectionModel()->isRowSelected(row + 1, view()->rootIndex())) { | - | ||||||||||||
282 | - | |||||||||||||
283 | - | |||||||||||||
284 | selection = QItemSelection(index, view()->model()->index(rowCount() - 1, 0, view()->rootIndex())); | - | ||||||||||||
285 | } | - | ||||||||||||
286 | default: | - | ||||||||||||
287 | break; | - | ||||||||||||
288 | } | - | ||||||||||||
289 | - | |||||||||||||
290 | view()->selectionModel()->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Rows); | - | ||||||||||||
291 | return true; | - | ||||||||||||
292 | } | - | ||||||||||||
293 | - | |||||||||||||
294 | bool QAccessibleTable::unselectColumn(int column) | - | ||||||||||||
295 | { | - | ||||||||||||
296 | if (!view()->model() || !view()->selectionModel()) | - | ||||||||||||
297 | return false; | - | ||||||||||||
298 | - | |||||||||||||
299 | QModelIndex index = view()->model()->index(0, column, view()->rootIndex()); | - | ||||||||||||
300 | if (!index.isValid()) | - | ||||||||||||
301 | return false; | - | ||||||||||||
302 | - | |||||||||||||
303 | QItemSelection selection(index, index); | - | ||||||||||||
304 | - | |||||||||||||
305 | switch (view()->selectionMode()) { | - | ||||||||||||
306 | case QAbstractItemView::SingleSelection: | - | ||||||||||||
307 | - | |||||||||||||
308 | - | |||||||||||||
309 | if (selectedColumnCount() == 1) | - | ||||||||||||
310 | return false; | - | ||||||||||||
311 | break; | - | ||||||||||||
312 | case QAbstractItemView::ContiguousSelection: | - | ||||||||||||
313 | if (selectedColumnCount() == 1) | - | ||||||||||||
314 | return false; | - | ||||||||||||
315 | - | |||||||||||||
316 | if ((!column || view()->selectionModel()->isColumnSelected(column - 1, view()->rootIndex())) | - | ||||||||||||
317 | && view()->selectionModel()->isColumnSelected(column + 1, view()->rootIndex())) { | - | ||||||||||||
318 | - | |||||||||||||
319 | - | |||||||||||||
320 | selection = QItemSelection(index, view()->model()->index(0, columnCount() - 1, view()->rootIndex())); | - | ||||||||||||
321 | } | - | ||||||||||||
322 | default: | - | ||||||||||||
323 | break; | - | ||||||||||||
324 | } | - | ||||||||||||
325 | - | |||||||||||||
326 | view()->selectionModel()->select(selection, QItemSelectionModel::Deselect | QItemSelectionModel::Columns); | - | ||||||||||||
327 | return true; | - | ||||||||||||
328 | } | - | ||||||||||||
329 | - | |||||||||||||
330 | QAccessible::Role QAccessibleTable::role() const | - | ||||||||||||
331 | { | - | ||||||||||||
332 | return m_role; | - | ||||||||||||
333 | } | - | ||||||||||||
334 | - | |||||||||||||
335 | QAccessible::State QAccessibleTable::state() const | - | ||||||||||||
336 | { | - | ||||||||||||
337 | return QAccessible::State(); | - | ||||||||||||
338 | } | - | ||||||||||||
339 | - | |||||||||||||
340 | QAccessibleInterface *QAccessibleTable::childAt(int x, int y) const | - | ||||||||||||
341 | { | - | ||||||||||||
342 | QPoint viewportOffset = view()->viewport()->mapTo(view(), QPoint(0,0)); | - | ||||||||||||
343 | QPoint indexPosition = view()->mapFromGlobal(QPoint(x, y) - viewportOffset); | - | ||||||||||||
344 | - | |||||||||||||
345 | - | |||||||||||||
346 | QModelIndex index = view()->indexAt(indexPosition); | - | ||||||||||||
347 | if (index.isValid()) { | - | ||||||||||||
348 | return child(logicalIndex(index)); | - | ||||||||||||
349 | } | - | ||||||||||||
350 | return 0; | - | ||||||||||||
351 | } | - | ||||||||||||
352 | - | |||||||||||||
353 | int QAccessibleTable::childCount() const | - | ||||||||||||
354 | { | - | ||||||||||||
355 | if (!view()->model()) | - | ||||||||||||
356 | return 0; | - | ||||||||||||
357 | int vHeader = verticalHeader() ? 1 : 0; | - | ||||||||||||
358 | int hHeader = horizontalHeader() ? 1 : 0; | - | ||||||||||||
359 | return (view()->model()->rowCount()+hHeader) * (view()->model()->columnCount()+vHeader); | - | ||||||||||||
360 | } | - | ||||||||||||
361 | - | |||||||||||||
362 | int QAccessibleTable::indexOfChild(const QAccessibleInterface *iface) const | - | ||||||||||||
363 | { | - | ||||||||||||
364 | if (!view()->model()) | - | ||||||||||||
365 | return -1; | - | ||||||||||||
366 | QAccessibleInterface *parent = iface->parent(); | - | ||||||||||||
367 | if (parent->object() != view()) | - | ||||||||||||
368 | return -1; | - | ||||||||||||
369 | - | |||||||||||||
370 | ((!(iface->role() != QAccessible::TreeItem)) ? qt_assert("iface->role() != QAccessible::TreeItem",__FILE__,423429) : qt_noop()); | - | ||||||||||||
371 | if (iface->role() == QAccessible::Cell || iface->role() == QAccessible::ListItem) { | - | ||||||||||||
372 | const QAccessibleTableCell* cell = static_cast<const QAccessibleTableCell*>(iface); | - | ||||||||||||
373 | return logicalIndex(cell->m_index); | - | ||||||||||||
374 | } else if (iface->role() == QAccessible::ColumnHeader){ | - | ||||||||||||
375 | const QAccessibleTableHeaderCell* cell = static_cast<const QAccessibleTableHeaderCell*>(iface); | - | ||||||||||||
376 | return cell->index + (verticalHeader() ? 1 : 0); | - | ||||||||||||
377 | } else if (iface->role() == QAccessible::RowHeader){ | - | ||||||||||||
378 | const QAccessibleTableHeaderCell* cell = static_cast<const QAccessibleTableHeaderCell*>(iface); | - | ||||||||||||
379 | return (cell->index + 1) * (view()->model()->columnCount() + 1); | - | ||||||||||||
380 | } else if (iface->role() == QAccessible::Pane) { | - | ||||||||||||
381 | return 0; | - | ||||||||||||
382 | } else { | - | ||||||||||||
383 | QMessageLogger(__FILE__, 436442, __PRETTY_FUNCTION__).warning() << "WARNING QAccessibleTable::indexOfChild Fix my children..." | - | ||||||||||||
384 | << iface->role() << iface->text(QAccessible::Name); | - | ||||||||||||
385 | } | - | ||||||||||||
386 | - | |||||||||||||
387 | return -1; | - | ||||||||||||
388 | } | - | ||||||||||||
389 | - | |||||||||||||
390 | QString QAccessibleTable::text(QAccessible::Text t) const | - | ||||||||||||
391 | { | - | ||||||||||||
392 | if (t == QAccessible::Description) | - | ||||||||||||
393 | return view()->accessibleDescription(); | - | ||||||||||||
394 | return view()->accessibleName(); | - | ||||||||||||
395 | } | - | ||||||||||||
396 | - | |||||||||||||
397 | QRect QAccessibleTable::rect() const | - | ||||||||||||
398 | { | - | ||||||||||||
399 | if (!view()->isVisible()) | - | ||||||||||||
400 | return QRect(); | - | ||||||||||||
401 | QPoint pos = view()->mapToGlobal(QPoint(0, 0)); | - | ||||||||||||
402 | return QRect(pos.x(), pos.y(), view()->width(), view()->height()); | - | ||||||||||||
403 | } | - | ||||||||||||
404 | - | |||||||||||||
405 | QAccessibleInterface *QAccessibleTable::parent() const | - | ||||||||||||
406 | { | - | ||||||||||||
407 | if (view() && view()->parent()) { | - | ||||||||||||
408 | if (qstrcmp("QComboBoxPrivateContainer", view()->parent()->metaObject()->className()) == 0) { | - | ||||||||||||
409 | return QAccessible::queryAccessibleInterface(view()->parent()->parent()); | - | ||||||||||||
410 | } | - | ||||||||||||
411 | return QAccessible::queryAccessibleInterface(view()->parent()); | - | ||||||||||||
412 | } | - | ||||||||||||
413 | return 0; | - | ||||||||||||
414 | } | - | ||||||||||||
415 | - | |||||||||||||
416 | QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const | - | ||||||||||||
417 | { | - | ||||||||||||
418 | if (!view()->model()
| 0 | ||||||||||||
419 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
420 | - | |||||||||||||
421 | if (childToId.contains(logicalIndex)
| 0 | ||||||||||||
422 | QAccessible::Id id = childToId.value(logicalIndex); | - | ||||||||||||
423 | return never executed: QAccessible::accessibleInterface(id);return QAccessible::accessibleInterface(id); never executed: return QAccessible::accessibleInterface(id); | 0 | ||||||||||||
424 | } | - | ||||||||||||
425 | - | |||||||||||||
426 | int vHeader = verticalHeader()
| 0 | ||||||||||||
427 | int hHeader = horizontalHeader()
| 0 | ||||||||||||
428 | - | |||||||||||||
429 | int columns = view()->model()->columnCount() + vHeader; | - | ||||||||||||
430 | - | |||||||||||||
431 | int row = logicalIndex / columns; | - | ||||||||||||
432 | int column = logicalIndex % columns; | - | ||||||||||||
433 | - | |||||||||||||
434 | QAccessibleInterface *iface = 0; | - | ||||||||||||
435 | - | |||||||||||||
436 | if (vHeader
| 0 | ||||||||||||
437 | if (column == 0
| 0 | ||||||||||||
438 | if (hHeader
| 0 | ||||||||||||
439 | iface = new QAccessibleTableCornerButton(view()); | - | ||||||||||||
440 | } never executed: else {end of block | 0 | ||||||||||||
441 | iface = new QAccessibleTableHeaderCell(view(), row - hHeader, Qt::Vertical); | - | ||||||||||||
442 | } never executed: end of block | 0 | ||||||||||||
443 | } | - | ||||||||||||
444 | --column; | - | ||||||||||||
445 | } never executed: end of block | 0 | ||||||||||||
446 | if (!iface
| 0 | ||||||||||||
447 | if (row == 0
| 0 | ||||||||||||
448 | iface = new QAccessibleTableHeaderCell(view(), column, Qt::Horizontal); | - | ||||||||||||
449 | } never executed: end of block | 0 | ||||||||||||
450 | --row; | - | ||||||||||||
451 | } never executed: end of block | 0 | ||||||||||||
452 | - | |||||||||||||
453 | if (!iface
| 0 | ||||||||||||
454 | QModelIndex index = view()->model()->index(row, column, view()->rootIndex()); | - | ||||||||||||
455 | if (!(__builtin_expect(!!(!
| 0 | ||||||||||||
456 | QMessageLogger(__FILE__, 509515, __PRETTY_FUNCTION__).warning() << "QAccessibleTable::child: Invalid index at: " << row << column; | - | ||||||||||||
457 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
458 | } | - | ||||||||||||
459 | iface = new QAccessibleTableCell(view(), index, cellRole()); | - | ||||||||||||
460 | } never executed: end of block | 0 | ||||||||||||
461 | - | |||||||||||||
462 | QAccessible::registerAccessibleInterface(iface); | - | ||||||||||||
463 | childToId.insert(logicalIndex, QAccessible::uniqueId(iface)); | - | ||||||||||||
464 | return never executed: iface;return iface; never executed: return iface; | 0 | ||||||||||||
465 | } | - | ||||||||||||
466 | - | |||||||||||||
467 | void *QAccessibleTable::interface_cast(QAccessible::InterfaceType t) | - | ||||||||||||
468 | { | - | ||||||||||||
469 | if (t == QAccessible::TableInterface) | - | ||||||||||||
470 | return static_cast<QAccessibleTableInterface*>(this); | - | ||||||||||||
471 | return 0; | - | ||||||||||||
472 | } | - | ||||||||||||
473 | - | |||||||||||||
474 | void QAccessibleTable::modelChange(QAccessibleTableModelChangeEvent *event) | - | ||||||||||||
475 | { | - | ||||||||||||
476 | - | |||||||||||||
477 | if (childToId.isEmpty()) | - | ||||||||||||
478 | return; | - | ||||||||||||
479 | - | |||||||||||||
480 | switch (event->modelChangeType()) { | - | ||||||||||||
481 | case QAccessibleTableModelChangeEvent::ModelReset: | - | ||||||||||||
482 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(childToId)>::type> _container_((childToId)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QAccessible::Id id = *_container_.i; _container_.control; _container_.control = 0) | - | ||||||||||||
483 | QAccessible::deleteAccessibleInterface(id); | - | ||||||||||||
484 | childToId.clear(); | - | ||||||||||||
485 | break; | - | ||||||||||||
486 | - | |||||||||||||
487 | - | |||||||||||||
488 | case QAccessibleTableModelChangeEvent::RowsInserted: | - | ||||||||||||
489 | case QAccessibleTableModelChangeEvent::ColumnsInserted: { | - | ||||||||||||
490 | int newRows = event->lastRow() - event->firstRow() + 1; | - | ||||||||||||
491 | int newColumns = event->lastColumn() - event->firstColumn() + 1; | - | ||||||||||||
492 | - | |||||||||||||
493 | ChildCache newCache; | - | ||||||||||||
494 | ChildCache::ConstIterator iter = childToId.constBegin(); | - | ||||||||||||
495 | - | |||||||||||||
496 | while (iter != childToId.constEnd()) { | - | ||||||||||||
497 | QAccessible::Id id = iter.value(); | - | ||||||||||||
498 | QAccessibleInterface *iface = QAccessible::accessibleInterface(id); | - | ||||||||||||
499 | ((!(iface)) ? qt_assert("iface",__FILE__,552558) : qt_noop()); | - | ||||||||||||
500 | if (event->modelChangeType() == QAccessibleTableModelChangeEvent::RowsInserted | - | ||||||||||||
501 | && iface->role() == QAccessible::RowHeader) { | - | ||||||||||||
502 | QAccessibleTableHeaderCell *cell = static_cast<QAccessibleTableHeaderCell*>(iface); | - | ||||||||||||
503 | if (cell->index >= event->firstRow()) { | - | ||||||||||||
504 | cell->index += newRows; | - | ||||||||||||
505 | } | - | ||||||||||||
506 | } else if (event->modelChangeType() == QAccessibleTableModelChangeEvent::ColumnsInserted | - | ||||||||||||
507 | && iface->role() == QAccessible::ColumnHeader) { | - | ||||||||||||
508 | QAccessibleTableHeaderCell *cell = static_cast<QAccessibleTableHeaderCell*>(iface); | - | ||||||||||||
509 | if (cell->index >= event->firstColumn()) { | - | ||||||||||||
510 | cell->index += newColumns; | - | ||||||||||||
511 | } | - | ||||||||||||
512 | } | - | ||||||||||||
513 | if (indexOfChild(iface) >= 0) { | - | ||||||||||||
514 | newCache.insert(indexOfChild(iface), id); | - | ||||||||||||
515 | } else { | - | ||||||||||||
516 | - | |||||||||||||
517 | - | |||||||||||||
518 | - | |||||||||||||
519 | QAccessible::deleteAccessibleInterface(id); | - | ||||||||||||
520 | } | - | ||||||||||||
521 | ++iter; | - | ||||||||||||
522 | } | - | ||||||||||||
523 | childToId = newCache; | - | ||||||||||||
524 | break; | - | ||||||||||||
525 | } | - | ||||||||||||
526 | - | |||||||||||||
527 | case QAccessibleTableModelChangeEvent::ColumnsRemoved: | - | ||||||||||||
528 | case QAccessibleTableModelChangeEvent::RowsRemoved: { | - | ||||||||||||
529 | int deletedColumns = event->lastColumn() - event->firstColumn() + 1; | - | ||||||||||||
530 | int deletedRows = event->lastRow() - event->firstRow() + 1; | - | ||||||||||||
531 | ChildCache newCache; | - | ||||||||||||
532 | ChildCache::ConstIterator iter = childToId.constBegin(); | - | ||||||||||||
533 | while (iter != childToId.constEnd()) { | - | ||||||||||||
534 | QAccessible::Id id = iter.value(); | - | ||||||||||||
535 | QAccessibleInterface *iface = QAccessible::accessibleInterface(id); | - | ||||||||||||
536 | ((!(iface)) ? qt_assert("iface",__FILE__,589595) : qt_noop()); | - | ||||||||||||
537 | if (iface->role() == QAccessible::Cell || iface->role() == QAccessible::ListItem) { | - | ||||||||||||
538 | ((!(iface->tableCellInterface())) ? qt_assert("iface->tableCellInterface()",__FILE__,591597) : qt_noop()); | - | ||||||||||||
539 | QAccessibleTableCell *cell = static_cast<QAccessibleTableCell*>(iface->tableCellInterface()); | - | ||||||||||||
540 | - | |||||||||||||
541 | if (cell->m_index.isValid()) | - | ||||||||||||
542 | newCache.insert(indexOfChild(cell), id); | - | ||||||||||||
543 | else | - | ||||||||||||
544 | QAccessible::deleteAccessibleInterface(id); | - | ||||||||||||
545 | } else if (event->modelChangeType() == QAccessibleTableModelChangeEvent::RowsRemoved | - | ||||||||||||
546 | && iface->role() == QAccessible::RowHeader) { | - | ||||||||||||
547 | QAccessibleTableHeaderCell *cell = static_cast<QAccessibleTableHeaderCell*>(iface); | - | ||||||||||||
548 | if (cell->index < event->firstRow()) { | - | ||||||||||||
549 | newCache.insert(indexOfChild(cell), id); | - | ||||||||||||
550 | } else if (cell->index > event->lastRow()) { | - | ||||||||||||
551 | cell->index -= deletedRows; | - | ||||||||||||
552 | newCache.insert(indexOfChild(cell), id); | - | ||||||||||||
553 | } else { | - | ||||||||||||
554 | QAccessible::deleteAccessibleInterface(id); | - | ||||||||||||
555 | } | - | ||||||||||||
556 | } else if (event->modelChangeType() == QAccessibleTableModelChangeEvent::ColumnsRemoved | - | ||||||||||||
557 | && iface->role() == QAccessible::ColumnHeader) { | - | ||||||||||||
558 | QAccessibleTableHeaderCell *cell = static_cast<QAccessibleTableHeaderCell*>(iface); | - | ||||||||||||
559 | if (cell->index < event->firstColumn()) { | - | ||||||||||||
560 | newCache.insert(indexOfChild(cell), id); | - | ||||||||||||
561 | } else if (cell->index > event->lastColumn()) { | - | ||||||||||||
562 | cell->index -= deletedColumns; | - | ||||||||||||
563 | newCache.insert(indexOfChild(cell), id); | - | ||||||||||||
564 | } else { | - | ||||||||||||
565 | QAccessible::deleteAccessibleInterface(id); | - | ||||||||||||
566 | } | - | ||||||||||||
567 | } | - | ||||||||||||
568 | ++iter; | - | ||||||||||||
569 | } | - | ||||||||||||
570 | childToId = newCache; | - | ||||||||||||
571 | break; | - | ||||||||||||
572 | } | - | ||||||||||||
573 | - | |||||||||||||
574 | case QAccessibleTableModelChangeEvent::DataChanged: | - | ||||||||||||
575 | - | |||||||||||||
576 | break; | - | ||||||||||||
577 | } | - | ||||||||||||
578 | } | - | ||||||||||||
579 | - | |||||||||||||
580 | - | |||||||||||||
581 | - | |||||||||||||
582 | QModelIndex QAccessibleTree::indexFromLogical(int row, int column) const | - | ||||||||||||
583 | { | - | ||||||||||||
584 | if (!isValid()
| 0 | ||||||||||||
585 | return never executed: QModelIndex();return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||
586 | - | |||||||||||||
587 | const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); | - | ||||||||||||
588 | if (((__builtin_expect(!!(
| 0 | ||||||||||||
589 | QMessageLogger(__FILE__, 642648, __PRETTY_FUNCTION__).warning() << "QAccessibleTree::indexFromLogical: invalid index: " << row << column << " for " << treeView; | - | ||||||||||||
590 | return never executed: QModelIndex();return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||
591 | } | - | ||||||||||||
592 | QModelIndex modelIndex = treeView->d_func()->viewItems.at(row).index; | - | ||||||||||||
593 | - | |||||||||||||
594 | if (modelIndex.isValid()
| 0 | ||||||||||||
595 | modelIndex = view()->model()->index(modelIndex.row(), column, modelIndex.parent()); | - | ||||||||||||
596 | } never executed: end of block | 0 | ||||||||||||
597 | return never executed: modelIndex;return modelIndex; never executed: return modelIndex; | 0 | ||||||||||||
598 | } | - | ||||||||||||
599 | - | |||||||||||||
600 | QAccessibleInterface *QAccessibleTree::childAt(int x, int y) const | - | ||||||||||||
601 | { | - | ||||||||||||
602 | if (!view()->model()) | - | ||||||||||||
603 | return 0; | - | ||||||||||||
604 | QPoint viewportOffset = view()->viewport()->mapTo(view(), QPoint(0,0)); | - | ||||||||||||
605 | QPoint indexPosition = view()->mapFromGlobal(QPoint(x, y) - viewportOffset); | - | ||||||||||||
606 | - | |||||||||||||
607 | QModelIndex index = view()->indexAt(indexPosition); | - | ||||||||||||
608 | if (!index.isValid()) | - | ||||||||||||
609 | return 0; | - | ||||||||||||
610 | - | |||||||||||||
611 | const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); | - | ||||||||||||
612 | int row = treeView->d_func()->viewIndex(index) + (horizontalHeader() ? 1 : 0); | - | ||||||||||||
613 | int column = index.column(); | - | ||||||||||||
614 | - | |||||||||||||
615 | int i = row * view()->model()->columnCount() + column; | - | ||||||||||||
616 | return child(i); | - | ||||||||||||
617 | } | - | ||||||||||||
618 | - | |||||||||||||
619 | int QAccessibleTree::childCount() const | - | ||||||||||||
620 | { | - | ||||||||||||
621 | const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); | - | ||||||||||||
622 | ((!(treeView)) ? qt_assert("treeView",__FILE__,675681) : qt_noop()); | - | ||||||||||||
623 | if (!view()->model()) | - | ||||||||||||
624 | return 0; | - | ||||||||||||
625 | - | |||||||||||||
626 | int hHeader = horizontalHeader() ? 1 : 0; | - | ||||||||||||
627 | return (treeView->d_func()->viewItems.count() + hHeader)* view()->model()->columnCount(); | - | ||||||||||||
628 | } | - | ||||||||||||
629 | - | |||||||||||||
630 | - | |||||||||||||
631 | QAccessibleInterface *QAccessibleTree::child(int logicalIndex) const | - | ||||||||||||
632 | { | - | ||||||||||||
633 | if (logicalIndex < 0 || !view()->model() || !view()->model()->columnCount()) | - | ||||||||||||
634 | return 0; | - | ||||||||||||
635 | - | |||||||||||||
636 | QAccessibleInterface *iface = 0; | - | ||||||||||||
637 | int index = logicalIndex; | - | ||||||||||||
638 | - | |||||||||||||
639 | if (horizontalHeader()) { | - | ||||||||||||
640 | if (index < view()->model()->columnCount()) { | - | ||||||||||||
641 | iface = new QAccessibleTableHeaderCell(view(), index, Qt::Horizontal); | - | ||||||||||||
642 | } else { | - | ||||||||||||
643 | index -= view()->model()->columnCount(); | - | ||||||||||||
644 | } | - | ||||||||||||
645 | } | - | ||||||||||||
646 | - | |||||||||||||
647 | if (!iface) { | - | ||||||||||||
648 | int row = index / view()->model()->columnCount(); | - | ||||||||||||
649 | int column = index % view()->model()->columnCount(); | - | ||||||||||||
650 | QModelIndex modelIndex = indexFromLogical(row, column); | - | ||||||||||||
651 | if (!modelIndex.isValid()) | - | ||||||||||||
652 | return 0; | - | ||||||||||||
653 | iface = new QAccessibleTableCell(view(), modelIndex, cellRole()); | - | ||||||||||||
654 | } | - | ||||||||||||
655 | QAccessible::registerAccessibleInterface(iface); | - | ||||||||||||
656 | - | |||||||||||||
657 | return iface; | - | ||||||||||||
658 | } | - | ||||||||||||
659 | - | |||||||||||||
660 | int QAccessibleTree::rowCount() const | - | ||||||||||||
661 | { | - | ||||||||||||
662 | const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); | - | ||||||||||||
663 | ((!(treeView)) ? qt_assert("treeView",__FILE__,716722) : qt_noop()); | - | ||||||||||||
664 | return treeView->d_func()->viewItems.count(); | - | ||||||||||||
665 | } | - | ||||||||||||
666 | - | |||||||||||||
667 | int QAccessibleTree::indexOfChild(const QAccessibleInterface *iface) const | - | ||||||||||||
668 | { | - | ||||||||||||
669 | if (!view()->model()) | - | ||||||||||||
670 | return -1; | - | ||||||||||||
671 | QAccessibleInterface *parent = iface->parent(); | - | ||||||||||||
672 | if (parent->object() != view()) | - | ||||||||||||
673 | return -1; | - | ||||||||||||
674 | - | |||||||||||||
675 | if (iface->role() == QAccessible::TreeItem) { | - | ||||||||||||
676 | const QAccessibleTableCell* cell = static_cast<const QAccessibleTableCell*>(iface); | - | ||||||||||||
677 | const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); | - | ||||||||||||
678 | ((!(treeView)) ? qt_assert("treeView",__FILE__,731737) : qt_noop()); | - | ||||||||||||
679 | int row = treeView->d_func()->viewIndex(cell->m_index) + (horizontalHeader() ? 1 : 0); | - | ||||||||||||
680 | int column = cell->m_index.column(); | - | ||||||||||||
681 | - | |||||||||||||
682 | int index = row * view()->model()->columnCount() + column; | - | ||||||||||||
683 | return index; | - | ||||||||||||
684 | } else if (iface->role() == QAccessible::ColumnHeader){ | - | ||||||||||||
685 | const QAccessibleTableHeaderCell* cell = static_cast<const QAccessibleTableHeaderCell*>(iface); | - | ||||||||||||
686 | return cell->index; | - | ||||||||||||
687 | } else { | - | ||||||||||||
688 | QMessageLogger(__FILE__, 741747, __PRETTY_FUNCTION__).warning() << "WARNING QAccessibleTable::indexOfChild invalid child" | - | ||||||||||||
689 | << iface->role() << iface->text(QAccessible::Name); | - | ||||||||||||
690 | } | - | ||||||||||||
691 | - | |||||||||||||
692 | return -1; | - | ||||||||||||
693 | } | - | ||||||||||||
694 | - | |||||||||||||
695 | QAccessibleInterface *QAccessibleTree::cellAt(int row, int column) const | - | ||||||||||||
696 | { | - | ||||||||||||
697 | QModelIndex index = indexFromLogical(row, column); | - | ||||||||||||
698 | if (!(__builtin_expect(!!(!
| 0 | ||||||||||||
699 | QMessageLogger(__FILE__, 752758, __PRETTY_FUNCTION__).warning() << "Requested invalid tree cell: " << row << column; | - | ||||||||||||
700 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
701 | } | - | ||||||||||||
702 | const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); | - | ||||||||||||
703 | ((!(treeView)) ? qt_assert("treeView",__FILE__,756762) : qt_noop()); | - | ||||||||||||
704 | int logicalIndex = treeView->d_func()->accessibleTable2Index(index); | - | ||||||||||||
705 | - | |||||||||||||
706 | return never executed: child(logicalIndex);return child(logicalIndex); never executed: return child(logicalIndex); | 0 | ||||||||||||
707 | } | - | ||||||||||||
708 | - | |||||||||||||
709 | QString QAccessibleTree::rowDescription(int) const | - | ||||||||||||
710 | { | - | ||||||||||||
711 | return QString(); | - | ||||||||||||
712 | } | - | ||||||||||||
713 | - | |||||||||||||
714 | bool QAccessibleTree::isRowSelected(int row) const | - | ||||||||||||
715 | { | - | ||||||||||||
716 | if (!view()->selectionModel()) | - | ||||||||||||
717 | return false; | - | ||||||||||||
718 | QModelIndex index = indexFromLogical(row); | - | ||||||||||||
719 | return view()->selectionModel()->isRowSelected(index.row(), index.parent()); | - | ||||||||||||
720 | } | - | ||||||||||||
721 | - | |||||||||||||
722 | bool QAccessibleTree::selectRow(int row) | - | ||||||||||||
723 | { | - | ||||||||||||
724 | if (!view()->selectionModel()) | - | ||||||||||||
725 | return false; | - | ||||||||||||
726 | QModelIndex index = indexFromLogical(row); | - | ||||||||||||
727 | - | |||||||||||||
728 | if (!index.isValid() || view()->selectionBehavior() == QAbstractItemView::SelectColumns) | - | ||||||||||||
729 | return false; | - | ||||||||||||
730 | - | |||||||||||||
731 | switch (view()->selectionMode()) { | - | ||||||||||||
732 | case QAbstractItemView::NoSelection: | - | ||||||||||||
733 | return false; | - | ||||||||||||
734 | case QAbstractItemView::SingleSelection: | - | ||||||||||||
735 | if ((view()->selectionBehavior() != QAbstractItemView::SelectRows) && (columnCount() > 1)) | - | ||||||||||||
736 | return false; | - | ||||||||||||
737 | view()->clearSelection(); | - | ||||||||||||
738 | break; | - | ||||||||||||
739 | case QAbstractItemView::ContiguousSelection: | - | ||||||||||||
740 | if ((!row || !view()->selectionModel()->isRowSelected(row - 1, view()->rootIndex())) | - | ||||||||||||
741 | && !view()->selectionModel()->isRowSelected(row + 1, view()->rootIndex())) | - | ||||||||||||
742 | view()->clearSelection(); | - | ||||||||||||
743 | break; | - | ||||||||||||
744 | default: | - | ||||||||||||
745 | break; | - | ||||||||||||
746 | } | - | ||||||||||||
747 | - | |||||||||||||
748 | view()->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); | - | ||||||||||||
749 | return true; | - | ||||||||||||
750 | } | - | ||||||||||||
751 | - | |||||||||||||
752 | - | |||||||||||||
753 | - | |||||||||||||
754 | QAccessibleTableCell::QAccessibleTableCell(QAbstractItemView *view_, const QModelIndex &index_, QAccessible::Role role_) | - | ||||||||||||
755 | : view(view_), m_index(index_), m_role(role_) | - | ||||||||||||
756 | { | - | ||||||||||||
757 | if (!(__builtin_expect(!!(!
| 0 | ||||||||||||
758 | QMessageLogger(__FILE__, 811817, __PRETTY_FUNCTION__).warning() << "QAccessibleTableCell::QAccessibleTableCell with invalid index: " << index_; never executed: QMessageLogger(__FILE__, 817, __PRETTY_FUNCTION__).warning() << "QAccessibleTableCell::QAccessibleTableCell with invalid index: " << index_; | 0 | ||||||||||||
759 | } never executed: end of block | 0 | ||||||||||||
760 | - | |||||||||||||
761 | void *QAccessibleTableCell::interface_cast(QAccessible::InterfaceType t) | - | ||||||||||||
762 | { | - | ||||||||||||
763 | if (t == QAccessible::TableCellInterface) | - | ||||||||||||
764 | return static_cast<QAccessibleTableCellInterface*>(this); | - | ||||||||||||
765 | if (t == QAccessible::ActionInterface) | - | ||||||||||||
766 | return static_cast<QAccessibleActionInterface*>(this); | - | ||||||||||||
767 | return 0; | - | ||||||||||||
768 | } | - | ||||||||||||
769 | - | |||||||||||||
770 | int QAccessibleTableCell::columnExtent() const { return 1; } | - | ||||||||||||
771 | int QAccessibleTableCell::rowExtent() const { return 1; } | - | ||||||||||||
772 | - | |||||||||||||
773 | QList<QAccessibleInterface*> QAccessibleTableCell::rowHeaderCells() const | - | ||||||||||||
774 | { | - | ||||||||||||
775 | QList<QAccessibleInterface*> headerCell; | - | ||||||||||||
776 | if (verticalHeader()) { | - | ||||||||||||
777 | - | |||||||||||||
778 | headerCell.append(new QAccessibleTableHeaderCell(view, m_index.row(), Qt::Vertical)); | - | ||||||||||||
779 | } | - | ||||||||||||
780 | return headerCell; | - | ||||||||||||
781 | } | - | ||||||||||||
782 | - | |||||||||||||
783 | QList<QAccessibleInterface*> QAccessibleTableCell::columnHeaderCells() const | - | ||||||||||||
784 | { | - | ||||||||||||
785 | QList<QAccessibleInterface*> headerCell; | - | ||||||||||||
786 | if (horizontalHeader()) { | - | ||||||||||||
787 | - | |||||||||||||
788 | headerCell.append(new QAccessibleTableHeaderCell(view, m_index.column(), Qt::Horizontal)); | - | ||||||||||||
789 | } | - | ||||||||||||
790 | return headerCell; | - | ||||||||||||
791 | } | - | ||||||||||||
792 | - | |||||||||||||
793 | QHeaderView *QAccessibleTableCell::horizontalHeader() const | - | ||||||||||||
794 | { | - | ||||||||||||
795 | QHeaderView *header = 0; | - | ||||||||||||
796 | - | |||||||||||||
797 | if (false) { dead code: { } | - | ||||||||||||
798 | - | |||||||||||||
799 | } dead code: else if (const QTableView *tv = qobject_cast<const QTableView*>(view)) {{ } | - | ||||||||||||
800 | header = tv->horizontalHeader(); | - | ||||||||||||
801 | - | |||||||||||||
802 | - | |||||||||||||
803 | } else if (const QTreeView *tv = qobject_cast<const QTreeView*>(view)) { | - | ||||||||||||
804 | header = tv->header(); | - | ||||||||||||
805 | - | |||||||||||||
806 | } | - | ||||||||||||
807 | - | |||||||||||||
808 | return header; | - | ||||||||||||
809 | } | - | ||||||||||||
810 | - | |||||||||||||
811 | QHeaderView *QAccessibleTableCell::verticalHeader() const | - | ||||||||||||
812 | { | - | ||||||||||||
813 | QHeaderView *header = 0; | - | ||||||||||||
814 | - | |||||||||||||
815 | if (const QTableView *tv = qobject_cast<const QTableView*>(view)) | - | ||||||||||||
816 | header = tv->verticalHeader(); | - | ||||||||||||
817 | - | |||||||||||||
818 | return header; | - | ||||||||||||
819 | } | - | ||||||||||||
820 | - | |||||||||||||
821 | int QAccessibleTableCell::columnIndex() const | - | ||||||||||||
822 | { | - | ||||||||||||
823 | return m_index.column(); | - | ||||||||||||
824 | } | - | ||||||||||||
825 | - | |||||||||||||
826 | int QAccessibleTableCell::rowIndex() const | - | ||||||||||||
827 | { | - | ||||||||||||
828 | if (role() == QAccessible::TreeItem) { | - | ||||||||||||
829 | const QTreeView *treeView = qobject_cast<const QTreeView*>(view); | - | ||||||||||||
830 | ((!(treeView)) ? qt_assert("treeView",__FILE__,883889) : qt_noop()); | - | ||||||||||||
831 | int row = treeView->d_func()->viewIndex(m_index); | - | ||||||||||||
832 | return row; | - | ||||||||||||
833 | } | - | ||||||||||||
834 | return m_index.row(); | - | ||||||||||||
835 | } | - | ||||||||||||
836 | - | |||||||||||||
837 | bool QAccessibleTableCell::isSelected() const | - | ||||||||||||
838 | { | - | ||||||||||||
839 | return view->selectionModel()->isSelected(m_index); | - | ||||||||||||
840 | } | - | ||||||||||||
841 | - | |||||||||||||
842 | QStringList QAccessibleTableCell::actionNames() const | - | ||||||||||||
843 | { | - | ||||||||||||
844 | QStringList names; | - | ||||||||||||
845 | names << toggleAction(); | - | ||||||||||||
846 | return names; | - | ||||||||||||
847 | } | - | ||||||||||||
848 | - | |||||||||||||
849 | void QAccessibleTableCell::doAction(const QString& actionName) | - | ||||||||||||
850 | { | - | ||||||||||||
851 | if (actionName == toggleAction()) { | - | ||||||||||||
852 | if (isSelected()) | - | ||||||||||||
853 | unselectCell(); | - | ||||||||||||
854 | else | - | ||||||||||||
855 | selectCell(); | - | ||||||||||||
856 | } | - | ||||||||||||
857 | } | - | ||||||||||||
858 | - | |||||||||||||
859 | QStringList QAccessibleTableCell::keyBindingsForAction(const QString &) const | - | ||||||||||||
860 | { | - | ||||||||||||
861 | return QStringList(); | - | ||||||||||||
862 | } | - | ||||||||||||
863 | - | |||||||||||||
864 | - | |||||||||||||
865 | void QAccessibleTableCell::selectCell() | - | ||||||||||||
866 | { | - | ||||||||||||
867 | QAbstractItemView::SelectionMode selectionMode = view->selectionMode(); | - | ||||||||||||
868 | if (!m_index.isValid() || (selectionMode == QAbstractItemView::NoSelection)) | - | ||||||||||||
869 | return; | - | ||||||||||||
870 | ((!(table())) ? qt_assert("table()",__FILE__,923929) : qt_noop()); | - | ||||||||||||
871 | QAccessibleTableInterface *cellTable = table()->tableInterface(); | - | ||||||||||||
872 | - | |||||||||||||
873 | switch (view->selectionBehavior()) { | - | ||||||||||||
874 | case QAbstractItemView::SelectItems: | - | ||||||||||||
875 | break; | - | ||||||||||||
876 | case QAbstractItemView::SelectColumns: | - | ||||||||||||
877 | if (cellTable) | - | ||||||||||||
878 | cellTable->selectColumn(m_index.column()); | - | ||||||||||||
879 | return; | - | ||||||||||||
880 | case QAbstractItemView::SelectRows: | - | ||||||||||||
881 | if (cellTable) | - | ||||||||||||
882 | cellTable->selectRow(m_index.row()); | - | ||||||||||||
883 | return; | - | ||||||||||||
884 | } | - | ||||||||||||
885 | - | |||||||||||||
886 | if (selectionMode == QAbstractItemView::SingleSelection) { | - | ||||||||||||
887 | view->clearSelection(); | - | ||||||||||||
888 | } | - | ||||||||||||
889 | - | |||||||||||||
890 | view->selectionModel()->select(m_index, QItemSelectionModel::Select); | - | ||||||||||||
891 | } | - | ||||||||||||
892 | - | |||||||||||||
893 | void QAccessibleTableCell::unselectCell() | - | ||||||||||||
894 | { | - | ||||||||||||
895 | - | |||||||||||||
896 | QAbstractItemView::SelectionMode selectionMode = view->selectionMode(); | - | ||||||||||||
897 | if (!m_index.isValid() || (selectionMode & QAbstractItemView::NoSelection)) | - | ||||||||||||
898 | return; | - | ||||||||||||
899 | - | |||||||||||||
900 | QAccessibleTableInterface *cellTable = table()->tableInterface(); | - | ||||||||||||
901 | - | |||||||||||||
902 | switch (view->selectionBehavior()) { | - | ||||||||||||
903 | case QAbstractItemView::SelectItems: | - | ||||||||||||
904 | break; | - | ||||||||||||
905 | case QAbstractItemView::SelectColumns: | - | ||||||||||||
906 | if (cellTable) | - | ||||||||||||
907 | cellTable->unselectColumn(m_index.column()); | - | ||||||||||||
908 | return; | - | ||||||||||||
909 | case QAbstractItemView::SelectRows: | - | ||||||||||||
910 | if (cellTable) | - | ||||||||||||
911 | cellTable->unselectRow(m_index.row()); | - | ||||||||||||
912 | return; | - | ||||||||||||
913 | } | - | ||||||||||||
914 | - | |||||||||||||
915 | - | |||||||||||||
916 | - | |||||||||||||
917 | if ((selectionMode != QAbstractItemView::MultiSelection) | - | ||||||||||||
918 | && (selectionMode != QAbstractItemView::ExtendedSelection) | - | ||||||||||||
919 | && (view->selectionModel()->selectedIndexes().count() <= 1)) | - | ||||||||||||
920 | return; | - | ||||||||||||
921 | - | |||||||||||||
922 | view->selectionModel()->select(m_index, QItemSelectionModel::Deselect); | - | ||||||||||||
923 | } | - | ||||||||||||
924 | - | |||||||||||||
925 | QAccessibleInterface *QAccessibleTableCell::table() const | - | ||||||||||||
926 | { | - | ||||||||||||
927 | return QAccessible::queryAccessibleInterface(view); | - | ||||||||||||
928 | } | - | ||||||||||||
929 | - | |||||||||||||
930 | QAccessible::Role QAccessibleTableCell::role() const | - | ||||||||||||
931 | { | - | ||||||||||||
932 | return m_role; | - | ||||||||||||
933 | } | - | ||||||||||||
934 | - | |||||||||||||
935 | QAccessible::State QAccessibleTableCell::state() const | - | ||||||||||||
936 | { | - | ||||||||||||
937 | QAccessible::State st; | - | ||||||||||||
938 | if (!view) | - | ||||||||||||
939 | return st; | - | ||||||||||||
940 | - | |||||||||||||
941 | QRect globalRect = view->rect(); | - | ||||||||||||
942 | globalRect.translate(view->mapToGlobal(QPoint(0,0))); | - | ||||||||||||
943 | if (!globalRect.intersects(rect())) | - | ||||||||||||
944 | st.invisible = true; | - | ||||||||||||
945 | - | |||||||||||||
946 | if (view->selectionModel()->isSelected(m_index)) | - | ||||||||||||
947 | st.selected = true; | - | ||||||||||||
948 | if (view->selectionModel()->currentIndex() == m_index) | - | ||||||||||||
949 | st.focused = true; | - | ||||||||||||
950 | if (m_index.model()->data(m_index, Qt::CheckStateRole).toInt() == Qt::Checked) | - | ||||||||||||
951 | st.checked = true; | - | ||||||||||||
952 | - | |||||||||||||
953 | Qt::ItemFlags flags = m_index.flags(); | - | ||||||||||||
954 | if (flags & Qt::ItemIsSelectable) { | - | ||||||||||||
955 | st.selectable = true; | - | ||||||||||||
956 | st.focusable = true; | - | ||||||||||||
957 | if (view->selectionMode() == QAbstractItemView::MultiSelection) | - | ||||||||||||
958 | st.multiSelectable = true; | - | ||||||||||||
959 | if (view->selectionMode() == QAbstractItemView::ExtendedSelection) | - | ||||||||||||
960 | st.extSelectable = true; | - | ||||||||||||
961 | } | - | ||||||||||||
962 | if (m_role == QAccessible::TreeItem) { | - | ||||||||||||
963 | const QTreeView *treeView = qobject_cast<const QTreeView*>(view); | - | ||||||||||||
964 | if (treeView->model()->hasChildren(m_index)) | - | ||||||||||||
965 | st.expandable = true; | - | ||||||||||||
966 | if (treeView->isExpanded(m_index)) | - | ||||||||||||
967 | st.expanded = true; | - | ||||||||||||
968 | } | - | ||||||||||||
969 | return st; | - | ||||||||||||
970 | } | - | ||||||||||||
971 | - | |||||||||||||
972 | - | |||||||||||||
973 | QRect QAccessibleTableCell::rect() const | - | ||||||||||||
974 | { | - | ||||||||||||
975 | QRect r; | - | ||||||||||||
976 | r = view->visualRect(m_index); | - | ||||||||||||
977 | - | |||||||||||||
978 | if (!r.isNull()) { | - | ||||||||||||
979 | r.translate(view->viewport()->mapTo(view, QPoint(0,0))); | - | ||||||||||||
980 | r.translate(view->mapToGlobal(QPoint(0, 0))); | - | ||||||||||||
981 | } | - | ||||||||||||
982 | return r; | - | ||||||||||||
983 | } | - | ||||||||||||
984 | - | |||||||||||||
985 | QString QAccessibleTableCell::text(QAccessible::Text t) const | - | ||||||||||||
986 | { | - | ||||||||||||
987 | QAbstractItemModel *model = view->model(); | - | ||||||||||||
988 | QString value; | - | ||||||||||||
989 | switch (t) { | - | ||||||||||||
990 | case QAccessible::Name: | - | ||||||||||||
991 | value = model->data(m_index, Qt::AccessibleTextRole).toString(); | - | ||||||||||||
992 | if (value.isEmpty()) | - | ||||||||||||
993 | value = model->data(m_index, Qt::DisplayRole).toString(); | - | ||||||||||||
994 | break; | - | ||||||||||||
995 | case QAccessible::Description: | - | ||||||||||||
996 | value = model->data(m_index, Qt::AccessibleDescriptionRole).toString(); | - | ||||||||||||
997 | break; | - | ||||||||||||
998 | default: | - | ||||||||||||
999 | break; | - | ||||||||||||
1000 | } | - | ||||||||||||
1001 | return value; | - | ||||||||||||
1002 | } | - | ||||||||||||
1003 | - | |||||||||||||
1004 | void QAccessibleTableCell::setText(QAccessible::Text , const QString &text) | - | ||||||||||||
1005 | { | - | ||||||||||||
1006 | if (!(m_index.flags() & Qt::ItemIsEditable)) | - | ||||||||||||
1007 | return; | - | ||||||||||||
1008 | view->model()->setData(m_index, text); | - | ||||||||||||
1009 | } | - | ||||||||||||
1010 | - | |||||||||||||
1011 | bool QAccessibleTableCell::isValid() const | - | ||||||||||||
1012 | { | - | ||||||||||||
1013 | return view && view->model() && m_index.isValid(); | - | ||||||||||||
1014 | } | - | ||||||||||||
1015 | - | |||||||||||||
1016 | QAccessibleInterface *QAccessibleTableCell::parent() const | - | ||||||||||||
1017 | { | - | ||||||||||||
1018 | return QAccessible::queryAccessibleInterface(view); | - | ||||||||||||
1019 | } | - | ||||||||||||
1020 | - | |||||||||||||
1021 | QAccessibleInterface *QAccessibleTableCell::child(int) const | - | ||||||||||||
1022 | { | - | ||||||||||||
1023 | return 0; | - | ||||||||||||
1024 | } | - | ||||||||||||
1025 | - | |||||||||||||
1026 | QAccessibleTableHeaderCell::QAccessibleTableHeaderCell(QAbstractItemView *view_, int index_, Qt::Orientation orientation_) | - | ||||||||||||
1027 | : view(view_), index(index_), orientation(orientation_) | - | ||||||||||||
1028 | { | - | ||||||||||||
1029 | ((!(index_ >= 0)) ? qt_assert("index_ >= 0",__FILE__,10821088) : qt_noop()); | - | ||||||||||||
1030 | } | - | ||||||||||||
1031 | - | |||||||||||||
1032 | QAccessible::Role QAccessibleTableHeaderCell::role() const | - | ||||||||||||
1033 | { | - | ||||||||||||
1034 | if (orientation == Qt::Horizontal) | - | ||||||||||||
1035 | return QAccessible::ColumnHeader; | - | ||||||||||||
1036 | return QAccessible::RowHeader; | - | ||||||||||||
1037 | } | - | ||||||||||||
1038 | - | |||||||||||||
1039 | QAccessible::State QAccessibleTableHeaderCell::state() const | - | ||||||||||||
1040 | { | - | ||||||||||||
1041 | QAccessible::State s; | - | ||||||||||||
1042 | if (QHeaderView *h = headerView()) { | - | ||||||||||||
1043 | s.invisible = !h->testAttribute(Qt::WA_WState_Visible); | - | ||||||||||||
1044 | s.disabled = !h->isEnabled(); | - | ||||||||||||
1045 | } | - | ||||||||||||
1046 | return s; | - | ||||||||||||
1047 | } | - | ||||||||||||
1048 | - | |||||||||||||
1049 | QRect QAccessibleTableHeaderCell::rect() const | - | ||||||||||||
1050 | { | - | ||||||||||||
1051 | QHeaderView *header = 0; | - | ||||||||||||
1052 | if (false) { dead code: { } | - | ||||||||||||
1053 | - | |||||||||||||
1054 | } dead code: else if (const QTableView *tv = qobject_cast<const QTableView*>(view)) {{ } | - | ||||||||||||
1055 | if (orientation == Qt::Horizontal) { | - | ||||||||||||
1056 | header = tv->horizontalHeader(); | - | ||||||||||||
1057 | } else { | - | ||||||||||||
1058 | header = tv->verticalHeader(); | - | ||||||||||||
1059 | } | - | ||||||||||||
1060 | - | |||||||||||||
1061 | - | |||||||||||||
1062 | } else if (const QTreeView *tv = qobject_cast<const QTreeView*>(view)) { | - | ||||||||||||
1063 | header = tv->header(); | - | ||||||||||||
1064 | - | |||||||||||||
1065 | } | - | ||||||||||||
1066 | if (!header) | - | ||||||||||||
1067 | return QRect(); | - | ||||||||||||
1068 | QPoint zero = header->mapToGlobal(QPoint(0, 0)); | - | ||||||||||||
1069 | int sectionSize = header->sectionSize(index); | - | ||||||||||||
1070 | int sectionPos = header->sectionPosition(index); | - | ||||||||||||
1071 | return orientation == Qt::Horizontal | - | ||||||||||||
1072 | ? QRect(zero.x() + sectionPos, zero.y(), sectionSize, header->height()) | - | ||||||||||||
1073 | : QRect(zero.x(), zero.y() + sectionPos, header->width(), sectionSize); | - | ||||||||||||
1074 | } | - | ||||||||||||
1075 | - | |||||||||||||
1076 | QString QAccessibleTableHeaderCell::text(QAccessible::Text t) const | - | ||||||||||||
1077 | { | - | ||||||||||||
1078 | QAbstractItemModel *model = view->model(); | - | ||||||||||||
1079 | QString value; | - | ||||||||||||
1080 | switch (t) { | - | ||||||||||||
1081 | case QAccessible::Name: | - | ||||||||||||
1082 | value = model->headerData(index, orientation, Qt::AccessibleTextRole).toString(); | - | ||||||||||||
1083 | if (value.isEmpty()) | - | ||||||||||||
1084 | value = model->headerData(index, orientation, Qt::DisplayRole).toString(); | - | ||||||||||||
1085 | break; | - | ||||||||||||
1086 | case QAccessible::Description: | - | ||||||||||||
1087 | value = model->headerData(index, orientation, Qt::AccessibleDescriptionRole).toString(); | - | ||||||||||||
1088 | break; | - | ||||||||||||
1089 | default: | - | ||||||||||||
1090 | break; | - | ||||||||||||
1091 | } | - | ||||||||||||
1092 | return value; | - | ||||||||||||
1093 | } | - | ||||||||||||
1094 | - | |||||||||||||
1095 | void QAccessibleTableHeaderCell::setText(QAccessible::Text, const QString &) | - | ||||||||||||
1096 | { | - | ||||||||||||
1097 | return; | - | ||||||||||||
1098 | } | - | ||||||||||||
1099 | - | |||||||||||||
1100 | bool QAccessibleTableHeaderCell::isValid() const | - | ||||||||||||
1101 | { | - | ||||||||||||
1102 | return view && view->model() && (index >= 0) | - | ||||||||||||
1103 | && ((orientation == Qt::Horizontal) ? (index < view->model()->columnCount()) : (index < view->model()->rowCount())); | - | ||||||||||||
1104 | } | - | ||||||||||||
1105 | - | |||||||||||||
1106 | QAccessibleInterface *QAccessibleTableHeaderCell::parent() const | - | ||||||||||||
1107 | { | - | ||||||||||||
1108 | return QAccessible::queryAccessibleInterface(view); | - | ||||||||||||
1109 | } | - | ||||||||||||
1110 | - | |||||||||||||
1111 | QAccessibleInterface *QAccessibleTableHeaderCell::child(int) const | - | ||||||||||||
1112 | { | - | ||||||||||||
1113 | return 0; | - | ||||||||||||
1114 | } | - | ||||||||||||
1115 | - | |||||||||||||
1116 | QHeaderView *QAccessibleTableHeaderCell::headerView() const | - | ||||||||||||
1117 | { | - | ||||||||||||
1118 | QHeaderView *header = 0; | - | ||||||||||||
1119 | if (false) { dead code: { } | - | ||||||||||||
1120 | - | |||||||||||||
1121 | } dead code: else if (const QTableView *tv = qobject_cast<const QTableView*>(view)) {{ } | - | ||||||||||||
1122 | if (orientation == Qt::Horizontal) { | - | ||||||||||||
1123 | header = tv->horizontalHeader(); | - | ||||||||||||
1124 | } else { | - | ||||||||||||
1125 | header = tv->verticalHeader(); | - | ||||||||||||
1126 | } | - | ||||||||||||
1127 | - | |||||||||||||
1128 | - | |||||||||||||
1129 | } else if (const QTreeView *tv = qobject_cast<const QTreeView*>(view)) { | - | ||||||||||||
1130 | header = tv->header(); | - | ||||||||||||
1131 | - | |||||||||||||
1132 | } | - | ||||||||||||
1133 | return header; | - | ||||||||||||
1134 | } | - | ||||||||||||
1135 | - | |||||||||||||
1136 | - | |||||||||||||
1137 | - | |||||||||||||
1138 | - | |||||||||||||
Switch to Source code | Preprocessed file |