QT6 源(144)模型视图架构里的视图总基类 QAbstractItemView 篇五:本基类视图的源代码,带注释。

(18)本源代码来自于头文件 qabstractitemview . h

#ifndef QABSTRACTITEMVIEW_H
#define QABSTRACTITEMVIEW_H

#include <QtWidgets/qtwidgetsglobal.h>
#include <QtWidgets/qabstractscrollarea.h>
#include <QtCore/qabstractitemmodel.h>
#include <QtCore/qitemselectionmodel.h>
#include <QtWidgets/qabstractitemdelegate.h>

class tst_QAbstractItemView;
class tst_QTreeView;

QT_REQUIRE_CONFIG(itemviews);

QT_BEGIN_NAMESPACE

class QMenu;
class QDrag;
class QEvent;
class QAbstractItemViewPrivate;

/*
The QAbstractItemView class provides the basic functionality for item view classes.

Detailed Description  :

QAbstractltemView 类是使用 QAbstractltemModel的每个标准视图的基类。
OAbstractltemView是一个抽象类,本身不能实例化。
它提供了一个标准接口,用于通过signals 和 slots 机制与模型进行互作,
    使 subclasses 能够随着模型的更改而保持最新状态。
此类为键盘和鼠标导航、视区滚动、项目编辑和选择提供标准支持。
QAbstractItemView class is the base class for every standard view that uses a
    QAbstractItemModel.
QAbstractItemView is an abstract class and cannot itself be instantiated.
It provides a standard interface for interoperating with models through the
    signals and slots mechanism,
    enabling subclasses to be kept up-to-date with changes to their models.
This class provides standard support for keyboard and mouse navigation,
    viewport scrolling, item editing, and selections.
The keyboard navigation implements this functionality: 键盘导航实现此功能 :此处的表格略。

请注意,上表假定选择模式允许这些操作。
例如,如果选择模式为 QAbstractltemView::NoSelection,则无法选择项目。
Note that the above table assumes that the selection mode allows the operations.
For instance, you cannot select items if the
    selection mode is QAbstractItemView::NoSelection.

QAbstractltemView类是模型/视图类之一,并且是 Qt 模型/视图框架的一部分。
The QAbstractItemView class is one of the
    Model/View Classes and is part of Qt's model/view framework.

继承 QAbstractltemView 的视图类只需要实现自己的特定于视图的功能,
例如绘制项、返回项的几何图形、查找项等。
The view classes that inherit QAbstractItemView only need to
    implement their own view-specific functionality,
    such as drawing items, returning the geometry of items, finding items, etc.

QAbstractltemView 提供了常见的槽函数,例如edit()和setCurrentIndex()。
还提供了许多受保护的插槽,包括dataChanged()、rowslnserted()、
    rowsAboutToBeRemoved()、selectionChanged()和currentChanged()
QAbstractItemView provides common slots such as edit() and setCurrentIndex().
Many protected slots are also provided, including dataChanged(), rowsInserted(),
    rowsAboutToBeRemoved(), selectionChanged(), and currentChanged().

根项通过rootindex()返回,当前项通过currentlndex()返回。
要确保某个项目可见,请使用scrollTo()方法。
The root item is returned by rootIndex(), and the current item by currentIndex().
To make sure that an item is visible use scrollTo().

QAbstractltemView 的一些函数与滚动有关,例如 setHorizontalScrollMode()和setVerticalScrollMode()。
Some of QAbstractItemView's functions are concerned with scrolling,
for example setHorizontalScrollMode() and setVerticalScrollMode().
To set the range of the scroll bars,
    you can, for example, reimplement the view's resizeEvent() function:
要设置滚动条的范围,例如,您可以重新实现视图的resizeEvent()函数:

     void MyView::resizeEvent(QResizeEvent * event) {
         horizontalScrollBar()->setRange(0, realWidth - width());
         ...
     }

请注意,范围在显示小部件之前不会更新。
Note that the range is not updated until the widget is shown.

其他几个函数与选择控制有关;例如setSelectionMode()和setSelectionBehavior()。
该类提供了一个默认的选择模型供使用(selectionModel()),
    但可以通过使用setSelectionModel ()并结合QltemSelectionModel的实例来替换它。
Several other functions are concerned with selection control;
    for example setSelectionMode(), and setSelectionBehavior().
This class provides a default selection model to work with (selectionModel()),
but this can be replaced by using setSelectionModel() with an
    instance of QItemSelectionModel.

为了完全控制项目的显示和编辑,你可以通过设置setltemDelegate()来指定一个委托。
For complete control over the display and editing of items,
    you can specify a delegate with setItemDelegate().

QAbstractltemView提供了许多受保护的函数。
有些与编辑有关,例如edit()和commitData(),而另一些则是键盘和鼠标事件处理程序。
QAbstractItemView provides a lot of protected functions.
Some are concerned with editing, for example, edit(), and commitData(),
    whilst连词,当……的时候 others are keyboard and mouse event handlers.

注意:如果您继承了 QAbstractltemView 并打算更新视区的内容,
则应使用 viewport->update()而不是 update(),因为所有绘制作都在视区上进行。
Note: If you inherit QAbstractItemView and intend to update the contents of the viewport,
    you should use viewport->update() instead of update() as
    all painting operations take place on the viewport.

*/

class Q_WIDGETS_EXPORT QAbstractItemView : public QAbstractScrollArea
{
private:
    Q_DECLARE_PRIVATE(QAbstractItemView)
    Q_DISABLE_COPY(QAbstractItemView)

    Q_PRIVATE_SLOT(d_func(), void _q_columnsAboutToBeRemoved(const QModelIndex&, int, int))
    Q_PRIVATE_SLOT(d_func(), void _q_columnsRemoved(const QModelIndex&, int, int))
    Q_PRIVATE_SLOT(d_func(), void _q_columnsInserted(const QModelIndex&, int, int))
    Q_PRIVATE_SLOT(d_func(), void _q_rowsInserted(const QModelIndex&, int, int))
    Q_PRIVATE_SLOT(d_func(), void _q_rowsRemoved(const QModelIndex&, int, int))
    Q_PRIVATE_SLOT(d_func(), void _q_columnsMoved(const QModelIndex&, int, int, const QModelIndex&, int))
    Q_PRIVATE_SLOT(d_func(), void _q_rowsMoved(const QModelIndex&, int, int, const QModelIndex&, int))
    Q_PRIVATE_SLOT(d_func(), void _q_modelDestroyed())
    Q_PRIVATE_SLOT(d_func(), void _q_layoutChanged())
    Q_PRIVATE_SLOT(d_func(), void _q_headerDataChanged())
#if QT_CONFIG(gestures) && QT_CONFIG(scroller)
    Q_PRIVATE_SLOT(d_func(), void _q_scrollerStateChanged())
#endif

