Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/itemviews/qheaderview.cpp

    r2 r561  
    22**
    33** 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])
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    6363#ifndef QT_NO_DATASTREAM
    6464#include <qdatastream.h>
     65
    6566
    6667QT_BEGIN_NAMESPACE
    6768
     69
    6870QDataStream &operator<<(QDataStream &out, const QHeaderViewPrivate::SectionSpan &span)
    6971{
     
    7779    return in;
    7880}
    79 #endif
     81#endif
    8082
    8183
     
    8789
    8890    \ingroup model-view
    89     \mainclass
     91
    9092
    9193    A QHeaderView displays the headers used in item views such as the
     
    521523{
    522524    Q_D(const QHeaderView);
    523     if (count() < 1)
    524         return QSize(0, 0);
    525525    if (d->cachedSizeHint.isValid())
    526526        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
    529530    // 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) {
    532533        if (isSectionHidden(i))
    533534            continue;
     535
    534536        QSize hint = sectionSizeFromContents(i);
    535         width = qMax(hint.width(), width);
    536         height = qMax(hint.height(), height);
     537        d->cachedSizeHint = d->cachedSizeHint.expandedTo(hint);
    537538    }
    538539    // 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) {
    541542        if (isSectionHidden(j))
    542543            continue;
     544
    543545        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    }
    548548    return d->cachedSizeHint;
    549549}
     
    10481048/*!
    10491049    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.
    10511053
    10521054    \sa visualIndex(), sectionPosition()
     
    11521154
    11531155    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.
    11551158
    11561159    \note This setting will be ignored for the last section if the stretchLastSection
     
    11951198    Q_D(const QHeaderView);
    11961199    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);
    11991203}
    12001204
     
    12351239        return;
    12361240
    1237     if (d->visualIndexResizeMode(sortIndicatorSection()) == ResizeToContents)
     1241    if (d->ResizeMode(sortIndicatorSection()) == ResizeToContents)
    12381242        resizeSections();
    12391243
     
    12681272    d->sortIndicatorOrder = order;
    12691273
    1270     if (logicalIndex >= d->sectionCount)
     1274    if (logicalIndex >= d->sectionCount) {
     1275        emit sortIndicatorChanged(logicalIndex, order);
    12711276        return; // nothing to do
     1277
    12721278
    12731279    if (old != logicalIndex
     
    13891395{
    13901396    Q_D(QHeaderView);
    1391     d->defaultSectionSize = size;
    1392     d->forceInitializing = true;
     1397    d->setDefaultSectionSize(size);
    13931398}
    13941399
     
    14151420        if (d->orientation == Qt::Horizontal)
    14161421            return qMax(strut.width(), (fontMetrics().maxWidth() + margin));
    1417         return qMax(strut.height(), (fontMetrics().lineSpacing() + margin));
     1422        return qMax(strut.height(), (fontMetrics().() + margin));
    14181423    }
    14191424    return d->minimumSectionSize;
     
    15351540    return false;
    15361541}
    1537 #endif
     1542#endif
    15381543
    15391544/*!
     
    18951900        if (newCount < oldCount)
    18961901            d->updateHiddenSections(0, newCount-1);
    1897     } else if (d->forceInitializing) {
    1898         initializeSections(0, newCount - 1);
    1899         d->forceInitializing = false;
    19001902    }
    19011903}
     
    19121914    Q_ASSERT(end >= 0);
    19131915
    1914     d->executePostedLayout();
    19151916    d->invalidateCachedSizeHint();
    19161917
     
    19381939
    19391940    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);
    19451960        }
    19461961    }
     
    19531968        d->sectionHidden.resize(d->sectionCount);
    19541969
    1955     if (d->sectionCount > oldCount || d->forceInitializing)
     1970    if (d->sectionCount > oldCount)
    19561971        d->createSectionSpan(start, end, (end - start + 1) * d->defaultSectionSize, d->globalResizeMode);
    19571972    //Q_ASSERT(d->headerLength() == d->length);
     
    19721987    if (d->orientation == Qt::Horizontal && current.column() != old.column()) {
    19731988        if (old.isValid() && old.parent() == d->root)
    1974             d->setDirtyRegion(QRect(sectionViewportPosition(old.column()), 0,
     1989            d->(QRect(sectionViewportPosition(old.column()), 0,
    19751990                                    sectionSize(old.column()), d->viewport->height()));
    19761991        if (current.isValid() && current.parent() == d->root)
    1977             d->setDirtyRegion(QRect(sectionViewportPosition(current.column()), 0,
     1992            d->(QRect(sectionViewportPosition(current.column()), 0,
    19781993                                    sectionSize(current.column()), d->viewport->height()));
    19791994    } else if (d->orientation == Qt::Vertical && current.row() != old.row()) {
    19801995        if (old.isValid() && old.parent() == d->root)
    1981             d->setDirtyRegion(QRect(0, sectionViewportPosition(old.row()),
     1996            d->(QRect(0, sectionViewportPosition(old.row()),
    19821997                                    d->viewport->width(), sectionSize(old.row())));
    19831998        if (current.isValid() && current.parent() == d->root)
    1984             d->setDirtyRegion(QRect(0, sectionViewportPosition(current.row()),
     1999            d->(QRect(0, sectionViewportPosition(current.row()),
    19852000                                    d->viewport->width(), sectionSize(current.row())));
    19862001    }
    1987     d->updateDirtyRegion();
    19882002}
    19892003
     
    23962410        d->pressed = d->section = d->target = -1;
    23972411        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; }
    23992418    default:
    24002419        break;
     
    25162535    Q_ASSERT(logicalIndex >= 0);
    25172536
     2537
     2538
    25182539    // use SizeHintRole
    25192540    QVariant variant = d->model->headerData(logicalIndex, d->orientation, Qt::SizeHintRole);
     
    25412562        opt.icon = qvariant_cast<QPixmap>(variant);
    25422563    QSize size = style()->sizeFromContents(QStyle::CT_HeaderSection, &opt, QSize(), this);
    2543     if (isSortIndicatorShown() && sortIndicatorSection() == logicalIndex) {
     2564    if (isSortIndicatorShown()) {
    25442565        int margin = style()->pixelMetric(QStyle::PM_HeaderMargin, &opt, this);
    25452566        if (d->orientation == Qt::Horizontal)
     
    26182639        int last = orientation() == Qt::Horizontal ? bottomRight.column() : bottomRight.row();
    26192640        for (int i = first; i <= last && !resizeRequired; ++i)
    2620             resizeRequired = (resizeRequired && resizeMode(i));
     2641            resizeRequired = (resize);
    26212642        if (resizeRequired)
    26222643            d->doDelayedResizeSections();
     
    28242845    }
    28252846
    2826     int x, y, w, h;
     2847    int w, h;
    28272848    int p = q->sectionViewportPosition(section);
    28282849    if (orientation == Qt::Horizontal) {
    2829         x = p;
    2830         y = 0;
    28312850        w = q->sectionSize(section);
    28322851        h = viewport->height();
    28332852    } else {
    2834         x = 0;
    2835         y = p;
    28362853        w = viewport->width();
    28372854        h = q->sectionSize(section);
     
    29392956{
    29402957    Q_Q(QHeaderView);
     2958
     2959
    29412960
    29422961    executePostedLayout();
    29432962    if (sectionCount == 0)
    29442963        return;
     2964
     2965
     2966
     2967
     2968
    29452969    invalidateCachedSizeHint();
     2970
     2971
    29462972
    29472973    // find stretchLastSection if we have it
    29482974    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();
    29572977
    29582978    // count up the number of strected sections and how much space left for them
     
    29682988            resizeMode = globalMode;
    29692989        else
    2970             resizeMode = (i == stretchSection ? QHeaderView::Stretch : visualIndexResizeMode(i));
     2990            resizeMode = (i == stretchSection ? QHeaderView::Stretch : ResizeMode(i));
    29712991
    29722992        if (resizeMode == QHeaderView::Stretch) {
     
    30003020    int spanStartSection = 0;
    30013021    int previousSectionLength = 0;
    3002     const int lastVisibleSection = lastVisibleVisualIndex();
    30033022
    30043023    QHeaderView::ResizeMode previousSectionResizeMode = QHeaderView::Interactive;
     
    30193038                resizeMode = (i == stretchSection
    30203039                              ? QHeaderView::Stretch
    3021                               : visualIndexResizeMode(i));
     3040                              : );
    30223041            if (resizeMode == QHeaderView::Stretch && stretchSectionLength != -1) {
    30233042                if (i == lastVisibleSection)
     
    30563075                      previousSectionResizeMode);
    30573076    //Q_ASSERT(headerLength() == length);
    3058 
     3077    resizeRecursionBlock = false;
    30593078    viewport->update();
    30603079}
     
    33653384}
    33663385
     3386
     3387
     3388
     3389
     3390
     3391
     3392
     3393
     3394
     3395
     3396
     3397
     3398
     3399
     3400
     3401
     3402
     3403
     3404
     3405
     3406
     3407
     3408
    33673409void QHeaderViewPrivate::resizeSectionSpan(int visualIndex, int oldSize, int newSize)
    33683410{
     
    34503492int QHeaderViewPrivate::viewSectionSizeHint(int logical) const
    34513493{
    3452     Q_Q(const QHeaderView);
    3453     if (QAbstractItemView *parent = qobject_cast<QAbstractItemView*>(q->parent())) {
     3494    if (QAbstractItemView *view = qobject_cast<QAbstractItemView*>(parent)) {
    34543495        return (orientation == Qt::Horizontal
    3455                 ? parent->sizeHintForColumn(logical)
    3456                 : parent->sizeHintForRow(logical));
     3496                ? ->sizeHintForColumn(logical)
     3497                : ->sizeHintForRow(logical));
    34573498    }
    34583499    return 0;
     
    35403581
    35413582    in >> align;
    3542     defaultAlignment = (Qt::Alignment)align;
     3583    defaultAlignment = ;
    35433584
    35443585    in >> global;
     
    35503591}
    35513592
     3593
     3594
    35523595QT_END_NAMESPACE
    35533596
    3554 #endif // QT_NO_DATASTREAEM
    3555 
    35563597#endif // QT_NO_ITEMVIEWS
    35573598
Note: See TracChangeset for help on using the changeset viewer.