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

网站建设制作汕头微网站移交

网站建设制作汕头,微网站移交,天元建设集团有限公司 李增启,wordpress产品目录插件一、效果示例图 1.1 自定义表格排序示例图 本文过滤条件为行索引取余2等于0时返回true#xff0c;且从下图中可以看到#xff0c;奇偶行是各自挨在一起的。 1.2 自定义表格过滤示例图 下图添加两列条件#xff08;当前数据大于当前列条件才返回true#xff0c;且多个列…一、效果示例图 1.1 自定义表格排序示例图 本文过滤条件为行索引取余2等于0时返回true且从下图中可以看到奇偶行是各自挨在一起的。 1.2 自定义表格过滤示例图 下图添加两列条件当前数据大于当前列条件才返回true且多个列条件为且关系下方添加条件分别为”0列条件值50“”2列条件值40“综合下来为0列值大于50且2列值大于40则返回true 二、相关理解 被动触发不论是排序还是过滤都会在添加数据的时候触发自定义排序/过滤函数 主动触发排序可通过数据模型或过滤模型的sort函数触发过滤可通过setFilterRegExp函数触发。此处说的两个函数主动调用后会运行自定义排序/过滤条件前提是对应的函数有重写 过滤此外除开本文写的filterAcceptsRow函数还有filterAcceptsColumn函数其触发条件与filterAcceptsRow一致 三、源码 CMainWindow.h #ifndef CMAINWINDOW_H #define CMAINWINDOW_H#include CSortFilterProxyModel.h#include QMainWindow #include QStandardItemModelnamespace Ui { class CMainWindow; }class CMainWindow : public QMainWindow {Q_OBJECTpublic:explicit CMainWindow(QWidget *parent nullptr);~CMainWindow();private slots:/*** brief on_btnCustom_clicked 自定义条件添加响应函数*/void on_btnCustom_clicked();/*** brief on_btnInitData_clicked 数据初始化响应函数*/void on_btnInitData_clicked();private:Ui::CMainWindow *ui;QStandardItemModel *m_model; // 数据模型CSortFilterProxyModel *m_customFilterModel; // 自定义过滤器模型 };#endif // CMAINWINDOW_H CMainWindow.cpp #include CMainWindow.h #include ui_CMainWindow.h#include QMessageBoxCMainWindow::CMainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::CMainWindow) {ui-setupUi(this);// 数据模型对象创建m_model new QStandardItemModel;// 自定义过滤器类对象创建m_customFilterModel new CSortFilterProxyModel;// 设置数据源模型m_customFilterModel-setSourceModel(m_model);// 先将正常数据模型类设置到表格中ui-tableView-setModel(m_customFilterModel);// 设置表格可排序设置过后通过自定义lessThan函数排序ui-tableView-setSortingEnabled(true); }CMainWindow::~CMainWindow() {// 释放内存空间delete m_customFilterModel;delete m_model;delete ui; }void CMainWindow::on_btnCustom_clicked() {// 获取条件字符串QString colStr ui-editCol-text();QString conditionStr ui-editCondition-text();if(colStr.isEmpty() || conditionStr.isEmpty()){QMessageBox::information(this, 提示, 条件值为空请输入条件);return;}// 获取条件并将其添加到自定义模型中m_customFilterModel-appendCondition(ui-editCol-text().toInt(), ui-editCondition-text().toInt());// 条件列和条件值编辑框清空ui-editCol-clear();ui-editCondition-clear();// 通过设置过滤条件触发自定义过滤此处条件不会影响自定义过滤m_customFilterModel-setFilterRegExp(); }void CMainWindow::on_btnInitData_clicked() {// 虽然表格上是过滤模型但是数据还是得设置到数据模型上才可for(int row 0; row ! 10; row){for(int col 0; col ! 10; col){// 设置当前行列的item, 并初始化随机值m_model-setItem(row, col, new QStandardItem(QString::number(rand() % 100)));}} } CMainWindow.ui ?xml version1.0 encodingUTF-8? ui version4.0classCMainWindow/classwidget classQMainWindow nameCMainWindowproperty namegeometryrectx0/xy0/ywidth821/widthheight525/height/rect/propertyproperty namewindowTitlestringCMainWindow/string/propertywidget classQWidget namecentralWidgetlayout classQGridLayout namegridLayoutitem row2 column1widget classQLineEdit nameeditConditionproperty nametextstring//propertyproperty nameplaceholderTextstring条件值/string/property/widget/itemitem row2 column0widget classQLineEdit nameeditColproperty nametextstring//propertyproperty nameplaceholderTextstring列/string/property/widget/itemitem row4 column0 colspan3widget classQTableView nametableView//itemitem row1 column0widget classQPushButton namebtnInitDataproperty nametextstring初始化数据/string/property/widget/itemitem row1 column1widget classQPushButton namebtnCustomproperty nametextstring添加自定义模型条件/string/property/widget/item/layout/widgetwidget classQMenuBar namemenuBarproperty namegeometryrectx0/xy0/ywidth821/widthheight23/height/rect/property/widgetwidget classQToolBar namemainToolBarattribute nametoolBarAreaenumTopToolBarArea/enum/attributeattribute nametoolBarBreakboolfalse/bool/attribute/widgetwidget classQStatusBar namestatusBar//widgetlayoutdefault spacing6 margin11/resources/connections/ /ui CSortFilterProxyModel.h #ifndef CSORTFILTERPROXYMODEL_H #define CSORTFILTERPROXYMODEL_H#include QSortFilterProxyModelclass CSortFilterProxyModel : public QSortFilterProxyModel {Q_OBJECT public:explicit CSortFilterProxyModel(QObject *parent nullptr);/*** brief appendCondition 追加条件函数* param col 条件列* param val 条件值*/void appendCondition(int col, int val);// QSortFilterProxyModel interface protected:/*** brief filterAcceptsRow 过滤行函数* param source_row 当前行索引* param source_parent 当前行父对象没有则为空* return 过滤结果*/bool filterAcceptsRow(int source_row, const QModelIndex source_parent) const;/*** brief lessThan 排序函数* param source_left 比较的左值* param source_right 比较的右值* return 比较结果*/bool lessThan(const QModelIndex source_left, const QModelIndex source_right) const;private:QMapint, int m_mapFilterCondition; // 条件值保存容器列 条件值};#endif // CSORTFILTERPROXYMODEL_H CSortFilterProxyModel.cpp #include CSortFilterProxyModel.h#include QDebug #include QStandardItemModelCSortFilterProxyModel::CSortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent) {}void CSortFilterProxyModel::appendCondition(int col, int val) {// 直接赋值不存在会添加已存在会更新m_mapFilterCondition[col] val; }bool CSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex source_parent) const {// 定义返回值变量bool ret true;// 获取数据源模型对象并转换为需要的类型模板QStandardItemModel *srcModel dynamic_castQStandardItemModel *(sourceModel());if(nullptr ! srcModel){foreach(int col, m_mapFilterCondition.keys()){// 获取当前的item对象QStandardItem *item srcModel-item(source_row, col);// 此时对应item不为空且整形值要小于条件值才显示if(nullptr ! item m_mapFilterCondition[col] item-text().toInt()){ret false;break;}}}return ret; }bool CSortFilterProxyModel::lessThan(const QModelIndex source_left, const QModelIndex source_right) const {// 当前行为取余2等于0时返回true(就是说默认降序排序偶数行在前)return 0 source_left.row() % 2; } 总结 虽然自定义排序和过滤比较简单但是在项目中非常实用如需要将某行/列置顶特殊条件过滤等。 友情提示——哪里看不懂可私哦让我们一起互相进步吧 创作不易请留下一个免费的赞叭 谢谢 o/) 注文章为作者编程过程中所遇到的问题和总结内容仅供参考若有错误欢迎指出。 注如有侵权请联系作者删除
http://www.hkea.cn/news/14559481/

