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

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

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

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    271271*/
    272272
    273 /*!
    274     Returns the list of model index items stored in the selection.
    275 */
    276 
    277 QModelIndexList QItemSelectionRange::indexes() const
    278 {
    279     QModelIndex index;
    280     QModelIndexList result;
    281     if (isValid() && model()) {
    282         for (int column = left(); column <= right(); ++column) {
    283             for (int row = top(); row <= bottom(); ++row) {
    284                 index = model()->index(row, column, parent());
    285                 Qt::ItemFlags flags = model()->flags(index);
     273/*
     274  \internal
     275
     276  utility function for getting the indexes from a range
     277  it avoid concatenating list and works on one
     278 */
     279
     280static void indexesFromRange(const QItemSelectionRange &range, QModelIndexList &result)
     281{
     282    if (range.isValid() && range.model()) {
     283        for (int column = range.left(); column <= range.right(); ++column) {
     284            for (int row = range.top(); row <= range.bottom(); ++row) {
     285                QModelIndex index = range.model()->index(row, column, range.parent());
     286                Qt::ItemFlags flags = range.model()->flags(index);
    286287                if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled))
    287288                    result.append(index);
     
    289290        }
    290291    }
     292}
     293
     294/*!
     295    Returns the list of model index items stored in the selection.
     296*/
     297
     298QModelIndexList QItemSelectionRange::indexes() const
     299{
     300    QModelIndexList result;
     301    indexesFromRange(*this, result);
    291302    return result;
    292303}
    293304
    294305/*!
    295   \class QItemSelection
    296 
    297   \brief The QItemSelection class manages information about selected items in a model.
    298 
    299   \ingroup model-view
    300 
    301   A QItemSelection describes the items in a model that have been
    302   selected by the user. A QItemSelection is basically a list of
    303   selection ranges, see QItemSelectionRange. It provides functions for
    304   creating and manipulating selections, and selecting a range of items
    305   from a model.
    306 
    307   The QItemSelection class is one of the \l{Model/View Classes}
    308   and is part of Qt's \l{Model/View Programming}{model/view framework}.
    309 
    310   An item selection can be constructed and initialized to contain a
    311   range of items from an existing model. The following example constructs
    312   a selection that contains a range of items from the given \c model,
    313   beginning at the \c topLeft, and ending at the \c bottomRight.
    314 
    315   \snippet doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp 0
    316 
    317   An empty item selection can be constructed, and later populated as
    318   required. So, if the model is going to be unavailable when we construct
    319   the item selection, we can rewrite the above code in the following way:
    320 
    321   \snippet doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp 1
    322 
    323   QItemSelection saves memory, and avoids unnecessary work, by working with
    324   selection ranges rather than recording the model item index for each
    325   item in the selection. Generally, an instance of this class will contain
    326   a list of non-overlapping selection ranges.
    327 
    328   Use merge() to merge one item selection into another without making
    329   overlapping ranges. Use split() to split one selection range into
    330   smaller ranges based on a another selection range.
    331 
    332   \sa {Model/View Programming}, QItemSelectionModel
    333 
     306    \class QItemSelection
     307
     308    \brief The QItemSelection class manages information about selected items in a model.
     309
     310    \ingroup model-view
     311
     312    A QItemSelection describes the items in a model that have been
     313    selected by the user. A QItemSelection is basically a list of
     314    selection ranges, see QItemSelectionRange. It provides functions for
     315    creating and manipulating selections, and selecting a range of items
     316    from a model.
     317
     318    The QItemSelection class is one of the \l{Model/View Classes}
     319    and is part of Qt's \l{Model/View Programming}{model/view framework}.
     320
     321    An item selection can be constructed and initialized to contain a
     322    range of items from an existing model. The following example constructs
     323    a selection that contains a range of items from the given \c model,
     324    beginning at the \c topLeft, and ending at the \c bottomRight.
     325
     326    \snippet doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp 0
     327
     328    An empty item selection can be constructed, and later populated as
     329    required. So, if the model is going to be unavailable when we construct
     330    the item selection, we can rewrite the above code in the following way:
     331
     332    \snippet doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp 1
     333
     334    QItemSelection saves memory, and avoids unnecessary work, by working with
     335    selection ranges rather than recording the model item index for each
     336    item in the selection. Generally, an instance of this class will contain
     337    a list of non-overlapping selection ranges.
     338
     339    Use merge() to merge one item selection into another without making
     340    overlapping ranges. Use split() to split one selection range into
     341    smaller ranges based on a another selection range.
     342
     343    \sa {Model/View Programming}, QItemSelectionModel
    334344*/
    335345
     
    405415    QList<QItemSelectionRange>::const_iterator it = begin();
    406416    for (; it != end(); ++it)
    407         result += (*it).indexes();
     417        indexesFromRange(*it, result);
    408418    return result;
    409419}
    410420
    411421/*!
    412   Merges the \a other selection with this QItemSelection using the
    413   \a command given. This method guarantees that no ranges are overlapping.
    414 
    415   Note that only QItemSelectionModel::Select,
    416   QItemSelectionModel::Deselect, and QItemSelectionModel::Toggle are
    417   supported.
    418 
    419   \sa split()
     422    Merges the \a other selection with this QItemSelection using the
     423    \a command given. This method guarantees that no ranges are overlapping.
     424
     425    Note that only QItemSelectionModel::Select,
     426    QItemSelectionModel::Deselect, and QItemSelectionModel::Toggle are
     427    supported.
     428
     429    \sa split()
    420430*/
    421431void QItemSelection::merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
     
    469479
    470480/*!
    471   Splits the selection \a range using the selection \a other range.
    472   Removes all items in \a other from \a range and puts the result in \a result.
    473   This can be compared with the semantics of the \e subtract operation of a set.
    474   \sa merge()
     481    Splits the selection \a range using the selection \a other range.
     482    Removes all items in \a other from \a range and puts the result in \a result.
     483    This can be compared with the semantics of the \e subtract operation of a set.
     484    \sa merge()
    475485*/
    476486
     
    519529
    520530/*!
    521   \internal
    522 
    523   returns a QItemSelection where all ranges have been expanded to:
    524   Rows: left: 0 and right: columnCount()-1
    525   Columns: top: 0 and bottom: rowCount()-1
     531    \internal
     532
     533    returns a QItemSelection where all ranges have been expanded to:
     534    Rows: left: 0 and right: columnCount()-1
     535    Columns: top: 0 and bottom: rowCount()-1
    526536*/
    527537
     
    558568
    559569/*!
    560   \internal
     570    \internal
    561571*/
    562572void QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &parent,
     
    564574{
    565575    Q_Q(QItemSelectionModel);
     576    finalize();
    566577
    567578    // update current index
     
    581592    }
    582593
    583     // update selectionsx
    584     QModelIndex tl = model->index(start, 0, parent);
    585     QModelIndex br = model->index(end, model->columnCount(parent) - 1, parent);
    586     q->select(QItemSelection(tl, br), QItemSelectionModel::Deselect);
    587     finalize();
    588 }
    589 
    590 /*!
    591   \internal
     594    QItemSelection deselected;
     595    QItemSelection::iterator it = ranges.begin();
     596    while (it != ranges.end()) {
     597        if (it->topLeft().parent() != parent) {  // Check parents until reaching root or contained in range
     598            QModelIndex itParent = it->topLeft().parent();
     599            while (itParent.isValid() && itParent.parent() != parent)
     600                itParent = itParent.parent();
     601
     602            if (itParent.isValid() && start <= itParent.row() && itParent.row() <= end) {
     603                deselected.append(*it);
     604                it = ranges.erase(it);
     605            } else {
     606                ++it;
     607            }
     608        } else if (start <= it->bottom() && it->bottom() <= end    // Full inclusion
     609                   && start <= it->top() && it->top() <= end) {
     610            deselected.append(*it);
     611            it = ranges.erase(it);
     612        } else if (start <= it->top() && it->top() <= end) {      // Top intersection
     613            deselected.append(QItemSelectionRange(it->topLeft(), model->index(end, it->left(), it->parent())));
     614            *it = QItemSelectionRange(model->index(end + 1, it->left(), it->parent()), it->bottomRight());
     615            ++it;
     616        } else if (start <= it->bottom() && it->bottom() <= end) {    // Bottom intersection
     617            deselected.append(QItemSelectionRange(model->index(start, it->right(), it->parent()), it->bottomRight()));
     618            *it = QItemSelectionRange(it->topLeft(), model->index(start - 1, it->right(), it->parent()));
     619            ++it;
     620        } else {
     621            if (it->top() < start && end < it->bottom())  // Middle intersection (do nothing)
     622                deselected.append(QItemSelectionRange(model->index(start, it->right(), it->parent()),
     623                                                      model->index(end, it->left(), it->parent())));
     624            ++it;
     625       }
     626    }
     627
     628    if (!deselected.isEmpty())
     629        emit q->selectionChanged(QItemSelection(), deselected);
     630}
     631
     632/*!
     633    \internal
    592634*/
    593635void QItemSelectionModelPrivate::_q_columnsAboutToBeRemoved(const QModelIndex &parent,
     
    620662
    621663/*!
    622   \internal
    623 
    624   Split selection ranges if columns are about to be inserted in the middle.
     664    \internal
     665
     666    Split selection ranges if columns are about to be inserted in the middle.
    625667*/
    626668void QItemSelectionModelPrivate::_q_columnsAboutToBeInserted(const QModelIndex &parent,
     
    649691
    650692/*!
    651   \internal
    652 
    653   Split selection ranges if rows are about to be inserted in the middle.
     693    \internal
     694
     695    Split selection ranges if rows are about to be inserted in the middle.
    654696*/
    655697void QItemSelectionModelPrivate::_q_rowsAboutToBeInserted(const QModelIndex &parent,
     
    678720
    679721/*!
    680   \internal
    681 
    682   Split selection into individual (persistent) indexes. This is done in
    683   preparation for the layoutChanged() signal, where the indexes can be
    684   merged again.
     722    \internal
     723
     724    Split selection into individual (persistent) indexes. This is done in
     725    preparation for the layoutChanged() signal, where the indexes can be
     726    merged again.
    685727*/
    686728void QItemSelectionModelPrivate::_q_layoutAboutToBeChanged()
     
    689731    savedPersistentCurrentIndexes.clear();
    690732
    691     // special case for when all indexes are selected
     733    // optimisation for when all indexes are selected
     734    // (only if there is lots of items (1000) because this is not entirely correct)
    692735    if (ranges.isEmpty() && currentSelection.count() == 1) {
    693736        QItemSelectionRange range = currentSelection.first();
    694737        QModelIndex parent = range.parent();
    695         if (range.top() == 0
     738        tableRowCount = model->rowCount(parent);
     739        tableColCount = model->columnCount(parent);
     740        if (tableRowCount * tableColCount > 1000
     741            && range.top() == 0
    696742            && range.left() == 0
    697             && range.bottom() == model->rowCount(parent) - 1
    698             && range.right() == model->columnCount(parent) - 1) {
     743            && range.bottom() == tableRowCount - 1
     744            && range.right() == tableColCount - 1) {
    699745            tableSelected = true;
    700746            tableParent = parent;
    701             tableColCount = model->columnCount(parent);
    702             tableRowCount = model->rowCount(parent);
    703747            return;
    704748        }
     
    716760
    717761/*!
    718   \internal
    719 
    720   Merges \a indexes into an item selection made up of ranges.
    721   Assumes that the indexes are sorted.
     762    \internal
     763
     764    Merges \a indexes into an item selection made up of ranges.
     765    Assumes that the indexes are sorted.
    722766*/
    723767static QItemSelection mergeIndexes(const QList<QPersistentModelIndex> &indexes)
     
    764808
    765809/*!
    766   \internal
    767 
    768   Merge the selected indexes into selection ranges again.
     810    \internal
     811
     812    Merge the selected indexes into selection ranges again.
    769813*/
    770814void QItemSelectionModelPrivate::_q_layoutChanged()
     
    808852
    809853/*!
    810   \class QItemSelectionModel
    811 
    812   \brief The QItemSelectionModel class keeps track of a view's selected items.
    813 
    814   \ingroup model-view
    815 
    816   A QItemSelectionModel keeps track of the selected items in a view, or
    817   in several views onto the same model. It also keeps track of the
    818   currently selected item in a view.
    819 
    820   The QItemSelectionModel class is one of the \l{Model/View Classes}
    821   and is part of Qt's \l{Model/View Programming}{model/view framework}.
    822 
    823   The selected items are stored using ranges. Whenever you want to
    824   modify the selected items use select() and provide either a
    825   QItemSelection, or a QModelIndex and a QItemSelectionModel::SelectionFlag.
    826 
    827   The QItemSelectionModel takes a two layer approach to selection
    828   management, dealing with both selected items that have been committed
    829   and items that are part of the current selection. The current
    830   selected items are part of the current interactive selection (for
    831   example with rubber-band selection or keyboard-shift selections).
    832 
    833   To update the currently selected items, use the bitwise OR of
    834   QItemSelectionModel::Current and any of the other SelectionFlags.
    835   If you omit the QItemSelectionModel::Current command, a new current
    836   selection will be created, and the previous one added to the whole
    837   selection. All functions operate on both layers; for example,
    838   selectedItems() will return items from both layers.
    839 
    840   \sa {Model/View Programming}, QAbstractItemModel, {Chart Example}
    841 */
    842 
    843 /*!
    844   Constructs a selection model that operates on the specified item \a model.
     854    \class QItemSelectionModel
     855
     856    \brief The QItemSelectionModel class keeps track of a view's selected items.
     857
     858    \ingroup model-view
     859
     860    A QItemSelectionModel keeps track of the selected items in a view, or
     861    in several views onto the same model. It also keeps track of the
     862    currently selected item in a view.
     863
     864    The QItemSelectionModel class is one of the \l{Model/View Classes}
     865    and is part of Qt's \l{Model/View Programming}{model/view framework}.
     866
     867    The selected items are stored using ranges. Whenever you want to
     868    modify the selected items use select() and provide either a
     869    QItemSelection, or a QModelIndex and a QItemSelectionModel::SelectionFlag.
     870
     871    The QItemSelectionModel takes a two layer approach to selection
     872    management, dealing with both selected items that have been committed
     873    and items that are part of the current selection. The current
     874    selected items are part of the current interactive selection (for
     875    example with rubber-band selection or keyboard-shift selections).
     876
     877    To update the currently selected items, use the bitwise OR of
     878    QItemSelectionModel::Current and any of the other SelectionFlags.
     879    If you omit the QItemSelectionModel::Current command, a new current
     880    selection will be created, and the previous one added to the whole
     881    selection. All functions operate on both layers; for example,
     882    selectedItems() will return items from both layers.
     883
     884    \sa {Model/View Programming}, QAbstractItemModel, {Chart Example}
     885*/
     886
     887/*!
     888    Constructs a selection model that operates on the specified item \a model.
    845889*/
    846890QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model)
     
    865909
    866910/*!
    867   Constructs a selection model that operates on the specified item \a model with \a parent.
     911    Constructs a selection model that operates on the specified item \a model with \a parent.
    868912*/
    869913QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model, QObject *parent)
     
    888932
    889933/*!
    890   \internal
     934    \internal
    891935*/
    892936QItemSelectionModel::QItemSelectionModel(QItemSelectionModelPrivate &dd, QAbstractItemModel *model)
     
    911955
    912956/*!
    913   Destroys the selection model.
     957    Destroys the selection model.
    914958*/
    915959QItemSelectionModel::~QItemSelectionModel()
     
    933977
    934978/*!
    935   Selects the model item \a index using the specified \a command, and emits
    936   selectionChanged().
    937 
    938   \sa QItemSelectionModel::SelectionFlags
     979    Selects the model item \a index using the specified \a command, and emits
     980    selectionChanged().
     981
     982    \sa QItemSelectionModel::SelectionFlags
    939983*/
    940984void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
     
    945989
    946990/*!
    947    \fn void QItemSelectionModel::currentChanged(const QModelIndex &current, const QModelIndex &previous)
    948 
    949    This signal is emitted whenever the current item changes. The \a previous
    950    model item index is replaced by the \a current index as the selection's
    951    current item.
    952 
    953    Note that this signal will not be emitted when the item model is reset.
    954 
    955    \sa currentIndex() setCurrentIndex() selectionChanged()
    956 */
    957 
    958 /*!
    959    \fn void QItemSelectionModel::currentColumnChanged(const QModelIndex &current, const QModelIndex &previous)
    960 
    961    This signal is emitted if the \a current item changes and its column is
    962    different to the column of the \a previous current item.
    963 
    964    Note that this signal will not be emitted when the item model is reset.
    965 
    966    \sa currentChanged() currentRowChanged() currentIndex() setCurrentIndex()
    967 */
    968 
    969 /*!
    970    \fn void QItemSelectionModel::currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
    971 
    972    This signal is emitted if the \a current item changes and its row is
    973    different to the row of the \a previous current item.
    974 
    975    Note that this signal will not be emitted when the item model is reset.
    976 
    977    \sa currentChanged() currentColumnChanged() currentIndex() setCurrentIndex()
     991    \fn void QItemSelectionModel::currentChanged(const QModelIndex &current, const QModelIndex &previous)
     992
     993    This signal is emitted whenever the current item changes. The \a previous
     994    model item index is replaced by the \a current index as the selection's
     995    current item.
     996
     997    Note that this signal will not be emitted when the item model is reset.
     998
     999    \sa currentIndex() setCurrentIndex() selectionChanged()
     1000*/
     1001
     1002/*!
     1003    \fn void QItemSelectionModel::currentColumnChanged(const QModelIndex &current, const QModelIndex &previous)
     1004
     1005    This signal is emitted if the \a current item changes and its column is
     1006    different to the column of the \a previous current item.
     1007
     1008    Note that this signal will not be emitted when the item model is reset.
     1009
     1010    \sa currentChanged() currentRowChanged() currentIndex() setCurrentIndex()
     1011*/
     1012
     1013/*!
     1014    \fn void QItemSelectionModel::currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
     1015
     1016    This signal is emitted if the \a current item changes and its row is
     1017    different to the row of the \a previous current item.
     1018
     1019    Note that this signal will not be emitted when the item model is reset.
     1020
     1021    \sa currentChanged() currentColumnChanged() currentIndex() setCurrentIndex()
    9781022*/
    9791023
     
    9921036
    9931037/*!
    994   \enum QItemSelectionModel::SelectionFlag
    995 
    996   This enum describes the way the selection model will be updated.
    997 
    998   \value NoUpdate       No selection will be made.
    999   \value Clear          The complete selection will be cleared.
    1000   \value Select         All specified indexes will be selected.
    1001   \value Deselect       All specified indexes will be deselected.
    1002   \value Toggle         All specified indexes will be selected or
    1003                         deselected depending on their current state.
    1004   \value Current        The current selection will be updated.
    1005   \value Rows           All indexes will be expanded to span rows.
    1006   \value Columns        All indexes will be expanded to span columns.
    1007   \value SelectCurrent  A combination of Select and Current, provided for
    1008                         convenience.
    1009   \value ToggleCurrent  A combination of Toggle and Current, provided for
    1010                         convenience.
    1011   \value ClearAndSelect A combination of Clear and Select, provided for
    1012                         convenience.
    1013 */
    1014 
    1015 /*!
    1016   Selects the item \a selection using the specified \a command, and emits
    1017   selectionChanged().
    1018 
    1019   \sa QItemSelectionModel::SelectionFlag
     1038    \enum QItemSelectionModel::SelectionFlag
     1039
     1040    This enum describes the way the selection model will be updated.
     1041
     1042    \value NoUpdate       No selection will be made.
     1043    \value Clear          The complete selection will be cleared.
     1044    \value Select         All specified indexes will be selected.
     1045    \value Deselect       All specified indexes will be deselected.
     1046    \value Toggle         All specified indexes will be selected or
     1047                          deselected depending on their current state.
     1048    \value Current        The current selection will be updated.
     1049    \value Rows           All indexes will be expanded to span rows.
     1050    \value Columns        All indexes will be expanded to span columns.
     1051    \value SelectCurrent  A combination of Select and Current, provided for
     1052                          convenience.
     1053    \value ToggleCurrent  A combination of Toggle and Current, provided for
     1054                          convenience.
     1055    \value ClearAndSelect A combination of Clear and Select, provided for
     1056                          convenience.
     1057*/
     1058
     1059/*!
     1060    Selects the item \a selection using the specified \a command, and emits
     1061    selectionChanged().
     1062
     1063    \sa QItemSelectionModel::SelectionFlag
    10201064*/
    10211065void QItemSelectionModel::select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
     
    10571101
    10581102/*!
    1059   Clears the selection model. Emits selectionChanged() and currentChanged().
     1103    Clears the selection model. Emits selectionChanged() and currentChanged().
    10601104*/
    10611105void QItemSelectionModel::clear()
     
    10731117
    10741118/*!
    1075   Clears the selection model. Does not emit any signals.
     1119    Clears the selection model. Does not emit any signals.
    10761120*/
    10771121void QItemSelectionModel::reset()
     
    10831127
    10841128/*!
    1085   \since 4.2
    1086   Clears the selection in the selection model. Emits selectionChanged().
     1129    \since 4.2
     1130    Clears the selection in the selection model. Emits selectionChanged().
    10871131*/
    10881132void QItemSelectionModel::clearSelection()
     
    11001144
    11011145/*!
    1102   Sets the model item \a index to be the current item, and emits
    1103   currentChanged(). The current item is used for keyboard navigation and
    1104   focus indication; it is independent of any selected items, although a
    1105   selected item can also be the current item.
    1106 
    1107   Depending on the specified \a command, the \a index can also become part
    1108   of the current selection.
    1109   \sa select()
     1146    Sets the model item \a index to be the current item, and emits
     1147    currentChanged(). The current item is used for keyboard navigation and
     1148    focus indication; it is independent of any selected items, although a
     1149    selected item can also be the current item.
     1150
     1151    Depending on the specified \a command, the \a index can also become part
     1152    of the current selection.
     1153    \sa select()
    11101154*/
    11111155void QItemSelectionModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
     
    11311175
    11321176/*!
    1133   Returns the model item index for the current item, or an invalid index
    1134   if there is no current item.
     1177    Returns the model item index for the current item, or an invalid index
     1178    if there is no current item.
    11351179*/
    11361180QModelIndex QItemSelectionModel::currentIndex() const
     
    11401184
    11411185/*!
    1142   Returns true if the given model item \a index is selected.
     1186    Returns true if the given model item \a index is selected.
    11431187*/
    11441188bool QItemSelectionModel::isSelected(const QModelIndex &index) const
     
    11771221
    11781222/*!
    1179   Returns true if all items are selected in the \a row with the given
    1180   \a parent.
    1181 
    1182   Note that this function is usually faster than calling isSelected()
    1183   on all items in the same row and that unselectable items are
    1184   ignored.
     1223    Returns true if all items are selected in the \a row with the given
     1224    \a parent.
     1225
     1226    Note that this function is usually faster than calling isSelected()
     1227    on all items in the same row and that unselectable items are
     1228    ignored.
    11851229*/
    11861230bool QItemSelectionModel::isRowSelected(int row, const QModelIndex &parent) const
     
    12371281
    12381282/*!
    1239   Returns true if all items are selected in the \a column with the given
    1240   \a parent.
    1241 
    1242   Note that this function is usually faster than calling isSelected()
    1243   on all items in the same column and that unselectable items are
    1244   ignored.
     1283    Returns true if all items are selected in the \a column with the given
     1284    \a parent.
     1285
     1286    Note that this function is usually faster than calling isSelected()
     1287    on all items in the same column and that unselectable items are
     1288    ignored.
    12451289*/
    12461290bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent) const
     
    12971341
    12981342/*!
    1299   Returns true if there are any items selected in the \a row with the given
    1300   \a parent.
     1343    Returns true if there are any items selected in the \a row with the given
     1344    \a parent.
    13011345*/
    13021346bool QItemSelectionModel::rowIntersectsSelection(int row, const QModelIndex &parent) const
     
    13141358        int right = sel.at(i).right();
    13151359        if (top <= row && bottom >= row) {
    1316             Qt::ItemFlags leftFlags = d->model->index(row, left, parent).flags();
    1317             Qt::ItemFlags rightFlags = d->model->index(row, right, parent).flags();
    1318             if ((leftFlags & Qt::ItemIsSelectable) && (leftFlags & Qt::ItemIsEnabled)
    1319                 && (rightFlags & Qt::ItemIsSelectable) && (rightFlags & Qt::ItemIsEnabled))
    1320                 return true;
     1360            for (int j = left; j <= right; j++) {
     1361                const Qt::ItemFlags flags = d->model->index(row, j, parent).flags();
     1362                if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled))
     1363                    return true;
     1364            }
    13211365        }
    13221366    }
     
    13261370
    13271371/*!
    1328   Returns true if there are any items selected in the \a column with the given
    1329   \a parent.
     1372    Returns true if there are any items selected in the \a column with the given
     1373    \a parent.
    13301374*/
    13311375bool QItemSelectionModel::columnIntersectsSelection(int column, const QModelIndex &parent) const
     
    13431387        int bottom =  sel.at(i).bottom();
    13441388        if (left <= column && right >= column) {
    1345             Qt::ItemFlags topFlags = d->model->index(top, column, parent).flags();
    1346             Qt::ItemFlags bottomFlags = d->model->index(bottom, column, parent).flags();
    1347             if ((topFlags & Qt::ItemIsSelectable) && (topFlags & Qt::ItemIsEnabled)
    1348                 && (bottomFlags & Qt::ItemIsSelectable) && (bottomFlags & Qt::ItemIsEnabled))
    1349                 return true;
     1389            for (int j = top; j <= bottom; j++) {
     1390                const Qt::ItemFlags flags = d->model->index(j, column, parent).flags();
     1391                if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled))
     1392                    return true;
     1393            }
    13501394        }
    13511395    }
     
    13671411        sel.merge(d->currentSelection, d->currentCommand);
    13681412        return !sel.isEmpty();
    1369     }
    1370     else {
     1413    } else {
    13711414        return !(d->ranges.isEmpty() && d->currentSelection.isEmpty());
    13721415    }
     
    13741417
    13751418/*!
    1376   Returns a list of all selected model item indexes. The list contains no
    1377   duplicates, and is not sorted.
     1419    Returns a list of all selected model item indexes. The list contains no
     1420    duplicates, and is not sorted.
    13781421*/
    13791422QModelIndexList QItemSelectionModel::selectedIndexes() const
     
    13861429
    13871430/*!
    1388   \since 4.2
    1389   Returns the indexes in the given \a column for the rows where all columns are selected.
    1390 
    1391   \sa selectedIndexes(), selectedColumns()
     1431    \since 4.2
     1432    Returns the indexes in the given \a column for the rows where all columns are selected.
     1433
     1434    \sa selectedIndexes(), selectedColumns()
    13921435*/
    13931436
     
    14501493
    14511494/*!
    1452   Returns the selection ranges stored in the selection model.
     1495    Returns the selection ranges stored in the selection model.
    14531496*/
    14541497const QItemSelection QItemSelectionModel::selection() const
     
    14701513
    14711514/*!
    1472   Returns the item model operated on by the selection model.
     1515    Returns the item model operated on by the selection model.
    14731516*/
    14741517const QAbstractItemModel *QItemSelectionModel::model() const
     
    14781521
    14791522/*!
    1480   Compares the two selections \a newSelection and \a oldSelection
    1481   and emits selectionChanged() with the deselected and selected items.
     1523    Compares the two selections \a newSelection and \a oldSelection
     1524    and emits selectionChanged() with the deselected and selected items.
    14821525*/
    14831526void QItemSelectionModel::emitSelectionChanged(const QItemSelection &newSelection,
     
    15461589    }
    15471590
    1548     emit selectionChanged(selected, deselected);
     1591    if (!selected.isEmpty() || !deselected.isEmpty())
     1592        emit selectionChanged(selected, deselected);
    15491593}
    15501594
     
    15541598#ifndef Q_BROKEN_DEBUG_STREAM
    15551599    dbg.nospace() << "QItemSelectionRange(" << range.topLeft()
    1556                   << "," << range.bottomRight() << ")";
     1600                  << ',' << range.bottomRight() << ')';
    15571601    return dbg.space();
    15581602#else
Note: See TracChangeset for help on using the changeset viewer.