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

« back to all changes in this revision

Viewing changes to src/gui/itemviews/qlistwidget.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 QtGui 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
****************************************************************************/
447
447
 
448
448
    \ingroup model-view
449
449
 
450
 
    QListWidgetItem is used to represent items in a list provided by the
451
 
    QListWidget class. Each item can hold several pieces of information,
452
 
    and will display these appropriately.
453
 
 
454
 
    The item view convenience classes use a classic item-based interface
455
 
    rather than a pure model/view approach. For a more flexible list view
456
 
    widget, consider using the QListView class with a standard model.
457
 
 
458
 
    List items can be automatically inserted into a list when they are
459
 
    constructed by specifying the list widget:
 
450
    A QListWidgetItem represents a single item in a QListWidget. Each item can
 
451
    hold several pieces of information, and will display them appropriately.
 
452
 
 
453
    The item view convenience classes use a classic item-based interface rather
 
454
    than a pure model/view approach. For a more flexible list view widget,
 
455
    consider using the QListView class with a standard model.
 
456
 
 
457
    List items can be inserted automatically into a list, when they are
 
458
    constructed, by specifying the list widget:
460
459
 
461
460
    \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 2
462
461
 
463
 
    They can also be created without a parent widget, and later inserted into
464
 
    a list (see \l{QListWidget::insertItem()}).
 
462
    Alternatively, list items can also be created without a parent widget, and
 
463
    later inserted into a list using QListWidget::insertItem().
465
464
 
466
465
    List items are typically used to display text() and an icon(). These are
467
466
    set with the setText() and setIcon() functions. The appearance of the text
471
470
    with setToolTip(), setStatusTip(), and setWhatsThis().
472
471
 
473
472
    By default, items are enabled, selectable, checkable, and can be the source
474
 
    of a drag and drop operation.
 
473
    of drag and drop operations.
 
474
 
475
475
    Each item's flags can be changed by calling setFlags() with the appropriate
476
 
    value (see \l{Qt::ItemFlags}). Checkable items can be checked, unchecked and
 
476
    value (see Qt::ItemFlags). Checkable items can be checked, unchecked and
477
477
    partially checked with the setCheckState() function. The corresponding
478
 
    checkState() function indicates what check state the item currently has.
479
 
 
480
 
    The isHidden() function can be used to determine whether the
481
 
    item is hidden.  Items can be hidden with setHidden().
 
478
    checkState() function indicates the item's current check state.
 
479
 
 
480
    The isHidden() function can be used to determine whether the item is
 
481
    hidden. To hide an item, use setHidden().
 
482
 
482
483
 
483
484
    \section1 Subclassing
484
485
 
485
486
    When subclassing QListWidgetItem to provide custom items, it is possible to
486
 
    define new types for them so that they can be distinguished from standard
487
 
    items. The constructors for subclasses that require this feature need to
488
 
    call the base class constructor with a new type value equal to or greater
489
 
    than \l UserType.
 
487
    define new types for them enabling them to be distinguished from standard
 
488
    items. For subclasses that require this feature, ensure that you call the
 
489
    base class constructor with a new type value equal to or greater than
 
490
    \l UserType, within \e your constructor.
490
491
 
491
492
    \sa QListWidget, {Model/View Programming}, QTreeWidgetItem, QTableWidgetItem
492
493
*/
515
516
/*!
516
517
    \fn QListWidget *QListWidgetItem::listWidget() const
517
518
 
518
 
    Returns the list widget that contains the item.
519
 
*/
520
 
 
521
 
/*!
522
 
  \fn void QListWidgetItem::setSelected(bool select)
523
 
  \since 4.2
524
 
 
525
 
  Sets the selected state of the item to \a select.
526
 
 
527
 
  \sa isSelected()
528
 
*/
529
 
 
530
 
/*!
531
 
  \fn bool QListWidgetItem::isSelected() const
532
 
  \since 4.2
533
 
 
534
 
  Returns true if the item is selected, otherwise returns false.
535
 
 
536
 
  \sa setSelected()
537
 
*/
538
 
 
539
 
/*!
540
 
  \fn void QListWidgetItem::setHidden(bool hide)
541
 
  \since 4.2
542
 
 
543
 
  Hides the item if \a hide is true, otherwise shows the item.
544
 
 
545
 
  \sa isHidden()
546
 
*/
547
 
 
548
 
/*!
549
 
  \fn bool QListWidgetItem::isHidden() const
550
 
  \since 4.2
551
 
 
552
 
  Returns true if the item is hidden, otherwise returns false.
553
 
 
554
 
  \sa setHidden()
 
519
    Returns the list widget containing the item.
 
520
*/
 
521
 
 
522
/*!
 
523
    \fn void QListWidgetItem::setSelected(bool select)
 
524
    \since 4.2
 
525
 
 
526
    Sets the selected state of the item to \a select.
 
527
 
 
528
    \sa isSelected()
 
529
*/
 
530
 
 
531
/*!
 
532
    \fn bool QListWidgetItem::isSelected() const
 
533
    \since 4.2
 
534
 
 
535
    Returns true if the item is selected; otherwise returns false.
 
536
 
 
537
    \sa setSelected()
 
538
*/
 
539
 
 
540
/*!
 
541
    \fn void QListWidgetItem::setHidden(bool hide)
 
542
    \since 4.2
 
543
 
 
544
    Hides the item if \a hide is true; otherwise shows the item.
 
545
 
 
546
    \sa isHidden()
 
547
*/
 
548
 
 
549
/*!
 
550
    \fn bool QListWidgetItem::isHidden() const
 
551
    \since 4.2
 
552
 
 
553
    Returns true if the item is hidden; otherwise returns false.
 
554
 
 
555
    \sa setHidden()
555
556
*/
556
557
 
557
558
/*!
558
559
    \fn QListWidgetItem::QListWidgetItem(QListWidget *parent, int type)
559
560
 
560
561
    Constructs an empty list widget item of the specified \a type with the
561
 
    given \a parent.
562
 
    If the parent is not specified, the item will need to be inserted into a
563
 
    list widget with QListWidget::insertItem().
 
562
    given \a parent. If \a parent is not specified, the item will need to be
 
563
    inserted into a list widget with QListWidget::insertItem().
 
564
 
 
565
    This constructor inserts the item into the model of the parent that is
 
566
    passed to the constructor. If the model is sorted then the behavior of the
 
567
    insert is undetermined since the model will call the \c '<' operator method
 
568
    on the item which, at this point, is not yet constructed. To avoid the
 
569
    undetermined behavior, we recommend not to specify the parent and use
 
570
    QListWidget::insertItem() instead.
564
571
 
565
572
    \sa type()
566
573
*/
579
586
    \fn QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *parent, int type)
