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:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • 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);
Note: See TracChangeset for help on using the changeset viewer.