    friend class ::tst_QAbstractItemView;
    friend class ::tst_QTreeView;
    friend class QTreeViewPrivate; // needed to compile with MSVC
    friend class QListModeViewBase;
    friend class QListViewPrivate;
    friend class QAbstractSlider;

    Q_OBJECT //又插入了此宏


#if QT_CONFIG(draganddrop) //有此定义,拿出来以彩色显示
#endif

    //This property holds whether the 此属性表示在拖动项目和放下时是否显示下拉指示器。
    //  drop indicator is shown when dragging items and dropping. //选中与否没感到有啥区别。
    Q_PROPERTY(bool showDropIndicator READ showDropIndicator WRITE setDropIndicatorShown)

    //This property holds whether the view supports dragging of its own items。
    //选中后,则多选被取消,原条目被拖动起来了。
    Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)


    //This property holds the view's drag and drop behavior。//此属性控制视图的拖放行为。
    //如果其值为真,则所选择的数据在被放置时会覆盖现有的项目数据,而移动数据则会清空该项目。
    //If its value is true, the selected data will overwrite the
    //  existing item data when dropped, while moving the data will clear the item.
    //如果其值为假,那么所选择的数据在被放置时会作为新项目插入,而移动数据时该项目也会被移除。
    //If its value is false, the selected data will be inserted as a new item when the
    //  data is dropped. When the data is moved, the item is removed as well.
    //默认值为假,与QListView和QTreeView子类中的情况相同。而在QTableView子类中,该属性已被设置为真。
    //The default value is false, as in the QListView and QTreeView subclasses.
    //In the QTableView subclass, on the other hand, the property has been set to true.
    //Note: This is not intended to prevent overwriting of items.注:这并非旨在防止对项的覆盖。
    //模型的`flags()、实现应通过不返回`Qt:ItemIsDropEnabled`来达到此目的。
    //The model's implementation of flags() should do that by not
    //  returning Qt::ItemIsDropEnabled.
    Q_PROPERTY(bool       dragDropOverwriteMode //为 true则拖放时成覆盖操作。
                READ      dragDropOverwriteMode //为 F   则拖放时成插入操作。
                WRITE  setDragDropOverwriteMode)

    //This property holds the drag and drop event the view will act upon。
    //enum DragDropMode { NoDragDrop, DragOnly, DropOnly, DragDrop, InternalMove };
    Q_PROPERTY(DragDropMode dragDropMode READ dragDropMode WRITE setDragDropMode)


    /*
    enum Qt::DropAction {
        CopyAction = 0x1,
        MoveAction = 0x2,
        LinkAction = 0x4,
        ActionMask = 0xff,
        TargetMoveAction = 0x8002,
        IgnoreAction = 0x0
    };
    */
    //This property holds the
    //  drop action that will be used by default in QAbstractItemView::drag()。
    //If the property is not set, the drop action is CopyAction when the
    //  supported actions support CopyAction.
    Q_PROPERTY(Qt::DropAction     defaultDropAction
                READ              defaultDropAction
                WRITE          setDefaultDropAction)

//********************************************************************************
//*************************以上都是关于拖放操作的,不重要******************************
//********************************************************************************

    //此属性表示是否启用拖动事件中的自动滚动。
    //This property holds whether autoscrolling in drag move events is enabled.
    //如果此属性设置为 true(默认值),则当用户在视区边缘的 16像素范围内拖动时,
    //QAbstractltemView会自动滚动视图的内容。
    //If this property is set to true (the default),
    //  the QAbstractItemView automatically scrolls the contents of the view if the
    //  user drags within 16 pixels of the viewport edge.
    //如果当前项发生更改,则视图将自动滚动以确保当前项完全可见。此属性仅在视口接受拖动时有效。
    //If the current item changes,
    //  then the view will scroll automatically to ensure that the
    //  current item is fully visible.
    //This property only works if the viewport accepts drops.
    //通过将此属性设置为false,可以关闭自动滚动。
    //Autoscroll is switched off by setting this property to false.
    // 允许后,在多选的时候会自动滚屏,以多选更多。
    Q_PROPERTY(bool  autoScroll        READ  hasAutoScroll        WRITE setAutoScroll)

    Q_PROPERTY(int   autoScrollMargin  READ     autoScrollMargin  WRITE setAutoScrollMargin)
    //允许滚动多选时,选中区域距离视口边界 16 像素,就开始滚屏。默认是 16.
    //This property holds the size of the area when auto scrolling is triggered.
    //This property controls the size of the area at the edge of the
    //  viewport that triggers autoscrolling. The default value is 16 pixels.

    //enum  crollMode { ScrollPerItem, ScrollPerPixel };
    //how the view scrolls its contents in the vertical direction。
    //This property controls how the view scroll its contents vertically.
    //Scrolling can be done either per pixel or per item.
    //Its default value comes from the style via the
    //  QStyle::SH_ItemView_ScrollMode style hint.
    //拖动滑块时按条目为单位跳跃滚动,还是按像素实现连续滚动。
    Q_PROPERTY(ScrollMode        verticalScrollMode
                READ             verticalScrollMode
                WRITE         setVerticalScrollMode
                RESET       resetVerticalScrollMode)

    Q_PROPERTY(ScrollMode        horizontalScrollMode
                READ             horizontalScrollMode
                WRITE         setHorizontalScrollMode
                RESET       resetHorizontalScrollMode)
    //how the view scrolls its contents in the horizontal direction


    //This property holds whether to draw the background using alternating colors。
    //If this property is true,
    //  the item background will be drawn using QPalette::Base and QPalette::AlternateBase;
    //otherwise the background will be drawn using the QPalette::Base color.
    //By default, this property is false.
    Q_PROPERTY(bool       alternatingRowColors //是否启用间隔行底色
                READ      alternatingRowColors
                WRITE  setAlternatingRowColors)


    //This property holds the size of items' icons。
    //Setting this property when the view is visible will cause the
    //  items to be laid out again. 本属性是设置视图里的条目里的图标的尺寸。
    Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged)


    /*
    enum TextElideMode {
        ElideLeft  ,
        ElideRight ,
        ElideMiddle,
        ElideNone
    };
    */
    //This property holds the position of the "..." in elided text.
    //The default value for all item views is Qt::ElideRight.
    //此属性表示省略文本中“...”的位置。所有项目视图的默认值是Qt::ElideRight。
    Q_PROPERTY(Qt::TextElideMode textElideMode READ textElideMode WRITE setTextElideMode)


    //此属性持有哪些操作将启动项目编辑。
    //This property holds which actions will initiate item editing。
    //这个属性是使用“ EditTrigger编辑触发器”定义的标志的组合,并通过“或”运算符进行组合。
    //This property is a selection of flags defined by EditTrigger,
    //  combined using the OR operator.
    //只有当执行的操作被设定在这个属性中时,视图才会启动对某个项目的编辑。
    //The view will only initiate启动 the editing of an item if the
    //  action performed is set in this property. 何种情况下视图才会启动代理以触发对条目的编辑。
    Q_PROPERTY(EditTriggers editTriggers  READ  editTriggers  WRITE  setEditTriggers)

    //This property holds whether item navigation with tab and backtab is enabled.
    //true 则允许用 tab来顺序选中条目,从左向右,从上往下。 shift + tab则实行全表的反向条目选中。
    Q_PROPERTY(bool tabKeyNavigation  READ  tabKeyNavigation  WRITE  setTabKeyNavigation)


    /*
    enum SelectionMode { //定义在本类。
                NoSelection,
            SingleSelection,
             MultiSelection,
          ExtendedSelection,  //此项功能最强
        ContiguousSelection
    };
    */
    //This property holds which selection mode the view operates in。单选时的多选与否
    //此属性控制用户是否可以选择一个或多个项,并且在多项选择中,是否必须选择连续的项范围。
    Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)


    /*
    enum SelectionBehavior {
        SelectItems,
        SelectRows,
        SelectColumns
    };
    Q_ENUM(SelectionBehavior)
    */
    //This property holds which selection behavior the view uses。
    //This property holds whether selections are done in terms of single items,
    //  rows or columns. 是单选,还是行选,或者列选。
    //本属性设置为行选、列选时,上面的 SelectionMode 属性将不再其作用。
    Q_PROPERTY(SelectionBehavior    selectionBehavior
                READ                selectionBehavior
                WRITE            setSelectionBehavior)


