~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/corelib/kernel/qabstractitemmodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
2
**
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
5
6
**
6
7
** This file is part of the QtCore module of the Qt Toolkit.
7
8
**
8
9
** $QT_BEGIN_LICENSE:LGPL$
9
 
** Commercial Usage
10
 
** Licensees holding valid Qt Commercial licenses may use this file in
11
 
** accordance with the Qt Commercial License Agreement provided with the
12
 
** Software or, alternatively, in accordance with the terms contained in
13
 
** a written agreement between you and Nokia.
 
10
** No Commercial Usage
 
11
** This file contains pre-release code and may not be distributed.
 
12
** You may use this file in accordance with the terms and conditions
 
13
** contained in the Technology Preview License Agreement accompanying
 
14
** this package.
14
15
**
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
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.
27
 
**
28
 
** GNU General Public License Usage
29
 
** Alternatively, this file may be used under the terms of the GNU
30
 
** General Public License version 3.0 as published by the Free Software
31
 
** Foundation and appearing in the file LICENSE.GPL included in the
32
 
** packaging of this file.  Please review the following information to
33
 
** ensure the GNU General Public License version 3.0 requirements will be
34
 
** met: http://www.gnu.org/copyleft/gpl.html.
35
 
**
36
 
** If you are unsure which license is appropriate for your use, please
37
 
** contact the sales department at http://www.qtsoftware.com/contact.
 
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
**
 
28
** If you have questions regarding the use of this file, please contact
 
29
** Nokia at qt-info@nokia.com.
 
30
**
 
31
**
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
38
38
** $QT_END_LICENSE$
39
39
**
40
40
****************************************************************************/
251
251
 
252
252
    Returns true if this persistent model index refers to the same location as
253
253
    the \a other model index; otherwise returns false.
254
 
    Note that all values in the persistent model index are used when comparing
255
 
    with another model index.
 
254
 
 
255
    All values in the persistent model index are used when comparing with
 
256
    another model index.
256
257
*/
257
258
 
258
259
bool QPersistentModelIndex::operator==(const QModelIndex &other) const
335
336
}
336
337
 
337
338
/*!
338
 
  Returns the parent QModelIndex for this persistent index, or
339
 
  QModelIndex() if it has no parent.
 
339
    Returns the parent QModelIndex for this persistent index, or an invalid
 
340
    QModelIndex if it has no parent.
340
341
 
341
 
  \sa child() sibling() model()
 
342
    \sa child() sibling() model()
342
343
*/
343
344
QModelIndex QPersistentModelIndex::parent() const
344
345
{
348
349
}
349
350
 
350
351
/*!
351
 
  Returns the sibling at \a row and \a column or an invalid
352
 
  QModelIndex if there is no sibling at this position.
 
352
    Returns the sibling at \a row and \a column or an invalid QModelIndex if
 
353
    there is no sibling at this position.
353
354
 
354
 
  \sa parent() child()
 
355
    \sa parent() child()
355
356
*/
356
357
 
357
358
QModelIndex QPersistentModelIndex::sibling(int row, int column) const
362
363
}
363
364
 
364
365
/*!
365
 
  Returns the child of the model index that is stored in the given
366
 
  \a row and \a column.
 
366
    Returns the child of the model index that is stored in the given \a row
 
367
    and \a column.
367
368
 
368
 
  \sa parent() sibling()
 
369
    \sa parent() sibling()
369
370
*/
370
371
 
371
372
QModelIndex QPersistentModelIndex::child(int row, int column) const
376
377
}
377
378
 
378
379
/*!
379
 
  Returns the data for the given \a role for the item referred to by the index.
 
380
    Returns the data for the given \a role for the item referred to by the
 
381
    index.
380
382
 
381
 
  \sa Qt::ItemDataRole, QAbstractItemModel::setData()
 
383
    \sa Qt::ItemDataRole, QAbstractItemModel::setData()
382
384
*/
383
385
QVariant QPersistentModelIndex::data(int role) const
384
386
{
388
390
}
389
391
 
390
392
/*!
391
 
  \since 4.2
 
393
    \since 4.2
392
394
 
393
 
  Returns the flags for the item referred to by the index.
 
395
    Returns the flags for the item referred to by the index.
394
396
*/
395
397
Qt::ItemFlags QPersistentModelIndex::flags() const
396
398
{
400
402
}
401
403
 
402
404
/*!
403
 
  Returns the model that the index belongs to.
 
405
    Returns the model that the index belongs to.
404
406
*/
405
407
const QAbstractItemModel *QPersistentModelIndex::model() const
406
408
{
414
416
 
415
417
    Returns true if this persistent model index is valid; otherwise returns
416
418
    false.
417
 
    A valid index belongs to a model, and has non-negative row and column numbers.
 
419
 
 
420
    A valid index belongs to a model, and has non-negative row and column
 
421
    numbers.
418
422
 
419
423
    \sa model(), row(), column()
420
424
*/
428
432
QDebug operator<<(QDebug dbg, const QModelIndex &idx)
429
433
{
430
434
#ifndef Q_BROKEN_DEBUG_STREAM
431
 
    dbg.nospace() << "QModelIndex(" << idx.row() << "," << idx.column()
432
 
                  << "," << idx.internalPointer() << "," << idx.model() << ")";
 
435
    dbg.nospace() << "QModelIndex(" << idx.row() << ',' << idx.column()
 
436
                  << ',' << idx.internalPointer() << ',' << idx.model() << ')';
433
437
    return dbg.space();
434
438
#else
435
439
    qWarning("This compiler doesn't support streaming QModelIndex to QDebug");
467
471
    return qEmptyModel();
468
472
}
469
473
 
 
474
namespace {
 
475
    struct DefaultRoleNames : public QHash<int, QByteArray>
 
476
    {
 
477
        DefaultRoleNames() {
 
478
            (*this)[Qt::DisplayRole] = "display";
 
479
            (*this)[Qt::DecorationRole] = "decoration";
 
480
            (*this)[Qt::EditRole] = "edit";
 
481
            (*this)[Qt::ToolTipRole] = "toolTip";
 
482
            (*this)[Qt::StatusTipRole] = "statusTip";
 
483
            (*this)[Qt::WhatsThisRole] = "whatsThis";
 
484
        }
 
485
    };
 
486
}
 
487
 
 
488
Q_GLOBAL_STATIC(DefaultRoleNames, qDefaultRoleNames)
 
489
 
 
490
const QHash<int,QByteArray> &QAbstractItemModelPrivate::defaultRoleNames()
 
491
{
 
492
    return *qDefaultRoleNames();
 
493
}
 
494
 
 
495
 
 
496
static uint typeOfVariant(const QVariant &value)
 
497
{
 
498
    //return 0 for integer, 1 for floating point and 2 for other
 
499
    switch (value.userType()) {
 
500
        case QVariant::Bool:
 
501
        case QVariant::Int:
 
502
        case QVariant::UInt:
 
503
        case QVariant::LongLong:
 
504
        case QVariant::ULongLong:
 
505
        case QVariant::Char:
 
506
        case QMetaType::Short:
 
507
        case QMetaType::UShort:
 
508
        case QMetaType::UChar:
 
509
        case QMetaType::ULong:
 
510
        case QMetaType::Long:
 
511
            return 0;
 
512
        case QVariant::Double:
 
513
        case QMetaType::Float:
 
514
            return 1;
 
515
        default:
 
516
            return 2;
 
517
    }
 
518
}
 
519
 
 
520
/*!
 
521
    \internal
 
522
    return true if \a value contains a numerical type
 
523
 
 
524
    This function is used by our Q{Tree,Widget,Table}WidgetModel classes to sort.
 
525
*/
 
526
bool QAbstractItemModelPrivate::variantLessThan(const QVariant &v1, const QVariant &v2)
 
527
{
 
528
    switch(qMax(typeOfVariant(v1), typeOfVariant(v2)))
 
529
    {
 
530
    case 0: //integer type
 
531
        return v1.toLongLong() < v2.toLongLong();
 
532
    case 1: //floating point
 
533
        return v1.toReal() < v2.toReal();
 
534
    default:
 
535
        return v1.toString() < v2.toString();
 
536
    }
 
537
}
 
538
 
470
539
void QAbstractItemModelPrivate::removePersistentIndexData(QPersistentModelIndexData *data)
471
540
{
472
541
    if (data->index.isValid()) {
525
594
        if (data->index.isValid()) {
526
595
            persistent.insertMultiAtEnd(data->index, data);
527
596
        } else {
528
 
            qWarning() << "QAbstractItemModel::endInsertRows:  Invalid index (" << old.row() + count << "," << old.column() << ") in model" << q_func();
529
 
        }
530
 
    }
 
597
            qWarning() << "QAbstractItemModel::endInsertRows:  Invalid index (" << old.row() + count << ',' << old.column() << ") in model" << q_func();
 
598
        }
 
599
    }
 
600
}
 
601
 
 
602
void QAbstractItemModelPrivate::itemsAboutToBeMoved(const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation)
 
603
{
 
604
    QVector<QPersistentModelIndexData *> persistent_moved_explicitly;
 
605
    QVector<QPersistentModelIndexData *> persistent_moved_in_source;
 
606
    QVector<QPersistentModelIndexData *> persistent_moved_in_destination;
 
607
 
 
608
    QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it;
 
609
    const QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator begin = persistent.indexes.constBegin();
 
610
    const QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator end = persistent.indexes.constEnd();
 
611
 
 
612
    const bool sameParent = (srcParent == destinationParent);
 
613
    const bool movingUp = (srcFirst > destinationChild);
 
614
 
 
615
    for ( it = begin; it != end; ++it) {
 
616
        QPersistentModelIndexData *data = *it;
 
617
        const QModelIndex &index = data->index;
 
618
        const QModelIndex &parent = index.parent();
 
619
        const bool isSourceIndex = (parent == srcParent);
 
620
        const bool isDestinationIndex = (parent == destinationParent);
 
621
 
 
622
        int childPosition;
 
623
        if (orientation == Qt::Vertical)
 
624
            childPosition = index.row();
 
625
        else
 
626
            childPosition = index.column();
 
627
 
 
628
        if (!index.isValid() || !(isSourceIndex || isDestinationIndex ) )
 
629
            continue;
 
630
 
 
631
        if (!sameParent && isDestinationIndex) {
 
632
            if (childPosition >= destinationChild)
 
633
                persistent_moved_in_destination.append(data);
 
634
            continue;
 
635
        }
 
636
 
 
637
        if (sameParent && movingUp && childPosition < destinationChild)
 
638
            continue;
 
639
 
 
640
        if (sameParent && !movingUp && childPosition < srcFirst )
 
641
            continue;
 
642
 
 
643
        if (!sameParent && childPosition < srcFirst)
 
644
            continue;
 
645
 
 
646
        if (sameParent && (childPosition > srcLast) && (childPosition >= destinationChild ))
 
647
            continue;
 
648
 
 
649
        if ((childPosition <= srcLast) && (childPosition >= srcFirst)) {
 
650
            persistent_moved_explicitly.append(data);
 
651
        } else {
 
652
            persistent_moved_in_source.append(data);
 
653
        }
 
654
    }
 
655
    persistent.moved.push(persistent_moved_explicitly);
 
656
    persistent.moved.push(persistent_moved_in_source);
 
657
    persistent.moved.push(persistent_moved_in_destination);
 
658
}
 
659
 
 
660
/*!
 
661
  \internal
 
662
 
 
663
  Moves persistent indexes \a indexes by amount \a change. The change will be either a change in row value or a change in
 
664
  column value depending on the value of \a orientation. The indexes may also be moved to a different parent if \a parent
 
665
  differs from the existing parent for the index.
 
666
*/
 
667
void QAbstractItemModelPrivate::movePersistentIndexes(QVector<QPersistentModelIndexData *> indexes, int change, const QModelIndex &parent, Qt::Orientation orientation)
 
