QJson数据用法实例
SonicAttribute::SonicAttribute(QWidget *parent, iDataEntity* ent_select,QList<QString> attrList, QList<QString> attr_values, int flag, QString surveyfilepath) //attrList:属性名列表,attr_values:属性值列表: QDialog(parent)
{surveyfilepath_copy = surveyfilepath;ent_copy = ent_select;QDir dir;dir.setCurrent(current_path); //设置相对路径if (flag == 0){setPlotType(FLOWPOINT);}else if (flag == 1){setPlotType(SONICPOINT);}ui.setupUi(this);//将测量文件数据添加到ui.listWidget_Filelist FLOWPOINT:验流点 SONICPOINT:声速点if (!surveyfilepath.isEmpty()){QJsonObject jsonSurveyFileObject = convertQStringToQJsonObject(surveyfilepath); //jsonSurveyFileObject:测量文件列表的Json格式if (getPlotType() == FLOWPOINT) //判断是否为验流点{if (jsonSurveyFileObject.contains(SURVEYFILELIST_FLOWPOINT)) //判断是否key包含验流点{QJsonValue flowarray_value = jsonSurveyFileObject.take(SURVEYFILELIST_FLOWPOINT);if (flowarray_value.isArray())//判断是否为json数组{QJsonArray flowPointArray = flowarray_value.toArray();//转成数组for (int i = 0; i < flowPointArray.size(); i++){QJsonValue flowPointValue = flowPointArray.at(i);if (flowPointValue.isString()){ui.listWidget_Filelist->addItem(flowPointValue.toString());}}}}}else if (getPlotType() == SONICPOINT) //判断是否为声速点{if (jsonSurveyFileObject.contains(SURVEYFILELIST_SONICPOINT)){QJsonValue sonicarray_value = jsonSurveyFileObject.take(SURVEYFILELIST_SONICPOINT);if (sonicarray_value.isArray())//判断是否为json数组{QJsonArray sonicPointArray = sonicarray_value.toArray();//转成数组for (int i = 0; i < sonicPointArray.size(); i++){QJsonValue sonicPointValue = sonicPointArray.at(i);if (sonicPointValue.isString()){ui.listWidget_Filelist->addItem(sonicPointValue.toString());//添加项到测量文件列表}}}}}}//设置tableWidget行列ui.tableWidget_EntAttribute->setColumnCount(2);ui.tableWidget_EntAttribute->setRowCount(attrList.size()); ui.tableWidget_EntAttribute->setSelectionMode(QAbstractItemView::NoSelection); //设置不可选//设置tableWidget表头内容QStringList header;header.append("属性名");header.append("属性值");ui.tableWidget_EntAttribute->setHorizontalHeaderLabels(header);//ui.tableWidget_EntAttribute->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);//设置宽度自适应//ui.tableWidget_EntAttribute->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); //ui.tableWidget_EntAttribute->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);//添加数据for (int i = 0; i < attrList.size(); i++){ //item_one:属性表名 item_two:属性值auto item_one = new QTableWidgetItem(attrList[i]);item_one->setFlags(item_one->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable); //设置不可编辑状态auto item_two = new QTableWidgetItem(attr_values[i]);item_two->setFlags(item_two->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable);ui.tableWidget_EntAttribute->setItem(i, 0, item_one);ui.tableWidget_EntAttribute->setItem(i, 1, item_two);}//添加右键取消功能ui.listWidget_Filelist->setContextMenuPolicy(Qt::CustomContextMenu);ui.tableWidget_EntAttribute->show();
}//刷新属性表
void SonicAttribute::refreshTableWidget(iDataEntity* curentity)
{QMap<QString, QVariant> ent_attr_map; //实体属性集合ent_attr_map = curentity->getXData().toMap(); //返回实体属性集合QMap<QString, QVariant>::iterator iter = ent_attr_map.begin();QList<QString> attr_keys;QList<QString> attr_values;while (iter != ent_attr_map.end()){QString ent_key = iter.key();QString ent_value = iter.value().toString();attr_keys.append(ent_key);attr_values.append(ent_value);iter++;}for (int i = 0; i < attr_keys.size(); i++){auto item_one = new QTableWidgetItem(attr_keys[i]);item_one->setFlags(item_one->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable); //设置不可编辑状态auto item_two = new QTableWidgetItem(attr_values[i]);item_two->setFlags(item_two->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable);ui.tableWidget_EntAttribute->setItem(i, 0, item_one);ui.tableWidget_EntAttribute->setItem(i, 1, item_two);}
}//绝对路径转成相对路径
QString getRelativePath(QString filepath) //将绝对路径转成相对路径
{if (!filepath.contains(current_path)) //current_path为相对路径 {return filepath;}else{filepath.replace(current_path, "");QString relative_path = "." + filepath;return relative_path;}
}void SonicAttribute::on_listWidget_Filelist_customContextMenuRequested(const QPoint &pos)
{QListWidgetItem* curItem = ui.listWidget_Filelist->itemAt(pos);if (curItem == NULL)return;QMenu *popMenu = new QMenu(this);QAction *cancelSeed = new QAction(tr("取消关联"), this);popMenu->addAction(cancelSeed);connect(cancelSeed, SIGNAL(triggered()), this, SLOT(cancelConnect())); //取消关联popMenu->exec(QCursor::pos());delete popMenu;delete cancelSeed;
}//取消关联操作TXTDSC
void SonicAttribute::cancelConnect()
{QString remove_path;if (ui.listWidget_Filelist->currentIndex().row() != 0){remove_path = ui.listWidget_Filelist->currentItem()->text(); //ui.listWidget_Filelist->takeItem(ui.listWidget_Filelist->currentIndex().row()); //去除一个item;}if (!remove_path.isEmpty()){//移除remove_path :判断移除完的size大小QJsonObject jsonSurveyObject_bef = convertQStringToQJsonObject(surveyfilepath_copy);if (getPlotType() == FLOWPOINT){QJsonValue surveyfileValue = jsonSurveyObject_bef.take(SURVEYFILELIST_FLOWPOINT);if (surveyfileValue.isArray()){QJsonArray surveyfileArray = surveyfileValue.toArray();for (int i = 0; i < surveyfileArray.size(); i++){if (surveyfileArray.at(i).toString() == remove_path){surveyfileArray.removeAt(i);break;}}jsonSurveyObject_bef.remove(SURVEYFILELIST_FLOWPOINT);if (surveyfileArray.size() > 0){jsonSurveyObject_bef.insert(SURVEYFILELIST_FLOWPOINT, surveyfileArray);}surveyfilepath_copy = convertQJsonObjectToQString(jsonSurveyObject_bef);ent_copy->setXData("TXTDSC",surveyfilepath_copy);}}else if (getPlotType() == SONICPOINT){QJsonValue surveyfileValue = jsonSurveyObject_bef.take(SURVEYFILELIST_SONICPOINT);if (surveyfileValue.isArray()){QJsonArray surveyfileArray = surveyfileValue.toArray();for (int i = 0; i < surveyfileArray.size(); i++){if (surveyfileArray.at(i).toString() == remove_path){surveyfileArray.removeAt(i);break;}}jsonSurveyObject_bef.remove(SURVEYFILELIST_SONICPOINT);if (surveyfileArray.size() > 0){jsonSurveyObject_bef.insert(SURVEYFILELIST_SONICPOINT, surveyfileArray);}surveyfilepath_copy = convertQJsonObjectToQString(jsonSurveyObject_bef);ent_copy->setXData("TXTDSC", surveyfilepath_copy);}}}refreshTableWidget(ent_copy);//刷新属性表信息
}//关联CSV文件信息
void SonicAttribute::readFileData()
{if (getPlotType() == SONICPOINT){QString filepath = QFileDialog::getOpenFileName(NULL, "请选择数据文件", QCoreApplication::applicationFilePath(), "CSV(*.CSV)");if (filepath.isEmpty()){QMessageBox::warning(NULL, "提示", "未选择数据文件", "确定");return;}QString relativePath = getRelativePath(filepath);//得到文件的相对路径int flag = 1;for (int i = 0; i < ui.listWidget_Filelist->count(); i++){if (ui.listWidget_Filelist->item(i)->text() == relativePath){flag = 0;}}if (flag == 1){ui.listWidget_Filelist->addItem(relativePath); //添加列表if (surveyfilepath_copy.isEmpty()) //判断原先文件列表是否为空{QJsonArray surveyarray;surveyarray.insert(0, relativePath);QJsonObject surveyFilesObject;surveyFilesObject.insert(SURVEYFILELIST_SONICPOINT, surveyarray);QString surveyfilepath_add = convertQJsonObjectToQString(surveyFilesObject);surveyfilepath_copy = surveyfilepath_add;ent_copy->setXData("TXTDSC", surveyfilepath_copy);}else{QJsonObject surveyFilesObject = convertQStringToQJsonObject(surveyfilepath_copy);if (surveyFilesObject.contains(SURVEYFILELIST_SONICPOINT)){QJsonValue surveyFilesValue = surveyFilesObject.take(SURVEYFILELIST_SONICPOINT);if (surveyFilesValue.isArray()){QJsonArray surveyFilesArray = surveyFilesValue.toArray();//int surveycount = surveyFilesArray.size();surveyFilesArray.append(relativePath);//surveyFilesArray.insert(surveycount, relativePath);surveyFilesObject.remove(SURVEYFILELIST_SONICPOINT);surveyFilesObject.insert(SURVEYFILELIST_SONICPOINT, surveyFilesArray);}}else{QJsonArray surveyFilesArray;surveyFilesArray.insert(0, relativePath);surveyFilesObject.insert(SURVEYFILELIST_SONICPOINT, surveyFilesArray);}QString surveyfilepath_add = convertQJsonObjectToQString(surveyFilesObject);surveyfilepath_copy = surveyfilepath_add;ent_copy->setXData("TXTDSC", surveyfilepath_copy);}}QMainWindow *idata_window;g_pInterface->GetMainWindow(idata_window);ReadSonicPoint sonicpoint(idata_window, relativePath);sonicpoint.setWindowTitle("查看声速点");sonicpoint.exec();}else if (getPlotType() == FLOWPOINT){QString filepath = QFileDialog::getOpenFileName(NULL, "请选择数据文件", QCoreApplication::applicationFilePath(), "TID(*.TID)");if (filepath.isEmpty()){QMessageBox::warning(NULL, "提示", "未选择数据文件", "确定");return;}QString relativePath = getRelativePath(filepath);//判断是否列表当中是否存在路径int flag = 1;for (int i = 0; i < ui.listWidget_Filelist->count(); i++){if (ui.listWidget_Filelist->item(i)->text() == relativePath){flag = 0;}}if (flag == 1){ui.listWidget_Filelist->addItem(relativePath); //添加列表if (surveyfilepath_copy.isEmpty()) //判断原先文件列表是否为空{QJsonArray surveyarray;surveyarray.insert(0, relativePath);QJsonObject surveyFilesObject;surveyFilesObject.insert(SURVEYFILELIST_FLOWPOINT, surveyarray);QString surveyfilepath_add = convertQJsonObjectToQString(surveyFilesObject);surveyfilepath_copy = surveyfilepath_add;ent_copy->setXData("TXTDSC", surveyfilepath_copy);}else{QJsonObject surveyFilesObject = convertQStringToQJsonObject(surveyfilepath_copy);if (surveyFilesObject.contains(SURVEYFILELIST_FLOWPOINT)){QJsonValue surveyFilesValue = surveyFilesObject.take(SURVEYFILELIST_FLOWPOINT);if (surveyFilesValue.isArray()){QJsonArray surveyFilesArray = surveyFilesValue.toArray();int surveycount = surveyFilesArray.size();surveyFilesArray.insert(surveycount, relativePath);surveyFilesObject.remove(SURVEYFILELIST_FLOWPOINT);surveyFilesObject.insert(SURVEYFILELIST_FLOWPOINT, surveyFilesArray);}}else{QJsonArray surveyFilesArray;surveyFilesArray.append(relativePath);surveyFilesObject.insert(SURVEYFILELIST_FLOWPOINT, surveyFilesArray);}QString surveyfilepath_add = convertQJsonObjectToQString(surveyFilesObject);surveyfilepath_copy = surveyfilepath_add;ent_copy->setXData("TXTDSC", surveyfilepath_copy);}}QMainWindow *idata_window;g_pInterface->GetMainWindow(idata_window);ReadFlowPoint flowpoint(idata_window, relativePath);flowpoint.setWindowTitle("查看验流点");flowpoint.exec();}refreshTableWidget(ent_copy);//刷新属性表
}
QJson数据用法实例相关推荐
- Go语言MD5加密用法实例
Go语言MD5加密用法实例 本文实例讲述了Go语言MD5加密用法.分享给大家供大家参考.具体实现方法如下: 复制代码 代码如下: import ( "crypto/md5" ...
- python mysqldb cursor_python中MySQLdb模块用法实例
转载自:http://www.jb51.net/article/57290.htm 姓名:梅金波 学号:16010110036 [嵌牛导读]MySQLdb ...
- input type=range标签用法实例代码
在HTML5中,又新增许多新<input>控件类型,比较实用的一个就是<input type="range">,以滑竿的方式来调整value值,在这以前需要 ...
- PHP中的常见魔术方法功能作用及用法实例
这篇文章主要介绍了PHP中的常见魔术方法功能作用及用法实例,本文讲解了构造函数和析构函数__construct()和__desctruct()以及属性重载(Property Overloading)_ ...
- python asyncio回调函数_python回调函数用法实例分析
python回调函数用法实例分析 本文实例讲述了python回调函数用法.分享给大家供大家参考.具体分析如下: 软件模块之间总是存在着一定的接口,从调用方式上,可以把他们分为三类:同步调用.回调和异步 ...
- python中max函数用法_Python中max函数用法实例分析
Python中max函数用法实例分析 更新时间:2015年07月17日 15:45:09 作者:优雅先生 这篇文章主要介绍了Python中max函数用法,实例分析了Python中max函数的功能与使用 ...
- traceroute命令的用法实例
ceroute命令的用法实例 traceroute 跟踪数据包到达网络主机所经过的路由工具: traceroute 是用来发出数据包的主机到目标主机之间所经过的网关的工具.traceroute 的原理 ...
- python中mysqldb模块_python中MySQLdb模块用法实例
本文实例讲述了python中MySQLdb模块用法.分享给大家供大家参考.具体用法分析如下: MySQLdb其实有点像php或asp中连接数据库的一个模式了,只是MySQLdb是针对mysql连接了接 ...
- java private 命名_java private关键字用法实例
这篇文章主要介绍了java private关键字用法实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 package java04; /* * 问 ...
最新文章
- cad线性标注命令_CAD图纸中怎么进行线性标注
- JCO与bapi的联合使用
- CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
- python3.7.2怎么使用win7_Win7同时安装Python2和Python3的配置
- 对安卓应用进行加固签名,为上架各大应用市场做准备
- 追求卓越追求完美规范学习_追求新的黄金比例
- 棋盘问题 POJ - 1321
- echart 高度 不用 不撑满_你担心的高度近视老了之后是这样的
- Maven下载jar包失败的原因- 解决方法汇总
- 妲己机器人功能_来自机器人影响者的5个功能强大的Instagram教训
- vscode有趣插件
- 智能家居无线系统为代表的Zigbee和Z-Wave协议的介绍,有线和无线的各自优势?
- 旧版的rust怎么老是掉线_RUST服务器进不去 RUST掉线用什么加速器解决?
- tomcat禁止外网访问,允许locat访问
- Amazon软件开发工程师面试题
- \u开头的unicode中的\u被转义\\u的问题处理
- 户外P10全彩LED显示屏一站式解决方案。
- win10微软图标点击无反应_win10的左下角的windows图标点击之后没反应,按下windows键也没有反应该如何做?...
- Ubuntu20.04 OpenSlide 读图Bug 解决
- vfp和c语言,c语言程序设计和vfp程序设计试题.doc
热门文章
- java的setbounds_java Swing组件setBounds()简单用法实例分析
- gulp常用组件【study笔记】
- C# 采用线程重绘图形要点记录
- 何修改基于ArcGIS Server .NET ADF确良9.3的WEB SERVER端口使ArcGIS Server Manager来创建WEB应用的注意事项...
- 实现编辑商品信息功能
- 6-Arco大讲堂(一)
- deepfakes怎么用_[mcj]deepfakesApp使用说明(2)
- 远程下层文档 正在打印_爱普生上线智能打印“宅家学习”好物选择就来京东电脑数码...
- iphone个系列尺寸_iPhone“立体边框”壁纸来了,拥有3D效果
- eclipse32位python版下载_python之(3)Python Eclipse+PyDec下载和安装教程(超级详细)...