public:

    /*
    enum Qt::ItemFlag {
        NoItemFlags = 0,
        ItemIsSelectable = 1,
        ItemIsEditable = 2,
        ItemIsDragEnabled = 4,
        ItemIsDropEnabled = 8,
        ItemIsUserCheckable = 16,
        ItemIsEnabled = 32,
        ItemIsAutoTristate = 64,
        ItemNeverHasChildren = 128,
        ItemIsUserTristate = 256
    };
    Q_DECLARE_FLAGS(ItemFlags, ItemFlag)
    */

    //Constructs an abstract item view with the given parent.
    explicit QAbstractItemView(QWidget * parent = nullptr); //有参构造函数

    ~QAbstractItemView();


//   Q_PROPERTY(bool      autoScroll
//              READ   hasAutoScroll
//              WRITE  setAutoScroll)
                bool   hasAutoScroll() const;
                void   setAutoScroll(bool enable);


//   Q_PROPERTY(int       autoScrollMargin
//              READ      autoScrollMargin   WRITE  setAutoScrollMargin)
                int       autoScrollMargin() const;
                void   setAutoScrollMargin(int margin);


        //This enum describes actions which will initiate item editing.
        enum    EditTrigger {     //本枚举类修饰视图,但 model 里的条目也有属性
            NoEditTriggers  =  0, //No editing possible.
            CurrentChanged  =  1, //Editing starts whenever current item changes.
            DoubleClicked   =  2, //Editing starts when an item is double clicked.
            SelectedClicked =  4, //Editing starts when clicking on an already selected item.
            EditKeyPressed  =  8, //Editing starts when the platform edit key比如enter键?
            //           has been pressed over an item.

            AnyKeyPressed   = 16, //Editing starts when any key is pressed over an item.
            AllEditTriggers = 31  //Editing starts for all above actions.
        };
        Q_DECLARE_FLAGS(EditTriggers, EditTrigger)
        Q_FLAG( EditTriggers )
//   Q_PROPERTY(EditTriggers    editTriggers
//              READ            editTriggers   WRITE   setEditTriggers)
                EditTriggers    editTriggers() const;
                void         setEditTriggers(EditTriggers triggers);


//   Q_PROPERTY(bool      tabKeyNavigation
//              READ      tabKeyNavigation     WRITE   setTabKeyNavigation)
                bool      tabKeyNavigation() const;
                void   setTabKeyNavigation(bool enable);


//   Q_PROPERTY(bool      showDropIndicator
//              READ      showDropIndicator    WRITE   setDropIndicatorShown)
                bool      showDropIndicator     () const;
                void       setDropIndicatorShown(bool enable);

//   Q_PROPERTY(bool      dragEnabled
//              READ      dragEnabled    WRITE   setDragEnabled)
                bool      dragEnabled() const;
                void   setDragEnabled(bool enable);


//   Q_PROPERTY(bool      dragDropOverwriteMode
//              READ      dragDropOverwriteMode
//              WRITE  setDragDropOverwriteMode)
                bool      dragDropOverwriteMode() const;
                void   setDragDropOverwriteMode(bool overwrite);

    //描述了视图可以处理的各种拖放事件。默认情况下,视图不支持拖放(NoDragDrop)。
    //Describes the various drag and drop events the view can act upon.
    //By default the view does not support dragging or dropping (NoDragDrop).
    //Note that the model used needs to provide support for drag and drop operations.
        enum    DragDropMode {
            NoDragDrop,  //Does not support dragging or dropping.
            DragOnly  ,  //The view supports dragging of its own items。
            DropOnly  ,  //The view accepts drops。
            DragDrop  ,  //The view supports both dragging and dropping。
            InternalMove //The view accepts move (not copy) operations only from itself。
        };
        Q_ENUM( DragDropMode )
//   Q_PROPERTY(DragDropMode     dragDropMode
//              READ             dragDropMode    WRITE    setDragDropMode)
                DragDropMode     dragDropMode() const;
                void          setDragDropMode(DragDropMode  behavior);


    /*
    enum Qt::DropAction { //本枚举类用于描述模型视图里的拖动操作的语义:复制、剪切或超链接。
        CopyAction       = 0x   1, //Copy the data to the target.
        MoveAction       = 0x   2, //Move the data from the source to the target.
        LinkAction       = 0x   4, //Create a link from the source to the target.
        ActionMask       = 0x  ff,
        TargetMoveAction = 0x8002, //在 Windows上,当 D&D数据的所有权应被目标应用程序接管时,
            //即源应用程序不应删除这些数据时,会使用此值。
            //在X11上,此值用于执行移动操作。Mac上不使用TargetMoveAction。
        IgnoreAction     = 0x   0  //Ignore the action (do nothing with the data).
    };
    Q_DECLARE_FLAGS(DropActions, DropAction)
    Q_DECLARE_OPERATORS_FOR_FLAGS(DropActions)
    */

//   Q_PROPERTY(Qt::DropAction     defaultDropAction
//              READ               defaultDropAction
//              WRITE           setDefaultDropAction)
                Qt::DropAction     defaultDropAction() const;
                void            setDefaultDropAction(Qt::DropAction dropAction);