668
{
 
669
    QVector<QPersistentModelIndexData *>::const_iterator it;
 
670
    const QVector<QPersistentModelIndexData *>::const_iterator begin = indexes.constBegin();
 
671
    const QVector<QPersistentModelIndexData *>::const_iterator end = indexes.constEnd();
 
672
 
 
673
    for (it = begin; it != end; ++it)
 
674
    {
 
675
        QPersistentModelIndexData *data = *it;
 
676
 
 
677
        int row = data->index.row();
 
678
        int column = data->index.column();
 
679
 
 
680
        if (Qt::Vertical == orientation)
 
681
            row += change;
 
682
        else
 
683
            column += change;
 
684
 
 
685
        persistent.indexes.erase(persistent.indexes.find(data->index));
 
686
        data->index = q_func()->index(row, column, parent);
 
687
        if (data->index.isValid()) {
 
688
            persistent.insertMultiAtEnd(data->index, data);
 
689
        } else {
 
690
            qWarning() << "QAbstractItemModel::endMoveRows:  Invalid index (" << row << "," << column << ") in model" << q_func();
 
691
        }
 
692
    }
 
693
}
 
694
 
 
695
void QAbstractItemModelPrivate::itemsMoved(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation)
 
696
{
 
697
    QVector<QPersistentModelIndexData *> moved_in_destination = persistent.moved.pop();
 
698
    QVector<QPersistentModelIndexData *> moved_in_source = persistent.moved.pop();
 
699
    QVector<QPersistentModelIndexData *> moved_explicitly = persistent.moved.pop();
 
700
 
 
701
    const bool sameParent = (sourceParent == destinationParent);
 
702
    const bool movingUp = (sourceFirst > destinationChild);
 
703
 
 
704
    const int explicit_change = (!sameParent || movingUp) ? destinationChild - sourceFirst : destinationChild - sourceLast - 1 ;
 
705
    const int source_change = (!sameParent || !movingUp) ? -1*(sourceLast - sourceFirst + 1) : sourceLast - sourceFirst + 1 ;
 
706
    const int destination_change = sourceLast - sourceFirst + 1;
 
707
 
 
708
    movePersistentIndexes(moved_explicitly, explicit_change, destinationParent, orientation);
 
709
    movePersistentIndexes(moved_in_source, source_change, sourceParent, orientation);
 
710
    movePersistentIndexes(moved_in_destination, destination_change, destinationParent, orientation);
531
711
}
532
712
 
533
713
void QAbstractItemModelPrivate::rowsAboutToBeRemoved(const QModelIndex &parent,
574
754
        if (data->index.isValid()) {
575
755
            persistent.insertMultiAtEnd(data->index, data);
576
756
        } else {
577
 
            qWarning() << "QAbstractItemModel::endRemoveRows:  Invalid index (" << old.row() - count << "," << old.column() << ") in model" << q_func();
 
757
            qWarning() << "QAbstractItemModel::endRemoveRows:  Invalid index (" << old.row() - count << ',' << old.column() << ") in model" << q_func();
578
758
        }
579
759
    }
580
760
    QVector<QPersistentModelIndexData *> persistent_invalidated = persistent.invalidated.pop();
619
799
        if (data->index.isValid()) {
620
800
            persistent.insertMultiAtEnd(data->index, data);
621
801
        } else {
622
 
            qWarning() << "QAbstractItemModel::endInsertColumns:  Invalid index (" << old.row() << "," << old.column() + count << ") in model" << q_func();
 
802
            qWarning() << "QAbstractItemModel::endInsertColumns:  Invalid index (" << old.row() << ',' << old.column() + count << ") in model" << q_func();
623
803
        }
624
804
     }
625
805
}
669
849
        if (data->index.isValid()) {
670
850
            persistent.insertMultiAtEnd(data->index, data);
671
851
        } else {
672
 
            qWarning() << "QAbstractItemModel::endRemoveColumns:  Invalid index (" << old.row() << "," << old.column() - count << ") in model" << q_func();
 
852
            qWarning() << "QAbstractItemModel::endRemoveColumns:  Invalid index (" << old.row() << ',' << old.column() - count << ") in model" << q_func();
673
853
        }
674
854
    }
675
855
    QVector<QPersistentModelIndexData *> persistent_invalidated = persistent.invalidated.pop();
688
868
    \brief The QModelIndex class is used to locate data in a data model.
689
869
 
690
870
    \ingroup model-view
691
 
    \mainclass
 
871
 
692
872
 
693
873
    This class is used as an index into item models derived from
694
874
    QAbstractItemModel. The index is used by item views, delegates, and
695
875
    selection models to locate an item in the model.
696
876
 
697
877
    New QModelIndex objects are created by the model using the
698
 
    QAbstractItemModel::createIndex() function. An \e invalid model index
699
 
    can be constructed with the QModelIndex constructor. Invalid indexes are
700
 
    often used as parent indexes when referring to top-level items in a model.
 
878
    QAbstractItemModel::createIndex() function. An \e invalid model index can
 
879
    be constructed with the QModelIndex constructor. Invalid indexes are often
 
880
    used as parent indexes when referring to top-level items in a model.
701
881
 
702
882
    Model indexes refer to items in models, and contain all the information
703
883
    required to specify their locations in those models. Each index is located
704
 
    in a given row and column, and may have a parent index; use row(), column(),
705
 
    and parent() to obtain this information. Each top-level item in a model is
706
 
    represented by a model index that does not have a parent index - in this
707
 
    case, parent() will return an invalid model index, equivalent to an index
708
 
    constructed with the zero argument form of the QModelIndex() constructor.
 
884
    in a given row and column, and may have a parent index; use row(),
 
885
    column(), and parent() to obtain this information. Each top-level item in a
 
886
    model is represented by a model index that does not have a parent index -
 
887
    in this case, parent() will return an invalid model index, equivalent to an
 
888
    index constructed with the zero argument form of the QModelIndex()
 
889
    constructor.
709
890
 
710
891
    To obtain a model index that refers to an existing item in a model, call
711
 
    QAbstractItemModel::index() with the required row and column
712
 
    values, and the model index of the parent. When referring to
713
 
    top-level items in a model, supply QModelIndex() as the parent index.
 
892
    QAbstractItemModel::index() with the required row and column values, and
 
893
    the model index of the parent. When referring to top-level items in a
 
894
    model, supply QModelIndex() as the parent index.
714
895
 
715
896
    The model() function returns the model that the index references as a
716
 
    QAbstractItemModel.
717
 
    The child() function is used to examine the items held beneath the index
718
 
    in the model.
719
 
    The sibling() function allows you to traverse items in the model on the
720
 
    same level as the index.
 
897
    QAbstractItemModel. The child() function is used to examine items held
 
898
    under the index in the model. The sibling() function allows you to traverse
 
899
    items in the model on the same level as the index.
721
900
 
722
901
    \note Model indexes should be used immediately and then discarded. You
723
902
    should not rely on indexes to remain valid after calling model functions
724
903
    that change the structure of the model or delete items. If you need to
725
904
    keep a model index over time use a QPersistentModelIndex.
726
905
 
727
 
    \sa \link model-view-programming.html Model/View Programming\endlink QPersistentModelIndex QAbstractItemModel
 
906
    \sa {Model/View Programming}, QPersistentModelIndex, QAbstractItemModel
728
907
*/
729
908
 
730
909
/*!
731
910
    \fn QModelIndex::QModelIndex()
732
911
 
733
 
    Creates a new empty model index.
734
 
    This type of model index is used to indicate
735
 
    that the position in the model is invalid.
 
912
    Creates a new empty model index. This type of model index is used to
 
913
    indicate that the position in the model is invalid.
736
914
 
737
915
    \sa isValid() QAbstractItemModel
738
916
*/
795
973
    \fn bool QModelIndex::isValid() const
796
974
 
797
975
    Returns true if this model index is valid; otherwise returns false.
798
 
    A valid index belongs to a model, and has non-negative row and column numbers.
 
976
 
 
977
    A valid index belongs to a model, and has non-negative row and column
 
978
    numbers.
799
979
 
800
980
    \sa model(), row(), column()
801
981
*/
806
986
    Returns a pointer to the model containing the item that this index
807
987
    refers to.
808
988
 
809
 
    You receive a const pointer to the model because calls to
810
 
    non-const functions of the model might invalidate the model index
811
 
    - and possibly crash your application.
 
989
    A const pointer to the model is returned because calls to non-const
 
990
    functions of the model might invalidate the model index and possibly
 
991
    crash your application.
812
992
*/
813
993
 
814
994
/*!
815
995
    \fn QModelIndex QModelIndex::sibling(int row, int column) const
816
996
 
817
 
    Returns the sibling at \a row and \a column or an invalid
818
 
    QModelIndex if there is no sibling at this position.
 
997
    Returns the sibling at \a row and \a column. If there is no sibling at this
 
998
    position, an invalid QModelIndex is returned.
819
999
 
820
 
    \sa parent() child()
 
1000
    \sa parent(), child()
821
1001
*/
822
1002
 
823
1003
/*!
824
1004
    \fn QModelIndex QModelIndex::child(int row, int column) const
825
1005
 
826
 
    Returns the child of the model index that is stored in the given
827
 
    \a row and \a column.
 
1006
    Returns the child of the model index that is stored in the given \a row and
 
1007
    \a column.
828
1008
 
829
 
    \sa parent() sibling()
 
1009
    \sa parent(), sibling()
830
1010
*/
831
1011
 
832
1012
/*!
833
1013
    \fn QVariant QModelIndex::data(int role) const
834
1014
 
835
 
    Returns the data for the given \a role for the item referred to by the index.
 
1015
    Returns the data for the given \a role for the item referred to by the
 
1016
    index.
836
1017
*/
837
1018
 
838
1019
/*!
845
1026
/*!
846
1027
    \fn bool QModelIndex::operator==(const QModelIndex &other) const
847
1028
 
848
 
    Returns true if this model index refers to the same location as
849
 
    the \a other model index; otherwise returns false.
850
 
    Note that all values in the model index are used when comparing
851
 
    with another model index.
 
1029
    Returns true if this model index refers to the same location as the
 
1030
    \a other model index; otherwise returns false.
 
1031
 
 
1032
    All values in the model index are used when comparing with another model
 
1033
    index.
852
1034
*/
853
1035
 
854
1036
 
855
1037
/*!
856
1038
    \fn bool QModelIndex::operator!=(const QModelIndex &other) const
857
1039
 
858
 
    Returns true if this model index does not refer to the same
859
 
    location as the \a other model index; otherwise returns false.
 
1040
    Returns true if this model index does not refer to the same location as
 
1041
    the \a other model index; otherwise returns false.
860
1042
*/
861
1043
 
862
1044
 
863
1045
/*!
864
 
  \fn QModelIndex QModelIndex::parent() const
865
 
 
866
 
  Returns the parent of the model index, or QModelIndex() if it has no
867
 
  parent.
868
 
 
869
 
  \sa child() sibling() model()
 
1046
    \fn QModelIndex QModelIndex::parent() const
 
1047
 
 
1048
    Returns the parent of the model index, or QModelIndex() if it has no
 
1049
    parent.
 
1050
 
 
1051
    \sa child(), sibling(), model()
870
1052
*/
871
1053
 
872
1054
/*!
876
1058
    item model classes.
877
1059
 
878
1060
    \ingroup model-view
879
 
    \mainclass
 
1061
 
880
1062
 
881
1063
    The QAbstractItemModel class defines the standard interface that item
882
1064
    models must use to be able to interoperate with other components in the
895
1077
    simple table of rows and columns. Each item has a unique index specified by
896
1078
    a QModelIndex.
897
1079
 
898
 
    \img modelindex-no-parent.png
 
1080
    \image modelindex-no-parent.png
899
1081
 
900
1082
    Every item of data that can be accessed via a model has an associated model
901
1083
    index. You can obtain this model index using the index() function. Each
1013
1195
 
1014
1196
    \sa {Model Classes}, {Model Subclassing Reference}, QModelIndex,
1015
1197
        QAbstractItemView, {Using Drag and Drop with Item Views},
1016
 
        {Simple DOM Model Example},
1017
 
        {Simple Tree Model Example}, {Editable Tree Model Example},
1018
 
        {Fetch More Example}
 
1198
        {Simple DOM Model Example}, {Simple Tree Model Example},
 
1199
        {Editable Tree Model Example}, {Fetch More Example}
1019
1200
*/
1020
1201
 
