Changeset 846 for trunk/src/corelib/kernel/qabstractitemmodel.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/corelib/kernel/qabstractitemmodel.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 1198 1198 1199 1199 \sa {Model Classes}, {Model Subclassing Reference}, QModelIndex, 1200 QAbstractItemView, {Using Drag and Drop with Item Views},1200 QAbstractItemView, {Using iews}, 1201 1201 {Simple DOM Model Example}, {Simple Tree Model Example}, 1202 1202 {Editable Tree Model Example}, {Fetch More Example} … … 1249 1249 \fn QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const = 0 1250 1250 1251 Returns the parent of the model item with the given \a index. If the model1251 Returns the parent of the model item with the given \a index. If the 1252 1252 has no parent, an invalid QModelIndex is returned. 1253 1253 … … 1337 1337 1338 1338 \list 1339 \o Call beginLayoutChanged()1339 \o 1340 1340 \o Remember the QModelIndex that will change 1341 1341 \o Update your internal data 1342 1342 \o Call changePersistentIndex() 1343 \o Call endLayoutChanged()1343 \o 1344 1344 \endlist 1345 1346 1345 1347 1346 \sa layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), modelReset(), … … 1762 1761 a parent. Models will usually append the data to the parent in this case. 1763 1762 1764 \sa supportedDropActions(), {Using Drag and Drop with Item Views}1763 \sa supportedDropActions(), {Using iews} 1765 1764 */ 1766 1765 bool QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, … … 1799 1798 operations. 1800 1799 1801 \sa dropMimeData(), Qt::DropActions, {Using Drag and Drop with Item1802 Views}1800 \sa dropMimeData(), Qt::DropActions, {Using tem 1801 iews} 1803 1802 */ 1804 1803 Qt::DropActions QAbstractItemModel::supportedDropActions() const … … 1816 1815 default values when a drag occurs. 1817 1816 1818 \sa Qt::DropActions, {Using Drag and Drop with Item Views}1817 \sa Qt::DropActions, {Using iews} 1819 1818 */ 1820 1819 Qt::DropActions QAbstractItemModel::supportedDragActions() const … … 1832 1831 Sets the supported drag \a actions for the items in the model. 1833 1832 1834 \sa supportedDragActions(), {Using Drag and Drop with Item Views}1833 \sa supportedDragActions(), {Using iews} 1835 1834 */ 1836 1835 void QAbstractItemModel::setSupportedDragActions(Qt::DropActions actions) … … 2502 2501 2503 2502 /*! 2503 2504 2504 2505 Begins a row move operation. 2505 2506 … … 2507 2508 entities in your model. This method is responsible for moving 2508 2509 persistent indexes in the model, which you would otherwise be 2509 required to do yourself. 2510 2511 Using beginMoveRows and endMoveRows is an alternative to emitting 2512 layoutAboutToBeChanged and layoutChanged directly along with 2513 changePersistentIndexes. layoutAboutToBeChanged is emitted by 2514 this method for compatibility reasons. 2510 required to do yourself. Using beginMoveRows and endMoveRows 2511 is an alternative to emitting layoutAboutToBeChanged and 2512 layoutChanged directly along with changePersistentIndexes. 2513 layoutAboutToBeChanged is emitted by this method for compatibility 2514 reasons. 2515 2515 2516 2516 The \a sourceParent index corresponds to the parent from which the 2517 rows are moved; \a sourceFirst and \a sourceLast are the row2518 numbers of the rows to be moved. The \a destinationParent index2519 corresponds to the parent into which th e rows are moved. The \a2517 rows are moved; \a sourceFirst and \a sourceLast are the 2518 numbers of the rows to be moved. The \a destinationParent index 2519 corresponds to the parent into which the rows are moved. The \a 2520 2520 destinationChild is the row to which the rows will be moved. That 2521 2521 is, the index at row \a sourceFirst in \a sourceParent will become 2522 row \a destinationChild in \a destinationParent. Its siblings will 2523 be moved correspondingly. 2524 2525 Note that \a sourceParent and \a destinationParent may be the 2526 same, in which case you must ensure that the \a destinationChild is 2527 not within the range of \a sourceFirst and \a sourceLast. You 2528 must also ensure that you do not attempt to move a row to one of 2529 its own chilren or ancestors. This method returns false if either 2530 condition is true, in which case you should abort your move 2531 operation. 2522 row \a destinationChild in \a destinationParent, followed by all other 2523 rows up to \a sourceLast. 2524 2525 However, when moving rows down in the same parent (\a sourceParent 2526 and \a destinationParent are equal), the rows will be placed before the 2527 \a destinationChild index. That is, if you wish to move rows 0 and 1 so 2528 they will become rows 1 and 2, \a destinationChild should be 3. In this 2529 case, the new index for the source row \c i (which is between 2530 \a sourceFirst and \a sourceLast) is equal to 2531 \c {(destinationChild-sourceLast-1+i)}. 2532 2533 Note that if \a sourceParent and \a destinationParent are the same, 2534 you must ensure that the \a destinationChild is not within the range 2535 of \a sourceFirst and \a sourceLast + 1. You must also ensure that you 2536 do not attempt to move a row to one of its own children or ancestors. 2537 This method returns false if either condition is true, in which case you 2538 should abort your move operation. 2539 2540 \table 80% 2541 \row 2542 \o \inlineimage modelview-move-rows-1.png Moving rows to another parent 2543 \o Specify the first and last row numbers for the span of rows in 2544 the source parent you want to move in the model. Also specify 2545 the row in the destination parent to move the span to. 2546 2547 For example, as shown in the diagram, we move three rows from 2548 row 2 to 4 in the source, so \a sourceFirst is 2 and \a sourceLast is 4. 2549 We move those items to above row 2 in the destination, so \a destinationChild is 2. 2550 2551 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 6 2552 2553 This moves the three rows rows 2, 3, and 4 in the source to become 2, 3 and 4 in 2554 the destination. Other affected siblings are displaced accordingly. 2555 \row 2556 \o \inlineimage modelview-move-rows-2.png Moving rows to append to another parent 2557 \o To append rows to another parent, move them to after the last row. 2558 2559 For example, as shown in the diagram, we move three rows to a 2560 collection of 6 existing rows (ending in row 5), so \a destinationChild is 6: 2561 2562 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 7 2563 2564 This moves the target rows to the end of the target parent as 6, 7 and 8. 2565 \row 2566 \o \inlineimage modelview-move-rows-3.png Moving rows in the same parent up 2567 \o To move rows within the same parent, specify the row to move them to. 2568 2569 For example, as shown in the diagram, we move one item from row 2 to row 0, 2570 so \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 0. 2571 2572 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 8 2573 2574 Note that other rows may be displaced accordingly. Note also that when moving 2575 items within the same parent you should not attempt invalid or no-op moves. In 2576 the above example, item 2 is at row 2 before the move, so it can not be moved 2577 to row 2 (where it is already) or row 3 (no-op as row 3 means above row 3, where 2578 it is already) 2579 2580 \row 2581 \o \inlineimage modelview-move-rows-4.png Moving rows in the same parent down 2582 \o To move rows within the same parent, specify the row to move them to. 2583 2584 For example, as shown in the diagram, we move one item from row 2 to row 4, 2585 so \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 4. 2586 2587 \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 9 2588 2589 Note that other rows may be displaced accordingly. 2590 \endtable 2532 2591 2533 2592 \sa endMoveRows() 2534 2535 \since 4.62536 2593 */ 2537 2594 bool QAbstractItemModel::beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild) … … 2546 2603 } 2547 2604 2548 d->changes.push(QAbstractItemModelPrivate::Change(sourceParent, sourceFirst, sourceLast)); 2605 QAbstractItemModelPrivate::Change sourceChange(sourceParent, sourceFirst, sourceLast); 2606 sourceChange.needsAdjust = sourceParent.isValid() && sourceParent.row() >= destinationChild && sourceParent.parent() == destinationParent; 2607 d->changes.push(sourceChange); 2549 2608 int destinationLast = destinationChild + (sourceLast - sourceFirst); 2550 d->changes.push(QAbstractItemModelPrivate::Change(destinationParent, destinationChild, destinationLast)); 2609 QAbstractItemModelPrivate::Change destinationChange(destinationParent, destinationChild, destinationLast); 2610 destinationChange.needsAdjust = destinationParent.isValid() && destinationParent.row() >= sourceLast && destinationParent.parent() == sourceParent; 2611 d->changes.push(destinationChange); 2551 2612 2552 2613 emit rowsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild); … … 2576 2637 QAbstractItemModelPrivate::Change removeChange = d->changes.pop(); 2577 2638 2578 d->itemsMoved(removeChange.parent, removeChange.first, removeChange.last, insertChange.parent, insertChange.first, Qt::Vertical); 2579 2580 emit rowsMoved(removeChange.parent, removeChange.first, removeChange.last, insertChange.parent, insertChange.first); 2639 QModelIndex adjustedSource = removeChange.parent; 2640 QModelIndex adjustedDestination = insertChange.parent; 2641 2642 const int numMoved = removeChange.last - removeChange.first + 1; 2643 if (insertChange.needsAdjust) 2644 adjustedDestination = createIndex(adjustedDestination.row() - numMoved, adjustedDestination.column(), adjustedDestination.internalPointer()); 2645 2646 if (removeChange.needsAdjust) 2647 adjustedSource = createIndex(adjustedSource.row() + numMoved, adjustedSource.column(), adjustedSource.internalPointer()); 2648 2649 d->itemsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, Qt::Vertical); 2650 2651 emit rowsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first); 2581 2652 emit layoutChanged(); 2582 2653 } … … 2710 2781 entities in your model. This method is responsible for moving 2711 2782 persistent indexes in the model, which you would otherwise be 2712 required to do yourself. 2713 2714 Using beginMoveColumns and endMoveColumns is an alternative to 2715 emitting layoutAboutToBeChanged and layoutChanged directly along 2716 with changePersistentIndexes. layoutAboutToBeChanged is emitted 2717 by this method for compatibility reasons. 2783 required to do yourself. Using beginMoveRows and endMoveRows 2784 is an alternative to emitting layoutAboutToBeChanged and 2785 layoutChanged directly along with changePersistentIndexes. 2786 layoutAboutToBeChanged is emitted by this method for compatibility 2787 reasons. 2718 2788 2719 2789 The \a sourceParent index corresponds to the parent from which the 2720 columns are moved; \a sourceFirst and \a sourceLast are the column 2721 numbers of the columns to be moved. The \a destinationParent index 2722 corresponds to the parent into which the columns are moved. The \a 2723 destinationChild is the column to which the columns will be 2724 moved. That is, the index at column \a sourceFirst in \a 2725 sourceParent will become column \a destinationChild in \a 2726 destinationParent. Its siblings will be moved correspondingly. 2727 2728 Note that \a sourceParent and \a destinationParent may be the 2729 same, in which case you must ensure that the \a destinationChild 2730 is not within the range of \a sourceFirst and \a sourceLast. You 2731 must also ensure that you do not attempt to move a row to one of 2732 its own chilren or ancestors. This method returns false if either 2733 condition is true, in which case you should abort your move 2734 operation. 2790 columns are moved; \a sourceFirst and \a sourceLast are the first and last 2791 column numbers of the columns to be moved. The \a destinationParent index 2792 corresponds to the parent into which those columns are moved. The \a 2793 destinationChild is the column to which the columns will be moved. That 2794 is, the index at column \a sourceFirst in \a sourceParent will become 2795 column \a destinationChild in \a destinationParent, followed by all other 2796 columns up to \a sourceLast. 2797 2798 However, when moving columns down in the same parent (\a sourceParent 2799 and \a destinationParent are equal), the columnss will be placed before the 2800 \a destinationChild index. That is, if you wish to move columns 0 and 1 so 2801 they will become columns 1 and 2, \a destinationChild should be 3. In this 2802 case, the new index for the source column \c i (which is between 2803 \a sourceFirst and \a sourceLast) is equal to 2804 \c {(destinationChild-sourceLast-1+i)}. 2805 2806 Note that if \a sourceParent and \a destinationParent are the same, 2807 you must ensure that the \a destinationChild is not within the range 2808 of \a sourceFirst and \a sourceLast + 1. You must also ensure that you 2809 do not attempt to move a column to one of its own children or ancestors. 2810 This method returns false if either condition is true, in which case you 2811 should abort your move operation. 2735 2812 2736 2813 \sa endMoveColumns() … … 2749 2826 } 2750 2827 2751 d->changes.push(QAbstractItemModelPrivate::Change(sourceParent, sourceFirst, sourceLast)); 2828 QAbstractItemModelPrivate::Change sourceChange(sourceParent, sourceFirst, sourceLast); 2829 sourceChange.needsAdjust = sourceParent.isValid() && sourceParent.row() >= destinationChild && sourceParent.parent() == destinationParent; 2830 d->changes.push(sourceChange); 2752 2831 int destinationLast = destinationChild + (sourceLast - sourceFirst); 2753 d->changes.push(QAbstractItemModelPrivate::Change(destinationParent, destinationChild, destinationLast)); 2832 QAbstractItemModelPrivate::Change destinationChange(destinationParent, destinationChild, destinationLast); 2833 destinationChange.needsAdjust = destinationParent.isValid() && destinationParent.row() >= sourceLast && destinationParent.parent() == sourceParent; 2834 d->changes.push(destinationChange); 2754 2835 2755 2836 d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal); … … 2780 2861 QAbstractItemModelPrivate::Change removeChange = d->changes.pop(); 2781 2862 2782 d->itemsMoved(removeChange.parent, removeChange.first, removeChange.last, insertChange.parent, insertChange.first, Qt::Horizontal); 2783 2784 emit columnsMoved(removeChange.parent, removeChange.first, removeChange.last, insertChange.parent, insertChange.first); 2863 QModelIndex adjustedSource = removeChange.parent; 2864 QModelIndex adjustedDestination = insertChange.parent; 2865 2866 const int numMoved = removeChange.last - removeChange.first + 1; 2867 if (insertChange.needsAdjust) 2868 adjustedDestination = createIndex(adjustedDestination.row(), adjustedDestination.column() - numMoved, adjustedDestination.internalPointer()); 2869 2870 if (removeChange.needsAdjust) 2871 adjustedSource = createIndex(adjustedSource.row(), adjustedSource.column() + numMoved, adjustedSource.internalPointer()); 2872 2873 d->itemsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, Qt::Horizontal); 2874 2875 emit columnsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first); 2785 2876 emit layoutChanged(); 2786 2877 } … … 2791 2882 \note Use beginResetModel() and endResetModel() instead whenever possible. 2792 2883 Use this method only if there is no way to call beginResetModel() before invalidating the model. 2793 Otherwise it could lead to unex cpected behaviour, especially when used with proxy models.2884 Otherwise it could lead to unexpected behaviour, especially when used with proxy models. 2794 2885 */ 2795 2886 void QAbstractItemModel::reset()
Note:
See TracChangeset
for help on using the changeset viewer.