//   Q_PROPERTY(bool       alternatingRowColors
//              READ       alternatingRowColors
//              WRITE   setAlternatingRowColors)
                bool       alternatingRowColors() const;
                void    setAlternatingRowColors(bool enable);


    enum SelectionMode { //This enum indicates how the view responds to user selections:
                NoSelection,//Items cannot be selected.
            SingleSelection,//当用户选择某个项目时,之前已选中的项目将变为未选中状态。
                            //用户可以通过在点击已选中项目时按下Ctrl键来取消选中已选中的项目。
             MultiSelection,//当用户以常规方式选择某个项目时,该项目的选择状态会被切换,
                            //而其他项目则保持不变。通过用鼠标在这些项目上拖动,可以同时切换多个项目。
          ExtendedSelection,//当用户以常规方式选择某个项目时,原先的选择会被清除,并选中新的项目。
                            //然而,如果用户在点击某个项目时按下了Ctrl键,那么被点击的项目将被切换状态,
                            //而其他所有项目则保持不变。如果用户在点击某个项目时按了下Shift键,
                            //那么当前项目与被点击项目之间的所有项目将被选中或取消选中,
                            //具体取决于被点击项目的状态。通过用鼠标拖动可以同时选择多个项目。
        ContiguousSelection //当用户以常规方式选择某个项目时,当前选择会被清除,并选中新的项目。
                            //然而,如果用户在点击某个项目时按下了Shift键,
                            //那么当前项目与所点击项目之间的所有项目将被选中或取消选中,
                            //具体取决于所点击项目的状态。
    }; //The most commonly used modes are SingleSelection and ExtendedSelection.单选与多选。
    Q_ENUM( SelectionMode )

//   Q_PROPERTY(SelectionMode         selectionMode
//              READ                  selectionMode     WRITE     setSelectionMode)
                QAbstractItemView::   SelectionMode     selectionMode() const;
    void    setSelectionMode(QAbstractItemView::SelectionMode mode);



        enum    SelectionBehavior {
                SelectItems,  //Selecting single items.
                SelectRows ,  //Selecting only rows.
                SelectColumns //Selecting only columns.
        };
        Q_ENUM( SelectionBehavior )
//   Q_PROPERTY(SelectionBehavior     selectionBehavior
//              READ                  selectionBehavior
//              WRITE              setSelectionBehavior)
                QAbstractItemView::   SelectionBehavior   selectionBehavior() const;
    void    setSelectionBehavior( QAbstractItemView::SelectionBehavior  behavior );


//   Q_PROPERTY(QSize      iconSize
//              READ       iconSize
//              WRITE   setIconSize
//              NOTIFY     iconSizeChanged)
                QSize      iconSize() const;
                void    setIconSize       (const QSize & size);
Q_SIGNALS:
                void       iconSizeChanged(const QSize & size);


public :
/*
    //This enum specifies where the ellipsis should appear
    //  when displaying texts that don't fit:
    //此枚举指定在显示不匹配文本时,句号应出现在何处:
    enum Qt::TextElideMode {  //  Elide  省略;忽略
        ElideLeft  , //The ellipsis should appear at the beginning of the text。
        ElideRight , //The ellipsis should appear at the end       of the text.
        ElideMiddle, //The ellipsis should appear in the middle    of the text.
        ElideNone    //Ellipsis should NOT appear in the text.
    };
*/
//   Q_PROPERTY(Qt::TextElideMode     textElideMode
//              READ                  textElideMode
//              WRITE              setTextElideMode)
                Qt::TextElideMode     textElideMode() const;
                void               setTextElideMode(Qt::TextElideMode  mode);


//   Q_PROPERTY(ScrollMode        verticalScrollMode
//              READ              verticalScrollMode
//              WRITE          setVerticalScrollMode
//              RESET        resetVerticalScrollMode)
                ScrollMode        verticalScrollMode() const;
                void           setVerticalScrollMode(ScrollMode  mode);
                void         resetVerticalScrollMode();


    //Describes how the scrollbar should behave. //描述了滚动条应如何表现。
    //当将滚动模式设置为“按像素滚动”时,单次步长将自动调整,除非使用setSingleStep()、显式设置过。
    //When setting the scroll mode to ScrollPerPixel,
    //  the single step size will adjust automatically unless it was
    //  set explicitly using setSingleStep().    //通过将单次步长设置为-1,可以恢复自动调整功能。
    //The automatic adjustment can be restored by setting the single step size to -1.
        enum    ScrollMode {
            ScrollPerItem, //The view will scroll the contents one item  at a time.
            ScrollPerPixel //The view will scroll the contents one pixel at a time。
        };
        Q_ENUM( ScrollMode )