1021
1202
/*!
1024
1205
    Returns the index of the item in the model specified by the given \a row,
1025
1206
    \a column and \a parent index.
1026
1207
 
1027
 
    When reimplementing this function in a subclass, call createIndex() to generate
1028
 
    model indexes that other components can use to refer to items in your model.
 
1208
    When reimplementing this function in a subclass, call createIndex() to
 
1209
    generate model indexes that other components can use to refer to items in
 
1210
    your model.
1029
1211
 
1030
1212
    \sa createIndex()
1031
1213
*/
1034
1216
    \fn bool QAbstractItemModel::insertColumn(int column, const QModelIndex &parent)
1035
1217
 
1036
1218
    Inserts a single column before the given \a column in the child items of
1037
 
    the \a parent specified. Returns true if the column is inserted; otherwise
1038
 
    returns false.
 
1219
    the \a parent specified.
 
1220
 
 
1221
    Returns true if the column is inserted; otherwise returns false.
1039
1222
 
1040
1223
    \sa insertColumns() insertRow() removeColumn()
1041
1224
*/
1043
1226
/*!
1044
1227
    \fn bool QAbstractItemModel::insertRow(int row, const QModelIndex &parent)
1045
1228
 
 
1229
    \note The base class implementation of this function does nothing and
 
1230
    returns false.
 
1231
 
1046
1232
    Inserts a single row before the given \a row in the child items of the
1047
 
    \a parent specified. Returns true if the row is inserted; otherwise
1048
 
    returns false.
 
1233
    \a parent specified.
 
1234
 
 
1235
    Returns true if the row is inserted; otherwise returns false.
1049
1236
 
1050
1237
    \sa insertRows() insertColumn() removeRow()
1051
1238
*/
1058
1245
/*!
1059
1246
    \fn QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const = 0
1060
1247
 
1061
 
    Returns the parent of the model item with the given \a index, or QModelIndex()
1062
 
    if it has no parent.
 
1248
    Returns the parent of the model item with the given \a index. If the model
 
1249
    has no parent, an invalid QModelIndex is returned.
1063
1250
 
1064
1251
    A common convention used in models that expose tree data structures is that
1065
 
    only items in the first column have children. For that case, when reimplementing
1066
 
    this function in a subclass the column of the returned QModelIndex would be 0.
 
1252
    only items in the first column have children. For that case, when
 
1253
    reimplementing this function in a subclass the column of the returned
 
1254
    QModelIndex would be 0.
1067
1255
 
1068
 
    \note When reimplementing this function in a subclass, be careful to avoid
 
1256
    When reimplementing this function in a subclass, be careful to avoid
1069
1257
    calling QModelIndex member functions, such as QModelIndex::parent(), since
1070
 
    indexes belonging to your model will simply call your implementation, leading
1071
 
    to infinite recursion.
 
1258
    indexes belonging to your model will simply call your implementation,
 
1259
    leading to infinite recursion.
1072
1260
 
1073
1261
    \sa createIndex()
1074
1262
*/
1076
1264
/*!
1077
1265
    \fn bool QAbstractItemModel::removeColumn(int column, const QModelIndex &parent)
1078
1266
 
1079
 
    Removes the given \a column from the child items of the \a parent specified.
 
1267
    Removes the given \a column from the child items of the \a parent
 
1268
    specified.
 
1269
 
1080
1270
    Returns true if the column is removed; otherwise returns false.
1081
1271
 
1082
1272
    \sa removeColumns(), removeRow(), insertColumn()
1086
1276
    \fn bool QAbstractItemModel::removeRow(int row, const QModelIndex &parent)
1087
1277
 
1088
1278
    Removes the given \a row from the child items of the \a parent specified.
 
1279
 
1089
1280
    Returns true if the row is removed; otherwise returns false.
1090
1281
 
1091
 
    The removeRow() is a convenience function that calls removeRows().
1092
 
    The QAbstractItemModel implementation of removeRows does nothing.
 
1282
    This is a convenience function that calls removeRows(). The
 
1283
    QAbstractItemModel implementation of removeRows() does nothing.
1093
1284
 
1094
1285
    \sa removeRows(), removeColumn(), insertRow()
1095
1286
*/
1101
1292
    indicates whether the horizontal or vertical header has changed. The
1102
1293
    sections in the header from the \a first to the \a last need to be updated.
1103
1294
 
1104
 
    Note that this signal must be emitted explicitly when
1105
 
    reimplementing the setHeaderData() function.
 
1295
    When reimplementing the setHeaderData() function, this signal must be
 
1296
    emitted explicitly.
1106
1297
 
1107
 
    If you are changing the number of columns or rows you don't need
1108
 
    to emit this signal, but use the begin/end functions (see the
1109
 
    section on subclassing in the QAbstractItemModel class description
1110
 
    for details).
 
1298
    If you are changing the number of columns or rows you do not need to emit
 
1299
    this signal, but use the begin/end functions (refer to the section on
 
1300
    subclassing in the QAbstractItemModel class description for details).
1111
1301
 
1112
1302
    \sa headerData(), setHeaderData(), dataChanged()
1113
1303
*/
1117
1307
    \since 4.2
1118
1308
 
1119
1309
    This signal is emitted just before the layout of a model is changed.
1120
 
    Components connected to this signal use it to adapt to changes
1121
 
    in the model's layout.
 
1310
    Components connected to this signal use it to adapt to changes in the
 
1311
    model's layout.
1122
1312
 
1123
1313
    Subclasses should update any persistent model indexes after emitting
1124
1314
    layoutAboutToBeChanged().
1130
1320
    \fn void QAbstractItemModel::layoutChanged()
1131
1321
 
1132
1322
    This signal is emitted whenever the layout of items exposed by the model
1133
 
    has changed; for example, when the model has been sorted. When this signal is
1134
 
    received by a view, it should update the layout of items to reflect this
 
1323
    has changed; for example, when the model has been sorted. When this signal
 
1324
    is received by a view, it should update the layout of items to reflect this
1135
1325
    change.
1136
1326
 
1137
 
    When subclassing QAbstractItemModel or QAbstractProxyModel, ensure that
1138
 
    you emit layoutAboutToBeChanged() before changing the order of items or
 
1327
    When subclassing QAbstractItemModel or QAbstractProxyModel, ensure that you
 
1328
    emit layoutAboutToBeChanged() before changing the order of items or
1139
1329
    altering the structure of the data you expose to views, and emit
1140
1330
    layoutChanged() after changing the layout.
1141
1331
 
1142
 
    Subclasses should update any persistent model indexes before
1143
 
    emitting layoutChanged().
1144
 
 
1145
 
    \sa layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), reset(), changePersistentIndex()
 
1332
    Subclasses should update any persistent model indexes before emitting
 
1333
    layoutChanged(). In other words, when the structure changes:
 
1334
 
 
1335
    \list
 
1336
        \o  Call beginLayoutChanged()
 
1337
        \o  Remember the QModelIndex that will change
 
1338
        \o  Update your internal data
 
1339
        \o  Call changePersistentIndex()
 
1340
        \o  Call endLayoutChanged()
 
1341
    \endlist
 
1342
 
 
1343
 
 
1344
    \sa layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), modelReset(),
 
1345
        changePersistentIndex()
1146
1346
*/
1147
1347
 
1148
1348
/*!
1172
1372
/*!
1173
1373
    \fn QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const
1174
1374
 
1175
 
    Returns the sibling at \a row and \a column for the item at \a index, or
1176
 
    an invalid QModelIndex if there is no sibling at that location.
 
1375
    Returns the sibling at \a row and \a column for the item at \a index, or an
 
1376
    invalid QModelIndex if there is no sibling at that location.
1177
1377
 
1178
1378
    sibling() is just a convenience function that finds the item's parent, and
1179
 
    uses it to retrieve the index of the child item in the specified \a row
1180
 
    and \a column.
 
1379
    uses it to retrieve the index of the child item in the specified \a row and
 
1380
    \a column.
1181
1381
 
1182
1382
    \sa index(), QModelIndex::row(), QModelIndex::column()
1183
1383
*/
1186
1386
/*!
1187
1387
    \fn int QAbstractItemModel::rowCount(const QModelIndex &parent) const
1188
1388
 
1189
 
    Returns the number of rows under the given \a parent.   When the parent
1190
 
    is valid it means that rowCount is returning the number of children of parent.
 
1389
    Returns the number of rows under the given \a parent. When the parent is
 
1390
    valid it means that rowCount is returning the number of children of parent.
1191
1391
 
1192
 
    \bold{Tip:} When implementing a table based model, rowCount() should return 0 when
1193
 
    the parent is valid.
 
1392
    \note When implementing a table based model, rowCount() should return 0
 
1393
    when the parent is valid.
1194
1394
 
1195
1395
    \sa columnCount()
1196
1396
*/
1200
1400
 
1201
1401
    Returns the number of columns for the children of the given \a parent.
1202
1402
 
1203
 
    In most subclasses, the number of columns is independent of the
1204
 
    \a parent. For example:
 
1403
    In most subclasses, the number of columns is independent of the \a parent.
 
1404
 
 
1405
    For example:
1205
1406
 
1206
1407
    \snippet examples/itemviews/simpledommodel/dommodel.cpp 2
1207
1408
 
1208
 
    \bold{Tip:} When implementing a table based model, columnCount() should return 0 when
1209
 
    the parent is valid.
 
1409
    \note When implementing a table based model, columnCount() should return 0
 
1410
    when the parent is valid.
1210
1411
 
1211
1412
    \sa rowCount()
1212
1413
*/
1233
1434
    model. The new items are those between \a start and \a end
1234
1435
    inclusive, under the given \a parent item.
1235
1436
 
1236
 
    \bold{Note:} Components connected to this signal use it to adapt to changes
1237
 
    in the model's dimensions. It can only be emitted by the QAbstractItemModel
 
1437
    \note Components connected to this signal use it to adapt to changes in the
 
1438
    model's dimensions. It can only be emitted by the QAbstractItemModel
1238
1439
    implementation, and cannot be explicitly emitted in subclass code.
1239
1440
 
1240
1441
    \sa insertRows(), beginInsertRows()
1243
1444
/*!
1244
1445
    \fn void QAbstractItemModel::rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
1245
1446
 
1246
 
    This signal is emitted just before rows are inserted into the
1247
 
    model. The new items will be positioned between \a start and \a end
1248
 
    inclusive, under the given \a parent item.
 
1447
    This signal is emitted just before rows are inserted into the model. The
 
1448
    new items will be positioned between \a start and \a end inclusive, under
 
1449
    the given \a parent item.
1249
1450
 
1250
 
    \bold{Note:} Components connected to this signal use it to adapt to changes
 
1451
    \note Components connected to this signal use it to adapt to changes
1251
1452
    in the model's dimensions. It can only be emitted by the QAbstractItemModel
1252
1453
    implementation, and cannot be explicitly emitted in subclass code.
1253
1454
 
1257
1458
/*!
1258
1459
    \fn void QAbstractItemModel::rowsRemoved(const QModelIndex &parent, int start, int end)
1259
1460
 
1260
 
    This signal is emitted after rows have been removed from the
1261
 
    model. The removed items are those between \a start and \a end
1262
 
    inclusive, under the given \a parent item.
 
1461
    This signal is emitted after rows have been removed from the model. The
 
1462
    removed items are those between \a start and \a end inclusive, under the
 
1463
    given \a parent item.
1263
1464
 
1264
 
    \bold{Note:} Components connected to this signal use it to adapt to changes
 
1465
    \note Components connected to this signal use it to adapt to changes
1265
1466
    in the model's dimensions. It can only be emitted by the QAbstractItemModel
1266
1467
    implementation, and cannot be explicitly emitted in subclass code.
1267
1468
 
1271
1472
/*!
1272
1473
    \fn void QAbstractItemModel::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
1273
1474
 
1274
 
    This signal is emitted just before rows are removed from the
1275
 
    model. The items that will be removed are those between \a start and \a end
1276
 
    inclusive, under the given \a parent item.
 
1475
    This signal is emitted just before rows are removed from the model. The
 
1476
    items that will be removed are those between \a start and \a end inclusive,
 
1477
    under the given \a parent item.
1277
1478
 
1278
 
    \bold{Note:} Components connected to this signal use it to adapt to changes
 
1479
    \note Components connected to this signal use it to adapt to changes
1279
1480
    in the model's dimensions. It can only be emitted by the QAbstractItemModel
1280
1481
    implementation, and cannot be explicitly emitted in subclass code.
1281
1482
 
1283
1484
*/
1284
1485
 
