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/corelib/kernel/qabstractitemmodel.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    11981198
    11991199    \sa {Model Classes}, {Model Subclassing Reference}, QModelIndex,
    1200         QAbstractItemView, {Using Drag and Drop with Item Views},
     1200        QAbstractItemView, {Using iews},
    12011201        {Simple DOM Model Example}, {Simple Tree Model Example},
    12021202        {Editable Tree Model Example}, {Fetch More Example}
     
    12491249    \fn QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const = 0
    12501250
    1251     Returns the parent of the model item with the given \a index. If the model
     1251    Returns the parent of the model item with the given \a index. If the
    12521252    has no parent, an invalid QModelIndex is returned.
    12531253
     
    13371337
    13381338    \list
    1339         \o  Call beginLayoutChanged()
     1339        \o 
    13401340        \o  Remember the QModelIndex that will change
    13411341        \o  Update your internal data
    13421342        \o  Call changePersistentIndex()
    1343         \o  Call endLayoutChanged()
     1343        \o 
    13441344    \endlist
    1345 
    13461345
    13471346    \sa layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), modelReset(),
     
    17621761    a parent. Models will usually append the data to the parent in this case.
    17631762
    1764     \sa supportedDropActions(), {Using Drag and Drop with Item Views}
     1763    \sa supportedDropActions(), {Using iews}
    17651764*/
    17661765bool QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
     
    17991798    operations.
    18001799
    1801     \sa dropMimeData(), Qt::DropActions, {Using Drag and Drop with Item
    1802     Views}
     1800    \sa dropMimeData(), Qt::DropActions, {Using tem
     1801    iews}
    18031802*/
    18041803Qt::DropActions QAbstractItemModel::supportedDropActions() const
     
    18161815    default values when a drag occurs.
    18171816
    1818     \sa Qt::DropActions, {Using Drag and Drop with Item Views}
     1817    \sa Qt::DropActions, {Using iews}
    18191818*/
    18201819Qt::DropActions QAbstractItemModel::supportedDragActions() const
     
    18321831    Sets the supported drag \a actions for the items in the model.
    18331832
    1834     \sa supportedDragActions(), {Using Drag and Drop with Item Views}
     1833    \sa supportedDragActions(), {Using iews}
    18351834*/
    18361835void QAbstractItemModel::setSupportedDragActions(Qt::DropActions actions)
     
    25022501
    25032502/*!
     2503
     2504
    25042505    Begins a row move operation.
    25052506
     
    25072508    entities in your model. This method is responsible for moving
    25082509    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.
    25152515
    25162516    The \a sourceParent index corresponds to the parent from which the
    2517     rows are moved; \a sourceFirst and \a sourceLast are the row
    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
     2517    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
    25202520    destinationChild is the row to which the rows will be moved.  That
    25212521    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
    25322591
    25332592    \sa endMoveRows()
    2534 
    2535     \since 4.6
    25362593*/
    25372594bool QAbstractItemModel::beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild)
     
    25462603    }
    25472604
    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);
    25492608    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);
    25512612
    25522613    emit rowsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild);
     
    25762637    QAbstractItemModelPrivate::Change removeChange = d->changes.pop();
    25772638
    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);
    25812652    emit layoutChanged();
    25822653}
     
    27102781    entities in your model. This method is responsible for moving
    27112782    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.
    27182788
    27192789    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.
    27352812
    27362813    \sa endMoveColumns()
     
    27492826    }
    27502827
    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);
    27522831    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);
    27542835
    27552836    d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal);
     
    27802861    QAbstractItemModelPrivate::Change removeChange = d->changes.pop();
    27812862
    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);
    27852876    emit layoutChanged();
    27862877}
     
    27912882    \note Use beginResetModel() and endResetModel() instead whenever possible.
    27922883    Use this method only if there is no way to call beginResetModel() before invalidating the model.
    2793     Otherwise it could lead to unexcpected behaviour, especially when used with proxy models.
     2884    Otherwise it could lead to unexpected behaviour, especially when used with proxy models.
    27942885*/
    27952886void QAbstractItemModel::reset()
Note: See TracChangeset for help on using the changeset viewer.