580
587
 
581
588
    Constructs an empty list widget item of the specified \a type with the
582
 
    given \a text and \a parent.
583
 
    If the parent is not specified, the item will need to be inserted into a
584
 
    list widget with QListWidget::insertItem().
 
589
    given \a text and \a parent. If the parent is not specified, the item will
 
590
    need to be inserted into a list widget with QListWidget::insertItem().
 
591
 
 
592
    This constructor inserts the item into the model of the parent that is
 
593
    passed to the constructor. If the model is sorted then the behavior of the
 
594
    insert is undetermined since the model will call the \c '<' operator method
 
595
    on the item which, at this point, is not yet constructed. To avoid the
 
596
    undetermined behavior, we recommend not to specify the parent and use
 
597
    QListWidget::insertItem() instead.
585
598
 
586
599
    \sa type()
587
600
*/
602
615
    \fn QListWidgetItem::QListWidgetItem(const QIcon &icon, const QString &text, QListWidget *parent, int type)
603
616
 
604
617
    Constructs an empty list widget item of the specified \a type with the
605
 
    given \a icon, \a text and \a parent.
606
 
    If the parent is not specified, the item will need to be inserted into a
607
 
    list widget with QListWidget::insertItem().
 
618
    given \a icon, \a text and \a parent. If the parent is not specified, the
 
619
    item will need to be inserted into a list widget with
 
620
    QListWidget::insertItem().
 
621
 
 
622
    This constructor inserts the item into the model of the parent that is
 
623
    passed to the constructor. If the model is sorted then the behavior of the
 
624
    insert is undetermined since the model will call the \c '<' operator method
 
625
    on the item which, at this point, is not yet constructed. To avoid the
 
626
    undetermined behavior, we recommend not to specify the parent and use
 
627
    QListWidget::insertItem() instead.
608
628
 
609
629
    \sa type()
610
630
*/
624
644
}
625
645
 
626
646
/*!
627
 
  Destroys the list item.
 
647
    Destroys the list item.
628
648
*/
629
649
QListWidgetItem::~QListWidgetItem()
630
650
{
634
654
}
635
655
 
636
656
/*!
637
 
  Creates an exact copy of the item.
 
657
    Creates an exact copy of the item.
638
658
*/
639
659
QListWidgetItem *QListWidgetItem::clone() const
640
660
{
642
662
}
643
663
 
644
664
/*!
645
 
  This function sets the data for a given \a role to the given \a value (see
646
 
  \l{Qt::ItemDataRole}). Reimplement this function if you need
647
 
  extra roles or special behavior for certain roles.
 
665
    Sets the data for a given \a role to the given \a value. Reimplement this
 
666
    function if you need extra roles or special behavior for certain roles.
648
667
 
649
 
  \sa Qt::ItemDataRole, data()
 
668
    \sa Qt::ItemDataRole, data()
650
669
*/
651
670
void QListWidgetItem::setData(int role, const QVariant &value)
652
671
{
668
687
}
669
688
 
670
689
/*!
671
 
   This function returns the item's data for a given \a role (see
672
 
   Qt::ItemDataRole). Reimplement this function if you need
673
 
   extra roles or special behavior for certain roles.
 
690
    Returns the item's data for a given \a role. Reimplement this function if
 
691
    you need extra roles or special behavior for certain roles.
 
692
 
 
693
    \sa Qt::ItemDataRole, setData()
674
694
*/
675
695
QVariant QListWidgetItem::data(int role) const
676
696
{
682
702
}
683
703
 
684
704
/*!
685
 
  Returns true if this item's text is less then \a other item's text;
686
 
  otherwise returns false.
 
705
    Returns true if this item's text is less then \a other item's text;
 
706
    otherwise returns false.
687
707
*/
688
708
bool QListWidgetItem::operator<(const QListWidgetItem &other) const
689
709
{
690
 
    return text() < other.text();
 
710
    const QVariant v1 = data(Qt::DisplayRole), v2 = other.data(Qt::DisplayRole);
 
711
    return QAbstractItemModelPrivate::variantLessThan(v1, v2);
691
712
}
692
713
 
693
714
#ifndef QT_NO_DATASTREAM
711
732
{
712
733
    out << d->values;
713
734
}
 
735
#endif // QT_NO_DATASTREAM
714
736
 
715
737
/*!
716
738
    \since 4.1
717
739
 
718
 
    Constructs a copy of \a other. Note that type() and listWidget()
719
 
    are not copied.
 
740
    Constructs a copy of \a other. Note that type() and listWidget() are not
 
741
    copied.
720
742
 
721
743
    This function is useful when reimplementing clone().
722
744
 
731
753
}
732
754
 
733
755
/*!
734
 
    Assigns \a other's data and flags to this item. Note that type()
735
 
    and listWidget() are not copied.
 
756
    Assigns \a other's data and flags to this item. Note that type() and
 
757
    listWidget() are not copied.
736
758
 
737
759
    This function is useful when reimplementing clone().
738
760
 
745
767
    return *this;
746
768
}
747
769
 
 
770
#ifndef QT_NO_DATASTREAM
 
771
 
748
772
/*!
749
773
    \relates QListWidgetItem
750
774
 
778
802
#endif // QT_NO_DATASTREAM
779
803
 
780
804
/*!
781
 
  \fn Qt::ItemFlags QListWidgetItem::flags() const
 
805
    \fn Qt::ItemFlags QListWidgetItem::flags() const
782
806
 
783
 
  Returns the item flags for this item (see \l{Qt::ItemFlags}).
 
807
    Returns the item flags for this item (see \l{Qt::ItemFlags}).
784
808
*/
785
809
 
786
810
/*!
824
848
*/
825
849
 
826
850
/*!
827
 
  \fn QFont QListWidgetItem::font() const
 
851
    \fn QFont QListWidgetItem::font() const
828
852
 
829
 
  Returns the font used to display this list item's text.
 
853
    Returns the font used to display this list item's text.
830
854
*/
831
855
 
832
856
/*!
833
 
  \fn int QListWidgetItem::textAlignment() const
834
 
 
835
 
  Returns the text alignment for the list item (see \l{Qt::AlignmentFlag}).
 
857
    \fn int QListWidgetItem::textAlignment() const
 
858
 
 
859
    Returns the text alignment for the list item.
 
860
 
 
861
    \sa Qt::AlignmentFlag
836
862
*/
837
863
 
838
864
/*!
878
904
*/
879
905
 
880
906
/*!
881
 
  \fn QSize QListWidgetItem::sizeHint() const
882
 
  \since 4.1
883
 
 
884
 
  Returns the size hint set for the list item.
885
 
*/
886
 
 
887
 