1285
1486
/*!
 
1487
    \fn void QAbstractItemModel::rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 
1488
    \since 4.6
 
1489
 
 
1490
    This signal is emitted after rows have been moved within the
 
1491
    model. The items between \a sourceStart and \a sourceEnd
 
1492
    inclusive, under the given \a sourceParent item have been moved to \a destinationParent
 
1493
    starting at the row \a destinationRow.
 
1494
 
 
1495
    \bold{Note:} Components connected to this signal use it to adapt to changes
 
1496
    in the model's dimensions. It can only be emitted by the QAbstractItemModel
 
1497
    implementation, and cannot be explicitly emitted in subclass code.
 
1498
 
 
1499
    \sa beginMoveRows()
 
1500
*/
 
1501
 
 
1502
/*!
 
1503
    \fn void QAbstractItemModel::rowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 
1504
    \since 4.6
 
1505
 
 
1506
    This signal is emitted just before rows are moved within the
 
1507
    model. The items that will be moved are those between \a sourceStart and \a sourceEnd
 
1508
    inclusive, under the given \a sourceParent item. They will be moved to \a destinationParent
 
1509
    starting at the row \a destinationRow.
 
1510
 
 
1511
    \bold{Note:} Components connected to this signal use it to adapt to changes
 
1512
    in the model's dimensions. It can only be emitted by the QAbstractItemModel
 
1513
    implementation, and cannot be explicitly emitted in subclass code.
 
1514
 
 
1515
    \sa beginMoveRows()
 
1516
*/
 
1517
 
 
1518
/*!
 
1519
    \fn void QAbstractItemModel::columnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 
1520
    \since 4.6
 
1521
 
 
1522
    This signal is emitted after columns have been moved within the
 
1523
    model. The items between \a sourceStart and \a sourceEnd
 
1524
    inclusive, under the given \a sourceParent item have been moved to \a destinationParent
 
1525
    starting at the column \a destinationColumn.
 
1526
 
 
1527
    \bold{Note:} Components connected to this signal use it to adapt to changes
 
1528
    in the model's dimensions. It can only be emitted by the QAbstractItemModel
 
1529
    implementation, and cannot be explicitly emitted in subclass code.
 
1530
 
 
1531
    \sa beginMoveRows()
 
1532
*/
 
1533
 
 
1534
/*!
 
1535
    \fn void QAbstractItemModel::columnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 
1536
    \since 4.6
 
1537
 
 
1538
    This signal is emitted just before columns are moved within the
 
1539
    model. The items that will be moved are those between \a sourceStart and \a sourceEnd
 
1540
    inclusive, under the given \a sourceParent item. They will be moved to \a destinationParent
 
1541
    starting at the column \a destinationColumn.
 
1542
 
 
1543
    \bold{Note:} Components connected to this signal use it to adapt to changes
 
1544
    in the model's dimensions. It can only be emitted by the QAbstractItemModel
 
1545
    implementation, and cannot be explicitly emitted in subclass code.
 
1546
 
 
1547
    \sa beginMoveRows()
 
1548
*/
 
1549
 
 
1550
/*!
1286
1551
    \fn void QAbstractItemModel::columnsInserted(const QModelIndex &parent, int start, int end)
1287
1552
 
1288
 
    This signal is emitted after columns have been inserted into the
1289
 
    model. The new items are those between \a start and \a end
1290
 
    inclusive, under the given \a parent item.
 
1553
    This signal is emitted after columns have been inserted into the model. The
 
1554
    new items are those between \a start and \a end inclusive, under the given
 
1555
    \a parent item.
1291
1556
 
1292
 
    \bold{Note:} Components connected to this signal use it to adapt to changes
1293
 
    in the model's dimensions. It can only be emitted by the QAbstractItemModel
 
1557
    \note Components connected to this signal use it to adapt to changes in the
 
1558
    model's dimensions. It can only be emitted by the QAbstractItemModel
1294
1559
    implementation, and cannot be explicitly emitted in subclass code.
1295
1560
 
1296
1561
    \sa insertColumns(), beginInsertColumns()
1299
1564
/*!
1300
1565
    \fn void QAbstractItemModel::columnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
1301
1566
 
1302
 
    This signal is emitted just before columns are inserted into the
1303
 
    model. The new items will be positioned between \a start and \a end
1304
 
    inclusive, under the given \a parent item.
 
1567
    This signal is emitted just before columns are inserted into the model. The
 
1568
    new items will be positioned between \a start and \a end inclusive, under
 
1569
    the given \a parent item.
1305
1570
 
1306
 
    \bold{Note:} Components connected to this signal use it to adapt to changes
1307
 
    in the model's dimensions. It can only be emitted by the QAbstractItemModel
 
1571
    \note Components connected to this signal use it to adapt to changes in the
 
1572
    model's dimensions. It can only be emitted by the QAbstractItemModel
1308
1573
    implementation, and cannot be explicitly emitted in subclass code.
1309
1574
 
1310
1575
    \sa insertColumns(), beginInsertColumns()
1313
1578
/*!
1314
1579
    \fn void QAbstractItemModel::columnsRemoved(const QModelIndex &parent, int start, int end)
1315
1580
 
1316
 
    This signal is emitted after columns have been removed from the
1317
 
    model. The removed items are those between \a start and \a end
1318
 
    inclusive, under the given \a parent item.
 
1581
    This signal is emitted after columns have been removed from the model.
 
1582
    The removed items are those between \a start and \a end inclusive,
 
1583
    under the given \a parent item.
1319
1584
 
1320
 
    \bold{Note:} Components connected to this signal use it to adapt to changes
1321
 
    in the model's dimensions. It can only be emitted by the QAbstractItemModel
 
1585
    \note Components connected to this signal use it to adapt to changes in
 
1586
    the model's dimensions. It can only be emitted by the QAbstractItemModel
1322
1587
    implementation, and cannot be explicitly emitted in subclass code.
1323
1588
 
1324
1589
    \sa removeColumns(), beginRemoveColumns()
1327
1592
/*!
1328
1593
    \fn void QAbstractItemModel::columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
1329
1594
 
1330
 
    This signal is emitted just before columns are removed
1331
 
    from the model. The items to be removed are those between \a start and
1332
 
    \a end inclusive, under the given \a parent item.
 
1595
    This signal is emitted just before columns are removed from the model. The
 
1596
    items to be removed are those between \a start and \a end inclusive, under
 
1597
    the given \a parent item.
1333
1598
 
1334
 
    \bold{Note:} Components connected to this signal use it to adapt to changes
1335
 
    in the model's dimensions. It can only be emitted by the QAbstractItemModel
 
1599
    \note Components connected to this signal use it to adapt to changes in the
 
1600
    model's dimensions. It can only be emitted by the QAbstractItemModel
1336
1601
    implementation, and cannot be explicitly emitted in subclass code.
1337
1602
 
1338
1603
    \sa removeColumns(), beginRemoveColumns()
1339
1604
*/
1340
1605
 
1341
1606
/*!
1342
 
  Returns true if the model returns a valid QModelIndex for \a row and
1343
 
  \a column with \a parent, otherwise returns false.
 
1607
    Returns true if the model returns a valid QModelIndex for \a row and
 
1608
    \a column with \a parent, otherwise returns false.
1344
1609
*/
1345
1610
bool QAbstractItemModel::hasIndex(int row, int column, const QModelIndex &parent) const
1346
1611
{
1351
1616
 
1352
1617
 
1353
1618
/*!
1354
 
  Returns true if \a parent has any children; otherwise returns false.
1355
 
  Use rowCount() on the parent to find out the number of children.
1356
 
 
1357
 
  \sa parent() index()
 
1619
    Returns true if \a parent has any children; otherwise returns false.
 
1620
 
 
1621
    Use rowCount() on the parent to find out the number of children.
 
1622
 
 
1623
    \sa parent() index()
1358
1624
*/
1359
1625
bool QAbstractItemModel::hasChildren(const QModelIndex &parent) const
1360
1626
{
1363
1629
 
1364
1630
 
1365
1631
/*!
1366
 
    Returns a map with values for all predefined roles in the model
1367
 
    for the item at the given \a index.
 
1632
    Returns a map with values for all predefined roles in the model for the
 
1633
    item at the given \a index.
1368
1634
 
1369
 
    Reimplemented this function if you want to extend the default behavior
1370
 
    of this function to include custom roles in the map.
 
1635
    Reimplement this function if you want to extend the default behavior of
 
1636
    this function to include custom roles in the map.
1371
1637
 
1372
1638
    \sa Qt::ItemDataRole, data()
1373
1639
*/
1376
1642
    QMap<int, QVariant> roles;
1377
1643
    for (int i = 0; i < Qt::UserRole; ++i) {
1378
1644
        QVariant variantData = data(index, i);
1379
 
        if (variantData.type() != QVariant::Invalid)
 
1645
        if (variantData.isValid())
1380
1646
            roles.insert(i, variantData);
1381
1647
    }
1382
1648
    return roles;
1384
1650
 
1385
1651
/*!
1386
1652
    Sets the \a role data for the item at \a index to \a value.
 
1653
 
1387
1654
    Returns true if successful; otherwise returns false.
1388
1655
 
1389
 
    The dataChanged() signal should be emitted if the data was successfully set.
 
1656
    The dataChanged() signal should be emitted if the data was successfully
 
1657
    set.
1390
1658
 
1391
 
    The base class implementation returns false. This function and
1392
 
    data() must be reimplemented for editable models. Note that the
1393
 
    dataChanged() signal must be emitted explicitly when
1394
 
    reimplementing this function.
 
1659
    The base class implementation returns false. This function and data() must
 
1660
    be reimplemented for editable models.
1395
1661
 
1396
1662
    \sa Qt::ItemDataRole, data(), itemData()
1397
1663
*/
1410
1676
    by the \a index.
1411
1677
 
1412
1678
    \note If you do not have a value to return, return an \bold invalid
1413
 
    QVariant() instead of returning 0.
 
1679
    QVariant instead of returning 0.
1414
1680
 
1415
1681
    \sa Qt::ItemDataRole, setData(), headerData()
1416
1682
*/
1417
1683
 
1418
1684
/*!
1419
1685
    Sets the role data for the item at \a index to the associated value in
1420
 
    \a roles, for every Qt::ItemDataRole. Returns true if successful; otherwise
1421
 
    returns false.
 
1686
    \a roles, for every Qt::ItemDataRole.
 
1687
 
 
1688
    Returns true if successful; otherwise returns false.
1422
1689
 
1423
1690
    Roles that are not in \a roles will not be modified.
1424
1691
 
1433
1700
}
1434
1701
 
1435
1702
/*!
1436
 
    Returns a list of MIME types that can be used to describe a list of
1437
 
    model indexes.
 
1703
    Returns a list of MIME types that can be used to describe a list of model
 
1704
    indexes.
1438
1705
 
1439
1706
    \sa mimeData()
1440
1707
*/
1446
1713
}
1447
1714
 
1448
1715
/*!
1449
 
    Returns an object that contains serialized items of data corresponding to the
1450
 
    list of \a indexes specified. The formats used to describe the encoded data
1451
 
    is obtained from the mimeTypes() function.
 
1716
    Returns an object that contains serialized items of data corresponding to
 
1717
    the list of \a indexes specified. The formats used to describe the encoded
 
1718
    data is obtained from the mimeTypes() function.
1452
1719
 
1453
 
    If the list of indexes is empty, or there are no supported MIME types,
1454
 
    0 is returned rather than a serialized empty list.
 
1720
    If the list of indexes is empty, or there are no supported MIME types, 0 is
 
1721
    returned rather than a serialized empty list.
1455
1722
 
1456
1723
    \sa mimeTypes(), dropMimeData()
1457
1724
*/
1473
1740
 
1474
1741
/*!
1475
1742
    Handles the \a data supplied by a drag and drop operation that ended with
1476
 
    the given \a action. Returns true if the data and action can be handled
1477
 
    by the model; otherwise returns false.
1478
 
 
1479
 
    Although the specified \a row, \a column and \a parent indicate the location of
1480
 
    an item in the model where the operation ended, it is the responsibility of the
1481
 
    view to provide a suitable location for where the data should be inserted.
1482
 
 
1483
 
    For instance, a drop action on an item in a QTreeView can result in new items
1484
 
    either being inserted as children of the item specified by \a row, \a column,
1485
 
    and \a parent, or as siblings of the item.
 
1743
    the given \a action.
 
1744
 
 
1745
    Returns true if the data and action can be handled by the model; otherwise
 
1746
    returns false.
 
1747
 
 
1748
    Although the specified \a row, \a column and \a parent indicate the
 
1749
    location of an item in the model where the operation ended, it is the
 
1750
    responsibility of the view to provide a suitable location for where the
 
1751
    data should be inserted.
 
1752
 
 
1753
    For instance, a drop action on an item in a QTreeView can result in new
 
1754
    items either being inserted as children of the item specified by \a row,
 
1755
    \a column, and \a parent, or as siblings of the item.
1486
1756
 
1487
1757
    When row and column are -1 it means that it is up to the model to decide
1488
 
    where to place the data.  This can occur in a tree when data is dropped
1489
 
    on a parent.  Models will usually append the data to the parent in this case.
1490
 
 
1491
 
    Returns true if the dropping was successful otherwise false.
 
1758
    where to place the data. This can occur in a tree when data is dropped on
 
1759
    a parent. Models will usually append the data to the parent in this case.
1492
1760
 
1493
1761
    \sa supportedDropActions(), {Using Drag and Drop with Item Views}
1494
1762
*/
1518
1786
}
1519
1787
 
