当前位置: 首页 > news >正文

开了个网站用年份做名字好吗如何创建一个app

开了个网站用年份做名字好吗,如何创建一个app,谁家做网站,网站上文章字体部分复制怎么做Fetch More Example这个例子说明了如何在视图模型上添加记录。 这个例子由一个对话框组成,在Directory的输入框中,可输入路径信息。应用程序会载入路径信息的文件信息等。不需要按回车键就能搜索。 当有大量数据时,需要对视图模型进行批量增…

Fetch More Example这个例子说明了如何在视图模型上添加记录。

这个例子由一个对话框组成,在Directory的输入框中,可输入路径信息。应用程序会载入路径信息的文件信息等。不需要按回车键就能搜索。

当有大量数据时,需要对视图模型进行批量增加。

此案例,实现了FileListModel类,此类包含了一个视图模型,这个视图模型获取路径下的文件。

下面来看下FileListModel的代码。

FileListModel Class Definition

FileListModel继承了QAbstractListModel并且存储了路径信息。只有视图自己请求添加项时,才会进行添加。

 class FileListModel : public QAbstractListModel{Q_OBJECTpublic:FileListModel(QObject *parent = 0);int rowCount(const QModelIndex &parent = QModelIndex()) const override;QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;signals:void numberPopulated(int number);public slots:void setDirPath(const QString &path);protected:bool canFetchMore(const QModelIndex &parent) const override;void fetchMore(const QModelIndex &parent) override;private:QStringList fileList;int fileCount;};

比较关键的2个函数是fetchMore()和canFetchMore(),这两个函数都是从QAbstractItemModel中继承下来的。当需要新增模型时,这2个函数就会被触发。

setDirPath()函数设置了当前模型的工作目录。当需要批量设置模型时,就会发出numberPopulated()信号。

所有文件条目都放到fileList里面,fileCount统计条目的数量。

FileListModel Class Implementation

首先来看下setDirPath()。

 void FileListModel::setDirPath(const QString &path){QDir dir(path);beginResetModel();fileList = dir.entryList();fileCount = 0;endResetModel();}

使用QDir获取目录内容。当要从模型中移除所有数据时需要通知QAbstractItemModel。

 bool FileListModel::canFetchMore(const QModelIndex & /* index */) const{if (fileCount < fileList.size())return true;elsereturn false;}

当需要更多项时,canFetchMore()函数会被触发。当不需要新增时此函数返回true,否则返回false。fetchMore()函数如下:

 void FileListModel::fetchMore(const QModelIndex & /* index */){int remainder = fileList.size() - fileCount;int itemsToFetch = qMin(100, remainder);if (itemsToFetch <= 0)return;beginInsertRows(QModelIndex(), fileCount, fileCount+itemsToFetch-1);fileCount += itemsToFetch;endInsertRows();emit numberPopulated(itemsToFetch);}

首先获取每一项的数量。beginInsertRow()和endInsertRow()在QAbstractItemModel中插入新行时,必须要调用的,最后emit numberPopulated()用于更新界面。

最后是rowCount()和data()

int FileListModel::rowCount(const QModelIndex & /* parent */) const{return fileCount;}QVariant FileListModel::data(const QModelIndex &index, int role) const{if (!index.isValid())return QVariant();if (index.row() >= fileList.size() || index.row() < 0)return QVariant();if (role == Qt::DisplayRole) {return fileList.at(index.row());} else if (role == Qt::BackgroundRole) {int batch = (index.row() / 100) % 2;if (batch == 0)return qApp->palette().base();elsereturn qApp->palette().alternateBase();}return QVariant();}

rowCount()函数是已经添加了的新行,不是目录中的条目数。

data()函数,从fileList中返回适当的条目。使用不同的背景颜色来区分。

http://www.hkea.cn/news/398690/

相关文章:

  • div css 网站模板免费的云服务器有哪些
  • 35互联做网站好吗网店运营工作内容
  • 网站建设模拟软件营销培训课程内容
  • 深圳建网站兴田德润专业2023年最新新闻简短摘抄
  • 学校网站怎么查询录取百度相册登录入口
  • 自助建设彩票网站网址查询工具
  • 怎么创建网页的快捷方式seo入门版
  • 互联网企业网站网络优化
  • 山东手工活外发加工网四川二级站seo整站优化排名
  • 行业门户网站开发百度竞价怎么做效果好
  • 适合前端做项目的网站百度网盘搜索
  • 下载网站怎么下载广州网站定制多少钱
  • 西安攻略旅游自由行怎么玩北京seo软件
  • 汉川网站建设sem代运营
  • 装酷网装修平台东莞seo外包
  • 专门做图片的网站吗如何建网站要什么条件
  • 卢氏县住房和城乡建设局网站站长统计 站长统计
  • 济南 网站制作旺道营销软件
  • 新上线网站如何做搜索引擎站长素材网站
  • 做网站编辑深圳疫情防控最新消息
  • PHP网站开发项目式教程google下载手机版
  • 国外专门用于做网站图片的做网站要多少钱
  • 网站维护费用计入什么科目媒介星软文平台官网
  • 网站建设seo 视频做网站哪个平台好
  • 旅行社网站建设方案论文百度seo公司
  • 长沙网站建设与维护百度开户联系方式
  • 做pcr查基因序列的网站南京百度网站快速优化
  • 数据服务网站策划方案关键词快速优化排名软件
  • 响应式网站缺点学大教育培训机构电话
  • 江苏天德建设工程有限公司网站一个平台怎么推广