/*!
888
 
  \fn void QListWidgetItem::setSizeHint(const QSize &size)
889
 
  \since 4.1
890
 
 
891
 
  Sets the size hint for the list item to be \a size.
892
 
  If no size hint is set, the item delegate will compute the
893
 
  size hint based on the item data.
894
 
*/
895
 
 
896
 
/*!
897
 
  \fn void QListWidgetItem::setFlags(Qt::ItemFlags flags)
898
 
 
899
 
  Sets the item flags for the list item to \a flags (see
900
 
  \l{Qt::ItemFlags}).
 
907
    \fn QSize QListWidgetItem::sizeHint() const
 
908
    \since 4.1
 
909
 
 
910
    Returns the size hint set for the list item.
 
911
*/
 
912
 
 
913
/*!
 
914
    \fn void QListWidgetItem::setSizeHint(const QSize &size)
 
915
    \since 4.1
 
916
 
 
917
    Sets the size hint for the list item to be \a size. If no size hint is set,
 
918
    the item delegate will compute the size hint based on the item data.
 
919
*/
 
920
 
 
921
/*!
 
922
    \fn void QListWidgetItem::setFlags(Qt::ItemFlags flags)
 
923
 
 
924
    Sets the item flags for the list item to \a flags.
 
925
 
 
926
    \sa Qt::ItemFlags
901
927
*/
902
928
void QListWidgetItem::setFlags(Qt::ItemFlags aflags) {
903
929
    itemFlags = aflags;
926
952
    \fn void QListWidgetItem::setStatusTip(const QString &statusTip)
927
953
 
928
954
    Sets the status tip for the list item to the text specified by
929
 
    \a statusTip. QListWidget mouse tracking needs to be enabled for this
 
955
    \a statusTip. QListWidget mouseTracking needs to be enabled for this
930
956
    feature to work.
931
957
 
932
 
    \sa statusTip() setToolTip() setWhatsThis()
 
958
    \sa statusTip(), setToolTip(), setWhatsThis(), QWidget::setMouseTracking()
933
959
*/
934
960
 
935
961
/*!
937
963
 
938
964
    Sets the tooltip for the list item to the text specified by \a toolTip.
939
965
 
940
 
    \sa toolTip() setStatusTip() setWhatsThis()
 
966
    \sa toolTip(), setStatusTip(), setWhatsThis()
941
967
*/
942
968
 
943
969
/*!
944
970
    \fn void QListWidgetItem::setWhatsThis(const QString &whatsThis)
945
971
 
946
 
    Sets the "What's This?" help for the list item to the text specified
947
 
    by \a whatsThis.
948
 
 
949
 
    \sa whatsThis() setStatusTip() setToolTip()
950
 
*/
951
 
 
952
 
/*!
953
 
  \fn void QListWidgetItem::setFont(const QFont &font)
954
 
 
955
 
  Sets the font used when painting the item to the given \a font.
956
 
*/
957
 
 
958
 
/*!
959
 
  \fn void QListWidgetItem::setTextAlignment(int alignment)
960
 
 
961
 
  Sets the list item's text alignment to \a alignment (see
962
 
  \l{Qt::AlignmentFlag}).
 
972
    Sets the "What's This?" help for the list item to the text specified by
 
973
    \a whatsThis.
 
974
 
 
975
    \sa whatsThis(), setStatusTip(), setToolTip()
 
976
*/
 
977
 
 
978
/*!
 
979
    \fn void QListWidgetItem::setFont(const QFont &font)
 
980
 
 
981
    Sets the font used when painting the item to the given \a font.
 
982
*/
 
983
 
 
984
/*!
 
985
    \fn void QListWidgetItem::setTextAlignment(int alignment)
 
986
 
 
987
    Sets the list item's text alignment to \a alignment.
 
988
 
 
989
    \sa Qt::AlignmentFlag
963
990
*/
964
991
 
965
992
/*!
1014
1041
    QObject::connect(q, SIGNAL(activated(QModelIndex)),
1015
1042
                     q, SLOT(_q_emitItemActivated(QModelIndex)));
1016
1043
    QObject::connect(q, SIGNAL(entered(QModelIndex)), q, SLOT(_q_emitItemEntered(QModelIndex)));
1017
 
    QObject::connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
 
1044
    QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
1018
1045
                     q, SLOT(_q_emitItemChanged(QModelIndex)));
1019
1046
    QObject::connect(q->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
1020
1047
                     q, SLOT(_q_emitCurrentItemChanged(QModelIndex,QModelIndex)));
1021
1048
    QObject::connect(q->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
1022
1049
                     q, SIGNAL(itemSelectionChanged()));
1023
 
    QObject::connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
 
1050
    QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
1024
1051
                     q, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));
1025
 
    QObject::connect(model(), SIGNAL(columnsRemoved(QModelIndex,int,int)), q, SLOT(_q_sort()));
 
1052
    QObject::connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), q, SLOT(_q_sort()));
1026
1053
}
1027
1054
 
1028
1055
void QListWidgetPrivate::_q_emitItemPressed(const QModelIndex &index)
1029
1056
{
1030
1057
    Q_Q(QListWidget);
1031
 
    emit q->itemPressed(model()->at(index.row()));
 
1058
    emit q->itemPressed(listModel()->at(index.row()));
1032
1059
}
1033
1060
 
1034
1061
void QListWidgetPrivate::_q_emitItemClicked(const QModelIndex &index)
1035
1062
{
1036
1063
    Q_Q(QListWidget);
1037
 
    emit q->itemClicked(model()->at(index.row()));
 
1064
    emit q->itemClicked(listModel()->at(index.row()));
1038
1065
}
1039
1066
 
1040
1067
void QListWidgetPrivate::_q_emitItemDoubleClicked(const QModelIndex &index)
1041
1068
{
1042
1069
    Q_Q(QListWidget);
1043
 
    emit q->itemDoubleClicked(model()->at(index.row()));
 
1070
    emit q->itemDoubleClicked(listModel()->at(index.row()));
1044
1071
}
1045
1072
 
1046
1073
void QListWidgetPrivate::_q_emitItemActivated(const QModelIndex &index)
1047
1074
{
1048
1075
    Q_Q(QListWidget);
1049
 
    emit q->itemActivated(model()->at(index.row()));
 
1076
    emit q->itemActivated(listModel()->at(index.row()));
1050
1077
}
1051
1078
 
1052
1079
void QListWidgetPrivate::_q_emitItemEntered(const QModelIndex &index)
1053
1080
{
1054
1081
    Q_Q(QListWidget);
1055
 
    emit q->itemEntered(model()->at(index.row()));
 
1082
    emit q->itemEntered(listModel()->at(index.row()));
1056
1083
}
1057
1084
 
1058
1085
void QListWidgetPrivate::_q_emitItemChanged(const QModelIndex &index)
1059
1086
{
1060
1087
    Q_Q(QListWidget);
1061
 
    emit q->itemChanged(model()->at(index.row()));
 
1088
    emit q->itemChanged(listModel()->at(index.row()));
1062
1089
}
1063
1090
 
1064
1091
void QListWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex &current,
1066
1093
{
1067
1094
    Q_Q(QListWidget);
1068
1095
    QPersistentModelIndex persistentCurrent = current;
1069
 
    QListWidgetItem *currentItem = model()->at(persistentCurrent.row());
1070
 
    emit q->currentItemChanged(currentItem, model()->at(previous.row()));
 
1096
    QListWidgetItem *currentItem = listModel()->at(persistentCurrent.row());
 
1097
    emit q->currentItemChanged(currentItem, listModel()->at(previous.row()));
1071
1098
 
1072
1099
    //persistentCurrent is invalid if something changed the model in response
1073
1100
    //to the currentItemChanged signal emission and the item was removed
1082
1109
void QListWidgetPrivate::_q_sort()
1083
1110
{
1084
1111
    if (sortingEnabled)
1085
 
        model()->sort(0, sortOrder);
 
1112
        model->sort(0, sortOrder);
1086
1113
}
1087
1114
 
1088
1115
void QListWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft,
1089
1116
                                        const QModelIndex &bottomRight)
1090
1117
{
1091
1118
    if (sortingEnabled && topLeft.isValid() && bottomRight.isValid())
1092
 
        model()->ensureSorted(topLeft.column(), sortOrder,
 
1119
        listModel()->ensureSorted(topLeft.column(), sortOrder,
1093
1120
                              topLeft.row(), bottomRight.row());
1094
1121
}
1095
1122
 
1098
1125
    \brief The QListWidget class provides an item-based list widget.
1099
1126
 
1100
1127
    \ingroup model-view
1101
 
    \mainclass
1102
 
 
1103
 
    QListWidget is a convenience class that provides a list view similar to
1104
 
    the one supplied by QListView, but with a classic item-based interface
1105
 
    for adding and removing items. QListWidget uses an internal model to
1106
 
    manage each QListWidgetItem in the list.
 
1128
 
 
1129
 
 
1130
    QListWidget is a convenience class that provides a list view similar to the
 
1131
    one supplied by QListView, but with a classic item-based interface for
 
1132
    adding and removing items. QListWidget uses an internal model to manage
 
1133
    each QListWidgetItem in the list.
1107
1134
 
1108
1135
    For a more flexible list view widget, use the QListView class with a
1109
1136
    standard model.
1118
1145
    function.
1119
1146
 
1120
1147
    There are two ways to add items to the list: they can be constructed with
1121
 
    the list widget as their parent widget, or they can be constructed with
1122
 
    no parent widget and added to the list later. If a list widget already
1123
 
    exists when the items are constructed, the first method is easier to use:
 
1148
    the list widget as their parent widget, or they can be constructed with no
 
1149
    parent widget and added to the list later. If a list widget already exists
 
1150
    when the items are constructed, the first method is easier to use:
1124
1151
 
1125
1152
    \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 1
1126
1153
 
1127
 
    If you need to insert a new item into the list at a particular position,
1128
 
    it is more required to construct the item without a parent widget and
1129
 
    use the insertItem() function to place it within the list.  The list
1130
 
    widget will take ownership of the item.
 
1154
    If you need to insert a new item into the list at a particular position, it
 
1155
    is more required to construct the item without a parent widget and use the
 
1156
    insertItem() function to place it within the list. The list widget will
 
1157
    take ownership of the item.
1131
1158
 
1132
1159
    \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 6
1133
1160
    \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 7
1134
1161
 
1135
 
    For multiple items, insertItems() can be used instead. The number of
1136
 
    items in the list is found with the count() function.
1137
 
    To remove items from the list, use takeItem().
 
1162
    For multiple items, insertItems() can be used instead. The number of items
 
1163
    in the list is found with the count() function. To remove items from the
 
1164
    list, use takeItem().
1138
1165
 
1139
1166
    The current item in the list can be found with currentItem(), and changed
1140
1167
    with setCurrentItem(). The user can also change the current item by
1160
1187
 
1161
1188
    Inserts the \a item at the end of the list widget.
1162
1189
 
1163
 
    \warning A QListWidgetItem can only be added to a
1164
 
    QListWidget once. Adding the same QListWidgetItem multiple
1165
 
    times to a QListWidget will result in undefined behavior.
 
1190
    \warning A QListWidgetItem can only be added to a QListWidget once. Adding
 
1191
    the same QListWidgetItem multiple times to a QListWidget will result in
 
1192
    undefined behavior.
1166
1193
 
1167
1194
    \sa insertItem()
1168
1195
*/
1170
1197
/*!
1171
1198
    \fn void QListWidget::addItem(const QString &label)
1172
1199
 
1173
 
    Inserts an item with the text \a label at the end of the list
1174
 
    widget.
 
1200
    Inserts an item with the text \a label at the end of the list widget.
1175
1201
*/
1176
1202
 
1177
1203
/*!
1185
1211
/*!
1186
1212
    \fn void QListWidget::itemPressed(QListWidgetItem *item)
1187
1213
 
1188
 
    This signal is emitted with the specified \a item when a mouse button is pressed
1189
 
    on an item in the widget.
 
1214
    This signal is emitted with the specified \a item when a mouse button is
 
1215
    pressed on an item in the widget.
1190
1216
 
1191
1217
    \sa itemClicked(), itemDoubleClicked()
1192
1218
*/
1194
1220
/*!
1195
1221
    \fn void QListWidget::itemClicked(QListWidgetItem *item)
1196
1222
 
1197
 
    This signal is emitted with the specified \a item when a mouse button is clicked
1198
 
    on an item in the widget.
 
1223
    This signal is emitted with the specified \a item when a mouse button is
 
1224
    clicked on an item in the widget.
1199
1225
 
1200
1226
    \sa itemPressed(), itemDoubleClicked()
1201
1227
*/
1203
1229
/*!
1204
1230
    \fn void QListWidget::itemDoubleClicked(QListWidgetItem *item)
1205
1231
 
1206
 
    This signal is emitted with the specified \a item when a mouse button is double
1207
 
    clicked on an item in the widget.
 
1232
    This signal is emitted with the specified \a item when a mouse button is
 
1233
    double clicked on an item in the widget.
1208
1234
 
1209
1235
    \sa itemClicked(), itemPressed()
1210
1236
*/
1212
1238
/*!
1213
1239
    \fn void QListWidget::itemActivated(QListWidgetItem *item)
1214
1240
 
1215
 
    This signal is emitted when the \a item is activated. The \a item
1216
 
    is activated when the user clicks or double clicks on it,
1217
 
    depending on the system configuration. It is also activated when
1218
 
    the user presses the activation key (on Windows and X11 this is
1219
 
    the \gui Return key, on Mac OS X it is \key{Ctrl+0}).
 
1241
    This signal is emitted when the \a item is activated. The \a item is
 
1242
    activated when the user clicks or double clicks on it, depending on the
 
1243
    system configuration. It is also activated when the user presses the
 
1244
    activation key (on Windows and X11 this is the \gui Return key, on Mac OS
 
1245
    X it is \key{Ctrl+0}).
1220
1246
*/
1221
1247
 
1222
1248
/*!
1223
1249
    \fn void QListWidget::itemEntered(QListWidgetItem *item)
1224
1250
 
1225
 
    This signal is emitted when the mouse cursor enters an item. The
1226
 
    \a item is the item entered. This signal is only emitted when
1227
 
    mouseTracking is turned on, or when a mouse button is pressed
1228
 
    while moving into an item.
 
1251
    This signal is emitted when the mouse cursor enters an item. The \a item is
 
1252
    the item entered. This signal is only emitted when mouseTracking is turned
 
1253
    on, or when a mouse button is pressed while moving into an item.
 
1254
 
 
1255
    \sa QWidget::setMouseTracking()
1229
1256
*/
1230
1257
 
1231
1258
/*!
1237
1264
/*!
1238
1265
    \fn void QListWidget::currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
1239
1266
 
1240
 
    This signal is emitted whenever the current item changes. The \a
1241
 
    previous item is the item that previously had the focus, \a
1242
 
    current is the new current item.
1243
 
*/
1244
 
 
1245
 
/*!
1246
 
  \fn void QListWidget::currentTextChanged(const QString &currentText)
1247
 
 
1248
 
  This signal is emitted whenever the current item changes. The \a currentText
1249
 
  is the text data in the current item. If there is no current item, the \a currentText
1250
 
  is invalid.
1251
 
*/
1252
 
 
1253
 
/*!
1254
 
  \fn void QListWidget::currentRowChanged(int currentRow)
1255
 
 
1256
 
  This signal is emitted whenever the current item changes. The \a currentRow
1257
 
  is the row of the current item. If there is no current item, the \a currentRow is -1.
 
1267
    This signal is emitted whenever the current item changes.
 
1268
 
 
1269
    \a previous is the item that previously had the focus; \a current is the
 
1270
    new current item.
 
1271
*/
 
1272
 
 
1273
/*!
 
1274
    \fn void QListWidget::currentTextChanged(const QString &currentText)
 
1275
 
 
1276
    This signal is emitted whenever the current item changes.
 
1277
 
 
1278
    \a currentText is the text data in the current item. If there is no current
 
1279
    item, the \a currentText is invalid.
 
1280
*/
 
1281
 
 
1282
/*!
 
1283
    \fn void QListWidget::currentRowChanged(int currentRow)
 
1284
 
 
1285
    This signal is emitted whenever the current item changes.
 
1286
 
 
1287
    \a currentRow is the row of the current item. If there is no current item,
 
1288
    the \a currentRow is -1.
1258
1289
*/
1259
1290
 
1260
1291
/*!
1262
1293
 
1263
1294
    This signal is emitted whenever the selection changes.
1264
1295
 
1265
 
    \sa selectedItems() isItemSelected() currentItemChanged()
 
1296
    \sa selectedItems(), QListWidgetItem::isSelected(), currentItemChanged()
1266
1297
*/
1267
1298
 
1268
1299
/*!
1269
 
  \since 4.3
1270
 
 
1271
 
  \fn void QListWidget::removeItemWidget(QListWidgetItem *item)
1272
 
 
1273
 
  Removes the widget set on the given \a item.
 
1300
    \since 4.3
 
1301
 
 
1302
    \fn void QListWidget::removeItemWidget(QListWidgetItem *item)
 
1303
 
 
1304
    Removes the widget set on the given \a item.
1274
1305
*/
1275
1306
 
1276
1307
/*!
1302
1333
QListWidgetItem *QListWidget::item(int row) const
1303
1334
{
1304
1335
    Q_D(const QListWidget);
1305
 
    if (row < 0 || row >= d->model()->rowCount())
 
1336
    if (row < 0 || row >= d->model->rowCount())
1306
1337
        return 0;
1307
 
    return d->model()->at(row);
 
1338
    return d->listModel()->at(row);
1308
1339
}
1309
1340
 
1310
1341
/*!
1316
1347
int QListWidget::row(const QListWidgetItem *item) const
1317
1348
{
1318
1349
    Q_D(const QListWidget);
1319
 
    return d->model()->index(const_cast<QListWidgetItem*>(item)).row();
 
1350
    return d->listModel()->index(const_cast<QListWidgetItem*>(item)).row();
1320
1351
}
1321
1352
 
1322
1353
 
1330
1361
{
1331
1362
    Q_D(QListWidget);
1332
1363
    if (item && !item->view)
1333
 
        d->model()->insert(row, item);
 
1364
        d->listModel()->insert(row, item);
1334
1365
}
1335
1366
 
1336
1367
/*!
1337
 
    Inserts an item with the text \a label in the list widget at the
1338
 
    position given by \a row.
 
1368
    Inserts an item with the text \a label in the list widget at the position
 
1369
    given by \a row.
1339
1370
 
1340
1371
    \sa addItem()
1341
1372
*/
1343
1374
void QListWidget::insertItem(int row, const QString &label)
1344
1375
{
1345
1376
    Q_D(QListWidget);
1346
 
    d->model()->insert(row, new QListWidgetItem(label));
 
1377
    d->listModel()->insert(row, new QListWidgetItem(label));
1347
1378
}
1348
1379
 
1349
1380
/*!
1356
1387
void QListWidget::insertItems(int row, const QStringList &labels)
1357
1388
{
1358
1389
    Q_D(QListWidget);
1359
 
    d->model()->insert(row, labels);
 
1390
    d->listModel()->insert(row, labels);
1360
1391
}
1361
1392
 
1362
1393
/*!
1363
 
    Removes and returns the item from the given \a row in the list widget; otherwise
1364
 
    returns 0.
 
1394
    Removes and returns the item from the given \a row in the list widget;
 
1395
    otherwise returns 0.
1365
1396
 
1366
 
    Items removed from a list widget will not be managed by Qt, and will need to be
1367
 
    deleted manually.
 
1397
    Items removed from a list widget will not be managed by Qt, and will need
 
1398
    to be deleted manually.
1368
1399
 
1369
1400
    \sa insertItem(), addItem()
1370
1401
*/
1372
1403
QListWidgetItem *QListWidget::takeItem(int row)
1373
1404
{
1374
1405
    Q_D(QListWidget);
1375
 
    if (row < 0 || row >= d->model()->rowCount())
 
1406
    if (row < 0 || row >= d->model->rowCount())
1376
1407
        return 0;
1377
 
    return d->model()->take(row);
 
1408
    return d->listModel()->take(row);
1378
1409
}
1379
1410
 
1380
1411
/*!
1381
 
  \property QListWidget::count
1382
 
  \brief the number of items in the list including any hidden items.
 
1412
    \property QListWidget::count
 
1413
    \brief the number of items in the list including any hidden items.
1383
1414
*/
1384
1415
 
1385
1416
int QListWidget::count() const
1386
1417
{
1387
1418
    Q_D(const QListWidget);
1388
 
    return d->model()->rowCount();
 
1419
    return d->model->rowCount();
1389
1420
}
1390
1421
 
1391
1422
/*!
1392
 
  Returns the current item.
 
1423
    Returns the current item.
1393
1424
*/
1394
1425
QListWidgetItem *QListWidget::currentItem() const
1395
1426
{
1396
1427
    Q_D(const QListWidget);
1397
 
    return d->model()->at(currentIndex().row());
 
1428
    return d->listModel()->at(currentIndex().row());
1398
1429
}
1399
1430
 
1400
1431
 
1401
1432
/*!
1402
 
  Sets the current item to \a item.
 
1433
    Sets the current item to \a item.
1403
1434
 
1404
 
  Depending on the current selection mode, the item may also be selected.
 
1435
    Unless the selection mode is \l{QAbstractItemView::}{NoSelection},
 
1436
    the item is also be selected.
1405
1437
*/
1406
1438
void QListWidget::setCurrentItem(QListWidgetItem *item)
1407
1439
{
1409
1441
}
1410
1442
 
1411
1443
/*!
1412
 
  \since 4.4
1413
 
  Set the current item to \a item, using the given \a command.
 
1444
    \since 4.4
 
1445
    Set the current item to \a item, using the given \a command.
1414
1446
*/
1415
1447
void QListWidget::setCurrentItem(QListWidgetItem *item, QItemSelectionModel::SelectionFlags command)
1416
1448
{
1418
1450
}
1419
1451
 
1420
1452
/*!
1421
 
  \property QListWidget::currentRow
1422
 
  \brief the row of the current item.
 
1453
    \property QListWidget::currentRow
 
1454
    \brief the row of the current item.
1423
1455
 
1424
 
  Depending on the current selection mode, the row may also be selected.
 
1456
    Depending on the current selection mode, the row may also be selected.
1425
1457
*/
1426
1458
 
1427
1459
int QListWidget::currentRow() const
1432
1464
void QListWidget::setCurrentRow(int row)
1433
1465
{
1434
1466
    Q_D(QListWidget);
1435
 
    QModelIndex index = d->model()->index(row);
 
1467
    QModelIndex index = d->listModel()->index(row);
1436
1468
    if (d->selectionMode == SingleSelection)
1437
1469
        selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
1438
1470
    else if (d->selectionMode == NoSelection)
1442
1474
}
1443
1475
 
1444
1476
/*!
1445
 
  \since 4.4
 
1477
    \since 4.4
1446
1478
 
1447
 
  Sets the current row to be the given \a row, using the given \a command,
 
1479
    Sets the current row to be the given \a row, using the given \a command,
1448
1480
*/
1449
1481
void QListWidget::setCurrentRow(int row, QItemSelectionModel::SelectionFlags command)
1450
1482
{
1451
1483
    Q_D(QListWidget);
1452
 
    d->selectionModel->setCurrentIndex(d->model()->index(row), command);
 
1484
    d->selectionModel->setCurrentIndex(d->listModel()->index(row), command);
1453
1485
}
1454
1486
 
1455
1487
/*!
1458
1490
QListWidgetItem *QListWidget::itemAt(const QPoint &p) const
1459
1491
{
1460
1492
    Q_D(const QListWidget);
1461
 
    return d->model()->at(indexAt(p).row());
 
1493
    return d->listModel()->at(indexAt(p).row());
1462
1494
 
1463
1495
}
1464
1496
 
1471
1503
 
1472
1504
 
1473
1505
/*!
1474
 
  Returns the rectangle on the viewport occupied by the item at \a item.
 
1506
    Returns the rectangle on the viewport occupied by the item at \a item.
1475
1507
*/
1476
1508
QRect QListWidget::visualItemRect(const QListWidgetItem *item) const
1477
1509
{
1478
1510
    Q_D(const QListWidget);
1479
 
    QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item));
 