1520
1788
/*!
1521
 
  \since 4.2
1522
 
 
1523
 
  Returns the drop actions supported by this model.
1524
 
 
1525
 
  The default implementation returns Qt::CopyAction. Reimplement this
1526
 
  function if you wish to support additional actions. Note that you
1527
 
  must also reimplement the dropMimeData() function to handle the
1528
 
  additional operations.
1529
 
 
1530
 
  \sa dropMimeData(), Qt::DropActions, {Using Drag and Drop with Item
1531
 
  Views}
 
1789
    \since 4.2
 
1790
 
 
1791
    Returns the drop actions supported by this model.
 
1792
 
 
1793
    The default implementation returns Qt::CopyAction. Reimplement this
 
1794
    function if you wish to support additional actions. You must also
 
1795
    reimplement the dropMimeData() function to handle the additional
 
1796
    operations.
 
1797
 
 
1798
    \sa dropMimeData(), Qt::DropActions, {Using Drag and Drop with Item
 
1799
    Views}
1532
1800
*/
1533
1801
Qt::DropActions QAbstractItemModel::supportedDropActions() const
1534
1802
{
1536
1804
}
1537
1805
 
1538
1806
/*!
1539
 
  Returns the actions supported by the data in this model.
1540
 
 
1541
 
  The default implementation returns supportedDropActions() unless
1542
 
  specific values have been set with setSupportedDragActions().
1543
 
 
1544
 
  supportedDragActions() is used by QAbstractItemView::startDrag() as
1545
 
  the default values when a drag occurs.
1546
 
 
1547
 
  \sa Qt::DropActions, {Using Drag and Drop with Item Views}
 
1807
    Returns the actions supported by the data in this model.
 
1808
 
 
1809
    The default implementation returns supportedDropActions() unless specific
 
1810
    values have been set with setSupportedDragActions().
 
1811
 
 
1812
    supportedDragActions() is used by QAbstractItemView::startDrag() as the
 
1813
    default values when a drag occurs.
 
1814
 
 
1815
    \sa Qt::DropActions, {Using Drag and Drop with Item Views}
1548
1816
*/
1549
1817
Qt::DropActions QAbstractItemModel::supportedDragActions() const
1550
1818
{
1569
1837
}
1570
1838
 
1571
1839
/*!
1572
 
  On models that support this, inserts \a count rows into the model before the
1573
 
  given \a row.  The items in the new row will be children of the item
1574
 
  represented by the \a parent model index.
1575
 
 
1576
 
  If \a row is 0, the rows are prepended to any existing rows in the parent.
1577
 
  If \a row is rowCount(), the rows are appended to any existing rows in the
1578
 
  parent.
1579
 
  If \a parent has no children, a single column with \a count rows is inserted.
1580
 
 
1581
 
  Returns true if the rows were successfully inserted; otherwise returns
1582
 
  false.
1583
 
 
1584
 
  The base class implementation does nothing and returns false.
1585
 
 
1586
 
  If you implement your own model, you can reimplement this function
1587
 
  if you want to support insertions. Alternatively, you can provide
1588
 
  you own API for altering the data.
1589
 
 
1590
 
  \sa insertColumns(), removeRows(), beginInsertRows(), endInsertRows()
 
1840
    \note The base class implementation of this function does nothing and
 
1841
    returns false.
 
1842
 
 
1843
    On models that support this, inserts \a count rows into the model before
 
1844
    the given \a row. Items in the new row will be children of the item
 
1845
    represented by the \a parent model index.
 
1846
 
 
1847
    If \a row is 0, the rows are prepended to any existing rows in the parent.
 
1848
 
 
1849
    If \a row is rowCount(), the rows are appended to any existing rows in the
 
1850
    parent.
 
1851
 
 
1852
    If \a parent has no children, a single column with \a count rows is
 
1853
    inserted.
 
1854
 
 
1855
    Returns true if the rows were successfully inserted; otherwise returns
 
1856
    false.
 
1857
 
 
1858
    If you implement your own model, you can reimplement this function if you
 
1859
    want to support insertions. Alternatively, you can provide your own API for
 
1860
    altering the data. In either case, you will need to call
 
1861
    beginInsertRows() and endInsertRows() to notify other components that the
 
1862
    model has changed.
 
1863
 
 
1864
    \sa insertColumns(), removeRows(), beginInsertRows(), endInsertRows()
1591
1865
*/
1592
1866
bool QAbstractItemModel::insertRows(int, int, const QModelIndex &)
1593
1867
{
1595
1869
}
1596
1870
 
1597
1871
/*!
1598
 
  On models that support this, inserts \a count new columns into the model
1599
 
  before the given \a column.  The items in each new column will be children
1600
 
  of the item represented by the \a parent model index.
1601
 
 
1602
 
  If \a column is 0, the columns are prepended to any existing columns.
1603
 
  If \a column is columnCount(), the columns are appended to any existing
1604
 
  columns.
1605
 
  If \a parent has no children, a single row with \a count columns is inserted.
1606
 
 
1607
 
  Returns true if the columns were successfully inserted; otherwise returns
1608
 
  false.
1609
 
 
1610
 
  The base class implementation does nothing and returns false.
1611
 
 
1612
 
  If you implement your own model, you can reimplement this function
1613
 
  if you want to support insertions. Alternatively, you can provide
1614
 
  you own API for altering the data.
1615
 
 
1616
 
  \sa insertRows(), removeColumns(), beginInsertColumns(), endInsertColumns()
 
1872
    On models that support this, inserts \a count new columns into the model
 
1873
    before the given \a column. The items in each new column will be children
 
1874
    of the item represented by the \a parent model index.
 
1875
 
 
1876
    If \a column is 0, the columns are prepended to any existing columns.
 
1877
 
 
1878
    If \a column is columnCount(), the columns are appended to any existing
 
1879
    columns.
 
1880
 
 
1881
    If \a parent has no children, a single row with \a count columns is
 
1882
    inserted.
 
1883
 
 
1884
    Returns true if the columns were successfully inserted; otherwise returns
 
1885
    false.
 
1886
 
 
1887
    The base class implementation does nothing and returns false.
 
1888
 
 
1889
    If you implement your own model, you can reimplement this function if you
 
1890
    want to support insertions. Alternatively, you can provide your own API for
 
1891
    altering the data.
 
1892
 
 
1893
    \sa insertRows(), removeColumns(), beginInsertColumns(), endInsertColumns()
1617
1894
*/
1618
1895
bool QAbstractItemModel::insertColumns(int, int, const QModelIndex &)
1619
1896
{
1622
1899
 
1623
1900
/*!
1624
1901
    On models that support this, removes \a count rows starting with the given
1625
 
    \a row under parent \a parent from the model. Returns true if the rows
1626
 
    were successfully removed; otherwise returns false.
 
1902
    \a row under parent \a parent from the model.
 
1903
 
 
1904
    Returns true if the rows were successfully removed; otherwise returns
 
1905
    false.
1627
1906
 
1628
1907
    The base class implementation does nothing and returns false.
1629
1908
 
1630
 
    If you implement your own model, you can reimplement this function
1631
 
    if you want to support removing. Alternatively, you can provide
1632
 
    you own API for altering the data.
 
1909
    If you implement your own model, you can reimplement this function if you
 
1910
    want to support removing. Alternatively, you can provide your own API for
 
1911
    altering the data.
1633
1912
 
1634
 
    \sa removeRow(), removeColumns(), insertColumns(), beginRemoveRows(), endRemoveRows()
 
1913
    \sa removeRow(), removeColumns(), insertColumns(), beginRemoveRows(),
 
1914
        endRemoveRows()
1635
1915
*/
1636
1916
bool QAbstractItemModel::removeRows(int, int, const QModelIndex &)
1637
1917
{
1640
1920
 
1641
1921
/*!
1642
1922
    On models that support this, removes \a count columns starting with the
1643
 
    given \a column under parent \a parent from the model. Returns true if the
1644
 
    columns were successfully removed; otherwise returns false.
 
1923
    given \a column under parent \a parent from the model.
 
1924
 
 
1925
    Returns true if the columns were successfully removed; otherwise returns
 
1926
    false.
1645
1927
 
1646
1928
    The base class implementation does nothing and returns false.
1647
1929
 
1648
 
    If you implement your own model, you can reimplement this function
1649
 
    if you want to support removing. Alternatively, you can provide
1650
 
    you own API for altering the data.
 
1930
    If you implement your own model, you can reimplement this function if you
 
1931
    want to support removing. Alternatively, you can provide your own API for
 
1932
    altering the data.
1651
1933
 
1652
 
    \sa removeColumn(), removeRows(), insertColumns(), beginRemoveColumns(), endRemoveColumns()
 
1934
    \sa removeColumn(), removeRows(), insertColumns(), beginRemoveColumns(),
 
1935
        endRemoveColumns()
1653
1936
*/
1654
1937
bool QAbstractItemModel::removeColumns(int, int, const QModelIndex &)
1655
1938
{
1672
1955
}
1673
1956
 
1674
1957
/*!
1675
 
    Returns true if there is more data available for \a parent; otherwise returns
1676
 
    false.
1677
 
    
 
1958
    Returns true if there is more data available for \a parent; otherwise
 
1959
    returns false.
 
1960
 
1678
1961
    The default implementation always returns false.
1679
1962
 
1680
1963
    If canFetchMore() returns true, QAbstractItemView will call fetchMore().
1691
1974
/*!
1692
1975
    Returns the item flags for the given \a index.
1693
1976
 
1694
 
    The base class implementation returns a combination of flags that
1695
 
    enables the item (\c ItemIsEnabled) and allows it to be
1696
 
    selected (\c ItemIsSelectable).
 
1977
    The base class implementation returns a combination of flags that enables
 
1978
    the item (\c ItemIsEnabled) and allows it to be selected
 
1979
    (\c ItemIsSelectable).
1697
1980
 
1698
1981
    \sa Qt::ItemFlags
1699
1982
*/
1719
2002
}
1720
2003
 
1721
2004
/*!
1722
 
  Returns a model index for the buddy of the item represented by \a index.
1723
 
  When the user wants to edit an item, the view will call this function to
1724
 
  check whether another item in the model should be edited instead, and
1725
 
  construct a delegate using the model index returned by the buddy item.
 
2005
    Returns a model index for the buddy of the item represented by \a index.
 
2006
    When the user wants to edit an item, the view will call this function to
 
2007
    check whether another item in the model should be edited instead. Then, the
 
2008
    view will construct a delegate using the model index returned by the buddy
 
2009
    item.
1726
2010
 
1727
 
  In the default implementation each item is its own buddy.
 
2011
    The default implementation of this function has each item as its own buddy.
1728
2012
*/
1729
2013
QModelIndex QAbstractItemModel::buddy(const QModelIndex &index) const
1730
2014
{
1732
2016
}
1733
2017
 
1734
2018
/*!
1735
 
    Returns a list of indexes for the items in the column of the \a
1736
 
    start index where the data stored under the given \a role matches
1737
 
    the specified \a value. The way the search is performed is defined
1738
 
    by the \a flags given. The list that is returned may be empty.
 
2019
    Returns a list of indexes for the items in the column of the \a start index
 
2020
    where data stored under the given \a role matches the specified \a value.
 
2021
    The way the search is performed is defined by the \a flags given. The list
 
2022
    that is returned may be empty.
1739
2023
 
1740
 
    The search starts from the \a start index, and continues until the
1741
 
    number of matching data items equals \a hits, the search reaches
1742
 
    the last row, or the search reaches \a start again, depending on
1743
 
    whether \c MatchWrap is specified in \a flags. If you want to search
1744
 
    for all matching items, use \a hits = -1.
 
2024
    The search begins from the \a start index, and continues until the number
 
2025
    of matching data items equals \a hits, the search reaches the last row, or
 
2026
    the search reaches \a start again - depending on whether \c MatchWrap is
 
2027
    specified in \a flags. If you want to search for all matching items, use
 
2028
    \a hits = -1.
1745
2029
 
1746
2030
    By default, this function will perform a wrapping, string-based comparison
1747
2031
    on all items, searching for items that begin with the search term specified
1748
2032
    by \a value.
1749
 
    
1750
 
    \note The default implementation of this function only searches columns,
1751
 
    This function can be reimplemented to include other search behavior.
 
2033
 
 
2034
    \note The default implementation of this function only searches columns.
 
2035
    Reimplement this function to include a different search behavior.
1752
2036
*/
1753
2037
QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role,
1754
2038
                                          const QVariant &value, int hits,
1823
2107
/*!
1824
2108
    Returns the row and column span of the item represented by \a index.
1825
2109
 
1826
 
    Note: span is not used currently, but will be in the future.
 
2110
    \note Currently, span is not used.
1827
2111
*/
1828
2112
 
1829
2113
QSize QAbstractItemModel::span(const QModelIndex &) const
1832
2116
}
1833
2117
 
