QAbstractProxyModel 类为代理项模型提供可以履行排序、过滤或其它数据处理任务的基类。 更多...
头: | #include <QAbstractProxyModel> |
CMake: |
find_package(Qt6 COMPONENTS Core REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
继承: | QAbstractItemModel |
继承者: | QIdentityProxyModel , QSortFilterProxyModel ,和 QTransposeProxyModel |
QAbstractProxyModel (QObject * parent = nullptr) | |
virtual | ~QAbstractProxyModel () |
virtual QModelIndex | mapFromSource (const QModelIndex & sourceIndex ) const = 0 |
virtual QItemSelection | mapSelectionFromSource (const QItemSelection & sourceSelection ) const |
virtual QItemSelection | mapSelectionToSource (const QItemSelection & proxySelection ) const |
virtual QModelIndex | mapToSource (const QModelIndex & proxyIndex ) const = 0 |
virtual void | setSourceModel (QAbstractItemModel * sourceModel ) |
QAbstractItemModel * | sourceModel () const |
virtual QModelIndex | buddy (const QModelIndex & index ) const override |
virtual bool | canDropMimeData (const QMimeData * data , Qt::DropAction action , int row , int column , const QModelIndex & parent ) const override |
virtual bool | canFetchMore (const QModelIndex & parent ) const override |
virtual bool | clearItemData (const QModelIndex & index ) override |
virtual QVariant | data (const QModelIndex & proxyIndex , int role = Qt::DisplayRole) const override |
virtual bool | dropMimeData (const QMimeData * data , Qt::DropAction action , int row , int column , const QModelIndex & parent ) override |
virtual void | fetchMore (const QModelIndex & parent ) override |
virtual Qt::ItemFlags | flags (const QModelIndex & index ) const override |
virtual bool | hasChildren (const QModelIndex & parent = QModelIndex()) const override |
virtual QVariant | headerData (int section , Qt::Orientation orientation , int role = Qt::DisplayRole) const override |
virtual QMap<int, QVariant> | itemData (const QModelIndex & proxyIndex ) const override |
virtual QMimeData * | mimeData (const QModelIndexList & indexes ) const override |
virtual QStringList | mimeTypes () const override |
virtual void | revert () override |
virtual QHash<int, QByteArray> | roleNames () const override |
virtual bool | setData (const QModelIndex & index , const QVariant & value , int role = Qt::EditRole) override |
virtual bool | setHeaderData (int section , Qt::Orientation orientation , const QVariant & value , int role = Qt::EditRole) override |
virtual bool | setItemData (const QModelIndex & index , const QMap<int, QVariant> & roles ) override |
virtual QModelIndex | sibling (int row , int column , const QModelIndex & idx ) const override |
virtual void | sort (int column , Qt::SortOrder order = Qt::AscendingOrder) override |
virtual QSize | span (const QModelIndex & index ) const override |
virtual bool | submit () override |
virtual Qt::DropActions | supportedDragActions () const override |
virtual Qt::DropActions | supportedDropActions () const override |
void | sourceModelChanged () |
QModelIndex | createSourceIndex (int row , int col , void * internalPtr ) const |
This class defines the standard interface that proxy models must use to be able to interoperate correctly with other model/view components. It is not supposed to be instantiated directly.
All standard proxy models are derived from the QAbstractProxyModel class. If you need to create a new proxy model class, it is usually better to subclass an existing class that provides the closest behavior to the one you want to provide.
Proxy models that filter or sort items of data from a source model should be created by using or subclassing QSortFilterProxyModel .
To subclass QAbstractProxyModel, you need to implement mapFromSource () 和 mapToSource ()。 mapSelectionFromSource () 和 mapSelectionToSource () functions only need to be reimplemented if you need a behavior different from the default behavior.
注意: If the source model is deleted or no source model is specified, the proxy model operates on a empty placeholder model.
另请参阅 QSortFilterProxyModel , QAbstractItemModel ,和 模型/视图编程 .
[bindable]
sourceModel
:
QAbstractItemModel
*
注意: 此特性支持 QProperty 绑定。
此特性保持此代理模型的源模型。
Constructs a proxy model with the given parent .
[virtual]
QAbstractProxyModel::
~QAbstractProxyModel
()
Destroys the proxy model.
[override virtual]
QModelIndex
QAbstractProxyModel::
buddy
(const
QModelIndex
&
index
) const
重实现: QAbstractItemModel::buddy (const QModelIndex &index) const.
[override virtual, since 5.4]
bool
QAbstractProxyModel::
canDropMimeData
(const
QMimeData
*
data
,
Qt::DropAction
action
,
int
row
,
int
column
, const
QModelIndex
&
parent
) const
重实现: QAbstractItemModel::canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const.
该函数在 Qt 5.4 引入。
[override virtual]
bool
QAbstractProxyModel::
canFetchMore
(const
QModelIndex
&
parent
) const
重实现: QAbstractItemModel::canFetchMore (const QModelIndex &parent) const.
[override virtual, since 6.0]
bool
QAbstractProxyModel::
clearItemData
(const
QModelIndex
&
index
)
重实现: QAbstractItemModel::clearItemData (const QModelIndex &index).
该函数在 Qt 6.0 引入。
[protected, since 6.2]
QModelIndex
QAbstractProxyModel::
createSourceIndex
(
int
row
,
int
col
,
void
*
internalPtr
) const
Equivalent to calling createIndex on the source model.
This method is useful if your proxy model wants to maintain the parent-child relationship of items in the source model. When reimplementing mapToSource (), you can call this method to create an index for row row and column col of the source model.
A typical use would be to save the internal pointer coming from the source model in the proxy index when reimplementing mapFromSource () and use the same internal pointer as internalPtr to recover the original source index when reimplementing mapToSource ().
该函数在 Qt 6.2 引入。
[override virtual]
QVariant
QAbstractProxyModel::
data
(const
QModelIndex
&
proxyIndex
,
int
role
= Qt::DisplayRole) const
重实现: QAbstractItemModel::data (const QModelIndex &index, int role) const.
另请参阅 setData ().
[override virtual, since 5.4]
bool
QAbstractProxyModel::
dropMimeData
(const
QMimeData
*
data
,
Qt::DropAction
action
,
int
row
,
int
column
, const
QModelIndex
&
parent
)
重实现: QAbstractItemModel::dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent).
该函数在 Qt 5.4 引入。
[override virtual]
void
QAbstractProxyModel::
fetchMore
(const
QModelIndex
&
parent
)
重实现: QAbstractItemModel::fetchMore (const QModelIndex &parent).
[override virtual]
Qt::ItemFlags
QAbstractProxyModel::
flags
(const
QModelIndex
&
index
) const
重实现: QAbstractItemModel::flags (const QModelIndex &index) const.
[override virtual]
bool
QAbstractProxyModel::
hasChildren
(const
QModelIndex
&
parent
= QModelIndex()) const
重实现: QAbstractItemModel::hasChildren (const QModelIndex &parent) const.
[override virtual]
QVariant
QAbstractProxyModel::
headerData
(
int
section
,
Qt::Orientation
orientation
,
int
role
= Qt::DisplayRole) const
重实现: QAbstractItemModel::headerData (int section, Qt::Orientation orientation, int role) const.
另请参阅 setHeaderData ().
[override virtual]
QMap
<
int
,
QVariant
> QAbstractProxyModel::
itemData
(const
QModelIndex
&
proxyIndex
) const
重实现: QAbstractItemModel::itemData (const QModelIndex &index) const.
另请参阅 setItemData ().
[pure virtual invokable]
QModelIndex
QAbstractProxyModel::
mapFromSource
(const
QModelIndex
&
sourceIndex
) const
Reimplement this function to return the model index in the proxy model that corresponds to the sourceIndex from the source model.
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
另请参阅 mapToSource ().
[virtual invokable]
QItemSelection
QAbstractProxyModel::
mapSelectionFromSource
(const
QItemSelection
&
sourceSelection
) const
Returns a proxy selection mapped from the specified sourceSelection .
Reimplement this method to map source selections to proxy selections.
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
[virtual invokable]
QItemSelection
QAbstractProxyModel::
mapSelectionToSource
(const
QItemSelection
&
proxySelection
) const
Returns a source selection mapped from the specified proxySelection .
Reimplement this method to map proxy selections to source selections.
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
[pure virtual invokable]
QModelIndex
QAbstractProxyModel::
mapToSource
(const
QModelIndex
&
proxyIndex
) const
Reimplement this function to return the model index in the source model that corresponds to the proxyIndex in the proxy model.
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
另请参阅 mapFromSource ().
[override virtual]
QMimeData
*QAbstractProxyModel::
mimeData
(const
QModelIndexList
&
indexes
) const
重实现: QAbstractItemModel::mimeData (const QModelIndexList &indexes) const.
[override virtual]
QStringList
QAbstractProxyModel::
mimeTypes
() const
重实现: QAbstractItemModel::mimeTypes () const.
[override virtual]
void
QAbstractProxyModel::
revert
()
重实现: QAbstractItemModel::revert ().
[override virtual]
QHash
<
int
,
QByteArray
> QAbstractProxyModel::
roleNames
() const
重实现: QAbstractItemModel::roleNames () const.
[override virtual]
bool
QAbstractProxyModel::
setData
(const
QModelIndex
&
index
, const
QVariant
&
value
,
int
role
= Qt::EditRole)
重实现: QAbstractItemModel::setData (const QModelIndex &index, const QVariant &value, int role).
另请参阅 data ().
[override virtual]
bool
QAbstractProxyModel::
setHeaderData
(
int
section
,
Qt::Orientation
orientation
, const
QVariant
&
value
,
int
role
= Qt::EditRole)
重实现: QAbstractItemModel::setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role).
另请参阅 headerData ().
[override virtual]
bool
QAbstractProxyModel::
setItemData
(const
QModelIndex
&
index
, const
QMap
<
int
,
QVariant
> &
roles
)
重实现: QAbstractItemModel::setItemData (const QModelIndex &index, const QMap<int, QVariant> &roles).
另请参阅 itemData ().
[virtual]
void
QAbstractProxyModel::
setSourceModel
(
QAbstractItemModel
*
sourceModel
)
设置给定 sourceModel to be processed by the proxy model.
Subclasses should call beginResetModel () at the beginning of the method, disconnect from the old model, call this method, connect to the new model, and call endResetModel ().
注意: Setter 函数对于特性 sourceModel .
另请参阅 sourceModel ().
[override virtual]
QModelIndex
QAbstractProxyModel::
sibling
(
int
row
,
int
column
, const
QModelIndex
&
idx
) const
重实现: QAbstractItemModel::sibling (int row, int column, const QModelIndex &index) const.
[override virtual]
void
QAbstractProxyModel::
sort
(
int
column
,
Qt::SortOrder
order
= Qt::AscendingOrder)
重实现: QAbstractItemModel::sort (int column, Qt::SortOrder order).
Returns the model that contains the data that is available through the proxy model.
注意: Getter function for property sourceModel.
另请参阅 setSourceModel ().
[override virtual]
QSize
QAbstractProxyModel::
span
(const
QModelIndex
&
index
) const
重实现: QAbstractItemModel::span (const QModelIndex &index) const.
[override virtual]
bool
QAbstractProxyModel::
submit
()
重实现: QAbstractItemModel::submit ().
[override virtual]
Qt::DropActions
QAbstractProxyModel::
supportedDragActions
() const
重实现: QAbstractItemModel::supportedDragActions () const.
[override virtual]
Qt::DropActions
QAbstractProxyModel::
supportedDropActions
() const
重实现: QAbstractItemModel::supportedDropActions () const.