//   Q_PROPERTY(ScrollMode        horizontalScrollMode
//              READ              horizontalScrollMode
//              WRITE          setHorizontalScrollMode
//              RESET        resetHorizontalScrollMode)
                ScrollMode        horizontalScrollMode() const;
                void           setHorizontalScrollMode(ScrollMode  mode);
                void         resetHorizontalScrollMode();

    //移动到并选择与字符串搜索最匹配的项目。如果没有找到任何项目,则不会发生任何事情。
    //在默认实现中,如果搜索为空,
    //或者自上次搜索以来的时间间隔已超过`QApplication::keyboardInputInterval()搜索将被重置。
    //Moves to and selects the item best matching the string search.
    //If no item is found nothing happens.
    //In the default implementation, the search is reset if search is empty,
    //  or the time interval since the
    //  last search has exceeded QApplication::keyboardInputInterval().
    virtual void keyboardSearch(const QString & search); //根据形参在视图里查找对应的条目

    enum ScrollHint {
        EnsureVisible   , //Scroll to ensure that the item is visible.
        PositionAtTop   , //Scroll to position the item at the top    of the viewport.
        PositionAtBottom, //Scroll to position the item at the bottom of the viewport.
        PositionAtCenter  //Scroll to position the item at the center of the viewport.
    };
    Q_ENUM(ScrollHint)    //滚动屏幕到条目 index处,并指明了 index条目的新的位置
    virtual void scrollTo(const QModelIndex & index, ScrollHint hint = EnsureVisible) = 0;

    //Returns the model index of the item at the viewport coordinates point.
    //In the base class this is a pure virtual function.
    //返回视口坐标系里位置 point 处的条目的索引。class QPoint { int xp; int yp; };
    virtual QModelIndex indexAt(const QPoint & point) const = 0; //纯虚函数

    //返回视口中由索引项占用的矩形。
    //如果您的项在多个区域中显示,那么`visualRect`应该返回包含索引的主区域,
    //而不是索引可能涵盖、触及或导致绘制的整个区域。
    //Returns the rectangle on the viewport occupied by the item at index.
    //If your item is displayed in several areas then visualRect should return the
    //  primary area that contains index and not the
    //  complete area that index might encompasses, touch or cause drawing.
    //In the base class this is a pure virtual function.
    virtual
    QRect              visualRect(const QModelIndex & index) const = 0;
    //返回视口坐标系中,某个索引指向的条目的坐标与大小。
    //class QRect { int x1; int y1; int x2; int y2; };

    //class QSize { int wd; int ht; };
    //Returns the size hint for the item with the specified index or
    //  an invalid size for invalid indexes.返回对条目 index的建议几何大小。
    QSize       sizeHintForIndex (const QModelIndex & index) const;


    //Returns the height size hint for the specified row or -1 if there is no model.
    //The returned height is calculated using the size hints of the given row's items,
    //i.e. the returned value is the maximum height among the items.
    //Note that to control the height of a row,
    //you must reimplement the QAbstractItemDelegate::sizeHint() function.
    //This function is used in views with a vertical header to find the
    //  size hint for a header section based on the contents of the given row.
    virtual int sizeHintForRow   (int row   ) const; //返回对行 row    的建议高度。
    virtual int sizeHintForColumn(int column) const; //返回对列 column 的建议宽度。
    //Returns the width size hint for the specified column or -1 if there is no model.
    //This function is used in views with a horizontal header to find the
    //  size hint for a header section based on the contents of the given column.

    //Returns the model that this view is presenting.
    QAbstractItemModel   *        model() const; //设置本视图的模型。
    virtual       void         setModel(QAbstractItemModel * model);
    //Sets the model for the view to present.
    //这个函数将创建并设置一个新的选择模型,取代之前使用 setSelectionModel()函数设置的任何模型。
    //然而,旧的选模型不会被删除,因为它可能存在于多个视图之间。
    //我们建议在不再需要时删除旧的选模型。这可以通过以下代码实现:
            // QItemSelectionModel * m = view->selectionModel();
            // view->setModel(new model);
            // delete m;
    //If both the old model and the old selection model do not have parents,
    //如果旧模型和旧选择模型都没有父对象,或者它们的父对象是生命周期较长的对象,
    //那么更可取的做法可能是调用它们的`deleteLater()、函数以明确删除它们。
    //视图不会接管模型的所有权,除非它是模型的父对象,因为模型可能在多个不同的视图之间共享。

    //Returns the current selection model.
    QItemSelectionModel *    selectionModel() const; //返回视图用的选择模型
    virtual void          setSelectionModel(QItemSelectionModel * selectionModel);
    //Sets the current selection model to the given selectionModel.
    //请注意,如果在调用此函数之后调用setModel(),则给定的选择模型将被视图创建的一个模型替换。
    //注:应用程序有责任在不再需要时删除旧的选择模型,即,如果其他视图不再使用它.
    //当其父对象被删除时,这将会自动发生。
    //然而,如果它没有父对象,或者如果父对象是一个生命周期较长的对象,
    //那么调用其`deleteLater()、函数以明确删除它可能更为合适。

    //Returns the item delegate used by this view and model.
    //This is either one set with setItemDelegate(), or the default one.
    QAbstractItemDelegate *    itemDelegate() const; //返回视图使用的代理,但视图不拥有代理
    void                    setItemDelegate(QAbstractItemDelegate * delegate);
    //Sets the item delegate for this view and its model to delegate.
    //This is useful if you want complete control over the editing and display of items.
    //Any existing delegate will be removed,
    //  but not deleted. QAbstractItemView does not take ownership of delegate.
    //警告:您不应在视图之间共享同一个委托实例。这样做可能会导致不正确或不直观的编辑行为,
    //因为连接到给定委托的每个视图都可能接收到“closeEditor()”信号,
    //  并尝试访问、修改或关闭一个已经关闭的编辑器。

    //Returns the item delegate used by this view and model for the given row,
    //  or nullptr if no delegate has been assigned.
    //You can call itemDelegate() to get a pointer to the current delegate for a given index.
    QAbstractItemDelegate *    itemDelegateForRow   (int row) const; //返回本行使用的代理。
    void  setItemDelegateForRow   (int    row,  QAbstractItemDelegate * delegate);
    //Sets the given item delegate used by this view and model for the given row.
    //All items on row will be drawn and managed by delegate instead of using the
    //  default delegate (i.e., itemDelegate()).
    //Any existing row delegate for row will be removed, but not deleted.
    //QAbstractItemView does not take ownership of delegate.
    //Note: If a delegate has been assigned to both a row and a column,
    //  the row delegate (i.e., this delegate) will take precedence and manage the
    //  intersecting cell index.         文档说明行代理的优先级高于列代理。

    //Returns the item delegate used by this view and model for the given column.
    QAbstractItemDelegate *    itemDelegateForColumn(int column) const;
    void  setItemDelegateForColumn(int column,  QAbstractItemDelegate * delegate);
    //Sets the given item delegate used by this view and model for the given column.
    //All items on column will be drawn and managed by delegate instead of using the
    //  default delegate (i.e., itemDelegate()).
    //Any existing column delegate for column will be removed, but not deleted.
    //  QAbstractItemView does not take ownership of delegate.

    virtual
    QAbstractItemDelegate *    itemDelegateForIndex (const QModelIndex & index) const;
    //Returns the item delegate used by this view and model for the given index.

    //返回模型根项的模型索引。根项是视图顶级项的父项。根项可能无效。
    //Returns the model index of the model's root item.
    //The root item is the parent item to the view's toplevel items.
    //The root can be invalid.
    QModelIndex      rootIndex() const; //根索引主要用于树视图里。
    QModelIndex   currentIndex() const;
    //Returns the model index of the current item.

    //Returns whether a persistent editor is open for the item at index index.
    bool      isPersistentEditorOpen(const QModelIndex & index) const;

    //这些函数的意思就是用代码的方式而非鼠标敲击的方式,为某条目打开一个编辑代理。
    //Opens a persistent editor on the item at the given index.
    //If no editor exists, the delegate will create a new editor.
    void    openPersistentEditor    (const QModelIndex & index);
    void   closePersistentEditor    (const QModelIndex & index);
    //Closes the persistent editor for the item at the given index.

    //Returns the widget for the item at the given index.
    QWidget *    indexWidget(const QModelIndex & index) const;
    void      setIndexWidget(const QModelIndex & index, QWidget * widget);
    //Sets the given widget on the item at the given index,
    //  passing the ownership of the widget to the viewport.
    //If index is invalid (e.g., if you pass the root index),
    //  this function will do nothing.
    //给定的widget的autoFillBackground属性必须设置为true,
    //否则widget的背景将是透明的,同时显示模型数据和给定索引处的项。
    //如果将索引小部件A替换为索引小部件B,则索引小部件A将被删除。
    //例如,在下面的代码片段中,QLineEdit对象将被删除。
            // setIndexWidget(index, new QLineEdit);
            // ...
            // setIndexWidget(index, new QTextEdit);
    //此函数只能用于显示与数据项对应的可见区域内的静态内容。
    //如果要显示自定义动态内容或实现自定义编辑器窗口小部件,请改为继承QStyledltemDelegate。


    //Reimplements: QWidget::inputMethodQuery(Qt::InputMethodQuery query) const.
    virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;

    using QAbstractScrollArea::update; //QAbstractScrollArea 里并没有这 update函数。
    /*
    class QWidget {
        void update(              );
        void update(const QRegion&);
        void update(const QRect  &);
        inline void update(int x, int y, int w, int h)
        {    update(QRect(ax, ay, aw, ah)); }
    }
    */