1511
    QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
1480
1512
    return visualRect(index);
1481
1513
}
1482
1514
 
1483
1515
/*!
1484
 
  Sorts all the items in the list widget according to the specified \a order.
 
1516
    Sorts all the items in the list widget according to the specified \a order.
1485
1517
*/
1486
1518
void QListWidget::sortItems(Qt::SortOrder order)
1487
1519
{
1488
1520
    Q_D(QListWidget);
1489
1521
    d->sortOrder = order;
1490
 
    d->model()->sort(0, order);
 
1522
    d->listModel()->sort(0, order);
1491
1523
}
1492
1524
 
1493
1525
/*!
1495
1527
    \property QListWidget::sortingEnabled
1496
1528
    \brief whether sorting is enabled
1497
1529
 
1498
 
    If this property is true, sorting is enabled for the list; if the
1499
 
    property is false, sorting is not enabled. The default value is false.
 
1530
    If this property is true, sorting is enabled for the list; if the property
 
1531
    is false, sorting is not enabled.
 
1532
 
 
1533
    The default value is false.
1500
1534
*/
1501
1535
void QListWidget::setSortingEnabled(bool enable)
1502
1536
{
1511
1545
}
1512
1546
 
1513
1547
/*!
1514
 
  \internal
 
1548
    \internal
1515
1549
*/
1516
1550
Qt::SortOrder QListWidget::sortOrder() const
1517
1551
{
1520
1554
}
1521
1555
 
