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

建材 东莞网站建设网店推广的常用方法有哪些

建材 东莞网站建设,网店推广的常用方法有哪些,苏州做儿童场馆门票包票的网站,研究院网站模板QSortFilterProxyModel是model的代理#xff0c;不能单独使用#xff0c;真正的数据需要另外的一个model提供#xff0c;它的工鞥呢是对被代理的model(source model)进行排序和过滤。所谓过滤#xff1a;也就是说按着你输入的内容进行数据的筛选#xff0c;因为器过滤功能…QSortFilterProxyModel是model的代理不能单独使用真正的数据需要另外的一个model提供它的工鞥呢是对被代理的model(source model)进行排序和过滤。所谓过滤也就是说按着你输入的内容进行数据的筛选因为器过滤功能是基本正则表达式所以功能强大。QsortFilterProxyModel类用来为model和view之间提供强大的排序和过滤支持。将模型排序或者过滤后在视图上显示,并且无需对模型中的数据进行任何转换也无需对模型在中数据进行修改 1 QSortFilterProxyModel使用提要 使用过滤器需要指定一个数据模型QStandardItemModel作为数据源并且该数据模型无需设置到表对象上 过滤器指定好数据源后设置到表对象上即可正常使用 过滤器不指定过滤列时默认过滤列为0列 2.QSortFilterProxyModel自定义排序 自定义排序需要子类化QsortFilterProxyModel,然后重写lessThan().注意 : 如果重写了lessThan(),那么就不会再调用model的sort方法了. lessThan()使用示例 bool SortFilterProxyModel::lessThan(const QModelIndex source_left, const QModelIndex source_right) const {//通过当前视图中的index位置获取model中实际的数据QVariant leftData sourceModel()-data(source_left);QVariant rightData sourceModel()-data(source_right);switch ( source_left.column() ){case 0 : //序号,需要判断数字case 3 : //信号ID,需要判断数字return leftData.toInt() rightData.toInt();break;default : //其它,只判断字符串return leftData.toString() rightData.toString();break;}return true; }除了排序外QSortFilterProxyModel还可以用来隐藏与某个过滤器不匹配的项。使用QRegExp对象指定筛选器并将筛选器应用于给定列的每个项的filterRole() 默认情况下为Qt::DisplayRole。QRegExp对象可用于匹配正则表达式、通配符模式或固定字符串。 3.过滤方法1-使用setFilterKeyColumn()过滤列 首先需要通过void QsortFilterProxyModel::setFilterRegExp(const QRegExp ®Exp)来设置FilterProxyModel的过滤器. 然后通过QsortFilterProxyModel::setFilterKeyColumn(int)来过滤某一列.如果要更改大小写匹配,可以通过QsortFilterProxyModel::sortCaseSensitivity()来设置.示例代码如下所示: QTableView *view new QTableView; MyItemModel *sourceModel new MyItemModel(this); QSortFilterProxyModel *proxyModel new QSortFilterProxyModel(this); proxyModel-setSourceModel(sourceModel); //将model放入代理中 view-setModel(proxyModel); //在视图中安装代理QRegExp regExp(^(-?\\d)(\\.\\d)?$, Qt::CaseSensitive, QRegExp::RegExp); //通过^(-?\d)(\.\d)?$来匹配整数 proxyModel-setFilterRegExp(regExp); //安装过滤器proxyModel-setFilterKeyColumn(0); proxyModel-setFilterKeyColumn(2); //将第一列和第三列同时是整数的数据显示出来.每当过滤格式改变,则setFilterRegExp()重新更新过滤器即可. 弊端:但是这样只能与方式显示model,要第一列和第三列公共是整数的才能显示出来,不能实现或方式显示. 所以,如果要使用联合多列过滤,建议使用过滤方法2来实现. 4.过滤方法2-重写filterAcceptsRow成员函数 以实现只要第一列有整数或者第三列有整数的都显示出来为例,首先需要子类化QsortFilterProxyModel类,然后重写filterAcceptsRow()或者filterAcceptsColumn()函数. 由于我们筛选第一列和第三列,列号是明确的,而行号是未知的, 所以我们只重写filterAcceptsRow()函数. 示例代码如下所示: bool SortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex source_parent) const {//获取model中实际的数据QString dataColumn1 sourceModel()-index(source_row, 0, source_parent).data(Qt::DisplayRole).toString();QString dataColumn3 sourceModel()-index(source_row, 2, source_parent).data(Qt::DisplayRole).toString();if(dataColumn1.contains(this-filterRegExp())) {return true;}else if(dataColumn3.contains(this-filterRegExp())) {return true;}return false; }然后创建SortFilterProxyModel类时,只需要安装过滤器即可: SortFilterProxyModel *proxyModel new SortFilterProxyModel(); proxyModel-setSourceModel(sourceModel); //将model放入代理中 treeView-setModel(proxyModel); //在视图中安装代理 proxyModel-setFilterRegExp(^(-?\\d)(\\.\\d)?$); //安装过滤器每当过滤格式改变,则setFilterRegExp()重新更新过滤器即可. 注意事项: 如果过滤方式改变了,比如从过滤第1列变成了过滤第2列,需要调用invalidateFilter()函数,使之前的过滤失效,激活当前过滤. setSourceModel用于设置哪个model被代理 setSortCaseSensitivity用来设置排序时是否区分大小写 setFilterKeyColumn用来制定当前过滤的列参数为列好 setFiliterRegExp用于设置过滤时的筛选规则参数类型为QRegExpHardwareLogWidget.h class CHardwareLogWidget : public QWidget{Q_OBJECTpublic:CHardwareLogWidget(QWidget *parent Q_NULLPTR);~CHardwareLogWidget();protected:void showEvent(QShowEvent *event);private slots:// 重置筛选条件void onReset();// 查询void onQuery();// 导出void onExport();private:// 初始化原始modelvoid initialModel();std::vectorHardWareOperateLogStr getFilterLog();private:Ui::CHardwareLogWidget ui;CLogProxyModel *m_pLogProxyModel{ nullptr }; // 数据模型对象指针QStandardItemModel *m_pRrecordModel{ nullptr }; // 数据模型对象指针};HardwareLogWidget.cpp CHardwareLogWidget::CHardwareLogWidget(QWidget *parent): QWidget(parent) {ui.setupUi(this);connect(ui.m_pBtnReset, SIGNAL(clicked()), this, SLOT(onReset()));connect(ui.m_pBtnQuery, SIGNAL(clicked()), this, SLOT(onQuery())); connect(ui.m_pBtnExport, SIGNAL(clicked()), this, SLOT(onExport()));ui.m_pLineEditUserName-setValidator(new QRegExpValidator(QRegExp([a-zA-Z0-9]{1,16})));// 弹出日历的形式ui.dateTimeEdit-setCalendarPopup(true);ui.dateTimeEdit_2-setCalendarPopup(true);// 全部/添加用户/删除用户...ui.m_pComboType-addItem(tr(All));for (int i UserAdd; i EquipmentModify; i){ui.m_pComboType-addItem(CLogTypeConverter::logtype2String(static_castHardWareOperateType(i)));}// 设置的选择0好索引ui.m_pComboType-setCurrentIndex(0);//数据模型QStandardItemModel//建立数据模型对象空间并指定父对象// 设置以项数据item data为基础的标准数据模型m_pRrecordModel new QStandardItemModel(this);// 添加列标题m_pRrecordModel-setHorizontalHeaderItem(0, new QStandardItem(tr(Operate Time)));m_pRrecordModel-setHorizontalHeaderItem(1, new QStandardItem(tr(User name)));m_pRrecordModel-setHorizontalHeaderItem(2, new QStandardItem(tr(Operate Type)));m_pRrecordModel-setHorizontalHeaderItem(3, new QStandardItem(tr(Operate Detail)));for (size_t i 0; i 4; i){m_pRrecordModel-horizontalHeaderItem(i)-setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);}//过滤器模型QSortFilterProxyModel//建立过滤器模型对象空间并指定父对象// 设置CLogProxyModel::QSortFilterProxyModel代理m_pLogProxyModel new CLogProxyModel(this);// 指定过滤器模型的数据源模型m_pLogProxyModel-setSourceModel(m_pRrecordModel);// 指定初始化过滤列m_pFilterModel-setFilterKeyColumn(0);//! 将过滤器模型设置到表对象上//! 数据模型就单纯当过滤器模型的数据源即可ui-tableView-setModel(m_pFilterModel);// 获取tableView的水平表头QHeaderView *verticalHeader ui.tableView-verticalHeader();// 使用固定行高大小verticalHeader-setSectionResizeMode(QHeaderView::Fixed);// 设置tableview所有列的默认行高为54verticalHeader-setDefaultSectionSize(54);// 所有对setColumnWidth()的调用都要放在setModel()之后,所有对setColumnWidth()的调用都要放在setModel()之后ui.tableView-setModel(m_pLogProxyModel);// 设置表格列宽ui.tableView-setColumnWidth(0, 300);ui.tableView-setColumnWidth(1, 250);ui.tableView-setColumnWidth(2, 250);// 隐藏表头verticalHeader-hide();// 不显示网格ui.tableView-setShowGrid(false);// 行选择ui.tableView-setSelectionBehavior(QAbstractItemView::SelectRows);// 设置为可以选中多个目标ui.tableView-setSelectionMode(QAbstractItemView::ExtendedSelection);// 设置为不可编辑状态ui.tableView-setEditTriggers(QAbstractItemView::NoEditTriggers);// 设置无交点ui.tableView-setFocusPolicy(Qt::NoFocus);// 初始化initialModel();// 重置onReset(); } void CHardwareLogWidget::onReset() {ui.m_pLineEditUserName-clear();m_pLogProxyModel-setFilterKey();ui.m_pComboType-setCurrentIndex(0);m_pLogProxyModel-setFilterLogType(ui.m_pComboType-currentText());// 默认筛选时间为一年内ui.dateTimeEdit_2-setDateTime(QDateTime::currentDateTime());ui.dateTimeEdit-setDateTime(QDateTime::currentDateTime().addYears(-1));m_pLogProxyModel-setDateTimeRange(QDateTime::currentDateTime().addYears(-1), QDateTime::currentDateTime());m_pLogProxyModel-setFilterRegExp(QRegExp());m_pLogProxyModel-setSourceModel(m_pRrecordModel);}////void CHardwareLogWidget::onQuery(){m_pLogProxyModel-setFilterKey(ui.m_pLineEditUserName-text());m_pLogProxyModel-setFilterLogType(ui.m_pComboType-currentText());QDateTime min ui.dateTimeEdit-dateTime();QDateTime max ui.dateTimeEdit_2-dateTime();if (min.toTime_t() max.toTime_t()){QToolTip::showText(ui.dateTimeEdit-mapToGlobal(QPoint(0, 0)), tr(max time must be more than min time));return;}QString str1 min.toString(yyyy-MM-dd hh:mm:ss);m_pLogProxyModel-setDateTimeRange(min, max);m_pLogProxyModel-setFilterRegExp(QRegExp());m_pLogProxyModel-setSourceModel(m_pRrecordModel);} 2 获取过滤器当前选中的文本 获取文本比较简单步骤如下 通过表对象的点击事件能拿到点击位置的QModelIndex对象 使用转到槽/自定义槽函数链接信号槽接收点击信号发出的QModelIndex对象 在槽函数中实现获取当前选中的文本 std::vectorHardWareOperateLogStr CHardwareLogWidget::getFilterLog() {std::vectorHardWareOperateLogStr vecReturn;int rowCount m_pLogProxyModel-rowCount();for (int i 0; i rowCount; i){HardWareOperateLogStr struLog;// 通过当前视图中的index位置获取model中实际的数据struLog.logTime m_pLogProxyModel-data(m_pLogProxyModel-index(i, 0)).toString();struLog.strUserNumber m_pLogProxyModel-data(m_pLogProxyModel-index(i, 1)).toString();struLog.strOperateType m_pLogProxyModel-data(m_pLogProxyModel-index(i, 2)).toString();struLog.strDetailInfo m_pLogProxyModel-data(m_pLogProxyModel-index(i, 3)).toString();vecReturn.push_back(struLog);}return vecReturn; }3 修改当前选中item的文本 修改item文本首先需要获取到item对象方法和获取文本一样都需要接收发出点击信号和参数但槽函数内容如下 存放当前点击对象的item指针在.h/.cpp文件中如下定义 4 实现多列分别过滤 20181207151416201 原理重写QSortFilterProxyModel类中的filterAcceptsRow即可 源码如下 mysortfilterproxymodel.h #ifndef MYSORTFILTERPROXYMODEL_H #define MYSORTFILTERPROXYMODEL_H#include QSortFilterProxyModel #include QRegExpclass MySortFilterProxyModel : public QSortFilterProxyModel {Q_OBJECT public:MySortFilterProxyModel(QObject *parent 0);void setRxCol1(const QString rx);void setRxCol2(const QString rx);protected:bool filterAcceptsRow(int source_row, const QModelIndex source_parent) const Q_DECL_OVERRIDE;private:QString m_rxCol1;QString m_rxCol2;};#endif // MYSORTFILTERPROXYMODEL_Hwidget.h #ifndef WIDGET_H #define WIDGET_H#include QWidgetQT_BEGIN_NAMESPACE class QStandardItemModel; class QSortFilterProxyModel; QT_END_NAMESPACEclass MySortFilterProxyModel;namespace Ui { class Widget; }class Widget : public QWidget {Q_OBJECTpublic:explicit Widget(QWidget *parent 0);~Widget();protected slots:void col1LineEditChanged(const QString text);void col2LineEidtChanged(const QString text);protected:void intsertModel(const int row, const int col, const QString data);private:Ui::Widget *ui;QStandardItemModel *m_model;MySortFilterProxyModel *m_filterModel; };#endif // WIDGET_Hmain.cpp #include widget.h #include QApplicationint main(int argc, char *argv[]) {QApplication a(argc, argv);Widget w;w.show();return a.exec(); }mysortfilterproxymodel.cpp #include mysortfilterproxymodel.h #include QModelIndex #include QDebugMySortFilterProxyModel::MySortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent) {m_rxCol1 ;m_rxCol2 ; }void MySortFilterProxyModel::setRxCol1(const QString rx) {m_rxCol1 rx; }void MySortFilterProxyModel::setRxCol2(const QString rx) {m_rxCol2 rx; }bool MySortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex source_parent) const {QModelIndex index0 sourceModel()-index(source_row, 0, source_parent);QModelIndex index1 sourceModel()-index(source_row, 1, source_parent);return (sourceModel()-data(index0).toString().contains(m_rxCol1) sourceModel()-data(index1).toString().contains(m_rxCol2)); }widget.cpp #include widget.h #include ui_widget.h #include mysortfilterproxymodel.h #include QStandardItemModel #include QRegExp #include QDebug #include QSortFilterProxyModelWidget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget) {ui-setupUi(this);this-setWindowTitle(CSDN IT1995);m_model new QStandardItemModel;m_filterModel new MySortFilterProxyModel;QStringList headList;headList 第一列 第二列 第三列 第四列;m_model-setHorizontalHeaderLabels(headList);ui-tableView-horizontalHeader()-setSectionResizeMode(QHeaderView::ResizeToContents);for(int row 0; row 100; row){for(int col 0; col 4; col){intsertModel(row, col, 第 QString::number(row) 行,第 QString::number(col) 列);}}intsertModel(100, 0, 中文);intsertModel(100, 1, China);intsertModel(100, 2, japan);intsertModel(100, 3, 日本人);intsertModel(101, 0, 中文);intsertModel(101, 1, 东京);intsertModel(101, 2, 东京热);intsertModel(101, 3, 东京冷);connect(ui-colOneLineEdit,SIGNAL(textEdited(QString)), this, SLOT(col1LineEditChanged(QString)));connect(ui-colTwoLineEdit,SIGNAL(textEdited(QString)), this, SLOT(col2LineEidtChanged(QString)));m_filterModel-setSourceModel(m_model);ui-tableView-setModel(m_filterModel); }Widget::~Widget() {delete ui; }void Widget::col1LineEditChanged(const QString text) {m_filterModel-setRxCol1(text);m_filterModel-setSourceModel(m_model); }void Widget::col2LineEidtChanged(const QString text) {m_filterModel-setRxCol2(text);m_filterModel-setSourceModel(m_model); }void Widget::intsertModel(const int row, const int col, const QString data) {QStandardItem *newItem new QStandardItem(data);newItem-setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);m_model-setItem(row, col, newItem); }
http://www.hkea.cn/news/14379612/

