Qt 4.8
itemviews.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "itemviews.h"
43 
44 #include <qheaderview.h>
45 #include <qtableview.h>
46 #include <qlistview.h>
47 #include <qtreeview.h>
48 #include <private/qtreewidget_p.h>
49 #include <qaccessible2.h>
50 #include <QDebug>
51 
52 #ifndef QT_NO_ACCESSIBILITY
53 
55 
57 
58 #ifndef QT_NO_ITEMVIEWS
59 /*
60 Implementation of the IAccessible2 table2 interface. Much simpler than
61 the other table interfaces since there is only the main table and cells:
62 
63 TABLE/LIST/TREE
64  |- HEADER CELL
65  |- CELL
66  |- CELL
67  ...
68 */
69 
71 {
73 }
74 
76 {
77  if (!view()->model() || !index.isValid())
78  return -1;
79  int vHeader = verticalHeader() ? 1 : 0;
80  int hHeader = horizontalHeader() ? 1 : 0;
81  // row * number columns + column + 1 for one based counting
82  return (index.row() + hHeader)*(index.model()->columnCount() + vHeader) + (index.column() + vHeader) + 1;
83 }
84 
86 {
87  if (!view()->model())
88  return 0;
89 
90  logicalIndex--; // one based counting ftw
91  int vHeader = verticalHeader() ? 1 : 0;
92  int hHeader = horizontalHeader() ? 1 : 0;
93 
94  int columns = view()->model()->columnCount() + vHeader;
95 
96  int row = logicalIndex / columns;
97  int column = logicalIndex % columns;
98 
99  if (vHeader) {
100  if (column == 0) {
101  if (row == 0) {
102  return new QAccessibleTable2CornerButton(view());
103  }
104  return new QAccessibleTable2HeaderCell(view(), row-1, Qt::Vertical);
105  }
106  --column;
107  }
108  if (hHeader) {
109  if (row == 0) {
110  return new QAccessibleTable2HeaderCell(view(), column, Qt::Horizontal);
111  }
112  --row;
113  }
114 
115  QModelIndex index = view()->model()->index(row, column, view()->rootIndex());
116  if (!index.isValid()) {
117  qWarning() << "QAccessibleTable2::childFromLogical: Invalid index at: " << row << column;
118  return 0;
119  }
120  return new QAccessibleTable2Cell(view(), index, cellRole());
121 }
122 
125 {
126  Q_ASSERT(view());
127 
128  if (qobject_cast<const QTableView*>(view())) {
130  } else if (qobject_cast<const QTreeView*>(view())) {
132  } else if (qobject_cast<const QListView*>(view())) {
134  } else {
135  // is this our best guess?
137  }
138 }
139 
141 {
142 }
143 
145 {
146  QHeaderView *header = 0;
147  if (false) {
148 #ifndef QT_NO_TABLEVIEW
149  } else if (const QTableView *tv = qobject_cast<const QTableView*>(view())) {
150  header = tv->horizontalHeader();
151 #endif
152 #ifndef QT_NO_TREEVIEW
153  } else if (const QTreeView *tv = qobject_cast<const QTreeView*>(view())) {
154  header = tv->header();
155 #endif
156  }
157  return header;
158 }
159 
161 {
162  QHeaderView *header = 0;
163  if (false) {
164 #ifndef QT_NO_TABLEVIEW
165  } else if (const QTableView *tv = qobject_cast<const QTableView*>(view())) {
166  header = tv->verticalHeader();
167 #endif
168  }
169  return header;
170 }
171 
173 {}
174 
175 void QAccessibleTable2::rowsInserted(const QModelIndex &, int first, int last)
176 {
177  lastChange.firstRow = first;
178  lastChange.lastRow = last;
182 }
183 
184 void QAccessibleTable2::rowsRemoved(const QModelIndex &, int first, int last)
185 {
186  lastChange.firstRow = first;
187  lastChange.lastRow = last;
191 }
192 
193 void QAccessibleTable2::columnsInserted(const QModelIndex &, int first, int last)
194 {
195  lastChange.firstRow = 0;
196  lastChange.lastRow = 0;
197  lastChange.firstColumn = first;
198  lastChange.lastColumn = last;
200 }
201 
202 void QAccessibleTable2::columnsRemoved(const QModelIndex &, int first, int last)
203 {
204  lastChange.firstRow = 0;
205  lastChange.lastRow = 0;
206  lastChange.firstColumn = first;
207  lastChange.lastColumn = last;
209 }
210 
211 void QAccessibleTable2::rowsMoved( const QModelIndex &, int, int, const QModelIndex &, int)
212 {
213  lastChange.firstRow = 0;
214  lastChange.lastRow = 0;
218 }
219 
220 void QAccessibleTable2::columnsMoved( const QModelIndex &, int, int, const QModelIndex &, int)
221 {
222  lastChange.firstRow = 0;
223  lastChange.lastRow = 0;
227 }
228 
230 {
231  if (index.isValid())
232  return new QAccessibleTable2Cell(view(), index, cellRole());
233  return 0;
234 }
235 
237 {
238  if (!view()->model())
239  return 0;
241  QModelIndex index = view()->model()->index(row, column, view()->rootIndex());
242  //Q_ASSERT(index.isValid());
243  if (!index.isValid()) {
244  qWarning() << "QAccessibleTable2::cellAt: invalid index: " << index << " for " << view();
245  return 0;
246  }
247  return cell(index);
248 }
249 
251 {
252  return 0;
253 }
254 
256 {
257  if (!view()->model())
258  return QString();
259  return view()->model()->headerData(column, Qt::Horizontal).toString();
260 }
261 
263 {
264  if (!view()->model())
265  return 0;
266  return view()->model()->columnCount();
267 }
268 
270 {
271  if (!view()->model())
272  return 0;
273  return view()->model()->rowCount();
274 }
275 
277 {
278  if (!view()->selectionModel())
279  return 0;
280  return view()->selectionModel()->selectedIndexes().count();
281 }
282 
284 {
285  if (!view()->selectionModel())
286  return 0;
287  return view()->selectionModel()->selectedColumns().count();
288 }
289 
291 {
292  if (!view()->selectionModel())
293  return 0;
294  return view()->selectionModel()->selectedRows().count();
295 }
296 
298 {
299  if (!view()->model())
300  return QString();
301  return view()->model()->headerData(row, Qt::Vertical).toString();
302 }
303 
305 {
307  if (!view()->selectionModel())
308  return cells;
309  Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedIndexes()) {
310  cells.append(cell(index));
311  }
312  return cells;
313 }
314 
316 {
317  QList<int> columns;
318  if (!view()->selectionModel())
319  return columns;
320  Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedColumns()) {
321  columns.append(index.column());
322  }
323  return columns;
324 }
325 
327 {
328  if (!view()->selectionModel())
329  return QList<int>();
330  QList<int> rows;
331  Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedRows()) {
332  rows.append(index.row());
333  }
334  return rows;
335 }
336 
338 {
339  return 0;
340 }
341 
343 {
344  if (!view()->selectionModel())
345  return false;
346  return view()->selectionModel()->isColumnSelected(column, QModelIndex());
347 }
348 
350 {
351  if (!view()->selectionModel())
352  return false;
353  return view()->selectionModel()->isRowSelected(row, QModelIndex());
354 }
355 
357 {
358  if (!view()->model() || !view()->selectionModel())
359  return false;
360  QModelIndex index = view()->model()->index(row, 0, view()->rootIndex());
362  return false;
364  return true;
365 }
366 
368 {
369  if (!view()->model() || !view()->selectionModel())
370  return false;
371  QModelIndex index = view()->model()->index(0, column, view()->rootIndex());
373  return false;
375  return true;
376 }
377 
379 {
380  if (!view()->model() || !view()->selectionModel())
381  return false;
382  QModelIndex index = view()->model()->index(row, 0, view()->rootIndex());
384  return false;
386  return true;
387 }
388 
390 {
391  if (!view()->model() || !view()->selectionModel())
392  return false;
393  QModelIndex index = view()->model()->index(0, column, view()->rootIndex());
395  return false;
397  return true;
398 }
399 
401 {
403  // FIXME
404  return change;
405 }
406 
408 {
409  Q_ASSERT(child >= 0);
410  if (child > 0)
411  return QAccessible::Cell;
412  return m_role;
413 }
414 
416 {
417  Q_ASSERT(child == 0);
419 }
420 
421 int QAccessibleTable2::childAt(int x, int y) const
422 {
423  QPoint viewportOffset = view()->viewport()->mapTo(view(), QPoint(0,0));
424  QPoint indexPosition = view()->mapFromGlobal(QPoint(x, y) - viewportOffset);
425  // FIXME: if indexPosition < 0 in one coordinate, return header
426 
427  QModelIndex index = view()->indexAt(indexPosition);
428  if (index.isValid()) {
429  return logicalIndex(index);
430  }
431  return -1;
432 }
433 
435 {
436  if (!view()->model())
437  return 0;
438  int vHeader = verticalHeader() ? 1 : 0;
439  int hHeader = horizontalHeader() ? 1 : 0;
440  return (view()->model()->rowCount()+hHeader) * (view()->model()->columnCount()+vHeader);
441 }
442 
444 {
445  if (!view()->model())
446  return -1;
447  Q_ASSERT(iface->role(0) != QAccessible::TreeItem); // should be handled by tree class
448  if (iface->role(0) == QAccessible::Cell || iface->role(0) == QAccessible::ListItem) {
449  const QAccessibleTable2Cell* cell = static_cast<const QAccessibleTable2Cell*>(iface);
450  return logicalIndex(cell->m_index);
451  } else if (iface->role(0) == QAccessible::ColumnHeader){
452  const QAccessibleTable2HeaderCell* cell = static_cast<const QAccessibleTable2HeaderCell*>(iface);
453  return cell->index + (verticalHeader() ? 1 : 0) + 1;
454  } else if (iface->role(0) == QAccessible::RowHeader){
455  const QAccessibleTable2HeaderCell* cell = static_cast<const QAccessibleTable2HeaderCell*>(iface);
456  return (cell->index+1) * (view()->model()->columnCount()+1) + 1;
457  } else if (iface->role(0) == QAccessible::Pane) {
458  return 1; // corner button
459  } else {
460  qWarning() << "WARNING QAccessibleTable2::indexOfChild Fix my children..."
461  << iface->role(0) << iface->text(QAccessible::Name, 0);
462  }
463  // FIXME: we are in denial of our children. this should stop.
464  return -1;
465 }
466 
468 {
469  Q_ASSERT(child == 0);
470  if (t == QAccessible::Description)
471  return view()->accessibleDescription();
472  return view()->accessibleName();
473 }
474 
476 {
477  Q_ASSERT(!child);
478  if (!view()->isVisible())
479  return QRect();
480  QPoint pos = view()->mapToGlobal(QPoint(0, 0));
481  return QRect(pos.x(), pos.y(), view()->width(), view()->height());
482 }
483 
485 {
486  *iface = 0;
487  if ((index < 0) || (!view()->model()))
488  return -1;
489 
490  switch (relation) {
491  case Ancestor: {
492  if (index == 1 && view()->parent()) {
493  *iface = QAccessible::queryAccessibleInterface(view()->parent());
494  if (*iface)
495  return 0;
496  }
497  break;
498  }
499  case QAccessible::Child: {
500  Q_ASSERT(index > 0);
501  *iface = childFromLogical(index);
502  if (*iface) {
503  return 0;
504  }
505  break;
506  }
507  default:
508  break;
509  }
510  return -1;
511 }
512 
513 QAccessible::Relation QAccessibleTable2::relationTo(int, const QAccessibleInterface *, int) const
514 {
515  return QAccessible::Unrelated;
516 }
517 
518 #ifndef QT_NO_ACTION
520 {
521  return 0;
522 }
524 {
525  return QString();
526 }
528 {
529  return false;
530 }
531 #endif
532 
533 
534 // TREE VIEW
535 
537 {
538  if (!isValid() || !view()->model())
539  return QModelIndex();
540 
541  const QTreeView *treeView = qobject_cast<const QTreeView*>(view());
542  if (treeView->d_func()->viewItems.count() <= row) {
543  qWarning() << "QAccessibleTree::indexFromLogical: invalid index: " << row << column << " for " << treeView;
544  return QModelIndex();
545  }
546  QModelIndex modelIndex = treeView->d_func()->viewItems.at(row).index;
547 
548  if (modelIndex.isValid() && column > 0) {
549  modelIndex = view()->model()->index(modelIndex.row(), column, modelIndex.parent());
550  }
551  return modelIndex;
552 }
553 
554 int QAccessibleTree::childAt(int x, int y) const
555 {
556  QPoint viewportOffset = view()->viewport()->mapTo(view(), QPoint(0,0));
557  QPoint indexPosition = view()->mapFromGlobal(QPoint(x, y) - viewportOffset);
558 
559  QModelIndex index = view()->indexAt(indexPosition);
560  if (!index.isValid())
561  return -1;
562 
563  const QTreeView *treeView = qobject_cast<const QTreeView*>(view());
564  int row = treeView->d_func()->viewIndex(index) + (horizontalHeader() ? 1 : 0);
565  int column = index.column();
566 
567  int i = row * view()->model()->columnCount() + column + 1;
568  Q_ASSERT(i > view()->model()->columnCount());
569  return i;
570 }
571 
573 {
574  const QTreeView *treeView = qobject_cast<const QTreeView*>(view());
575  Q_ASSERT(treeView);
576  if (!view()->model())
577  return 0;
578 
579  int hHeader = horizontalHeader() ? 1 : 0;
580  return (treeView->d_func()->viewItems.count() + hHeader)* view()->model()->columnCount();
581 }
582 
584 {
585  const QTreeView *treeView = qobject_cast<const QTreeView*>(view());
586  Q_ASSERT(treeView);
587  return treeView->d_func()->viewItems.count();
588 }
589 
591 {
592  if (!view()->model())
593  return -1;
594  if (iface->role(0) == QAccessible::TreeItem) {
595  const QAccessibleTable2Cell* cell = static_cast<const QAccessibleTable2Cell*>(iface);
596  const QTreeView *treeView = qobject_cast<const QTreeView*>(view());
597  Q_ASSERT(treeView);
598  int row = treeView->d_func()->viewIndex(cell->m_index) + (horizontalHeader() ? 1 : 0);
599  int column = cell->m_index.column();
600 
601  int index = row * view()->model()->columnCount() + column + 1;
602  //qDebug() << "QAccessibleTree::indexOfChild r " << row << " c " << column << "index " << index;
603  Q_ASSERT(index > treeView->model()->columnCount());
604  return index;
605  } else if (iface->role(0) == QAccessible::ColumnHeader){
606  const QAccessibleTable2HeaderCell* cell = static_cast<const QAccessibleTable2HeaderCell*>(iface);
607  //qDebug() << "QAccessibleTree::indexOfChild header " << cell->index << "is: " << cell->index + 1;
608  return cell->index + 1;
609  } else {
610  qWarning() << "WARNING QAccessibleTable2::indexOfChild invalid child"
611  << iface->role(0) << iface->text(QAccessible::Name, 0);
612  }
613  // FIXME: add scrollbars and don't just ignore them
614  return -1;
615 }
616 
618 {
619  *iface = 0;
620  if ((index < 0) || (!view()->model()))
621  return -1;
622 
623  switch (relation) {
624  case QAccessible::Child: {
625  Q_ASSERT(index > 0);
626  --index;
627  int hHeader = horizontalHeader() ? 1 : 0;
628 
629  if (hHeader) {
630  if (index < view()->model()->columnCount()) {
631  *iface = new QAccessibleTable2HeaderCell(view(), index, Qt::Horizontal);
632  return 0;
633  } else {
634  index -= view()->model()->columnCount();
635  }
636  }
637 
638  int row = index / view()->model()->columnCount();
639  int column = index % view()->model()->columnCount();
640  QModelIndex modelIndex = indexFromLogical(row, column);
641  if (modelIndex.isValid()) {
642  *iface = cell(modelIndex);
643  return 0;
644  }
645  return -1;
646  }
647  default:
648  break;
649  }
650  // handle everything except child
651  return QAccessibleTable2::navigate(relation, index, iface);
652 }
653 
654 QAccessible::Relation QAccessibleTree::relationTo(int, const QAccessibleInterface *, int) const
655 {
656  return QAccessible::Unrelated;
657 }
658 
660 {
661  QModelIndex index = indexFromLogical(row, column);
662  if (!index.isValid()) {
663  qWarning() << "Requested invalid tree cell: " << row << column;
664  return 0;
665  }
666  return new QAccessibleTable2Cell(view(), index, cellRole());
667 }
668 
670 {
671  return QString(); // no headers for rows in trees
672 }
673 
675 {
676  if (!view()->selectionModel())
677  return false;
678  QModelIndex index = indexFromLogical(row);
679  return view()->selectionModel()->isRowSelected(index.row(), index.parent());
680 }
681 
683 {
684  if (!view()->selectionModel())
685  return false;
686  QModelIndex index = indexFromLogical(row);
688  return false;
690  return true;
691 }
692 
693 // TABLE CELL
694 
696  : /* QAccessibleSimpleEditableTextInterface(this), */ view(view_), m_index(index_), m_role(role_)
697 {
698  Q_ASSERT(index_.isValid());
699 }
700 
701 int QAccessibleTable2Cell::columnExtent() const { return 1; }
702 int QAccessibleTable2Cell::rowExtent() const { return 1; }
703 
705 {
706  QList<QAccessibleInterface*> headerCell;
707  if (verticalHeader()) {
709  }
710  return headerCell;
711 }
712 
714 {
715  QList<QAccessibleInterface*> headerCell;
716  if (horizontalHeader()) {
718  }
719  return headerCell;
720 }
721 
723 {
724  QHeaderView *header = 0;
725 
726  if (false) {
727 #ifndef QT_NO_TABLEVIEW
728  } else if (const QTableView *tv = qobject_cast<const QTableView*>(view)) {
729  header = tv->horizontalHeader();
730 #endif
731 #ifndef QT_NO_TREEVIEW
732  } else if (const QTreeView *tv = qobject_cast<const QTreeView*>(view)) {
733  header = tv->header();
734 #endif
735  }
736 
737  return header;
738 }
739 
741 {
742  QHeaderView *header = 0;
743 #ifndef QT_NO_TABLEVIEW
744  if (const QTableView *tv = qobject_cast<const QTableView*>(view))
745  header = tv->verticalHeader();
746 #endif
747  return header;
748 }
749 
751 {
752  return m_index.column();
753 }
754 
756 {
757  if (role(0) == QAccessible::TreeItem) {
758  const QTreeView *treeView = qobject_cast<const QTreeView*>(view);
759  Q_ASSERT(treeView);
760  int row = treeView->d_func()->viewIndex(m_index);
761  return row;
762  }
763  return m_index.row();
764 }
765 
767 {
769 }
770 
771 void QAccessibleTable2Cell::rowColumnExtents(int *row, int *column, int *rowExtents, int *columnExtents, bool *selected) const
772 {
773  *row = m_index.row();
774  *column = m_index.column();
775  *rowExtents = 1;
776  *columnExtents = 1;
777  *selected = isSelected();
778 }
779 
781 {
783 }
784 
786 {
787  Q_ASSERT(child == 0);
788  return m_role;
789 }
790 
792 {
793  Q_ASSERT(child == 0);
794  State st = Normal;
795 
796  QRect globalRect = view->rect();
797  globalRect.translate(view->mapToGlobal(QPoint(0,0)));
798  if (!globalRect.intersects(rect(0)))
799  st |= Invisible;
800 
802  st |= Selected;
804  st |= Focused;
806  st |= Checked;
807 
808  Qt::ItemFlags flags = m_index.flags();
809  if (flags & Qt::ItemIsSelectable) {
810  st |= Selectable;
811  st |= Focusable;
813  st |= MultiSelectable;
815  st |= ExtSelectable;
816  }
817  if (m_role == QAccessible::TreeItem) {
818  const QTreeView *treeView = qobject_cast<const QTreeView*>(view);
819  if (treeView->isExpanded(m_index))
820  st |= Expanded;
821  }
822  return st;
823 }
824 
826 {
827  return view->model()->hasChildren(m_index);
828 }
829 
831 {
832  Q_ASSERT(child == 0);
833 
834  QRect r;
835  r = view->visualRect(m_index);
836 
837  if (!r.isNull())
838  r.translate(view->viewport()->mapTo(view, QPoint(0,0)));
839  r.translate(view->mapToGlobal(QPoint(0, 0)));
840  return r;
841 }
842 
844 {
845  Q_ASSERT(child == 0);
846  QAbstractItemModel *model = view->model();
847  QString value;
848  switch (t) {
849  case QAccessible::Value:
850  case QAccessible::Name:
851  value = model->data(m_index, Qt::AccessibleTextRole).toString();
852  if (value.isEmpty())
853  value = model->data(m_index, Qt::DisplayRole).toString();
854  break;
857  break;
858  default:
859  break;
860  }
861  return value;
862 }
863 
864 void QAccessibleTable2Cell::setText(Text /*t*/, int child, const QString &text)
865 {
866  Q_ASSERT(child == 0);
867  if (!(m_index.flags() & Qt::ItemIsEditable))
868  return;
869  view->model()->setData(m_index, text);
870 }
871 
873 {
874  return view && view->model() && m_index.isValid();
875 }
876 
878 {
879  if (relation == Ancestor && index == 1) {
880  if (m_role == QAccessible::TreeItem) {
881  *iface = new QAccessibleTree(view);
882  } else {
883  *iface = new QAccessibleTable2(view);
884  }
885  return 0;
886  }
887 
888  *iface = 0;
889  if (!view)
890  return -1;
891 
892  switch (relation) {
893 
894  case Child: {
895  return -1;
896  }
897  case Sibling:
898  if (index > 0) {
900  int ret = parent->navigate(QAccessible::Child, index, iface);
901  delete parent;
902  if (*iface)
903  return ret;
904  }
905  return -1;
906 
907 // From table1 implementation:
908 // case Up:
909 // case Down:
910 // case Left:
911 // case Right: {
912 // // This is in the "not so nice" category. In order to find out which item
913 // // is geometrically around, we have to set the current index, navigate
914 // // and restore the index as well as the old selection
915 // view()->setUpdatesEnabled(false);
916 // const QModelIndex oldIdx = view()->currentIndex();
917 // QList<QModelIndex> kids = children();
918 // const QModelIndex currentIndex = index ? kids.at(index - 1) : QModelIndex(row);
919 // const QItemSelection oldSelection = view()->selectionModel()->selection();
920 // view()->setCurrentIndex(currentIndex);
921 // const QModelIndex idx = view()->moveCursor(toCursorAction(relation), Qt::NoModifier);
922 // view()->setCurrentIndex(oldIdx);
923 // view()->selectionModel()->select(oldSelection, QItemSelectionModel::ClearAndSelect);
924 // view()->setUpdatesEnabled(true);
925 // if (!idx.isValid())
926 // return -1;
927 
928 // if (idx.parent() != row.parent() || idx.row() != row.row())
929 // *iface = cell(idx);
930 // return index ? kids.indexOf(idx) + 1 : 0; }
931  default:
932  break;
933  }
934 
935  return -1;
936 }
937 
938 QAccessible::Relation QAccessibleTable2Cell::relationTo(int child, const QAccessibleInterface *other, int otherChild) const
939 {
940  Q_ASSERT(child == 0);
941  Q_ASSERT(otherChild == 0);
942  // we only check for parent-child relationships in trees
943  if (m_role == QAccessible::TreeItem && other->role(0) == QAccessible::TreeItem) {
944  QModelIndex otherIndex = static_cast<const QAccessibleTable2Cell*>(other)->m_index;
945  // is the other our parent?
946  if (otherIndex.parent() == m_index)
947  return QAccessible::Ancestor;
948  // are we the other's child?
949  if (m_index.parent() == otherIndex)
950  return QAccessible::Child;
951  }
952  return QAccessible::Unrelated;
953 }
954 
955 #ifndef QT_NO_ACTION
957 {
958  return 0;
959 }
960 
962 {
963  return QString();
964 }
965 
967 {
968  return false;
969 }
970 
972  : view(view_), index(index_), orientation(orientation_)
973 {
974  Q_ASSERT(index_ >= 0);
975 }
976 
978 {
979  Q_ASSERT(child == 0);
982  return QAccessible::RowHeader;
983 }
984 
986 {
987  Q_ASSERT(child == 0);
988  return QAccessible::Normal;
989 }
990 
992 {
993  Q_ASSERT(child == 0);
994 
995  QHeaderView *header = 0;
996  if (false) {
997 #ifndef QT_NO_TABLEVIEW
998  } else if (const QTableView *tv = qobject_cast<const QTableView*>(view)) {
999  if (orientation == Qt::Horizontal) {
1000  header = tv->horizontalHeader();
1001  } else {
1002  header = tv->verticalHeader();
1003  }
1004 #endif
1005 #ifndef QT_NO_TREEVIEW
1006  } else if (const QTreeView *tv = qobject_cast<const QTreeView*>(view)) {
1007  header = tv->header();
1008 #endif
1009  }
1010  if (!header)
1011  return QRect();
1012  QPoint zero = header->mapToGlobal(QPoint(0, 0));
1013  int sectionSize = header->sectionSize(index);
1014  int sectionPos = header->sectionPosition(index);
1015  return orientation == Qt::Horizontal
1016  ? QRect(zero.x() + sectionPos, zero.y(), sectionSize, header->height())
1017  : QRect(zero.x(), zero.y() + sectionPos, header->width(), sectionSize);
1018 }
1019 
1021 {
1022  Q_ASSERT(child == 0);
1023  QAbstractItemModel *model = view->model();
1024  QString value;
1025  switch (t) {
1026  case QAccessible::Value:
1027  case QAccessible::Name:
1029  if (value.isEmpty())
1030  value = model->headerData(index, orientation, Qt::DisplayRole).toString();
1031  break;
1034  break;
1035  default:
1036  break;
1037  }
1038  return value;
1039 }
1040 
1042 {
1043  return;
1044 }
1045 
1047 {
1048  return view && view->model() && (index >= 0)
1049  && ((orientation == Qt::Horizontal) ? (index < view->model()->columnCount()) : (index < view->model()->rowCount()));
1050 }
1051 
1053 {
1054  if (relation == QAccessible::Ancestor && index == 1) {
1055  if (false) {
1056 #ifndef QT_NO_TREEVIEW
1057  } else if (qobject_cast<const QTreeView*>(view)) {
1058  *iface = new QAccessibleTree(view);
1059  return 0;
1060 #endif
1061  } else {
1062  *iface = new QAccessibleTable2(view);
1063  return 0;
1064  }
1065  }
1066  *iface = 0;
1067  return -1;
1068 }
1069 
1070 QAccessible::Relation QAccessibleTable2HeaderCell::relationTo(int, const QAccessibleInterface *, int) const
1071 {
1072  return QAccessible::Unrelated;
1073 }
1074 
1075 #ifndef QT_NO_ACTION
1077 {
1078  return 0;
1079 }
1080 
1082 {
1083  return QString();
1084 }
1085 
1087 {
1088  return false;
1089 }
1090 #endif
1091 
1092 
1093 
1094 #endif
1095 
1096 #endif // QT_NO_ITEMVIEWS
1097 
1099 
1100 #endif // QT_NO_ACCESSIBILITY
virtual void columnsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
Definition: itemviews.cpp:220
bool selectRow(int row)
Definition: itemviews.cpp:682
QModelIndexList selectedRows(int column=0) const
Returns the indexes in the given column for the rows where all columns are selected.
T qobject_cast(QObject *object)
Definition: qobject.h:375
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
virtual void rowsRemoved(const QModelIndex &parent, int first, int last)
Definition: itemviews.cpp:184
Role role(int child) const
Returns the role of the object, or of the object&#39;s child if child is not 0.
Definition: itemviews.cpp:407
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
QAccessible::Role m_role
Definition: itemviews.h:149
virtual ~QAccessibleTable2()
Definition: itemviews.cpp:140
virtual QAccessibleTable2Interface * table() const
Definition: itemviews.cpp:780
QAccessible::Role cellRole() const
Definition: itemviews.h:128
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual QList< int > selectedRows() const
Definition: itemviews.cpp:326
int childAt(int x, int y) const
Returns the 1-based index of the child that contains the screen coordinates (x, y).
Definition: itemviews.cpp:554
State state(int child) const
Returns the current state of the object, or of the object&#39;s child if child is not 0...
Definition: itemviews.cpp:985
int childCount() const
Returns the number of children that belong to this object.
Definition: itemviews.cpp:434
virtual bool selectColumn(int column)
Definition: itemviews.cpp:367
QPoint mapTo(QWidget *, const QPoint &) const
Translates the widget coordinate pos to the coordinate system of parent.
Definition: qwidget.cpp:4409
QAccessibleTable2HeaderCell(QAbstractItemView *view, int index, Qt::Orientation orientation)
Definition: itemviews.cpp:971
virtual int rowCount() const
Definition: itemviews.cpp:269
virtual QRect visualRect(const QModelIndex &index) const =0
Returns the rectangle on the viewport occupied by the item at index.
Role role(int child) const
Returns the role of the object, or of the object&#39;s child if child is not 0.
Definition: itemviews.cpp:785
bool isColumnSelected(int column, const QModelIndex &parent) const
Returns true if all items are selected in the column with the given parent.
virtual QList< QAccessibleInterface * > columnHeaderCells() const
Definition: itemviews.cpp:713
QObject * object() const
Returns a pointer to the QObject this interface implementation provides information for...
virtual int selectedCellCount() const
Definition: itemviews.cpp:276
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
virtual void rowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
Definition: itemviews.cpp:211
virtual int columnExtent() const
Definition: itemviews.cpp:701
QModelIndexList selectedIndexes() const
Returns a list of all selected model item indexes.
Role
This enum defines the role of an accessible object.
Definition: qaccessible.h:188
QAbstractItemView * view() const
Definition: itemviews.cpp:70
friend class QAccessibleTable2
Definition: itemviews.h:227
bool isValid() const
Returns true if all the data necessary to use this interface implementation is valid (e...
Definition: itemviews.cpp:1046
QHeaderView * horizontalHeader() const
Definition: itemviews.cpp:722
QAccessibleTable2Cell * cell(const QModelIndex &index) const
Definition: itemviews.cpp:229
friend class QAccessibleTable2
Definition: itemviews.h:265
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int userActionCount(int child) const
Returns the number of custom actions of the object, or of the object&#39;s child if child is not 0...
Definition: itemviews.cpp:1076
QModelIndex indexFromLogical(int row, int column=0) const
Definition: itemviews.cpp:536
virtual QAccessible2::TableModelChange modelChange() const
Definition: itemviews.cpp:400
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
virtual void rowColumnExtents(int *row, int *column, int *rowExtents, int *columnExtents, bool *selected) const
Definition: itemviews.cpp:771
QRect rect(int child) const
Returns the geometry of the object, or of the object&#39;s child if child is not 0.
Definition: itemviews.cpp:475
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
virtual QList< QAccessibleTable2CellInterface * > selectedCells() const
Definition: itemviews.cpp:304
int navigate(RelationFlag relation, int m_index, QAccessibleInterface **iface) const
Navigates from this object to an object that has a relationship relation to this object, and returns the respective object in target.
Definition: itemviews.cpp:877
int userActionCount(int child) const
Returns the number of custom actions of the object, or of the object&#39;s child if child is not 0...
Definition: itemviews.cpp:519
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
State state(int child) const
Returns the current state of the object, or of the object&#39;s child if child is not 0...
Definition: itemviews.cpp:415
QString accessibleDescription() const
int logicalIndex(const QModelIndex &index) const
Definition: itemviews.cpp:75
bool isExpanded(const QModelIndex &index) const
Returns true if the model item index is expanded; otherwise returns false.
Definition: qtreeview.cpp:859
Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const
Returns the relationship between this object&#39;s \a child and the \a other object&#39;s \a otherChild...
Definition: itemviews.cpp:654
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int height() const
bool isValid() const
Returns true if all the data necessary to use this interface implementation is valid (e...
Definition: itemviews.cpp:872
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
QModelIndex m_index
Definition: itemviews.h:224
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns the data for the given role and section in the header with the specified orientation.
QString actionText(int action, Text t, int child) const
Returns the text property t of the action action supported by the object, or of the object&#39;s child if...
Definition: itemviews.cpp:1081
SelectionMode selectionMode
which selection mode the view operates in
bool isExpandable() const
Definition: itemviews.cpp:825
TableModelChangeType type
Definition: qaccessible2.h:85
QAccessible2::TableModelChange lastChange
Definition: itemviews.h:126
QHeaderView * verticalHeader() const
Definition: itemviews.cpp:160
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
QWidget * viewport() const
Returns the viewport widget.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
QString text(Text t, int child) const
Returns the value of the text property t of the object, or of the object&#39;s child if child is not 0...
Definition: itemviews.cpp:467
virtual int columnCount() const
Definition: itemviews.cpp:262
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool isRowSelected(int row) const
Definition: itemviews.cpp:674
friend class QAccessibleTree
Definition: itemviews.h:228
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QAccessible::Role m_role
Definition: itemviews.h:225
QString rowDescription(int row) const
Definition: itemviews.cpp:669
Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const
Returns the relationship between this object&#39;s \a child and the \a other object&#39;s \a otherChild...
Definition: itemviews.cpp:1070
virtual bool unselectColumn(int column)
Definition: itemviews.cpp:389
virtual bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Returns true if parent has any children; otherwise returns false.
virtual int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const =0
Navigates from this object to an object that has a relationship relation to this object, and returns the respective object in target.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QItemSelectionModel * selectionModel() const
Returns the current selection model.
bool isSelected(const QModelIndex &index) const
Returns true if the given model item index is selected.
int width() const
RelationFlag
This enum type defines bit flags that can be combined to indicate the relationship between two access...
Definition: qaccessible.h:268
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
int row() const
Returns the row this model index refers to.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
virtual int selectedRowCount() const
Definition: itemviews.cpp:290
virtual QList< int > selectedColumns() const
Definition: itemviews.cpp:315
Qt::Orientation orientation
Definition: itemviews.h:263
Q_CORE_EXPORT void qWarning(const char *,...)
virtual bool isRowSelected(int row) const
Definition: itemviews.cpp:349
int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
Navigates from this object to an object that has a relationship relation to this object, and returns the respective object in target.
Definition: itemviews.cpp:484
QString accessibleName() const
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
QModelIndex currentIndex() const
Returns the model item index for the current item, or an invalid index if there is no current item...
virtual int rowIndex() const
Definition: itemviews.cpp:755
virtual QAccessibleInterface * caption() const
Definition: itemviews.cpp:250
virtual void rowsInserted(const QModelIndex &parent, int first, int last)
Definition: itemviews.cpp:175
The State element defines configurations of objects and properties.
virtual bool selectRow(int row)
Definition: itemviews.cpp:356
void setText(Text t, int child, const QString &text)
Sets the text property t of the object, or of the object&#39;s child if child is not 0, to text.
Definition: itemviews.cpp:1041
virtual int rowExtent() const
Definition: itemviews.cpp:702
bool doAction(int action, int child, const QVariantList &params)
Asks the object, or the object&#39;s child if child is not 0, to execute action using the parameters...
Definition: itemviews.cpp:1086
The QTableView class provides a default model/view implementation of a table view.
Definition: qtableview.h:58
virtual int selectedColumnCount() const
Definition: itemviews.cpp:283
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
friend class QAccessibleTree
Definition: itemviews.h:266
QRect rect() const
virtual QString columnDescription(int column) const
Definition: itemviews.cpp:255
The QAbstractItemModel class provides the abstract interface for item model classes.
Qt::ItemFlags flags() const
Returns the flags for the item referred to by the index.
static QAccessibleInterface * queryAccessibleInterface(QObject *)
If a QAccessibleInterface implementation exists for the given object, this function returns a pointer...
virtual Role role(int child) const =0
Returns the role of the object, or of the object&#39;s child if child is not 0.
QAbstractItemView * view
Definition: itemviews.h:261
int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
Navigates from this object to an object that has a relationship relation to this object, and returns the respective object in target.
Definition: itemviews.cpp:617
The QAbstractItemView class provides the basic functionality for item view classes.
QAccessibleTable2Cell(QAbstractItemView *view, const QModelIndex &m_index, QAccessible::Role role)
Definition: itemviews.cpp:695
QModelIndexList selectedColumns(int row=0) const
Returns the indexes in the given row for columns where all rows are selected.
QHeaderView * horizontalHeader() const
Definition: itemviews.cpp:144
State
Definition: qaudio.h:59
The QAccessibleInterface class defines an interface that exposes information about accessible objects...
Definition: qaccessible.h:370
QString Q_GUI_EXPORT qt_accStripAmp(const QString &text)
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().
int rowCount() const
Definition: itemviews.cpp:583
virtual void columnsRemoved(const QModelIndex &parent, int first, int last)
Definition: itemviews.cpp:202
bool doAction(int action, int child, const QVariantList &params)
Asks the object, or the object&#39;s child if child is not 0, to execute action using the parameters...
Definition: itemviews.cpp:966
#define st(var, type, card)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QModelIndex class is used to locate data in a data model.
virtual bool unselectRow(int row)
Definition: itemviews.cpp:378
QString text(Text t, int child) const
Returns the value of the text property t of the object, or of the object&#39;s child if child is not 0...
Definition: itemviews.cpp:1020
virtual QString text(Text t, int child) const =0
Returns the value of the text property t of the object, or of the object&#39;s child if child is not 0...
QAccessibleTable2Interface * table2Interface()
Definition: qaccessible.h:432
virtual bool isColumnSelected(int column) const
Definition: itemviews.cpp:342
virtual int columnIndex() const
Definition: itemviews.cpp:750
Role role(int child) const
Returns the role of the object, or of the object&#39;s child if child is not 0.
Definition: itemviews.cpp:977
int sectionSize(int logicalIndex) const
Returns the width (or height for vertical headers) of the given logicalIndex.
static const int zero
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QRect rect(int child) const
Returns the geometry of the object, or of the object&#39;s child if child is not 0.
Definition: itemviews.cpp:991
virtual void modelReset()
Definition: itemviews.cpp:172
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
quint16 index
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
int indexOfChild(const QAccessibleInterface *) const
Returns the 1-based index of the object child in this object&#39;s children list, or -1 if child is not a...
Definition: itemviews.cpp:590
QString actionText(int action, Text t, int child) const
Returns the text property t of the action action supported by the object, or of the object&#39;s child if...
Definition: itemviews.cpp:961
int childCount() const
Returns the number of children that belong to this object.
Definition: itemviews.cpp:572
Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const
Returns the relationship between this object&#39;s \a child and the \a other object&#39;s \a otherChild...
Definition: itemviews.cpp:513
#define Q_FOREACH(variable, container)
Same as foreach(variable, container).
Definition: qglobal.h:2435
QAccessibleTable2CellInterface * cellAt(int row, int column) const
Definition: itemviews.cpp:659
QPointer< QAbstractItemView > view
Definition: itemviews.h:223
bool isValid() const
Returns true if all the data necessary to use this interface implementation is valid (e...
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
virtual QString rowDescription(int row) const
Definition: itemviews.cpp:297
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
int sectionPosition(int logicalIndex) const
Returns the section position of the given logicalIndex, or -1 if the section is hidden.
State state(int child) const
Returns the current state of the object, or of the object&#39;s child if child is not 0...
Definition: itemviews.cpp:791
int childAt(int x, int y) const
Returns the 1-based index of the child that contains the screen coordinates (x, y).
Definition: itemviews.cpp:421
void setText(Text t, int child, const QString &text)
Sets the text property t of the object, or of the object&#39;s child if child is not 0, to text.
Definition: itemviews.cpp:864
QAccessibleTable2(QWidget *w)
Definition: itemviews.cpp:123
QAbstractItemModel * model() const
Returns the model that this view is presenting.
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
Orientation
Definition: qnamespace.h:174
int indexOfChild(const QAccessibleInterface *) const
Returns the 1-based index of the object child in this object&#39;s children list, or -1 if child is not a...
Definition: itemviews.cpp:443
QString actionText(int action, Text t, int child) const
Returns the text property t of the action action supported by the object, or of the object&#39;s child if...
Definition: itemviews.cpp:523
virtual QList< QAccessibleInterface * > rowHeaderCells() const
Definition: itemviews.cpp:704
virtual QAccessibleTable2CellInterface * cellAt(int row, int column) const
Definition: itemviews.cpp:236
QAccessibleInterface * childFromLogical(int logicalIndex) const
Definition: itemviews.cpp:85
QRect rect(int child) const
Returns the geometry of the object, or of the object&#39;s child if child is not 0.
Definition: itemviews.cpp:830
bool doAction(int action, int child, const QVariantList &params)
Asks the object, or the object&#39;s child if child is not 0, to execute action using the parameters...
Definition: itemviews.cpp:527
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const
Returns the relationship between this object&#39;s \a child and the \a other object&#39;s \a otherChild...
Definition: itemviews.cpp:938
int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
Navigates from this object to an object that has a relationship relation to this object, and returns the respective object in target.
Definition: itemviews.cpp:1052
QHeaderView * verticalHeader() const
Definition: itemviews.cpp:740
int userActionCount(int child) const
Returns the number of custom actions of the object, or of the object&#39;s child if child is not 0...
Definition: itemviews.cpp:956
QString text(Text t, int child) const
Returns the value of the text property t of the object, or of the object&#39;s child if child is not 0...
Definition: itemviews.cpp:843
#define text
Definition: qobjectdefs.h:80
bool isRowSelected(int row, const QModelIndex &parent) const
Returns true if all items are selected in the row with the given parent.
int column() const
Returns the column this model index refers to.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
virtual bool isSelected() const
Definition: itemviews.cpp:766
The Text item allows you to add formatted text to a scene.
virtual QModelIndex indexAt(const QPoint &point) const =0
Returns the model index of the item at the viewport coordinates point.
virtual QAccessibleInterface * summary() const
Definition: itemviews.cpp:337
virtual void columnsInserted(const QModelIndex &parent, int first, int last)
Definition: itemviews.cpp:193