Changeset 561 for trunk/src/gui/itemviews/qitemselectionmodel.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/itemviews/qitemselectionmodel.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 271 271 */ 272 272 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 280 static 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); 286 287 if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) 287 288 result.append(index); … … 289 290 } 290 291 } 292 } 293 294 /*! 295 Returns the list of model index items stored in the selection. 296 */ 297 298 QModelIndexList QItemSelectionRange::indexes() const 299 { 300 QModelIndexList result; 301 indexesFromRange(*this, result); 291 302 return result; 292 303 } 293 304 294 305 /*! 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 334 344 */ 335 345 … … 405 415 QList<QItemSelectionRange>::const_iterator it = begin(); 406 416 for (; it != end(); ++it) 407 result += (*it).indexes();417 indexesFromRange(*it, result); 408 418 return result; 409 419 } 410 420 411 421 /*! 412 Merges the \a other selection with this QItemSelection using the413 \a command given. This method guarantees that no ranges are overlapping.414 415 Note that only QItemSelectionModel::Select,416 QItemSelectionModel::Deselect, and QItemSelectionModel::Toggle are417 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() 420 430 */ 421 431 void QItemSelection::merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command) … … 469 479 470 480 /*! 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() 475 485 */ 476 486 … … 519 529 520 530 /*! 521 \internal522 523 returns a QItemSelection where all ranges have been expanded to:524 Rows: left: 0 and right: columnCount()-1525 Columns: top: 0 and bottom: rowCount()-1531 \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 526 536 */ 527 537 … … 558 568 559 569 /*! 560 \internal570 \internal 561 571 */ 562 572 void QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &parent, … … 564 574 { 565 575 Q_Q(QItemSelectionModel); 576 finalize(); 566 577 567 578 // update current index … … 581 592 } 582 593 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 592 634 */ 593 635 void QItemSelectionModelPrivate::_q_columnsAboutToBeRemoved(const QModelIndex &parent, … … 620 662 621 663 /*! 622 \internal623 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. 625 667 */ 626 668 void QItemSelectionModelPrivate::_q_columnsAboutToBeInserted(const QModelIndex &parent, … … 649 691 650 692 /*! 651 \internal652 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. 654 696 */ 655 697 void QItemSelectionModelPrivate::_q_rowsAboutToBeInserted(const QModelIndex &parent, … … 678 720 679 721 /*! 680 \internal681 682 Split selection into individual (persistent) indexes. This is done in683 preparation for the layoutChanged() signal, where the indexes can be684 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. 685 727 */ 686 728 void QItemSelectionModelPrivate::_q_layoutAboutToBeChanged() … … 689 731 savedPersistentCurrentIndexes.clear(); 690 732 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) 692 735 if (ranges.isEmpty() && currentSelection.count() == 1) { 693 736 QItemSelectionRange range = currentSelection.first(); 694 737 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 696 742 && range.left() == 0 697 && range.bottom() == model->rowCount(parent)- 1698 && range.right() == model->columnCount(parent)- 1) {743 && range.bottom() == tableRowCount - 1 744 && range.right() == tableColCount - 1) { 699 745 tableSelected = true; 700 746 tableParent = parent; 701 tableColCount = model->columnCount(parent);702 tableRowCount = model->rowCount(parent);703 747 return; 704 748 } … … 716 760 717 761 /*! 718 \internal719 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. 722 766 */ 723 767 static QItemSelection mergeIndexes(const QList<QPersistentModelIndex> &indexes) … … 764 808 765 809 /*! 766 \internal767 768 Merge the selected indexes into selection ranges again.810 \internal 811 812 Merge the selected indexes into selection ranges again. 769 813 */ 770 814 void QItemSelectionModelPrivate::_q_layoutChanged() … … 808 852 809 853 /*! 810 \class QItemSelectionModel811 812 \brief The QItemSelectionModel class keeps track of a view's selected items.813 814 \ingroup model-view815 816 A QItemSelectionModel keeps track of the selected items in a view, or817 in several views onto the same model. It also keeps track of the818 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 to824 modify the selected items use select() and provide either a825 QItemSelection, or a QModelIndex and a QItemSelectionModel::SelectionFlag.826 827 The QItemSelectionModel takes a two layer approach to selection828 management, dealing with both selected items that have been committed829 and items that are part of the current selection. The current830 selected items are part of the current interactive selection (for831 example with rubber-band selection or keyboard-shift selections).832 833 To update the currently selected items, use the bitwise OR of834 QItemSelectionModel::Current and any of the other SelectionFlags.835 If you omit the QItemSelectionModel::Current command, a new current836 selection will be created, and the previous one added to the whole837 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. 845 889 */ 846 890 QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model) … … 865 909 866 910 /*! 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. 868 912 */ 869 913 QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model, QObject *parent) … … 888 932 889 933 /*! 890 \internal934 \internal 891 935 */ 892 936 QItemSelectionModel::QItemSelectionModel(QItemSelectionModelPrivate &dd, QAbstractItemModel *model) … … 911 955 912 956 /*! 913 Destroys the selection model.957 Destroys the selection model. 914 958 */ 915 959 QItemSelectionModel::~QItemSelectionModel() … … 933 977 934 978 /*! 935 Selects the model item \a index using the specified \a command, and emits936 selectionChanged().937 938 \sa QItemSelectionModel::SelectionFlags979 Selects the model item \a index using the specified \a command, and emits 980 selectionChanged(). 981 982 \sa QItemSelectionModel::SelectionFlags 939 983 */ 940 984 void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) … … 945 989 946 990 /*! 947 \fn void QItemSelectionModel::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)948 949 This signal is emitted whenever the current item changes. The \a previous950 model item index is replaced by the \a current index as the selection's951 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 ¤t, const QModelIndex &previous)960 961 This signal is emitted if the \a current item changes and its column is962 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 ¤t, const QModelIndex &previous)971 972 This signal is emitted if the \a current item changes and its row is973 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 ¤t, 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 ¤t, 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 ¤t, 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() 978 1022 */ 979 1023 … … 992 1036 993 1037 /*! 994 \enum QItemSelectionModel::SelectionFlag995 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 or1003 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 for1008 convenience.1009 \value ToggleCurrent A combination of Toggle and Current, provided for1010 convenience.1011 \value ClearAndSelect A combination of Clear and Select, provided for1012 convenience.1013 */ 1014 1015 /*! 1016 Selects the item \a selection using the specified \a command, and emits1017 selectionChanged().1018 1019 \sa QItemSelectionModel::SelectionFlag1038 \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 1020 1064 */ 1021 1065 void QItemSelectionModel::select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) … … 1057 1101 1058 1102 /*! 1059 Clears the selection model. Emits selectionChanged() and currentChanged().1103 Clears the selection model. Emits selectionChanged() and currentChanged(). 1060 1104 */ 1061 1105 void QItemSelectionModel::clear() … … 1073 1117 1074 1118 /*! 1075 Clears the selection model. Does not emit any signals.1119 Clears the selection model. Does not emit any signals. 1076 1120 */ 1077 1121 void QItemSelectionModel::reset() … … 1083 1127 1084 1128 /*! 1085 \since 4.21086 Clears the selection in the selection model. Emits selectionChanged().1129 \since 4.2 1130 Clears the selection in the selection model. Emits selectionChanged(). 1087 1131 */ 1088 1132 void QItemSelectionModel::clearSelection() … … 1100 1144 1101 1145 /*! 1102 Sets the model item \a index to be the current item, and emits1103 currentChanged(). The current item is used for keyboard navigation and1104 focus indication; it is independent of any selected items, although a1105 selected item can also be the current item.1106 1107 Depending on the specified \a command, the \a index can also become part1108 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() 1110 1154 */ 1111 1155 void QItemSelectionModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) … … 1131 1175 1132 1176 /*! 1133 Returns the model item index for the current item, or an invalid index1134 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. 1135 1179 */ 1136 1180 QModelIndex QItemSelectionModel::currentIndex() const … … 1140 1184 1141 1185 /*! 1142 Returns true if the given model item \a index is selected.1186 Returns true if the given model item \a index is selected. 1143 1187 */ 1144 1188 bool QItemSelectionModel::isSelected(const QModelIndex &index) const … … 1177 1221 1178 1222 /*! 1179 Returns true if all items are selected in the \a row with the given1180 \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 are1184 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. 1185 1229 */ 1186 1230 bool QItemSelectionModel::isRowSelected(int row, const QModelIndex &parent) const … … 1237 1281 1238 1282 /*! 1239 Returns true if all items are selected in the \a column with the given1240 \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 are1244 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. 1245 1289 */ 1246 1290 bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent) const … … 1297 1341 1298 1342 /*! 1299 Returns true if there are anyitems selected in the \a row with the given1300 \a parent.1343 Returns true if there are any items selected in the \a row with the given 1344 \a parent. 1301 1345 */ 1302 1346 bool QItemSelectionModel::rowIntersectsSelection(int row, const QModelIndex &parent) const … … 1314 1358 int right = sel.at(i).right(); 1315 1359 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 } 1321 1365 } 1322 1366 } … … 1326 1370 1327 1371 /*! 1328 Returns true if there are anyitems selected in the \a column with the given1329 \a parent.1372 Returns true if there are any items selected in the \a column with the given 1373 \a parent. 1330 1374 */ 1331 1375 bool QItemSelectionModel::columnIntersectsSelection(int column, const QModelIndex &parent) const … … 1343 1387 int bottom = sel.at(i).bottom(); 1344 1388 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 } 1350 1394 } 1351 1395 } … … 1367 1411 sel.merge(d->currentSelection, d->currentCommand); 1368 1412 return !sel.isEmpty(); 1369 } 1370 else { 1413 } else { 1371 1414 return !(d->ranges.isEmpty() && d->currentSelection.isEmpty()); 1372 1415 } … … 1374 1417 1375 1418 /*! 1376 Returns a list of all selected model item indexes. The list contains no1377 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. 1378 1421 */ 1379 1422 QModelIndexList QItemSelectionModel::selectedIndexes() const … … 1386 1429 1387 1430 /*! 1388 \since 4.21389 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() 1392 1435 */ 1393 1436 … … 1450 1493 1451 1494 /*! 1452 Returns the selection ranges stored in the selection model.1495 Returns the selection ranges stored in the selection model. 1453 1496 */ 1454 1497 const QItemSelection QItemSelectionModel::selection() const … … 1470 1513 1471 1514 /*! 1472 Returns the item model operated on by the selection model.1515 Returns the item model operated on by the selection model. 1473 1516 */ 1474 1517 const QAbstractItemModel *QItemSelectionModel::model() const … … 1478 1521 1479 1522 /*! 1480 Compares the two selections \a newSelection and \a oldSelection1481 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. 1482 1525 */ 1483 1526 void QItemSelectionModel::emitSelectionChanged(const QItemSelection &newSelection, … … 1546 1589 } 1547 1590 1548 emit selectionChanged(selected, deselected); 1591 if (!selected.isEmpty() || !deselected.isEmpty()) 1592 emit selectionChanged(selected, deselected); 1549 1593 } 1550 1594 … … 1554 1598 #ifndef Q_BROKEN_DEBUG_STREAM 1555 1599 dbg.nospace() << "QItemSelectionRange(" << range.topLeft() 1556 << "," << range.bottomRight() << ")";1600 << ',' << range.bottomRight() << ')'; 1557 1601 return dbg.space(); 1558 1602 #else
Note:
See TracChangeset
for help on using the changeset viewer.