protected:
    QAbstractItemView(QAbstractItemViewPrivate &, QWidget *parent = nullptr); //有参构造函数

    /*
        enum KeyboardModifier {
            NoModifier           = 0x00000000,
            ShiftModifier        = 0x02000000,
            ControlModifier      = 0x04000000,
            AltModifier          = 0x08000000,
            MetaModifier         = 0x10000000,
            KeypadModifier       = 0x20000000,
            GroupSwitchModifier  = 0x40000000,
            // Do not extend the mask to include 0x01000000
            KeyboardModifierMask = 0xfe000000
        };
        Q_DECLARE_FLAGS(KeyboardModifiers, KeyboardModifier)
        Q_DECLARE_OPERATORS_FOR_FLAGS(KeyboardModifiers)
    */
    enum CursorAction { MoveUp  , MoveDown, MoveLeft  , MoveRight,
                        MoveHome, MoveEnd , MovePageUp, MovePageDown,
                        MoveNext, MovePrevious };
    virtual QModelIndex moveCursor(CursorAction cursorAction,
                                   Qt::KeyboardModifiers modifiers) = 0; //纯虚函数
    //Returns a QModelIndex object pointing to the next object in the view,
    //  based on the given cursorAction and keyboard modifiers specified by modifiers.
    //In the base class this is a pure virtual function.
    //返回一个指向视图中下一个对象的QModelIndex对象,
    //  基于给定的cursorAction和由modifiers指定的键盘修饰符。
    //返回与键盘操作对应的下一个条目的索引。

    //Returns the horizontal / vertical  offset of the view.
    virtual int horizontalOffset() const = 0;
    virtual int   verticalOffset() const = 0;

    //Returns true if the item referred to by the given index is hidden in the view,
    //otherwise returns false. Hiding is a view specific feature.
    //For example in TableView a column can be marked as hidden or a row in the TreeView.
    //若索引指向的条目被隐藏,则返回 true。可以隐藏表格里的列,或树表里的行。
    virtual bool isIndexHidden(const QModelIndex & index) const = 0;


    /*
    enum QItemSelectionModel::SelectionFlag {
        NoUpdate       = 0x0000,
        Clear          = 0x0001,
        Select         = 0x0002,
        Deselect       = 0x0004,
        Toggle         = 0x0008,
        Current        = 0x0010,
        Rows           = 0x0020,
        Columns        = 0x0040,
        SelectCurrent  = Select | Current,
        ToggleCurrent  = Toggle | Current,
        ClearAndSelect = Clear  | Select
    };
    Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)
    Q_FLAG(SelectionFlags)
    */
    //typedef QList<QModelIndex> QModelIndexList;
    //此方便函数返回视图中所有选定且未隐藏的项目索引列表。该列表不包含重复项,并且未排序。
    virtual QModelIndexList        selectedIndexes() const;

    //Applies the selection flags to the items in or touched by the rectangle, rect.
    //当实现你自己的项目视图时,setSelection应该调用 selectionModel()->select(selection,flags),
    //  其中selection 是一个空的 OModellndex 或一个包含 rect 中包含的所有项目的 QltemSelection。
    virtual void                setSelection(const QRect & rect,
                              QItemSelectionModel::SelectionFlags command) = 0;

    virtual QRegion visualRegionForSelection(const QItemSelection & selection) const = 0;
    //Returns the region from the viewport of the items in the given selection.
    //返回形参里的条目占据的区域。

    //Starts editing the item at index, creating an editor if necessary,
    //and returns true if the view's State is now EditingState; otherwise returns false.
    //The action that caused the editing process is described by trigger,
    //and the associated event is specified by event.
    //Editing can be forced by specifying the
    //  trigger to be QAbstractItemView::AllEditTriggers.
    //启用视图里的对 index条目的代理编辑,触发条件是形参 trigger,对应的事件是 event。
    virtual bool edit(const QModelIndex & index, EditTrigger trigger, QEvent * event);
    /*
    enum QAbstractItemView::EditTrigger {
        NoEditTriggers  =  0,
        CurrentChanged  =  1,
        DoubleClicked   =  2,
        SelectedClicked =  4,
        EditKeyPressed  =  8,
        AnyKeyPressed   = 16,
        AllEditTriggers = 31
    };
    Q_DECLARE_FLAGS(EditTriggers, EditTrigger)
    Q_FLAG(EditTriggers)
    */

    /*
    enum QItemSelectionModel::SelectionFlag {
        NoUpdate       = 0x0000,
        Clear          = 0x0001,
        Select         = 0x0002,
        Deselect       = 0x0004,
        Toggle         = 0x0008,
        Current        = 0x0010,
        Rows           = 0x0020,
        Columns        = 0x0040,
        SelectCurrent  = Select | Current,
        ToggleCurrent  = Toggle | Current,
        ClearAndSelect = Clear  | Select
    };
    Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)
    Q_FLAG(SelectionFlags)
    */
    virtual QItemSelectionModel::SelectionFlags selectionCommand(
                const QModelIndex & index, const QEvent * event = nullptr) const;
    //Returns the SelectionFlags to be used when updating a selection with to
    //  include the index specified. The event is a user input event,
    //such as a mouse or keyboard event.
    //Reimplement this function to define your own selection behavior.


    /*
    enum Qt::DropAction {
        CopyAction = 0x1,
        MoveAction = 0x2,
        LinkAction = 0x4,
        ActionMask = 0xff,
        TargetMoveAction = 0x8002,
        IgnoreAction = 0x0
    };
    Q_DECLARE_FLAGS(DropActions, DropAction)
    Q_DECLARE_OPERATORS_FOR_FLAGS(DropActions)
    */
    virtual void startDrag(Qt::DropActions   supportedActions);
    //Starts a drag by calling drag->exec() using the given supportedActions.

    //Initialize the option structure with the view's palette, font, state,
    //  alignments etc.
    //注:实现此方法时,应检查接收到的结构的版本,填充实现所熟悉的全部成员,
    //并在返回前将版本成员设置为实现所支持的版本。
    virtual void initViewItemOption(QStyleOptionViewItem * option) const;

    //Describes the different states the view can be in.
    //This is usually only interesting when reimplementing your own view.
    enum State  {
                   NoState, //This is the default state.
             DraggingState, //The user is dragging items.
        DragSelectingState, //The user is selecting items.
              EditingState, //The user is editing an item in a widget editor。
            ExpandingState, //The user is opening a branch of items.
           CollapsingState, //The user is closing a branch of items. 折叠
            AnimatingState  //The item view is performing an animation.
    };

    State     state()      const; //Returns the item view's state.
    void   setState(State state); //Sets the item view's state to the given state.

    //安排在事件处理开始时执行视图中项目的布局。
    //Schedules a layout of the items in the view to be executed when the
    //  event processing starts.
    //即使在处理事件之前多次调用scheduleDelayedltemsLayout(),视图也将只会进行一次布局。
    //Even if scheduleDelayedItemsLayout() is called multiple times before
    //  events are processed, the view will only do the layout once.
    void scheduleDelayedItemsLayout();
    void  executeDelayedItemsLayout();
    //Executes the scheduled layouts without waiting for the
    //  event processing to begin.

    //通过反向移动脏区域,为滚动操作(dx,dy)像素做好准备。
    //Prepares the view for scrolling by (dx,dy) pixels by moving the
    //  dirty regions in the opposite direction.
    //只有在您的视图子类中实现滚动视口时,才需要调用此函数。
    //You only need to call this function if you are implementing a
    //  scrolling viewport in your view subclass.
    //如果在OAbstractltemView的子类中实现scrollcontentsBy(),
    //那么在调用viewport上的OWidget:scroll()之前应先调用此函数。或者,直接调用update()即可。
    //If you implement scrollContentsBy() in a subclass of QAbstractItemView,
    //  call this function before you call QWidget::scroll() on the viewport.
    //Alternatively, just call update().
    void  scrollDirtyRegion(int dx, int dy);

    //Marks the given region as dirty and schedules it to be updated.
    //You only need to call this function if you are implementing your own view subclass.
    void     setDirtyRegion(const QRegion & region);
    QPoint      dirtyRegionOffset() const;
    //返回视图中脏区域的偏移量。
    //Returns the offset of the dirty regions in the view.
    //如果使用 scrollDirtyRegion()并在 QAbstractltemView的子类中实现 paintEvent(),
    //则应使用此函数返回的偏移量转换 paint 事件给定的区域。
    //If you use scrollDirtyRegion() and implement a paintEvent() in a
    //  subclass of QAbstractItemView, you should translate the area given by the
    //  paint event with the offset returned from this function.

    void startAutoScroll(); //无注释
    void  stopAutoScroll();
    void    doAutoScroll();

    //此枚举表示当前鼠标位置相对于索引的下拉指示器的位置:
    //This enum indicates the position of the drop indicator in relation to the
    //  index at the current mouse position:
    enum DropIndicatorPosition {
           OnItem, //The item will be dropped on    the index.
        AboveItem, //The item will be dropped above the index.
        BelowItem, //The item will be dropped below the index.
        OnViewport //The item will be dropped onto a region of the viewport with no items.
            //The way each view handles items dropped onto the viewport depends on the
            //  behavior of the underlying model in use.
            //该物品将被放置在视窗中没有任何物品的区域。
            //视窗如何处理被放置在视窗上的物品,取决于当前使用的底层模型的行为。
    };
    DropIndicatorPosition dropIndicatorPosition() const;
    //Returns the position of the drop indicator in relation to the closest item.

    //Reimplements: QAbstractScrollArea::viewportSizeHint() const.
    QSize viewportSizeHint() const override;

    bool focusNextPrevChild(bool next) override;

    bool eventFilter(QObject * object, QEvent * event) override;

    bool                 event(QEvent            * event) override;
    bool         viewportEvent(QEvent            * event) override;
    void       mousePressEvent(QMouseEvent       * event) override;
    void        mouseMoveEvent(QMouseEvent       * event) override;
    void     mouseReleaseEvent(QMouseEvent       * event) override;
    void mouseDoubleClickEvent(QMouseEvent       * event) override;

    void        dragEnterEvent(QDragEnterEvent   * event) override;
    void         dragMoveEvent(QDragMoveEvent    * event) override;
    void        dragLeaveEvent(QDragLeaveEvent   * event) override;
    void             dropEvent(QDropEvent        * event) override;

    void          focusInEvent(QFocusEvent       * event) override;
    void         focusOutEvent(QFocusEvent       * event) override;
    void         keyPressEvent(QKeyEvent         * event) override;
    void           resizeEvent(QResizeEvent      * event) override;
    void            timerEvent(QTimerEvent       * event) override;
    void      inputMethodEvent(QInputMethodEvent * event) override;

