Qt 4.8
qheaderview.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 "qheaderview.h"
43 
44 #ifndef QT_NO_ITEMVIEWS
45 #include <qbitarray.h>
46 #include <qbrush.h>
47 #include <qdebug.h>
48 #include <qevent.h>
49 #include <qpainter.h>
50 #include <qscrollbar.h>
51 #include <qtooltip.h>
52 #include <qwhatsthis.h>
53 #include <qstyle.h>
54 #include <qstyleoption.h>
55 #include <qvector.h>
56 #include <qapplication.h>
57 #include <qvarlengtharray.h>
58 #include <qabstractitemdelegate.h>
59 #include <qvariant.h>
60 #include <private/qheaderview_p.h>
61 #include <private/qabstractitemmodel_p.h>
62 
63 #ifndef QT_NO_DATASTREAM
64 #include <qdatastream.h>
65 #endif
66 
68 
69 #ifndef QT_NO_DATASTREAM
71 {
72  span.write(out);
73  return out;
74 }
75 
77 {
78  span.read(in);
79  return in;
80 }
81 #endif // QT_NO_DATASTREAM
82 
83 
330 // ### Qt 5: change to sectionAutoResized()
331 
356  : QAbstractItemView(*new QHeaderViewPrivate, parent)
357 {
358  Q_D(QHeaderView);
359  d->setDefaultValues(orientation);
360  initialize();
361 }
362 
368  : QAbstractItemView(dd, parent)
369 {
370  Q_D(QHeaderView);
371  d->setDefaultValues(orientation);
372  initialize();
373 }
374 
380 {
381 }
382 
387 {
388  Q_D(QHeaderView);
393  d->viewport->setMouseTracking(true);
394  d->viewport->setBackgroundRole(QPalette::Button);
395  d->textElideMode = Qt::ElideNone;
396  delete d->itemDelegate;
397 }
398 
403 {
404  if (model == this->model())
405  return;
406  Q_D(QHeaderView);
407  if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
408  if (d->orientation == Qt::Horizontal) {
409  QObject::disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),
410  this, SLOT(sectionsInserted(QModelIndex,int,int)));
411  QObject::disconnect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
412  this, SLOT(sectionsAboutToBeRemoved(QModelIndex,int,int)));
413  QObject::disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
414  this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
415  } else {
417  this, SLOT(sectionsInserted(QModelIndex,int,int)));
419  this, SLOT(sectionsAboutToBeRemoved(QModelIndex,int,int)));
420  QObject::disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
421  this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
422  }
424  this, SLOT(headerDataChanged(Qt::Orientation,int,int)));
425  QObject::disconnect(d->model, SIGNAL(layoutAboutToBeChanged()),
426  this, SLOT(_q_layoutAboutToBeChanged()));
427  }
428 
429  if (model && model != QAbstractItemModelPrivate::staticEmptyModel()) {
430  if (d->orientation == Qt::Horizontal) {
431  QObject::connect(model, SIGNAL(columnsInserted(QModelIndex,int,int)),
432  this, SLOT(sectionsInserted(QModelIndex,int,int)));
433  QObject::connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
434  this, SLOT(sectionsAboutToBeRemoved(QModelIndex,int,int)));
435  QObject::connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
436  this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
437  } else {
439  this, SLOT(sectionsInserted(QModelIndex,int,int)));
441  this, SLOT(sectionsAboutToBeRemoved(QModelIndex,int,int)));
442  QObject::connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
443  this, SLOT(_q_sectionsRemoved(QModelIndex,int,int)));
444  }
446  this, SLOT(headerDataChanged(Qt::Orientation,int,int)));
447  QObject::connect(model, SIGNAL(layoutAboutToBeChanged()),
448  this, SLOT(_q_layoutAboutToBeChanged()));
449  }
450 
454 
455  // Users want to set sizes and modes before the widget is shown.
456  // Thus, we have to initialize when the model is set,
457  // and not lazily like we do in the other views.
459 }
460 
468 {
469  Q_D(const QHeaderView);
470  return d->orientation;
471 }
472 
481 {
482  Q_D(const QHeaderView);
483  return d->offset;
484 }
485 
497 void QHeaderView::setOffset(int newOffset)
498 {
499  Q_D(QHeaderView);
500  if (d->offset == (int)newOffset)
501  return;
502  int ndelta = d->offset - newOffset;
503  d->offset = newOffset;
504  if (d->orientation == Qt::Horizontal)
505  d->viewport->scroll(isRightToLeft() ? -ndelta : ndelta, 0);
506  else
507  d->viewport->scroll(0, ndelta);
508  if (d->state == QHeaderViewPrivate::ResizeSection) {
509  QPoint cursorPos = QCursor::pos();
510  if (d->orientation == Qt::Horizontal)
511  QCursor::setPos(cursorPos.x() + ndelta, cursorPos.y());
512  else
513  QCursor::setPos(cursorPos.x(), cursorPos.y() + ndelta);
514  d->firstPos += ndelta;
515  d->lastPos += ndelta;
516  }
517 }
518 
529 {
530  Q_D(QHeaderView);
531  if (visualIndex > -1 && visualIndex < d->sectionCount) {
532  int position = d->headerSectionPosition(d->adjustedVisualIndex(visualIndex));
533  setOffset(position);
534  }
535 }
536 
547 {
548  Q_D(const QHeaderView);
549  int size = (d->orientation == Qt::Horizontal ? viewport()->width() : viewport()->height());
550  int position = length() - size;
551  setOffset(position);
552 }
553 
561 {
562  Q_D(const QHeaderView);
563  d->executePostedLayout();
564  d->executePostedResize();
565  //Q_ASSERT(d->headerLength() == d->length);
566  return d->length;
567 }
568 
576 {
577  Q_D(const QHeaderView);
578  if (d->cachedSizeHint.isValid())
579  return d->cachedSizeHint;
580  d->cachedSizeHint = QSize(0, 0); //reinitialize the cached size hint
581  const int sectionCount = count();
582 
583  // get size hint for the first n sections
584  int i = 0;
585  for (int checked = 0; checked < 100 && i < sectionCount; ++i) {
586  if (isSectionHidden(i))
587  continue;
588  checked++;
589  QSize hint = sectionSizeFromContents(i);
590  d->cachedSizeHint = d->cachedSizeHint.expandedTo(hint);
591  }
592  // get size hint for the last n sections
593  i = qMax(i, sectionCount - 100 );
594  for (int j = sectionCount - 1, checked = 0; j >= i && checked < 100; --j) {
595  if (isSectionHidden(j))
596  continue;
597  checked++;
598  QSize hint = sectionSizeFromContents(j);
599  d->cachedSizeHint = d->cachedSizeHint.expandedTo(hint);
600  }
601  return d->cachedSizeHint;
602 }
603 
612 {
613  Q_D(const QHeaderView);
614  if (isSectionHidden(logicalIndex))
615  return 0;
616  if (logicalIndex < 0 || logicalIndex >= count())
617  return -1;
618  QSize size;
619  QVariant value = d->model->headerData(logicalIndex, d->orientation, Qt::SizeHintRole);
620  if (value.isValid())
621  size = qvariant_cast<QSize>(value);
622  else
623  size = sectionSizeFromContents(logicalIndex);
624  int hint = d->orientation == Qt::Horizontal ? size.width() : size.height();
625  return qMax(minimumSectionSize(), hint);
626 }
627 
636 {
637  Q_D(const QHeaderView);
638  int vposition = position;
639  d->executePostedLayout();
640  d->executePostedResize();
641  const int count = d->sectionCount;
642  if (count < 1)
643  return -1;
644 
645  if (d->reverse())
646  vposition = d->viewport->width() - vposition;
647  vposition += d->offset;
648 
649  if (vposition > d->length)
650  return -1;
651  int visual = d->headerVisualIndexAt(vposition);
652  if (visual < 0)
653  return -1;
654 
655  while (d->isVisualIndexHidden(visual)){
656  ++visual;
657  if (visual >= count)
658  return -1;
659  }
660  return visual;
661 }
662 
670 {
671  const int visual = visualIndexAt(position);
672  if (visual > -1)
673  return logicalIndex(visual);
674  return -1;
675 }
676 
685 {
686  Q_D(const QHeaderView);
687  if (isSectionHidden(logicalIndex))
688  return 0;
689  if (logicalIndex < 0 || logicalIndex >= count())
690  return 0;
691  int visual = visualIndex(logicalIndex);
692  if (visual == -1)
693  return 0;
694  d->executePostedResize();
695  return d->headerSectionSize(visual);
696 }
697 
710 {
711  Q_D(const QHeaderView);
712  int visual = visualIndex(logicalIndex);
713  // in some cases users may change the selections
714  // before we have a chance to do the layout
715  if (visual == -1)
716  return -1;
717  d->executePostedResize();
718  return d->headerSectionPosition(visual);
719 }
720 
730 {
731  Q_D(const QHeaderView);
732  if (logicalIndex >= count())
733  return -1;
734  int position = sectionPosition(logicalIndex);
735  if (position < 0)
736  return position; // the section was hidden
737  int offsetPosition = position - d->offset;
738  if (d->reverse())
739  return d->viewport->width() - (offsetPosition + sectionSize(logicalIndex));
740  return offsetPosition;
741 }
742 
773 void QHeaderView::moveSection(int from, int to)
774 {
775  Q_D(QHeaderView);
776 
777  d->executePostedLayout();
778  if (from < 0 || from >= d->sectionCount || to < 0 || to >= d->sectionCount)
779  return;
780 
781  if (from == to) {
782  int logical = logicalIndex(from);
783  Q_ASSERT(logical != -1);
784  updateSection(logical);
785  return;
786  }
787 
788  if (stretchLastSection() && to == d->lastVisibleVisualIndex())
789  d->lastSectionSize = sectionSize(from);
790 
791  //int oldHeaderLength = length(); // ### for debugging; remove later
792  d->initializeIndexMapping();
793 
794  QBitArray sectionHidden = d->sectionHidden;
795  int *visualIndices = d->visualIndices.data();
796  int *logicalIndices = d->logicalIndices.data();
797  int logical = logicalIndices[from];
798  int visual = from;
799 
800  int affected_count = qAbs(to - from) + 1;
801  QVarLengthArray<int> sizes(affected_count);
802  QVarLengthArray<ResizeMode> modes(affected_count);
803 
804  // move sections and indices
805  if (to > from) {
806  sizes[to - from] = d->headerSectionSize(from);
807  modes[to - from] = d->headerSectionResizeMode(from);
808  while (visual < to) {
809  sizes[visual - from] = d->headerSectionSize(visual + 1);
810  modes[visual - from] = d->headerSectionResizeMode(visual + 1);
811  if (!sectionHidden.isEmpty())
812  sectionHidden.setBit(visual, sectionHidden.testBit(visual + 1));
813  visualIndices[logicalIndices[visual + 1]] = visual;
814  logicalIndices[visual] = logicalIndices[visual + 1];
815  ++visual;
816  }
817  } else {
818  sizes[0] = d->headerSectionSize(from);
819  modes[0] = d->headerSectionResizeMode(from);
820  while (visual > to) {
821  sizes[visual - to] = d->headerSectionSize(visual - 1);
822  modes[visual - to] = d->headerSectionResizeMode(visual - 1);
823  if (!sectionHidden.isEmpty())
824  sectionHidden.setBit(visual, sectionHidden.testBit(visual - 1));
825  visualIndices[logicalIndices[visual - 1]] = visual;
826  logicalIndices[visual] = logicalIndices[visual - 1];
827  --visual;
828  }
829  }
830  if (!sectionHidden.isEmpty()) {
831  sectionHidden.setBit(to, d->sectionHidden.testBit(from));
832  d->sectionHidden = sectionHidden;
833  }
834  visualIndices[logical] = to;
835  logicalIndices[to] = logical;
836 
837  //Q_ASSERT(oldHeaderLength == length());
838  // move sizes
839  // ### check for spans of section sizes here
840  if (to > from) {
841  for (visual = from; visual <= to; ++visual) {
842  int size = sizes[visual - from];
843  ResizeMode mode = modes[visual - from];
844  d->createSectionSpan(visual, visual, size, mode);
845  }
846  } else {
847  for (visual = to; visual <= from; ++visual) {
848  int size = sizes[visual - to];
849  ResizeMode mode = modes[visual - to];
850  d->createSectionSpan(visual, visual, size, mode);
851  }
852  }
853  //Q_ASSERT(d->headerLength() == length());
854  //Q_ASSERT(oldHeaderLength == length());
855  //Q_ASSERT(d->logicalIndices.count() == d->sectionCount);
856 
857  if (d->hasAutoResizeSections())
858  d->doDelayedResizeSections();
859  d->viewport->update();
860 
861  emit sectionMoved(logical, from, to);
862 }
863 
874 void QHeaderView::swapSections(int first, int second)
875 {
876  Q_D(QHeaderView);
877 
878  if (first == second)
879  return;
880  d->executePostedLayout();
881  if (first < 0 || first >= d->sectionCount || second < 0 || second >= d->sectionCount)
882  return;
883 
884  int firstSize = d->headerSectionSize(first);
885  ResizeMode firstMode = d->headerSectionResizeMode(first);
886  int firstLogical = d->logicalIndex(first);
887 
888  int secondSize = d->headerSectionSize(second);
889  ResizeMode secondMode = d->headerSectionResizeMode(second);
890  int secondLogical = d->logicalIndex(second);
891 
892  d->createSectionSpan(second, second, firstSize, firstMode);
893  d->createSectionSpan(first, first, secondSize, secondMode);
894 
895  d->initializeIndexMapping();
896 
897  d->visualIndices[firstLogical] = second;
898  d->logicalIndices[second] = firstLogical;
899 
900  d->visualIndices[secondLogical] = first;
901  d->logicalIndices[first] = secondLogical;
902 
903  if (!d->sectionHidden.isEmpty()) {
904  bool firstHidden = d->sectionHidden.testBit(first);
905  bool secondHidden = d->sectionHidden.testBit(second);
906  d->sectionHidden.setBit(first, secondHidden);
907  d->sectionHidden.setBit(second, firstHidden);
908  }
909 
910  d->viewport->update();
911  emit sectionMoved(firstLogical, first, second);
912  emit sectionMoved(secondLogical, second, first);
913 }
914 
927 void QHeaderView::resizeSection(int logical, int size)
928 {
929  Q_D(QHeaderView);
930  if (logical < 0 || logical >= count())
931  return;
932 
933  if (isSectionHidden(logical)) {
934  d->hiddenSectionSize.insert(logical, size);
935  return;
936  }
937 
938  int visual = visualIndex(logical);
939  if (visual == -1)
940  return;
941 
942  int oldSize = d->headerSectionSize(visual);
943  if (oldSize == size)
944  return;
945 
946  d->executePostedLayout();
947  d->invalidateCachedSizeHint();
948 
949  if (stretchLastSection() && visual == d->lastVisibleVisualIndex())
950  d->lastSectionSize = size;
951 
952  if (size != oldSize)
953  d->createSectionSpan(visual, visual, size, d->headerSectionResizeMode(visual));
954 
955  if (!updatesEnabled()) {
956  if (d->hasAutoResizeSections())
957  d->doDelayedResizeSections();
958  emit sectionResized(logical, oldSize, size);
959  return;
960  }
961 
962  int w = d->viewport->width();
963  int h = d->viewport->height();
964  int pos = sectionViewportPosition(logical);
965  QRect r;
966  if (d->orientation == Qt::Horizontal)
967  if (isRightToLeft())
968  r.setRect(0, 0, pos + size, h);
969  else
970  r.setRect(pos, 0, w - pos, h);
971  else
972  r.setRect(0, pos, w, h - pos);
973 
974  if (d->hasAutoResizeSections()) {
975  d->doDelayedResizeSections();
976  r = d->viewport->rect();
977  }
978  d->viewport->update(r.normalized());
979  emit sectionResized(logical, oldSize, size);
980 }
981 
990 {
991  Q_D(QHeaderView);
992  d->resizeSections(mode, true);
993 }
994 
1025 {
1026  Q_D(const QHeaderView);
1027  d->executePostedLayout();
1028  if (logicalIndex >= d->sectionHidden.count() || logicalIndex < 0 || logicalIndex >= d->sectionCount)
1029  return false;
1030  int visual = visualIndex(logicalIndex);
1031  Q_ASSERT(visual != -1);
1032  return d->sectionHidden.testBit(visual);
1033 }
1034 
1046 {
1047  Q_D(const QHeaderView);
1048  return d->hiddenSectionSize.count();
1049 }
1050 
1059 {
1060  Q_D(QHeaderView);
1061  if (logicalIndex < 0 || logicalIndex >= count())
1062  return;
1063 
1064  d->executePostedLayout();
1065  int visual = visualIndex(logicalIndex);
1066  Q_ASSERT(visual != -1);
1067  if (hide == d->isVisualIndexHidden(visual))
1068  return;
1069  if (hide) {
1070  int size = d->headerSectionSize(visual);
1071  if (!d->hasAutoResizeSections())
1072  resizeSection(logicalIndex, 0);
1073  d->hiddenSectionSize.insert(logicalIndex, size);
1074  if (d->sectionHidden.count() < count())
1075  d->sectionHidden.resize(count());
1076  d->sectionHidden.setBit(visual, true);
1077  if (d->hasAutoResizeSections())
1078  d->doDelayedResizeSections();
1079  } else {
1080  int size = d->hiddenSectionSize.value(logicalIndex, d->defaultSectionSize);
1081  d->hiddenSectionSize.remove(logicalIndex);
1082  if (d->hiddenSectionSize.isEmpty()) {
1083  d->sectionHidden.clear();
1084  } else {
1085  Q_ASSERT(visual <= d->sectionHidden.count());
1086  d->sectionHidden.setBit(visual, false);
1087  }
1088  resizeSection(logicalIndex, size);
1089  }
1090 }
1091 
1099 {
1100  Q_D(const QHeaderView);
1101  //Q_ASSERT(d->sectionCount == d->headerSectionCount());
1102  // ### this may affect the lazy layout
1103  d->executePostedLayout();
1104  return d->sectionCount;
1105 }
1106 
1117 {
1118  Q_D(const QHeaderView);
1119  if (logicalIndex < 0)
1120  return -1;
1121  d->executePostedLayout();
1122  if (d->visualIndices.isEmpty()) { // nothing has been moved, so we have no mapping
1123  if (logicalIndex < d->sectionCount)
1124  return logicalIndex;
1125  } else if (logicalIndex < d->visualIndices.count()) {
1126  int visual = d->visualIndices.at(logicalIndex);
1127  Q_ASSERT(visual < d->sectionCount);
1128  return visual;
1129  }
1130  return -1;
1131 }
1132 
1143 {
1144  Q_D(const QHeaderView);
1145  if (visualIndex < 0 || visualIndex >= d->sectionCount)
1146  return -1;
1147  return d->logicalIndex(visualIndex);
1148 }
1149 
1157 // ### Qt 5: change to setSectionsMovable()
1158 void QHeaderView::setMovable(bool movable)
1159 {
1160  Q_D(QHeaderView);
1161  d->movableSections = movable;
1162 }
1163 
1171 // ### Qt 5: change to sectionsMovable()
1173 {
1174  Q_D(const QHeaderView);
1175  return d->movableSections;
1176 }
1177 
1185 // ### Qt 5: change to setSectionsClickable()
1186 void QHeaderView::setClickable(bool clickable)
1187 {
1188  Q_D(QHeaderView);
1189  d->clickableSections = clickable;
1190 }
1191 
1200 // ### Qt 5: change to sectionsClickable()
1202 {
1203  Q_D(const QHeaderView);
1204  return d->clickableSections;
1205 }
1206 
1208 {
1209  Q_D(QHeaderView);
1210  d->highlightSelected = highlight;
1211 }
1212 
1213 bool QHeaderView::highlightSections() const
1214 {
1215  Q_D(const QHeaderView);
1216  return d->highlightSelected;
1217 }
1218 
1227 {
1228  Q_D(QHeaderView);
1230  d->stretchSections = (mode == Stretch ? count() : 0);
1231  d->contentsSections = (mode == ResizeToContents ? count() : 0);
1232  d->setGlobalHeaderResizeMode(mode);
1233  if (d->hasAutoResizeSections())
1234  d->doDelayedResizeSections(); // section sizes may change as a result of the new mode
1235 }
1236 
1254 // ### Qt 5: change to setSectionResizeMode()
1256 {
1257  Q_D(QHeaderView);
1258  int visual = visualIndex(logicalIndex);
1259  Q_ASSERT(visual != -1);
1260 
1261  ResizeMode old = d->headerSectionResizeMode(visual);
1262  d->setHeaderSectionResizeMode(visual, mode);
1263 
1264  if (mode == Stretch && old != Stretch)
1265  ++d->stretchSections;
1266  else if (mode == ResizeToContents && old != ResizeToContents)
1267  ++d->contentsSections;
1268  else if (mode != Stretch && old == Stretch)
1269  --d->stretchSections;
1270  else if (mode != ResizeToContents && old == ResizeToContents)
1271  --d->contentsSections;
1272 
1273  if (d->hasAutoResizeSections() && d->state == QHeaderViewPrivate::NoState)
1274  d->doDelayedResizeSections(); // section sizes may change as a result of the new mode
1275 }
1276 
1285 {
1286  Q_D(const QHeaderView);
1287  int visual = visualIndex(logicalIndex);
1288  if (visual == -1)
1289  return Fixed; //the default value
1290  return d->headerSectionResizeMode(visual);
1291 }
1292 
1307 {
1308  Q_D(const QHeaderView);
1309  return d->stretchSections;
1310 }
1311 
1325 {
1326  Q_D(QHeaderView);
1327  if (d->sortIndicatorShown == show)
1328  return;
1329 
1330  d->sortIndicatorShown = show;
1331 
1332  if (sortIndicatorSection() < 0 || sortIndicatorSection() > count())
1333  return;
1334 
1335  if (d->headerSectionResizeMode(sortIndicatorSection()) == ResizeToContents)
1336  resizeSections();
1337 
1338  d->viewport->update();
1339 }
1340 
1342 {
1343  Q_D(const QHeaderView);
1344  return d->sortIndicatorShown;
1345 }
1346 
1360 {
1361  Q_D(QHeaderView);
1362 
1363  // This is so that people can set the position of the sort indicator before the fill the model
1364  int old = d->sortIndicatorSection;
1365  d->sortIndicatorSection = logicalIndex;
1366  d->sortIndicatorOrder = order;
1367 
1368  if (logicalIndex >= d->sectionCount) {
1369  emit sortIndicatorChanged(logicalIndex, order);
1370  return; // nothing to do
1371  }
1372 
1373  if (old != logicalIndex
1374  && ((logicalIndex >= 0 && resizeMode(logicalIndex) == ResizeToContents)
1375  || old >= d->sectionCount || (old >= 0 && resizeMode(old) == ResizeToContents))) {
1376  resizeSections();
1377  d->viewport->update();
1378  } else {
1379  if (old >= 0 && old != logicalIndex)
1380  updateSection(old);
1381  if (logicalIndex >= 0)
1382  updateSection(logicalIndex);
1383  }
1384 
1385  emit sortIndicatorChanged(logicalIndex, order);
1386 }
1387 
1396 {
1397  Q_D(const QHeaderView);
1398  return d->sortIndicatorSection;
1399 }
1400 
1409 {
1410  Q_D(const QHeaderView);
1411  return d->sortIndicatorOrder;
1412 }
1413 
1433 {
1434  Q_D(const QHeaderView);
1435  return d->stretchLastSection;
1436 }
1437 
1439 {
1440  Q_D(QHeaderView);
1441  d->stretchLastSection = stretch;
1442  if (d->state != QHeaderViewPrivate::NoState)
1443  return;
1444  if (stretch)
1445  resizeSections();
1446  else if (count())
1447  resizeSection(count() - 1, d->defaultSectionSize);
1448 }
1449 
1468 {
1469  Q_D(const QHeaderView);
1470  return d->cascadingResizing;
1471 }
1472 
1474 {
1475  Q_D(QHeaderView);
1476  d->cascadingResizing = enable;
1477 }
1478 
1492 {
1493  Q_D(const QHeaderView);
1494  return d->defaultSectionSize;
1495 }
1496 
1498 {
1499  Q_D(QHeaderView);
1500  d->setDefaultSectionSize(size);
1501 }
1502 
1521 {
1522  Q_D(const QHeaderView);
1523  if (d->minimumSectionSize == -1) {
1524  QSize strut = QApplication::globalStrut();
1525  int margin = style()->pixelMetric(QStyle::PM_HeaderMargin, 0, this);
1526  if (d->orientation == Qt::Horizontal)
1527  return qMax(strut.width(), (fontMetrics().maxWidth() + margin));
1528  return qMax(strut.height(), (fontMetrics().height() + margin));
1529  }
1530  return d->minimumSectionSize;
1531 }
1532 
1534 {
1535  Q_D(QHeaderView);
1536  d->minimumSectionSize = size;
1537 }
1538 
1548 Qt::Alignment QHeaderView::defaultAlignment() const
1549 {
1550  Q_D(const QHeaderView);
1551  return d->defaultAlignment;
1552 }
1553 
1554 void QHeaderView::setDefaultAlignment(Qt::Alignment alignment)
1555 {
1556  Q_D(QHeaderView);
1557  if (d->defaultAlignment == alignment)
1558  return;
1559 
1560  d->defaultAlignment = alignment;
1561  d->viewport->update();
1562 }
1563 
1568 {
1571 }
1572 
1580 {
1581  Q_D(const QHeaderView);
1582  return !d->visualIndices.isEmpty();
1583 }
1584 
1594 {
1595  Q_D(const QHeaderView);
1596  return !d->hiddenSectionSize.isEmpty();
1597 }
1598 
1599 #ifndef QT_NO_DATASTREAM
1600 
1613 {
1614  Q_D(const QHeaderView);
1615  QByteArray data;
1618  stream << 0; // current version is 0
1619  d->write(stream);
1620  return data;
1621 }
1622 
1635 {
1636  Q_D(QHeaderView);
1637  if (state.isEmpty())
1638  return false;
1639  QByteArray data = state;
1641  int marker;
1642  int ver;
1643  stream >> marker;
1644  stream >> ver;
1645  if (stream.status() != QDataStream::Ok
1647  || ver != 0) // current version is 0
1648  return false;
1649 
1650  if (d->read(stream)) {
1651  emit sortIndicatorChanged(d->sortIndicatorSection, d->sortIndicatorOrder );
1652  d->viewport->update();
1653  return true;
1654  }
1655  return false;
1656 }
1657 #endif // QT_NO_DATASTREAM
1658 
1663 {
1665  // it would be correct to call clear, but some apps rely
1666  // on the header keeping the sections, even after calling reset
1667  //d->clear();
1669 }
1670 
1675 void QHeaderView::headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast)
1676 {
1677  Q_D(QHeaderView);
1678  if (d->orientation != orientation)
1679  return;
1680 
1681  if (logicalFirst < 0 || logicalLast < 0 || logicalFirst >= count() || logicalLast >= count())
1682  return;
1683 
1684  d->invalidateCachedSizeHint();
1685 
1686  int firstVisualIndex = INT_MAX, lastVisualIndex = -1;
1687 
1688  for (int section = logicalFirst; section <= logicalLast; ++section) {
1689  const int visual = visualIndex(section);
1690  firstVisualIndex = qMin(firstVisualIndex, visual);
1691  lastVisualIndex = qMax(lastVisualIndex, visual);
1692  }
1693 
1694  d->executePostedResize();
1695  const int first = d->headerSectionPosition(firstVisualIndex),
1696  last = d->headerSectionPosition(lastVisualIndex)
1697  + d->headerSectionSize(lastVisualIndex);
1698 
1699  if (orientation == Qt::Horizontal) {
1700  d->viewport->update(first, 0, last - first, d->viewport->height());
1701  } else {
1702  d->viewport->update(0, first, d->viewport->width(), last - first);
1703  }
1704 }
1705 
1717 {
1718  Q_D(QHeaderView);
1719  if (d->orientation == Qt::Horizontal)
1720  d->viewport->update(QRect(sectionViewportPosition(logicalIndex),
1721  0, sectionSize(logicalIndex), d->viewport->height()));
1722  else
1723  d->viewport->update(QRect(0, sectionViewportPosition(logicalIndex),
1724  d->viewport->width(), sectionSize(logicalIndex)));
1725 }
1726 
1733 {
1734  Q_D(QHeaderView);
1735  if (d->hasAutoResizeSections())
1736  d->resizeSections(Interactive, false); // no global resize mode
1737 }
1738 
1749  int logicalFirst, int logicalLast)
1750 {
1751  Q_D(QHeaderView);
1752  if (parent != d->root)
1753  return; // we only handle changes in the top level
1754  int oldCount = d->sectionCount;
1755 
1756  d->invalidateCachedSizeHint();
1757 
1758  // add the new sections
1759  int insertAt = 0;
1760  for (int spanStart = 0; insertAt < d->sectionSpans.count() && spanStart < logicalFirst; ++insertAt)
1761  spanStart += d->sectionSpans.at(insertAt).count;
1762 
1763  int insertCount = logicalLast - logicalFirst + 1;
1764  d->sectionCount += insertCount;
1765 
1766  if (d->sectionSpans.isEmpty() || insertAt >= d->sectionSpans.count()) {
1767  int insertLength = d->defaultSectionSize * insertCount;
1768  d->length += insertLength;
1769  QHeaderViewPrivate::SectionSpan span(insertLength, insertCount, d->globalResizeMode);
1770  d->sectionSpans.append(span);
1771  } else if ((d->sectionSpans.at(insertAt).sectionSize() == d->defaultSectionSize)
1772  && d->sectionSpans.at(insertAt).resizeMode == d->globalResizeMode) {
1773  // add the new sections to an existing span
1774  int insertLength = d->sectionSpans.at(insertAt).sectionSize() * insertCount;
1775  d->length += insertLength;
1776  d->sectionSpans[insertAt].size += insertLength;
1777  d->sectionSpans[insertAt].count += insertCount;
1778  } else {
1779  // separate them out into their own span
1780  int insertLength = d->defaultSectionSize * insertCount;
1781  d->length += insertLength;
1782  QHeaderViewPrivate::SectionSpan span(insertLength, insertCount, d->globalResizeMode);
1783  d->sectionSpans.insert(insertAt, span);
1784  }
1785 
1786  // update sorting column
1787  if (d->sortIndicatorSection >= logicalFirst)
1788  d->sortIndicatorSection += insertCount;
1789 
1790  // update resize mode section counts
1791  if (d->globalResizeMode == Stretch)
1792  d->stretchSections = d->sectionCount;
1793  else if (d->globalResizeMode == ResizeToContents)
1794  d->contentsSections = d->sectionCount;
1795 
1796  // clear selection cache
1797  d->sectionSelected.clear();
1798 
1799  // update mapping
1800  if (!d->visualIndices.isEmpty() && !d->logicalIndices.isEmpty()) {
1801  Q_ASSERT(d->visualIndices.count() == d->logicalIndices.count());
1802  int mappingCount = d->visualIndices.count();
1803  for (int i = 0; i < mappingCount; ++i) {
1804  if (d->visualIndices.at(i) >= logicalFirst)
1805  d->visualIndices[i] += insertCount;
1806  if (d->logicalIndices.at(i) >= logicalFirst)
1807  d->logicalIndices[i] += insertCount;
1808  }
1809  for (int j = logicalFirst; j <= logicalLast; ++j) {
1810  d->visualIndices.insert(j, j);
1811  d->logicalIndices.insert(j, j);
1812  }
1813  }
1814 
1815  // insert sections into sectionsHidden
1816  if (!d->sectionHidden.isEmpty()) {
1817  QBitArray sectionHidden(d->sectionHidden);
1818  sectionHidden.resize(sectionHidden.count() + insertCount);
1819  sectionHidden.fill(false, logicalFirst, logicalLast + 1);
1820  for (int j = logicalLast + 1; j < sectionHidden.count(); ++j)
1821  //here we simply copy the old sectionHidden
1822  sectionHidden.setBit(j, d->sectionHidden.testBit(j - insertCount));
1823  d->sectionHidden = sectionHidden;
1824  }
1825 
1826  // insert sections into hiddenSectionSize
1827  QHash<int, int> newHiddenSectionSize; // from logical index to section size
1828  for (int i = 0; i < logicalFirst; ++i)
1829  if (isSectionHidden(i))
1830  newHiddenSectionSize[i] = d->hiddenSectionSize[i];
1831  for (int j = logicalLast + 1; j < d->sectionCount; ++j)
1832  if (isSectionHidden(j))
1833  newHiddenSectionSize[j] = d->hiddenSectionSize[j - insertCount];
1834  d->hiddenSectionSize = newHiddenSectionSize;
1835 
1836  d->doDelayedResizeSections();
1837  emit sectionCountChanged(oldCount, count());
1838 
1839  // if the new sections were not updated by resizing, we need to update now
1840  if (!d->hasAutoResizeSections())
1841  d->viewport->update();
1842 }
1843 
1853  int logicalFirst, int logicalLast)
1854 {
1855  Q_UNUSED(parent);
1856  Q_UNUSED(logicalFirst);
1857  Q_UNUSED(logicalLast);
1858 }
1859 
1860 void QHeaderViewPrivate::updateHiddenSections(int logicalFirst, int logicalLast)
1861 {
1862  Q_Q(QHeaderView);
1863  const int changeCount = logicalLast - logicalFirst + 1;
1864 
1865  // remove sections from hiddenSectionSize
1866  QHash<int, int> newHiddenSectionSize; // from logical index to section size
1867  for (int i = 0; i < logicalFirst; ++i)
1868  if (q->isSectionHidden(i))
1869  newHiddenSectionSize[i] = hiddenSectionSize[i];
1870  for (int j = logicalLast + 1; j < sectionCount; ++j)
1871  if (q->isSectionHidden(j))
1872  newHiddenSectionSize[j - changeCount] = hiddenSectionSize[j];
1873  hiddenSectionSize = newHiddenSectionSize;
1874 
1875  // remove sections from sectionsHidden
1876  if (!sectionHidden.isEmpty()) {
1877  const int newsize = qMin(sectionCount - changeCount, sectionHidden.size());
1878  QBitArray newSectionHidden(newsize);
1879  for (int j = 0, k = 0; j < sectionHidden.size(); ++j) {
1880  const int logical = logicalIndex(j);
1881  if (logical < logicalFirst || logical > logicalLast) {
1882  newSectionHidden[k++] = sectionHidden[j];
1883  }
1884  }
1885  sectionHidden = newSectionHidden;
1886  }
1887 }
1888 
1890  int logicalFirst, int logicalLast)
1891 {
1892  Q_Q(QHeaderView);
1893  if (parent != root)
1894  return; // we only handle changes in the top level
1895  if (qMin(logicalFirst, logicalLast) < 0
1896  || qMax(logicalLast, logicalFirst) >= sectionCount)
1897  return;
1898  int oldCount = q->count();
1899  int changeCount = logicalLast - logicalFirst + 1;
1900 
1901  updateHiddenSections(logicalFirst, logicalLast);
1902 
1903  if (visualIndices.isEmpty() && logicalIndices.isEmpty()) {
1904  //Q_ASSERT(headerSectionCount() == sectionCount);
1905  removeSectionsFromSpans(logicalFirst, logicalLast);
1906  } else {
1907  for (int l = logicalLast; l >= logicalFirst; --l) {
1908  int visual = visualIndices.at(l);
1909  for (int v = 0; v < sectionCount; ++v) {
1910  if (v >= logicalIndices.count())
1911  continue; // the section doesn't exist
1912  if (v > visual) {
1913  int logical = logicalIndices.at(v);
1914  --(visualIndices[logical]);
1915  }
1916  if (logicalIndex(v) > l) // no need to move the positions before l
1917  --(logicalIndices[v]);
1918  }
1919  logicalIndices.remove(visual);
1920  visualIndices.remove(l);
1921  //Q_ASSERT(headerSectionCount() == sectionCount);
1922  removeSectionsFromSpans(visual, visual);
1923  }
1924  // ### handle sectionSelection, sectionHidden
1925  }
1926  sectionCount -= changeCount;
1927 
1928  // update sorting column
1929  if (sortIndicatorSection >= logicalFirst) {
1930  if (sortIndicatorSection <= logicalLast)
1931  sortIndicatorSection = -1;
1932  else
1933  sortIndicatorSection -= changeCount;
1934  }
1935 
1936  // if we only have the last section (the "end" position) left, the header is empty
1937  if (sectionCount <= 0)
1938  clear();
1939  invalidateCachedSizeHint();
1940  emit q->sectionCountChanged(oldCount, q->count());
1941  viewport->update();
1942 }
1943 
1945 {
1946  //if there is no row/column we can't have mapping for columns
1947  //because no QModelIndex in the model would be valid
1948  // ### this is far from being bullet-proof and we would need a real system to
1949  // ### map columns or rows persistently
1950  if ((orientation == Qt::Horizontal && model->rowCount(root) == 0)
1951  || model->columnCount(root) == 0)
1952  return;
1953 
1954  for (int i = 0; i < sectionHidden.count(); ++i)
1955  if (sectionHidden.testBit(i)) // ### note that we are using column or row 0
1956  persistentHiddenSections.append(orientation == Qt::Horizontal
1957  ? model->index(0, logicalIndex(i), root)
1958  : model->index(logicalIndex(i), 0, root));
1959 }
1960 
1962 {
1963  Q_Q(QHeaderView);
1964  viewport->update();
1965  if (persistentHiddenSections.isEmpty() || modelIsEmpty()) {
1966  if (modelSectionCount() != sectionCount)
1967  q->initializeSections();
1968  persistentHiddenSections.clear();
1969  return;
1970  }
1971 
1972  QBitArray oldSectionHidden = sectionHidden;
1973  bool sectionCountChanged = false;
1974 
1975  for (int i = 0; i < persistentHiddenSections.count(); ++i) {
1976  QModelIndex index = persistentHiddenSections.at(i);
1977  if (index.isValid()) {
1978  const int logical = (orientation == Qt::Horizontal
1979  ? index.column()
1980  : index.row());
1981  q->setSectionHidden(logical, true);
1982  oldSectionHidden.setBit(logical, false);
1983  } else if (!sectionCountChanged && (modelSectionCount() != sectionCount)) {
1984  sectionCountChanged = true;
1985  break;
1986  }
1987  }
1988  persistentHiddenSections.clear();
1989 
1990  for (int i = 0; i < oldSectionHidden.count(); ++i) {
1991  if (oldSectionHidden.testBit(i))
1992  q->setSectionHidden(i, false);
1993  }
1994 
1995  // the number of sections changed; we need to reread the state of the model
1996  if (sectionCountChanged)
1997  q->initializeSections();
1998 }
1999 
2005 {
2006  Q_D(QHeaderView);
2007  const int oldCount = d->sectionCount;
2008  const int newCount = d->modelSectionCount();
2009  if (newCount <= 0) {
2010  d->clear();
2011  emit sectionCountChanged(oldCount, 0);
2012  } else if (newCount != oldCount) {
2013  const int min = qBound(0, oldCount, newCount - 1);
2014  initializeSections(min, newCount - 1);
2015  if (stretchLastSection()) // we've already gotten the size hint
2016  d->lastSectionSize = sectionSize(logicalIndex(d->sectionCount - 1));
2017 
2018  //make sure we update the hidden sections
2019  if (newCount < oldCount)
2020  d->updateHiddenSections(0, newCount-1);
2021  }
2022 }
2023 
2029 {
2030  Q_D(QHeaderView);
2031 
2032  Q_ASSERT(start >= 0);
2033  Q_ASSERT(end >= 0);
2034 
2035  d->invalidateCachedSizeHint();
2036 
2037  if (end + 1 < d->sectionCount) {
2038  int newCount = end + 1;
2039  d->removeSectionsFromSpans(newCount, d->sectionCount);
2040  if (!d->hiddenSectionSize.isEmpty()) {
2041  if (d->sectionCount - newCount > d->hiddenSectionSize.count()) {
2042  for (int i = end + 1; i < d->sectionCount; ++i)
2043  d->hiddenSectionSize.remove(i);
2044  } else {
2045  QHash<int, int>::iterator it = d->hiddenSectionSize.begin();
2046  while (it != d->hiddenSectionSize.end()) {
2047  if (it.key() > end)
2048  it = d->hiddenSectionSize.erase(it);
2049  else
2050  ++it;
2051  }
2052  }
2053  }
2054  }
2055 
2056  int oldCount = d->sectionCount;
2057  d->sectionCount = end + 1;
2058 
2059  if (!d->logicalIndices.isEmpty()) {
2060  if (oldCount <= d->sectionCount) {
2061  d->logicalIndices.resize(d->sectionCount);
2062  d->visualIndices.resize(d->sectionCount);
2063  for (int i = oldCount; i < d->sectionCount; ++i) {
2064  d->logicalIndices[i] = i;
2065  d->visualIndices[i] = i;
2066  }
2067  } else {
2068  int j = 0;
2069  for (int i = 0; i < oldCount; ++i) {
2070  int v = d->logicalIndices.at(i);
2071  if (v < d->sectionCount) {
2072  d->logicalIndices[j] = v;
2073  d->visualIndices[v] = j;
2074  j++;
2075  }
2076  }
2077  d->logicalIndices.resize(d->sectionCount);
2078  d->visualIndices.resize(d->sectionCount);
2079  }
2080  }
2081 
2082  if (d->globalResizeMode == Stretch)
2083  d->stretchSections = d->sectionCount;
2084  else if (d->globalResizeMode == ResizeToContents)
2085  d->contentsSections = d->sectionCount;
2086  if (!d->sectionHidden.isEmpty())
2087  d->sectionHidden.resize(d->sectionCount);
2088 
2089  if (d->sectionCount > oldCount)
2090  d->createSectionSpan(start, end, (end - start + 1) * d->defaultSectionSize, d->globalResizeMode);
2091  //Q_ASSERT(d->headerLength() == d->length);
2092 
2093  if (d->sectionCount != oldCount)
2094  emit sectionCountChanged(oldCount, d->sectionCount);
2095  d->viewport->update();
2096 }
2097 
2102 void QHeaderView::currentChanged(const QModelIndex &current, const QModelIndex &old)
2103 {
2104  Q_D(QHeaderView);
2105 
2106  if (d->orientation == Qt::Horizontal && current.column() != old.column()) {
2107  if (old.isValid() && old.parent() == d->root)
2108  d->viewport->update(QRect(sectionViewportPosition(old.column()), 0,
2109  sectionSize(old.column()), d->viewport->height()));
2110  if (current.isValid() && current.parent() == d->root)
2111  d->viewport->update(QRect(sectionViewportPosition(current.column()), 0,
2112  sectionSize(current.column()), d->viewport->height()));
2113  } else if (d->orientation == Qt::Vertical && current.row() != old.row()) {
2114  if (old.isValid() && old.parent() == d->root)
2115  d->viewport->update(QRect(0, sectionViewportPosition(old.row()),
2116  d->viewport->width(), sectionSize(old.row())));
2117  if (current.isValid() && current.parent() == d->root)
2118  d->viewport->update(QRect(0, sectionViewportPosition(current.row()),
2119  d->viewport->width(), sectionSize(current.row())));
2120  }
2121 }
2122 
2123 
2129 {
2130  Q_D(QHeaderView);
2131  switch (e->type()) {
2132  case QEvent::HoverEnter: {
2133  QHoverEvent *he = static_cast<QHoverEvent*>(e);
2134  d->hover = logicalIndexAt(he->pos());
2135  if (d->hover != -1)
2136  updateSection(d->hover);
2137  break; }
2138  case QEvent::Leave:
2139  case QEvent::HoverLeave: {
2140  if (d->hover != -1)
2141  updateSection(d->hover);
2142  d->hover = -1;
2143  break; }
2144  case QEvent::HoverMove: {
2145  QHoverEvent *he = static_cast<QHoverEvent*>(e);
2146  int oldHover = d->hover;
2147  d->hover = logicalIndexAt(he->pos());
2148  if (d->hover != oldHover) {
2149  if (oldHover != -1)
2150  updateSection(oldHover);
2151  if (d->hover != -1)
2152  updateSection(d->hover);
2153  }
2154  break; }
2155  case QEvent::Timer: {
2156  QTimerEvent *te = static_cast<QTimerEvent*>(e);
2157  if (te->timerId() == d->delayedResize.timerId()) {
2158  d->delayedResize.stop();
2159  resizeSections();
2160  }
2161  break; }
2162  default:
2163  break;
2164  }
2165  return QAbstractItemView::event(e);
2166 }
2167 
2173 {
2174  Q_D(QHeaderView);
2175 
2176  if (count() == 0)
2177  return;
2178 
2179  QPainter painter(d->viewport);
2180  const QPoint offset = d->scrollDelayOffset;
2181  QRect translatedEventRect = e->rect();
2182  translatedEventRect.translate(offset);
2183 
2184  int start = -1;
2185  int end = -1;
2186  if (d->orientation == Qt::Horizontal) {
2187  start = visualIndexAt(translatedEventRect.left());
2188  end = visualIndexAt(translatedEventRect.right());
2189  } else {
2190  start = visualIndexAt(translatedEventRect.top());
2191  end = visualIndexAt(translatedEventRect.bottom());
2192  }
2193 
2194  if (d->reverse()) {
2195  start = (start == -1 ? count() - 1 : start);
2196  end = (end == -1 ? 0 : end);
2197  } else {
2198  start = (start == -1 ? 0 : start);
2199  end = (end == -1 ? count() - 1 : end);
2200  }
2201 
2202  int tmp = start;
2203  start = qMin(start, end);
2204  end = qMax(tmp, end);
2205 
2206  d->prepareSectionSelected(); // clear and resize the bit array
2207 
2208  QRect currentSectionRect;
2209  int logical;
2210  const int width = d->viewport->width();
2211  const int height = d->viewport->height();
2212  for (int i = start; i <= end; ++i) {
2213  if (d->isVisualIndexHidden(i))
2214  continue;
2215  painter.save();
2216  logical = logicalIndex(i);
2217  if (d->orientation == Qt::Horizontal) {
2218  currentSectionRect.setRect(sectionViewportPosition(logical), 0, sectionSize(logical), height);
2219  } else {
2220  currentSectionRect.setRect(0, sectionViewportPosition(logical), width, sectionSize(logical));
2221  }
2222  currentSectionRect.translate(offset);
2223 
2224  QVariant variant = d->model->headerData(logical, d->orientation,
2225  Qt::FontRole);
2226  if (variant.isValid() && variant.canConvert<QFont>()) {
2227  QFont sectionFont = qvariant_cast<QFont>(variant);
2228  painter.setFont(sectionFont);
2229  }
2230  paintSection(&painter, currentSectionRect, logical);
2231  painter.restore();
2232  }
2233 
2234  QStyleOption opt;
2235  opt.init(this);
2236  // Paint the area beyond where there are indexes
2237  if (d->reverse()) {
2239  if (currentSectionRect.left() > translatedEventRect.left()) {
2240  opt.rect = QRect(translatedEventRect.left(), 0,
2241  currentSectionRect.left() - translatedEventRect.left(), height);
2242  style()->drawControl(QStyle::CE_HeaderEmptyArea, &opt, &painter, this);
2243  }
2244  } else if (currentSectionRect.right() < translatedEventRect.right()) {
2245  // paint to the right
2247  opt.rect = QRect(currentSectionRect.right() + 1, 0,
2248  translatedEventRect.right() - currentSectionRect.right(), height);
2249  style()->drawControl(QStyle::CE_HeaderEmptyArea, &opt, &painter, this);
2250  } else if (currentSectionRect.bottom() < translatedEventRect.bottom()) {
2251  // paint the bottom section
2252  opt.state &= ~QStyle::State_Horizontal;
2253  opt.rect = QRect(0, currentSectionRect.bottom() + 1,
2254  width, height - currentSectionRect.bottom() - 1);
2255  style()->drawControl(QStyle::CE_HeaderEmptyArea, &opt, &painter, this);
2256  }
2257 
2258 #if 0
2259  // ### visualize section spans
2260  for (int a = 0, i = 0; i < d->sectionSpans.count(); ++i) {
2261  QColor color((i & 4 ? 255 : 0), (i & 2 ? 255 : 0), (i & 1 ? 255 : 0));
2262  if (d->orientation == Qt::Horizontal)
2263  painter.fillRect(a - d->offset, 0, d->sectionSpans.at(i).size, 4, color);
2264  else
2265  painter.fillRect(0, a - d->offset, 4, d->sectionSpans.at(i).size, color);
2266  a += d->sectionSpans.at(i).size;
2267  }
2268 
2269 #endif
2270 }
2271 
2277 {
2278  Q_D(QHeaderView);
2279  if (d->state != QHeaderViewPrivate::NoState || e->button() != Qt::LeftButton)
2280  return;
2281  int pos = d->orientation == Qt::Horizontal ? e->x() : e->y();
2282  int handle = d->sectionHandleAt(pos);
2283  d->originalSize = -1; // clear the stored original size
2284  if (handle == -1) {
2285  d->pressed = logicalIndexAt(pos);
2286  if (d->clickableSections)
2287  emit sectionPressed(d->pressed);
2288  if (d->movableSections) {
2289  d->section = d->target = d->pressed;
2290  if (d->section == -1)
2291  return;
2293  d->setupSectionIndicator(d->section, pos);
2294  } else if (d->clickableSections && d->pressed != -1) {
2295  updateSection(d->pressed);
2297  }
2298  } else if (resizeMode(handle) == Interactive) {
2299  d->originalSize = sectionSize(handle);
2301  d->section = handle;
2302  }
2303 
2304  d->firstPos = pos;
2305  d->lastPos = pos;
2306 
2307  d->clearCascadingSections();
2308 }
2309 
2315 {
2316  Q_D(QHeaderView);
2317  int pos = d->orientation == Qt::Horizontal ? e->x() : e->y();
2318  if (pos < 0)
2319  return;
2320  if (e->buttons() == Qt::NoButton) {
2321 #if !defined(Q_WS_MAC)
2322  // Under Cocoa, when the mouse button is released, may include an extra
2323  // simulated mouse moved event. The state of the buttons when this event
2324  // is generated is already "no button" and the code below gets executed
2325  // just before the mouseReleaseEvent and resets the state. This prevents
2326  // column dragging from working. So this code is disabled under Cocoa.
2327  d->state = QHeaderViewPrivate::NoState;
2328  d->pressed = -1;
2329 #endif
2330  }
2331  switch (d->state) {
2333  Q_ASSERT(d->originalSize != -1);
2334  if (d->cascadingResizing) {
2335  int delta = d->reverse() ? d->lastPos - pos : pos - d->lastPos;
2336  int visual = visualIndex(d->section);
2337  d->cascadingResize(visual, d->headerSectionSize(visual) + delta);
2338  } else {
2339  int delta = d->reverse() ? d->firstPos - pos : pos - d->firstPos;
2340  resizeSection(d->section, qMax(d->originalSize + delta, minimumSectionSize()));
2341  }
2342  d->lastPos = pos;
2343  return;
2344  }
2346  if (qAbs(pos - d->firstPos) >= QApplication::startDragDistance()
2347  || !d->sectionIndicator->isHidden()) {
2348  int visual = visualIndexAt(pos);
2349  if (visual == -1)
2350  return;
2351  int posThreshold = d->headerSectionPosition(visual) - d->offset + d->headerSectionSize(visual) / 2;
2352  int moving = visualIndex(d->section);
2353  if (visual < moving) {
2354  if (pos < posThreshold)
2355  d->target = d->logicalIndex(visual);
2356  else
2357  d->target = d->logicalIndex(visual + 1);
2358  } else if (visual > moving) {
2359  if (pos > posThreshold)
2360  d->target = d->logicalIndex(visual);
2361  else
2362  d->target = d->logicalIndex(visual - 1);
2363  } else {
2364  d->target = d->section;
2365  }
2366  d->updateSectionIndicator(d->section, pos);
2367  }
2368  return;
2369  }
2371  int logical = logicalIndexAt(pos);
2372  if (logical == d->pressed)
2373  return; // nothing to do
2374  else if (d->pressed != -1)
2375  updateSection(d->pressed);
2376  d->pressed = logical;
2377  if (d->clickableSections && logical != -1) {
2378  emit sectionEntered(d->pressed);
2379  updateSection(d->pressed);
2380  }
2381  return;
2382  }
2384 #ifndef QT_NO_CURSOR
2385  int handle = d->sectionHandleAt(pos);
2386  bool hasCursor = testAttribute(Qt::WA_SetCursor);
2387  if (handle != -1 && (resizeMode(handle) == Interactive)) {
2388  if (!hasCursor)
2390  } else if (hasCursor) {
2391  unsetCursor();
2392  }
2393 #endif
2394  return;
2395  }
2396  default:
2397  break;
2398  }
2399 }
2400 
2406 {
2407  Q_D(QHeaderView);
2408  int pos = d->orientation == Qt::Horizontal ? e->x() : e->y();
2409  switch (d->state) {
2411  if (!d->sectionIndicator->isHidden()) { // moving
2412  int from = visualIndex(d->section);
2413  Q_ASSERT(from != -1);
2414  int to = visualIndex(d->target);
2415  Q_ASSERT(to != -1);
2416  moveSection(from, to);
2417  d->section = d->target = -1;
2418  d->updateSectionIndicator(d->section, pos);
2419  break;
2420  } // not moving
2422  if (!d->clickableSections) {
2423  int section = logicalIndexAt(pos);
2424  updateSection(section);
2425  }
2426  // fall through
2428  if (d->clickableSections) {
2429  int section = logicalIndexAt(pos);
2430  if (section != -1 && section == d->pressed) {
2431  d->flipSortIndicator(section);
2432  emit sectionClicked(section);
2433  }
2434  if (d->pressed != -1)
2435  updateSection(d->pressed);
2436  }
2437  break;
2439  d->originalSize = -1;
2440  d->clearCascadingSections();
2441  break;
2442  default:
2443  break;
2444  }
2445  d->state = QHeaderViewPrivate::NoState;
2446  d->pressed = -1;
2447 }
2448 
2454 {
2455  Q_D(QHeaderView);
2456  int pos = d->orientation == Qt::Horizontal ? e->x() : e->y();
2457  int handle = d->sectionHandleAt(pos);
2458  if (handle > -1 && resizeMode(handle) == Interactive) {
2460 #ifndef QT_NO_CURSOR
2461  Qt::CursorShape splitCursor = (d->orientation == Qt::Horizontal)
2463  if (cursor().shape() == splitCursor) {
2464  // signal handlers may have changed the section size
2465  handle = d->sectionHandleAt(pos);
2466  if (!(handle > -1 && resizeMode(handle) == Interactive))
2468  }
2469 #endif
2470  } else {
2472  }
2473 }
2474 
2480 {
2481  Q_D(QHeaderView);
2482  switch (e->type()) {
2483 #ifndef QT_NO_TOOLTIP
2484  case QEvent::ToolTip: {
2485  QHelpEvent *he = static_cast<QHelpEvent*>(e);
2486  int logical = logicalIndexAt(he->pos());
2487  if (logical != -1) {
2488  QVariant variant = d->model->headerData(logical, d->orientation, Qt::ToolTipRole);
2489  if (variant.isValid()) {
2490  QToolTip::showText(he->globalPos(), variant.toString(), this);
2491  return true;
2492  }
2493  }
2494  break; }
2495 #endif
2496 #ifndef QT_NO_WHATSTHIS
2497  case QEvent::QueryWhatsThis: {
2498  QHelpEvent *he = static_cast<QHelpEvent*>(e);
2499  int logical = logicalIndexAt(he->pos());
2500  if (logical != -1
2501  && d->model->headerData(logical, d->orientation, Qt::WhatsThisRole).isValid())
2502  return true;
2503  break; }
2504  case QEvent::WhatsThis: {
2505  QHelpEvent *he = static_cast<QHelpEvent*>(e);
2506  int logical = logicalIndexAt(he->pos());
2507  if (logical != -1) {
2508  QVariant whatsthis = d->model->headerData(logical, d->orientation,
2510  if (whatsthis.isValid()) {
2511  QWhatsThis::showText(he->globalPos(), whatsthis.toString(), this);
2512  return true;
2513  }
2514  }
2515  break; }
2516 #endif // QT_NO_WHATSTHIS
2517 #ifndef QT_NO_STATUSTIP
2518  case QEvent::StatusTip: {
2519  QHelpEvent *he = static_cast<QHelpEvent*>(e);
2520  int logical = logicalIndexAt(he->pos());
2521  if (logical != -1) {
2522  QString statustip = d->model->headerData(logical, d->orientation,
2523  Qt::StatusTipRole).toString();
2524  if (!statustip.isEmpty())
2525  setStatusTip(statustip);
2526  }
2527  return true; }
2528 #endif // QT_NO_STATUSTIP
2529  case QEvent::Hide:
2530  case QEvent::Show:
2531  case QEvent::FontChange:
2532  case QEvent::StyleChange:
2533  d->invalidateCachedSizeHint();
2534  resizeSections();
2536  break;
2537  case QEvent::ContextMenu: {
2538  d->state = QHeaderViewPrivate::NoState;
2539  d->pressed = d->section = d->target = -1;
2540  d->updateSectionIndicator(d->section, -1);
2541  break; }
2542  case QEvent::Wheel: {
2544  if (asa)
2545  return QApplication::sendEvent(asa->viewport(), e);
2546  break; }
2547  default:
2548  break;
2549  }
2551 }
2552 
2560 void QHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
2561 {
2562  Q_D(const QHeaderView);
2563  if (!rect.isValid())
2564  return;
2565  // get the state of the section
2566  QStyleOptionHeader opt;
2567  initStyleOption(&opt);
2569  if (isEnabled())
2570  state |= QStyle::State_Enabled;
2571  if (window()->isActiveWindow())
2572  state |= QStyle::State_Active;
2573  if (d->clickableSections) {
2574  if (logicalIndex == d->hover)
2575  state |= QStyle::State_MouseOver;
2576  if (logicalIndex == d->pressed)
2577  state |= QStyle::State_Sunken;
2578  else if (d->highlightSelected) {
2579  if (d->sectionIntersectsSelection(logicalIndex))
2580  state |= QStyle::State_On;
2581  if (d->isSectionSelected(logicalIndex))
2582  state |= QStyle::State_Sunken;
2583  }
2584 
2585  }
2589 
2590  // setup the style options structure
2591  QVariant textAlignment = d->model->headerData(logicalIndex, d->orientation,
2593  opt.rect = rect;
2594  opt.section = logicalIndex;
2595  opt.state |= state;
2596  opt.textAlignment = Qt::Alignment(textAlignment.isValid()
2597  ? Qt::Alignment(textAlignment.toInt())
2598  : d->defaultAlignment);
2599 
2601  opt.text = d->model->headerData(logicalIndex, d->orientation,
2602  Qt::DisplayRole).toString();
2603  if (d->textElideMode != Qt::ElideNone)
2604  opt.text = opt.fontMetrics.elidedText(opt.text, d->textElideMode , rect.width() - 4);
2605 
2606  QVariant variant = d->model->headerData(logicalIndex, d->orientation,
2608  opt.icon = qvariant_cast<QIcon>(variant);
2609  if (opt.icon.isNull())
2610  opt.icon = qvariant_cast<QPixmap>(variant);
2611  QVariant foregroundBrush = d->model->headerData(logicalIndex, d->orientation,
2613  if (foregroundBrush.canConvert<QBrush>())
2614  opt.palette.setBrush(QPalette::ButtonText, qvariant_cast<QBrush>(foregroundBrush));
2615 
2616  QPointF oldBO = painter->brushOrigin();
2617  QVariant backgroundBrush = d->model->headerData(logicalIndex, d->orientation,
2619  if (backgroundBrush.canConvert<QBrush>()) {
2620  opt.palette.setBrush(QPalette::Button, qvariant_cast<QBrush>(backgroundBrush));
2621  opt.palette.setBrush(QPalette::Window, qvariant_cast<QBrush>(backgroundBrush));
2622  painter->setBrushOrigin(opt.rect.topLeft());
2623  }
2624 
2625  // the section position
2626  int visual = visualIndex(logicalIndex);
2627  Q_ASSERT(visual != -1);
2628  if (count() == 1)
2630  else if (visual == 0)
2632  else if (visual == count() - 1)
2634  else
2636  opt.orientation = d->orientation;
2637  // the selected position
2638  bool previousSelected = d->isSectionSelected(this->logicalIndex(visual - 1));
2639  bool nextSelected = d->isSectionSelected(this->logicalIndex(visual + 1));
2640  if (previousSelected && nextSelected)
2642  else if (previousSelected)
2644  else if (nextSelected)
2646  else
2648  // draw the section
2649  style()->drawControl(QStyle::CE_Header, &opt, painter, this);
2650 
2651  painter->setBrushOrigin(oldBO);
2652 }
2653 
2662 {
2663  Q_D(const QHeaderView);
2664  Q_ASSERT(logicalIndex >= 0);
2665 
2666  ensurePolished();
2667 
2668  // use SizeHintRole
2669  QVariant variant = d->model->headerData(logicalIndex, d->orientation, Qt::SizeHintRole);
2670  if (variant.isValid())
2671  return qvariant_cast<QSize>(variant);
2672 
2673  // otherwise use the contents
2674  QStyleOptionHeader opt;
2675  initStyleOption(&opt);
2676  opt.section = logicalIndex;
2677  QVariant var = d->model->headerData(logicalIndex, d->orientation,
2678  Qt::FontRole);
2679  QFont fnt;
2680  if (var.isValid() && var.canConvert<QFont>())
2681  fnt = qvariant_cast<QFont>(var);
2682  else
2683  fnt = font();
2684  fnt.setBold(true);
2685  opt.fontMetrics = QFontMetrics(fnt);
2686  opt.text = d->model->headerData(logicalIndex, d->orientation,
2687  Qt::DisplayRole).toString();
2688  variant = d->model->headerData(logicalIndex, d->orientation, Qt::DecorationRole);
2689  opt.icon = qvariant_cast<QIcon>(variant);
2690  if (opt.icon.isNull())
2691  opt.icon = qvariant_cast<QPixmap>(variant);
2693  if (isSortIndicatorShown()) {
2694  int margin = style()->pixelMetric(QStyle::PM_HeaderMargin, &opt, this);
2695  if (d->orientation == Qt::Horizontal)
2696  size.rwidth() += size.height() + margin;
2697  else
2698  size.rheight() += size.width() + margin;
2699  }
2700  return size;
2701 }
2702 
2711 {
2712  Q_D(const QHeaderView);
2713  if (d->orientation == Qt::Horizontal)
2714  return d->offset;
2715  return 0;
2716 }
2717 
2726 {
2727  Q_D(const QHeaderView);
2728  if (d->orientation == Qt::Vertical)
2729  return d->offset;
2730  return 0;
2731 }
2732 
2739 {
2740  Q_D(QHeaderView);
2741  d->layoutChildren();
2742  if (d->hasAutoResizeSections())
2743  d->doDelayedResizeSections();
2744 }
2745 
2751 void QHeaderView::scrollContentsBy(int dx, int dy)
2752 {
2753  Q_D(QHeaderView);
2754  d->scrollDirtyRegion(dx, dy);
2755 }
2756 
2761 void QHeaderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
2762 {
2763  Q_D(QHeaderView);
2764  d->invalidateCachedSizeHint();
2765  if (d->hasAutoResizeSections()) {
2766  bool resizeRequired = d->globalResizeMode == ResizeToContents;
2767  int first = orientation() == Qt::Horizontal ? topLeft.column() : topLeft.row();
2768  int last = orientation() == Qt::Horizontal ? bottomRight.column() : bottomRight.row();
2769  for (int i = first; i <= last && !resizeRequired; ++i)
2770  resizeRequired = (resizeMode(i) == ResizeToContents);
2771  if (resizeRequired)
2772  d->doDelayedResizeSections();
2773  }
2774 }
2775 
2786 {
2787  // do nothing
2788 }
2789 
2801 {
2802  return QRect();
2803 }
2804 
2816 {
2817  // do nothing - the header only displays sections
2818 }
2819 
2831 {
2832  return QModelIndex();
2833 }
2834 
2846 {
2847  return true; // the header view has no items, just sections
2848 }
2849 
2861 {
2862  return QModelIndex();
2863 }
2864 
2877 void QHeaderView::setSelection(const QRect&, QItemSelectionModel::SelectionFlags)
2878 {
2879  // do nothing
2880 }
2881 
2887 {
2888  Q_D(const QHeaderView);
2889  const int max = d->modelSectionCount();
2890  if (d->orientation == Qt::Horizontal) {
2891  int left = max;
2892  int right = 0;
2893  int rangeLeft, rangeRight;
2894 
2895  for (int i = 0; i < selection.count(); ++i) {
2896  QItemSelectionRange r = selection.at(i);
2897  if (r.parent().isValid() || !r.isValid())
2898  continue; // we only know about toplevel items and we don't want invalid ranges
2899  // FIXME an item inside the range may be the leftmost or rightmost
2900  rangeLeft = visualIndex(r.left());
2901  if (rangeLeft == -1) // in some cases users may change the selections
2902  continue; // before we have a chance to do the layout
2903  rangeRight = visualIndex(r.right());
2904  if (rangeRight == -1) // in some cases users may change the selections
2905  continue; // before we have a chance to do the layout
2906  if (rangeLeft < left)
2907  left = rangeLeft;
2908  if (rangeRight > right)
2909  right = rangeRight;
2910  }
2911 
2912  int logicalLeft = logicalIndex(left);
2913  int logicalRight = logicalIndex(right);
2914 
2915  if (logicalLeft < 0 || logicalLeft >= count() ||
2916  logicalRight < 0 || logicalRight >= count())
2917  return QRegion();
2918 
2919  int leftPos = sectionViewportPosition(logicalLeft);
2920  int rightPos = sectionViewportPosition(logicalRight);
2921  rightPos += sectionSize(logicalRight);
2922  return QRect(leftPos, 0, rightPos - leftPos, height());
2923  }
2924  // orientation() == Qt::Vertical
2925  int top = max;
2926  int bottom = 0;
2927  int rangeTop, rangeBottom;
2928 
2929  for (int i = 0; i < selection.count(); ++i) {
2930  QItemSelectionRange r = selection.at(i);
2931  if (r.parent().isValid() || !r.isValid())
2932  continue; // we only know about toplevel items
2933  // FIXME an item inside the range may be the leftmost or rightmost
2934  rangeTop = visualIndex(r.top());
2935  if (rangeTop == -1) // in some cases users may change the selections
2936  continue; // before we have a chance to do the layout
2937  rangeBottom = visualIndex(r.bottom());
2938  if (rangeBottom == -1) // in some cases users may change the selections
2939  continue; // before we have a chance to do the layout
2940  if (rangeTop < top)
2941  top = rangeTop;
2942  if (rangeBottom > bottom)
2943  bottom = rangeBottom;
2944  }
2945 
2946  int logicalTop = logicalIndex(top);
2947  int logicalBottom = logicalIndex(bottom);
2948 
2949  if (logicalTop == -1 || logicalBottom == -1)
2950  return QRect();
2951 
2952  int topPos = sectionViewportPosition(logicalTop);
2953  int bottomPos = sectionViewportPosition(logicalBottom) + sectionSize(logicalBottom);
2954 
2955  return QRect(0, topPos, width(), bottomPos - topPos);
2956 }
2957 
2958 
2959 // private implementation
2960 
2962 {
2963  Q_Q(QHeaderView);
2964  int visual = q->visualIndexAt(position);
2965  if (visual == -1)
2966  return -1;
2967  int log = logicalIndex(visual);
2968  int pos = q->sectionViewportPosition(log);
2969  int grip = q->style()->pixelMetric(QStyle::PM_HeaderGripMargin, 0, q);
2970 
2971  bool atLeft = position < pos + grip;
2972  bool atRight = (position > pos + q->sectionSize(log) - grip);
2973  if (reverse())
2974  qSwap(atLeft, atRight);
2975 
2976  if (atLeft) {
2977  //grip at the beginning of the section
2978  while(visual > -1) {
2979  int logical = q->logicalIndex(--visual);
2980  if (!q->isSectionHidden(logical))
2981  return logical;
2982  }
2983  } else if (atRight) {
2984  //grip at the end of the section
2985  return log;
2986  }
2987  return -1;
2988 }
2989 
2991 {
2992  Q_Q(QHeaderView);
2993  if (!sectionIndicator) {
2994  sectionIndicator = new QLabel(viewport);
2995  }
2996 
2997  int w, h;
2998  int p = q->sectionViewportPosition(section);
2999  if (orientation == Qt::Horizontal) {
3000  w = q->sectionSize(section);
3001  h = viewport->height();
3002  } else {
3003  w = viewport->width();
3004  h = q->sectionSize(section);
3005  }
3006  sectionIndicator->resize(w, h);
3007 
3008  QPixmap pm(w, h);
3009  pm.fill(QColor(0, 0, 0, 45));
3010  QRect rect(0, 0, w, h);
3011 
3012  QPainter painter(&pm);
3013  painter.setOpacity(0.75);
3014  q->paintSection(&painter, rect, section);
3015  painter.end();
3016 
3017  sectionIndicator->setPixmap(pm);
3018  sectionIndicatorOffset = position - qMax(p, 0);
3019 }
3020 
3022 {
3023  if (!sectionIndicator)
3024  return;
3025 
3026  if (section == -1 || target == -1) {
3027  sectionIndicator->hide();
3028  return;
3029  }
3030 
3031  if (orientation == Qt::Horizontal)
3032  sectionIndicator->move(position - sectionIndicatorOffset, 0);
3033  else
3034  sectionIndicator->move(0, position - sectionIndicatorOffset);
3035 
3036  sectionIndicator->show();
3037 }
3038 
3047 {
3048  Q_D(const QHeaderView);
3049  option->initFrom(this);
3051  option->orientation = d->orientation;
3052  if (d->orientation == Qt::Horizontal)
3053  option->state |= QStyle::State_Horizontal;
3054  if (isEnabled())
3055  option->state |= QStyle::State_Enabled;
3056  option->section = 0;
3057 }
3058 
3060 {
3061  int i = section * 2;
3062  if (i < 0 || i >= sectionSelected.count())
3063  return false;
3064  if (sectionSelected.testBit(i)) // if the value was cached
3065  return sectionSelected.testBit(i + 1);
3066  bool s = false;
3067  if (orientation == Qt::Horizontal)
3068  s = isColumnSelected(section);
3069  else
3070  s = isRowSelected(section);
3071  sectionSelected.setBit(i + 1, s); // selection state
3072  sectionSelected.setBit(i, true); // cache state
3073  return s;
3074 }
3075 
3084 {
3085  Q_Q(const QHeaderView);
3086  for (int visual = q->count()-1; visual >= 0; --visual) {
3087  if (!q->isSectionHidden(q->logicalIndex(visual)))
3088  return visual;
3089  }
3090 
3091  //default value if no section is actually visible
3092  return -1;
3093 }
3094 
3112 {
3113  Q_Q(QHeaderView);
3114  //stop the timer in case it is delayed
3115  delayedResize.stop();
3116 
3117  executePostedLayout();
3118  if (sectionCount == 0)
3119  return;
3120 
3121  if (resizeRecursionBlock)
3122  return;
3123  resizeRecursionBlock = true;
3124 
3125  invalidateCachedSizeHint();
3126 
3127  const int lastVisibleSection = lastVisibleVisualIndex();
3128 
3129  // find stretchLastSection if we have it
3130  int stretchSection = -1;
3131  if (stretchLastSection && !useGlobalMode)
3132  stretchSection = lastVisibleVisualIndex();
3133 
3134  // count up the number of strected sections and how much space left for them
3135  int lengthToStrech = (orientation == Qt::Horizontal ? viewport->width() : viewport->height());
3136  int numberOfStretchedSections = 0;
3137  QList<int> section_sizes;
3138  for (int i = 0; i < sectionCount; ++i) {
3139  if (isVisualIndexHidden(i))
3140  continue;
3141 
3143  if (useGlobalMode && (i != stretchSection))
3144  resizeMode = globalMode;
3145  else
3146  resizeMode = (i == stretchSection ? QHeaderView::Stretch : headerSectionResizeMode(i));
3147 
3148  if (resizeMode == QHeaderView::Stretch) {
3149  ++numberOfStretchedSections;
3150  section_sizes.append(headerSectionSize(i));
3151  continue;
3152  }
3153 
3154  // because it isn't stretch, determine its width and remove that from lengthToStrech
3155  int sectionSize = 0;
3156  if (resizeMode == QHeaderView::Interactive || resizeMode == QHeaderView::Fixed) {
3157  sectionSize = headerSectionSize(i);
3158  } else { // resizeMode == QHeaderView::ResizeToContents
3159  int logicalIndex = q->logicalIndex(i);
3160  sectionSize = qMax(viewSectionSizeHint(logicalIndex),
3161  q->sectionSizeHint(logicalIndex));
3162  }
3163  section_sizes.append(sectionSize);
3164  lengthToStrech -= sectionSize;
3165  }
3166 
3167  // calculate the new length for all of the stretched sections
3168  int stretchSectionLength = -1;
3169  int pixelReminder = 0;
3170  if (numberOfStretchedSections > 0 && lengthToStrech > 0) { // we have room to stretch in
3171  int hintLengthForEveryStretchedSection = lengthToStrech / numberOfStretchedSections;
3172  stretchSectionLength = qMax(hintLengthForEveryStretchedSection, q->minimumSectionSize());
3173  pixelReminder = lengthToStrech % numberOfStretchedSections;
3174  }
3175 
3176  int spanStartSection = 0;
3177  int previousSectionLength = 0;
3178 
3179  QHeaderView::ResizeMode previousSectionResizeMode = QHeaderView::Interactive;
3180 
3181  // resize each section along the total length
3182  for (int i = 0; i < sectionCount; ++i) {
3183  int oldSectionLength = headerSectionSize(i);
3184  int newSectionLength = -1;
3185  QHeaderView::ResizeMode newSectionResizeMode = headerSectionResizeMode(i);
3186 
3187  if (isVisualIndexHidden(i)) {
3188  newSectionLength = 0;
3189  } else {
3191  if (useGlobalMode)
3192  resizeMode = globalMode;
3193  else
3194  resizeMode = (i == stretchSection
3196  : newSectionResizeMode);
3197  if (resizeMode == QHeaderView::Stretch && stretchSectionLength != -1) {
3198  if (i == lastVisibleSection)
3199  newSectionLength = qMax(stretchSectionLength, lastSectionSize);
3200  else
3201  newSectionLength = stretchSectionLength;
3202  if (pixelReminder > 0) {
3203  newSectionLength += 1;
3204  --pixelReminder;
3205  }
3206  section_sizes.removeFirst();
3207  } else {
3208  newSectionLength = section_sizes.front();
3209  section_sizes.removeFirst();
3210  }
3211  }
3212 
3213  //Q_ASSERT(newSectionLength > 0);
3214  if ((previousSectionResizeMode != newSectionResizeMode
3215  || previousSectionLength != newSectionLength) && i > 0) {
3216  int spanLength = (i - spanStartSection) * previousSectionLength;
3217  createSectionSpan(spanStartSection, i - 1, spanLength, previousSectionResizeMode);
3218  //Q_ASSERT(headerLength() == length);
3219  spanStartSection = i;
3220  }
3221 
3222  if (newSectionLength != oldSectionLength)
3223  emit q->sectionResized(logicalIndex(i), oldSectionLength, newSectionLength);
3224 
3225  previousSectionLength = newSectionLength;
3226  previousSectionResizeMode = newSectionResizeMode;
3227  }
3228 
3229  createSectionSpan(spanStartSection, sectionCount - 1,
3230  (sectionCount - spanStartSection) * previousSectionLength,
3231  previousSectionResizeMode);
3232  //Q_ASSERT(headerLength() == length);
3233  resizeRecursionBlock = false;
3234  viewport->update();
3235 }
3236 
3238 {
3239  // ### the code for merging spans does not merge at all opertuneties
3240  // ### what if the number of sections is reduced ?
3241 
3242  SectionSpan span(size, (end - start) + 1, mode);
3243  int start_section = 0;
3244 #ifndef QT_NO_DEBUG
3245  int initial_section_count = headerSectionCount(); // ### debug code
3246 #endif
3247 
3248  QList<int> spansToRemove;
3249  for (int i = 0; i < sectionSpans.count(); ++i) {
3250  int end_section = start_section + sectionSpans.at(i).count - 1;
3251  int section_count = sectionSpans.at(i).count;
3252  if (start <= start_section && end > end_section) {
3253  // the existing span is entirely coveded by the new span
3254  spansToRemove.append(i);
3255  } else if (start < start_section && end >= end_section) {
3256  // the existing span is entirely coveded by the new span
3257  spansToRemove.append(i);
3258  } else if (start == start_section && end == end_section) {
3259  // the new span is covered by an existin span
3260  length -= sectionSpans.at(i).size;
3261  length += size;
3262  sectionSpans[i].size = size;
3263  sectionSpans[i].resizeMode = mode;
3264  // ### check if we can merge the section with any of its neighbours
3265  removeSpans(spansToRemove);
3266  Q_ASSERT(initial_section_count == headerSectionCount());
3267  return;
3268  } else if (start > start_section && end < end_section) {
3269  if (sectionSpans.at(i).sectionSize() == span.sectionSize()
3270  && sectionSpans.at(i).resizeMode == span.resizeMode) {
3271  Q_ASSERT(initial_section_count == headerSectionCount());
3272  return;
3273  }
3274  // the new span is in the middle of the old span, so we have to split it
3275  length -= sectionSpans.at(i).size;
3276  int section_size = sectionSpans.at(i).sectionSize();
3277 #ifndef QT_NO_DEBUG
3278  int span_count = sectionSpans.at(i).count;
3279 #endif
3280  QHeaderView::ResizeMode span_mode = sectionSpans.at(i).resizeMode;
3281  // first span
3282  int first_span_count = start - start_section;
3283  int first_span_size = section_size * first_span_count;
3284  sectionSpans[i].count = first_span_count;
3285  sectionSpans[i].size = first_span_size;
3286  sectionSpans[i].resizeMode = span_mode;
3287  length += first_span_size;
3288  // middle span (the new span)
3289 #ifndef QT_NO_DEBUG
3290  int mid_span_count = span.count;
3291 #endif
3292  int mid_span_size = span.size;
3293  sectionSpans.insert(i + 1, span);
3294  length += mid_span_size;
3295  // last span
3296  int last_span_count = end_section - end;
3297  int last_span_size = section_size * last_span_count;
3298  sectionSpans.insert(i + 2, SectionSpan(last_span_size, last_span_count, span_mode));
3299  length += last_span_size;
3300  Q_ASSERT(span_count == first_span_count + mid_span_count + last_span_count);
3301  removeSpans(spansToRemove);
3302  Q_ASSERT(initial_section_count == headerSectionCount());
3303  return;
3304  } else if (start > start_section && start <= end_section && end >= end_section) {
3305  // the new span covers the last part of the existing span
3306  length -= sectionSpans.at(i).size;
3307  int removed_count = (end_section - start + 1);
3308  int span_count = sectionSpans.at(i).count - removed_count;
3309  int section_size = sectionSpans.at(i).sectionSize();
3310  int span_size = section_size * span_count;
3311  sectionSpans[i].count = span_count;
3312  sectionSpans[i].size = span_size;
3313  length += span_size;
3314  if (end == end_section) {
3315  sectionSpans.insert(i + 1, span); // insert after
3316  length += span.size;
3317  removeSpans(spansToRemove);
3318  Q_ASSERT(initial_section_count == headerSectionCount());
3319  return;
3320  }
3321  } else if (end < end_section && end >= start_section && start <= start_section) {
3322  // the new span covers the first part of the existing span
3323  length -= sectionSpans.at(i).size;
3324  int removed_count = (end - start_section + 1);
3325  int section_size = sectionSpans.at(i).sectionSize();
3326  int span_count = sectionSpans.at(i).count - removed_count;
3327  int span_size = section_size * span_count;
3328  sectionSpans[i].count = span_count;
3329  sectionSpans[i].size = span_size;
3330  length += span_size;
3331  sectionSpans.insert(i, span); // insert before
3332  length += span.size;
3333  removeSpans(spansToRemove);
3334  Q_ASSERT(initial_section_count == headerSectionCount());
3335  return;
3336  }
3337  start_section += section_count;
3338  }
3339 
3340  // ### adding and removing _ sections_ in addition to spans
3341  // ### add some more checks here
3342 
3343  if (spansToRemove.isEmpty()) {
3344  if (!sectionSpans.isEmpty()
3345  && sectionSpans.last().sectionSize() == span.sectionSize()
3346  && sectionSpans.last().resizeMode == span.resizeMode) {
3347  length += span.size;
3348  int last = sectionSpans.count() - 1;
3349  sectionSpans[last].count += span.count;
3350  sectionSpans[last].size += span.size;
3351  sectionSpans[last].resizeMode = span.resizeMode;
3352  } else {
3353  length += span.size;
3354  sectionSpans.append(span);
3355  }
3356  } else {
3357  removeSpans(spansToRemove);
3358  length += span.size;
3359  sectionSpans.insert(spansToRemove.first(), span);
3360  //Q_ASSERT(initial_section_count == headerSectionCount());
3361  }
3362 }
3363 
3365 {
3366  // remove sections
3367  int start_section = 0;
3368  QList<int> spansToRemove;
3369  for (int i = 0; i < sectionSpans.count(); ++i) {
3370  int end_section = start_section + sectionSpans.at(i).count - 1;
3371  int section_size = sectionSpans.at(i).sectionSize();
3372  int section_count = sectionSpans.at(i).count;
3373  if (start <= start_section && end >= end_section) {
3374  // the change covers the entire span
3375  spansToRemove.append(i);
3376  if (end == end_section)
3377  break;
3378  } else if (start > start_section && end < end_section) {
3379  // all the removed sections are inside the span
3380  int change = (end - start + 1);
3381  sectionSpans[i].count -= change;
3382  sectionSpans[i].size = section_size * sectionSpans.at(i).count;
3383  length -= (change * section_size);
3384  break;
3385  } else if (start >= start_section && start <= end_section) {
3386  // the some of the removed sections are inside the span,at the end
3387  int change = qMin(end_section - start + 1, end - start + 1);
3388  sectionSpans[i].count -= change;
3389  sectionSpans[i].size = section_size * sectionSpans.at(i).count;
3390  start += change;
3391  length -= (change * section_size);
3392  // the change affects several spans
3393  } else if (end >= start_section && end <= end_section) {
3394  // the some of the removed sections are inside the span, at the beginning
3395  int change = qMin((end - start_section + 1), end - start + 1);
3396  sectionSpans[i].count -= change;
3397  sectionSpans[i].size = section_size * sectionSpans.at(i).count;
3398  length -= (change * section_size);
3399  break;
3400  }
3401  start_section += section_count;
3402  }
3403 
3404  for (int i = spansToRemove.count() - 1; i >= 0; --i) {
3405  int s = spansToRemove.at(i);
3406  length -= sectionSpans.at(s).size;
3407  sectionSpans.remove(s);
3408  // ### merge remaining spans
3409  }
3410 }
3411 
3413 {
3414  if (state != NoClear) {
3415  length = 0;
3416  sectionCount = 0;
3417  visualIndices.clear();
3418  logicalIndices.clear();
3419  sectionSelected.clear();
3420  sectionHidden.clear();
3421  hiddenSectionSize.clear();
3422  sectionSpans.clear();
3423  invalidateCachedSizeHint();
3424  }
3425 }
3426 
3428 {
3429  Q_Q(QHeaderView);
3430  Qt::SortOrder sortOrder;
3431  if (sortIndicatorSection == section) {
3433  } else {
3434  const QVariant value = model->headerData(section, orientation, Qt::InitialSortOrderRole);
3435  if (value.canConvert(QVariant::Int))
3436  sortOrder = static_cast<Qt::SortOrder>(value.toInt());
3437  else
3438  sortOrder = Qt::AscendingOrder;
3439  }
3440  q->setSortIndicator(section, sortOrder);
3441 }
3442 
3443 void QHeaderViewPrivate::cascadingResize(int visual, int newSize)
3444 {
3445  Q_Q(QHeaderView);
3446  const int minimumSize = q->minimumSectionSize();
3447  const int oldSize = headerSectionSize(visual);
3448  int delta = newSize - oldSize;
3449 
3450  if (delta > 0) { // larger
3451  bool sectionResized = false;
3452 
3453  // restore old section sizes
3454  for (int i = firstCascadingSection; i < visual; ++i) {
3455  if (cascadingSectionSize.contains(i)) {
3456  int currentSectionSize = headerSectionSize(i);
3457  int originalSectionSize = cascadingSectionSize.value(i);
3458  if (currentSectionSize < originalSectionSize) {
3459  int newSectionSize = currentSectionSize + delta;
3460  resizeSectionSpan(i, currentSectionSize, newSectionSize);
3461  if (newSectionSize >= originalSectionSize && false)
3462  cascadingSectionSize.remove(i); // the section is now restored
3463  sectionResized = true;
3464  break;
3465  }
3466  }
3467 
3468  }
3469 
3470  // resize the section
3471  if (!sectionResized) {
3472  newSize = qMax(newSize, minimumSize);
3473  if (oldSize != newSize)
3474  resizeSectionSpan(visual, oldSize, newSize);
3475  }
3476 
3477  // cascade the section size change
3478  for (int i = visual + 1; i < sectionCount; ++i) {
3479  if (!sectionIsCascadable(i))
3480  continue;
3481  int currentSectionSize = headerSectionSize(i);
3482  if (currentSectionSize <= minimumSize)
3483  continue;
3484  int newSectionSize = qMax(currentSectionSize - delta, minimumSize);
3485  //qDebug() << "### cascading to" << i << newSectionSize - currentSectionSize << delta;
3486  resizeSectionSpan(i, currentSectionSize, newSectionSize);
3487  saveCascadingSectionSize(i, currentSectionSize);
3488  delta = delta - (currentSectionSize - newSectionSize);
3489  //qDebug() << "new delta" << delta;
3490  //if (newSectionSize != minimumSize)
3491  if (delta <= 0)
3492  break;
3493  }
3494  } else { // smaller
3495  bool sectionResized = false;
3496 
3497  // restore old section sizes
3498  for (int i = lastCascadingSection; i > visual; --i) {
3499  if (!cascadingSectionSize.contains(i))
3500  continue;
3501  int currentSectionSize = headerSectionSize(i);
3502  int originalSectionSize = cascadingSectionSize.value(i);
3503  if (currentSectionSize >= originalSectionSize)
3504  continue;
3505  int newSectionSize = currentSectionSize - delta;
3506  resizeSectionSpan(i, currentSectionSize, newSectionSize);
3507  if (newSectionSize >= originalSectionSize && false) {
3508  //qDebug() << "section" << i << "restored to" << originalSectionSize;
3509  cascadingSectionSize.remove(i); // the section is now restored
3510  }
3511  sectionResized = true;
3512  break;
3513  }
3514 
3515  // resize the section
3516  resizeSectionSpan(visual, oldSize, qMax(newSize, minimumSize));
3517 
3518  // cascade the section size change
3519  if (delta < 0 && newSize < minimumSize) {
3520  for (int i = visual - 1; i >= 0; --i) {
3521  if (!sectionIsCascadable(i))
3522  continue;
3523  int sectionSize = headerSectionSize(i);
3524  if (sectionSize <= minimumSize)
3525  continue;
3526  resizeSectionSpan(i, sectionSize, qMax(sectionSize + delta, minimumSize));
3527  saveCascadingSectionSize(i, sectionSize);
3528  break;
3529  }
3530  }
3531 
3532  // let the next section get the space from the resized section
3533  if (!sectionResized) {
3534  for (int i = visual + 1; i < sectionCount; ++i) {
3535  if (!sectionIsCascadable(i))
3536  continue;
3537  int currentSectionSize = headerSectionSize(i);
3538  int newSectionSize = qMax(currentSectionSize - delta, minimumSize);
3539  resizeSectionSpan(i, currentSectionSize, newSectionSize);
3540  break;
3541  }
3542  }
3543  }
3544 
3545  if (hasAutoResizeSections())
3546  doDelayedResizeSections();
3547 
3548  viewport->update();
3549 }
3550 
3552 {
3553  Q_Q(QHeaderView);
3555  int currentVisualIndex = 0;
3556  for (int i = 0; i < sectionSpans.count(); ++i) {
3557  QHeaderViewPrivate::SectionSpan &span = sectionSpans[i];
3558  if (span.size > 0) {
3559  //we resize it if it is not hidden (ie size > 0)
3560  const int newSize = span.count * size;
3561  if (newSize != span.size) {
3562  length += newSize - span.size; //the whole length is changed
3563  const int oldSectionSize = span.sectionSize();
3564  span.size = span.count * size;
3565  for (int i = currentVisualIndex; i < currentVisualIndex + span.count; ++i) {
3566  emit q->sectionResized(logicalIndex(i), oldSectionSize, size);
3567  }
3568  }
3569  }
3570  currentVisualIndex += span.count;
3571  }
3572 }
3573 
3574 void QHeaderViewPrivate::resizeSectionSpan(int visualIndex, int oldSize, int newSize)
3575 {
3576  Q_Q(QHeaderView);
3577  QHeaderView::ResizeMode mode = headerSectionResizeMode(visualIndex);
3578  createSectionSpan(visualIndex, visualIndex, newSize, mode);
3579  emit q->sectionResized(logicalIndex(visualIndex), oldSize, newSize);
3580 }
3581 
3583 {
3584  // ### stupid iteration
3585  int section_start = 0;
3586  const int sectionSpansCount = sectionSpans.count();
3587  for (int i = 0; i < sectionSpansCount; ++i) {
3588  const QHeaderViewPrivate::SectionSpan &currentSection = sectionSpans.at(i);
3589  int section_end = section_start + currentSection.count - 1;
3590  if (visual >= section_start && visual <= section_end)
3591  return currentSection.sectionSize();
3592  section_start = section_end + 1;
3593  }
3594  return -1;
3595 }
3596 
3598 {
3599  // ### stupid iteration
3600  int section_start = 0;
3601  int span_position = 0;
3602  const int sectionSpansCount = sectionSpans.count();
3603  for (int i = 0; i < sectionSpansCount; ++i) {
3604  const QHeaderViewPrivate::SectionSpan &currentSection = sectionSpans.at(i);
3605  int section_end = section_start + currentSection.count - 1;
3606  if (visual >= section_start && visual <= section_end)
3607  return span_position + (visual - section_start) * currentSection.sectionSize();
3608  section_start = section_end + 1;
3609  span_position += currentSection.size;
3610  }
3611  return -1;
3612 }
3613 
3615 {
3616  // ### stupid iteration
3617  int span_start_section = 0;
3618  int span_position = 0;
3619  const int sectionSpansCount = sectionSpans.count();
3620  for (int i = 0; i < sectionSpansCount; ++i) {
3621  const QHeaderViewPrivate::SectionSpan &currentSection = sectionSpans.at(i);
3622  int next_span_start_section = span_start_section + currentSection.count;
3623  int next_span_position = span_position + currentSection.size;
3624  if (position == span_position && currentSection.size > 0)
3625  return span_start_section;
3626  if (position > span_position && position < next_span_position) {
3627  int position_in_span = position - span_position;
3628  return span_start_section + (position_in_span / currentSection.sectionSize());
3629  }
3630  span_start_section = next_span_start_section;
3631  span_position = next_span_position;
3632  }
3633  return -1;
3634 }
3635 
3637 {
3638  int size = headerSectionSize(visual);
3639  createSectionSpan(visual, visual, size, mode);
3640 }
3641 
3643 {
3644  int span = sectionSpanIndex(visual);
3645  if (span == -1)
3646  return globalResizeMode;
3647  return sectionSpans.at(span).resizeMode;
3648 }
3649 
3651 {
3652  globalResizeMode = mode;
3653  for (int i = 0; i < sectionSpans.count(); ++i)
3654  sectionSpans[i].resizeMode = mode;
3655 }
3656 
3658 {
3659  if (QAbstractItemView *view = qobject_cast<QAbstractItemView*>(parent)) {
3660  return (orientation == Qt::Horizontal
3661  ? view->sizeHintForColumn(logical)
3662  : view->sizeHintForRow(logical));
3663  }
3664  return 0;
3665 }
3666 
3668 {
3669  if (hiddenSectionSize.count() > 0) {
3670  int adjustedVisualIndex = visualIndex;
3671  int currentVisualIndex = 0;
3672  for (int i = 0; i < sectionSpans.count(); ++i) {
3673  if (sectionSpans.at(i).size == 0)
3674  adjustedVisualIndex += sectionSpans.at(i).count;
3675  else
3676  currentVisualIndex += sectionSpans.at(i).count;
3677  if (currentVisualIndex >= visualIndex)
3678  break;
3679  }
3680  visualIndex = adjustedVisualIndex;
3681  }
3682  return visualIndex;
3683 }
3684 
3685 #ifndef QT_NO_DATASTREAM
3687 {
3688  out << int(orientation);
3689  out << int(sortIndicatorOrder);
3690  out << sortIndicatorSection;
3691  out << sortIndicatorShown;
3692 
3693  out << visualIndices;
3694  out << logicalIndices;
3695 
3696  out << sectionHidden;
3697  out << hiddenSectionSize;
3698 
3699  out << length;
3700  out << sectionCount;
3701  out << movableSections;
3702  out << clickableSections;
3703  out << highlightSelected;
3704  out << stretchLastSection;
3705  out << cascadingResizing;
3706  out << stretchSections;
3707  out << contentsSections;
3708  out << defaultSectionSize;
3709  out << minimumSectionSize;
3710 
3711  out << int(defaultAlignment);
3712  out << int(globalResizeMode);
3713 
3714  out << sectionSpans;
3715 }
3716 
3718 {
3719  int orient, order, align, global;
3720  in >> orient;
3721  orientation = (Qt::Orientation)orient;
3722 
3723  in >> order;
3725 
3726  in >> sortIndicatorSection;
3727  in >> sortIndicatorShown;
3728 
3729  in >> visualIndices;
3730  in >> logicalIndices;
3731 
3732  in >> sectionHidden;
3733  in >> hiddenSectionSize;
3734 
3735  in >> length;
3736  in >> sectionCount;
3737  in >> movableSections;
3738  in >> clickableSections;
3739  in >> highlightSelected;
3740  in >> stretchLastSection;
3741  in >> cascadingResizing;
3742  in >> stretchSections;
3743  in >> contentsSections;
3744  in >> defaultSectionSize;
3745  in >> minimumSectionSize;
3746 
3747  in >> align;
3748  defaultAlignment = Qt::Alignment(align);
3749 
3750  in >> global;
3751  globalResizeMode = (QHeaderView::ResizeMode)global;
3752 
3753  in >> sectionSpans;
3754 
3755  return true;
3756 }
3757 
3758 #endif // QT_NO_DATASTREAM
3759 
3761 
3762 #endif // QT_NO_ITEMVIEWS
3763 
3764 #include "moc_qheaderview.cpp"
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex)
This signal is emitted when a section is moved.
QPoint pos() const
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
Status status() const
Returns the status of the data stream.
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
This slot is called when rows are about to be removed.
void setMinimumSectionSize(int size)
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
void resizeSections()
Resizes the sections according to their size hints.
int defaultSectionSize() const
static QAbstractItemModel * staticEmptyModel()
QHeaderView(Qt::Orientation orientation, QWidget *parent=0)
Creates a new generic header with the given orientation and parent.
int left() const
Returns the column index corresponding to the leftmost selected column in the selection range...
void mouseMoveEvent(QMouseEvent *e)
Reimplemented Function
QRegion visualRegionForSelection(const QItemSelection &selection) const
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
int sectionSizeHint(int logicalIndex) const
Returns a suitable size hint for the section specified by logicalIndex.
void setOffset(int offset)
Sets the header&#39;s offset to offset.
QSize size() const
int viewSectionSizeHint(int logical) const
void _q_layoutChanged()
This slot is called when the layout is changed.
QCursor cursor() const
int headerSectionSize(int visual) const
void setGlobalHeaderResizeMode(QHeaderView::ResizeMode mode)
void scrollTo(const QModelIndex &index, ScrollHint hint)
Empty implementation because the header doesn&#39;t show QModelIndex items.
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
void unsetCursor()
Definition: qwidget.cpp:5311
void sectionResized(int logicalIndex, int oldSize, int newSize)
This signal is emitted when a section is resized.
int maxWidth() const
Returns the width of the widest character in the font.
void setModel(QAbstractItemModel *model)
Reimplemented Function
int horizontalOffset() const
Returns the horizontal offset of the header.
void scrollContentsBy(int dx, int dy)
Reimplemented Function
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
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
int sortIndicatorSection() const
Returns the logical index of the section that has a sort indicator.
void setHighlightSections(bool highlight)
virtual ~QHeaderView()
Destroys the header.
void setStretchLastSection(bool stretch)
int visualIndex(int logicalIndex) const
Returns the visual index position of the section specified by the given logicalIndex, or -1 otherwise.
void rowsInserted(const QModelIndex &parent, int start, int end)
Empty implementation because the header doesn&#39;t show QModelIndex items.
void initStyleOption(QStyleOptionHeader *option) const
Initialize option with the values from this QHeaderView.
static QSize globalStrut()
bool isValid() const
Returns true if the selection range is valid; otherwise returns false.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
ResizeMode resizeMode(int logicalIndex) const
Returns the resize mode that applies to the section specified by the given logicalIndex.
void paintEvent(QPaintEvent *e)
Reimplemented Function
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
void setDefaultAlignment(Qt::Alignment alignment)
void mousePressEvent(QMouseEvent *e)
Reimplemented Function
int headerVisualIndexAt(int position) const
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static C reverse(const C &l)
The QHoverEvent class contains parameters that describe a mouse event.
Definition: qevent.h:125
friend class QFontMetrics
Definition: qwidget.h:749
#define SLOT(a)
Definition: qobjectdefs.h:226
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void cascadingResize(int visual, int newSize)
void setupSectionIndicator(int section, int position)
void sectionsAboutToBeRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast)
This slot is called when sections are removed from the parent.
bool highlightSections() const
QSize sizeHint() const
Returns a suitable size hint for this header.
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QRect normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:322
void write(QDataStream &out) const
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy)
The QItemSelectionRange class manages information about a range of selected items in a model...
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags)
Selects the items in the given rect according to the specified flags.
QHeaderView::ResizeMode headerSectionResizeMode(int visual) const
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
void init(const QWidget *w)
Use initFrom(widget) instead.
void updateHiddenSections(int logicalFirst, int logicalLast)
bool updatesEnabled() const
void sectionClicked(int logicalIndex)
This signal is emitted when a section is clicked.
SortIndicator sortIndicator
the direction the sort indicator should be drawn
Definition: qstyleoption.h:269
int bottom() const
Returns the row index corresponding to the lowermost selected row in the selection range...
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.
void initialize()
int right() const
Returns the column index corresponding to the rightmost selected column in the selection range...
QString text
the text of the header
Definition: qstyleoption.h:263
bool isActiveWindow() const
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
int minimumSectionSize() const
T * qobject_cast(QObject *object)
Definition: qobject.h:375
virtual void doItemsLayout()
This function is intended to lay out the items in the view.
ResizeMode
The resize mode specifies the behavior of the header sections.
Definition: qheaderview.h:72
void resizeSection(int logicalIndex, int size)
Resizes the section specified by logicalIndex to size measured in pixels.
static void setPos(int x, int y)
Moves the cursor (hot spot) to the global screen position (x, y).
Definition: qcursor_mac.mm:315
bool read(QDataStream &in)
bool testBit(int i) const
Returns true if the bit at index position i is 1; otherwise returns false.
Definition: qbitarray.h:124
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void moveSection(int from, int to)
Moves the section at visual index from to occupy visual index to.
int height() const
bool sectionsMoved() const
Returns true if sections in the header has been moved; otherwise returns false;.
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
Qt::Orientation orientation
the header&#39;s orientation (horizontal or vertical)
Definition: qstyleoption.h:270
QModelIndex parent() const
Returns the parent model item index of the items in the selection range.
int headerSectionPosition(int visual) const
Qt::Alignment textAlignment
the alignment flags for the text of the header
Definition: qstyleoption.h:264
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)
void read(QDataStream &in)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns the data for the given role and section in the header with the specified orientation.
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags=0) const
If the string text is wider than width, returns an elided version of the string (i.
void sectionCountChanged(int oldCount, int newCount)
This signal is emitted when the number of sections changes, i.
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
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
bool cascadingSectionResizes() const
int lastVisibleVisualIndex() const
Returns the last visible (ie.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QRect visualRect(const QModelIndex &index) const
Empty implementation because the header doesn&#39;t show QModelIndex items.
QWidget * viewport() const
Returns the viewport widget.
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...
#define SIGNAL(a)
Definition: qobjectdefs.h:227
for(int ii=mo->methodOffset();ii< mo->methodCount();++ii)
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 updateSection(int logicalIndex)
Updates the section specified by the given logicalIndex.
bool fill(bool val, int size=-1)
Sets every bit in the bit array to value, returning true if successful; otherwise returns false...
Definition: qbitarray.h:117
bool sectionsHidden() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
int offset() const
Returns the offset of the header: this is the header&#39;s left-most (or top-most for vertical headers) v...
T & front()
This function is provided for STL compatibility.
Definition: qlist.h:298
static FILE * stream
QPoint brushOrigin() const
Returns the currently set brush origin.
Definition: qpainter.cpp:2168
void setClickable(bool clickable)
If clickable is true, the header will respond to single clicks.
bool viewportEvent(QEvent *e)
Reimplemented Function
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
bool isMovable() const
Returns true if the header can be moved by the user; otherwise returns false.
QByteArray saveState() const
Saves the current state of this header view.
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
void setOffsetToSectionPosition(int visualIndex)
Sets the offset to the start of the section at the given visualIndex.
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
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
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Qt::Orientation orientation() const
Returns the orientation of the header.
int width() const
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
int row() const
Returns the row this model index refers to.
void setCascadingSectionResizes(bool enable)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
void setStatusTip(const QString &)
Definition: qwidget.cpp:11629
virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
Paints the section specified by the given logicalIndex, using the given painter and rect...
QWidgetData * data
Definition: qwidget.h:815
void resize(int size)
Resizes the bit array to size bits.
Definition: qbitarray.cpp:214
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
void currentChanged(const QModelIndex &current, const QModelIndex &old)
Reimplemented Function
void sectionEntered(int logicalIndex)
This signal is emitted when the cursor moves over the section and the left mouse button is pressed...
void sectionPressed(int logicalIndex)
This signal is emitted when a section is pressed.
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
void removeFirst()
Removes the first item in the list.
Definition: qlist.h:286
virtual void reset()
Reset the internal state of the view.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
static int startDragDistance()
void reset()
Reimplemented Function
bool isClickable() const
Returns true if the header is clickable; otherwise returns false.
void mouseDoubleClickEvent(QMouseEvent *e)
Reimplemented Function
void show()
Shows the widget and its child widgets.
void removeSectionsFromSpans(int start, int end)
bool isIndexHidden(const QModelIndex &index) const
Empty implementation because the header doesn&#39;t show QModelIndex items.
int sectionViewportPosition(int logicalIndex) const
Returns the section viewport position of the given logicalIndex.
int length() const
Returns the length along the orientation of the header.
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QRect rect() const
bool isEnabled() const
Definition: qwidget.h:948
void hide()
Hides the widget.
Definition: qwidget.h:501
void initializeSections()
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
void headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast)
Updates the changed header sections with the given orientation, from logicalFirst to logicalLast incl...
QIcon icon
the icon of the header
Definition: qstyleoption.h:265
void write(QDataStream &out) const
The QAbstractItemModel class provides the abstract interface for item model classes.
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers)
Empty implementation because the header doesn&#39;t show QModelIndex items.
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
The QBitArray class provides an array of bits.
Definition: qbitarray.h:54
int adjustedVisualIndex(int visualIndex) const
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
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
bool isSectionSelected(int section) const
int hiddenSectionCount() const
Returns the number of sections in the header that has been hidden.
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy)
SectionPosition position
the section&#39;s position in relation to the other sections
Definition: qstyleoption.h:267
void doItemsLayout()
The QAbstractItemView class provides the basic functionality for item view classes.
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.
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:131
void updateGeometries()
Reimplemented Function
int visualIndexAt(int position) const
Returns the visual index of the section that covers the given position in the viewport.
void resizeSections(QHeaderView::ResizeMode globalMode, bool useGlobalMode=false)
Go through and resize all of the sections applying stretchLastSection, manualy stretches, sizes, and useGlobalMode.
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
void setSectionHidden(int logicalIndex, bool hide)
If hide is true the section specified by logicalIndex is hidden; otherwise the section is shown...
int logicalIndex(int visualIndex) const
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 ...
void sectionHandleDoubleClicked(int logicalIndex)
This signal is emitted when a section is double-clicked.
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
Qt::Alignment iconAlignment
the alignment flags for the icon of the header
Definition: qstyleoption.h:266
SelectedPosition selectedPosition
the section&#39;s position in relation to the selected section
Definition: qstyleoption.h:268
State
Definition: qaudio.h:59
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
Reimplemented Function
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
void setSortIndicatorShown(bool show)
int y() const
Returns the y position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:98
void sectionDoubleClicked(int logicalIndex)
This signal is emitted when a section is double-clicked.
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674
CursorShape
Definition: qnamespace.h:1262
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setFrameStyle(int)
Sets the frame style to style.
Definition: qframe.cpp:329
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
void setMovable(bool movable)
If movable is true, the header may be moved by the user; otherwise it is fixed in place...
The QModelIndex class is used to locate data in a data model.
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given element with the provided painter with the style options specified by option...
int sectionHandleAt(int position)
int verticalOffset() const
Returns the vertical offset of the header.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
int count() const
Returns the number of sections in the header.
int & rheight()
Returns a reference to the height.
Definition: qsize.h:144
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
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition: qevent.h:598
if(void) toggleToolbarShown
void resizeSectionSpan(int visualIndex, int oldSize, int newSize)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void setDefaultSectionSize(int size)
QFactoryLoader * l
QSize minimumSize() const
The QLabel widget provides a text or image display.
Definition: qlabel.h:55
QHeaderView::ResizeMode resizeMode
int count() const
Same as size().
Definition: qbitarray.h:74
bool restoreState(const QByteArray &state)
Restores the state of this header view.
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
void sectionsInserted(const QModelIndex &parent, int logicalFirst, int logicalLast)
This slot is called when sections are inserted into the parent.
State state() const
Returns the item view&#39;s state.
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
quint16 index
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
int top() const
Returns the row index corresponding to the uppermost selected row in the selection range...
int stretchSectionCount() const
Returns the number of sections that are set to resize mode stretch.
const QFont & font() const
void setDefaultSectionSize(int size)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void setFont(const QFont &f)
Sets the painter&#39;s font to the given font.
Definition: qpainter.cpp:4288
void sortIndicatorChanged(int logicalIndex, Qt::SortOrder order)
bool isRightToLeft() const
Definition: qwidget.h:428
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
int section
which section of the header is being painted
Definition: qstyleoption.h:262
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
void setOffsetToLastSection()
Sets the offset to make the last section visible.
int sectionPosition(int logicalIndex) const
Returns the section position of the given logicalIndex, or -1 if the section is hidden.
void createSectionSpan(int start, int end, int size, QHeaderView::ResizeMode mode)
const char * variant
void setOpacity(qreal opacity)
Sets the opacity of the painter to opacity.
Definition: qpainter.cpp:2139
void flipSortIndicator(int section)
void swapSections(int first, int second)
Swaps the section at visual index first with the section at visual index second.
void setSortIndicator(int logicalIndex, Qt::SortOrder order)
Sets the sort indicator for the section specified by the given logicalIndex in the direction specifie...
int logicalIndexAt(int position) const
Returns the section that covers the given position in the viewport.
bool isSortIndicatorShown() const
const QRect & rect() const
Returns the rectangle that needs to be updated.
Definition: qevent.h:305
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
int height() const
Returns the height of the font.
void mouseReleaseEvent(QMouseEvent *e)
Reimplemented Function
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
Shows text as a "What&#39;s This?" window, at global position pos.
Definition: qwhatsthis.cpp:754
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
bool stretchLastSection() const
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
void _q_layoutAboutToBeChanged()
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
Orientation
Definition: qnamespace.h:174
Qt::SortOrder sortIndicatorOrder() const
Returns the order for the sort indicator.
bool event(QEvent *event)
Reimplemented Function
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
QDataStream & operator<<(QDataStream &out, const QUrl &url)
Writes url url to the stream out and returns a reference to the stream.
Definition: qurl.cpp:6757
bool event(QEvent *e)
Reimplemented Function
#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
void updateSectionIndicator(int section, int position)
void _q_sectionsRemoved(const QModelIndex &, int, int)
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
void setHeaderSectionResizeMode(int visual, QHeaderView::ResizeMode mode)
#define INT_MAX
bool isEmpty() const
Returns true if this bit array has size 0; otherwise returns false.
Definition: qbitarray.h:78
QModelIndex indexAt(const QPoint &p) const
Empty implementation because the header doesn&#39;t show QModelIndex items.
bool end()
Ends painting.
Definition: qpainter.cpp:1929
virtual QSize sectionSizeFromContents(int logicalIndex) const
Returns the size of the contents of the section specified by the given logicalIndex.
bool viewportEvent(QEvent *event)
This function is used to handle tool tips, and What&#39;s This? mode, if the given event is a QEvent::Too...
int & rwidth()
Returns a reference to the width.
Definition: qsize.h:141
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
int column() const
Returns the column this model index refers to.
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7631
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
Qt::Alignment defaultAlignment() const
int x() const
Returns the x position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:97
void geometriesChanged()
This signal is emitted when the header&#39;s geometries have changed.
Qt::CursorShape shape() const
Returns the cursor shape identifier.
Definition: qcursor.cpp:469
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
void setResizeMode(ResizeMode mode)
Sets the constraints on how the header can be resized to those described by the given mode...
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtooltip.cpp:497
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:586
QDataStream & operator>>(QDataStream &in, QUrl &url)
Reads a url into url from the stream in and returns a reference to the stream.
Definition: qurl.cpp:6774
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60
const QPoint & pos() const
Returns the mouse cursor position when the event was generated, relative to the widget to which the e...
Definition: qevent.h:597