1522
1556
/*!
1523
 
  Starts editing the \a item if it is editable.
 
1557
    Starts editing the \a item if it is editable.
1524
1558
*/
1525
1559
 
1526
1560
void QListWidget::editItem(QListWidgetItem *item)
1527
1561
{
1528
1562
    Q_D(QListWidget);
1529
 
    edit(d->model()->index(item));
 
1563
    edit(d->listModel()->index(item));
1530
1564
}
1531
1565
 
1532
1566
/*!
1533
 
  Opens an editor for the given \a item. The editor remains open after editing.
 
1567
    Opens an editor for the given \a item. The editor remains open after
 
1568
    editing.
1534
1569
 
1535
 
  \sa closePersistentEditor()
 
1570
    \sa closePersistentEditor()
1536
1571
*/
1537
1572
void QListWidget::openPersistentEditor(QListWidgetItem *item)
1538
1573
{
1539
1574
    Q_D(QListWidget);
1540
 
    QModelIndex index = d->model()->index(item);
 
1575
    QModelIndex index = d->listModel()->index(item);
1541
1576
    QAbstractItemView::openPersistentEditor(index);
1542
1577
}
1543
1578
 
1544
1579
/*!
1545
 
  Closes the persistent editor for the given \a item.
 
1580
    Closes the persistent editor for the given \a item.
1546
1581
 
1547
 
  \sa openPersistentEditor()
 
1582
    \sa openPersistentEditor()
1548
1583
*/
1549
1584
void QListWidget::closePersistentEditor(QListWidgetItem *item)
1550
1585
{
1551
1586
    Q_D(QListWidget);
1552
 
    QModelIndex index = d->model()->index(item);
 
1587
    QModelIndex index = d->listModel()->index(item);
1553
1588
    QAbstractItemView::closePersistentEditor(index);
1554
1589
}
1555
1590
 
