Changeset 561 for trunk/src/gui/itemviews/qheaderview.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/itemviews/qheaderview.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 63 63 #ifndef QT_NO_DATASTREAM 64 64 #include <qdatastream.h> 65 65 66 66 67 QT_BEGIN_NAMESPACE 67 68 69 68 70 QDataStream &operator<<(QDataStream &out, const QHeaderViewPrivate::SectionSpan &span) 69 71 { … … 77 79 return in; 78 80 } 79 #endif 81 #endif 80 82 81 83 … … 87 89 88 90 \ingroup model-view 89 \mainclass 91 90 92 91 93 A QHeaderView displays the headers used in item views such as the … … 521 523 { 522 524 Q_D(const QHeaderView); 523 if (count() < 1)524 return QSize(0, 0);525 525 if (d->cachedSizeHint.isValid()) 526 526 return d->cachedSizeHint; 527 int width = 0; 528 int height = 0; 527 d->cachedSizeHint = QSize(0, 0); //reinitialize the cached size hint 528 const int sectionCount = count(); 529 529 530 // get size hint for the first n sections 530 int c = qMin(count(), 100);531 for (int i = 0; i < c; ++i) {531 int ; 532 for (int ; ++i) { 532 533 if (isSectionHidden(i)) 533 534 continue; 535 534 536 QSize hint = sectionSizeFromContents(i); 535 width = qMax(hint.width(), width); 536 height = qMax(hint.height(), height); 537 d->cachedSizeHint = d->cachedSizeHint.expandedTo(hint); 537 538 } 538 539 // get size hint for the last n sections 539 c = qMax(count() - 100, c);540 for (int j = count() - 1; j >= c; --j) {540 ); 541 for (int j = ; --j) { 541 542 if (isSectionHidden(j)) 542 543 continue; 544 543 545 QSize hint = sectionSizeFromContents(j); 544 width = qMax(hint.width(), width); 545 height = qMax(hint.height(), height); 546 } 547 d->cachedSizeHint = QSize(width, height); 546 d->cachedSizeHint = d->cachedSizeHint.expandedTo(hint); 547 } 548 548 return d->cachedSizeHint; 549 549 } … … 1048 1048 /*! 1049 1049 Returns the logicalIndex for the section at the given \a visualIndex 1050 position, or -1 otherwise. 1050 position, or -1 if visualIndex < 0 or visualIndex >= QHeaderView::count(). 1051 1052 Note that the visualIndex is not affected by hidden sections. 1051 1053 1052 1054 \sa visualIndex(), sectionPosition() … … 1152 1154 1153 1155 Sets the constraints on how the section specified by \a logicalIndex in 1154 the header can be resized to those described by the given \a mode. 1156 the header can be resized to those described by the given \a mode. The logical 1157 index should exist at the time this function is called. 1155 1158 1156 1159 \note This setting will be ignored for the last section if the stretchLastSection … … 1195 1198 Q_D(const QHeaderView); 1196 1199 int visual = visualIndex(logicalIndex); 1197 Q_ASSERT(visual != -1); 1198 return d->visualIndexResizeMode(visual); 1200 if (visual == -1) 1201 return Fixed; //the default value 1202 return d->headerSectionResizeMode(visual); 1199 1203 } 1200 1204 … … 1235 1239 return; 1236 1240 1237 if (d-> visualIndexResizeMode(sortIndicatorSection()) == ResizeToContents)1241 if (d->ResizeMode(sortIndicatorSection()) == ResizeToContents) 1238 1242 resizeSections(); 1239 1243 … … 1268 1272 d->sortIndicatorOrder = order; 1269 1273 1270 if (logicalIndex >= d->sectionCount) 1274 if (logicalIndex >= d->sectionCount) { 1275 emit sortIndicatorChanged(logicalIndex, order); 1271 1276 return; // nothing to do 1277 1272 1278 1273 1279 if (old != logicalIndex … … 1389 1395 { 1390 1396 Q_D(QHeaderView); 1391 d->defaultSectionSize = size; 1392 d->forceInitializing = true; 1397 d->setDefaultSectionSize(size); 1393 1398 } 1394 1399 … … 1415 1420 if (d->orientation == Qt::Horizontal) 1416 1421 return qMax(strut.width(), (fontMetrics().maxWidth() + margin)); 1417 return qMax(strut.height(), (fontMetrics(). lineSpacing() + margin));1422 return qMax(strut.height(), (fontMetrics().() + margin)); 1418 1423 } 1419 1424 return d->minimumSectionSize; … … 1535 1540 return false; 1536 1541 } 1537 #endif 1542 #endif 1538 1543 1539 1544 /*! … … 1895 1900 if (newCount < oldCount) 1896 1901 d->updateHiddenSections(0, newCount-1); 1897 } else if (d->forceInitializing) {1898 initializeSections(0, newCount - 1);1899 d->forceInitializing = false;1900 1902 } 1901 1903 } … … 1912 1914 Q_ASSERT(end >= 0); 1913 1915 1914 d->executePostedLayout();1915 1916 d->invalidateCachedSizeHint(); 1916 1917 … … 1938 1939 1939 1940 if (!d->logicalIndices.isEmpty()) { 1940 d->logicalIndices.resize(d->sectionCount); 1941 d->visualIndices.resize(d->sectionCount); 1942 for (int i = start; i < d->sectionCount; ++i){ 1943 d->logicalIndices[i] = i; 1944 d->visualIndices[i] = i; 1941 if (oldCount <= d->sectionCount) { 1942 d->logicalIndices.resize(d->sectionCount); 1943 d->visualIndices.resize(d->sectionCount); 1944 for (int i = oldCount; i < d->sectionCount; ++i) { 1945 d->logicalIndices[i] = i; 1946 d->visualIndices[i] = i; 1947 } 1948 } else { 1949 int j = 0; 1950 for (int i = 0; i < oldCount; ++i) { 1951 int v = d->logicalIndices.at(i); 1952 if (v < d->sectionCount) { 1953 d->logicalIndices[j] = v; 1954 d->visualIndices[v] = j; 1955 j++; 1956 } 1957 } 1958 d->logicalIndices.resize(d->sectionCount); 1959 d->visualIndices.resize(d->sectionCount); 1945 1960 } 1946 1961 } … … 1953 1968 d->sectionHidden.resize(d->sectionCount); 1954 1969 1955 if (d->sectionCount > oldCount || d->forceInitializing)1970 if (d->sectionCount > oldCount) 1956 1971 d->createSectionSpan(start, end, (end - start + 1) * d->defaultSectionSize, d->globalResizeMode); 1957 1972 //Q_ASSERT(d->headerLength() == d->length); … … 1972 1987 if (d->orientation == Qt::Horizontal && current.column() != old.column()) { 1973 1988 if (old.isValid() && old.parent() == d->root) 1974 d-> setDirtyRegion(QRect(sectionViewportPosition(old.column()), 0,1989 d->(QRect(sectionViewportPosition(old.column()), 0, 1975 1990 sectionSize(old.column()), d->viewport->height())); 1976 1991 if (current.isValid() && current.parent() == d->root) 1977 d-> setDirtyRegion(QRect(sectionViewportPosition(current.column()), 0,1992 d->(QRect(sectionViewportPosition(current.column()), 0, 1978 1993 sectionSize(current.column()), d->viewport->height())); 1979 1994 } else if (d->orientation == Qt::Vertical && current.row() != old.row()) { 1980 1995 if (old.isValid() && old.parent() == d->root) 1981 d-> setDirtyRegion(QRect(0, sectionViewportPosition(old.row()),1996 d->(QRect(0, sectionViewportPosition(old.row()), 1982 1997 d->viewport->width(), sectionSize(old.row()))); 1983 1998 if (current.isValid() && current.parent() == d->root) 1984 d-> setDirtyRegion(QRect(0, sectionViewportPosition(current.row()),1999 d->(QRect(0, sectionViewportPosition(current.row()), 1985 2000 d->viewport->width(), sectionSize(current.row()))); 1986 2001 } 1987 d->updateDirtyRegion();1988 2002 } 1989 2003 … … 2396 2410 d->pressed = d->section = d->target = -1; 2397 2411 d->updateSectionIndicator(d->section, -1); 2398 } 2412 break; } 2413 case QEvent::Wheel: { 2414 QAbstractScrollArea *asa = qobject_cast<QAbstractScrollArea *>(parentWidget()); 2415 if (asa) 2416 return QApplication::sendEvent(asa->viewport(), e); 2417 break; } 2399 2418 default: 2400 2419 break; … … 2516 2535 Q_ASSERT(logicalIndex >= 0); 2517 2536 2537 2538 2518 2539 // use SizeHintRole 2519 2540 QVariant variant = d->model->headerData(logicalIndex, d->orientation, Qt::SizeHintRole); … … 2541 2562 opt.icon = qvariant_cast<QPixmap>(variant); 2542 2563 QSize size = style()->sizeFromContents(QStyle::CT_HeaderSection, &opt, QSize(), this); 2543 if (isSortIndicatorShown() && sortIndicatorSection() == logicalIndex) {2564 if (isSortIndicatorShown()) { 2544 2565 int margin = style()->pixelMetric(QStyle::PM_HeaderMargin, &opt, this); 2545 2566 if (d->orientation == Qt::Horizontal) … … 2618 2639 int last = orientation() == Qt::Horizontal ? bottomRight.column() : bottomRight.row(); 2619 2640 for (int i = first; i <= last && !resizeRequired; ++i) 2620 resizeRequired = (resize Required && resizeMode(i));2641 resizeRequired = (resize); 2621 2642 if (resizeRequired) 2622 2643 d->doDelayedResizeSections(); … … 2824 2845 } 2825 2846 2826 int x, y,w, h;2847 int w, h; 2827 2848 int p = q->sectionViewportPosition(section); 2828 2849 if (orientation == Qt::Horizontal) { 2829 x = p;2830 y = 0;2831 2850 w = q->sectionSize(section); 2832 2851 h = viewport->height(); 2833 2852 } else { 2834 x = 0;2835 y = p;2836 2853 w = viewport->width(); 2837 2854 h = q->sectionSize(section); … … 2939 2956 { 2940 2957 Q_Q(QHeaderView); 2958 2959 2941 2960 2942 2961 executePostedLayout(); 2943 2962 if (sectionCount == 0) 2944 2963 return; 2964 2965 2966 2967 2968 2945 2969 invalidateCachedSizeHint(); 2970 2971 2946 2972 2947 2973 // find stretchLastSection if we have it 2948 2974 int stretchSection = -1; 2949 if (stretchLastSection && !useGlobalMode) { 2950 for (int i = sectionCount - 1; i >= 0; --i) { 2951 if (!isVisualIndexHidden(i)) { 2952 stretchSection = i; 2953 break; 2954 } 2955 } 2956 } 2975 if (stretchLastSection && !useGlobalMode) 2976 stretchSection = lastVisibleVisualIndex(); 2957 2977 2958 2978 // count up the number of strected sections and how much space left for them … … 2968 2988 resizeMode = globalMode; 2969 2989 else 2970 resizeMode = (i == stretchSection ? QHeaderView::Stretch : visualIndexResizeMode(i));2990 resizeMode = (i == stretchSection ? QHeaderView::Stretch : ResizeMode(i)); 2971 2991 2972 2992 if (resizeMode == QHeaderView::Stretch) { … … 3000 3020 int spanStartSection = 0; 3001 3021 int previousSectionLength = 0; 3002 const int lastVisibleSection = lastVisibleVisualIndex();3003 3022 3004 3023 QHeaderView::ResizeMode previousSectionResizeMode = QHeaderView::Interactive; … … 3019 3038 resizeMode = (i == stretchSection 3020 3039 ? QHeaderView::Stretch 3021 : visualIndexResizeMode(i));3040 : ); 3022 3041 if (resizeMode == QHeaderView::Stretch && stretchSectionLength != -1) { 3023 3042 if (i == lastVisibleSection) … … 3056 3075 previousSectionResizeMode); 3057 3076 //Q_ASSERT(headerLength() == length); 3058 3077 resizeRecursionBlock = false; 3059 3078 viewport->update(); 3060 3079 } … … 3365 3384 } 3366 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3367 3409 void QHeaderViewPrivate::resizeSectionSpan(int visualIndex, int oldSize, int newSize) 3368 3410 { … … 3450 3492 int QHeaderViewPrivate::viewSectionSizeHint(int logical) const 3451 3493 { 3452 Q_Q(const QHeaderView); 3453 if (QAbstractItemView *parent = qobject_cast<QAbstractItemView*>(q->parent())) { 3494 if (QAbstractItemView *view = qobject_cast<QAbstractItemView*>(parent)) { 3454 3495 return (orientation == Qt::Horizontal 3455 ? parent->sizeHintForColumn(logical)3456 : parent->sizeHintForRow(logical));3496 ? ->sizeHintForColumn(logical) 3497 : ->sizeHintForRow(logical)); 3457 3498 } 3458 3499 return 0; … … 3540 3581 3541 3582 in >> align; 3542 defaultAlignment = (Qt::Alignment)align;3583 defaultAlignment = ; 3543 3584 3544 3585 in >> global; … … 3550 3591 } 3551 3592 3593 3594 3552 3595 QT_END_NAMESPACE 3553 3596 3554 #endif // QT_NO_DATASTREAEM3555 3556 3597 #endif // QT_NO_ITEMVIEWS 3557 3598
Note:
See TracChangeset
for help on using the changeset viewer.