Qt 4.8
qtableview.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 QtGui module 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 "qtableview.h"
43 
44 #ifndef QT_NO_TABLEVIEW
45 #include <qheaderview.h>
46 #include <qitemdelegate.h>
47 #include <qapplication.h>
48 #include <qpainter.h>
49 #include <qstyle.h>
50 #include <qsize.h>
51 #include <qevent.h>
52 #include <qbitarray.h>
53 #include <qscrollbar.h>
54 #include <qabstractbutton.h>
55 #include <private/qtableview_p.h>
56 #ifndef QT_NO_ACCESSIBILITY
57 #include <qaccessible.h>
58 #endif
59 
61 
66 {
67  spans.append(span);
68  Index::iterator it_y = index.lowerBound(-span->top());
69  if (it_y == index.end() || it_y.key() != -span->top()) {
70  //there is no spans that starts with the row in the index, so create a sublist for it.
71  SubIndex sub_index;
72  if (it_y != index.end()) {
73  //the previouslist is the list of spans that sarts _before_ the row of the span.
74  // and which may intersect this row.
75  const SubIndex previousList = it_y.value();
76  foreach(Span *s, previousList) {
77  //If a subspans intersect the row, we need to split it into subspans
78  if(s->bottom() >= span->top())
79  sub_index.insert(-s->left(), s);
80  }
81  }
82  it_y = index.insert(-span->top(), sub_index);
83  //we will insert span to *it_y in the later loop
84  }
85 
86  //insert the span as supspan in all the lists that intesects the span
87  while(-it_y.key() <= span->bottom()) {
88  (*it_y).insert(-span->left(), span);
89  if(it_y == index.begin())
90  break;
91  --it_y;
92  }
93 }
94 
95 
104 {
105  if (old_height < span->height()) {
106  //add the span as subspan in all the lists that intersect the new covered columns
107  Index::iterator it_y = index.lowerBound(-(span->top() + old_height - 1));
108  Q_ASSERT(it_y != index.end()); //it_y must exist since the span is in the list
109  while (-it_y.key() <= span->bottom()) {
110  (*it_y).insert(-span->left(), span);
111  if(it_y == index.begin())
112  break;
113  --it_y;
114  }
115  } else if (old_height > span->height()) {
116  //remove the span from all the subspans lists that intersect the columns not covered anymore
117  Index::iterator it_y = index.lowerBound(-qMax(span->bottom(), span->top())); //qMax useful if height is 0
118  Q_ASSERT(it_y != index.end()); //it_y must exist since the span is in the list
119  while (-it_y.key() <= span->top() + old_height -1) {
120  if (-it_y.key() > span->bottom()) {
121  int removed = (*it_y).remove(-span->left());
122  Q_ASSERT(removed == 1); Q_UNUSED(removed);
123  if (it_y->isEmpty()) {
124  it_y = index.erase(it_y);
125  }
126  }
127  if(it_y == index.begin())
128  break;
129  --it_y;
130  }
131  }
132 
133  if (span->width() == 0 && span->height() == 0) {
134  spans.removeOne(span);
135  delete span;
136  }
137 }
138 
143 {
145  if (it_y == index.end())
146  return 0;
147  SubIndex::const_iterator it_x = (*it_y).lowerBound(-x);
148  if (it_x == (*it_y).end())
149  return 0;
150  Span *span = *it_x;
151  if (span->right() >= x && span->bottom() >= y)
152  return span;
153  return 0;
154 }
155 
156 
161 {
162  qDeleteAll(spans);
163  index.clear();
164  spans.clear();
165 }
166 
171 {
172  QSet<Span *> list;
174  if(it_y == index.end())
175  --it_y;
176  while(-it_y.key() <= y + h) {
177  SubIndex::const_iterator it_x = (*it_y).lowerBound(-x);
178  if (it_x == (*it_y).end())
179  --it_x;
180  while(-it_x.key() <= x + w) {
181  Span *s = *it_x;
182  if (s->bottom() >= y && s->right() >= x)
183  list << s;
184  if (it_x == (*it_y).begin())
185  break;
186  --it_x;
187  }
188  if(it_y == index.begin())
189  break;
190  --it_y;
191  }
192  return list.toList();
193 }
194 
195 #undef DEBUG_SPAN_UPDATE
196 
197 #ifdef DEBUG_SPAN_UPDATE
199 {
200  str << "(" << span.top() << "," << span.left() << "," << span.bottom() << "," << span.right() << ")";
201  return str;
202 }
203 #endif
204 
209 {
210 #ifdef DEBUG_SPAN_UPDATE
211  qDebug() << Q_FUNC_INFO;
212  qDebug() << start << end;
213  qDebug() << index;
214 #endif
215  if (spans.isEmpty())
216  return;
217 
218  int delta = end - start + 1;
219 #ifdef DEBUG_SPAN_UPDATE
220  qDebug("Before");
221 #endif
222  for (SpanList::iterator it = spans.begin(); it != spans.end(); ++it) {
223  Span *span = *it;
224 #ifdef DEBUG_SPAN_UPDATE
225  qDebug() << span << *span;
226 #endif
227  if (span->m_bottom < start)
228  continue;
229  if (span->m_top >= start)
230  span->m_top += delta;
231  span->m_bottom += delta;
232  }
233 
234 #ifdef DEBUG_SPAN_UPDATE
235  qDebug("After");
236  foreach (QSpanCollection::Span *span, spans)
237  qDebug() << span << *span;
238 #endif
239 
240  for (Index::iterator it_y = index.begin(); it_y != index.end(); ) {
241  int y = -it_y.key();
242  if (y < start) {
243  ++it_y;
244  continue;
245  }
246 
247  index.insert(-y - delta, it_y.value());
248  it_y = index.erase(it_y);
249  }
250 #ifdef DEBUG_SPAN_UPDATE
251  qDebug() << index;
252 #endif
253 }
254 
259 {
260 #ifdef DEBUG_SPAN_UPDATE
261  qDebug() << Q_FUNC_INFO;
262  qDebug() << start << end;
263  qDebug() << index;
264 #endif
265  if (spans.isEmpty())
266  return;
267 
268  int delta = end - start + 1;
269 #ifdef DEBUG_SPAN_UPDATE
270  qDebug("Before");
271 #endif
272  for (SpanList::iterator it = spans.begin(); it != spans.end(); ++it) {
273  Span *span = *it;
274 #ifdef DEBUG_SPAN_UPDATE
275  qDebug() << span << *span;
276 #endif
277  if (span->m_right < start)
278  continue;
279  if (span->m_left >= start)
280  span->m_left += delta;
281  span->m_right += delta;
282  }
283 
284 #ifdef DEBUG_SPAN_UPDATE
285  qDebug("After");
286  foreach (QSpanCollection::Span *span, spans)
287  qDebug() << span << *span;
288 #endif
289 
290  for (Index::iterator it_y = index.begin(); it_y != index.end(); ++it_y) {
291  SubIndex &subindex = it_y.value();
292  for (SubIndex::iterator it = subindex.begin(); it != subindex.end(); ) {
293  int x = -it.key();
294  if (x < start) {
295  ++it;
296  continue;
297  }
298  subindex.insert(-x - delta, it.value());
299  it = subindex.erase(it);
300  }
301  }
302 #ifdef DEBUG_SPAN_UPDATE
303  qDebug() << index;
304 #endif
305 }
306 
313 {
314  if (subindex.isEmpty())
315  return true;
316 
317  bool should_be_deleted = true;
318  SubIndex::iterator it = subindex.end();
319  do {
320  --it;
321  int x = -it.key();
322  Span *span = it.value();
323  if (span->will_be_deleted) {
324  it = subindex.erase(it);
325  continue;
326  }
327  if (update && span->m_left != x) {
328  subindex.insert(-span->m_left, span);
329  it = subindex.erase(it);
330  }
331  if (should_be_deleted && span->m_top == y)
332  should_be_deleted = false;
333  } while (it != subindex.begin());
334 
335  return should_be_deleted;
336 }
337 
342 {
343 #ifdef DEBUG_SPAN_UPDATE
344  qDebug() << Q_FUNC_INFO;
345  qDebug() << start << end;
346  qDebug() << index;
347 #endif
348  if (spans.isEmpty())
349  return;
350 
351  SpanList spansToBeDeleted;
352  int delta = end - start + 1;
353 #ifdef DEBUG_SPAN_UPDATE
354  qDebug("Before");
355 #endif
356  for (SpanList::iterator it = spans.begin(); it != spans.end(); ) {
357  Span *span = *it;
358 #ifdef DEBUG_SPAN_UPDATE
359  qDebug() << span << *span;
360 #endif
361  if (span->m_bottom < start) {
362  ++it;
363  continue;
364  }
365  if (span->m_top < start) {
366  if (span->m_bottom <= end)
367  span->m_bottom = start - 1;
368  else
369  span->m_bottom -= delta;
370  } else {
371  if (span->m_bottom > end) {
372  if (span->m_top <= end)
373  span->m_top = start;
374  else
375  span->m_top -= delta;
376  span->m_bottom -= delta;
377  } else {
378  span->will_be_deleted = true;
379  }
380  }
381  if (span->m_top == span->m_bottom && span->m_left == span->m_right)
382  span->will_be_deleted = true;
383  if (span->will_be_deleted) {
384  spansToBeDeleted.append(span);
385  it = spans.erase(it);
386  } else {
387  ++it;
388  }
389  }
390 
391 #ifdef DEBUG_SPAN_UPDATE
392  qDebug("After");
393  foreach (QSpanCollection::Span *span, spans)
394  qDebug() << span << *span;
395 #endif
396  if (spans.isEmpty()) {
397  qDeleteAll(spansToBeDeleted);
398  index.clear();
399  return;
400  }
401 
402  Index::iterator it_y = index.end();
403  do {
404  --it_y;
405  int y = -it_y.key();
406  SubIndex &subindex = it_y.value();
407  if (y < start) {
408  if (cleanSpanSubIndex(subindex, y))
409  it_y = index.erase(it_y);
410  } else if (y >= start && y <= end) {
411  bool span_at_start = false;
412  SubIndex spansToBeMoved;
413  for (SubIndex::iterator it = subindex.begin(); it != subindex.end(); ++it) {
414  Span *span = it.value();
415  if (span->will_be_deleted)
416  continue;
417  if (!span_at_start && span->m_top == start)
418  span_at_start = true;
419  spansToBeMoved.insert(it.key(), span);
420  }
421 
422  if (y == start && span_at_start)
423  subindex.clear();
424  else
425  it_y = index.erase(it_y);
426 
427  if (span_at_start) {
428  Index::iterator it_start;
429  if (y == start)
430  it_start = it_y;
431  else {
432  it_start = index.find(-start);
433  if (it_start == index.end())
434  it_start = index.insert(-start, SubIndex());
435  }
436  SubIndex &start_subindex = it_start.value();
437  for (SubIndex::iterator it = spansToBeMoved.begin(); it != spansToBeMoved.end(); ++it)
438  start_subindex.insert(it.key(), it.value());
439  }
440  } else {
441  if (y == end + 1) {
442  Index::iterator it_top = index.find(-y + delta);
443  if (it_top == index.end())
444  it_top = index.insert(-y + delta, SubIndex());
445  for (SubIndex::iterator it = subindex.begin(); it != subindex.end(); ) {
446  Span *span = it.value();
447  if (!span->will_be_deleted)
448  it_top.value().insert(it.key(), span);
449  ++it;
450  }
451  } else {
452  index.insert(-y + delta, subindex);
453  }
454  it_y = index.erase(it_y);
455  }
456  } while (it_y != index.begin());
457 
458 #ifdef DEBUG_SPAN_UPDATE
459  qDebug() << index;
460  qDebug("Deleted");
461  foreach (QSpanCollection::Span *span, spansToBeDeleted)
462  qDebug() << span << *span;
463 #endif
464  qDeleteAll(spansToBeDeleted);
465 }
466 
471 {
472 #ifdef DEBUG_SPAN_UPDATE
473  qDebug() << Q_FUNC_INFO;
474  qDebug() << start << end;
475  qDebug() << index;
476 #endif
477  if (spans.isEmpty())
478  return;
479 
480  SpanList toBeDeleted;
481  int delta = end - start + 1;
482 #ifdef DEBUG_SPAN_UPDATE
483  qDebug("Before");
484 #endif
485  for (SpanList::iterator it = spans.begin(); it != spans.end(); ) {
486  Span *span = *it;
487 #ifdef DEBUG_SPAN_UPDATE
488  qDebug() << span << *span;
489 #endif
490  if (span->m_right < start) {
491  ++it;
492  continue;
493  }
494  if (span->m_left < start) {
495  if (span->m_right <= end)
496  span->m_right = start - 1;
497  else
498  span->m_right -= delta;
499  } else {
500  if (span->m_right > end) {
501  if (span->m_left <= end)
502  span->m_left = start;
503  else
504  span->m_left -= delta;
505  span->m_right -= delta;
506  } else {
507  span->will_be_deleted = true;
508  }
509  }
510  if (span->m_top == span->m_bottom && span->m_left == span->m_right)
511  span->will_be_deleted = true;
512  if (span->will_be_deleted) {
513  toBeDeleted.append(span);
514  it = spans.erase(it);
515  } else {
516  ++it;
517  }
518  }
519 
520 #ifdef DEBUG_SPAN_UPDATE
521  qDebug("After");
522  foreach (QSpanCollection::Span *span, spans)
523  qDebug() << span << *span;
524 #endif
525  if (spans.isEmpty()) {
526  qDeleteAll(toBeDeleted);
527  index.clear();
528  return;
529  }
530 
531  for (Index::iterator it_y = index.begin(); it_y != index.end(); ) {
532  int y = -it_y.key();
533  if (cleanSpanSubIndex(it_y.value(), y, true))
534  it_y = index.erase(it_y);
535  else
536  ++it_y;
537  }
538 
539 #ifdef DEBUG_SPAN_UPDATE
540  qDebug() << index;
541  qDebug("Deleted");
542  foreach (QSpanCollection::Span *span, toBeDeleted)
543  qDebug() << span << *span;
544 #endif
545  qDeleteAll(toBeDeleted);
546 }
547 
548 #ifdef QT_BUILD_INTERNAL
549 
556 bool QSpanCollection::checkConsistency() const
557 {
558  for (Index::const_iterator it_y = index.begin(); it_y != index.end(); ++it_y) {
559  int y = -it_y.key();
560  const SubIndex &subIndex = it_y.value();
561  for (SubIndex::const_iterator it = subIndex.begin(); it != subIndex.end(); ++it) {
562  int x = -it.key();
563  Span *span = it.value();
564  if (!spans.contains(span) || span->left() != x
565  || y < span->top() || y > span->bottom())
566  return false;
567  }
568  }
569 
570  foreach (const Span *span, spans) {
571  if (span->width() < 1 || span->height() < 1
572  || (span->width() == 1 && span->height() == 1))
573  return false;
574  for (int y = span->top(); y <= span->bottom(); ++y) {
575  Index::const_iterator it_y = index.find(-y);
576  if (it_y == index.end()) {
577  if (y == span->top())
578  return false;
579  else
580  continue;
581  }
582  const SubIndex &subIndex = it_y.value();
583  SubIndex::const_iterator it = subIndex.find(-span->left());
584  if (it == subIndex.end() || it.value() != span)
585  return false;
586  }
587  }
588  return true;
589 }
590 #endif
591 
593 {
594  Q_OBJECT
595 public:
598  QStyleOptionHeader opt;
599  opt.init(this);
601  if (isEnabled())
602  state |= QStyle::State_Enabled;
603  if (isActiveWindow())
604  state |= QStyle::State_Active;
605  if (isDown())
606  state |= QStyle::State_Sunken;
607  opt.state = state;
608  opt.rect = rect();
610  QPainter painter(this);
611  style()->drawControl(QStyle::CE_Header, &opt, &painter, this);
612  }
613 };
614 
616 {
617  Q_Q(QTableView);
618 
619  q->setEditTriggers(editTriggers|QAbstractItemView::AnyKeyPressed);
620 
621  QHeaderView *vertical = new QHeaderView(Qt::Vertical, q);
622  vertical->setClickable(true);
623  vertical->setHighlightSections(true);
624  q->setVerticalHeader(vertical);
625 
626  QHeaderView *horizontal = new QHeaderView(Qt::Horizontal, q);
627  horizontal->setClickable(true);
628  horizontal->setHighlightSections(true);
629  q->setHorizontalHeader(horizontal);
630 
631  tabKeyNavigation = true;
632 
633  cornerWidget = new QTableCornerButton(q);
634  cornerWidget->setFocusPolicy(Qt::NoFocus);
635  QObject::connect(cornerWidget, SIGNAL(clicked()), q, SLOT(selectAll()));
636 }
637 
646 {
647  Q_ASSERT(range && range->isValid());
648 
649  int top = range->top();
650  int left = range->left();
651  int bottom = range->bottom();
652  int right = range->right();
653 
654  while (bottom >= top && verticalHeader->isSectionHidden(bottom))
655  --bottom;
656  while (right >= left && horizontalHeader->isSectionHidden(right))
657  --right;
658 
659  if (top > bottom || left > right) { // everything is hidden
660  *range = QItemSelectionRange();
661  return;
662  }
663 
664  while (verticalHeader->isSectionHidden(top) && top <= bottom)
665  ++top;
666  while (horizontalHeader->isSectionHidden(left) && left <= right)
667  ++left;
668 
669  if (top > bottom || left > right) { // everything is hidden
670  *range = QItemSelectionRange();
671  return;
672  }
673 
674  QModelIndex bottomRight = model->index(bottom, right, range->parent());
675  QModelIndex topLeft = model->index(top, left, range->parent());
676  *range = QItemSelectionRange(topLeft, bottomRight);
677 }
678 
686 void QTableViewPrivate::setSpan(int row, int column, int rowSpan, int columnSpan)
687 {
688  if (row < 0 || column < 0 || rowSpan <= 0 || columnSpan <= 0) {
689  qWarning() << "QTableView::setSpan: invalid span given: (" << row << ',' << column << ',' << rowSpan << ',' << columnSpan << ')';
690  return;
691  }
692  QSpanCollection::Span *sp = spans.spanAt(column, row);
693  if (sp) {
694  if (sp->top() != row || sp->left() != column) {
695  qWarning() << "QTableView::setSpan: span cannot overlap";
696  return;
697  }
698  if (rowSpan == 1 && columnSpan == 1) {
699  rowSpan = columnSpan = 0;
700  }
701  const int old_height = sp->height();
702  sp->m_bottom = row + rowSpan - 1;
703  sp->m_right = column + columnSpan - 1;
704  spans.updateSpan(sp, old_height);
705  return;
706  } else if (rowSpan == 1 && columnSpan == 1) {
707  qWarning() << "QTableView::setSpan: single cell span won't be added";
708  return;
709  }
710  sp = new QSpanCollection::Span(row, column, rowSpan, columnSpan);
711  spans.addSpan(sp);
712 }
713 
722 {
723  QSpanCollection::Span *sp = spans.spanAt(column, row);
724  if (sp)
725  return *sp;
726 
727  return QSpanCollection::Span(row, column, 1, 1);
728 }
729 
737 int QTableViewPrivate::sectionSpanEndLogical(const QHeaderView *header, int logical, int span) const
738 {
739  int visual = header->visualIndex(logical);
740  for (int i = 1; i < span; ) {
741  if (++visual >= header->count())
742  break;
743  logical = header->logicalIndex(visual);
744  ++i;
745  }
746  return logical;
747 }
748 
757 int QTableViewPrivate::sectionSpanSize(const QHeaderView *header, int logical, int span) const
758 {
759  int endLogical = sectionSpanEndLogical(header, logical, span);
760  return header->sectionPosition(endLogical)
761  - header->sectionPosition(logical)
762  + header->sectionSize(endLogical);
763 }
764 
774 bool QTableViewPrivate::spanContainsSection(const QHeaderView *header, int logical, int spanLogical, int span) const
775 {
776  if (logical == spanLogical)
777  return true; // it's the start of the span
778  int visual = header->visualIndex(spanLogical);
779  for (int i = 1; i < span; ) {
780  if (++visual >= header->count())
781  break;
782  spanLogical = header->logicalIndex(visual);
783  if (logical == spanLogical)
784  return true;
785  ++i;
786  }
787  return false;
788 }
789 
798 {
799  Q_Q(const QTableView);
800  // vertical
801  int row = span.top();
802  int rowp = verticalHeader->sectionViewportPosition(row);
803  int rowh = rowSpanHeight(row, span.height());
804  // horizontal
805  int column = span.left();
806  int colw = columnSpanWidth(column, span.width());
807  if (q->isRightToLeft())
808  column = span.right();
809  int colp = horizontalHeader->sectionViewportPosition(column);
810 
811  const int i = showGrid ? 1 : 0;
812  if (q->isRightToLeft())
813  return QRect(colp + i, rowp, colw - i, rowh - i);
814  return QRect(colp, rowp, colw - i, rowh - i);
815 }
816 
827  const QStyleOptionViewItemV4 &option, QBitArray *drawn,
828  int firstVisualRow, int lastVisualRow, int firstVisualColumn, int lastVisualColumn)
829 {
830  bool alternateBase = false;
831  QRegion region = viewport->rect();
832 
833  QList<QSpanCollection::Span *> visibleSpans;
834  bool sectionMoved = verticalHeader->sectionsMoved() || horizontalHeader->sectionsMoved();
835 
836  if (!sectionMoved) {
837  visibleSpans = spans.spansInRect(logicalColumn(firstVisualColumn), logicalRow(firstVisualRow),
838  lastVisualColumn - firstVisualColumn + 1, lastVisualRow - firstVisualRow + 1);
839  } else {
841  for(int x = firstVisualColumn; x <= lastVisualColumn; x++)
842  for(int y = firstVisualRow; y <= lastVisualRow; y++)
843  set.insert(spans.spanAt(x,y));
844  set.remove(0);
845  visibleSpans = set.toList();
846  }
847 
848  foreach (QSpanCollection::Span *span, visibleSpans) {
849  int row = span->top();
850  int col = span->left();
851  QModelIndex index = model->index(row, col, root);
852  if (!index.isValid())
853  continue;
854  QRect rect = visualSpanRect(*span);
855  rect.translate(scrollDelayOffset);
856  if (!area.intersects(rect))
857  continue;
858  QStyleOptionViewItemV4 opt = option;
859  opt.rect = rect;
860  alternateBase = alternatingColors && (span->top() & 1);
861  if (alternateBase)
863  else
864  opt.features &= ~QStyleOptionViewItemV2::Alternate;
865  drawCell(painter, opt, index);
866  region -= rect;
867  for (int r = span->top(); r <= span->bottom(); ++r) {
868  const int vr = visualRow(r);
869  if (vr < firstVisualRow || vr > lastVisualRow)
870  continue;
871  for (int c = span->left(); c <= span->right(); ++c) {
872  const int vc = visualColumn(c);
873  if (vc < firstVisualColumn || vc > lastVisualColumn)
874  continue;
875  drawn->setBit((vr - firstVisualRow) * (lastVisualColumn - firstVisualColumn + 1)
876  + vc - firstVisualColumn);
877  }
878  }
879 
880  }
881  painter->setClipRegion(region);
882 }
883 
892 {
893  Q_UNUSED(parent)
894  spans.updateInsertedRows(start, end);
895 }
896 
905 {
906  Q_UNUSED(parent)
907  spans.updateInsertedColumns(start, end);
908 }
909 
918 {
919  Q_UNUSED(parent)
920  spans.updateRemovedRows(start, end);
921 }
922 
931 {
932  Q_UNUSED(parent)
933  spans.updateRemovedColumns(start, end);
934 }
935 
944 {
945  Q_Q(QTableView);
946  QStyleOptionViewItemV4 opt = option;
947 
948  if (selectionModel && selectionModel->isSelected(index))
950  if (index == hover)
952  if (option.state & QStyle::State_Enabled) {
954  if ((model->flags(index) & Qt::ItemIsEnabled) == 0) {
955  opt.state &= ~QStyle::State_Enabled;
956  cg = QPalette::Disabled;
957  } else {
958  cg = QPalette::Normal;
959  }
961  }
962 
963  if (index == q->currentIndex()) {
964  const bool focus = (q->hasFocus() || viewport->hasFocus()) && q->currentIndex().isValid();
965  if (focus)
967  }
968 
969  q->style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, q);
970 
971  q->itemDelegate(index)->paint(painter, opt, index);
972 }
973 
1077  : QAbstractItemView(*new QTableViewPrivate, parent)
1078 {
1079  Q_D(QTableView);
1080  d->init();
1081 }
1082 
1087  : QAbstractItemView(dd, parent)
1088 {
1089  Q_D(QTableView);
1090  d->init();
1091 }
1092 
1097 {
1098 }
1099 
1104 {
1105  Q_D(QTableView);
1106  if (model == d->model)
1107  return;
1108  //let's disconnect from the old model
1109  if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
1110  disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
1111  this, SLOT(_q_updateSpanInsertedRows(QModelIndex,int,int)));
1112  disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),
1113  this, SLOT(_q_updateSpanInsertedColumns(QModelIndex,int,int)));
1114  disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
1115  this, SLOT(_q_updateSpanRemovedRows(QModelIndex,int,int)));
1116  disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
1117  this, SLOT(_q_updateSpanRemovedColumns(QModelIndex,int,int)));
1118  }
1119  if (model) { //and connect to the new one
1120  connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
1121  this, SLOT(_q_updateSpanInsertedRows(QModelIndex,int,int)));
1122  connect(model, SIGNAL(columnsInserted(QModelIndex,int,int)),
1123  this, SLOT(_q_updateSpanInsertedColumns(QModelIndex,int,int)));
1124  connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
1125  this, SLOT(_q_updateSpanRemovedRows(QModelIndex,int,int)));
1126  connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
1127  this, SLOT(_q_updateSpanRemovedColumns(QModelIndex,int,int)));
1128  }
1129  d->verticalHeader->setModel(model);
1130  d->horizontalHeader->setModel(model);
1132 }
1133 
1138 {
1139  Q_D(QTableView);
1140  if (index == d->root) {
1141  viewport()->update();
1142  return;
1143  }
1144  d->verticalHeader->setRootIndex(index);
1145  d->horizontalHeader->setRootIndex(index);
1147 }
1148 
1153 {
1154  Q_D(QTableView);
1157  const int max = verticalScrollBar()->maximum();
1158  if (max > 0 && verticalScrollBar()->value() == max)
1159  d->verticalHeader->setOffsetToLastSection();
1160  else
1161  d->verticalHeader->setOffsetToSectionPosition(verticalScrollBar()->value());
1162  } else {
1163  d->verticalHeader->setOffset(verticalScrollBar()->value());
1164  }
1165  if (!d->verticalHeader->updatesEnabled())
1166  d->verticalHeader->setUpdatesEnabled(true);
1167 }
1168 
1173 {
1174  Q_D(QTableView);
1175  Q_ASSERT(selectionModel);
1176  d->verticalHeader->setSelectionModel(selectionModel);
1177  d->horizontalHeader->setSelectionModel(selectionModel);
1178  QAbstractItemView::setSelectionModel(selectionModel);
1179 }
1180 
1187 {
1188  Q_D(const QTableView);
1189  return d->horizontalHeader;
1190 }
1191 
1198 {
1199  Q_D(const QTableView);
1200  return d->verticalHeader;
1201 }
1202 
1209 {
1210  Q_D(QTableView);
1211 
1212  if (!header || header == d->horizontalHeader)
1213  return;
1214  if (d->horizontalHeader && d->horizontalHeader->parent() == this)
1215  delete d->horizontalHeader;
1216  d->horizontalHeader = header;
1217  d->horizontalHeader->setParent(this);
1218  if (!d->horizontalHeader->model()) {
1219  d->horizontalHeader->setModel(d->model);
1220  if (d->selectionModel)
1221  d->horizontalHeader->setSelectionModel(d->selectionModel);
1222  }
1223 
1224  connect(d->horizontalHeader,SIGNAL(sectionResized(int,int,int)),
1225  this, SLOT(columnResized(int,int,int)));
1226  connect(d->horizontalHeader, SIGNAL(sectionMoved(int,int,int)),
1227  this, SLOT(columnMoved(int,int,int)));
1228  connect(d->horizontalHeader, SIGNAL(sectionCountChanged(int,int)),
1229  this, SLOT(columnCountChanged(int,int)));
1230  connect(d->horizontalHeader, SIGNAL(sectionPressed(int)), this, SLOT(selectColumn(int)));
1231  connect(d->horizontalHeader, SIGNAL(sectionEntered(int)), this, SLOT(_q_selectColumn(int)));
1232  connect(d->horizontalHeader, SIGNAL(sectionHandleDoubleClicked(int)),
1233  this, SLOT(resizeColumnToContents(int)));
1234  connect(d->horizontalHeader, SIGNAL(geometriesChanged()), this, SLOT(updateGeometries()));
1235 
1236  //update the sorting enabled states on the new header
1237  setSortingEnabled(d->sortingEnabled);
1238 }
1239 
1246 {
1247  Q_D(QTableView);
1248 
1249  if (!header || header == d->verticalHeader)
1250  return;
1251  if (d->verticalHeader && d->verticalHeader->parent() == this)
1252  delete d->verticalHeader;
1253  d->verticalHeader = header;
1254  d->verticalHeader->setParent(this);
1255  if (!d->verticalHeader->model()) {
1256  d->verticalHeader->setModel(d->model);
1257  if (d->selectionModel)
1258  d->verticalHeader->setSelectionModel(d->selectionModel);
1259  }
1260 
1261  connect(d->verticalHeader, SIGNAL(sectionResized(int,int,int)),
1262  this, SLOT(rowResized(int,int,int)));
1263  connect(d->verticalHeader, SIGNAL(sectionMoved(int,int,int)),
1264  this, SLOT(rowMoved(int,int,int)));
1265  connect(d->verticalHeader, SIGNAL(sectionCountChanged(int,int)),
1266  this, SLOT(rowCountChanged(int,int)));
1267  connect(d->verticalHeader, SIGNAL(sectionPressed(int)), this, SLOT(selectRow(int)));
1268  connect(d->verticalHeader, SIGNAL(sectionEntered(int)), this, SLOT(_q_selectRow(int)));
1269  connect(d->verticalHeader, SIGNAL(sectionHandleDoubleClicked(int)),
1270  this, SLOT(resizeRowToContents(int)));
1271  connect(d->verticalHeader, SIGNAL(geometriesChanged()), this, SLOT(updateGeometries()));
1272 }
1273 
1282 void QTableView::scrollContentsBy(int dx, int dy)
1283 {
1284  Q_D(QTableView);
1285 
1286  d->delayedAutoScroll.stop(); // auto scroll was canceled by the user scrolling
1287 
1288  dx = isRightToLeft() ? -dx : dx;
1289  if (dx) {
1291  int oldOffset = d->horizontalHeader->offset();
1292  if (horizontalScrollBar()->value() == horizontalScrollBar()->maximum())
1293  d->horizontalHeader->setOffsetToLastSection();
1294  else
1295  d->horizontalHeader->setOffsetToSectionPosition(horizontalScrollBar()->value());
1296  int newOffset = d->horizontalHeader->offset();
1297  dx = isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset;
1298  } else {
1299  d->horizontalHeader->setOffset(horizontalScrollBar()->value());
1300  }
1301  }
1302  if (dy) {
1304  int oldOffset = d->verticalHeader->offset();
1305  if (verticalScrollBar()->value() == verticalScrollBar()->maximum())
1306  d->verticalHeader->setOffsetToLastSection();
1307  else
1308  d->verticalHeader->setOffsetToSectionPosition(verticalScrollBar()->value());
1309  int newOffset = d->verticalHeader->offset();
1310  dy = oldOffset - newOffset;
1311  } else {
1312  d->verticalHeader->setOffset(verticalScrollBar()->value());
1313  }
1314  }
1315  d->scrollContentsBy(dx, dy);
1316 
1317  if (d->showGrid) {
1318  //we need to update the first line of the previous top item in the view
1319  //because it has the grid drawn if the header is invisible.
1320  //It is strictly related to what's done at then end of the paintEvent
1321  if (dy > 0 && d->horizontalHeader->isHidden() && d->verticalScrollMode == ScrollPerItem) {
1322  d->viewport->update(0, dy, d->viewport->width(), dy);
1323  }
1324  if (dx > 0 && d->verticalHeader->isHidden() && d->horizontalScrollMode == ScrollPerItem) {
1325  d->viewport->update(dx, 0, dx, d->viewport->height());
1326  }
1327  }
1328 }
1329 
1334 {
1336  option.showDecorationSelected = true;
1337  return option;
1338 }
1339 
1344 {
1345  Q_D(QTableView);
1346  // setup temp variables for the painting
1347  QStyleOptionViewItemV4 option = d->viewOptionsV4();
1348  const QPoint offset = d->scrollDelayOffset;
1349  const bool showGrid = d->showGrid;
1350  const int gridSize = showGrid ? 1 : 0;
1351  const int gridHint = style()->styleHint(QStyle::SH_Table_GridLineColor, &option, this);
1352  const QColor gridColor = static_cast<QRgb>(gridHint);
1353  const QPen gridPen = QPen(gridColor, 0, d->gridStyle);
1354  const QHeaderView *verticalHeader = d->verticalHeader;
1355  const QHeaderView *horizontalHeader = d->horizontalHeader;
1356  const bool alternate = d->alternatingColors;
1357  const bool rightToLeft = isRightToLeft();
1358 
1359  QPainter painter(d->viewport);
1360 
1361  // if there's nothing to do, clear the area and return
1362  if (horizontalHeader->count() == 0 || verticalHeader->count() == 0 || !d->itemDelegate)
1363  return;
1364 
1365  uint x = horizontalHeader->length() - horizontalHeader->offset() - (rightToLeft ? 0 : 1);
1366  uint y = verticalHeader->length() - verticalHeader->offset() - 1;
1367 
1368  const QRegion region = event->region().translated(offset);
1369  const QVector<QRect> rects = region.rects();
1370 
1371  //firstVisualRow is the visual index of the first visible row. lastVisualRow is the visual index of the last visible Row.
1372  //same goes for ...VisualColumn
1373  int firstVisualRow = qMax(verticalHeader->visualIndexAt(0),0);
1374  int lastVisualRow = verticalHeader->visualIndexAt(verticalHeader->viewport()->height());
1375  if (lastVisualRow == -1)
1376  lastVisualRow = d->model->rowCount(d->root) - 1;
1377 
1378  int firstVisualColumn = horizontalHeader->visualIndexAt(0);
1379  int lastVisualColumn = horizontalHeader->visualIndexAt(horizontalHeader->viewport()->width());
1380  if (rightToLeft)
1381  qSwap(firstVisualColumn, lastVisualColumn);
1382  if (firstVisualColumn == -1)
1383  firstVisualColumn = 0;
1384  if (lastVisualColumn == -1)
1385  lastVisualColumn = horizontalHeader->count() - 1;
1386 
1387  QBitArray drawn((lastVisualRow - firstVisualRow + 1) * (lastVisualColumn - firstVisualColumn + 1));
1388 
1389  if (d->hasSpans()) {
1390  d->drawAndClipSpans(region, &painter, option, &drawn,
1391  firstVisualRow, lastVisualRow, firstVisualColumn, lastVisualColumn);
1392  }
1393 
1394  for (int i = 0; i < rects.size(); ++i) {
1395  QRect dirtyArea = rects.at(i);
1396  dirtyArea.setBottom(qMin(dirtyArea.bottom(), int(y)));
1397  if (rightToLeft) {
1398  dirtyArea.setLeft(qMax(dirtyArea.left(), d->viewport->width() - int(x)));
1399  } else {
1400  dirtyArea.setRight(qMin(dirtyArea.right(), int(x)));
1401  }
1402 
1403  // get the horizontal start and end visual sections
1404  int left = horizontalHeader->visualIndexAt(dirtyArea.left());
1405  int right = horizontalHeader->visualIndexAt(dirtyArea.right());
1406  if (rightToLeft)
1407  qSwap(left, right);
1408  if (left == -1) left = 0;
1409  if (right == -1) right = horizontalHeader->count() - 1;
1410 
1411  // get the vertical start and end visual sections and if alternate color
1412  int bottom = verticalHeader->visualIndexAt(dirtyArea.bottom());
1413  if (bottom == -1) bottom = verticalHeader->count() - 1;
1414  int top = 0;
1415  bool alternateBase = false;
1416  if (alternate && verticalHeader->sectionsHidden()) {
1417  uint verticalOffset = verticalHeader->offset();
1418  int row = verticalHeader->logicalIndex(top);
1419  for (int y = 0;
1420  ((uint)(y += verticalHeader->sectionSize(top)) <= verticalOffset) && (top < bottom);
1421  ++top) {
1422  row = verticalHeader->logicalIndex(top);
1423  if (alternate && !verticalHeader->isSectionHidden(row))
1424  alternateBase = !alternateBase;
1425  }
1426  } else {
1427  top = verticalHeader->visualIndexAt(dirtyArea.top());
1428  alternateBase = (top & 1) && alternate;
1429  }
1430  if (top == -1 || top > bottom)
1431  continue;
1432 
1433  // Paint each row item
1434  for (int visualRowIndex = top; visualRowIndex <= bottom; ++visualRowIndex) {
1435  int row = verticalHeader->logicalIndex(visualRowIndex);
1436  if (verticalHeader->isSectionHidden(row))
1437  continue;
1438  int rowY = rowViewportPosition(row);
1439  rowY += offset.y();
1440  int rowh = rowHeight(row) - gridSize;
1441 
1442  // Paint each column item
1443  for (int visualColumnIndex = left; visualColumnIndex <= right; ++visualColumnIndex) {
1444  int currentBit = (visualRowIndex - firstVisualRow) * (lastVisualColumn - firstVisualColumn + 1)
1445  + visualColumnIndex - firstVisualColumn;
1446 
1447  if (currentBit < 0 || currentBit >= drawn.size() || drawn.testBit(currentBit))
1448  continue;
1449  drawn.setBit(currentBit);
1450 
1451  int col = horizontalHeader->logicalIndex(visualColumnIndex);
1452  if (horizontalHeader->isSectionHidden(col))
1453  continue;
1454  int colp = columnViewportPosition(col);
1455  colp += offset.x();
1456  int colw = columnWidth(col) - gridSize;
1457 
1458  const QModelIndex index = d->model->index(row, col, d->root);
1459  if (index.isValid()) {
1460  option.rect = QRect(colp + (showGrid && rightToLeft ? 1 : 0), rowY, colw, rowh);
1461  if (alternate) {
1462  if (alternateBase)
1464  else
1465  option.features &= ~QStyleOptionViewItemV2::Alternate;
1466  }
1467  d->drawCell(&painter, option, index);
1468  }
1469  }
1470  alternateBase = !alternateBase && alternate;
1471  }
1472 
1473  if (showGrid) {
1474  // Find the bottom right (the last rows/columns might be hidden)
1475  while (verticalHeader->isSectionHidden(verticalHeader->logicalIndex(bottom))) --bottom;
1476  QPen old = painter.pen();
1477  painter.setPen(gridPen);
1478  // Paint each row
1479  for (int visualIndex = top; visualIndex <= bottom; ++visualIndex) {
1480  int row = verticalHeader->logicalIndex(visualIndex);
1481  if (verticalHeader->isSectionHidden(row))
1482  continue;
1483  int rowY = rowViewportPosition(row);
1484  rowY += offset.y();
1485  int rowh = rowHeight(row) - gridSize;
1486  painter.drawLine(dirtyArea.left(), rowY + rowh, dirtyArea.right(), rowY + rowh);
1487  }
1488 
1489  // Paint each column
1490  for (int h = left; h <= right; ++h) {
1491  int col = horizontalHeader->logicalIndex(h);
1492  if (horizontalHeader->isSectionHidden(col))
1493  continue;
1494  int colp = columnViewportPosition(col);
1495  colp += offset.x();
1496  if (!rightToLeft)
1497  colp += columnWidth(col) - gridSize;
1498  painter.drawLine(colp, dirtyArea.top(), colp, dirtyArea.bottom());
1499  }
1500 
1501  //draw the top & left grid lines if the headers are not visible.
1502  //We do update this line when subsequent scroll happen (see scrollContentsBy)
1503  if (horizontalHeader->isHidden() && verticalScrollMode() == ScrollPerItem)
1504  painter.drawLine(dirtyArea.left(), 0, dirtyArea.right(), 0);
1505  if (verticalHeader->isHidden() && horizontalScrollMode() == ScrollPerItem)
1506  painter.drawLine(0, dirtyArea.top(), 0, dirtyArea.bottom());
1507  painter.setPen(old);
1508  }
1509  }
1510 
1511 #ifndef QT_NO_DRAGANDDROP
1512  // Paint the dropIndicator
1513  d->paintDropIndicator(&painter);
1514 #endif
1515 }
1516 
1522 {
1523  Q_D(const QTableView);
1524  d->executePostedLayout();
1525  int r = rowAt(pos.y());
1526  int c = columnAt(pos.x());
1527  if (r >= 0 && c >= 0) {
1528  if (d->hasSpans()) {
1529  QSpanCollection::Span span = d->span(r, c);
1530  r = span.top();
1531  c = span.left();
1532  }
1533  return d->model->index(r, c, d->root);
1534  }
1535  return QModelIndex();
1536 }
1537 
1547 {
1548  Q_D(const QTableView);
1549  return d->horizontalHeader->offset();
1550 }
1551 
1561 {
1562  Q_D(const QTableView);
1563  return d->verticalHeader->offset();
1564 }
1565 
1577 QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
1578 {
1579  Q_D(QTableView);
1580  Q_UNUSED(modifiers);
1581 
1582  int bottom = d->model->rowCount(d->root) - 1;
1583  // make sure that bottom is the bottommost *visible* row
1584  while (bottom >= 0 && isRowHidden(d->logicalRow(bottom)))
1585  --bottom;
1586 
1587  int right = d->model->columnCount(d->root) - 1;
1588 
1589  while (right >= 0 && isColumnHidden(d->logicalColumn(right)))
1590  --right;
1591 
1592  if (bottom == -1 || right == -1)
1593  return QModelIndex(); // model is empty
1594 
1595  QModelIndex current = currentIndex();
1596 
1597  if (!current.isValid()) {
1598  int row = 0;
1599  int column = 0;
1600  while (column < right && isColumnHidden(d->logicalColumn(column)))
1601  ++column;
1602  while (isRowHidden(d->logicalRow(row)) && row < bottom)
1603  ++row;
1604  d->visualCursor = QPoint(column, row);
1605  return d->model->index(d->logicalRow(row), d->logicalColumn(column), d->root);
1606  }
1607 
1608  // Update visual cursor if current index has changed.
1609  QPoint visualCurrent(d->visualColumn(current.column()), d->visualRow(current.row()));
1610  if (visualCurrent != d->visualCursor) {
1611  if (d->hasSpans()) {
1612  QSpanCollection::Span span = d->span(current.row(), current.column());
1613  if (span.top() > d->visualCursor.y() || d->visualCursor.y() > span.bottom()
1614  || span.left() > d->visualCursor.x() || d->visualCursor.x() > span.right())
1615  d->visualCursor = visualCurrent;
1616  } else {
1617  d->visualCursor = visualCurrent;
1618  }
1619  }
1620 
1621  int visualRow = d->visualCursor.y();
1622  if (visualRow > bottom)
1623  visualRow = bottom;
1624  Q_ASSERT(visualRow != -1);
1625  int visualColumn = d->visualCursor.x();
1626  if (visualColumn > right)
1627  visualColumn = right;
1628  Q_ASSERT(visualColumn != -1);
1629 
1630  if (isRightToLeft()) {
1631  if (cursorAction == MoveLeft)
1632  cursorAction = MoveRight;
1633  else if (cursorAction == MoveRight)
1634  cursorAction = MoveLeft;
1635  }
1636 
1637  switch (cursorAction) {
1638  case MoveUp: {
1639  int originalRow = visualRow;
1640 #ifdef QT_KEYPAD_NAVIGATION
1641  if (QApplication::keypadNavigationEnabled() && visualRow == 0)
1642  visualRow = d->visualRow(model()->rowCount() - 1) + 1;
1643  // FIXME? visualRow = bottom + 1;
1644 #endif
1645  int r = d->logicalRow(visualRow);
1646  int c = d->logicalColumn(visualColumn);
1647  if (r != -1 && d->hasSpans()) {
1648  QSpanCollection::Span span = d->span(r, c);
1649  if (span.width() > 1 || span.height() > 1)
1650  visualRow = d->visualRow(span.top());
1651  }
1652  while (visualRow >= 0) {
1653  --visualRow;
1654  r = d->logicalRow(visualRow);
1655  c = d->logicalColumn(visualColumn);
1656  if (r == -1 || (!isRowHidden(r) && d->isCellEnabled(r, c)))
1657  break;
1658  }
1659  if (visualRow < 0)
1660  visualRow = originalRow;
1661  break;
1662  }
1663  case MoveDown: {
1664  int originalRow = visualRow;
1665  if (d->hasSpans()) {
1666  QSpanCollection::Span span = d->span(current.row(), current.column());
1667  visualRow = d->visualRow(d->rowSpanEndLogical(span.top(), span.height()));
1668  }
1669 #ifdef QT_KEYPAD_NAVIGATION
1670  if (QApplication::keypadNavigationEnabled() && visualRow >= bottom)
1671  visualRow = -1;
1672 #endif
1673  int r = d->logicalRow(visualRow);
1674  int c = d->logicalColumn(visualColumn);
1675  if (r != -1 && d->hasSpans()) {
1676  QSpanCollection::Span span = d->span(r, c);
1677  if (span.width() > 1 || span.height() > 1)
1678  visualRow = d->visualRow(d->rowSpanEndLogical(span.top(), span.height()));
1679  }
1680  while (visualRow <= bottom) {
1681  ++visualRow;
1682  r = d->logicalRow(visualRow);
1683  c = d->logicalColumn(visualColumn);
1684  if (r == -1 || (!isRowHidden(r) && d->isCellEnabled(r, c)))
1685  break;
1686  }
1687  if (visualRow > bottom)
1688  visualRow = originalRow;
1689  break;
1690  }
1691  case MovePrevious:
1692  case MoveLeft: {
1693  int originalRow = visualRow;
1694  int originalColumn = visualColumn;
1695  bool firstTime = true;
1696  bool looped = false;
1697  bool wrapped = false;
1698  do {
1699  int r = d->logicalRow(visualRow);
1700  int c = d->logicalColumn(visualColumn);
1701  if (firstTime && c != -1 && d->hasSpans()) {
1702  firstTime = false;
1703  QSpanCollection::Span span = d->span(r, c);
1704  if (span.width() > 1 || span.height() > 1)
1705  visualColumn = d->visualColumn(span.left());
1706  }
1707  while (visualColumn >= 0) {
1708  --visualColumn;
1709  r = d->logicalRow(visualRow);
1710  c = d->logicalColumn(visualColumn);
1711  if (r == -1 || c == -1 || (!isRowHidden(r) && !isColumnHidden(c) && d->isCellEnabled(r, c)))
1712  break;
1713  if (wrapped && (originalRow < visualRow || (originalRow == visualRow && originalColumn <= visualColumn))) {
1714  looped = true;
1715  break;
1716  }
1717  }
1718  if (cursorAction == MoveLeft || visualColumn >= 0)
1719  break;
1720  visualColumn = right + 1;
1721  if (visualRow == 0) {
1722  wrapped = true;
1723  visualRow = bottom;
1724  } else {
1725  --visualRow;
1726  }
1727  } while (!looped);
1728  if (visualColumn < 0)
1729  visualColumn = originalColumn;
1730  break;
1731  }
1732  case MoveNext:
1733  case MoveRight: {
1734  int originalRow = visualRow;
1735  int originalColumn = visualColumn;
1736  bool firstTime = true;
1737  bool looped = false;
1738  bool wrapped = false;
1739  do {
1740  int r = d->logicalRow(visualRow);
1741  int c = d->logicalColumn(visualColumn);
1742  if (firstTime && c != -1 && d->hasSpans()) {
1743  firstTime = false;
1744  QSpanCollection::Span span = d->span(r, c);
1745  if (span.width() > 1 || span.height() > 1)
1746  visualColumn = d->visualColumn(d->columnSpanEndLogical(span.left(), span.width()));
1747  }
1748  while (visualColumn <= right) {
1749  ++visualColumn;
1750  r = d->logicalRow(visualRow);
1751  c = d->logicalColumn(visualColumn);
1752  if (r == -1 || c == -1 || (!isRowHidden(r) && !isColumnHidden(c) && d->isCellEnabled(r, c)))
1753  break;
1754  if (wrapped && (originalRow > visualRow || (originalRow == visualRow && originalColumn >= visualColumn))) {
1755  looped = true;
1756  break;
1757  }
1758  }
1759  if (cursorAction == MoveRight || visualColumn <= right)
1760  break;
1761  visualColumn = -1;
1762  if (visualRow == bottom) {
1763  wrapped = true;
1764  visualRow = 0;
1765  } else {
1766  ++visualRow;
1767  }
1768  } while (!looped);
1769  if (visualColumn > right)
1770  visualColumn = originalColumn;
1771  break;
1772  }
1773  case MoveHome:
1774  visualColumn = 0;
1775  while (visualColumn < right && d->isVisualColumnHiddenOrDisabled(visualRow, visualColumn))
1776  ++visualColumn;
1777  if (modifiers & Qt::ControlModifier) {
1778  visualRow = 0;
1779  while (visualRow < bottom && d->isVisualRowHiddenOrDisabled(visualRow, visualColumn))
1780  ++visualRow;
1781  }
1782  break;
1783  case MoveEnd:
1784  visualColumn = right;
1785  if (modifiers & Qt::ControlModifier)
1786  visualRow = bottom;
1787  break;
1788  case MovePageUp: {
1789  int newRow = rowAt(visualRect(current).top() - d->viewport->height());
1790  if (newRow == -1)
1791  newRow = d->logicalRow(0);
1792  return d->model->index(newRow, current.column(), d->root);
1793  }
1794  case MovePageDown: {
1795  int newRow = rowAt(visualRect(current).bottom() + d->viewport->height());
1796  if (newRow == -1)
1797  newRow = d->logicalRow(bottom);
1798  return d->model->index(newRow, current.column(), d->root);
1799  }}
1800 
1801  d->visualCursor = QPoint(visualColumn, visualRow);
1802  int logicalRow = d->logicalRow(visualRow);
1803  int logicalColumn = d->logicalColumn(visualColumn);
1804  if (!d->model->hasIndex(logicalRow, logicalColumn, d->root))
1805  return QModelIndex();
1806 
1807  QModelIndex result = d->model->index(logicalRow, logicalColumn, d->root);
1808  if (!d->isRowHidden(logicalRow) && !d->isColumnHidden(logicalColumn) && d->isIndexEnabled(result))
1809  return result;
1810 
1811  return QModelIndex();
1812 }
1813 
1824 void QTableView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
1825 {
1826  Q_D(QTableView);
1827  QModelIndex tl = indexAt(QPoint(isRightToLeft() ? qMax(rect.left(), rect.right())
1828  : qMin(rect.left(), rect.right()), qMin(rect.top(), rect.bottom())));
1829  QModelIndex br = indexAt(QPoint(isRightToLeft() ? qMin(rect.left(), rect.right()) :
1830  qMax(rect.left(), rect.right()), qMax(rect.top(), rect.bottom())));
1831  if (!d->selectionModel || !tl.isValid() || !br.isValid() || !d->isIndexEnabled(tl) || !d->isIndexEnabled(br))
1832  return;
1833 
1834  bool verticalMoved = verticalHeader()->sectionsMoved();
1835  bool horizontalMoved = horizontalHeader()->sectionsMoved();
1836 
1837  QItemSelection selection;
1838 
1839  if (d->hasSpans()) {
1840  bool expanded;
1841  int top = qMin(d->visualRow(tl.row()), d->visualRow(br.row()));
1842  int left = qMin(d->visualColumn(tl.column()), d->visualColumn(br.column()));
1843  int bottom = qMax(d->visualRow(tl.row()), d->visualRow(br.row()));
1844  int right = qMax(d->visualColumn(tl.column()), d->visualColumn(br.column()));
1845  do {
1846  expanded = false;
1847  foreach (QSpanCollection::Span *it, d->spans.spans) {
1848  const QSpanCollection::Span &span = *it;
1849  int t = d->visualRow(span.top());
1850  int l = d->visualColumn(span.left());
1851  int b = d->visualRow(d->rowSpanEndLogical(span.top(), span.height()));
1852  int r = d->visualColumn(d->columnSpanEndLogical(span.left(), span.width()));
1853  if ((t > bottom) || (l > right) || (top > b) || (left > r))
1854  continue; // no intersect
1855  if (t < top) {
1856  top = t;
1857  expanded = true;
1858  }
1859  if (l < left) {
1860  left = l;
1861  expanded = true;
1862  }
1863  if (b > bottom) {
1864  bottom = b;
1865  expanded = true;
1866  }
1867  if (r > right) {
1868  right = r;
1869  expanded = true;
1870  }
1871  if (expanded)
1872  break;
1873  }
1874  } while (expanded);
1875  for (int horizontal = left; horizontal <= right; ++horizontal) {
1876  int column = d->logicalColumn(horizontal);
1877  for (int vertical = top; vertical <= bottom; ++vertical) {
1878  int row = d->logicalRow(vertical);
1879  QModelIndex index = d->model->index(row, column, d->root);
1880  selection.append(QItemSelectionRange(index));
1881  }
1882  }
1883  } else if (verticalMoved && horizontalMoved) {
1884  int top = d->visualRow(tl.row());
1885  int left = d->visualColumn(tl.column());
1886  int bottom = d->visualRow(br.row());
1887  int right = d->visualColumn(br.column());
1888  for (int horizontal = left; horizontal <= right; ++horizontal) {
1889  int column = d->logicalColumn(horizontal);
1890  for (int vertical = top; vertical <= bottom; ++vertical) {
1891  int row = d->logicalRow(vertical);
1892  QModelIndex index = d->model->index(row, column, d->root);
1893  selection.append(QItemSelectionRange(index));
1894  }
1895  }
1896  } else if (horizontalMoved) {
1897  int left = d->visualColumn(tl.column());
1898  int right = d->visualColumn(br.column());
1899  for (int visual = left; visual <= right; ++visual) {
1900  int column = d->logicalColumn(visual);
1901  QModelIndex topLeft = d->model->index(tl.row(), column, d->root);
1902  QModelIndex bottomRight = d->model->index(br.row(), column, d->root);
1903  selection.append(QItemSelectionRange(topLeft, bottomRight));
1904  }
1905  } else if (verticalMoved) {
1906  int top = d->visualRow(tl.row());
1907  int bottom = d->visualRow(br.row());
1908  for (int visual = top; visual <= bottom; ++visual) {
1909  int row = d->logicalRow(visual);
1910  QModelIndex topLeft = d->model->index(row, tl.column(), d->root);
1911  QModelIndex bottomRight = d->model->index(row, br.column(), d->root);
1912  selection.append(QItemSelectionRange(topLeft, bottomRight));
1913  }
1914  } else { // nothing moved
1915  QItemSelectionRange range(tl, br);
1916  if (!range.isEmpty())
1917  selection.append(range);
1918  }
1919 
1920  d->selectionModel->select(selection, command);
1921 }
1922 
1936 {
1937  Q_D(const QTableView);
1938 
1939  if (selection.isEmpty())
1940  return QRegion();
1941 
1942  QRegion selectionRegion;
1943  const QRect &viewportRect = d->viewport->rect();
1944  bool verticalMoved = verticalHeader()->sectionsMoved();
1945  bool horizontalMoved = horizontalHeader()->sectionsMoved();
1946 
1947  if ((verticalMoved && horizontalMoved) || (d->hasSpans() && (verticalMoved || horizontalMoved))) {
1948  for (int i = 0; i < selection.count(); ++i) {
1949  QItemSelectionRange range = selection.at(i);
1950  if (range.parent() != d->root || !range.isValid())
1951  continue;
1952  for (int r = range.top(); r <= range.bottom(); ++r)
1953  for (int c = range.left(); c <= range.right(); ++c) {
1954  const QRect &rangeRect = visualRect(d->model->index(r, c, d->root));
1955  if (viewportRect.intersects(rangeRect))
1956  selectionRegion += rangeRect;
1957  }
1958  }
1959  } else if (horizontalMoved) {
1960  for (int i = 0; i < selection.count(); ++i) {
1961  QItemSelectionRange range = selection.at(i);
1962  if (range.parent() != d->root || !range.isValid())
1963  continue;
1964  int top = rowViewportPosition(range.top());
1965  int bottom = rowViewportPosition(range.bottom()) + rowHeight(range.bottom());
1966  if (top > bottom)
1967  qSwap<int>(top, bottom);
1968  int height = bottom - top;
1969  for (int c = range.left(); c <= range.right(); ++c) {
1970  const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height);
1971  if (viewportRect.intersects(rangeRect))
1972  selectionRegion += rangeRect;
1973  }
1974  }
1975  } else if (verticalMoved) {
1976  for (int i = 0; i < selection.count(); ++i) {
1977  QItemSelectionRange range = selection.at(i);
1978  if (range.parent() != d->root || !range.isValid())
1979  continue;
1980  int left = columnViewportPosition(range.left());
1981  int right = columnViewportPosition(range.right()) + columnWidth(range.right());
1982  if (left > right)
1983  qSwap<int>(left, right);
1984  int width = right - left;
1985  for (int r = range.top(); r <= range.bottom(); ++r) {
1986  const QRect rangeRect(left, rowViewportPosition(r), width, rowHeight(r));
1987  if (viewportRect.intersects(rangeRect))
1988  selectionRegion += rangeRect;
1989  }
1990  }
1991  } else { // nothing moved
1992  const int gridAdjust = showGrid() ? 1 : 0;
1993  for (int i = 0; i < selection.count(); ++i) {
1994  QItemSelectionRange range = selection.at(i);
1995  if (range.parent() != d->root || !range.isValid())
1996  continue;
1997  d->trimHiddenSelections(&range);
1998 
1999  const int rtop = rowViewportPosition(range.top());
2000  const int rbottom = rowViewportPosition(range.bottom()) + rowHeight(range.bottom());
2001  int rleft;
2002  int rright;
2003  if (isLeftToRight()) {
2004  rleft = columnViewportPosition(range.left());
2005  rright = columnViewportPosition(range.right()) + columnWidth(range.right());
2006  } else {
2007  rleft = columnViewportPosition(range.right());
2008  rright = columnViewportPosition(range.left()) + columnWidth(range.left());
2009  }
2010  const QRect rangeRect(QPoint(rleft, rtop), QPoint(rright - 1 - gridAdjust, rbottom - 1 - gridAdjust));
2011  if (viewportRect.intersects(rangeRect))
2012  selectionRegion += rangeRect;
2013  if (d->hasSpans()) {
2014  foreach (QSpanCollection::Span *s,
2015  d->spans.spansInRect(range.left(), range.top(), range.width(), range.height())) {
2016  if (range.contains(s->top(), s->left(), range.parent())) {
2017  const QRect &visualSpanRect = d->visualSpanRect(*s);
2018  if (viewportRect.intersects(visualSpanRect))
2019  selectionRegion += visualSpanRect;
2020  }
2021  }
2022  }
2023  }
2024  }
2025 
2026  return selectionRegion;
2027 }
2028 
2029 
2034 {
2035  Q_D(const QTableView);
2036  QModelIndexList viewSelected;
2037  QModelIndexList modelSelected;
2038  if (d->selectionModel)
2039  modelSelected = d->selectionModel->selectedIndexes();
2040  for (int i = 0; i < modelSelected.count(); ++i) {
2041  QModelIndex index = modelSelected.at(i);
2042  if (!isIndexHidden(index) && index.parent() == d->root)
2043  viewSelected.append(index);
2044  }
2045  return viewSelected;
2046 }
2047 
2048 
2054 void QTableView::rowCountChanged(int oldCount, int newCount )
2055 {
2056  Q_D(QTableView);
2057  //when removing rows, we need to disable updates for the header until the geometries have been
2058  //updated and the offset has been adjusted, or we risk calling paintSection for all the sections
2059  if (newCount < oldCount)
2060  d->verticalHeader->setUpdatesEnabled(false);
2061  d->doDelayedItemsLayout();
2062 }
2063 
2070 {
2071  Q_D(QTableView);
2072  updateGeometries();
2074  d->horizontalHeader->setOffsetToSectionPosition(horizontalScrollBar()->value());
2075  else
2076  d->horizontalHeader->setOffset(horizontalScrollBar()->value());
2077  d->viewport->update();
2078 }
2079 
2084 {
2085  Q_D(QTableView);
2086  if (d->geometryRecursionBlock)
2087  return;
2088  d->geometryRecursionBlock = true;
2089 
2090  int width = 0;
2091  if (!d->verticalHeader->isHidden()) {
2092  width = qMax(d->verticalHeader->minimumWidth(), d->verticalHeader->sizeHint().width());
2093  width = qMin(width, d->verticalHeader->maximumWidth());
2094  }
2095  int height = 0;
2096  if (!d->horizontalHeader->isHidden()) {
2097  height = qMax(d->horizontalHeader->minimumHeight(), d->horizontalHeader->sizeHint().height());
2098  height = qMin(height, d->horizontalHeader->maximumHeight());
2099  }
2100  bool reverse = isRightToLeft();
2101  if (reverse)
2102  setViewportMargins(0, height, width, 0);
2103  else
2104  setViewportMargins(width, height, 0, 0);
2105 
2106  // update headers
2107 
2108  QRect vg = d->viewport->geometry();
2109 
2110  int verticalLeft = reverse ? vg.right() + 1 : (vg.left() - width);
2111  d->verticalHeader->setGeometry(verticalLeft, vg.top(), width, vg.height());
2112  if (d->verticalHeader->isHidden())
2113  QMetaObject::invokeMethod(d->verticalHeader, "updateGeometries");
2114 
2115  int horizontalTop = vg.top() - height;
2116  d->horizontalHeader->setGeometry(vg.left(), horizontalTop, vg.width(), height);
2117  if (d->horizontalHeader->isHidden())
2118  QMetaObject::invokeMethod(d->horizontalHeader, "updateGeometries");
2119 
2120  // update cornerWidget
2121  if (d->horizontalHeader->isHidden() || d->verticalHeader->isHidden()) {
2122  d->cornerWidget->setHidden(true);
2123  } else {
2124  d->cornerWidget->setHidden(false);
2125  d->cornerWidget->setGeometry(verticalLeft, horizontalTop, width, height);
2126  }
2127 
2128  // update scroll bars
2129 
2130  // ### move this block into the if
2131  QSize vsize = d->viewport->size();
2132  QSize max = maximumViewportSize();
2133  uint horizontalLength = d->horizontalHeader->length();
2134  uint verticalLength = d->verticalHeader->length();
2135  if ((uint)max.width() >= horizontalLength && (uint)max.height() >= verticalLength)
2136  vsize = max;
2137 
2138  // horizontal scroll bar
2139  const int columnCount = d->horizontalHeader->count();
2140  const int viewportWidth = vsize.width();
2141  int columnsInViewport = 0;
2142  for (int width = 0, column = columnCount - 1; column >= 0; --column) {
2143  int logical = d->horizontalHeader->logicalIndex(column);
2144  if (!d->horizontalHeader->isSectionHidden(logical)) {
2145  width += d->horizontalHeader->sectionSize(logical);
2146  if (width > viewportWidth)
2147  break;
2148  ++columnsInViewport;
2149  }
2150  }
2151  columnsInViewport = qMax(columnsInViewport, 1); //there must be always at least 1 column
2152 
2154  const int visibleColumns = columnCount - d->horizontalHeader->hiddenSectionCount();
2155  horizontalScrollBar()->setRange(0, visibleColumns - columnsInViewport);
2156  horizontalScrollBar()->setPageStep(columnsInViewport);
2157  if (columnsInViewport >= visibleColumns)
2158  d->horizontalHeader->setOffset(0);
2160  } else { // ScrollPerPixel
2162  horizontalScrollBar()->setRange(0, horizontalLength - vsize.width());
2163  horizontalScrollBar()->setSingleStep(qMax(vsize.width() / (columnsInViewport + 1), 2));
2164  }
2165 
2166  // vertical scroll bar
2167  const int rowCount = d->verticalHeader->count();
2168  const int viewportHeight = vsize.height();
2169  int rowsInViewport = 0;
2170  for (int height = 0, row = rowCount - 1; row >= 0; --row) {
2171  int logical = d->verticalHeader->logicalIndex(row);
2172  if (!d->verticalHeader->isSectionHidden(logical)) {
2173  height += d->verticalHeader->sectionSize(logical);
2174  if (height > viewportHeight)
2175  break;
2176  ++rowsInViewport;
2177  }
2178  }
2179  rowsInViewport = qMax(rowsInViewport, 1); //there must be always at least 1 row
2180 
2182  const int visibleRows = rowCount - d->verticalHeader->hiddenSectionCount();
2183  verticalScrollBar()->setRange(0, visibleRows - rowsInViewport);
2184  verticalScrollBar()->setPageStep(rowsInViewport);
2185  if (rowsInViewport >= visibleRows)
2186  d->verticalHeader->setOffset(0);
2188  } else { // ScrollPerPixel
2189  verticalScrollBar()->setPageStep(vsize.height());
2190  verticalScrollBar()->setRange(0, verticalLength - vsize.height());
2191  verticalScrollBar()->setSingleStep(qMax(vsize.height() / (rowsInViewport + 1), 2));
2192  }
2193 
2194  d->geometryRecursionBlock = false;
2196 }
2197 
2212 int QTableView::sizeHintForRow(int row) const
2213 {
2214  Q_D(const QTableView);
2215 
2216  if (!model())
2217  return -1;
2218 
2219  ensurePolished();
2220 
2221  int left = qMax(0, d->horizontalHeader->visualIndexAt(0));
2222  int right = d->horizontalHeader->visualIndexAt(d->viewport->width());
2223  if (right == -1) // the table don't have enough columns to fill the viewport
2224  right = d->model->columnCount(d->root) - 1;
2225 
2226  QStyleOptionViewItemV4 option = d->viewOptionsV4();
2227 
2228  int hint = 0;
2230  for (int column = left; column <= right; ++column) {
2231  int logicalColumn = d->horizontalHeader->logicalIndex(column);
2232  if (d->horizontalHeader->isSectionHidden(logicalColumn))
2233  continue;
2234  index = d->model->index(row, logicalColumn, d->root);
2235  if (d->wrapItemText) {// for wrapping boundaries
2236  option.rect.setY(rowViewportPosition(index.row()));
2237  option.rect.setHeight(rowHeight(index.row()));
2238  option.rect.setX(columnViewportPosition(index.column()));
2239  option.rect.setWidth(columnWidth(index.column()));
2240  }
2241 
2242  QWidget *editor = d->editorForIndex(index).widget.data();
2243  if (editor && d->persistent.contains(editor)) {
2244  hint = qMax(hint, editor->sizeHint().height());
2245  int min = editor->minimumSize().height();
2246  int max = editor->maximumSize().height();
2247  hint = qBound(min, hint, max);
2248  }
2249 
2250  hint = qMax(hint, itemDelegate(index)->sizeHint(option, index).height());
2251  }
2252 
2253  return d->showGrid ? hint + 1 : hint;
2254 }
2255 
2271 int QTableView::sizeHintForColumn(int column) const
2272 {
2273  Q_D(const QTableView);
2274 
2275  if (!model())
2276  return -1;
2277 
2278  ensurePolished();
2279 
2280  int top = qMax(0, d->verticalHeader->visualIndexAt(0));
2281  int bottom = d->verticalHeader->visualIndexAt(d->viewport->height());
2282  if (!isVisible() || bottom == -1) // the table don't have enough rows to fill the viewport
2283  bottom = d->model->rowCount(d->root) - 1;
2284 
2285  QStyleOptionViewItemV4 option = d->viewOptionsV4();
2286 
2287  int hint = 0;
2289  for (int row = top; row <= bottom; ++row) {
2290  int logicalRow = d->verticalHeader->logicalIndex(row);
2291  if (d->verticalHeader->isSectionHidden(logicalRow))
2292  continue;
2293  index = d->model->index(logicalRow, column, d->root);
2294 
2295  QWidget *editor = d->editorForIndex(index).widget.data();
2296  if (editor && d->persistent.contains(editor)) {
2297  hint = qMax(hint, editor->sizeHint().width());
2298  int min = editor->minimumSize().width();
2299  int max = editor->maximumSize().width();
2300  hint = qBound(min, hint, max);
2301  }
2302 
2303  hint = qMax(hint, itemDelegate(index)->sizeHint(option, index).width());
2304  }
2305 
2306  return d->showGrid ? hint + 1 : hint;
2307 }
2308 
2314 {
2315  Q_D(const QTableView);
2316  return d->verticalHeader->sectionViewportPosition(row);
2317 }
2318 
2328 int QTableView::rowAt(int y) const
2329 {
2330  Q_D(const QTableView);
2331  return d->verticalHeader->logicalIndexAt(y);
2332 }
2333 
2343 {
2344  Q_D(const QTableView);
2345  d->verticalHeader->resizeSection(row, height);
2346 }
2347 
2353 int QTableView::rowHeight(int row) const
2354 {
2355  Q_D(const QTableView);
2356  return d->verticalHeader->sectionSize(row);
2357 }
2358 
2364 {
2365  Q_D(const QTableView);
2366  return d->horizontalHeader->sectionViewportPosition(column);
2367 }
2368 
2378 int QTableView::columnAt(int x) const
2379 {
2380  Q_D(const QTableView);
2381  return d->horizontalHeader->logicalIndexAt(x);
2382 }
2383 
2392 void QTableView::setColumnWidth(int column, int width)
2393 {
2394  Q_D(const QTableView);
2395  d->horizontalHeader->resizeSection(column, width);
2396 }
2397 
2403 int QTableView::columnWidth(int column) const
2404 {
2405  Q_D(const QTableView);
2406  return d->horizontalHeader->sectionSize(column);
2407 }
2408 
2414 bool QTableView::isRowHidden(int row) const
2415 {
2416  Q_D(const QTableView);
2417  return d->verticalHeader->isSectionHidden(row);
2418 }
2419 
2425 void QTableView::setRowHidden(int row, bool hide)
2426 {
2427  Q_D(QTableView);
2428  if (row < 0 || row >= d->verticalHeader->count())
2429  return;
2430  d->verticalHeader->setSectionHidden(row, hide);
2431 }
2432 
2438 bool QTableView::isColumnHidden(int column) const
2439 {
2440  Q_D(const QTableView);
2441  return d->horizontalHeader->isSectionHidden(column);
2442 }
2443 
2450 void QTableView::setColumnHidden(int column, bool hide)
2451 {
2452  Q_D(QTableView);
2453  if (column < 0 || column >= d->horizontalHeader->count())
2454  return;
2455  d->horizontalHeader->setSectionHidden(column, hide);
2456 }
2457 
2483 {
2484  Q_D(QTableView);
2485  d->sortingEnabled = enable;
2487  if (enable) {
2488  disconnect(d->horizontalHeader, SIGNAL(sectionEntered(int)),
2489  this, SLOT(_q_selectColumn(int)));
2490  disconnect(horizontalHeader(), SIGNAL(sectionPressed(int)),
2491  this, SLOT(selectColumn(int)));
2492  connect(horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
2493  this, SLOT(sortByColumn(int)), Qt::UniqueConnection);
2494  sortByColumn(horizontalHeader()->sortIndicatorSection(),
2495  horizontalHeader()->sortIndicatorOrder());
2496  } else {
2497  connect(d->horizontalHeader, SIGNAL(sectionEntered(int)),
2498  this, SLOT(_q_selectColumn(int)), Qt::UniqueConnection);
2499  connect(horizontalHeader(), SIGNAL(sectionPressed(int)),
2500  this, SLOT(selectColumn(int)), Qt::UniqueConnection);
2501  disconnect(horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
2502  this, SLOT(sortByColumn(int)));
2503  }
2504 }
2505 
2507 {
2508  Q_D(const QTableView);
2509  return d->sortingEnabled;
2510 }
2511 
2522 bool QTableView::showGrid() const
2523 {
2524  Q_D(const QTableView);
2525  return d->showGrid;
2526 }
2527 
2529 {
2530  Q_D(QTableView);
2531  if (d->showGrid != show) {
2532  d->showGrid = show;
2533  d->viewport->update();
2534  }
2535 }
2536 
2547 {
2548  Q_D(const QTableView);
2549  return d->gridStyle;
2550 }
2551 
2553 {
2554  Q_D(QTableView);
2555  if (d->gridStyle != style) {
2556  d->gridStyle = style;
2557  d->viewport->update();
2558  }
2559 }
2560 
2579 {
2580  Q_D(QTableView);
2581  if (d->wrapItemText == on)
2582  return;
2583  d->wrapItemText = on;
2584  QMetaObject::invokeMethod(d->verticalHeader, "resizeSections");
2585  QMetaObject::invokeMethod(d->horizontalHeader, "resizeSections");
2586 }
2587 
2588 bool QTableView::wordWrap() const
2589 {
2590  Q_D(const QTableView);
2591  return d->wrapItemText;
2592 }
2593 
2609 {
2610  Q_D(QTableView);
2611  d->cornerWidget->setEnabled(enable);
2612 }
2613 
2615 {
2616  Q_D(const QTableView);
2617  return d->cornerWidget->isEnabled();
2618 }
2619 
2631 {
2632  Q_D(const QTableView);
2633  if (!d->isIndexValid(index) || index.parent() != d->root
2634  || (!d->hasSpans() && isIndexHidden(index)))
2635  return QRect();
2636 
2637  d->executePostedLayout();
2638 
2639  if (d->hasSpans()) {
2640  QSpanCollection::Span span = d->span(index.row(), index.column());
2641  return d->visualSpanRect(span);
2642  }
2643 
2644  int rowp = rowViewportPosition(index.row());
2645  int rowh = rowHeight(index.row());
2646  int colp = columnViewportPosition(index.column());
2647  int colw = columnWidth(index.column());
2648 
2649  const int i = showGrid() ? 1 : 0;
2650  return QRect(colp, rowp, colw - i, rowh - i);
2651 }
2652 
2663 {
2664  Q_D(QTableView);
2665 
2666  // check if we really need to do anything
2667  if (!d->isIndexValid(index)
2668  || (d->model->parent(index) != d->root)
2669  || isRowHidden(index.row()) || isColumnHidden(index.column()))
2670  return;
2671 
2672  QSpanCollection::Span span;
2673  if (d->hasSpans())
2674  span = d->span(index.row(), index.column());
2675 
2676  // Adjust horizontal position
2677 
2678  int viewportWidth = d->viewport->width();
2679  int horizontalOffset = d->horizontalHeader->offset();
2680  int horizontalPosition = d->horizontalHeader->sectionPosition(index.column());
2681  int horizontalIndex = d->horizontalHeader->visualIndex(index.column());
2682  int cellWidth = d->hasSpans()
2683  ? d->columnSpanWidth(index.column(), span.width())
2684  : d->horizontalHeader->sectionSize(index.column());
2685 
2687 
2688  bool positionAtLeft = (horizontalPosition - horizontalOffset < 0);
2689  bool positionAtRight = (horizontalPosition - horizontalOffset + cellWidth > viewportWidth);
2690 
2691  if (hint == PositionAtCenter || positionAtRight) {
2692  int w = (hint == PositionAtCenter ? viewportWidth / 2 : viewportWidth);
2693  int x = cellWidth;
2694  while (horizontalIndex > 0) {
2695  x += columnWidth(d->horizontalHeader->logicalIndex(horizontalIndex-1));
2696  if (x > w)
2697  break;
2698  --horizontalIndex;
2699  }
2700  }
2701 
2702  if (positionAtRight || hint == PositionAtCenter || positionAtLeft) {
2703  int hiddenSections = 0;
2704  if (d->horizontalHeader->sectionsHidden()) {
2705  for (int s = horizontalIndex - 1; s >= 0; --s) {
2706  int column = d->horizontalHeader->logicalIndex(s);
2707  if (d->horizontalHeader->isSectionHidden(column))
2708  ++hiddenSections;
2709  }
2710  }
2711  horizontalScrollBar()->setValue(horizontalIndex - hiddenSections);
2712  }
2713 
2714  } else { // ScrollPerPixel
2715  if (hint == PositionAtCenter) {
2716  horizontalScrollBar()->setValue(horizontalPosition - ((viewportWidth - cellWidth) / 2));
2717  } else {
2718  if (horizontalPosition - horizontalOffset < 0 || cellWidth > viewportWidth)
2719  horizontalScrollBar()->setValue(horizontalPosition);
2720  else if (horizontalPosition - horizontalOffset + cellWidth > viewportWidth)
2721  horizontalScrollBar()->setValue(horizontalPosition - viewportWidth + cellWidth);
2722  }
2723  }
2724 
2725  // Adjust vertical position
2726 
2727  int viewportHeight = d->viewport->height();
2728  int verticalOffset = d->verticalHeader->offset();
2729  int verticalPosition = d->verticalHeader->sectionPosition(index.row());
2730  int verticalIndex = d->verticalHeader->visualIndex(index.row());
2731  int cellHeight = d->hasSpans()
2732  ? d->rowSpanHeight(index.row(), span.height())
2733  : d->verticalHeader->sectionSize(index.row());
2734 
2735  if (verticalPosition - verticalOffset < 0 || cellHeight > viewportHeight) {
2736  if (hint == EnsureVisible)
2737  hint = PositionAtTop;
2738  } else if (verticalPosition - verticalOffset + cellHeight > viewportHeight) {
2739  if (hint == EnsureVisible)
2740  hint = PositionAtBottom;
2741  }
2742 
2744 
2745  if (hint == PositionAtBottom || hint == PositionAtCenter) {
2746  int h = (hint == PositionAtCenter ? viewportHeight / 2 : viewportHeight);
2747  int y = cellHeight;
2748  while (verticalIndex > 0) {
2749  int row = d->verticalHeader->logicalIndex(verticalIndex - 1);
2750  y += d->verticalHeader->sectionSize(row);
2751  if (y > h)
2752  break;
2753  --verticalIndex;
2754  }
2755  }
2756 
2757  if (hint == PositionAtBottom || hint == PositionAtCenter || hint == PositionAtTop) {
2758  int hiddenSections = 0;
2759  if (d->verticalHeader->sectionsHidden()) {
2760  for (int s = verticalIndex - 1; s >= 0; --s) {
2761  int row = d->verticalHeader->logicalIndex(s);
2762  if (d->verticalHeader->isSectionHidden(row))
2763  ++hiddenSections;
2764  }
2765  }
2766  verticalScrollBar()->setValue(verticalIndex - hiddenSections);
2767  }
2768 
2769  } else { // ScrollPerPixel
2770  if (hint == PositionAtTop) {
2771  verticalScrollBar()->setValue(verticalPosition);
2772  } else if (hint == PositionAtBottom) {
2773  verticalScrollBar()->setValue(verticalPosition - viewportHeight + cellHeight);
2774  } else if (hint == PositionAtCenter) {
2775  verticalScrollBar()->setValue(verticalPosition - ((viewportHeight - cellHeight) / 2));
2776  }
2777  }
2778 
2779  update(index);
2780 }
2781 
2789 void QTableView::rowResized(int row, int, int)
2790 {
2791  Q_D(QTableView);
2792  d->rowsToUpdate.append(row);
2793  if (d->rowResizeTimerID == 0)
2794  d->rowResizeTimerID = startTimer(0);
2795 }
2796 
2804 void QTableView::columnResized(int column, int, int)
2805 {
2806  Q_D(QTableView);
2807  d->columnsToUpdate.append(column);
2808  if (d->columnResizeTimerID == 0)
2809  d->columnResizeTimerID = startTimer(0);
2810 }
2811 
2816 {
2817  Q_D(QTableView);
2818 
2819  if (event->timerId() == d->columnResizeTimerID) {
2820  updateGeometries();
2821  killTimer(d->columnResizeTimerID);
2822  d->columnResizeTimerID = 0;
2823 
2824  QRect rect;
2825  int viewportHeight = d->viewport->height();
2826  int viewportWidth = d->viewport->width();
2827  if (d->hasSpans()) {
2828  rect = QRect(0, 0, viewportWidth, viewportHeight);
2829  } else {
2830  for (int i = d->columnsToUpdate.size()-1; i >= 0; --i) {
2831  int column = d->columnsToUpdate.at(i);
2832  int x = columnViewportPosition(column);
2833  if (isRightToLeft())
2834  rect |= QRect(0, 0, x + columnWidth(column), viewportHeight);
2835  else
2836  rect |= QRect(x, 0, viewportWidth - x, viewportHeight);
2837  }
2838  }
2839 
2840  d->viewport->update(rect.normalized());
2841  d->columnsToUpdate.clear();
2842  }
2843 
2844  if (event->timerId() == d->rowResizeTimerID) {
2845  updateGeometries();
2846  killTimer(d->rowResizeTimerID);
2847  d->rowResizeTimerID = 0;
2848 
2849  int viewportHeight = d->viewport->height();
2850  int viewportWidth = d->viewport->width();
2851  int top;
2852  if (d->hasSpans()) {
2853  top = 0;
2854  } else {
2855  top = viewportHeight;
2856  for (int i = d->rowsToUpdate.size()-1; i >= 0; --i) {
2857  int y = rowViewportPosition(d->rowsToUpdate.at(i));
2858  top = qMin(top, y);
2859  }
2860  }
2861 
2862  d->viewport->update(QRect(0, top, viewportWidth, viewportHeight - top));
2863  d->rowsToUpdate.clear();
2864  }
2865 
2867 }
2868 
2876 void QTableView::rowMoved(int, int oldIndex, int newIndex)
2877 {
2878  Q_D(QTableView);
2879 
2880  updateGeometries();
2881  int logicalOldIndex = d->verticalHeader->logicalIndex(oldIndex);
2882  int logicalNewIndex = d->verticalHeader->logicalIndex(newIndex);
2883  if (d->hasSpans()) {
2884  d->viewport->update();
2885  } else {
2886  int oldTop = rowViewportPosition(logicalOldIndex);
2887  int newTop = rowViewportPosition(logicalNewIndex);
2888  int oldBottom = oldTop + rowHeight(logicalOldIndex);
2889  int newBottom = newTop + rowHeight(logicalNewIndex);
2890  int top = qMin(oldTop, newTop);
2891  int bottom = qMax(oldBottom, newBottom);
2892  int height = bottom - top;
2893  d->viewport->update(0, top, d->viewport->width(), height);
2894  }
2895 }
2896 
2904 void QTableView::columnMoved(int, int oldIndex, int newIndex)
2905 {
2906  Q_D(QTableView);
2907 
2908  updateGeometries();
2909  int logicalOldIndex = d->horizontalHeader->logicalIndex(oldIndex);
2910  int logicalNewIndex = d->horizontalHeader->logicalIndex(newIndex);
2911  if (d->hasSpans()) {
2912  d->viewport->update();
2913  } else {
2914  int oldLeft = columnViewportPosition(logicalOldIndex);
2915  int newLeft = columnViewportPosition(logicalNewIndex);
2916  int oldRight = oldLeft + columnWidth(logicalOldIndex);
2917  int newRight = newLeft + columnWidth(logicalNewIndex);
2918  int left = qMin(oldLeft, newLeft);
2919  int right = qMax(oldRight, newRight);
2920  int width = right - left;
2921  d->viewport->update(left, 0, width, d->viewport->height());
2922  }
2923 }
2924 
2932 {
2933  Q_D(QTableView);
2934  d->selectRow(row, true);
2935 }
2936 
2944 {
2945  Q_D(QTableView);
2946  d->selectColumn(column, true);
2947 }
2948 
2954 void QTableView::hideRow(int row)
2955 {
2956  Q_D(QTableView);
2957  d->verticalHeader->hideSection(row);
2958 }
2959 
2965 void QTableView::hideColumn(int column)
2966 {
2967  Q_D(QTableView);
2968  d->horizontalHeader->hideSection(column);
2969 }
2970 
2976 void QTableView::showRow(int row)
2977 {
2978  Q_D(QTableView);
2979  d->verticalHeader->showSection(row);
2980 }
2981 
2987 void QTableView::showColumn(int column)
2988 {
2989  Q_D(QTableView);
2990  d->horizontalHeader->showSection(column);
2991 }
2992 
2998 {
2999  Q_D(QTableView);
3000  int content = sizeHintForRow(row);
3001  int header = d->verticalHeader->sectionSizeHint(row);
3002  d->verticalHeader->resizeSection(row, qMax(content, header));
3003 }
3004 
3010 {
3011  Q_D(QTableView);
3012  d->verticalHeader->resizeSections(QHeaderView::ResizeToContents);
3013 }
3014 
3023 {
3024  Q_D(QTableView);
3025  int content = sizeHintForColumn(column);
3026  int header = d->horizontalHeader->sectionSizeHint(column);
3027  d->horizontalHeader->resizeSection(column, qMax(content, header));
3028 }
3029 
3035 {
3036  Q_D(QTableView);
3037  d->horizontalHeader->resizeSections(QHeaderView::ResizeToContents);
3038 }
3039 
3050 {
3051  Q_D(QTableView);
3052  if (column == -1)
3053  return;
3054  d->model->sort(column, d->horizontalHeader->sortIndicatorOrder());
3055 }
3056 
3068 {
3069  Q_D(QTableView);
3070  d->horizontalHeader->setSortIndicator(column, order);
3071  sortByColumn(column);
3072 }
3073 
3078 {
3080 }
3081 
3086 {
3088 }
3089 
3094 {
3095  Q_D(const QTableView);
3096  Q_ASSERT(d->isIndexValid(index));
3097  if (isRowHidden(index.row()) || isColumnHidden(index.column()))
3098  return true;
3099  if (d->hasSpans()) {
3100  QSpanCollection::Span span = d->span(index.row(), index.column());
3101  return !((span.top() == index.row()) && (span.left() == index.column()));
3102  }
3103  return false;
3104 }
3105 
3118 void QTableView::setSpan(int row, int column, int rowSpan, int columnSpan)
3119 {
3120  Q_D(QTableView);
3121  if (row < 0 || column < 0 || rowSpan < 0 || columnSpan < 0)
3122  return;
3123  d->setSpan(row, column, rowSpan, columnSpan);
3124  d->viewport->update();
3125 }
3126 
3138 int QTableView::rowSpan(int row, int column) const
3139 {
3140  Q_D(const QTableView);
3141  return d->rowSpan(row, column);
3142 }
3143 
3155 int QTableView::columnSpan(int row, int column) const
3156 {
3157  Q_D(const QTableView);
3158  return d->columnSpan(row, column);
3159 }
3160 
3173 {
3174  Q_D(QTableView);
3175  d->spans.clear();
3176  d->viewport->update();
3177 }
3178 
3180 {
3181  selectRow(row, false);
3182 }
3183 
3185 {
3186  selectColumn(column, false);
3187 }
3188 
3189 void QTableViewPrivate::selectRow(int row, bool anchor)
3190 {
3191  Q_Q(QTableView);
3192 
3193  if (q->selectionBehavior() == QTableView::SelectColumns
3194  || (q->selectionMode() == QTableView::SingleSelection
3195  && q->selectionBehavior() == QTableView::SelectItems))
3196  return;
3197 
3198  if (row >= 0 && row < model->rowCount(root)) {
3199  int column = horizontalHeader->logicalIndexAt(q->isRightToLeft() ? viewport->width() : 0);
3200  QModelIndex index = model->index(row, column, root);
3201  QItemSelectionModel::SelectionFlags command = q->selectionCommand(index);
3203  if ((anchor && !(command & QItemSelectionModel::Current))
3204  || (q->selectionMode() == QTableView::SingleSelection))
3205  rowSectionAnchor = row;
3206 
3207  if (q->selectionMode() != QTableView::SingleSelection
3208  && command.testFlag(QItemSelectionModel::Toggle)) {
3209  if (anchor)
3210  ctrlDragSelectionFlag = verticalHeader->selectionModel()->selectedRows().contains(index)
3212  command &= ~QItemSelectionModel::Toggle;
3213  command |= ctrlDragSelectionFlag;
3214  if (!anchor)
3215  command |= QItemSelectionModel::Current;
3216  }
3217 
3218  QModelIndex tl = model->index(qMin(rowSectionAnchor, row), 0, root);
3219  QModelIndex br = model->index(qMax(rowSectionAnchor, row), model->columnCount(root) - 1, root);
3220  if (verticalHeader->sectionsMoved() && tl.row() != br.row())
3221  q->setSelection(q->visualRect(tl)|q->visualRect(br), command);
3222  else
3223  selectionModel->select(QItemSelection(tl, br), command);
3224  }
3225 }
3226 
3227 void QTableViewPrivate::selectColumn(int column, bool anchor)
3228 {
3229  Q_Q(QTableView);
3230 
3231  if (q->selectionBehavior() == QTableView::SelectRows
3232  || (q->selectionMode() == QTableView::SingleSelection
3233  && q->selectionBehavior() == QTableView::SelectItems))
3234  return;
3235 
3236  if (column >= 0 && column < model->columnCount(root)) {
3237  int row = verticalHeader->logicalIndexAt(0);
3238  QModelIndex index = model->index(row, column, root);
3239  QItemSelectionModel::SelectionFlags command = q->selectionCommand(index);
3241  if ((anchor && !(command & QItemSelectionModel::Current))
3242  || (q->selectionMode() == QTableView::SingleSelection))
3243  columnSectionAnchor = column;
3244 
3245  if (q->selectionMode() != QTableView::SingleSelection
3246  && command.testFlag(QItemSelectionModel::Toggle)) {
3247  if (anchor)
3248  ctrlDragSelectionFlag = horizontalHeader->selectionModel()->selectedColumns().contains(index)
3250  command &= ~QItemSelectionModel::Toggle;
3251  command |= ctrlDragSelectionFlag;
3252  if (!anchor)
3253  command |= QItemSelectionModel::Current;
3254  }
3255 
3256  QModelIndex tl = model->index(0, qMin(columnSectionAnchor, column), root);
3257  QModelIndex br = model->index(model->rowCount(root) - 1,
3258  qMax(columnSectionAnchor, column), root);
3259  if (horizontalHeader->sectionsMoved() && tl.column() != br.column())
3260  q->setSelection(q->visualRect(tl)|q->visualRect(br), command);
3261  else
3262  selectionModel->select(QItemSelection(tl, br), command);
3263  }
3264 }
3265 
3269 void QTableView::currentChanged(const QModelIndex &current, const QModelIndex &previous)
3270 {
3271 #ifndef QT_NO_ACCESSIBILITY
3272  if (QAccessible::isActive()) {
3273  if (current.isValid()) {
3274 #ifdef Q_WS_X11
3275  Q_D(QTableView);
3276  int entry = d->accessibleTable2Index(current);
3278 #else
3279  int entry = visualIndex(current) + 1;
3280  if (horizontalHeader())
3281  ++entry;
3283 #endif
3284  }
3285  }
3286 #endif
3287  QAbstractItemView::currentChanged(current, previous);
3288 }
3289 
3294  const QItemSelection &deselected)
3295 {
3296 #ifndef QT_NO_ACCESSIBILITY
3297  Q_D(QTableView);
3298  Q_UNUSED(d)
3299  if (QAccessible::isActive()) {
3300  // ### does not work properly for selection ranges.
3301  QModelIndex sel = selected.indexes().value(0);
3302  if (sel.isValid()) {
3303 #ifdef Q_WS_X11
3304  int entry = d->accessibleTable2Index(sel);
3306 #else
3307  int entry = visualIndex(sel);
3308  if (horizontalHeader())
3309  ++entry;
3311 #endif
3312  }
3313  QModelIndex desel = deselected.indexes().value(0);
3314  if (desel.isValid()) {
3315 #ifdef Q_WS_X11
3316  int entry = d->accessibleTable2Index(desel);
3318 #else
3319  int entry = visualIndex(sel);
3320  if (horizontalHeader())
3321  ++entry;
3323 #endif
3324  }
3325  }
3326 #endif
3327  QAbstractItemView::selectionChanged(selected, deselected);
3328 }
3329 
3331 {
3332  return index.row();
3333 }
3334 
3336 
3337 #include "qtableview.moc"
3338 
3339 #include "moc_qtableview.cpp"
3340 
3341 #endif // QT_NO_TABLEVIEW
void addSpan(Span *span)
Definition: qtableview.cpp:65
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
QModelIndexList selectedRows(int column=0) const
Returns the indexes in the given column for the rows where all columns are selected.
QPoint pos() const
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
void clear()
Removes all the items in the list.
Definition: qlinkedlist.h:311
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
QSize maximumSize
the widget&#39;s maximum size in pixels
Definition: qwidget.h:173
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
QTableCornerButton(QWidget *parent)
Definition: qtableview.cpp:596
QSize minimumSize
the widget&#39;s minimum size
Definition: qwidget.h:172
void setViewportMargins(int left, int top, int right, int bottom)
Sets the margins around the scrolling area to left, top, right and bottom.
void trimHiddenSelections(QItemSelectionRange *range) const
Trims away indices that are hidden in the treeview due to hidden horizontal or vertical sections...
Definition: qtableview.cpp:645
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
const Key & key() const
Returns the current item&#39;s key as a const reference.
Definition: qmap.h:250
iterator erase(iterator pos)
Removes the item pointed to by the iterator pos from the list, and returns an iterator to the next it...
Definition: qlinkedlist.h:470
bool isIndexHidden(const QModelIndex &index) const
Reimplemented Function
bool isColumnHidden(int column) const
Returns true if the given column is hidden; otherwise returns false.
unsigned int QRgb
Definition: qrgb.h:53
static QAbstractItemModel * staticEmptyModel()
void hideColumn(int column)
Hide the given column.
int columnAt(int x) const
Returns the column in which the given x-coordinate, x, in contents coordinates is located...
The QItemSelectionModel class keeps track of a view&#39;s selected items.
void sortByColumn(int column, Qt::SortOrder order)
Sorts the model by the values in the given column in the given order.
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
int left() const
Returns the column index corresponding to the leftmost selected column in the selection range...
int y() const
void setBottom(int pos)
Sets the bottom edge of the rectangle to the given y coordinate.
Definition: qrect.h:267
unsigned char c[8]
Definition: qnumeric_p.h:62
void setSpan(int row, int column, int rowSpan, int columnSpan)
Sets the span for the cell at (row, column).
Definition: qtableview.cpp:686
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void setBit(int i)
Sets the bit at index position i to 1.
Definition: qbitarray.h:128
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual QStyleOptionViewItem viewOptions() const
Returns a QStyleOptionViewItem structure populated with the view&#39;s palette, font, state...
virtual void setSelectionModel(QItemSelectionModel *selectionModel)
Sets the current selection model to the given selectionModel.
int rowSpan(int row, int column) const
Returns the row span of the table element at (row, column).
ScrollMode horizontalScrollMode() const
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
QRect visualSpanRect(const QSpanCollection::Span &span) const
Returns the visual rect for the given span.
Definition: qtableview.cpp:797
int columnWidth(int column) const
Returns the width of the given column.
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
int columnViewportPosition(int column) const
Returns the x-coordinate in contents coordinates of the given column.
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
#define it(className, varName)
The QStyleOptionHeader class is used to describe the parameters for drawing a header.
Definition: qstyleoption.h:251
void setHighlightSections(bool highlight)
void currentChanged(const QModelIndex &current, const QModelIndex &previous)
Reimplemented Function
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
Span * spanAt(int x, int y) const
Definition: qtableview.cpp:142
bool isVisible() const
Definition: qwidget.h:1005
void showRow(int row)
Show the given row.
void updateRemovedColumns(int start, int end)
Definition: qtableview.cpp:470
void setModel(QAbstractItemModel *model)
Reimplemented Function
bool isValid() const
Returns true if the selection range is valid; otherwise returns false.
int sizeHintForRow(int row) const
Returns the size hint for the given row&#39;s height or -1 if there is no model.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
virtual void setRootIndex(const QModelIndex &index)
Sets the root item to the item at the given index.
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlinkedlist.h:182
bool remove(const T &value)
Definition: qset.h:89
static C reverse(const C &l)
void _q_selectColumn(int column)
void resizeRowsToContents()
Resizes all rows based on the size hints of the delegate used to render each item in the rows...
void updateSpan(Span *span, int old_height)
Definition: qtableview.cpp:103
#define SLOT(a)
Definition: qobjectdefs.h:226
QRect visualRect(const QModelIndex &index) const
Returns the rectangle on the viewport occupied by the given index.
void resizeColumnsToContents()
Resizes all columns based on the size hints of the delegate used to render each item in the columns...
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
QRect normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:322
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlinkedlist.h:103
QHeaderView * horizontalHeader() const
Returns the table view&#39;s horizontal header.
The QItemSelectionRange class manages information about a range of selected items in a model...
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
void updateInsertedColumns(int start, int end)
Definition: qtableview.cpp:258
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
void setRootIndex(const QModelIndex &index)
Reimplemented Function
void timerEvent(QTimerEvent *event)
This function is called with the given event when a timer event is sent to the widget.
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
bool removeOne(const T &t)
Removes the first occurrences of value in the list.
Definition: qlinkedlist.h:397
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
void init(const QWidget *w)
Use initFrom(widget) instead.
void rowResized(int row, int oldHeight, int newHeight)
This slot is called to change the height of the given row.
int rowViewportPosition(int row) const
Returns the y-coordinate in contents coordinates of the given row.
int bottom() const
Returns the row index corresponding to the lowermost selected row in the selection range...
const Key & key() const
Returns the current item&#39;s key.
Definition: qmap.h:324
void _q_updateSpanInsertedRows(const QModelIndex &parent, int start, int end)
Updates spans after row insertion.
Definition: qtableview.cpp:891
void append(const T &)
Inserts value at the end of the list.
Definition: qlinkedlist.h:350
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
virtual void verticalScrollbarAction(int action)
int right() const
Returns the column index corresponding to the rightmost selected column in the selection range...
iterator find(const Key &key)
Returns an iterator pointing to the item with key key in the map.
Definition: qmap.h:618
void drawLine(const QLineF &line)
Draws a line defined by line.
Definition: qpainter.h:573
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void setY(int y)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:285
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
QAbstractItemDelegate * itemDelegate() const
Returns the item delegate used by this view and model.
void columnResized(int column, int oldWidth, int newWidth)
This slot is called to change the width of the given column.
virtual void doItemsLayout()
This function is intended to lay out the items in the view.
void setGridStyle(Qt::PenStyle style)
bool isEmpty() const
Returns true if the selection range contains no selectable item.
QList< Span * > spansInRect(int x, int y, int w, int h) const
Definition: qtableview.cpp:170
void selectRow(int row, bool anchor)
bool testBit(int i) const
Returns true if the bit at index position i is 1; otherwise returns false.
Definition: qbitarray.h:124
bool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlinkedlist.h:425
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void horizontalScrollbarAction(int action)
int rowAt(int y) const
Returns the row in which the given y-coordinate, y, in contents coordinates is located.
#define Q_D(Class)
Definition: qglobal.h:2482
int height() const
bool sectionsMoved() const
Returns true if sections in the header has been moved; otherwise returns false;.
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
QModelIndex parent() const
Returns the parent model item index of the items in the selection range.
bool isSectionHidden(int logicalIndex) const
Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise r...
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
PenStyle
Definition: qnamespace.h:1134
QTableView(QWidget *parent=0)
Constructs a table view with a parent to represent the data.
void paintEvent(QPaintEvent *)
Reimplemented Function
Definition: qtableview.cpp:597
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
bool showGrid() const
void setRange(int min, int max)
Sets the slider&#39;s minimum to min and its maximum to max.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QStyle * style() const
Definition: qwidget.cpp:2742
#define Q_Q(Class)
Definition: qglobal.h:2483
The QStyleOptionViewItemV2 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:562
ColorGroup
Definition: qpalette.h:92
void setHorizontalHeader(QHeaderView *header)
Sets the widget to use for the horizontal header to header.
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition: qwidget.h:1008
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qmap.h:251
void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Sets the model item index to be the current item, and emits currentChanged().
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
int width() const
Returns the number of selected columns in the selection range.
QWidget * viewport() const
Returns the viewport widget.
Q_CORE_EXPORT void qDebug(const char *,...)
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
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...
void setCurrentColorGroup(ColorGroup cg)
Set the palette&#39;s current color group to cg.
Definition: qpalette.h:105
int rowHeight(int row) const
Returns the height of the given row.
void resizeColumnToContents(int column)
Resizes the given column based on the size hints of the delegate used to render each item in the colu...
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QLinkedList class is a template class that provides linked lists.
Definition: qdatastream.h:63
int width() const
Returns the width.
Definition: qsize.h:126
SortOrder
Definition: qnamespace.h:189
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void selectColumn(int column, bool anchor)
void scrollContentsBy(int dx, int dy)
Scroll the contents of the table view by (dx, dy).
bool sectionsHidden() const
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int offset() const
Returns the offset of the header: this is the header&#39;s left-most (or top-most for vertical headers) v...
ViewItemFeatures features
a bitwise OR of the features that describe this view item
Definition: qstyleoption.h:577
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
QStyleOptionViewItem viewOptions() const
Reimplemented Function
ScrollMode verticalScrollMode() const
void setClickable(bool clickable)
If clickable is true, the header will respond to single clicks.
~QTableView()
Destroys the table view.
void setVerticalHeader(QHeaderView *header)
Sets the widget to use for the vertical header to header.
void hideRow(int row)
Hide the given row.
bool wordWrap() const
QList< T > toList() const
Definition: qset.h:296
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QItemSelectionModel * selectionModel() const
Returns the current selection model.
void clearSpans()
Removes all row and column spans in the table view.
int width() const
int row() const
Returns the row this model index refers to.
void setCornerButtonEnabled(bool enable)
void verticalScrollbarAction(int action)
void updateInsertedRows(int start, int end)
Definition: qtableview.cpp:208
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void showColumn(int column)
Show the given column.
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous)
This slot is called when a new item becomes the current item.
void drawCell(QPainter *painter, const QStyleOptionViewItemV4 &option, const QModelIndex &index)
Draws a table cell.
Definition: qtableview.cpp:943
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:264
void _q_updateSpanInsertedColumns(const QModelIndex &parent, int start, int end)
Updates spans after column insertion.
Definition: qtableview.cpp:904
Q_CORE_EXPORT void qWarning(const char *,...)
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
bool showDecorationSelected
whether the decoration should be highlighted on selected items
Definition: qstyleoption.h:553
unsigned int uint
Definition: qglobal.h:996
void setShowGrid(bool show)
QHeaderView * verticalHeader() const
Returns the table view&#39;s vertical header.
QModelIndex currentIndex() const
Returns the model index of the current item.
The QLinkedList::iterator class provides an STL-style non-const iterator for QLinkedList.
Definition: qlinkedlist.h:118
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
void selectRow(int row)
Selects the given row in the table view if the current SelectionMode and SelectionBehavior allows row...
void setRowHeight(int row, int height)
Sets the height of the given row to be height.
void updateRemovedRows(int start, int end)
Definition: qtableview.cpp:341
void show()
Shows the widget and its child widgets.
int length() const
Returns the length along the orientation of the header.
void columnMoved(int column, int oldIndex, int newIndex)
This slot is called to change the index of the given column in the table view.
The QTableView class provides a default model/view implementation of a table view.
Definition: qtableview.h:58
void setX(int x)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:282
bool contains(const QModelIndex &index) const
Returns true if the model item specified by the index lies within the range of selected items; otherw...
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
bool cleanSpanSubIndex(SubIndex &subindex, int end, bool update=false)
Definition: qtableview.cpp:312
QRect rect() const
#define Q_OBJECT
Definition: qobjectdefs.h:157
void timerEvent(QTimerEvent *event)
Reimplemented Function
void hide()
Hides the widget.
Definition: qwidget.h:501
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void drawAndClipSpans(const QRegion &area, QPainter *painter, const QStyleOptionViewItemV4 &option, QBitArray *drawn, int firstVisualRow, int lastVisualRow, int firstVisualColumn, int lastVisualColumn)
Draws the spanning cells within rect area, and clips them off as preparation for the main drawing loo...
Definition: qtableview.cpp:826
The QAbstractItemModel class provides the abstract interface for item model classes.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlinkedlist.h:185
friend class iterator
Definition: qmap.h:299
static bool isActive()
Returns true if an accessibility implementation has been requested during the runtime of the applicat...
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
bool isCornerButtonEnabled() const
The QBitArray class provides an array of bits.
Definition: qbitarray.h:54
void setColumnWidth(int column, int width)
Sets the width of the given column to be width.
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This slot is called when the selection is changed.
void paintEvent(QPaintEvent *e)
Paints the table on receipt of the given paint event event.
SectionPosition position
the section&#39;s position in relation to the other sections
Definition: qstyleoption.h:267
The QAbstractItemView class provides the basic functionality for item view classes.
QSize maximumViewportSize() const
Returns the size of the viewport as if the scroll bars had no valid scrolling range.
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
Definition: qmap.h:301
QSpanCollection::Span span(int row, int column) const
Gets the span information for the cell at (row, column).
Definition: qtableview.cpp:721
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
The QItemSelection class manages information about selected items in a model.
int visualIndex(const QModelIndex &index) const
int visualIndexAt(int position) const
Returns the visual index of the section that covers the given position in the viewport.
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
Definition: qpainter.cpp:2917
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
int sectionSpanEndLogical(const QHeaderView *header, int logical, int span) const
Returns the logical index of the last section that&#39;s part of the span.
Definition: qtableview.cpp:737
int x() const
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
QModelIndexList selectedColumns(int row=0) const
Returns the indexes in the given row for columns where all rows are selected.
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
Definition: qmap.h:233
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
void setWordWrap(bool on)
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:258
State
Definition: qaudio.h:59
int height() const
Returns the number of selected rows in the selection range.
void setSortIndicatorShown(bool show)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().
int columnSpan(int row, int column) const
Returns the column span of the table element at (row, column).
void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)
Makes sure that the given item is visible in the table view, scrolling if necessary.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void setSelectionModel(QItemSelectionModel *selectionModel)
Reimplemented Function
void setSpan(int row, int column, int rowSpan, int columnSpan)
Sets the span of the table element at (row, column) to the number of rows and columns specified by (r...
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setRowHidden(int row, bool hide)
If hide is true row will be hidden, otherwise it will be shown.
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
The QModelIndex class is used to locate data in a data model.
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
Definition: qmap.h:203
int count() const
Returns the number of sections in the header.
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
void resizeRowToContents(int row)
Resizes the given row based on the size hints of the delegate used to render each item in the row...
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
int sectionSize(int logicalIndex) const
Returns the width (or height for vertical headers) of the given logicalIndex.
int height() const
Returns the height.
Definition: qsize.h:129
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QFactoryLoader * l
const T & value() const
Returns the current item&#39;s value.
Definition: qmap.h:325
void rowMoved(int row, int oldIndex, int newIndex)
This slot is called to change the index of the given row in the table view.
void doItemsLayout()
bool isRowHidden(int row) const
Returns true if the given row is hidden; otherwise returns false.
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
Moves the cursor in accordance with the given cursorAction, using the information provided by the mod...
void updateGeometries()
Reimplemented Function
void columnCountChanged(int oldCount, int newCount)
This slot is called whenever columns are added or deleted.
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
quint16 index
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
This slot is called when rows are inserted.
bool intersects(const QRegion &r) const
Returns true if this region intersects with region, otherwise returns false.
Definition: qregion.cpp:766
int verticalOffset() const
Returns the vertical offset of the items in the table view.
virtual void updateGeometries()
Updates the geometry of the child widgets of the view.
bool isLeftToRight() const
Definition: qwidget.h:429
int top() const
Returns the row index corresponding to the uppermost selected row in the selection range...
void setSortingEnabled(bool enable)
If enabled true enables sorting for the table and immediately trigger a call to sortByColumn() with t...
void _q_updateSpanRemovedColumns(const QModelIndex &parent, int start, int end)
Updates spans after column removal.
Definition: qtableview.cpp:930
QDataStream & operator<<(QDataStream &s, const QAxBase &c)
Definition: qaxbase.h:203
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
Applies the selection flags to the items in or touched by the rectangle, rect.
iterator erase(iterator it)
Removes the (key, value) pair pointed to by the iterator pos from the map, and returns an iterator to...
Definition: qmap.h:717
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
QRegion visualRegionForSelection(const QItemSelection &selection) const
Returns the rectangle from the viewport of the items in the given selection.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QSize sizeHint
the recommended size for the widget
Definition: qwidget.h:195
void _q_selectRow(int row)
QRegion translated(int dx, int dy) const
Returns a copy of the region that is translated dx along the x axis and dy along the y axis...
Definition: qregion.cpp:743
bool isRightToLeft() const
Definition: qwidget.h:428
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
int horizontalOffset() const
Returns the horizontal offset of the items in the table view.
iterator lowerBound(const Key &key)
Returns an iterator pointing to the first item with key key in the map.
Definition: qmap.h:899
CursorAction
This enum describes the different ways to navigate between items,.
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
bool spanContainsSection(const QHeaderView *header, int logical, int spanLogical, int span) const
Returns true if the section at logical index logical is part of the span starting at logical index sp...
Definition: qtableview.cpp:774
int sectionPosition(int logicalIndex) const
Returns the section position of the given logicalIndex, or -1 if the section is hidden.
QModelIndexList indexes() const
Returns a list of model indexes that correspond to the selected items.
The QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widg...
Definition: qstyleoption.h:539
virtual void horizontalScrollbarAction(int action)
int logicalIndexAt(int position) const
Returns the section that covers the given position in the viewport.
int sectionSpanSize(const QHeaderView *header, int logical, int span) const
Returns the size of the span starting at logical index logical and spanning span sections.
Definition: qtableview.cpp:757
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
int maximum() const
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Appends a new row to the current test data.
Definition: qtestcase.cpp:2183
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
static const KeyPair *const end
void rowCountChanged(int oldCount, int newCount)
This slot is called whenever rows are added or deleted.
bool event(QEvent *event)
Reimplemented Function
Qt::PenStyle gridStyle() const
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
bool isSortingEnabled() const
QSize sizeHint() const
Reimplemented Function
int size() const
Returns the number of bits stored in the bit array.
Definition: qbitarray.h:73
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
void setColumnHidden(int column, bool hide)
If hide is true the given column will be hidden; otherwise it will be shown.
QModelIndex indexAt(const QPoint &p) const
Returns the index position of the model item corresponding to the table item at position pos in conte...
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
QModelIndexList selectedIndexes() const
Reimplemented Function
void clear()
Removes all items from the map.
Definition: qmap.h:444
void _q_updateSpanRemovedRows(const QModelIndex &parent, int start, int end)
Updates spans after row removal.
Definition: qtableview.cpp:917
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
int column() const
Returns the column this model index refers to.
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Reimplemented Function
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
static int area(const QSize &s)
Definition: qicon.cpp:155
void selectColumn(int column)
Selects the given column in the table view if the current SelectionMode and SelectionBehavior allows ...
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650
friend class const_iterator
Definition: qmap.h:369
int sizeHintForColumn(int column) const
Returns the size hint for the given column&#39;s width or -1 if there is no model.
#define Q_FUNC_INFO
Definition: qglobal.h:1871