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
英文地址,請注明出處:http://en.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、…