public Q_SLOTS:
    //Reset the internal state of the view.
    virtual void reset();
    //警告:此函数将重置打开的编辑器、滚动条位置、选择项等。现有的更改将不会被承诺 commit。
    //如果希望在重置视图时保存更改,可以重新实现此函数,提交更改,然后调用超类的实现。

    //Sets the root item to the item at the given index.
    virtual void setRootIndex(const QModelIndex & index); //奇怪

    virtual void doItemsLayout(); //无注释

    //Selects all items in the view.
    //This function will use the selection behavior set on the view when selecting.
    virtual void selectAll();

    //Starts editing the item corresponding to the given index if it is editable.
    //Note that this function does not change the current index.
    //Since the current index defines the next and previous items to edit,
    //users may find that keyboard navigation does not work as expected.
    //To provide consistent navigation behavior,
    //call setCurrentIndex() before this function with the same model index.
    //请注意,此函数不会改变当前索引。由于当前索引定义了待编辑的下一个和上一个项目,
    //用户可能会发现键盘导航无法按预期工作。
    //为了提供一致的导航行为,
    //请在调用此函数之前,使用相同的模型索引调用setCurrentIndex()函数。
    void edit(const QModelIndex & index);

    //Deselects all selected items. The current index will not be changed.
    void clearSelection(); //清除之前所做的所有的条目选择。

    void setCurrentIndex(const QModelIndex & index);
    //Sets the current item to be the item at index.
    //Unless the current selection mode is NoSelection, the item is also selected.
    //Note that this function also updates the
    //  starting position for any new selections the user performs.
    //To set an item as the current item without selecting it, call
    // selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);

    void scrollToTop   (); //Scrolls the view to the top.
    void scrollToBottom(); //Scrolls the view to the bottom.

    void update(const QModelIndex & index); //多定义了重载函数
    /*
    class QWidget {
        void update(int x, int y, int w, int h);
        void update(const QRect   &);
        void update(const QRegion &);
    };
    */