1834
2118
/*!
1835
 
  Called to let the model know that it should submit whatever it has cached
1836
 
  to the permanent storage. Typically used for row editing.
1837
 
 
1838
 
  Returns false on error, otherwise true.
 
2119
    \since 4.6
 
2120
 
 
2121
    Sets the model's role names to \a roleNames.
 
2122
 
 
2123
    This function allows mapping of role identifiers to role property names in
 
2124
    Declarative UI.  This function must be called before the model is used.
 
2125
    Modifying the role names after the model has been set may result in
 
2126
    undefined behaviour.
 
2127
 
 
2128
    \sa roleNames()
 
2129
*/
 
2130
void QAbstractItemModel::setRoleNames(const QHash<int,QByteArray> &roleNames)
 
2131
{
 
2132
    Q_D(QAbstractItemModel);
 
2133
    d->roleNames = roleNames;
 
2134
}
 
2135
 
 
2136
/*!
 
2137
    \since 4.6
 
2138
 
 
2139
    Returns the model's role names.
 
2140
 
 
2141
    \sa setRoleNames()
 
2142
*/
 
2143
const QHash<int,QByteArray> &QAbstractItemModel::roleNames() const
 
2144
{
 
2145
    Q_D(const QAbstractItemModel);
 
2146
    return d->roleNames;
 
2147
}
 
2148
 
 
2149
/*!
 
2150
    Lets the model know that it should submit cached information to permanent
 
2151
    storage. This function is typically used for row editing.
 
2152
 
 
2153
    Returns true if there is no error; otherwise returns false.
 
2154
 
 
2155
    \sa revert()
1839
2156
*/
1840
2157
 
1841
2158
bool QAbstractItemModel::submit()
1844
2161
}
1845
2162
 
1846
2163
/*!
1847
 
  Called to let the model know that it should discard whatever it has cached.
1848
 
  Typically used for row editing.
 
2164
    Lets the model know that it should discard cached information. This
 
2165
    function is typically used for row editing.
 
2166
 
 
2167
    \sa submit()
1849
2168
*/
1850
2169
 
1851
2170
void QAbstractItemModel::revert()
1854
2173
}
1855
2174
 
1856
2175
/*!
1857
 
  Returns the data for the given \a role and \a section in the header
1858
 
  with the specified \a orientation.
1859
 
 
1860
 
  For horizontal headers, the section number corresponds to the column
1861
 
  number of items shown beneath it. For vertical headers, the section
1862
 
  number typically to the row number of items shown alongside it.
1863
 
 
1864
 
  \sa Qt::ItemDataRole, setHeaderData(), QHeaderView
 
2176
    Returns the data for the given \a role and \a section in the header with
 
2177
    the specified \a orientation.
 
2178
 
 
2179
    For horizontal headers, the section number corresponds to the column
 
2180
    number. Similarly, for vertical headers, the section number corresponds to
 
2181
    the row number.
 
2182
 
 
2183
    \sa Qt::ItemDataRole, setHeaderData(), QHeaderView
1865
2184
*/
1866
2185
 
1867
2186
QVariant QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role) const
1873
2192
}
1874
2193
 
1875
2194
/*!
1876
 
  Sets the data for the given \a role and \a section in the header with
1877
 
  the specified \a orientation to the \a value supplied.
1878
 
  Returns true if the header's data was updated; otherwise returns false.
1879
 
 
1880
 
  Note that the headerDataChanged() signal must be emitted explicitly
1881
 
  when reimplementing this function.
1882
 
 
1883
 
  \sa Qt::ItemDataRole, headerData()
 
2195
    Sets the data for the given \a role and \a section in the header with the
 
2196
    specified \a orientation to the \a value supplied.
 
2197
 
 
2198
    Returns true if the header's data was updated; otherwise returns false.
 
2199
 
 
2200
    When reimplementing this function, the headerDataChanged() signal must be
 
2201
    emitted explicitly.
 
2202
 
 
2203
    \sa Qt::ItemDataRole, headerData()
1884
2204
*/
1885
2205
 
1886
2206
bool QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation,
1896
2216
/*!
1897
2217
    \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, void *ptr) const
1898
2218
 
1899
 
    Creates a model index for the given \a row and \a column with the internal pointer \a ptr.
 
2219
    Creates a model index for the given \a row and \a column with the internal
 
2220
    pointer \a ptr.
1900
2221
 
1901
 
    Note that when you are using a QSortFilterProxyModel its indexes have their own
1902
 
    internal pointer.  It is not advisable to access the internal pointer in the index
1903
 
    outside of the model.  Use the data() function instead.
 
2222
    When using a QSortFilterProxyModel, its indexes have their own internal
 
2223
    pointer. It is not advisable to access this internal pointer outside of the
 
2224
    model. Use the data() function instead.
1904
2225
 
1905
2226
    This function provides a consistent interface that model subclasses must
1906
2227
    use to create model indexes.
1910
2231
    \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, int id) const
1911
2232
    \obsolete
1912
2233
 
1913
 
    Use QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) instead.
 
2234
    Use QModelIndex
 
2235
    QAbstractItemModel::createIndex(int row, int column, quint32 id) instead.
1914
2236
*/
1915
2237
 
1916
2238
/*!
1921
2243
 
1922
2244
    This function provides a consistent interface that model subclasses must
1923
2245
    use to create model indexes.
 
2246
 
1924
2247
    \sa QModelIndex::internalId()
1925
2248
*/
1926
2249
 
2024
2347
/*!
2025
2348
    Begins a row insertion operation.
2026
2349
 
2027
 
    When reimplementing insertRows() in a subclass, you must call this
2028
 
    function \e before inserting data into the model's underlying data
2029
 
    store.
 
2350
    When reimplementing insertRows() in a subclass, you must call this function
 
2351
    \e before inserting data into the model's underlying data store.
2030
2352
 
2031
 
    The \a parent index corresponds to the parent into which the new
2032
 
    rows are inserted; \a first and \a last are the row numbers that the
2033
 
    new rows will have after they have been inserted.
 
2353
    The \a parent index corresponds to the parent into which the new rows are
 
2354
    inserted; \a first and \a last are the row numbers that the new rows will
 
2355
    have after they have been inserted.
2034
2356
 
2035
2357
    \table 80%
2036
 
    \row \o \inlineimage modelview-begin-insert-rows.png Inserting rows
2037
 
    \o Specify the first and last row numbers for the span of rows
2038
 
       you want to insert into an item in a model.
2039
 
 
2040
 
    For example, as shown in the diagram, we insert three rows before
2041
 
    row 2, so \a first is 2 and \a last is 4:
2042
 
    \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 0
2043
 
    This inserts the three new rows as rows 2, 3, and 4.
2044
 
    \row
2045
 
    \o \inlineimage modelview-begin-append-rows.png Appending rows
2046
 
    \o To append rows, insert them after the last row.
2047
 
 
2048
 
    For example, as shown in the diagram, we append two rows to a
2049
 
    collection of 4 existing rows (ending in row 3), so \a first is 4
2050
 
    and \a last is 5:
2051
 
    \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 1
2052
 
    This appends the two new rows as rows 4 and 5.
 
2358
    \row
 
2359
        \o  \inlineimage modelview-begin-insert-rows.png Inserting rows
 
2360
        \o  Specify the first and last row numbers for the span of rows you
 
2361
            want to insert into an item in a model.
 
2362
 
 
2363
            For example, as shown in the diagram, we insert three rows before
 
2364
            row 2, so \a first is 2 and \a last is 4:
 
2365
 
 
2366
            \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 0
 
2367
 
 
2368
            This inserts the three new rows as rows 2, 3, and 4.
 
2369
    \row
 
2370
        \o  \inlineimage modelview-begin-append-rows.png Appending rows
 
2371
        \o  To append rows, insert them after the last row.
 
2372
 
 
2373
            For example, as shown in the diagram, we append two rows to a
 
2374
            collection of 4 existing rows (ending in row 3), so \a first is 4
 
2375
            and \a last is 5:
 
2376
 
 
2377
            \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 1
 
2378
 
 
2379
            This appends the two new rows as rows 4 and 5.
2053
2380
    \endtable
2054
2381
 
 
2382
    \note This function emits the rowsAboutToBeInserted() signal which
 
2383
    connected views (or proxies) must handle before the data is inserted.
 
2384
    Otherwise, the views may end up in an invalid state.
2055
2385
    \sa endInsertRows()
2056
2386
*/
2057
2387
void QAbstractItemModel::beginInsertRows(const QModelIndex &parent, int first, int last)
2067
2397
/*!
2068
2398
    Ends a row insertion operation.
2069
2399
 
2070
 
    When reimplementing insertRows() in a subclass, you must call this
2071
 
    function \e after inserting data into the model's underlying data
2072
 
    store.
 
2400
    When reimplementing insertRows() in a subclass, you must call this function
 
2401
    \e after inserting data into the model's underlying data store.
2073
2402
 
2074
2403
    \sa beginInsertRows()
2075
2404
*/
2085
2414
    Begins a row removal operation.
2086
2415
 
2087
2416
    When reimplementing removeRows() in a subclass, you must call this
2088
 
    function \e before removing data from the model's underlying data
2089
 
    store.
 
2417
    function \e before removing data from the model's underlying data store.
2090
2418
 
2091
 
    The \a parent index corresponds to the parent from which the new
2092
 
    rows are removed; \a first and \a last are the row numbers of the
2093
 
    rows to be removed.
 
2419
    The \a parent index corresponds to the parent from which the new rows are
 
2420
    removed; \a first and \a last are the row numbers of the rows to be
 
2421
    removed.
2094
2422
 
2095
2423
    \table 80%
2096
 
    \row \o \inlineimage modelview-begin-remove-rows.png Removing rows
2097
 
    \o Specify the first and last row numbers for the span of rows
2098
 
       you want to remove from an item in a model.
2099
 
 
2100
 
    For example, as shown in the diagram, we remove the two rows from
2101
 
    row 2 to row 3, so \a first is 2 and \a last is 3:
2102
 
    \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 2
 
2424
    \row
 
