QT6 源(130)视图模型架构中的字符串列表模型 QStringListModel:成员函数,本类的继承关系图以及源码注释

(1)字符串列表型的 model ,可以交给视图 view 来显示,也可以由组合框 comboBox 读取其中的内容

在这里插入图片描述

(2)以下开始学习本字符串 model 里的成员函数,本类没有再定义信号与槽函数

在这里插入图片描述

++

在这里插入图片描述

++ 依然是基于同一个例子来做实验

在这里插入图片描述

++ 获得本模型中条目的标志

在这里插入图片描述

(3)读取与设置本模型里的条目里的数据

在这里插入图片描述

++拿本节的子模型测试一下

在这里插入图片描述

++补充,其实本类重新实现了基类里以上的三个成员函数的

在这里插入图片描述

++ 以下是本列表类里的成员函数

在这里插入图片描述

++测试

在这里插入图片描述

++ 再测试

在这里插入图片描述

++ 奇奇怪怪的角色数据

在这里插入图片描述

(4)返回与形参 3的索引在同一父类下的位于 (row, column) 坐标处的同伴的索引。故形参 3不可为空

在这里插入图片描述

(5)模型里元素条目的插入与删除

在这里插入图片描述

++测试

在这里插入图片描述

(6)模型内行的移动

在这里插入图片描述

++ 给出测试

在这里插入图片描述

(7)拖动模型里的条目

在这里插入图片描述

(8)给出本类的继承关系

在这里插入图片描述

(9)至此,本字符串列表模型 QStringListModel 的源码阅读完毕,给出带了一些注释的源码,本类定义在头文件 qstringlistmodel . h

