Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
67 edited

Legend:

Unmodified
Added
Removed
  • trunk

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

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    292292
    293293/*!
    294     Whenever an event occurs, this function is called with the \a event
    295     \a model \a option and the \a index that corresponds to the item being edited.
     294    When editing of an item starts, this function is called with the
     295    \a event that triggered the editing, the \a model, the \a index of
     296    the item, and the \a option used for rendering the item.
     297
     298    Mouse events are sent to editorEvent() even if they don't start
     299    editing of the item. This can, for instance, be useful if you wish
     300    to open a context menu when the right mouse button is pressed on
     301    an item.
    296302
    297303    The base implementation returns false (indicating that it has not
  • trunk/src/gui/itemviews/qabstractitemdelegate.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qabstractitemview.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    105105        currentIndexSet(false),
    106106        wrapItemText(false),
    107         delayedPendingLayout(false)
    108 {
     107        delayedPendingLayout(true),
     108        moveCursorUpdatedView(false)
     109{
     110    keyboardInputTime.invalidate();
    109111}
    110112
     
    131133
    132134    viewport->setBackgroundRole(QPalette::Base);
    133 
    134     doDelayedItemsLayout();
    135135
    136136    q->setAttribute(Qt::WA_InputMethodEnabled);
     
    596596QAbstractItemView::~QAbstractItemView()
    597597{
     598    Q_D(QAbstractItemView);
     599    // stop these timers here before ~QObject
     600    d->delayedReset.stop();
     601    d->updateTimer.stop();
     602    d->delayedEditing.stop();
     603    d->delayedAutoScroll.stop();
     604    d->autoScrollTimer.stop();
     605    d->delayedLayout.stop();
     606    d->fetchMoreTimer.stop();
    598607}
    599608
     
    680689        connect(d->model, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged()));
    681690    }
    682     setSelectionModel(new QItemSelectionModel(d->model, this));
     691
     692    QItemSelectionModel *selection_model = new QItemSelectionModel(d->model, this);
     693    connect(d->model, SIGNAL(destroyed()), selection_model, SLOT(deleteLater()));
     694    setSelectionModel(selection_model);
     695
    683696    reset(); // kill editors, set new root and do layout
    684697}
     
    824837
    825838    \note If a delegate has been assigned to both a row and a column, the row
    826     delegate (i.e., this delegate) will take presedence and manage the
     839    delegate (i.e., this delegate) will take precedence and manage the
    827840    intersecting cell index.
    828841
     
    882895
    883896    \note If a delegate has been assigned to both a row and a column, the row
    884     delegate will take presedence and manage the intersecting cell index.
     897    delegate will take precedence and manage the intersecting cell index.
    885898
    886899    \warning You should not share the same instance of a delegate between views.
     
    11631176    \brief how the view scrolls its contents in the vertical direction
    11641177
    1165     This property controlls how the view scroll its contents vertically.
     1178    This property controls how the view scroll its contents vertically.
    11661179    Scrolling can be done either per pixel or per item.
    11671180*/
     
    11891202    \brief how the view scrolls its contents in the horizontal direction
    11901203
    1191     This property controlls how the view scroll its contents horizontally.
     1204    This property controls how the view scroll its contents horizontally.
    11921205    Scrolling can be done either per pixel or per item.
    11931206*/
     
    12721285    \brief the size of the area when auto scrolling is triggered
    12731286
    1274     This property controlls the size of the area at the edge of the viewport that
     1287    This property controls the size of the area at the edge of the viewport that
    12751288    triggers autoscrolling. The default value is 16 pixels.
    12761289*/
     
    13601373    Note that the model used needs to provide support for drag and drop operations.
    13611374
    1362     \sa setDragDropMode() {Using Drag and Drop with Item Views}
     1375    \sa setDragDropMode() {Using drag and drop with item views}
    13631376*/
    13641377
     
    20942107        d->autoScroll = false;
    20952108        QModelIndex index = moveCursor(MoveNext, Qt::NoModifier); // first visible index
    2096         if (index.isValid() && d->isIndexEnabled(index))
     2109        if (index.isValid() && d->isIndexEnabled(index) && event->reason() != Qt::MouseFocusReason)
    20972110            selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
    20982111        d->autoScroll = autoScroll;
     
    22142227
    22152228    QPersistentModelIndex newCurrent;
     2229    d->moveCursorUpdatedView = false;
    22162230    switch (event->key()) {
    22172231    case Qt::Key_Down:
     
    22662280                d->selectionModel->setCurrentIndex(newCurrent, command);
    22672281                d->pressedPosition = visualRect(newCurrent).center() + d->offset();
    2268                 // We copy the same behaviour as for mousePressEvent().
    2269                 QRect rect(d->pressedPosition - d->offset(), QSize(1, 1));
    2270                 setSelection(rect, command);
     2282                if (newCurrent.isValid()) {
     2283                    // We copy the same behaviour as for mousePressEvent().
     2284                    QRect rect(d->pressedPosition - d->offset(), QSize(1, 1));
     2285                    setSelection(rect, command);
     2286                }
    22712287            }
     2288            event->accept();
    22722289            return;
    22732290        }
     
    23012318    case Qt::Key_Shift:
    23022319    case Qt::Key_Control:
     2320    case Qt::Key_Delete:
     2321    case Qt::Key_Backspace:
    23032322        event->ignore();
    23042323        break;
     
    23652384        break; }
    23662385    }
     2386    if (d->moveCursorUpdatedView)
     2387        event->accept();
    23672388}
    23682389
     
    28412862    QModelIndex start = currentIndex().isValid() ? currentIndex()
    28422863                        : d->model->index(0, 0, d->root);
    2843     QTime now(QTime::currentTime());
    28442864    bool skipRow = false;
    2845     if (search.isEmpty()
    2846         || (d->keyboardInputTime.msecsTo(now) > QApplication::keyboardInputInterval())) {
     2865    bool keyboardTimeWasValid = d->keyboardInputTime.isValid();
     2866    qint64 keyboardInputTimeElapsed = d->keyboardInputTime.restart();
     2867    if (search.isEmpty() || !keyboardTimeWasValid
     2868        || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) {
    28472869        d->keyboardInput = search;
    28482870        skipRow = currentIndex().isValid(); //if it is not valid we should really start at QModelIndex(0,0)
     
    28502872        d->keyboardInput += search;
    28512873    }
    2852     d->keyboardInputTime = now;
    28532874
    28542875    // special case for searches with same key like 'aaaaa'
  • trunk/src/gui/itemviews/qabstractitemview.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qabstractitemview_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5757#include "private/qabstractitemmodel_p.h"
    5858#include "QtGui/qapplication.h"
    59 #include "QtCore/qdatetime.h"
    6059#include "QtGui/qevent.h"
    6160#include "QtGui/qmime.h"
     
    6665#include "QtGui/qpainter.h"
    6766#include "QtCore/qbasictimer.h"
     67#include "QtCore/qelapsedtimer.h"
    6868
    6969#ifndef QT_NO_ITEMVIEWS
     
    391391
    392392    QString keyboardInput;
    393     QTime keyboardInputTime;
     393    QElapsedTimer keyboardInputTime;
    394394
    395395    bool autoScroll;
     
    420420    bool wrapItemText;
    421421    mutable bool delayedPendingLayout;
     422    bool moveCursorUpdatedView;
    422423
    423424private:
  • trunk/src/gui/itemviews/qabstractproxymodel.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    188188    QModelIndexList proxyIndexes = proxySelection.indexes();
    189189    QItemSelection sourceSelection;
    190     for (int i = 0; i < proxyIndexes.size(); ++i)
    191         sourceSelection << QItemSelectionRange(mapToSource(proxyIndexes.at(i)));
     190    for (int i = 0; i < proxyIndexes.size(); ++i) {
     191        const QModelIndex proxyIdx = mapToSource(proxyIndexes.at(i));
     192        if (!proxyIdx.isValid())
     193            continue;
     194        sourceSelection << QItemSelectionRange(proxyIdx);
     195    }
    192196    return sourceSelection;
    193197}
     
    202206    QModelIndexList sourceIndexes = sourceSelection.indexes();
    203207    QItemSelection proxySelection;
    204     for (int i = 0; i < sourceIndexes.size(); ++i)
    205         proxySelection << QItemSelectionRange(mapFromSource(sourceIndexes.at(i)));
     208    for (int i = 0; i < sourceIndexes.size(); ++i) {
     209        const QModelIndex srcIdx = mapFromSource(sourceIndexes.at(i));
     210        if (!srcIdx.isValid())
     211            continue;
     212        proxySelection << QItemSelectionRange(srcIdx);
     213    }
    206214    return proxySelection;
    207215}
  • trunk/src/gui/itemviews/qabstractproxymodel.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qabstractproxymodel_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qbsptree.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qbsptree_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qcolumnview.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qcolumnview.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qcolumnview_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qcolumnviewgrip.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qcolumnviewgrip_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qdatawidgetmapper.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qdatawidgetmapper.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qdirmodel.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    186186/*!
    187187    \class QDirModel
    188 
     188    \obsolete
    189189    \brief The QDirModel class provides a data model for the local filesystem.
    190190
    191191    \ingroup model-view
    192192
    193     \note The usage of QDirModel is not recommended anymore. The
     193    The usage of QDirModel is not recommended anymore. The
    194194    QFileSystemModel class is a more performant alternative.
    195195
     
    201201    QDirModel keeps a cache with file information. The cache needs to be
    202202    updated with refresh().
    203 
    204     A directory model that displays the contents of a default directory
    205     is usually constructed with a parent object:
    206 
    207     \snippet doc/src/snippets/shareddirmodel/main.cpp 2
    208 
    209     A tree view can be used to display the contents of the model
    210 
    211     \snippet doc/src/snippets/shareddirmodel/main.cpp 4
    212 
    213     and the contents of a particular directory can be displayed by
    214     setting the tree view's root index:
    215 
    216     \snippet doc/src/snippets/shareddirmodel/main.cpp 7
    217 
    218     The view's root index can be used to control how much of a
    219     hierarchical model is displayed. QDirModel provides a convenience
    220     function that returns a suitable model index for a path to a
    221     directory within the model.
    222203
    223204    QDirModel can be accessed using the standard interface provided by
     
    11831164void QDirModelPrivate::init()
    11841165{
     1166    Q_Q(QDirModel);
    11851167    filters = QDir::AllEntries | QDir::NoDotAndDotDot;
    11861168    sort = QDir::Name;
     
    11891171    root.info = QFileInfo();
    11901172    clear(&root);
     1173    QHash<int, QByteArray> roles = q->roleNames();
     1174    roles.insertMulti(QDirModel::FileIconRole, "fileIcon"); // == Qt::decoration
     1175    roles.insert(QDirModel::FilePathRole, "filePath");
     1176    roles.insert(QDirModel::FileNameRole, "fileName");
     1177    q->setRoleNames(roles);
    11911178}
    11921179
  • trunk/src/gui/itemviews/qdirmodel.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qfileiconprovider.cpp

    r829 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    7777  \class QFileIconProvider
    7878
    79   \brief The QFileIconProvider class provides file icons for the QDirModel class.
     79  \brief The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes.
    8080*/
    8181
     
    106106#endif
    107107    QFileIconProvider *q_ptr;
    108     QString homePath;
     108    const QString homePath;
    109109
    110110private:
    111     QIcon file;
    112     QIcon fileLink;
    113     QIcon directory;
    114     QIcon directoryLink;
    115     QIcon harddisk;
    116     QIcon floppy;
    117     QIcon cdrom;
    118     QIcon ram;
    119     QIcon network;
    120     QIcon computer;
    121     QIcon desktop;
    122     QIcon trashcan;
    123     QIcon generic;
    124     QIcon home;
     111    mutable QIcon file;
     112    mutable QIcon fileLink;
     113    mutable QIcon directory;
     114    mutable QIcon directoryLink;
     115    mutable QIcon harddisk;
     116    mutable QIcon floppy;
     117    mutable QIcon cdrom;
     118    mutable QIcon ram;
     119    mutable QIcon network;
     120    mutable QIcon computer;
     121    mutable QIcon desktop;
     122    mutable QIcon trashcan;
     123    mutable QIcon generic;
     124    mutable QIcon home;
    125125};
    126126
    127 QFileIconProviderPrivate::QFileIconProviderPrivate()
    128 {
    129     QStyle *style = QApplication::style();
    130     file = style->standardIcon(QStyle::SP_FileIcon);
    131     directory = style->standardIcon(QStyle::SP_DirIcon);
    132     fileLink = style->standardIcon(QStyle::SP_FileLinkIcon);
    133     directoryLink = style->standardIcon(QStyle::SP_DirLinkIcon);
    134     harddisk = style->standardIcon(QStyle::SP_DriveHDIcon);
    135     floppy = style->standardIcon(QStyle::SP_DriveFDIcon);
    136     cdrom = style->standardIcon(QStyle::SP_DriveCDIcon);
    137     network = style->standardIcon(QStyle::SP_DriveNetIcon);
    138     computer = style->standardIcon(QStyle::SP_ComputerIcon);
    139     desktop = style->standardIcon(QStyle::SP_DesktopIcon);
    140     trashcan = style->standardIcon(QStyle::SP_TrashIcon);
    141     home = style->standardIcon(QStyle::SP_DirHomeIcon);
    142     homePath = QDir::home().absolutePath();
     127QFileIconProviderPrivate::QFileIconProviderPrivate() :
     128    homePath(QDir::home().absolutePath())
     129{
    143130}
    144131
     
    147134    switch (name) {
    148135    case QStyle::SP_FileIcon:
     136        if (file.isNull())
     137            file = QApplication::style()->standardIcon(name);
    149138        return file;
    150139    case QStyle::SP_FileLinkIcon:
     140        if (fileLink.isNull())
     141            fileLink = QApplication::style()->standardIcon(name);
    151142        return fileLink;
    152143    case QStyle::SP_DirIcon:
     144        if (directory.isNull())
     145            directory = QApplication::style()->standardIcon(name);
    153146        return directory;
    154147    case QStyle::SP_DirLinkIcon:
     148        if (directoryLink.isNull())
     149            directoryLink = QApplication::style()->standardIcon(name);
    155150        return directoryLink;
    156151    case QStyle::SP_DriveHDIcon:
     152        if (harddisk.isNull())
     153            harddisk = QApplication::style()->standardIcon(name);
    157154        return harddisk;
    158155    case QStyle::SP_DriveFDIcon:
     156        if (floppy.isNull())
     157            floppy = QApplication::style()->standardIcon(name);
    159158        return floppy;
    160159    case QStyle::SP_DriveCDIcon:
     160        if (cdrom.isNull())
     161            cdrom = QApplication::style()->standardIcon(name);
    161162        return cdrom;
    162163    case QStyle::SP_DriveNetIcon:
     164        if (network.isNull())
     165            network = QApplication::style()->standardIcon(name);
    163166        return network;
    164167    case QStyle::SP_ComputerIcon:
     168        if (computer.isNull())
     169            computer = QApplication::style()->standardIcon(name);
    165170        return computer;
    166171    case QStyle::SP_DesktopIcon:
     172        if (desktop.isNull())
     173            desktop = QApplication::style()->standardIcon(name);
    167174        return desktop;
    168175    case QStyle::SP_TrashIcon:
     176        if (trashcan.isNull())
     177            trashcan = QApplication::style()->standardIcon(name);
    169178        return trashcan;
    170179    case QStyle::SP_DirHomeIcon:
     180        if (home.isNull())
     181            home = QApplication::style()->standardIcon(name);
    171182        return home;
    172183    default:
  • trunk/src/gui/itemviews/qfileiconprovider.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qheaderview.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    16991699        QBitArray sectionHidden(d->sectionHidden);
    17001700        sectionHidden.resize(sectionHidden.count() + insertCount);
    1701         //sectionHidden.fill(false, logicalFirst, logicalLast + 1);
    1702         for (int i = logicalFirst; i <= logicalLast; ++i)
    1703             // visual == logical in this range (see previous block)
    1704             sectionHidden.setBit(i, false);
     1701        sectionHidden.fill(false, logicalFirst, logicalLast + 1);
    17051702        for (int j = logicalLast + 1; j < sectionHidden.count(); ++j)
    1706             sectionHidden.setBit(d->visualIndex(j),
    1707                     d->sectionHidden.testBit(d->visualIndex(j - insertCount)));
     1703            //here we simply copy the old sectionHidden
     1704            sectionHidden.setBit(j, d->sectionHidden.testBit(j - insertCount));
    17081705        d->sectionHidden = sectionHidden;
    17091706    }
     
    18541851        return;
    18551852    }
     1853
     1854    QBitArray oldSectionHidden = sectionHidden;
    18561855    bool sectionCountChanged = false;
    1857     for (int i = 0; i < sectionHidden.count(); ++i) {
    1858         if (sectionHidden.testBit(i))
    1859             q->setSectionHidden(logicalIndex(i), false);
    1860     }
    18611856
    18621857    for (int i = 0; i < persistentHiddenSections.count(); ++i) {
     
    18671862                                 : index.row());
    18681863            q->setSectionHidden(logical, true);
     1864            oldSectionHidden.setBit(logical, false);
    18691865        } else if (!sectionCountChanged && (modelSectionCount() != sectionCount)) {
    18701866            sectionCountChanged = true;
     
    18731869    }
    18741870    persistentHiddenSections.clear();
     1871
     1872    for (int i = 0; i < oldSectionHidden.count(); ++i) {
     1873        if (oldSectionHidden.testBit(i))
     1874            q->setSectionHidden(i, false);
     1875    }
    18751876
    18761877    // the number of sections changed; we need to reread the state of the model
     
    20342035        }
    20352036        break; }
    2036     case QEvent::Timer: { // ### reimplement timerEvent() instead ?
     2037    case QEvent::Timer: {
    20372038        QTimerEvent *te = static_cast<QTimerEvent*>(e);
    20382039        if (te->timerId() == d->delayedResize.timerId()) {
     
    22182219        }
    22192220        case QHeaderViewPrivate::MoveSection: {
    2220             if (qAbs(pos - d->firstPos) >= QApplication::startDragDistance()) {
    2221                 int indicatorCenter = (d->orientation == Qt::Horizontal
    2222                                        ? d->sectionIndicator->width()
    2223                                        : d->sectionIndicator->height()) / 2;
    2224                 int centerOffset = indicatorCenter - d->sectionIndicatorOffset;
    2225                 // This will drop the moved section to the position under the center of the indicator.
    2226                 // If centerOffset is 0, the section will be moved to the position of the mouse cursor.
    2227                 int visual = visualIndexAt(pos + centerOffset);
     2221            if (qAbs(pos - d->firstPos) >= QApplication::startDragDistance()
     2222                || !d->sectionIndicator->isHidden()) {
     2223                int visual = visualIndexAt(pos);
    22282224                if (visual == -1)
    22292225                    return;
    2230                 d->target = d->logicalIndex(visual);
     2226                int posThreshold = d->headerSectionPosition(visual) + d->headerSectionSize(visual) / 2;
     2227                int moving = visualIndex(d->section);
     2228                if (visual < moving) {
     2229                    if (pos < posThreshold)
     2230                        d->target = d->logicalIndex(visual);
     2231                    else
     2232                        d->target = d->logicalIndex(visual + 1);
     2233                } else if (visual > moving) {
     2234                    if (pos > posThreshold)
     2235                        d->target = d->logicalIndex(visual);
     2236                    else
     2237                        d->target = d->logicalIndex(visual - 1);
     2238                } else {
     2239                    d->target = d->section;
     2240                }
    22312241                d->updateSectionIndicator(d->section, pos);
    2232             } else {
    2233                 int visual = visualIndexAt(d->firstPos);
    2234                 if (visual == -1)
    2235                     return;
    2236                 d->target = d->logicalIndex(visual);
    2237                 d->updateSectionIndicator(d->section, d->firstPos);
    22382242            }
    22392243            return;
     
    23012305            if (section != -1 && section == d->pressed) {
    23022306                d->flipSortIndicator(section);
    2303                 emit sectionClicked(logicalIndexAt(pos));
     2307                emit sectionClicked(section);
    23042308            }
    23052309            if (d->pressed != -1)
     
    26122616    d->layoutChildren();
    26132617    if (d->hasAutoResizeSections())
    2614         resizeSections();
     2618        d->doDelayedResizeSections();
    26152619}
    26162620
  • trunk/src/gui/itemviews/qheaderview.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qheaderview_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qitemdelegate.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    7070#include <qlocale.h>
    7171#include <qdialog.h>
     72#include <qmath.h>
    7273
    7374#include <limits.h>
     
    667668    Q_D(const QItemDelegate);
    668669
    669     QPen pen = painter->pen();
    670670    QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
    671671                              ? QPalette::Normal : QPalette::Disabled;
     
    10241024static QString qPixmapSerial(quint64 i, bool enabled)
    10251025{
    1026     ushort arr[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', '0' + enabled };
     1026    ushort arr[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', ushort('0' + enabled) };
    10271027    ushort *ptr = &arr[16];
    10281028
     
    11491149    d->textLayout.setFont(font);
    11501150    d->textLayout.setText(QItemDelegatePrivate::replaceNewLine(text));
    1151     const QSize size = d->doTextLayout(rect.width()).toSize();
     1151    QSizeF fpSize = d->doTextLayout(rect.width());
     1152    const QSize size = QSize(qCeil(fpSize.width()), qCeil(fpSize.height()));
    11521153    // ###: textRectangle should take style option as argument
    11531154    const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
  • trunk/src/gui/itemviews/qitemdelegate.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qitemeditorfactory.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qitemeditorfactory.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qitemeditorfactory_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qitemselectionmodel.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    293293
    294294/*!
     295    Returns true if the selection range contains no selectable item
     296    \since 4.7
     297*/
     298
     299bool QItemSelectionRange::isEmpty() const
     300{
     301    if (!isValid() || !model())
     302        return true;
     303
     304    for (int column = left(); column <= right(); ++column) {
     305        for (int row = top(); row <= bottom(); ++row) {
     306            QModelIndex index = model()->index(row, column, parent());
     307            Qt::ItemFlags flags = model()->flags(index);
     308            if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled))
     309                return false;
     310        }
     311    }
     312    return true;
     313}
     314
     315/*!
    295316    Returns the list of model index items stored in the selection.
    296317*/
     
    525546        result->append(QItemSelectionRange(tl, br));
    526547        right = other_right;
     548    }
     549}
     550
     551
     552void QItemSelectionModelPrivate::initModel(QAbstractItemModel *model)
     553{
     554    this->model = model;
     555    if (model) {
     556        Q_Q(QItemSelectionModel);
     557        QObject::connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
     558                q, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int)));
     559        QObject::connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
     560                q, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int)));
     561        QObject::connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
     562                q, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int)));
     563        QObject::connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
     564                q, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int)));
     565        QObject::connect(model, SIGNAL(layoutAboutToBeChanged()),
     566                q, SLOT(_q_layoutAboutToBeChanged()));
     567        QObject::connect(model, SIGNAL(layoutChanged()),
     568                q, SLOT(_q_layoutChanged()));
    527569    }
    528570}
     
    731773    savedPersistentCurrentIndexes.clear();
    732774
    733     // optimisation for when all indexes are selected
     775    // optimization for when all indexes are selected
    734776    // (only if there is lots of items (1000) because this is not entirely correct)
    735777    if (ranges.isEmpty() && currentSelection.count() == 1) {
     
    794836            QModelIndex nextTl = colSpans.at(i).topLeft();
    795837            QModelIndex nextBr = colSpans.at(i).bottomRight();
     838
     839            if (nextTl.parent() != tl.parent())
     840                break; // we can't merge selection ranges from different parents
     841
    796842            if ((nextTl.column() == prevTl.column()) && (nextBr.column() == br.column())
    797843                && (nextTl.row() == prevTl.row() + 1) && (nextBr.row() == br.row() + 1)) {
     
    891937    : QObject(*new QItemSelectionModelPrivate, model)
    892938{
    893     d_func()->model = model;
    894     if (model) {
    895         connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
    896                 this, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int)));
    897         connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
    898                 this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int)));
    899         connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
    900                 this, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int)));
    901         connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
    902                 this, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int)));
    903         connect(model, SIGNAL(layoutAboutToBeChanged()),
    904                 this, SLOT(_q_layoutAboutToBeChanged()));
    905         connect(model, SIGNAL(layoutChanged()),
    906                 this, SLOT(_q_layoutChanged()));
    907     }
     939    d_func()->initModel(model);
    908940}
    909941
     
    914946    : QObject(*new QItemSelectionModelPrivate, parent)
    915947{
    916     d_func()->model = model;
    917     if (model) {
    918         connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
    919                 this, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int)));
    920         connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
    921                 this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int)));
    922         connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
    923                 this, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int)));
    924         connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
    925                 this, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int)));
    926         connect(model, SIGNAL(layoutAboutToBeChanged()),
    927                 this, SLOT(_q_layoutAboutToBeChanged()));
    928         connect(model, SIGNAL(layoutChanged()),
    929                 this, SLOT(_q_layoutChanged()));
    930     }
     948    d_func()->initModel(model);
    931949}
    932950
     
    937955    : QObject(dd, model)
    938956{
    939     d_func()->model = model;
    940     if (model) {
    941         connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
    942                 this, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int)));
    943         connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
    944                 this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int)));
    945         connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
    946                 this, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int)));
    947         connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
    948                 this, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int)));
    949         connect(model, SIGNAL(layoutAboutToBeChanged()),
    950                 this, SLOT(_q_layoutAboutToBeChanged()));
    951         connect(model, SIGNAL(layoutChanged()),
    952                 this, SLOT(_q_layoutChanged()));
    953     }
     957    dd.initModel(model);
    954958}
    955959
     
    959963QItemSelectionModel::~QItemSelectionModel()
    960964{
    961     Q_D(QItemSelectionModel);
    962     if (d->model) {
    963         disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
    964                 this, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int)));
    965         disconnect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
    966                 this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int)));
    967         disconnect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
    968                 this, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int)));
    969         disconnect(d->model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
    970                 this, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int)));
    971         disconnect(d->model, SIGNAL(layoutAboutToBeChanged()),
    972                 this, SLOT(_q_layoutAboutToBeChanged()));
    973         disconnect(d->model, SIGNAL(layoutChanged()),
    974                 this, SLOT(_q_layoutChanged()));
    975     }
    976965}
    977966
     
    10711060    // store old selection
    10721061    QItemSelection sel = selection;
     1062    // If d->ranges is non-empty when the source model is reset the persistent indexes
     1063    // it contains will be invalid. We can't clear them in a modelReset slot because that might already
     1064    // be too late if another model observer is connected to the same modelReset slot and is invoked first
     1065    // it might call select() on this selection model before any such QItemSelectionModelPrivate::_q_modelReset() slot
     1066    // is invoked, so it would not be cleared yet. We clear it invalid ranges in it here.
     1067    QItemSelection::iterator it = d->ranges.begin();
     1068    while (it != d->ranges.end()) {
     1069      if (!it->isValid())
     1070        it = d->ranges.erase(it);
     1071      else
     1072        ++it;
     1073    }
     1074
    10731075    QItemSelection old = d->ranges;
    10741076    old.merge(d->currentSelection, d->currentCommand);
  • trunk/src/gui/itemviews/qitemselectionmodel.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    108108                && top() <= bottom() && left() <= right());
    109109    }
     110
     111    bool isEmpty() const;
    110112
    111113    QModelIndexList indexes() const;
  • trunk/src/gui/itemviews/qitemselectionmodel_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    7171                                   QItemSelectionModel::SelectionFlags command) const;
    7272
     73    void initModel(QAbstractItemModel *model);
     74
    7375    void _q_rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
    7476    void _q_columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
  • trunk/src/gui/itemviews/qlistview.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    13881388/*!
    13891389  \reimp
     1390
     1391  Since 4.7, the returned region only contains rectangles intersecting
     1392  (or included in) the viewport.
    13901393*/
    13911394QRegion QListView::visualRegionForSelection(const QItemSelection &selection) const
     
    13951398    int c = d->column;
    13961399    QRegion selectionRegion;
     1400    const QRect &viewportRect = d->viewport->rect();
    13971401    for (int i = 0; i < selection.count(); ++i) {
    13981402        if (!selection.at(i).isValid())
     
    14061410        int b = selection.at(i).bottomRight().row();
    14071411        if (d->viewMode == IconMode || d->isWrapping()) { // in non-static mode, we have to go through all selected items
    1408             for (int r = t; r <= b; ++r)
    1409                 selectionRegion += QRegion(visualRect(d->model->index(r, c, parent)));
     1412            for (int r = t; r <= b; ++r) {
     1413                const QRect &rect = visualRect(d->model->index(r, c, parent));
     1414                if (viewportRect.intersects(rect))
     1415                    selectionRegion += rect;
     1416            }
    14101417        } else { // in static mode, we can optimize a bit
    14111418            while (t <= b && d->isHidden(t)) ++t;
     
    14151422            QRect rect(visualRect(top).topLeft(),
    14161423                       visualRect(bottom).bottomRight());
    1417             selectionRegion += QRegion(rect);
     1424            if (viewportRect.intersects(rect))
     1425                selectionRegion += rect;
    14181426        }
    14191427    }
     
    18461854    horizontalScrollBar()->setSingleStep(step.width() + spacing());
    18471855    horizontalScrollBar()->setPageStep(viewport()->width());
    1848     horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width() - 2 * spacing());
     1856    horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width());
    18491857}
    18501858
     
    18531861    verticalScrollBar()->setSingleStep(step.height() + spacing());
    18541862    verticalScrollBar()->setPageStep(viewport()->height());
    1855     verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height() - 2 * spacing());
     1863    verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height());
    18561864}
    18571865
     
    22692277    QStyleOptionViewItemV4 option = viewOptions();
    22702278    option.rect = info.bounds;
     2279    option.rect.adjust(info.spacing, info.spacing, -info.spacing, -info.spacing);
    22712280
    22722281    // The static layout data structures are as follows:
     
    27742783        items.reserve(rowCount() - hiddenCount());
    27752784    } else {
    2776         const QListViewItem item = items.at(info.first - 1);
     2785        int idx = info.first - 1;
     2786        while (idx > 0 && !items.at(idx).isValid())
     2787            --idx;
     2788        const QListViewItem &item = items.at(idx);
    27772789        x = item.x;
    27782790        y = item.y;
     
    28982910    bool done = (info.last >= rowCount() - 1);
    28992911    // resize the content area
    2900     if (done || !info.bounds.contains(item->rect()))
    2901         contentsSize = QSize(rect.width(), rect.height());
     2912    if (done || !info.bounds.contains(item->rect())) {
     2913        contentsSize = rect.size();
     2914        if (info.flow == QListView::LeftToRight)
     2915            contentsSize.rheight() += info.spacing;
     2916        else
     2917            contentsSize.rwidth() += info.spacing;
     2918    }
     2919    if (rect.size().isEmpty())
     2920        return;
    29022921    // resize tree
    29032922    int insertFrom = info.first;
  • trunk/src/gui/itemviews/qlistview.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qlistview_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qlistwidget.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    792792    This operator uses QListWidgetItem::write().
    793793
    794     \sa {Format of the QDataStream Operators}
     794    \sa {Serializing Qt Data Types}
    795795*/
    796796QDataStream &operator<<(QDataStream &out, const QListWidgetItem &item)
     
    807807    This operator uses QListWidgetItem::read().
    808808
    809     \sa {Format of the QDataStream Operators}
     809    \sa {Serializing Qt Data Types}
    810810*/
    811811QDataStream &operator>>(QDataStream &in, QListWidgetItem &item)
  • trunk/src/gui/itemviews/qlistwidget.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qlistwidget_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qproxymodel.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qproxymodel.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    6868    // implementing model interface
    6969
    70     QModelIndex index(int row, int column, const QModelIndex &parent) const;
     70    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
    7171    QModelIndex parent(const QModelIndex &child) const;
    7272
    73     int rowCount(const QModelIndex &parent) const;
    74     int columnCount(const QModelIndex &parent) const;
    75     bool hasChildren(const QModelIndex &parent) const;
     73    int rowCount(const QModelIndex &parent = QModelIndex()) const;
     74    int columnCount(const QModelIndex &parent = QModelIndex()) const;
     75    bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
    7676
    77     QVariant data(const QModelIndex &index, int role) const;
    78     bool setData(const QModelIndex &index, const QVariant &value, int role);
     77    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
     78    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
    7979
    80     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
     80    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
    8181    bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
    82                        int role);
     82                       int role = Qt::EditRole);
    8383
    8484    QStringList mimeTypes() const;
     
    8888    Qt::DropActions supportedDropActions() const;
    8989
    90     bool insertRows(int row, int count, const QModelIndex &parent);
    91     bool insertColumns(int column, int count, const QModelIndex &parent);
     90    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
     91    bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex());
    9292
    9393    void fetchMore(const QModelIndex &parent);
    9494    Qt::ItemFlags flags(const QModelIndex &index) const;
    9595
    96     void sort(int column, Qt::SortOrder order);
     96    void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
    9797
    9898    QModelIndexList match(const QModelIndex &start, int role, const QVariant &value,
    99                           int hits, Qt::MatchFlags flags) const;
     99                          int hits = 1, Qt::MatchFlags flags =
     100                          Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const;
    100101
    101102    QSize span(const QModelIndex &index) const;
  • trunk/src/gui/itemviews/qproxymodel_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qsortfilterproxymodel.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    112112
    113113
     114//this struct is used to store what are the rows that are removed
     115//between a call to rowsAboutToBeRemoved and rowsRemoved
     116//it avoids readding rows to the mapping that are currently being removed
     117struct QRowsRemoval
     118{
     119    QRowsRemoval(const QModelIndex &parent_source, int start, int end) : parent_source(parent_source), start(start), end(end)
     120    {
     121    }
     122
     123    QRowsRemoval() : start(-1), end(-1)
     124    {
     125    }
     126
     127    bool contains(QModelIndex parent, int row)
     128    {
     129        do {
     130            if (parent == parent_source)
     131                return row >= start && row <= end;
     132            row = parent.row();
     133            parent = parent.parent();
     134        } while (row >= 0);
     135        return false;
     136    }
     137private:
     138    QModelIndex parent_source;
     139    int start;
     140    int end;
     141};
     142
    114143class QSortFilterProxyModelPrivate : public QAbstractProxyModelPrivate
    115144{
     
    123152        QVector<int> proxy_columns;
    124153        QVector<QModelIndex> mapped_children;
    125         QMap<QModelIndex, Mapping *>::const_iterator map_iter;
     154        QHash<QModelIndex, Mapping *>::const_iterator map_iter;
    126155    };
    127156
    128     mutable QMap<QModelIndex, Mapping*> source_index_mapping;
     157    mutable QHash<QModelIndex, Mapping*> source_index_mapping;
    129158
    130159    int source_sort_column;
     
    140169
    141170    bool dynamic_sortfilter;
     171    QRowsRemoval itemsBeingRemoved;
    142172
    143173    QModelIndexPairList saved_persistent_indexes;
    144174
    145     QMap<QModelIndex, Mapping *>::const_iterator create_mapping(
     175    QHash<QModelIndex, Mapping *>::const_iterator create_mapping(
    146176        const QModelIndex &source_parent) const;
    147177    QModelIndex proxy_to_source(const QModelIndex &proxyIndex) const;
     
    151181    void remove_from_mapping(const QModelIndex &source_parent);
    152182
    153     inline QMap<QModelIndex, Mapping *>::const_iterator index_to_iterator(
     183    inline QHash<QModelIndex, Mapping *>::const_iterator index_to_iterator(
    154184        const QModelIndex &proxy_index) const
    155185    {
     
    158188        const void *p = proxy_index.internalPointer();
    159189        Q_ASSERT(p);
    160         QMap<QModelIndex, Mapping *>::const_iterator it =
     190        QHash<QModelIndex, Mapping *>::const_iterator it =
    161191            static_cast<const Mapping*>(p)->map_iter;
    162192        Q_ASSERT(it != source_index_mapping.constEnd());
     
    166196
    167197    inline QModelIndex create_index(int row, int column,
    168                                     QMap<QModelIndex, Mapping*>::const_iterator it) const
     198                                    QHash<QModelIndex, Mapping*>::const_iterator it) const
    169199    {
    170200        return q_func()->createIndex(row, column, *it);
     
    247277};
    248278
    249 typedef QMap<QModelIndex, QSortFilterProxyModelPrivate::Mapping *> IndexMap;
     279typedef QHash<QModelIndex, QSortFilterProxyModelPrivate::Mapping *> IndexMap;
    250280
    251281void QSortFilterProxyModelPrivate::_q_sourceModelDestroyed()
     
    271301    qDeleteAll(source_index_mapping);
    272302    source_index_mapping.clear();
     303    if (dynamic_sortfilter && update_source_sort_column()) {
     304        //update_source_sort_column might have created wrong mapping so we have to clear it again
     305        qDeleteAll(source_index_mapping);
     306        source_index_mapping.clear();
     307    }
    273308
    274309    // update the persistent indexes
     
    288323
    289324    int source_rows = model->rowCount(source_parent);
     325    m->source_rows.reserve(source_rows);
    290326    for (int i = 0; i < source_rows; ++i) {
    291327        if (q->filterAcceptsRow(i, source_parent))
     
    293329    }
    294330    int source_cols = model->columnCount(source_parent);
     331    m->source_columns.reserve(source_cols);
    295332    for (int i = 0; i < source_cols; ++i) {
    296333        if (q->filterAcceptsColumn(i, source_parent))
     
    559596    int source_items_index = 0;
    560597    QVector<int> source_items_in_interval;
    561     bool compare = (orient == Qt::Vertical && source_sort_column >= 0);
     598    bool compare = (orient == Qt::Vertical && source_sort_column >= 0 && dynamic_sortfilter);
    562599    while (source_items_index < source_items.size()) {
    563600        source_items_in_interval.clear();
     
    738775        // Items were inserted where there were none before.
    739776        // If it was new rows make sure to create mappings for columns so that a
    740         // valid mapping can be retreived later and vice-versa.
     777        // valid mapping can be retrieved later and vice-versa.
    741778
    742779        QVector<int> &orthogonal_proxy_to_source = (orient == Qt::Horizontal) ? m->source_rows : m->source_columns;
     
    745782        if (orthogonal_source_to_proxy.isEmpty()) {
    746783            const int ortho_end = (orient == Qt::Horizontal) ? model->rowCount(source_parent) : model->columnCount(source_parent);
     784
     785            orthogonal_source_to_proxy.resize(ortho_end);
    747786
    748787            for (int ortho_item = 0; ortho_item < ortho_end; ++ortho_item) {
     
    752791                }
    753792            }
    754             orthogonal_source_to_proxy.resize(orthogonal_proxy_to_source.size());
    755 
    756793            if (orient == Qt::Horizontal) {
    757794                // We're reacting to columnsInserted, but we've just inserted new rows. Sort them.
     
    10631100        return;
    10641101    QModelIndex source_parent = source_top_left.parent();
    1065     IndexMap::const_iterator it = create_mapping(source_parent);
     1102    IndexMap::const_iterator it = source_index_mapping.find(source_parent);
    10661103    if (it == source_index_mapping.constEnd()) {
    10671104        // Don't care, since we don't have mapping for this index
     
    10901127                }
    10911128            } else {
    1092                 if (q->filterAcceptsRow(source_row, source_parent)) {
     1129                if (!itemsBeingRemoved.contains(source_parent, source_row) && q->filterAcceptsRow(source_row, source_parent)) {
    10931130                    // This source row now satisfies the filter, so it must be added
    10941131                    source_rows_insert.append(source_row);
     
    11811218    Q_Q(QSortFilterProxyModel);
    11821219    q->beginResetModel();
     1220}
     1221
     1222void QSortFilterProxyModelPrivate::_q_sourceReset()
     1223{
     1224    Q_Q(QSortFilterProxyModel);
    11831225    invalidatePersistentIndexes();
    11841226    clear_mapping();
    1185 }
    1186 
    1187 void QSortFilterProxyModelPrivate::_q_sourceReset()
    1188 {
    1189     Q_Q(QSortFilterProxyModel);
    11901227    // All internal structures are deleted in clear()
    11911228    q->endResetModel();
     
    12091246{
    12101247    Q_Q(QSortFilterProxyModel);
    1211     if (saved_persistent_indexes.isEmpty()) {
    1212         clear_mapping();
    1213         emit q->layoutChanged();
    1214         return;
    1215     }
    12161248
    12171249    qDeleteAll(source_index_mapping);
     
    12211253    saved_persistent_indexes.clear();
    12221254
    1223     update_source_sort_column();
     1255    if (dynamic_sortfilter && update_source_sort_column()) {
     1256        //update_source_sort_column might have created wrong mapping so we have to clear it again
     1257        qDeleteAll(source_index_mapping);
     1258        source_index_mapping.clear();
     1259    }
    12241260
    12251261    emit q->layoutChanged();
     
    12411277{
    12421278    source_items_inserted(source_parent, start, end, Qt::Vertical);
    1243     if (update_source_sort_column()) //previous call to update_source_sort_column may fail if the model has no column.
     1279    if (update_source_sort_column() && dynamic_sortfilter) //previous call to update_source_sort_column may fail if the model has no column.
    12441280        sort();                      // now it should succeed so we need to make sure to sort again
    12451281}
     
    12481284    const QModelIndex &source_parent, int start, int end)
    12491285{
     1286    itemsBeingRemoved = QRowsRemoval(source_parent, start, end);
    12501287    source_items_about_to_be_removed(source_parent, start, end,
    12511288                                     Qt::Vertical);
     
    12551292    const QModelIndex &source_parent, int start, int end)
    12561293{
     1294    itemsBeingRemoved = QRowsRemoval();
    12571295    source_items_removed(source_parent, start, end, Qt::Vertical);
    12581296}
     
    12781316        return; //we sort according to the root column only
    12791317    if (source_sort_column == -1) {
    1280         //we update the source_sort_column depending on the prox_sort_column
    1281         if (update_source_sort_column())
     1318        //we update the source_sort_column depending on the proxy_sort_column
     1319        if (update_source_sort_column() && dynamic_sortfilter)
    12821320            sort();
    12831321    } else {
     
    14821520    d->filter_role = Qt::DisplayRole;
    14831521    d->dynamic_sortfilter = false;
    1484     connect(this, SIGNAL(modelReset()), this, SLOT(invalidate()));
    14851522}
    14861523
     
    21942231    whenever the contents of the source model change
    21952232
     2233    Note that you should not update the source model through the proxy
     2234    model when dynamicSortFilter is true. For instance, if you set the
     2235    proxy model on a QComboBox, then using functions that update the
     2236    model, e.g., \l{QComboBox::}{addItem()}, will not work as
     2237    expected. An alternative is to set dynamicSortFilter to false and
     2238    call \l{QSortFilterProxyModel::}{sort()} after adding items to the
     2239    QComboBox.
     2240
    21962241    The default value is false.
    21972242*/
     
    23562401    switch (l.userType()) {
    23572402    case QVariant::Invalid:
    2358         return (r.type() == QVariant::Invalid);
     2403        return (r.type() != QVariant::Invalid);
    23592404    case QVariant::Int:
    23602405        return l.toInt() < r.toInt();
  • trunk/src/gui/itemviews/qsortfilterproxymodel.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qstandarditemmodel.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    11311131  user cannot interact with the item.
    11321132
    1133   This flag takes presedence over the other item flags; e.g. if an item is not
     1133  This flag takes precedence over the other item flags; e.g. if an item is not
    11341134  enabled, it cannot be selected by the user, even if the Qt::ItemIsSelectable
    11351135  flag has been set.
     
    19221922    This operator uses QStandardItem::read().
    19231923
    1924     \sa {Format of the QDataStream Operators}
     1924    \sa {Serializing Qt Data Types}
    19251925*/
    19261926QDataStream &operator>>(QDataStream &in, QStandardItem &item)
     
    19381938    This operator uses QStandardItem::write().
    19391939
    1940     \sa {Format of the QDataStream Operators}
     1940    \sa {Serializing Qt Data Types}
    19411941*/
    19421942QDataStream &operator<<(QDataStream &out, const QStandardItem &item)
  • trunk/src/gui/itemviews/qstandarditemmodel.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qstandarditemmodel_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qstringlistmodel.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qstringlistmodel.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qstyleditemdelegate.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qstyleditemdelegate.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qtableview.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    115115    } else if (old_height > span->height()) {
    116116        //remove the span from all the subspans lists that intersect the columns not covered anymore
    117         Index::iterator it_y = index.lowerBound(-qMax(span->bottom(), span->top())); //qMax usefull if height is 0
     117        Index::iterator it_y = index.lowerBound(-qMax(span->bottom(), span->top())); //qMax useful if height is 0
    118118        Q_ASSERT(it_y != index.end()); //it_y must exist since the span is in the list
    119119        while (-it_y.key() <= span->top() + old_height -1) {
     
    14121412
    14131413        if (showGrid) {
    1414             // Find the bottom right (the last rows/coloumns might be hidden)
     1414            // Find the bottom right (the last rows/columns might be hidden)
    14151415            while (verticalHeader->isSectionHidden(verticalHeader->logicalIndex(bottom))) --bottom;
    14161416            QPen old = painter.pen();
     
    18471847        }
    18481848    } else { // nothing moved
    1849         selection.append(QItemSelectionRange(tl, br));
     1849        QItemSelectionRange range(tl, br);
     1850        if (!range.isEmpty())
     1851            selection.append(range);
    18501852    }
    18511853
     
    18581860    Returns the rectangle from the viewport of the items in the given
    18591861    \a selection.
     1862
     1863    Since 4.7, the returned region only contains rectangles intersecting
     1864    (or included in) the viewport.
    18601865*/
    18611866QRegion QTableView::visualRegionForSelection(const QItemSelection &selection) const
     
    18671872
    18681873    QRegion selectionRegion;
     1874    const QRect &viewportRect = d->viewport->rect();
    18691875    bool verticalMoved = verticalHeader()->sectionsMoved();
    18701876    bool horizontalMoved = horizontalHeader()->sectionsMoved();
     
    18761882                continue;
    18771883            for (int r = range.top(); r <= range.bottom(); ++r)
    1878                 for (int c = range.left(); c <= range.right(); ++c)
    1879                     selectionRegion += QRegion(visualRect(d->model->index(r, c, d->root)));
     1884                for (int c = range.left(); c <= range.right(); ++c) {
     1885                    const QRect &rangeRect = visualRect(d->model->index(r, c, d->root));
     1886                    if (viewportRect.intersects(rangeRect))
     1887                        selectionRegion += rangeRect;
     1888                }
    18801889        }
    18811890    } else if (horizontalMoved) {
     
    18891898                qSwap<int>(top, bottom);
    18901899            int height = bottom - top;
    1891             for (int c = range.left(); c <= range.right(); ++c)
    1892                 selectionRegion += QRegion(QRect(columnViewportPosition(c), top,
    1893                                                  columnWidth(c), height));
     1900            for (int c = range.left(); c <= range.right(); ++c) {
     1901                const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height);
     1902                if (viewportRect.intersects(rangeRect))
     1903                    selectionRegion += rangeRect;
     1904            }
    18941905        }
    18951906    } else if (verticalMoved) {
     
    19031914                qSwap<int>(left, right);
    19041915            int width = right - left;
    1905             for (int r = range.top(); r <= range.bottom(); ++r)
    1906                 selectionRegion += QRegion(QRect(left, rowViewportPosition(r),
    1907                                                  width, rowHeight(r)));
     1916            for (int r = range.top(); r <= range.bottom(); ++r) {
     1917                const QRect rangeRect(left, rowViewportPosition(r), width, rowHeight(r));
     1918                if (viewportRect.intersects(rangeRect))
     1919                    selectionRegion += rangeRect;
     1920            }
    19081921        }
    19091922    } else { // nothing moved
     
    19261939                rright = columnViewportPosition(range.left()) + columnWidth(range.left());
    19271940            }
    1928             selectionRegion += QRect(QPoint(rleft, rtop), QPoint(rright - 1 - gridAdjust, rbottom - 1 - gridAdjust));
     1941            const QRect rangeRect(QPoint(rleft, rtop), QPoint(rright - 1 - gridAdjust, rbottom - 1 - gridAdjust));
     1942            if (viewportRect.intersects(rangeRect))
     1943                selectionRegion += rangeRect;
    19291944            if (d->hasSpans()) {
    19301945                foreach (QSpanCollection::Span *s,
    19311946                         d->spans.spansInRect(range.left(), range.top(), range.width(), range.height())) {
    1932                     if (range.contains(s->top(), s->left(), range.parent()))
    1933                         selectionRegion += d->visualSpanRect(*s);
     1947                    if (range.contains(s->top(), s->left(), range.parent())) {
     1948                        const QRect &visualSpanRect = d->visualSpanRect(*s);
     1949                        if (viewportRect.intersects(visualSpanRect))
     1950                            selectionRegion += visualSpanRect;
     1951                    }
    19341952                }
    19351953            }
     
    19681986{
    19691987    Q_D(QTableView);
    1970     updateGeometries();
    1971     if (verticalScrollMode() == QAbstractItemView::ScrollPerItem)
    1972         d->verticalHeader->setOffsetToSectionPosition(verticalScrollBar()->value());
    1973     else
    1974         d->verticalHeader->setOffset(verticalScrollBar()->value());
    1975     d->viewport->update();
     1988    d->doDelayedItemsLayout();
    19761989}
    19771990
     
    21332146    ensurePolished();
    21342147
    2135     int left = qMax(0, columnAt(0));
    2136     int right = columnAt(d->viewport->width());
     2148    int left = qMax(0, d->horizontalHeader->visualIndexAt(0));
     2149    int right = d->horizontalHeader->visualIndexAt(d->viewport->width());
    21372150    if (right == -1) // the table don't have enough columns to fill the viewport
    21382151        right = d->model->columnCount(d->root) - 1;
     
    21922205    ensurePolished();
    21932206
    2194     int top = qMax(0, rowAt(0));
    2195     int bottom = rowAt(d->viewport->height());
     2207    int top = qMax(0, d->verticalHeader->visualIndexAt(0));
     2208    int bottom = d->verticalHeader->visualIndexAt(d->viewport->height());
    21962209    if (!isVisible() || bottom == -1) // the table don't have enough rows to fill the viewport
    21972210        bottom = d->model->rowCount(d->root) - 1;
  • trunk/src/gui/itemviews/qtableview.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qtableview_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qtablewidget.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    14291429    This operator uses QTableWidgetItem::read().
    14301430
    1431     \sa {Format of the QDataStream Operators}
     1431    \sa {Serializing Qt Data Types}
    14321432*/
    14331433QDataStream &operator>>(QDataStream &in, QTableWidgetItem &item)
     
    14441444    This operator uses QTableWidgetItem::write().
    14451445
    1446     \sa {Format of the QDataStream Operators}
     1446    \sa {Serializing Qt Data Types}
    14471447*/
    14481448QDataStream &operator<<(QDataStream &out, const QTableWidgetItem &item)
  • trunk/src/gui/itemviews/qtablewidget.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qtablewidget_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qtreeview.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    675675    // since QAbstractItemView::dataChanged() will get the visualRect for the items anyway
    676676
     677    bool sizeChanged = false;
    677678    int topViewIndex = d->viewIndex(topLeft);
    678     if (topViewIndex == 0)
    679         d->defaultItemHeight = indexRowSizeHint(topLeft);
    680     bool sizeChanged = false;
     679    if (topViewIndex == 0) {
     680        int newDefaultItemHeight = indexRowSizeHint(topLeft);
     681        sizeChanged = d->defaultItemHeight != newDefaultItemHeight;
     682        d->defaultItemHeight = newDefaultItemHeight;
     683    }
     684
    681685    if (topViewIndex != -1) {
    682         if (topLeft == bottomRight) {
     686        if (topLeft.row() == bottomRight.row()) {
    683687            int oldHeight = d->itemHeight(topViewIndex);
    684688            d->invalidateHeightCache(topViewIndex);
    685             sizeChanged = (oldHeight != d->itemHeight(topViewIndex));
     689            sizeChanged |= (oldHeight != d->itemHeight(topViewIndex));
     690            if (topLeft.column() == 0)
     691                d->viewItems[topViewIndex].hasChildren = d->hasVisibleChildren(topLeft);
    686692        } else {
    687693            int bottomViewIndex = d->viewIndex(bottomRight);
     
    690696                d->invalidateHeightCache(i);
    691697                sizeChanged |= (oldHeight != d->itemHeight(i));
     698                if (topLeft.column() == 0)
     699                    d->viewItems[i].hasChildren = d->hasVisibleChildren(d->viewItems.at(i).index);
    692700            }
    693701        }
     
    955963        start = d->model->index(0, 0, d->root);
    956964
    957     QTime now(QTime::currentTime());
    958965    bool skipRow = false;
    959     if (search.isEmpty()
    960         || (d->keyboardInputTime.msecsTo(now) > QApplication::keyboardInputInterval())) {
     966    bool keyboardTimeWasValid = d->keyboardInputTime.isValid();
     967    qint64 keyboardInputTimeElapsed = d->keyboardInputTime.restart();
     968    if (search.isEmpty() || !keyboardTimeWasValid
     969        || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) {
    961970        d->keyboardInput = search;
    962         skipRow = true;
     971        skipRow = currentIndex().isValid(); //if it is not valid we should really start at QModelIndex(0,0)
    963972    } else {
    964973        d->keyboardInput += search;
    965974    }
    966     d->keyboardInputTime = now;
    967975
    968976    // special case for searches with same key like 'aaaaa'
     
    12291237        d->hoverBranch = d->itemDecorationAt(he->pos());
    12301238        if (oldBranch != d->hoverBranch) {
    1231             QModelIndex oldIndex = d->modelIndex(oldBranch),
    1232                 newIndex = d->modelIndex(d->hoverBranch);
    1233             if (oldIndex != newIndex) {
    1234                 QRect oldRect = visualRect(oldIndex);
    1235                 QRect newRect = visualRect(newIndex);
    1236                 oldRect.setLeft(oldRect.left() - d->indent);
    1237                 newRect.setLeft(newRect.left() - d->indent);
    1238                 //we need to paint the whole items (including the decoration) so that when the user
    1239                 //moves the mouse over those elements they are updated
    1240                 viewport()->update(oldRect);
    1241                 viewport()->update(newRect);
     1239            //we need to paint the whole items (including the decoration) so that when the user
     1240            //moves the mouse over those elements they are updated
     1241            if (oldBranch >= 0) {
     1242                int y = d->coordinateForItem(oldBranch);
     1243                int h = d->itemHeight(oldBranch);
     1244                viewport()->update(QRect(0, y, viewport()->width(), h));
     1245            }
     1246            if (d->hoverBranch >= 0) {
     1247                int y = d->coordinateForItem(d->hoverBranch);
     1248                int h = d->itemHeight(d->hoverBranch);
     1249                viewport()->update(QRect(0, y, viewport()->width(), h));
    12421250            }
    12431251        }
     
    19942002{
    19952003    Q_D(QTreeView);
     2004    if (d->hasRemovedItems) {
     2005        //clean the QSet that may contains old (and this invalid) indexes
     2006        d->hasRemovedItems = false;
     2007        QSet<QPersistentModelIndex>::iterator it = d->expandedIndexes.begin();
     2008        while (it != d->expandedIndexes.constEnd()) {
     2009            if (!it->isValid())
     2010                it = d->expandedIndexes.erase(it);
     2011            else
     2012                ++it;
     2013        }
     2014        it = d->hiddenIndexes.begin();
     2015        while (it != d->hiddenIndexes.constEnd()) {
     2016            if (!it->isValid())
     2017                it = d->hiddenIndexes.erase(it);
     2018            else
     2019                ++it;
     2020        }
     2021    }
    19962022    d->viewItems.clear(); // prepare for new layout
    19972023    QModelIndex parent = d->root;
     
    21352161    case MoveLeft: {
    21362162        QScrollBar *sb = horizontalScrollBar();
    2137         if (vi < d->viewItems.count() && d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum())
     2163        if (vi < d->viewItems.count() && d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum()) {
    21382164            d->collapse(vi, true);
    2139         else {
     2165            d->moveCursorUpdatedView = true;
     2166        } else {
    21402167            bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, 0, this);
    21412168            if (descend) {
     
    21572184                }
    21582185
     2186                int oldValue = sb->value();
    21592187                sb->setValue(sb->value() - sb->singleStep());
     2188                if (oldValue != sb->value())
     2189                    d->moveCursorUpdatedView = true;
    21602190            }
    21612191
     
    21692199            && d->hasVisibleChildren(d->viewItems.at(vi).index)) {
    21702200            d->expand(vi, true);
     2201            d->moveCursorUpdatedView = true;
    21712202        } else {
    21722203            bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, 0, this);
     
    21912222                //last restort: we change the scrollbar value
    21922223                QScrollBar *sb = horizontalScrollBar();
     2224                int oldValue = sb->value();
    21932225                sb->setValue(sb->value() + sb->singleStep());
     2226                if (oldValue != sb->value())
     2227                    d->moveCursorUpdatedView = true;
    21942228            }
    21952229        }
     
    22502284  Returns the rectangle from the viewport of the items in the given
    22512285  \a selection.
     2286
     2287  Since 4.7, the returned region only contains rectangles intersecting
     2288  (or included in) the viewport.
    22522289*/
    22532290QRegion QTreeView::visualRegionForSelection(const QItemSelection &selection) const
     
    22582295
    22592296    QRegion selectionRegion;
     2297    const QRect &viewportRect = d->viewport->rect();
    22602298    for (int i = 0; i < selection.count(); ++i) {
    22612299        QItemSelectionRange range = selection.at(i);
     
    22902328        int height = bottom - top + 1;
    22912329        if (d->header->sectionsMoved()) {
    2292             for (int c = range.left(); c <= range.right(); ++c)
    2293                 selectionRegion += QRegion(QRect(columnViewportPosition(c), top,
    2294                                                  columnWidth(c), height));
     2330            for (int c = range.left(); c <= range.right(); ++c) {
     2331                const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height);
     2332                if (viewportRect.intersects(rangeRect))
     2333                    selectionRegion += rangeRect;
     2334            }
    22952335        } else {
    22962336            QRect combined = leftRect|rightRect;
    22972337            combined.setX(columnViewportPosition(isRightToLeft() ? range.right() : range.left()));
    2298             selectionRegion += combined;
     2338            if (viewportRect.intersects(combined))
     2339                selectionRegion += combined;
    22992340        }
    23002341    }
     
    24032444
    24042445/*!
    2405   \internal
    2406 */
    2407 static bool treeViewItemLessThan(const QTreeViewItem &left,
    2408                                  const QTreeViewItem &right)
    2409 {
    2410     if (left.level != right.level) {
    2411         Q_ASSERT(left.level > right.level);
    2412         QModelIndex leftParent = left.index.parent();
    2413         QModelIndex rightParent = right.index.parent();
    2414         // computer parent, don't get
    2415         while (leftParent.isValid() && leftParent.parent() != rightParent)
    2416             leftParent = leftParent.parent();
    2417         return (leftParent.row() < right.index.row());
    2418     }
    2419     return (left.index.row() < right.index.row());
    2420 }
    2421 
    2422 /*!
    24232446  Informs the view that the rows from the \a start row to the \a end row
    24242447  inclusive have been inserted into the \a parent model item.
     
    24492472    if (((parentItem != -1) && d->viewItems.at(parentItem).expanded && updatesEnabled())
    24502473        || (parent == d->root)) {
    2451         const uint childLevel = (parentItem == -1)
    2452                                 ? uint(0) : d->viewItems.at(parentItem).level + 1;
    2453         const int firstChildItem = parentItem + 1;
    2454         const int lastChildItem = firstChildItem + ((parentItem == -1)
    2455                                                     ? d->viewItems.count()
    2456                                                     : d->viewItems.at(parentItem).total) - 1;
    2457 
    2458         if (parentRowCount == end + 1 && start > 0) {
    2459             //need to Update hasMoreSiblings
    2460             int previousRow = start - 1;
    2461             QModelIndex previousSibilingModelIndex = d->model->index(previousRow, 0, parent);
    2462             bool isHidden = d->isRowHidden(previousSibilingModelIndex);
    2463             while (isHidden && previousRow > 0) {
    2464                 previousRow--;
    2465                 previousSibilingModelIndex = d->model->index(previousRow, 0, parent);
    2466                 isHidden = d->isRowHidden(previousSibilingModelIndex);
    2467             }
    2468             if (!isHidden) {
    2469                 const int previousSibilling = d->viewIndex(previousSibilingModelIndex);
    2470                 if(previousSibilling != -1)
    2471                     d->viewItems[previousSibilling].hasMoreSiblings = true;
    2472             }
    2473         }
    2474 
    2475         QVector<QTreeViewItem> insertedItems(delta);
    2476         for (int i = 0; i < delta; ++i) {
    2477             QTreeViewItem &item = insertedItems[i];
    2478             item.index = d->model->index(i + start, 0, parent);
    2479             item.level = childLevel;
    2480             item.hasChildren = d->hasVisibleChildren(item.index);
    2481             item.hasMoreSiblings = !((i == delta - 1) && (parentRowCount == end +1));
    2482         }
    2483         if (d->viewItems.isEmpty())
    2484             d->defaultItemHeight = indexRowSizeHint(insertedItems[0].index);
    2485 
    2486         int insertPos;
    2487         if (lastChildItem < firstChildItem) { // no children
    2488             insertPos = firstChildItem;
    2489         } else {
    2490             // do a binary search to figure out where to insert
    2491             QVector<QTreeViewItem>::iterator it;
    2492             it = qLowerBound(d->viewItems.begin() + firstChildItem,
    2493                              d->viewItems.begin() + lastChildItem + 1,
    2494                              insertedItems.at(0), treeViewItemLessThan);
    2495             insertPos = it - d->viewItems.begin();
    2496 
    2497             // update stale model indexes of siblings
    2498             for (int item = insertPos; item <= lastChildItem; ) {
    2499                 Q_ASSERT(d->viewItems.at(item).level == childLevel);
    2500                 const QModelIndex modelIndex = d->viewItems.at(item).index;
    2501                 //Q_ASSERT(modelIndex.parent() == parent);
    2502                 d->viewItems[item].index = d->model->index(
    2503                     modelIndex.row() + delta, modelIndex.column(), parent);
    2504 
    2505                 if (!d->viewItems[item].index.isValid()) {
    2506                     // Something really bad is happening, a bad model is
    2507                     // often the cause.  We can't optimize in this case :(
    2508                     qWarning() << "QTreeView::rowsInserted internal representation of the model has been corrupted, resetting.";
    2509                     doItemsLayout();
    2510                     return;
    2511                 }
    2512 
    2513                 item += d->viewItems.at(item).total + 1;
    2514             }
    2515         }
    2516 
    2517         d->viewItems.insert(insertPos, delta, insertedItems.at(0));
    2518         if (delta > 1) {
    2519             qCopy(insertedItems.begin() + 1, insertedItems.end(),
    2520                   d->viewItems.begin() + insertPos + 1);
    2521         }
    2522 
    2523         if (parentItem != -1)
    2524             d->viewItems[parentItem].hasChildren = true;
    2525         d->updateChildCount(parentItem, delta);
    2526 
    2527         updateGeometries();
    2528         viewport()->update();
     2474        d->doDelayedItemsLayout();
    25292475    } else if ((parentItem != -1) && d->viewItems.at(parentItem).expanded) {
    25302476        d->doDelayedItemsLayout();
     
    25442490{
    25452491    Q_D(QTreeView);
    2546     d->rowsRemoved(parent, start, end, false);
    25472492    QAbstractItemView::rowsAboutToBeRemoved(parent, start, end);
     2493    d->viewItems.clear();
    25482494}
    25492495
     
    25572503{
    25582504    Q_D(QTreeView);
    2559     d->rowsRemoved(parent, start, end, true);
     2505    d->viewItems.clear();
     2506    d->doDelayedItemsLayout();
     2507    d->hasRemovedItems = true;
     2508    d->_q_rowsRemoved(parent, start, end);
    25602509}
    25612510
     
    26592608    Q_D(QTreeView);
    26602609    d->viewItems.clear();
    2661     d->expandedIndexes.clear();
    26622610    d->interruptDelayedItemsLayout();
    2663     d->layout(-1);
    2664     for (int i = 0; i < d->viewItems.count(); ++i) {
    2665         if (d->viewItems[i].expanded)
    2666             continue;
    2667         d->viewItems[i].expanded = true;
    2668         d->layout(i);
    2669         QModelIndex idx = d->viewItems.at(i).index;
    2670         d->expandedIndexes.insert(idx);
    2671     }
     2611    d->layout(-1, true);
    26722612    updateGeometries();
    26732613    d->viewport->update();
     
    29502890}
    29512891
     2892void QTreeViewPrivate::insertViewItems(int pos, int count, const QTreeViewItem &viewItem)
     2893{
     2894    viewItems.insert(pos, count, viewItem);
     2895    QTreeViewItem *items = viewItems.data();
     2896    for (int i = pos + count; i < viewItems.count(); i++)
     2897        if (items[i].parentItem >= pos)
     2898            items[i].parentItem += count;
     2899}
     2900
     2901void QTreeViewPrivate::removeViewItems(int pos, int count)
     2902{
     2903    viewItems.remove(pos, count);
     2904    QTreeViewItem *items = viewItems.data();
     2905    for (int i = pos; i < viewItems.count(); i++)
     2906        if (items[i].parentItem >= pos)
     2907            items[i].parentItem -= count;
     2908}
     2909
     2910#if 0
     2911bool QTreeViewPrivate::checkViewItems() const
     2912{
     2913    for (int i = 0; i < viewItems.count(); ++i) {
     2914        const QTreeViewItem &vi = viewItems.at(i);
     2915        if (vi.parentItem == -1) {
     2916            Q_ASSERT(!vi.index.parent().isValid() || vi.index.parent() == root);
     2917        } else {
     2918            Q_ASSERT(vi.index.parent() == viewItems.at(vi.parentItem).index);
     2919        }
     2920    }
     2921    return true;
     2922}
     2923#endif
     2924
    29522925void QTreeViewPrivate::collapse(int item, bool emitSignal)
    29532926{
     
    29782951    viewItems[item].expanded = false;
    29792952    int index = item;
    2980     QModelIndex parent = modelIndex;
    2981     while (parent.isValid() && parent != root) {
    2982         Q_ASSERT(index > -1);
     2953    while (index > -1) {
    29832954        viewItems[index].total -= total;
    2984         parent = parent.parent();
    2985         index = viewIndex(parent);
    2986     }
    2987     viewItems.remove(item + 1, total); // collapse
     2955        index = viewItems[index].parentItem;
     2956    }
     2957    removeViewItems(item + 1, total); // collapse
    29882958    q->setState(oldState);
    29892959
     
    31223092}
    31233093
    3124 void QTreeViewPrivate::layout(int i)
     3094/** \internal
     3095    creates and initialize the viewItem structure of the children of the element \i
     3096
     3097    set \a recursiveExpanding if the function has to expand all the children (called from expandAll)
     3098    \a afterIsUninitialized is when we recurse from layout(-1), it means all the items after 'i' are
     3099    not yet initialized and need not to be moved
     3100 */
     3101void QTreeViewPrivate::layout(int i, bool recursiveExpanding, bool afterIsUninitialized)
    31253102{
    31263103    Q_Q(QTreeView);
     
    31493126        }
    31503127        viewItems.resize(count);
     3128        afterIsUninitialized = true;
    31513129    } else if (viewItems[i].total != (uint)count) {
    3152             viewItems.insert(i + 1, count, QTreeViewItem()); // expand
     3130        if (!afterIsUninitialized)
     3131            insertViewItems(i + 1, count, QTreeViewItem()); // expand
     3132        else if (count > 0)
     3133            viewItems.resize(viewItems.count() + count);
    31533134    } else {
    31543135        expanding = false;
     
    31723153            item = &viewItems[last];
    31733154            item->index = current;
     3155            item->parentItem = i;
    31743156            item->level = level;
    31753157            item->height = 0;
     
    31783160            item->total = 0;
    31793161            item->hasMoreSiblings = false;
    3180             if (isIndexExpanded(current)) {
     3162            if (recursiveExpanding || isIndexExpanded(current)) {
     3163                if (recursiveExpanding)
     3164                    expandedIndexes.insert(current);
    31813165                item->expanded = true;
    3182                 layout(last);
     3166                layout(last, recursiveExpanding, afterIsUninitialized);
    31833167                item = &viewItems[last];
    31843168                children += item->total;
     
    31923176
    31933177    // remove hidden items
    3194     if (hidden > 0)
    3195         viewItems.remove(last + 1, hidden); // collapse
     3178    if (hidden > 0) {
     3179        if (!afterIsUninitialized)
     3180            removeViewItems(last + 1, hidden);
     3181        else
     3182            viewItems.resize(viewItems.size() - hidden);
     3183    }
    31963184
    31973185    if (!expanding)
    31983186        return; // nothing changed
    31993187
    3200     while (parent != root) {
    3201         Q_ASSERT(i > -1);
     3188    while (i > -1) {
    32023189        viewItems[i].total += count - hidden;
    3203         parent = parent.parent();
    3204         i = viewIndex(parent);
     3190        i = viewItems[i].parentItem;
    32053191    }
    32063192}
     
    32093195{
    32103196    int index = itemAtCoordinate(coordinateForItem(i) - viewport->height());
     3197    while (isItemHiddenOrDisabled(index))
     3198        index--;
    32113199    return index == -1 ? 0 : index;
    32123200}
     
    32153203{
    32163204    int index = itemAtCoordinate(coordinateForItem(i) + viewport->height());
     3205    while (isItemHiddenOrDisabled(index))
     3206        index++;
    32173207    return index == -1 ? viewItems.count() - 1 : index;
    32183208}
     
    33573347    const int totalCount = viewItems.count();
    33583348    const QModelIndex index = _index.sibling(_index.row(), 0);
    3359 
    3360 
    3361     // A quick check near the last item to see if we are just incrementing
    3362     const int start = lastViewedItem > 2 ? lastViewedItem - 2 : 0;
    3363     const int end = lastViewedItem < totalCount - 2 ? lastViewedItem + 2 : totalCount;
    3364     int row = index.row();
    3365     for (int i = start; i < end; ++i) {
    3366         const QModelIndex &idx = viewItems.at(i).index;
    3367         if (idx.row() == row) {
    3368             if (idx.internalId() == index.internalId()) {
    3369                 lastViewedItem = i;
    3370                 return i;
    3371             }
    3372         }
    3373     }
    3374 
    3375     // NOTE: this function is slow if the item is outside the visible area
    3376     // search in visible items first and below
    3377     int t = firstVisibleItem();
    3378     t = t > 100 ? t - 100 : 0; // start 100 items above the visible area
    3379 
    3380     for (int i = t; i < totalCount; ++i) {
    3381         const QModelIndex &idx = viewItems.at(i).index;
    3382         if (idx.row() == row) {
    3383             if (idx.internalId() == index.internalId()) {
    3384                 lastViewedItem = i;
    3385                 return i;
    3386             }
    3387         }
    3388     }
    3389     // search from top to first visible
    3390     for (int j = 0; j < t; ++j) {
     3349    const int row = index.row();
     3350    const qint64 internalId = index.internalId();
     3351
     3352    // We start nearest to the lastViewedItem
     3353    int localCount = qMin(lastViewedItem - 1, totalCount - lastViewedItem);
     3354    for (int i = 0; i < localCount; ++i) {
     3355        const QModelIndex &idx1 = viewItems.at(lastViewedItem + i).index;
     3356        if (idx1.row() == row && idx1.internalId() == internalId) {
     3357            lastViewedItem = lastViewedItem + i;
     3358            return lastViewedItem;
     3359        }
     3360        const QModelIndex &idx2 = viewItems.at(lastViewedItem - i - 1).index;
     3361        if (idx2.row() == row && idx2.internalId() == internalId) {
     3362            lastViewedItem = lastViewedItem - i - 1;
     3363            return lastViewedItem;
     3364        }
     3365    }
     3366
     3367    for (int j = qMax(0, lastViewedItem + localCount); j < totalCount; ++j) {
    33913368        const QModelIndex &idx = viewItems.at(j).index;
    3392         if (idx.row() == row) {
    3393             if (idx.internalId() == index.internalId()) {
    3394                 lastViewedItem = j;
    3395                 return j;
    3396             }
    3397         }
    3398     }
     3369        if (idx.row() == row && idx.internalId() == internalId) {
     3370            lastViewedItem = j;
     3371            return j;
     3372        }
     3373    }
     3374    for (int j = qMin(totalCount, lastViewedItem - localCount) - 1; j >= 0; --j) {
     3375        const QModelIndex &idx = viewItems.at(j).index;
     3376        if (idx.row() == row && idx.internalId() == internalId) {
     3377            lastViewedItem = j;
     3378            return j;
     3379        }
     3380    }
     3381
    33993382    // nothing found
    34003383    return -1;
     
    34463429}
    34473430
    3448 void QTreeViewPrivate::relayout(const QModelIndex &parent)
    3449 {
    3450     Q_Q(QTreeView);
    3451     // do a local relayout of the items
    3452     if (parent.isValid()) {
    3453         int parentViewIndex = viewIndex(parent);
    3454         if (parentViewIndex > -1 && viewItems.at(parentViewIndex).expanded) {
    3455             collapse(parentViewIndex, false); // remove the current layout
    3456             expand(parentViewIndex, false); // do the relayout
    3457             q->updateGeometries();
    3458             viewport->update();
    3459         }
    3460     } else {
    3461         viewItems.clear();
    3462         q->doItemsLayout();
    3463     }
    3464 }
    3465 
    3466 
    34673431void QTreeViewPrivate::updateScrollBars()
    34683432{
     
    34713435    if (!viewportSize.isValid())
    34723436        viewportSize = QSize(0, 0);
     3437
     3438    if (viewItems.isEmpty()) {
     3439        q->doItemsLayout();
     3440    }
    34733441
    34743442    int itemsInViewport = 0;
     
    37183686}
    37193687
    3720 void QTreeViewPrivate::rowsRemoved(const QModelIndex &parent,
    3721                                    int start, int end, bool after)
    3722 {
    3723     Q_Q(QTreeView);
    3724     // if we are going to do a complete relayout anyway, there is no need to update
    3725     if (delayedPendingLayout) {
    3726         _q_rowsRemoved(parent, start, end);
    3727         return;
    3728     }
    3729 
    3730     const int parentItem = viewIndex(parent);
    3731     if ((parentItem != -1) || (parent == root)) {
    3732 
    3733         const uint childLevel = (parentItem == -1)
    3734                                 ? uint(0) : viewItems.at(parentItem).level + 1;
    3735         Q_UNUSED(childLevel); // unused in release mode, used in assert below
    3736 
    3737         const int firstChildItem = parentItem + 1;
    3738         int lastChildItem = firstChildItem + ((parentItem == -1)
    3739                                               ? viewItems.count()
    3740                                               : viewItems.at(parentItem).total) - 1;
    3741 
    3742         const int delta = end - start + 1;
    3743 
    3744         int previousSibiling = -1;
    3745         int removedCount = 0;
    3746         for (int item = firstChildItem; item <= lastChildItem; ) {
    3747             Q_ASSERT(viewItems.at(item).level == childLevel);
    3748             const QModelIndex modelIndex = viewItems.at(item).index;
    3749             //Q_ASSERT(modelIndex.parent() == parent);
    3750             const int count = viewItems.at(item).total + 1;
    3751             if (modelIndex.row() < start) {
    3752                 previousSibiling = item;
    3753                 // not affected by the removal
    3754                 item += count;
    3755             } else if (modelIndex.row() <= end) {
    3756                 // removed
    3757                 viewItems.remove(item, count);
    3758                 removedCount += count;
    3759                 lastChildItem -= count;
    3760             } else {
    3761                 if (after) {
    3762                     // moved; update the model index
    3763                     viewItems[item].index = model->index(
    3764                         modelIndex.row() - delta, modelIndex.column(), parent);
    3765                 }
    3766                 item += count;
    3767             }
    3768         }
    3769 
    3770         if (previousSibiling != -1 && after && model->rowCount(parent) == start)
    3771             viewItems[previousSibiling].hasMoreSiblings = false;
    3772 
    3773         if (parentItem != -1) {
    3774             if (viewItems.at(parentItem).expanded) {
    3775                 updateChildCount(parentItem, -removedCount);
    3776                 if (viewItems.at(parentItem).total == 0)
    3777                     viewItems[parentItem].hasChildren = false; //every children have been removed;
    3778             } else if (viewItems[parentItem].hasChildren && !hasVisibleChildren(parent)) {
    3779                 viewItems[parentItem].hasChildren = false;
    3780             }
    3781         }
    3782         if (after) {
    3783             q->updateGeometries();
    3784             viewport->update();
    3785         } else {
    3786             //we have removed items: we should at least update the scroll bar values.
    3787             // They are used to determine the item geometry.
    3788             updateScrollBars();
    3789         }
    3790     } else {
    3791         // If an ancestor of root is removed then relayout
    3792         QModelIndex idx = root;
    3793         while (idx.isValid()) {
    3794             idx = idx.parent();
    3795             if (idx == parent) {
    3796                 doDelayedItemsLayout();
    3797                 break;
    3798             }
    3799         }
    3800     }
    3801     _q_rowsRemoved(parent, start, end);
    3802 
    3803     QSet<QPersistentModelIndex>::iterator it = expandedIndexes.begin();
    3804     while (it != expandedIndexes.constEnd()) {
    3805         if (!it->isValid())
    3806             it = expandedIndexes.erase(it);
    3807         else
    3808             ++it;
    3809     }
    3810     it = hiddenIndexes.begin();
    3811     while (it != hiddenIndexes.constEnd()) {
    3812         if (!it->isValid())
    3813             it = hiddenIndexes.erase(it);
    3814         else
    3815             ++it;
    3816     }
    3817 }
    3818 
    3819 void QTreeViewPrivate::updateChildCount(const int parentItem, const int delta)
    3820 {
    3821     if ((parentItem != -1) && delta) {
    3822         int level = viewItems.at(parentItem).level;
    3823         int item = parentItem;
    3824         do {
    3825             Q_ASSERT(item >= 0);
    3826             for ( ; int(viewItems.at(item).level) != level; --item) ;
    3827             viewItems[item].total += delta;
    3828             --level;
    3829         } while (level >= 0);
    3830     }
    3831 }
    3832 
    3833 
    38343688void QTreeViewPrivate::_q_sortIndicatorChanged(int column, Qt::SortOrder order)
    38353689{
  • trunk/src/gui/itemviews/qtreeview.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qtreeview_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5656#include "private/qabstractitemview_p.h"
    5757#include <QtCore/qvariantanimation.h>
     58#include <QtCore/qabstractitemmodel.h>
    5859
    5960#ifndef QT_NO_TREEVIEW
     
    6364struct QTreeViewItem
    6465{
    65     QTreeViewItem() : expanded(false), spanning(false), hasChildren(false),
     66    QTreeViewItem() : parentItem(-1), expanded(false), spanning(false), hasChildren(false),
    6667                      hasMoreSiblings(false), total(0), level(0), height(0) {}
    6768    QModelIndex index; // we remove items whenever the indexes are invalidated
     69    int parentItem; // parent item index in viewItems
    6870    uint expanded : 1;
    6971    uint spanning : 1;
     
    7577};
    7678
     79Q_DECLARE_TYPEINFO(QTreeViewItem, Q_MOVABLE_TYPE);
     80
    7781class QTreeViewPrivate : public QAbstractItemViewPrivate
    7882{
     
    8892          allColumnsShowFocus(false), current(0), spanning(false),
    8993          animationsEnabled(false), columnResizeTimerID(0),
    90           autoExpandDelay(-1), hoverBranch(-1), geometryRecursionBlock(false) {}
     94          autoExpandDelay(-1), hoverBranch(-1), geometryRecursionBlock(false), hasRemovedItems(false) {}
    9195
    9296    ~QTreeViewPrivate() {}
     
    124128    void _q_modelDestroyed();
    125129
    126     void layout(int item);
     130    void layout(int item, bool recusiveExpanding = false, bool afterIsUninitialized = false);
    127131
    128132    int pageUp(int item) const;
     
    137141    QModelIndex modelIndex(int i, int column = 0) const;
    138142
     143    void insertViewItems(int pos, int count, const QTreeViewItem &viewItem);
     144    void removeViewItems(int pos, int count);
     145#if 0
     146    bool checkViewItems() const;
     147#endif
     148
    139149    int firstVisibleItem(int *offset = 0) const;
    140150    int columnAt(int x) const;
    141151    bool hasVisibleChildren( const QModelIndex& parent) const;
    142152
    143     void relayout(const QModelIndex &parent);
    144153    bool expandOrCollapseItemAtPos(const QPoint &pos);
    145154
     
    156165
    157166    void updateChildCount(const int parentItem, const int delta);
    158     void rowsRemoved(const QModelIndex &parent,
    159                      int start, int end, bool before);
    160167
    161168    void paintAlternatingRowColors(QPainter *painter, QStyleOptionViewItemV4 *option, int y, int bottom) const;
     
    233240    // used for blocking recursion when calling setViewportMargins from updateGeometries
    234241    bool geometryRecursionBlock;
     242
     243    // If we should clean the set
     244    bool hasRemovedItems;
    235245};
    236246
  • trunk/src/gui/itemviews/qtreewidget.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    14731473/*!
    14741474  Destroys this tree widget item.
     1475 
     1476  The item will be removed from \l{QTreeWidget}s to which it has
     1477  been added. This makes it safe to delete an item at any time.
     1478
    14751479*/
    14761480
     
    22002204    This operator uses QTreeWidgetItem::write().
    22012205
    2202     \sa {Format of the QDataStream Operators}
     2206    \sa {Serializing Qt Data Types}
    22032207*/
    22042208QDataStream &operator<<(QDataStream &out, const QTreeWidgetItem &item)
     
    22152219    This operator uses QTreeWidgetItem::read().
    22162220
    2217     \sa {Format of the QDataStream Operators}
     2221    \sa {Serializing Qt Data Types}
    22182222*/
    22192223QDataStream &operator>>(QDataStream &in, QTreeWidgetItem &item)
     
    30403044    QModelIndexList indexes = selectionModel()->selectedIndexes();
    30413045    QList<QTreeWidgetItem*> items;
     3046    items.reserve(indexes.count());
     3047    QSet<QTreeWidgetItem *> seen;
     3048    seen.reserve(indexes.count());
    30423049    for (int i = 0; i < indexes.count(); ++i) {
    30433050        QTreeWidgetItem *item = d->item(indexes.at(i));
    3044         if (isItemHidden(item) || items.contains(item)) // ### slow, optimize later
     3051        if (isItemHidden(item) || seen.contains(item))
    30453052            continue;
     3053        seen.insert(item);
    30463054        items.append(item);
    30473055    }
  • trunk/src/gui/itemviews/qtreewidget.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qtreewidget_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qtreewidgetitemiterator.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qtreewidgetitemiterator.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qtreewidgetitemiterator_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/gui/itemviews/qwidgetitemdata_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
Note: See TracChangeset for help on using the changeset viewer.