QRangeModelAdapter::DataReference Struct
struct QRangeModelAdapter::DataReferenceDataReference 是围绕QRangeModel 中某项内容构建的引用封装器。更多内容...
该结构体处于技术预览阶段,可能会有变动。
该结构体于 Qt 6.11 版本中引入。
公共类型
公共函数
| DataReference(const QModelIndex &index) | |
| DataReference(const QRangeModelAdapter<Range, Protocol, Model>::DataReference &other) | |
| DataReference(QRangeModelAdapter<Range, Protocol, Model>::DataReference &&other) | |
| ~DataReference() | |
| QRangeModelAdapter<Range, Protocol, Model>::DataReference::const_value_type | get() const |
| bool | isValid() const |
| operator QRangeModelAdapter<Range, Protocol, Model>::DataReference::const_value_type() const | |
| QRangeModelAdapter<Range, Protocol, Model>::DataReference::pointer | operator->() const |
| QRangeModelAdapter<Range, Protocol, Model>::DataReference & | operator=(QRangeModelAdapter<Range, Protocol, Model>::DataReference &&other) |
| QRangeModelAdapter<Range, Protocol, Model>::DataReference & | operator=(QRangeModelAdapter<Range, Protocol, Model>::DataReference::value_type &&value) |
| QRangeModelAdapter<Range, Protocol, Model>::DataReference & | operator=(const QRangeModelAdapter<Range, Protocol, Model>::DataReference &other) |
| QRangeModelAdapter<Range, Protocol, Model>::DataReference & | operator=(const QRangeModelAdapter<Range, Protocol, Model>::DataReference::value_type &value) |
详细说明
使用at()的非const重载、下标operator[] ,或解引用非const的iterator 来访问模型中的项目,将返回一个围绕模型中该项目的DataReference包装器。
对该引用包装器进行赋值会通过QAbstractItemModel API 更改模型中的数据。
adapter[0] = newValue;可以使用get() 或 operator->() 访问该值本身的 const 版本。
QRangeModelAdapter adapter(QList<Gadget>{ ~~~ });
auto value = adapter[0]->value();
// adapter[0]->setValue(); // not allowed - would not emit dataChanged()与 `std::reference_wrapper` 不同,将一个 `DataReference` 赋值给另一个不会重新绑定引用,而是使用复制语义设置值。
adapter[0] = adapter[1]; // items at row 0 and row 1 now have the same value另请参阅 RowReference 和ConstRowReference 。
成员类型文档
[alias] DataReference::const_value_type
这是存储在底层范围中的项的 const 类型的别名。如果模型中不同列的类型不同,则此别名对应于 `const QVariant`。
[alias] DataReference::pointer
operator->() 返回的指针类型的别名。
[alias] DataReference::value_type
这是存储在底层范围中的项的类型的别名。如果模型中的不同列具有不同的类型,则此别名对应于QVariant 。
成员函数文档
[explicit noexcept] DataReference::DataReference(const QModelIndex &index)
为位于index 的项目创建一个 DataReference 封装对象。
[default] DataReference::DataReference(const QRangeModelAdapter<Range, Protocol, Model>::DataReference &other)
创建other 的副本。
[default] DataReference::DataReference(QRangeModelAdapter<Range, Protocol, Model>::DataReference &&other)
通过从other 移动,构建一个DataReference。
[default] DataReference::~DataReference()
销毁DataReference 的实例。
QRangeModelAdapter<Range, Protocol, Model>::DataReference::const_value_type DataReference::get() const
DataReference::operator QRangeModelAdapter<Range, Protocol, Model>::DataReference::const_value_type() const
将此DataReference 所引用的项目值作为常量值返回。
bool DataReference::isValid() const
如果此DataReference 指向一个有效的模型索引,则返回true。
QRangeModelAdapter<Range, Protocol, Model>::DataReference::pointer DataReference::operator->() const
返回指向该DataReference 所引用的值的指针。
QRangeModelAdapter<Range, Protocol, Model>::DataReference &DataReference::operator=(QRangeModelAdapter<Range, Protocol, Model>::DataReference &&other)
将位于other 处的值引用移动到该包装器所引用的值中。
QRangeModelAdapter<Range, Protocol, Model>::DataReference &DataReference::operator=(QRangeModelAdapter<Range, Protocol, Model>::DataReference::value_type &&value)
将value 移动并赋值给底层模型项。
QRangeModelAdapter<Range, Protocol, Model>::DataReference &DataReference::operator=(const QRangeModelAdapter<Range, Protocol, Model>::DataReference &other)
将other 所引用的项目值赋给此包装器所引用的值。
QRangeModelAdapter<Range, Protocol, Model>::DataReference &DataReference::operator=(const QRangeModelAdapter<Range, Protocol, Model>::DataReference::value_type &value)
将value 分配给底层模型项。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.