1561
1596
QWidget *QListWidget::itemWidget(QListWidgetItem *item) const
1562
1597
{
1563
1598
    Q_D(const QListWidget);
1564
 
    QModelIndex index = d->model()->index(item);
 
1599
    QModelIndex index = d->listModel()->index(item);
1565
1600
    return QAbstractItemView::indexWidget(index);
1566
1601
}
1567
1602
 
1570
1605
 
1571
1606
    Sets the \a widget to be displayed in the give \a item.
1572
1607
 
1573
 
    This function should only be used to display static content in the place of a list
1574
 
    widget item. If you want to display custom dynamic content or implement a custom
1575
 
    editor widget, use QListView and subclass QItemDelegate instead.
 
1608
    This function should only be used to display static content in the place of
 
1609
    a list widget item. If you want to display custom dynamic content or
 
1610
    implement a custom editor widget, use QListView and subclass QItemDelegate
 
1611
    instead.
1576
1612
 
1577
1613
    \sa {Delegate Classes}
1578
1614
*/
1579
1615
void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget)
1580
1616
{
1581
1617
    Q_D(QListWidget);
1582
 
    QModelIndex index = d->model()->index(item);
 
1618
    QModelIndex index = d->listModel()->index(item);
1583
1619
    QAbstractItemView::setIndexWidget(index, widget);
1584
1620
}
1585
1621
 
