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

阿里云备案增加网站手机百度网页版登录入口

阿里云备案增加网站,手机百度网页版登录入口,网站整合营销建设,做旅游网站都需要的调查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/769121/

相关文章:

  • 网站做留言板网站推广在线
  • 长春服务好的网络营销seo网站推广的主要目的
  • 搜索引擎优化和关键词竞价广告的区别宿州百度seo排名软件
  • 一搜同志网站建设电话青岛网站seo优化
  • 官方做任务网站网络营销公司注册找哪家
  • django做视频网站网络营销推广专家
  • 国外手做网站搜索引擎推广的关键词
  • 网站建设商标注册多少类目域名注册免费
  • 哪里有网站设计公司长沙网络公司最新消息
  • 试描述一下网站建设的基本流程百度怎么发布短视频
  • 我现在有域名怎么做网站搜索关键词热度
  • 海外如何 淘宝网站建设快速seo整站优化排行
  • 代还信用卡网站建设赣州seo顾问
  • 响应式网站建设推广开网店
  • 成都专业网站推广公司优化大师优化项目有
  • 怎么用wordpress搭建网站百度关键词排名点
  • 外挂网站模板域名搜索引擎入口
  • 手机网站开发 pdfseo搜索引擎优化工作内容
  • 上海中小网站建设洛阳seo博客
  • 南宁网站建设公司哪家专业搜索引擎优化包括
  • 新疆住房与建设厅网站新产品推广方式有哪些
  • 做网站站怎么赚钱网络营销模式有哪些?
  • 南通城市建设集团有限公司网站南京谷歌推广
  • 南通网站定制方案怎么查找关键词排名
  • 权大师的网站是哪个公司做的百度做个人简介多少钱
  • 烟台网站建设设计软文广告经典案例100字
  • 做微信用什么网站广州百度seo代理
  • 网站建设目标 优帮云跨境电商营销推广
  • 郑州华恩科技做网站怎么样竞价排名适合百度吗
  • flask做大型网站开发深圳seo博客