2425
        \o  \inlineimage modelview-begin-remove-rows.png Removing rows
 
2426
        \o  Specify the first and last row numbers for the span of rows you
 
2427
            want to remove from an item in a model.
 
2428
 
 
2429
            For example, as shown in the diagram, we remove the two rows from
 
2430
            row 2 to row 3, so \a first is 2 and \a last is 3:
 
2431
 
 
2432
            \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 2
2103
2433
    \endtable
2104
2434
 
 
2435
    \note This function emits the rowsAboutToBeRemoved() signal which connected
 
2436
    views (or proxies) must handle before the data is removed. Otherwise, the
 
2437
    views may end up in an invalid state.
 
2438
 
2105
2439
    \sa endRemoveRows()
2106
2440
*/
2107
2441
void QAbstractItemModel::beginRemoveRows(const QModelIndex &parent, int first, int last)
2117
2451
/*!
2118
2452
    Ends a row removal operation.
2119
2453
 
2120
 
    When reimplementing removeRows() in a subclass, you must call this
2121
 
    function \e after removing data from the model's underlying data
2122
 
    store.
 
2454
    When reimplementing removeRows() in a subclass, you must call this function
 
2455
    \e after removing data from the model's underlying data store.
2123
2456
 
2124
2457
    \sa beginRemoveRows()
2125
2458
*/
2132
2465
}
2133
2466
 
2134
2467
/*!
 
2468
    Returns whether a move operation is valid.
 
2469
 
 
2470
    A move operation is not allowed if it moves a continuous range of rows to a destination within
 
2471
    itself, or if it attempts to move a row to one of its own descendants.
 
2472
 
 
2473
    \internal
 
2474
*/
 
2475
bool QAbstractItemModelPrivate::allowMove(const QModelIndex &srcParent, int start, int end, const QModelIndex &destinationParent, int destinationStart, Qt::Orientation orientation)
 
2476
{
 
2477
    // Don't move the range within itself.
 
2478
    if ( ( destinationParent == srcParent )
 
2479
            && ( destinationStart >= start )
 
2480
            && ( destinationStart <= end + 1) )
 
2481
        return false;
 
2482
 
 
2483
    QModelIndex destinationAncestor = destinationParent;
 
2484
    int pos = (Qt::Vertical == orientation) ? destinationAncestor.row() : destinationAncestor.column();
 
2485
    forever {
 
2486
        if (destinationAncestor == srcParent) {
 
2487
            if (pos >= start && pos <= end)
 
2488
                return false;
 
2489
            break;
 
2490
        }
 
2491
 
 
2492
        if (!destinationAncestor.isValid())
 
2493
          break;
 
2494
 
 
2495
        pos = (Qt::Vertical == orientation) ? destinationAncestor.row() : destinationAncestor.column();
 
2496
        destinationAncestor = destinationAncestor.parent();
 
2497
    }
 
2498
 
 
2499
    return true;
 
2500
}
 
2501
 
 
2502
/*!
 
2503
    Begins a row move operation.
 
2504
 
 
2505
    When reimplementing a subclass, this method simplifies moving
 
2506
    entities in your model. This method is responsible for moving
 
2507
    persistent indexes in the model, which you would otherwise be
 
2508
    required to do yourself.
 
2509
 
 
2510
    Using beginMoveRows and endMoveRows is an alternative to emitting
 
2511
    layoutAboutToBeChanged and layoutChanged directly along with
 
2512
    changePersistentIndexes.  layoutAboutToBeChanged is emitted by
 
2513
    this method for compatibility reasons.
 
2514
 
 
2515
    The \a sourceParent index corresponds to the parent from which the
 
2516
    rows are moved; \a sourceFirst and \a sourceLast are the row
 
2517
    numbers of the rows to be moved. The \a destinationParent index
 
2518
    corresponds to the parent into which the rows are moved. The \a
 
2519
    destinationChild is the row to which the rows will be moved.  That
 
2520
    is, the index at row \a sourceFirst in \a sourceParent will become
 
2521
    row \a destinationChild in \a destinationParent. Its siblings will
 
2522
    be moved correspondingly.
 
2523
 
 
2524
    Note that \a sourceParent and \a destinationParent may be the
 
2525
    same, in which case you must ensure that the \a destinationChild is
 
2526
    not within the range of \a sourceFirst and \a sourceLast.  You
 
2527
    must also ensure that you do not attempt to move a row to one of
 
2528
    its own chilren or ancestors.  This method returns false if either
 
2529
    condition is true, in which case you should abort your move
 
2530
    operation.
 
2531
 
 
2532
    \sa endMoveRows()
 
2533
 
 
2534
    \since 4.6
 
2535
*/
 
2536
bool QAbstractItemModel::beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild)
 
2537
{
 
2538
    Q_ASSERT(sourceFirst >= 0);
 
2539
    Q_ASSERT(sourceLast >= sourceFirst);
 
2540
    Q_ASSERT(destinationChild >= 0);
 
2541
    Q_D(QAbstractItemModel);
 
2542
 
 
2543
    if (!d->allowMove(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Vertical)) {
 
2544
        return false;
 
2545
    }
 
2546
 
 
2547
    d->changes.push(QAbstractItemModelPrivate::Change(sourceParent, sourceFirst, sourceLast));
 
2548
    int destinationLast = destinationChild + (sourceLast - sourceFirst);
 
2549
    d->changes.push(QAbstractItemModelPrivate::Change(destinationParent, destinationChild, destinationLast));
 
2550
 
 
2551
    d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Vertical);
 
2552
    emit rowsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild);
 
2553
    emit layoutAboutToBeChanged();
 
2554
    return true;
 
2555
}
 
2556
 
 
2557
/*!
 
2558
    Ends a row move operation.
 
2559
 
 
2560
    When implementing a subclass, you must call this
 
2561
    function \e after moving data within the model's underlying data
 
2562
    store.
 
2563
 
 
2564
    layoutChanged is emitted by this method for compatibility reasons.
 
2565
 
 
2566
    \sa beginMoveRows()
 
2567
 
 
2568
    \since 4.6
 
2569
*/
 
2570
void QAbstractItemModel::endMoveRows()
 
2571
{
 
2572
    Q_D(QAbstractItemModel);
 
2573
 
 
2574
    QAbstractItemModelPrivate::Change insertChange = d->changes.pop();
 
2575
    QAbstractItemModelPrivate::Change removeChange = d->changes.pop();
 
2576
 
 
2577
    d->itemsMoved(removeChange.parent, removeChange.first, removeChange.last, insertChange.parent, insertChange.first, Qt::Vertical);
 
2578
 
 
2579
    emit rowsMoved(removeChange.parent, removeChange.first, removeChange.last, insertChange.parent, insertChange.first);
 
2580
    emit layoutChanged();
 
2581
}
 
2582
 
 
2583
/*!
2135
2584
    Begins a column insertion operation.
2136
2585
 
2137
2586
    When reimplementing insertColumns() in a subclass, you must call this
2138
 
    function \e before inserting data into the model's underlying data
2139
 
    store.
 
2587
    function \e before inserting data into the model's underlying data store.
2140
2588
 
2141
 
    The \a parent index corresponds to the parent into which the new
2142
 
    columns are inserted; \a first and \a last are the column numbers of
2143
 
    the new columns will have after they have been inserted.
 
2589
    The \a parent index corresponds to the parent into which the new columns
 
2590
    are inserted; \a first and \a last are the column numbers of the new
 
2591
    columns will have after they have been inserted.
2144
2592
 
2145
2593
    \table 80%
2146
 
    \row \o \inlineimage modelview-begin-insert-columns.png Inserting columns
2147
 
    \o Specify the first and last column numbers for the span of columns
2148
 
       you want to insert into an item in a model.
2149
 
 
2150
 
    For example, as shown in the diagram, we insert three columns before
2151
 
    column 4, so \a first is 4 and \a last is 6:
2152
 
    \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 3
2153
 
    This inserts the three new columns as columns 4, 5, and 6.
2154
 
    \row
2155
 
    \o \inlineimage modelview-begin-append-columns.png Appending columns
2156
 
    \o To append columns, insert them after the last column.
2157
 
 
2158
 
    For example, as shown in the diagram, we append three columns to a
2159
 
    collection of six existing columns (ending in column 5), so \a first
2160
 
    is 6 and \a last is 8:
2161
 
    \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 4
2162
 
    This appends the two new columns as columns 6, 7, and 8.
 
2594
    \row
 
2595
        \o  \inlineimage modelview-begin-insert-columns.png Inserting columns
 
2596
        \o  Specify the first and last column numbers for the span of columns
 
2597
            you want to insert into an item in a model.
 
2598
 
 
2599
            For example, as shown in the diagram, we insert three columns
 
2600
            before column 4, so \a first is 4 and \a last is 6:
 
2601
 
 
2602
            \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 3
 
2603
 
 
2604
            This inserts the three new columns as columns 4, 5, and 6.
 
2605
    \row
 
2606
        \o  \inlineimage modelview-begin-append-columns.png Appending columns
 
2607
        \o  To append columns, insert them after the last column.
 
2608
 
 
2609
            For example, as shown in the diagram, we append three columns to a
 
2610
            collection of six existing columns (ending in column 5), so
 
2611
            \a first is 6 and \a last is 8:
 
2612
 
 
2613
            \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 4
 
2614
 
 
2615
            This appends the two new columns as columns 6, 7, and 8.
2163
2616
    \endtable
2164
2617
 
 
2618
    \note This function emits the columnsAboutToBeInserted() signal which
 
2619
    connected views (or proxies) must handle before the data is inserted.
 
2620
    Otherwise, the views may end up in an invalid state.
 
2621
 
2165
2622
    \sa endInsertColumns()
2166
2623
*/
2167
2624
void QAbstractItemModel::beginInsertColumns(const QModelIndex &parent, int first, int last)
2195
2652
    Begins a column removal operation.
2196
2653
 
2197
2654
    When reimplementing removeColumns() in a subclass, you must call this
2198
 
    function \e before removing data from the model's underlying data
2199
 
    store.
 
2655
    function \e before removing data from the model's underlying data store.
2200
2656
 
2201
 
    The \a parent index corresponds to the parent from which the new
2202
 
    columns are removed; \a first and \a last are the column numbers of
2203
 
    the first and last columns to be removed.
 
2657
    The \a parent index corresponds to the parent from which the new columns
 
2658
    are removed; \a first and \a last are the column numbers of the first and
 
2659
    last columns to be removed.
2204
2660
 
2205
2661
    \table 80%
2206
 
    \row \o \inlineimage modelview-begin-remove-columns.png Removing columns
2207
 
    \o Specify the first and last column numbers for the span of columns
2208
 
       you want to remove from an item in a model.
2209
 
 
2210
 
    For example, as shown in the diagram, we remove the three columns
2211
 
    from column 4 to column 6, so \a first is 4 and \a last is 6:
2212
 
    \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 5
 
2662
    \row
 
2663
        \o  \inlineimage modelview-begin-remove-columns.png Removing columns
 
2664
        \o  Specify the first and last column numbers for the span of columns
 
2665
            you want to remove from an item in a model.
 
2666
 
 
2667
            For example, as shown in the diagram, we remove the three columns
 
2668
            from column 4 to column 6, so \a first is 4 and \a last is 6:
 
2669
 
 
2670
            \snippet doc/src/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp 5
2213
2671
    \endtable
2214
2672
 
 
2673
    \note This function emits the columnsAboutToBeRemoved() signal which
 
2674
    connected views (or proxies) must handle before the data is removed.
 
2675
    Otherwise, the views may end up in an invalid state.
 
2676
 
2215
2677
    \sa endRemoveColumns()
2216
2678
*/
2217
2679
void QAbstractItemModel::beginRemoveColumns(const QModelIndex &parent, int first, int last)
2228
2690
    Ends a column removal operation.
2229
2691
 
2230
2692
    When reimplementing removeColumns() in a subclass, you must call this
2231
 
    function \e after removing data from the model's underlying data
2232
 
    store.
 
2693
    function \e after removing data from the model's underlying data store.
2233
2694
 
2234
2695
    \sa beginRemoveColumns()
2235
2696
*/
2242
2703
}
2243
2704
 