相关文章:

  • 有免费的网站建设十大网站排行榜
  • 重庆平台网站建设价格青岛+网站建设
  • 东莞网站建设主要学什么电商网站制作流程图
  • 网站备案中 解析地址平台网站如何做推广方案设计
  • 西安网站建设市场tp框架做网站的优点
  • 义乌好品质自适应网站建设云南网站制作案例
  • 电影网站怎么做网站搜索 收录优化
  • 营销型网站单页域名转发网站
  • 精品资料网官方网站南充市房产信息网
  • 任务发布插件wordpressseo优化专家
  • 手机创建个人网站 免费网站域名备案需要什么
  • 手机网站建设分析厦门seo排名优化
  • 赣icp南昌网站建设html网站开发项目
  • 工信网备案网站不用源码做网站
  • 基础微网站开发动态龙采哈尔滨建站公司
  • 网站建设的页面要求vps网站能打开
  • 官方网站、门户网站是什么意思?youhosting wordpress
  • 移动应用开发公司网站模板百度贴吧怎么做推广
  • 免费的静态网站托管一二三四视频社区在线一中文
  • 网站内链怎么删除滨河网站建设
  • 南京免费发布信息网站wordpress小工具空格
  • 营销型设计网站网龙网络公司地址
  • 陕西住房和城乡建设部网站保定网站优化哪家好
  • 济南公司做网站goodnex drupal7企业wordpress模板
  • 衡水做网站技术建站软件排名
  • 如何用腾讯云主机做网站手机网站建设 小程序
  • 网站收录量深圳皇冠科技有限公司网站
  • 如何设置便于搜索引擎收录的网站结构自己模板做网站
  • 江西app网站建设网络营销方案规范
  • 天津市建设工程管理总队网站wordpress文章管理模板