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

沈阳市于洪区建设局网站郑州营销型网站设计

沈阳市于洪区建设局网站,郑州营销型网站设计,广州网站制作公司多少钱,做公司的网站有哪些文章目录 1 实现程序保存操作记录的思路2 XML文档基本结构3 QDomDocument实现XML读写3.1 QDomDocument实现生成XML文件3.2 QDomDocument实现读取XML文件 4 QXmlStreamWriter实现读写4.1 QXmlStreamWriter实现生成XML4.2 QXmlStreamWriter实现读取XML 1 实现程序保存操作记录的思… 文章目录 1 实现程序保存操作记录的思路2 XML文档基本结构3 QDomDocument实现XML读写3.1 QDomDocument实现生成XML文件3.2 QDomDocument实现读取XML文件 4 QXmlStreamWriter实现读写4.1 QXmlStreamWriter实现生成XML4.2 QXmlStreamWriter实现读取XML 1 实现程序保存操作记录的思路 思路来源 由于在一些绘图工具中有些将操作的历史记录缓存的操作配置保存在了json文件也有的保存到了xml文件中如下图所示。经过个人的对比发现xml的文件结构简单、文件的可读性强节点和内容项之间关系层次清晰能够实现简单、快速、清晰的内容缓存非常适合做复杂数据类型的操作记录、工程操作文件记录、配置文件工具。 json 示例(来自一个友商的算法标注工具) {version: 4.5.6,flags: {},shapes: [{description: null,mask: null,label: 7,points: [[574.5679012345677,630.8641975308642],[701.7283950617282,0.0],[822.7160493827159,193.82716049382702],[1091.8518518518517,169.1358024691358]],group_id: null,shape_type: polygon,flags: {}},{description: null,mask: null,label: 7,points: [[970.5472636815921,377.96019900497504],[763.2246176524784,204.6395798783858],[689.9502487562188,457.0646766169153],[689.9502487562188,639.1542288557212],[882.4875621890546,636.1691542288554],[1222.7860696517412,583.9303482587063]],group_id: null,shape_type: polygon,flags: {}},{description: null,mask: null,label: 7,points: [[536.8694885361556,394.21340388007053],[596.1287477954147,430.01587301587324]],group_id: null,shape_type: circle,flags: {}}],imagePath: 微信图片_20231027144505.png,imageData: null,imageHeight: 1080,imageWidth: 1920 }xml示例 (qdraw) ?xml version1.0 encodingUTF-8? !DOCTYPE qdraw canvas width800 height600polyline rotate0 x469.004 y326.484 z0 width394 height289point x-88.0041 y20.5161/point x76.9959 y144.516/point x196.996 y65.5161/point x150.996 y-144.484/point x-24.0041 y-59.4839/point x-163.004 y-63.4839/point x-197.004 y53.5161/point x-116.004 y56.5161/point x-150.004 y11.5161//polylinepolyline rotate0 x164.945 y321.008 z0 width218 height134point x-71.9446 y26.9924/point x27.0554 y66.9924/point x109.055 y8.99239/point x-44.9446 y-67.0076/point x-108.945 y17.9924/point x-70.9446 y25.9924//polylineellipse startAngle40 spanAngle400 rotate0 x155 y125.5 z0 width174 height125/roundrect rx0.1 ry0.333333 rotate0 x357.5 y461 z0 width141 height108/rect rotate0 x104 y488.5 z0 width152 height163/ /canvas2 XML文档基本结构 3 QDomDocument实现XML读写 原理说明 和json文件处理发方式相同。根据节点、子节点、内容项的关系生成、加载XML文件的内容。 方案缺点 生成的xml文档中的内容项的顺序是随机的如下图所示。需要添加随机方法处理参见文章Qt中使用QDomDocument生成XML文件元素属性随机乱序解决办法 、解决QDomDocument的setattribute乱序这样能保证每行顺序都是一样的但是也和自己生成顺序不同。该方法逐渐被淘汰请参见下文方法2QXmlStreamWriter实现。 !--自己期望的结果!-- ?xml version1.0 encodingUTF-8? !DOCTYPE algoConfig baseConfigalgolistalgo algId101001 algName未戴安全帽 serverType图片服务 depModel11030 depLable1NO_HELMET depModel2 depLable2 depModel3 depLable3/algo algId101002 algName未穿长袖 serverType图片服务 depModel11030 depLable1PERSON depModel2 depLable2 depModel3 depLable3/ /algolistmodelMapmodel modelName1303 reName2303//modelMap /baseConfig!--生成的结果!-- ?xml version1.0 encodingUTF-8? !DOCTYPE algoConfig baseConfigalgolistalgo serverType图片服务 algName未戴安全帽 algId101001 depModel11030 depLable1NO_HELMET depModel2 depLable2 depModel3 depLable3/algo serverType图片服务 algName未穿长袖 algId101002 depModel11030 depLable1PERSON depModel2 depLable2 depModel3 depLable3/ /algolistmodelMapmodel modelName1303 reName2303//modelMap /baseConfig3.1 QDomDocument实现生成XML文件 方法说明 采用QDomDocument实现方案传统优缺点。 #include QDomDocument #include QFile #include QTextStream// Method to generate XML file void generateXMLFile() {QDomDocument document;// Making the root elementQDomElement root document.createElement(baseConfig);// Making elements of algolistQDomElement algolist document.createElement(algolist);QDomElement algo1 document.createElement(algo);algo1.setAttribute(algId, 101001);algo1.setAttribute(algName, 未戴安全帽);algo1.setAttribute(serverType, 图片服务);algo1.setAttribute(depModel1, 1030);algo1.setAttribute(depLable1, NO_HELMET);algolist.appendChild(algo1);QDomElement algo2 document.createElement(algo);algo2.setAttribute(algId, 101002);algo2.setAttribute(algName, 未穿长袖);algo2.setAttribute(serverType, 图片服务);algo2.setAttribute(depModel1, 1030);algo2.setAttribute(depLable1, PERSON);algolist.appendChild(algo2);root.appendChild(algolist);// Making elements of modelMapQDomElement modelMap document.createElement(modelMap);QDomElement model document.createElement(model);model.setAttribute(modelName, 1303);model.setAttribute(reName, 2303);modelMap.appendChild(model);root.appendChild(modelMap);document.appendChild(root);// Writing to a fileQFile file(Config.xml);if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) {qDebug() Failed to open file for writing.;return;} else {QTextStream stream(file);stream document.toString();file.close();qDebug() File written.;} }3.2 QDomDocument实现读取XML文件 #include QDomDocument void loadXMLFile() {QDomDocument document;QFile file(Config.xml);if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {qDebug() Failed to open file for reading.;return;} else {if(!document.setContent(file)) {qDebug() Failed to load document.;return;}file.close();}QDomElement root document.firstChildElement();QDomNodeList algos root.firstChildElement(algolist).elementsByTagName(algo);for(int i 0; i algos.count(); i) {QDomNode algoNode algos.at(i);if(algoNode.isElement()) {QDomElement algo algoNode.toElement();qDebug() Algo ID: algo.attribute(algId);qDebug() Algo Name: algo.attribute(algName);}}QDomNodeList models root.firstChildElement(modelMap).elementsByTagName(model);for(int i 0; i models.count(); i) {QDomNode modelNode models.at(i);if(modelNode.isElement()) {QDomElement model modelNode.toElement();qDebug() Model Name: model.attribute(modelName);qDebug() Renamed as: model.attribute(reName);}} }4 QXmlStreamWriter实现读写 使用QXmlStreamWriter方法读写超级简单实现容易快速。 4.1 QXmlStreamWriter实现生成XML #include QXmlStreamReader void genConfForm::genXmlFile() {QFile file(conf.xml);if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {qDebug() Failed to open file for writing.;return;}QXmlStreamWriter xmlWriter(file);xmlWriter.setAutoFormatting(true);xmlWriter.writeStartDocument();xmlWriter.writeDTD(!DOCTYPE algoConfig);xmlWriter.writeStartElement(baseConfig);xmlWriter.writeStartElement(algolist);int rows ui-tableView_gc-model()-rowCount();for(int r 0; r rows; r){/*|0算法ID|1算法名称|2服务类型|3依赖模型1|4依赖label1|5依赖模型2|6依赖label2|7依赖模型3|8依赖label3|*/QString algId ui-tableView_gc-model()-index(r,0).data().toString();QString algName ui-tableView_gc-model()-index(r,1).data().toString();QString serverType ui-tableView_gc-model()-index(r,2).data().toString();QString depModel1 ui-tableView_gc-model()-index(r,3).data().toString();QString depLabel1 ui-tableView_gc-model()-index(r,4).data().toString();QString depModel2 ui-tableView_gc-model()-index(r,5).data().toString();QString depLabel2 ui-tableView_gc-model()-index(r,6).data().toString();QString depModel3 ui-tableView_gc-model()-index(r,7).data().toString();QString depLabel3 ui-tableView_gc-model()-index(r,8).data().toString();xmlWriter.writeEmptyElement(algo);xmlWriter.writeAttribute(algId, algId);xmlWriter.writeAttribute(algName, algName);xmlWriter.writeAttribute(serverType, serverType);xmlWriter.writeAttribute(depModel1, depModel1);xmlWriter.writeAttribute(depLable1, depLabel1);xmlWriter.writeAttribute(depModel2, depModel2);xmlWriter.writeAttribute(depLable2, depLabel2);xmlWriter.writeAttribute(depModel3, depModel3);xmlWriter.writeAttribute(depLable3, depLabel3);}xmlWriter.writeEndElement();//algolistxmlWriter.writeStartElement(modelMap);for(auto model:m_modelRename){//第一次修改后的值第二次修改前的值auto modName model.first;auto reName model.second;xmlWriter.writeEmptyElement(model);xmlWriter.writeAttribute(modelName, modName);xmlWriter.writeAttribute(reName, reName);}xmlWriter.writeEndElement();//modelMapxmlWriter.writeEndElement(); // baseConfigxmlWriter.writeEndDocument();file.close();qDebug() XML file generated successfully.; }4.2 QXmlStreamWriter实现读取XML #include QXmlStreamReader struct DepAllModelInfo{QString m_model1;QString m_label1;QString m_model2;QString m_label2;QString m_model3;QString m_label3; }; using depModel std::vectorDepModelInfo; struct algInfo{QString m_alg_name;QString m_server_type;DepAllModelInfo m_dep_model; }; using algFullCapacity std::mapQString,algInfo; /*以上是读取config.xml文件结构在程序中的数据结构*/ void genConfForm::loadXmlFile() {algFullCapacity afc;QFile file(config.xml);if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {qDebug() Failed to open file for reading.;return;}QXmlStreamReader xmlReader(file);while (!xmlReader.atEnd() !xmlReader.hasError()) {// Read next elementQXmlStreamReader::TokenType token xmlReader.readNext();// If token is just StartDocument, well go to nextif (token QXmlStreamReader::StartDocument) {continue;}// If token is StartElement - read itif (token QXmlStreamReader::StartElement){if (xmlReader.name() algo){DepAllModelInfo dam;QXmlStreamAttributes attributes xmlReader.attributes();QString algId attributes.value(algId).toString();QString algName attributes.value(algName).toString();QString serverType attributes.value(serverType).toString();dam.m_model1 attributes.value(depModel1).toString();dam.m_label1 attributes.value(depLable1).toString();dam.m_model2 attributes.value(depModel2).toString();dam.m_label2 attributes.value(depLable2).toString();dam.m_model3 attributes.value(depModel3).toString();dam.m_label3 attributes.value(depLable3).toString();if(!algId.isEmpty() !algName.isEmpty()){afc.insert(std::pairQString,algInfo(algId, {algName,serverType,dam}));}}if (xmlReader.name() model){QXmlStreamAttributes attributes xmlReader.attributes();QString dbModelName attributes.value(modelName).toString();QString modifyName attributes.value(reName).toString();m_modelRename.insert(std::pairQString,QString(dbModelName,modifyName));}}}if(!afc.empty())slotAlgInfo(afc);if (xmlReader.hasError()) {qDebug() XML error: xmlReader.errorString();}file.close(); }
http://www.zqtcl.cn/news/481026/