1586
1622
/*!
1587
 
  Returns true if \a item is selected; otherwise returns false.
1588
 
 
1589
 
  \obsolete
1590
 
 
1591
 
  This function is deprecated. Use \l{QListWidgetItem::isSelected()} instead.
 
1623
    Returns true if \a item is selected; otherwise returns false.
 
1624
 
 
1625
    \obsolete
 
1626
 
 
1627
    This function is deprecated. Use QListWidgetItem::isSelected() instead.
1592
1628
*/
1593
1629
bool QListWidget::isItemSelected(const QListWidgetItem *item) const
1594
1630
{
1595
1631
    Q_D(const QListWidget);
1596
 
    QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item));
 
1632
    QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
1597
1633
    return selectionModel()->isSelected(index);
1598
1634
}
1599
1635
 
1600
1636
/*!
1601
 
  Selects or deselects the given \a item depending on whether \a select is
1602
 
  true of false.
1603
 
 
1604
 
  \obsolete
1605
 
 
1606
 
  This function is deprecated. Use \l{QListWidgetItem::setSelected()} instead.
 
1637
    Selects or deselects the given \a item depending on whether \a select is
 
1638
    true of false.
 
1639
 
 
1640
    \obsolete
 
1641
 
 
1642
    This function is deprecated. Use QListWidgetItem::setSelected() instead.
1607
1643
*/
1608
1644
void QListWidget::setItemSelected(const QListWidgetItem *item, bool select)
1609
1645
{
1610
1646
    Q_D(QListWidget);
1611
 
    QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item));
 
1647
    QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
1612
1648
 
1613
1649
    if (d->selectionMode == SingleSelection) {
1614
1650
        selectionModel()->select(index, select
1623
1659
}
1624
1660
 
1625
1661
/*!
1626
 
  Returns a list of all selected items in the list widget.
 
1662
    Returns a list of all selected items in the list widget.
1627
1663
*/
1628
1664
 
1629
1665
QList<QListWidgetItem*> QListWidget::selectedItems() const
1632
1668
    QModelIndexList indexes = selectionModel()->selectedIndexes();
1633
1669
    QList<QListWidgetItem*> items;
1634
1670
    for (int i = 0; i < indexes.count(); ++i)
1635
 
        items.append(d->model()->at(indexes.at(i).row()));
 
1671
        items.append(d->listModel()->at(indexes.at(i).row()));
1636
1672
    return items;
1637
1673
}
1638
1674
 
1639
1675
/*!
1640
 
  Finds items with the text that matches the string \a text using the given \a flags.
 
1676
    Finds items with the text that matches the string \a text using the given
 
1677
    \a flags.
1641
1678
*/
1642
1679
 
