#include "tab_basemsg.h"
#include "ui_tab_basemsg.h"
#include "src/util/basemsgadddialog.h"
#include <QTableWidget>
#include <QFileDialog>
#include <QMessageBox>
#include <QDebug>
#define WD_BASE_WIDTH 780
#define WD_BASE_HEIGHT 440
tab_basemsg::tab_basemsg(QWidget *parent) :
QWidget(parent),
ui(new Ui::tab_basemsg)
{
ui->setupUi(this);
//tab_basemsg::resize(800,500);
//ui->tableWidget->resize(WD_BASE_WIDTH, WD_BASE_HEIGHT);
init();
//读取json数据,显示表格信息
ShowTableContent();
basemsgDialg = new basemsgaddDialog(this);
connect(basemsgDialg,&basemsgaddDialog::refreshbasemsg,this,[=](int flag,const stBasemsg& basemsg){
qDebug()<< __LINE__ << "refreshbasemsg";
if(flag==0){
comfun.insertjsondata(basemsg,BASEMSG_JSONPATH);
}else{
comfun.updatejsondata(basemsg,BASEMSG_JSONPATH);
}
ShowTableContent();//重新更新表格数据
});
pingdlg = new pingDialog(this);
}
tab_basemsg::~tab_basemsg()
{
delete ui;
delete basemsgDialg;
delete pingdlg;
}
void tab_basemsg::init(){
//如果想调顺序,先调枚举TEnBaseMsgHeadtype中的值顺序,再调这里的顺序
m_all_fieldsHeadname[HEAD_BASEMSG_ID]="序号";
m_all_fieldsHeadname[HEAD_BASEMSG_CODE]="编码";
m_all_fieldsHeadname[HEAD_BASEMSG_NAME]="名称";
m_all_fieldsHeadname[HEAD_BASEMSG_BRAND]="品牌";
m_all_fieldsHeadname[HEAD_BASEMSG_TYPE]="类型";
m_all_fieldsHeadname[HEAD_BASEMSG_IP]="IP地址";
m_all_fieldsHeadname[HEAD_BASEMSG_UPDATE]="更新时间";
m_all_fieldsHeadname[HEAD_BASEMSG_OPT]="操作";
QString fieldsset;
AppConfig::Get().readIni(QString(BASE_FILE_NAME), QString("MENU_CONF"),QString("field"),fieldsset);
qDebug()<< __LINE__ << "fieldsset:"<<fieldsset;
m_fieldslist.clear();
m_fieldslist=fieldsset.split("|");
m_cur_fieldsHeadname.clear();
int index=0;
for(int num=0;num<m_fieldslist.size();num++){
if(m_fieldslist[num]=="1"){
m_cur_fieldsHeadname[index]=m_all_fieldsHeadname[num];
index++;
}
}
QStringList tablelHeader;
for(int i=0;i<m_cur_fieldsHeadname.size();i++) {
tablelHeader << m_cur_fieldsHeadname[i];
}
qDebug() << __LINE__ << __FUNCTION__<<tablelHeader;
//tablelHeader<<"序号"<<"编码"<<"名称"<<"品牌"<<"类型"<<"IP地址"<<"更新时间"<<"操作";
ui->tableWidget->setColumnCount(tablelHeader.size()); // 设置列数
ui->tableWidget->setHorizontalHeaderLabels(tablelHeader);
ui->tableWidget->verticalHeader()->setVisible(false);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);// 设置选择行为整行选择
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);//单元格不可编辑
ui->tableWidget->setStyleSheet("QTableView::item:selected { color:#000000;background-color: #ADD8E6; }");//设置选择后的颜色
ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);//设置右键菜单功能
connect(ui->tableWidget, &QTableWidget::customContextMenuRequested, this, &tab_basemsg::tableWidget_MenuRequested);
//connect(ui->tableWidget, &QTableWidget::customContextMenuRequested, this, &tab_basemsg::on_tableWidget_customContextMenuRequested);
//设置表格表头
for (int i = 0; i < tablelHeader.size(); ++i) {
QTableWidgetItem* headerItem = new QTableWidgetItem(tablelHeader.at(i));
QFont font = headerItem->font();
// font.setBold(true); // 设置字体加粗
headerItem->setFont(font);
ui->tableWidget->setHorizontalHeaderItem(i, headerItem);
if(tablelHeader[i]=="序号" || tablelHeader[i]=="品牌" || tablelHeader[i]=="类型" || tablelHeader[i]=="更新时间"|| tablelHeader[i]=="操作")
{
ui->tableWidget->horizontalHeader()->setSectionResizeMode(i,QHeaderView::Fixed);
int width = 40;//默认宽度
if(tablelHeader[i]=="更新时间") width=160;
else if(tablelHeader[i]=="品牌"||tablelHeader[i]=="类型") width=80;
else if(tablelHeader[i]=="操作") width=80;
ui->tableWidget->setColumnWidth(i,width);
}
}
QString headerStyleSheet = "QHeaderView::section { background-color: rgb(242,242,242); color: #333;padding-top:3px;padding-bottom:3px; }";
ui->tableWidget->horizontalHeader()->setStyleSheet(headerStyleSheet);
ui->tableWidget->setWordWrap(false);
}
void tab_basemsg::reShowTableContent(){
qDebug() << __LINE__ << __FUNCTION__;
init();
//读取json数据,显示表格信息
ShowTableContent();
}
void tab_basemsg::ShowTableContent(){
//qDebug() << __LINE__ << __FUNCTION__;
ui->tableWidget->setRowCount(0);//清空表格
comfun.readjsondata(m_basemsgmap,BASEMSG_JSONPATH);
int id = 1;
// 使用迭代器遍历map
for (auto it = m_basemsgmap.begin(); it != m_basemsgmap.end(); ++it,id++) {
QString code=it.key();
stBasemsg st_basemsg=it.value();
QStringList rowData;
int index=0;
for(int num=0;num<m_cur_fieldsHeadname.size();num++,index++){
if(m_cur_fieldsHeadname[num]==m_all_fieldsHeadname[HEAD_BASEMSG_ID]){
rowData.insert(index,QString::number(id));
}else if(m_cur_fieldsHeadname[num]==m_all_fieldsHeadname[HEAD_BASEMSG_CODE]){
rowData.insert(index,st_basemsg.code);
}else if(m_cur_fieldsHeadname[num]==m_all_fieldsHeadname[HEAD_BASEMSG_NAME]){
rowData.insert(index,st_basemsg.name);
}else if(m_cur_fieldsHeadname[num]==m_all_fieldsHeadname[HEAD_BASEMSG_BRAND]){
rowData.insert(index,st_basemsg.brand);
}else if(m_cur_fieldsHeadname[num]==m_all_fieldsHeadname[HEAD_BASEMSG_TYPE]){
rowData.insert(index,st_basemsg.type_name);
}else if(m_cur_fieldsHeadname[num]==m_all_fieldsHeadname[HEAD_BASEMSG_IP]){
rowData.insert(index,st_basemsg.Ip);
}else if(m_cur_fieldsHeadname[num]==m_all_fieldsHeadname[HEAD_BASEMSG_UPDATE]){
qint64 uptime = st_basemsg.updatetime;
rowData.insert(index,comfun.qint64todatestring(uptime));
}else if(m_cur_fieldsHeadname[num]==m_all_fieldsHeadname[HEAD_BASEMSG_OPT]){
rowData.insert(index,"");
}
}
//rowData << QString::number(index) << code << st_basemsg.name <<st_basemsg.brand <<st_basemsg.type_name <<st_basemsg.updatetime <<"";
renderTable(rowData);
}
}
void tab_basemsg::renderTable(const QStringList& rowData){
int row = ui->tableWidget->rowCount();
ui->tableWidget->insertRow(row);
for (int column = 0; column < rowData.size(); ++column) {
QTableWidgetItem* item = new QTableWidgetItem(rowData.at(column));
item->setTextAlignment(Qt::AlignCenter);
ui->tableWidget->setItem(row, column, item);
QTableWidgetItem* headerItem = ui->tableWidget->horizontalHeaderItem(column);
QString headerText = headerItem ? headerItem->text() : QString();
if (headerText == "操作") {
//编辑按钮
QPushButton* edit = new QPushButton();
edit->setIcon(QIcon(":/index/img/edit.png"));
edit->setIconSize(QSize(24, 24));
edit->setStyleSheet("QPushButton { border: none; }");
edit->setCursor(Qt::PointingHandCursor);
//删除按钮
QPushButton* deleteButton = new QPushButton();
deleteButton->setIcon(QIcon(":/index/img/delete.png"));
deleteButton->setIconSize(QSize(24, 24));
deleteButton->setStyleSh
没有合适的资源?快使用搜索试试~ 我知道了~
【QT常用技术讲解】多线程编程
共55个文件
h:18个
cpp:17个
ui:9个
0 下载量 35 浏览量
2024-08-04
23:17:34
上传
评论
收藏 71KB ZIP 举报
温馨提示
【QT常用技术讲解】多线程编程
资源推荐
资源详情
资源评论
收起资源包目录
myproject.zip (55个子文件)
myproject
lib
commdll.dll 55KB
commdll.h 409B
mainwindow.h 989B
myproject.pro 3KB
src
tools
contrl
threadCmd.cpp 909B
login.cpp 2KB
threadCmd.h 457B
login.h 447B
menu
bar_fieldsmgt.h 490B
tab_serial.h 532B
bar_user.cpp 3KB
tab_serial.cpp 1KB
tab_basemsg.ui 3KB
tab_serial.ui 4KB
tab_basemsg.h 1KB
bar_user.ui 932B
tab_firstpage.cpp 2KB
bar_fieldsmgt.cpp 2KB
tab_firstpage.h 409B
tab_firstpage.ui 3KB
tab_basemsg.cpp 15KB
bar_fieldsmgt.ui 6KB
bar_user.h 346B
util
commfuntion.cpp 14KB
Appsqldb.h 786B
basemsgadddialog.ui 5KB
customtabstyle.cpp 1KB
pingdialog.cpp 2KB
LogHandler.cpp 10KB
basemsgadddialog.h 737B
basemsgadddialog.cpp 2KB
AppConfig.cpp 2KB
AppInit.h 2KB
AppInit.cpp 79B
Appsqldb.cpp 5KB
AppConfig.h 862B
pingdialog.h 680B
commfuntion.h 1KB
LogHandler.h 2KB
pingdialog.ui 7KB
comm_define.h 1KB
customtabstyle.h 509B
mainwindow.cpp 4KB
login.ui 2KB
main.cpp 697B
mainwindow.ui 4KB
img
edit.png 818B
download.png 354B
upload.png 306B
add.png 271B
user.png 1KB
delete.png 458B
cow.png 1KB
myproject.pro.user 25KB
res.qrc 317B
共 55 条
- 1
资源评论
扶尔魔ocy
- 粉丝: 1107
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功