相关文章:

  • 珠海网站建设平台中国软文网官网
  • 绵阳学校网站建设wordpress 采集站
  • 免费设计软件下载网站大全贵州seo技术培训
  • wordpress网站+搬家自做购物网站多少钱
  • 用自己网站做淘宝客深圳上市公司一览表
  • 如何用图片文字做网站建设部网站安全事故
  • 订制网站网易企业邮箱怎么修改密码
  • 一小时做网站网上免费设计效果图
  • 网站如何注册域名公司主页填什么
  • 南宁国贸网站建设网站跟网页有什么区别
  • 兰州企业 网站建设短链接在线转换
  • 长沙网上商城网站建设方案导航网站系统
  • 网站更换目录名如何做301跳转网站活泼
  • 化妆品网站网页设计怎样在淘宝网做网站
  • 邢台建站湛江海田网站建设招聘
  • 免费个人网站建站能上传视频吗中国舆情在线网
  • 网站开发项目的心得体会惠州建设厅网站
  • 网站小程序怎么做北京单位网站建设培训
  • 北京市专业网站建设广州安全教育平台登录账号登录入口
  • 广州做网站的价格三个关键词介绍自己
  • 基于工作过程的商务网站建设:网页制作扬州网站建设公元国际
  • wordpress著名网站微信公众号怎么做网站链接
  • 长沙网站建设大概多少钱深圳做网站网络营销公司
  • 融资平台排行榜企业网站seo运营
  • 英文手表网站南昌装修网站建设
  • 网站建设要懂哪些技术甘肃园区网络搭建
  • go做的网站微信跳转链接生成器免费
  • 网站开发中怎么设置快捷键怎样打开用sql做的网站
  • 做餐饮企业网站的费用短视频素材免费下载网站
  • 美食优秀设计网站制作网页网站