相关文章:

  • 自考大型网站开发工具做培训的网站
  • 成都微信网站建设报价单彩票网站建设成本
  • seo渠道台州seo管理
  • 农家乐网站 建设网络营销优化外包
  • 网站能实现什么功能中国国家住房和城乡建设部网站首页
  • 企业申请完域名以后 怎么把网站运行起来怎样做视频电影网站
  • 微信小程序网站建设哪家好如何免费制作微信小程序
  • 甘肃建设银行网站网站建设 职责
  • 企业网站 建设过程工商注册信息查询系统
  • 做网站策划需要用什么软件phpwind转WordPress
  • 大丰专业做网站如何做国外的电商网站
  • 做微博网站好不好网站展示型推广
  • 河北省住房和城乡建设厅网站查网站需求文档
  • 女与男做那个的视频网站小程序怎么进入公众号
  • 丽水网站seo做网站互联网公司排名
  • 网站建设seo优化浙江idc数据中心
  • 泰安红河网站建设重庆网站备案需要几天
  • 云主机怎么上传网站手机网站开发 教程
  • 威海屋顶防水价格威海做防水网站长沙装修公司排名榜
  • 电商网站怎样优化用文件传输协议登录网站
  • 南阳住房和城乡建设管理局网站惠州网站建设公司推荐乐云seo
  • 网站个人备案 企业备案吗看设计案例的有哪些网站
  • 公司建个网站要多少钱app平台网站搭建
  • 网站后台asp源码网站建设模块培训ppt
  • 上海好的网站有哪些企业网站 合同
  • 如何利用问答类网站做推广wordpress 制作专题
  • fn网站不是做那么好吗赚钱软件排行
  • 网站后台登陆验证码不显示阿里巴巴网站建设要多少钱
  • mifa网站开发费用黄陂区建设局网站
  • 网站建设 sql 模版公司网站设计基础任务书