#ifndef QSTRINGLISTMODEL_H
#define QSTRINGLISTMODEL_H#include <QtCore/qabstractitemmodel.h>
#include <QtCore/qstringlist.h>QT_REQUIRE_CONFIG(stringlistmodel);QT_BEGIN_NAMESPACE/*
The QStringListModel class provides a model that supplies strings to views.QStringListModel是一种可编辑的模型,适用于简单场景,
即需要在视图小部件(如 QListView 或 QComboBox)中显示一系列字符串。
QStringListModel is an editable model that can be used for simple caseswhere you need to display a number of strings in a view widget,such as a QListView or a QComboBox.该模型提供了可编辑模型的所有标准功能,它将字符串列表中的数据表示为一个具有一列且行数等于列表中项目数量的模型。
The model provides all the standard functions of an editable model,
representing the data in the string list as a model with one column anda number of rows equal to the number of items in the list.模型索引对应于项目通过index()函数获得,项目标志通过flags()获得。
项目数据通过data()函数读取,并使用setData()写入。
行数(以及字符串列表中的项目数量)可以通过rowcount()函数找到。
Model indexes corresponding to items are obtained with the index() function,
and item flags are obtained with flags().
Item data is read with the data() function and written with setData().
The number of rows (and number of items in the string list)can be found with the rowCount() function.模型可以使用现有的字符串列表进行构建,或者可以稍后使用setstringList()便捷函数设置字符串列表。
字符串也可以通过insertRows()函数以常规方式插入,并使用removeRows()移除。
可以通过stringList()便利函数获取字符串列表的内容。
The model can be constructed with an existing string list,
or strings can be set later with the setStringList() convenience function.
Strings can also be inserted in the usual way with the insertRows() function,
and removed with removeRows().
The contents of the string list can be retrieved with the stringList() convenience function.*/class Q_CORE_EXPORT QStringListModel : public QAbstractListModel
{Q_OBJECTprivate:Q_DISABLE_COPY(QStringListModel)QStringList lst;    //本类的数据成员 using QStringList = QList<QString>;public://Constructs a string list model with the given parent.explicit QStringListModel(                             QObject * parent = nullptr);explicit QStringListModel(const QStringList & strings, QObject * parent = nullptr);//Constructs a string list model containing the specified strings with the given parent.//Returns the string list used by the model to store data.QStringList      stringList() const;void          setStringList(const QStringList & strings); //本函数会触发信号以更新绑定的视图//Sets the model's internal string list to strings.//The model will notify any attached views that its underlying data has changed.//enum Qt::SortOrder { AscendingOrder, DescendingOrder };void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;//Reimplements: QAbstractItemModel::sort(int column, Qt::SortOrder order).//Reimplements: QAbstractItemModel::rowCount(const QModelIndex & parent) const.//返回模型中行的数量。该值对应于模型内部字符串列表中的项目数量。//在大多数模型中,可选的父项参数 parent 用于指定要计数的行的父项。// 由于这是一个列表,如果指定了有效的父项,则结果将始终为0。int rowCount(const QModelIndex & parent = QModelIndex()) const override;/*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)*/Qt::ItemFlags flags(const QModelIndex & index) const override;//Reimplements: QAbstractListModel::flags(const QModelIndex &index) const.//Returns the flags for the item with the given index.//Valid items are enabled, selectable, editable, drag enabled and drop enabled.//Reimplements: QAbstractItemModel::data(const QModelIndex &index, int role) const.//Returns data for the specified role, from the item with the given index.//If the view requests an invalid index, an invalid variant is returned.QVariant       data(const QModelIndex & index, // Qt::DisplayRole = 0int     role = Qt::DisplayRole) const override;//QVariant      QModelIndex::data(int     role = Qt::DisplayRole)bool        setData(const QModelIndex & index, //本函会触发模型的 dataChanged()信号const QVariant    & value, // Qt::EditRole    = 2int     role = Qt::EditRole   ) override;//Reimplements: QAbstractItemModel::setData(//                  QModelIndex & index, QVariant & value, int role).//Sets the data for the specified role in the item with the given index in the model,//  to the provided value.//The dataChanged() signal is emitted if the item is changed.//Returns true after emitting the dataChanged() signal.//void QAbstractItemModel::dataChanged( QModelIndex & topLeft,//           QModelIndex & bottomRight, QList<int>  & roles = QList<int>());//Reimplements: QAbstractItemModel::itemData(const QModelIndex & index) const.QMap<int, QVariant>    itemData(const QModelIndex & index) const override;//Reimplements: QAbstractItemModel::setItemData(index, QMap<int, QVariant> & roles).//If roles contains both Qt::DisplayRole = 0 and Qt::EditRole = 2,//  the latter will take precedence。 //EditRole具有更高优先级(而 DecorationRole = 1)bool                setItemData(const QModelIndex & index,const QMap<int, QVariant> & roles) override;bool              clearItemData(const QModelIndex & index) override;//本函也会触发 dataChanged()信号//Reimplements: QAbstractItemModel::clearItemData(const QModelIndex & index).//Removes the data stored in all the roles for the given index. 删除成功则返回 true。//返回与形参 3的索引在同一父类下的位于 (row, column) 坐标处的同伴的索引。故形参 3不可为空。//Reimplements: QAbstractListModel::sibling(int row, int column, QModelIndex & idx).QModelIndex sibling(int row, int column, const QModelIndex & idx) const override;//模型索引也有检测同伴的成员函数 QModelIndex QModelIndex::sibling(int row, int column)//Reimplements: QAbstractItemModel::insertRows(int row, int count, QModelIndex & parent).//Inserts count rows into the model, beginning at the given row.//The parent index of the rows is optional//  and is only used for consistency with QAbstractItemModel.//By default, a null index is specified,//  indicating that the rows are inserted in the top level of the model.//Returns true if the insertion was successful.//对于本字符串列表模型来讲,形参 3 的父节点索引可为空,因为插入的都是顶层节点。bool insertRows(int row, int count, //在本列表里的下表 row 行处插入 count 行条目。const QModelIndex & parent = QModelIndex()) override;bool removeRows(int row, int count, //删除本列表里从行 row 开始的  count 个条目const QModelIndex & parent = QModelIndex()) override;//Reimplements: QAbstractItemModel::removeRows(int row, int count, QModelIndex & parent).//Removes count rows from the model, beginning at the given row.//The parent index of the rows is optional//  and is only used for consistency with QAbstractItemModel.//By default, a null index is specified, indicating that the//  rows are removed in the top level of the model.//Returns true if the row removal was successful.//以下这两个成员函数继承于其基类。这俩函数,也是可以用的。//bool QAbstractItemModel::insertRow(int row, QModelIndex & parent = QModelIndex())//bool QAbstractItemModel::removeRow(int row, QModelIndex & parent = QModelIndex())bool moveRows  (const QModelIndex &      sourceParent, int sourceRow, int count,const QModelIndex & destinationParent, int destinationChild) override;//QAbstractItemModel::moveRows(QModelIndex & sourceParent, int sourceRow, int count,//本类重新实现了基类里的同一函数    QModelIndex & destinationParent, int destinationChild).//以下这个成员函数继承于其基类。也是可以用的。一次只移动模型里的一行元素。//bool moveRow (const QModelIndex & sourceParent     , int sourceRow,//              const QModelIndex & destinationParent, int destinationChild)Qt::DropActions supportedDropActions() const override; //描述拖动模型条目时的语义//Reimplements: QAbstractItemModel::supportedDropActions() const./*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)*/}; //完结 class QStringListModel : public QAbstractListModelQT_END_NAMESPACE#endif // QSTRINGLISTMODEL_H

(10)

谢谢

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/web/86353.shtml
繁体地址,请注明出处:http://hk.pswp.cn/web/86353.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

dockerfile命令及构建+docker-compose安装构建

一&#xff0c;dockerfile常用命令 命令介绍FROM–指定基础镜像LABEL作者信息USER切换运行属主身份WORKDUR切换工作目录ENV用于docker容器设置环境变量RUN用来执行命令行的命令COPY把宿主机文件复制到镜像中去ADD将文件路径复制添加到容器内部路径EXPOSE为容器打开指定要监听的…

数学:逆元,同余

逆元&#xff0c;同余 0.引言1.同余1.1 同余的基本性质1.2 解同余线性方程 2.逆元费马小定理求逆元(m必需为质数&#xff09;扩展欧几里得求逆元&#xff08;使用任意互质的a和m&#xff09; 0.引言 本文讲述什么是逆元&#xff0c;如何求逆元。求逆元的两种常规方法。然后知道…

广州华锐互动:技术与创意双驱动的 VR 先锋​

广州华锐互动能够在众多 VR 公司中崭露头角&#xff0c;离不开其强大的技术实力和源源不断的创意灵感 。在技术研发方面&#xff0c;广州华锐互动组建了一支专业的技术团队&#xff0c;团队成员均具备扎实的技术功底和丰富的行业经验&#xff0c;他们专注于 VR、AR、3D 等核心技…

教育培训教学通用PPT模版

教育培训通用PPT模版&#xff0c;儿童教育PPT模版&#xff0c;公开课件教学PPT模版&#xff0c;读书笔记PPT模版&#xff0c;古风PPT模版&#xff0c;教育教学通用PPT模版 教育培训教学通用PPT模版&#xff1a;https://pan.quark.cn/s/6c2ed020e398

Data Vault 初探(五) —— 定期装载_SQL

说明&#xff1a; 1. 定期装载的周期为每天一次。 2. 每天装载自上次装载后的变化数据 3. 建立源数据库的过渡表用于CDC 4. 建立cdc_time表用于基于时间戳的CDC 5. 因为源库上只有订单销售表有时间属性&#xff0c;所以除了sales_order和sales_order_item拉取变化数据外&#x…

Java虚拟机栈(JVM Stack)详解与工作流程分析

Java虚拟机栈&#xff08;JVM Stack&#xff09;详解与工作流程分析 1. 虚拟机栈核心概念 基本特性 线程私有&#xff1a;每个线程在创建时都会分配一个独立的栈存储内容&#xff1a; 栈帧&#xff08;Stack Frame&#xff09;&#xff1a;每个方法调用对应一个栈帧 生命周期…

Sonarqube:Jenkins触发sonar扫描出现UnsupportedClassVersionError错误处理

文章目录 1、问题现象2、问题根因3、解决思路3.1 解决思路13.2 解决思路23.3 解决思路3 1、问题现象 问题现象&#xff1a;在每次Jenkins触发sonar扫描时&#xff0c;Sonar-scanner扫描器执行都会出现UnsupportedClassVersionError异常&#xff0c;如下&#xff1a; ERROR: …

Spark SQL to_json 函数介绍

目录 前言函数介绍参数说明示例 前言 在Apache Hive中&#xff0c;并没有内置的to_json函数。在Apache Spark SQL中确实有to_json函数,它可以用来将结构化数据&#xff08;如结构化类型或MAP类型&#xff09;转换为JSON字符串。这个功能对于需要将表格数据输出为JSON格式的场景…

《解锁前端潜力:自动化流程搭建秘籍》

当项目逐渐从萌芽走向繁茂&#xff0c;中期阶段对流程优化与效率提升的需求便愈发迫切。搭建一套自动化测试、持续集成与部署的完整流程&#xff0c;已然成为突破瓶颈、保障代码质量与上线效率的关键密钥。这不仅是技术的进阶&#xff0c;更是思维与协作模式的革新。在踏上构建…

计算机体系结构中的片上系统SoC是什么?

计算机体系结构中的片上系统SoC是什么&#xff1f; 片上系统&#xff08;SoC&#xff0c;System on Chip&#xff09; 是一种将计算机或其他电子系统的多个关键组件集成到单一芯片上的集成电路设计。它不仅仅是处理器&#xff08;CPU&#xff09;&#xff0c;而是将处理器、内…

linux虚拟机基础-磁盘扩容详细版本模拟实验

扩容实验参考上一篇博客&#xff1a; https://blog.csdn.net/wenxiaocsdn/article/details/141932877?spm1001.2014.3001.5502 LVM基础知识附录红帽官方文档 配置和管理逻辑卷 | Red Hat Enterprise Linux | 8 | Red Hat Documentation LVM逻辑结构图 LVM 管理命令速查表&…

hbase高可用部署

要实现HBase集群的高可用部署&#xff08;High Availability, HA&#xff09;&#xff0c;核心在于消除单点故障&#xff08;特别是HMaster节点&#xff09;&#xff0c;并确保数据冗余和服务自动恢复。以下是、关键步骤和配置要点&#xff1a; 一、核心配置步骤‌ ‌1.1 启用…

STM32F103ZET6开发板【项目工程创建】+具体实现步骤流程

硬件介绍 芯片为STM32F103ZET6 STM32F103 资源简介 STM32 的优异性 1&#xff0c;超低的价格。8 位机的价格&#xff0c;32 位机的性能&#xff0c;是 STM32 最大的优势。 2&#xff0c;超多的外设。STM32 拥有包括&#xff1a;FMC、TIMER、SPI、IIC、USB、CAN、IIS、SDIO、…

CyberGlove触觉反馈手套遥操作机器人灵巧手解决方案

CyberGlove触觉反馈手套确实可以实时捕捉运动信号和触觉反馈&#xff0c;并将其重新定位到人形机器人上。CyberGlove触觉反馈手套遥操作机器人是通过手套上的传感器捕捉手部动作&#xff0c;将信号传输给机器人&#xff0c;同时接收机器人反馈的触觉信息&#xff0c;实现远程操…

[C#]C# winform部署yolov13目标检测的onnx模型

yolov13官方框架&#xff1a;github.com/iMoonLab/yolov13/releases/tag/yolov13 【测试环境】 vs2019 netframework4.7.2 opencvsharp4.8.0 onnxruntime1.16.3 【效果展示】 【调用代码】 using System; using System.Collections.Generic; using System.ComponentMode…

创客匠人 AI 赋能:创始人 IP 打造的效率革命与信任重构

在注意力经济时代&#xff0c;创始人 IP 面临内容生产效率与信任构建的双重挑战。创客匠人 2025 年战略升级为 “IP 变现整体解决方案服务商”&#xff0c;其推出的 AI 销售信、免训数字人、智能客服三大工具&#xff0c;正通过技术重构破解行业痛点&#xff0c;为知识变现开辟…

飞轮储能VSG控制策略辅助双馈风机一次调频的仿真模型研究

以下是为您撰写的《飞轮储能VSG控制策略辅助双馈风机一次调频的仿真模型研究》技术报告,包含完整的理论分析、控制策略设计及MATLAB/Simulink仿真实现细节: 飞轮储能VSG控制策略辅助双馈风机一次调频的仿真模型研究 摘要 针对双馈感应发电机(DFIG)参与电网一次调频时存在…

临床开发计划:从实验室到市场的战略蓝图

一、临床开发计划概述 1.1 定义与重要性 1.1.1 CDP核心定义 临床开发计划(CDP)是药物、生物制品或医疗器械从实验室走向市场的核心路线图,详细规划临床研究及其策略、时间表和资源需求,以满足监管机构审批要求。 1.1.2 指导意义 CDP为开发团队提供清晰指引,指导资源规划…

【大模型实战】微调Qwen2.5 VL模型,增强目标检测任务。

文章目录 制作数据集使用微调的模型制作数据集 制作数据集 这个章节将详细解析一个将Labelme标注数据集转换为Qwen2.5-VL模型训练格式的Python脚本。该工具实现了图像大小调整、边界框坐标转换和数据格式标准化等功能。生成适用Qwen2.5-VL的数据集。 核心功能概述 图像处理&a…

【python实用小脚本-118】基于Flask的用户认证系统:app.py、forms.py与user.py解析

在当今的网络应用中&#xff0c;用户认证是一个不可或缺的功能。无论是社交平台、电商平台还是企业管理系统&#xff0c;都需要确保只有授权用户才能访问特定的资源。本文将详细介绍一个基于 Flask 框架的用户认证系统&#xff0c;该系统由三个主要文件组成&#xff1a;app.py、…