1643
1680
QList<QListWidgetItem*> QListWidget::findItems(const QString &text, Qt::MatchFlags flags) const
1644
1681
{
1645
1682
    Q_D(const QListWidget);
1646
 
    QModelIndexList indexes = d->model()->match(model()->index(0, 0, QModelIndex()),
 
1683
    QModelIndexList indexes = d->listModel()->match(model()->index(0, 0, QModelIndex()),
1647
1684
                                                Qt::DisplayRole, text, -1, flags);
1648
1685
    QList<QListWidgetItem*> items;
1649
1686
    for (int i = 0; i < indexes.size(); ++i)
1650
 
        items.append(d->model()->at(indexes.at(i).row()));
 
1687
        items.append(d->listModel()->at(indexes.at(i).row()));
1651
1688
    return items;
1652
1689
}
1653
1690
 
1654
1691
/*!
1655
 
  Returns true if the \a item is explicitly hidden; otherwise returns false.
1656
 
 
1657
 
  \obsolete
1658
 
 
1659
 
  This function is deprecated. Use \l{QListWidgetItem::isHidden()} instead.
 
1692
    Returns true if the \a item is explicitly hidden; otherwise returns false.
 
1693
 
 
1694
    \obsolete
 
1695
 
 
1696
    This function is deprecated. Use QListWidgetItem::isHidden() instead.
1660
1697
*/
1661
1698
bool QListWidget::isItemHidden(const QListWidgetItem *item) const
1662
1699
{
1664
1701
}
1665
1702
 
1666
1703
/*!
1667
 
  If \a hide is true, the \a item will be hidden; otherwise it will be shown.
1668
 
 
1669
 
  \obsolete
1670
 
 
1671
 
  This function is deprecated. Use \l{QListWidgetItem::setHidden()} instead.
 
1704
    If \a hide is true, the \a item will be hidden; otherwise it will be shown.
 
1705
 
 
1706
    \obsolete
 
1707
 
 
1708
    This function is deprecated. Use QListWidgetItem::setHidden() instead.
1672
1709
*/
1673
1710
void QListWidget::setItemHidden(const QListWidgetItem *item, bool hide)
1674
1711
{
1676
1713
}
1677
1714
 
1678
1715
/*!
1679
 
    Scrolls the view if necessary to ensure that the \a item is
1680
 
    visible. The \a hint parameter specifies more precisely where the
1681
 
    \a item should be located after the operation.
 
1716
    Scrolls the view if necessary to ensure that the \a item is visible.
 
1717
 
 
1718
    \a hint specifies where the \a item should be located after the operation.
1682
1719
*/
1683
1720
 
1684
1721
void QListWidget::scrollToItem(const QListWidgetItem *item, QAbstractItemView::ScrollHint hint)
1685
1722
{
1686
1723
    Q_D(QListWidget);
1687
 
    QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item));
 
1724
    QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
1688
1725
    QListView::scrollTo(index, hint);
1689
1726
}
1690
1727
 
1691
1728
/*!
1692
1729
    Removes all items and selections in the view.
1693
1730
 
1694
 
    \note All items will be permanently deleted.
 
1731
    \warning All items will be permanently deleted.
1695
1732
*/
1696
1733
void QListWidget::clear()
1697
1734
{
1698
1735
    Q_D(QListWidget);
1699
1736
    selectionModel()->clear();
1700
 
    d->model()->clear();
 
1737
    d->listModel()->clear();
1701
1738
}
1702
1739
 
1703
1740
/*!
1708
1745
*/
1709
1746
QStringList QListWidget::mimeTypes() const
1710
1747
{
1711
 
    return d_func()->model()->QAbstractListModel::mimeTypes();
 
1748
    return d_func()->listModel()->QAbstractListModel::mimeTypes();
1712
1749
}
1713
1750
 
1714
1751
/*!
1716
1753
    \a items. The format used to describe the items is obtained from the
1717
1754
    mimeTypes() function.
1718
1755
 
1719
 
    If the list of items is empty, 0 is returned rather than a serialized
1720
 
    empty list.
 
1756
    If the list of items is empty, 0 is returned instead of a serialized empty
 
1757
    list.
1721
1758
*/
1722
1759
QMimeData *QListWidget::mimeData(const QList<QListWidgetItem*>) const
1723
1760
{
1724
 
    return d_func()->model()->internalMimeData();
 
1761
    return d_func()->listModel()->internalMimeData();
1725
1762
}
1726
1763
 
1727
1764
#ifndef QT_NO_DRAGANDDROP
1728
1765
/*!
1729
 
    Handles the \a data supplied by an external drag and drop operation
1730
 
    that ended with the given \a action in the given \a index.
1731
 
    Returns true if the data and action can be handled by the model;
1732
 
    otherwise returns false.
 
1766
    Handles \a data supplied by an external drag and drop operation that ended
 
1767
    with the given \a action in the given \a index. Returns true if \a data and
 
1768
    \a action can be handled by the model; otherwise returns false.
1733
1769
 
1734
1770
    \sa supportedDropActions()
1735
1771
*/
1744
1780
        row = -1;
1745
1781
        column = -1;
1746
1782
    }
1747
 
    return d_func()->model()->QAbstractListModel::dropMimeData(data, action , row, column, idx);
 
1783
    return d_func()->listModel()->QAbstractListModel::dropMimeData(data, action , row, column, idx);
1748
1784
}
1749
1785
 
1750
1786
/*! \reimp */
1796
1832
}
1797
1833
 
1798
1834
/*!
1799
 
  Returns the drop actions supported by this view.
 
1835
    Returns the drop actions supported by this view.
1800
1836
 
1801
 
  \sa Qt::DropActions
 
1837
    \sa Qt::DropActions
1802
1838
*/
1803
1839
Qt::DropActions QListWidget::supportedDropActions() const
1804
1840
{
1805
1841
    Q_D(const QListWidget);
1806
 
    return d->model()->QAbstractListModel::supportedDropActions() | Qt::MoveAction;
 
1842
    return d->listModel()->QAbstractListModel::supportedDropActions() | Qt::MoveAction;
1807
1843
}
1808
1844
#endif // QT_NO_DRAGANDDROP
1809
1845
 
1810
1846
/*!
1811
 
  Returns a list of pointers to the items contained in the \a data object.
1812
 
  If the object was not created by a QListWidget in the same process, the list
1813
 
  is empty.
 
1847
    Returns a list of pointers to the items contained in the \a data object. If
 
1848
    the object was not created by a QListWidget in the same process, the list
 
1849
    is empty.
1814
1850
*/
1815
1851
QList<QListWidgetItem*> QListWidget::items(const QMimeData *data) const
1816
1852
{
1821
1857
}
1822
1858
 
1823
1859
/*!
1824
 
  Returns the QModelIndex assocated with the given \a item.
 
1860
    Returns the QModelIndex assocated with the given \a item.
1825
1861
*/
1826
1862
 
1827
1863
QModelIndex QListWidget::indexFromItem(QListWidgetItem *item) const
1828
1864
{
1829
1865
    Q_D(const QListWidget);
1830
 
    return d->model()->index(item);
 
1866
    return d->listModel()->index(item);
1831
1867
}
1832
1868
 
1833
1869
/*!
1834
 
  Returns a pointer to the QListWidgetItem assocated with the given \a index.
 
1870
    Returns a pointer to the QListWidgetItem assocated with the given \a index.
1835
1871
*/
1836
1872
 
1837
1873
QListWidgetItem *QListWidget::itemFromIndex(const QModelIndex &index) const
1838
1874
{
1839
1875
    Q_D(const QListWidget);
1840
1876
    if (d->isIndexValid(index))
1841
 
        return d->model()->at(index.row());
 
1877
        return d->listModel()->at(index.row());
1842
1878
    return 0;
1843
1879
}
1844
1880
 
1845
1881
/*!
1846
 
  \internal
 
1882
    \internal
1847
1883
*/
1848
1884
void QListWidget::setModel(QAbstractItemModel * /*model*/)
1849
1885
{