protected Q_SLOTS:

    //This slot is called when items with the given roles are changed in the model.
    //The changed items are those from topLeft to bottomRight inclusive.
    //If just one item is changed topLeft == bottomRight.
    //The roles which have been changed can either be an empty container
    //(meaning everything has changed),
    //  or a non-empty container with the subset of roles which have changed.
    //Note: Qt::ToolTipRole is not honored by dataChanged() in the views provided by Qt.
    //当模型里的条目被改变的时候,触发视图里的此槽函数,以实现模型与视图的同步。
    virtual void        dataChanged(const QModelIndex & topLeft,
                                    const QModelIndex & bottomRight,
                                    const QList<int>  & roles = QList<int>());//角色组合


    //This slot is called when a new item becomes the current item.
    //The previous current item is specified by the previous index,
    //and the new item by the current index.
    //If you want to know about changes to items see the dataChanged() signal.
    //当一个新项成为当前项时,会触发这个插槽。先前的当前项由先前的索引指定,而新项则由当前索引指定。
    //如果你想了解项目的变化,请查看dataChanged()信号。
    //当视图里的当前条目发生切换时,调用本槽函数。
    virtual void     currentChanged(const QModelIndex & current,
                                    const QModelIndex & previous);

    //This slot is called when the selection is changed.
    //The previous selection (which may be empty), is specified by deselected,
    //and the new selection by selected. //引入了 QItemSelection 类,看来也要学习。
    //又是响应选择变化时候的槽函数。
    virtual void   selectionChanged(const QItemSelection &   selected,
                                    const QItemSelection & deselected);

    //槽函数,响应视图里滚动条滚动时的界面更新。
    virtual void   verticalScrollbarValueChanged(int value ); //无注释
    virtual void   verticalScrollbarAction      (int action); //无注释
    virtual void horizontalScrollbarValueChanged(int value );
    virtual void horizontalScrollbarAction      (int action);


    //This slot is called when rows are inserted.
    //The new rows are those under the given parent from start to end inclusive.
    //The base class implementation calls fetchMore() on the model to check for more data.
    //当插入行时,会调用这个方法。新行是在给定的父元素下从起始到结束(包含起始和结束)的所有行。
    //基类实现会在模型上调用`fetchMore()、方法以检查是否有更多数据。
    //当往 parent条目里子表里插入新的行时候,调用本槽函数更新视图。
    virtual void rowsInserted        (const QModelIndex & parent, int start, int end);

    //This slot is called when rows are about to be removed.
    //The deleted rows are those under the given parent from start to end inclusive.
    //当行即将被删除时,会调用此插槽。要删除的行是从给定父项开始到结束(包括结束)的所有行。
    //当模型要删除 parent项的子表里的行的时候调用对应视图里此槽函数,完成视图更新。
    virtual void rowsAboutToBeRemoved(const QModelIndex & parent, int start, int end);


    //Updates the geometry of the child widgets of the view.
    //更新本视图里,子组件的集合尺寸。
    virtual void updateGeometries();

    virtual void updateEditorData(); //无注释,更新代理里的数据与代理的尺寸。

    virtual void updateEditorGeometries();

    //Commit the data in the editor to the model.
    virtual void commitData(QWidget * editor); //把视图里代理里的数据提交给模型。

    /*
    enum QAbstractItemDelegate::EndEditHint {
        NoHint,
        EditNextItem,
        EditPreviousItem,
        SubmitModelCache,
        RevertModelCache
    };
    */
    //Closes the given editor, and releases it.
    //The hint is used to specify how the view should respond to the
    //  end of the editing operation. For example,
    //the hint may indicate that the next item in the view should be opened for editing.
    //关闭指定的编辑器,并释放它。提示用于指定视图应如何响应编辑操作的结束。
    //例如,提示可能指示视图中的-个项目应被打开以供编辑。
    //当视图里一个条目上的代理在完成编辑后被关闭时,调用本槽函数,处理视图接着应该怎么做。
    virtual void  closeEditor(QWidget * editor, QAbstractItemDelegate::EndEditHint hint);
    virtual void       editorDestroyed(QObject * editor);
    //This function is called when the given editor has been destroyed.
    //当视图里一个代理被内存销毁后,调用本槽函数。


Q_SIGNALS:
  //void iconSizeChanged(const QSize & size); //这也是信号函数。

    //This signal is emitted when the mouse cursor enters the viewport.
    //Mouse tracking needs to be enabled for this feature to work.
    //当鼠标光标进入视口时,会发出此信号。需要启用鼠标跟踪才能使此功能正常工作。
    void viewportEntered(); //在 QWidget 基类里开启鼠标跟踪。
    void         entered  (const QModelIndex & index);
    //This signal is emitted when the mouse cursor enters the item specified by index.
    //Mouse tracking needs to be enabled for this feature to work.
    //class QWidget { Q_PROPERTY(bool    mouseTracking
    //                           READ hasMouseTracking WRITE setMouseTracking) };

    //This signal is emitted when the item specified by index is activated by the user.
    //How to activate items depends on the platform;
    //e.g., by single- or double-clicking the item,
    //or by pressing the Return or Enter key when the item is current.
    //当用户激活由索引指定的项时,会发出这个信号。如何激活项取决于平台;
    //例如,通过单击项一次或两次,或者在项处于当前位置时按下回车或Enter键。
    void activated    (const QModelIndex & index);

    //This signal is emitted when a mouse button is pressed.
    //The item the mouse was pressed on is specified by index.
    //The signal is only emitted when the index is valid.
    //Use the QGuiApplication::mouseButtons() function to get the
    //  state of the mouse buttons.视图响应条目上的鼠标信号,可以用来启用条目代理。
    void pressed      (const QModelIndex & index); //鼠标左键或右键的压下

    //This signal is emitted when a mouse button is left-clicked.
    //The item the mouse was clicked on is specified by index.
    void       clicked(const QModelIndex & index); //鼠标左键的一次完成的点击操作。
    void doubleClicked(const QModelIndex & index);
    //This signal is emitted when a mouse button is double-clicked.
    //The item the mouse was double-clicked on is specified by index.
    //The signal is only emitted when the index is valid.

    //总之,基类视图提供的信号函数很简单,这也可能是又出现选择模型的意义。

}; //完结 class QAbstractItemView : public QAbstractScrollArea

Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractItemView::EditTriggers)

QT_END_NAMESPACE

#endif // QABSTRACTITEMVIEW_H

(19)

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangzhangkeji

谢谢支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值