2244
2705
/*!
 
2706
    Begins a column move operation.
 
2707
 
 
2708
    When reimplementing a subclass, this method simplifies moving
 
2709
    entities in your model. This method is responsible for moving
 
2710
    persistent indexes in the model, which you would otherwise be
 
2711
    required to do yourself.
 
2712
 
 
2713
    Using beginMoveColumns and endMoveColumns is an alternative to
 
2714
    emitting layoutAboutToBeChanged and layoutChanged directly along
 
2715
    with changePersistentIndexes.  layoutAboutToBeChanged is emitted
 
2716
    by this method for compatibility reasons.
 
2717
 
 
2718
    The \a sourceParent index corresponds to the parent from which the
 
2719
    columns are moved; \a sourceFirst and \a sourceLast are the column
 
2720
    numbers of the columns to be moved. The \a destinationParent index
 
2721
    corresponds to the parent into which the columns are moved. The \a
 
2722
    destinationChild is the column to which the columns will be
 
2723
    moved.  That is, the index at column \a sourceFirst in \a
 
2724
    sourceParent will become column \a destinationChild in \a
 
2725
    destinationParent. Its siblings will be moved correspondingly.
 
2726
 
 
2727
    Note that \a sourceParent and \a destinationParent may be the
 
2728
    same, in which case you must ensure that the \a destinationChild
 
2729
    is not within the range of \a sourceFirst and \a sourceLast.  You
 
2730
    must also ensure that you do not attempt to move a row to one of
 
2731
    its own chilren or ancestors.  This method returns false if either
 
2732
    condition is true, in which case you should abort your move
 
2733
    operation.
 
2734
 
 
2735
    \sa endMoveColumns()
 
2736
 
 
2737
    \since 4.6
 
2738
*/
 
2739
bool QAbstractItemModel::beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild)
 
2740
{
 
2741
    Q_ASSERT(sourceFirst >= 0);
 
2742
    Q_ASSERT(sourceLast >= sourceFirst);
 
2743
    Q_ASSERT(destinationChild >= 0);
 
2744
    Q_D(QAbstractItemModel);
 
2745
 
 
2746
    if (!d->allowMove(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal)) {
 
2747
        return false;
 
2748
    }
 
2749
 
 
2750
    d->changes.push(QAbstractItemModelPrivate::Change(sourceParent, sourceFirst, sourceLast));
 
2751
    int destinationLast = destinationChild + (sourceLast - sourceFirst);
 
2752
    d->changes.push(QAbstractItemModelPrivate::Change(destinationParent, destinationChild, destinationLast));
 
2753
 
 
2754
    d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal);
 
2755
 
 
2756
    emit columnsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild);
 
2757
    emit layoutAboutToBeChanged();
 
2758
    return true;
 
2759
}
 
2760
 
 
2761
/*!
 
2762
    Ends a column move operation.
 
2763
 
 
2764
    When implementing a subclass, you must call this
 
2765
    function \e after moving data within the model's underlying data
 
2766
    store.
 
2767
 
 
2768
    layoutChanged is emitted by this method for compatibility reasons.
 
2769
 
 
2770
    \sa beginMoveColumns()
 
2771
 
 
2772
    \since 4.6
 
2773
*/
 
2774
void QAbstractItemModel::endMoveColumns()
 
2775
{
 
2776
    Q_D(QAbstractItemModel);
 
2777
 
 
2778
    QAbstractItemModelPrivate::Change insertChange = d->changes.pop();
 
2779
    QAbstractItemModelPrivate::Change removeChange = d->changes.pop();
 
2780
 
 
2781
    d->itemsMoved(removeChange.parent, removeChange.first, removeChange.last, insertChange.parent, insertChange.first, Qt::Horizontal);
 
2782
 
 
2783
    emit columnsMoved(removeChange.parent, removeChange.first, removeChange.last, insertChange.parent, insertChange.first);
 
2784
    emit layoutChanged();
 
2785
}
 
2786
 
 
2787
/*!
2245
2788
    Resets the model to its original state in any attached views.
2246
2789
 
2247
 
    \note The view to which the model is attached to will be reset as well.
 
2790
    \note Use beginResetModel() and endResetModel() instead whenever possible.
 
2791
    Use this method only if there is no way to call beginResetModel() before invalidating the model.
 
2792
    Otherwise it could lead to unexcpected behaviour, especially when used with proxy models.
 
2793
*/
 
2794
void QAbstractItemModel::reset()
 
2795
{
 
2796
    Q_D(QAbstractItemModel);
 
2797
    emit modelAboutToBeReset();
 
2798
    d->invalidatePersistentIndexes();
 
2799
    emit modelReset();
 
2800
}
 
2801
 
 
2802
/*!
 
2803
    Begins a model reset operation.
 
2804
 
 
2805
    A reset operation resets the model to its current state in any attached views.
 
2806
 
 
2807
    \note Any views attached to this model will be reset as well.
2248
2808
 
2249
2809
    When a model is reset it means that any previous data reported from the
2250
 
    model is now invalid and has to be queried for again.
 
2810
    model is now invalid and has to be queried for again. This also means that
 
2811
    the current item and any selected items will become invalid.
2251
2812
 
2252
2813
    When a model radically changes its data it can sometimes be easier to just
2253
2814
    call this function rather than emit dataChanged() to inform other
2254
2815
    components when the underlying data source, or its structure, has changed.
2255
2816
 
2256
 
    \sa modelAboutToBeReset(), modelReset()
2257
 
*/
2258
 
void QAbstractItemModel::reset()
 
2817
    You must call this function before resetting any internal data structures in your model
 
2818
    or proxy model.
 
2819
 
 
2820
    \sa modelAboutToBeReset(), modelReset(), endResetModel()
 
2821
    \since 4.6
 
2822
*/
 
2823
void QAbstractItemModel::beginResetModel()
 
2824
{
 
2825
    emit modelAboutToBeReset();
 
2826
}
 
2827
 
 
2828
/*!
 
2829
    Completes a model reset operation.
 
2830
 
 
2831
    You must call this function after resetting any internal data structure in your model
 
2832
    or proxy model.
 
2833
 
 
2834
    \sa beginResetModel()
 
2835
    \since 4.6
 
2836
*/
 
2837
void QAbstractItemModel::endResetModel()
2259
2838
{
2260
2839
    Q_D(QAbstractItemModel);
2261
 
    emit modelAboutToBeReset();
2262
2840
    d->invalidatePersistentIndexes();
2263
2841
    emit modelReset();
2264
2842
}
2265
2843
 
2266
2844
/*!
2267
 
  Changes the QPersistentModelIndex that is equal to the given \a from
2268
 
  model index to the given \a to model index.
2269
 
 
2270
 
  If no persistent model index equal to the given \a from model index was
2271
 
  found, nothing is changed.
2272
 
 
2273
 
  \sa persistentIndexList(), changePersistentIndexList()
 
2845
    Changes the QPersistentModelIndex that is equal to the given \a from model
 
2846
    index to the given \a to model index.
 
2847
 
 
2848
    If no persistent model index equal to the given \a from model index was
 
2849
    found, nothing is changed.
 
2850
 
 
2851
    \sa persistentIndexList(), changePersistentIndexList()
2274
2852
*/
2275
2853
void QAbstractItemModel::changePersistentIndex(const QModelIndex &from, const QModelIndex &to)
2276
2854
{
2291
2869
}
2292
2870
 
2293
2871
/*!
2294
 
  \since 4.1
2295
 
 
2296
 
  Changes the QPersistentModelIndexes that is equal to the indexes in the given \a from
2297
 
  model index list to the given \a to model index list.
2298
 
 
2299
 
  If no persistent model indexes equal to the indexes in the given \a from model index list
2300
 
  was found, nothing is changed.
2301
 
 
2302
 
  \sa persistentIndexList(), changePersistentIndex()
 
2872
    \since 4.1
 
2873
 
 
2874
    Changes the QPersistentModelIndexes that is equal to the indexes in the
 
2875
    given \a from model index list to the given \a to model index list.
 
2876
 
 
2877
    If no persistent model indexes equal to the indexes in the given \a from
 
2878
    model index list was found, nothing is changed.
 
2879
 
 
2880
    \sa persistentIndexList(), changePersistentIndex()
2303
2881
*/
2304
2882
void QAbstractItemModel::changePersistentIndexList(const QModelIndexList &from,
2305
2883
                                                   const QModelIndexList &to)
2332
2910
}
2333
2911
 
2334
2912
/*!
2335
 
  \since 4.2
 
2913
    \since 4.2
2336
2914
 
2337
 
  Returns the list of indexes stored as persistent indexes in the model.
 
2915
    Returns the list of indexes stored as persistent indexes in the model.
2338
2916
*/
2339
2917
QModelIndexList QAbstractItemModel::persistentIndexList() const
2340
2918
{
2361
2939
    but must be subclassed.
2362
2940
 
2363
2941
    Since the model provides a more specialized interface than
2364
 
    QAbstractItemModel, it is not suitable for use with tree views, although
2365
 
    it can be used to provide data to a QListView. If you need to represent
2366
 
    a simple list of items, and only need a model to contain a single column
2367
 
    of data, subclassing the QAbstractListModel may be more appropriate.
 
2942
    QAbstractItemModel, it is not suitable for use with tree views, although it
 
2943
    can be used to provide data to a QListView. If you need to represent a
 
2944
    simple list of items, and only need a model to contain a single column of
 
2945
    data, subclassing the QAbstractListModel may be more appropriate.
2368
2946
 
2369
2947
    The rowCount() and columnCount() functions return the dimensions of the
2370
2948
    table. To retrieve a model index corresponding to an item in the model, use
2372
2950
 
2373
2951
    \section1 Subclassing
2374
2952
 
2375
 
    \bold{Note:} Some general guidelines for subclassing models are
2376
 
    available in the \l{Model Subclassing Reference}.
2377
 
 
2378
2953
    When subclassing QAbstractTableModel, you must implement rowCount(),
2379
2954
    columnCount(), and data(). Default implementations of the index() and
2380
2955
    parent() functions are provided by QAbstractTableModel.
2405
2980
       call endRemoveColumns() \e{immediately afterwards}.
2406
2981
    \endlist
2407
2982
 
2408
 
    \sa {Model Classes}, {Model Subclassing Reference}, QAbstractItemModel,
2409
 
        QAbstractListModel,
2410
 
        {Pixelator Example}
 
2983
    \note Some general guidelines for subclassing models are available in the
 
2984
    \l{Model Subclassing Reference}.
 
2985
 
 
2986
    \note
 
2987
 
 
2988
    \sa {Model Classes}, QAbstractItemModel, QAbstractListModel,
 
2989
    {Pixelator Example}
2411
2990
*/
2412
2991
 
2413
2992
/*!
2505
3084
 
2506
3085
    \section1 Subclassing
2507
3086
 
2508
 
    \bold{Note:} Some general guidelines for subclassing models are
2509
 
    available in the \l{Model Subclassing Reference}.
2510
 
 
2511
3087
    When subclassing QAbstractListModel, you must provide implementations
2512
3088
    of the rowCount() and data() functions. Well behaved models also provide
2513
3089
    a headerData() implementation.
2534
3110
       call endRemoveRows() \e{immediately afterwards}.
2535
3111
    \endlist
2536
3112
 
 
3113
    \note Some general guidelines for subclassing models are available in the
 
3114
    \l{Model Subclassing Reference}.
 
3115
 
2537
3116
    \sa {Model Classes}, {Model Subclassing Reference}, QAbstractItemView,
2538
3117
        QAbstractTableModel, {Item Views Puzzle Example}
2539
3118
*/
2729
3308
    This signal is emitted when reset() is called, before the model's internal
2730
3309
    state (e.g. persistent model indexes) has been invalidated.
2731
3310
 
2732
 
    \sa reset(), modelReset()
 
3311
    \sa beginResetModel(), modelReset()
2733
3312
*/
2734
3313
 
2735
3314
/*!
2739
3318
    This signal is emitted when reset() is called, after the model's internal
2740
3319
    state (e.g. persistent model indexes) has been invalidated.
2741
3320
 
2742
 
    \sa reset(), modelAboutToBeReset()
 
3321
    \sa endResetModel(), modelAboutToBeReset()
2743
3322
*/
2744
3323
 
2745
3324
/*!