【Qt编写可视化大屏电子看板系统32-模块10大屏地图】五、核心代码#include "frmmodulemap.h"#include "ui_frmmodulemap.h"#include "quihelper.h"#ifdef echarts#include "echarts.h"#include "echartjs.h"#endiffrmModuleMap::frmModuleMap(QWidget *parent) : QWidget(parent), ui(new Ui::frmModuleMap){ui-setupUi(this);this-initForm;this-initBg;this-changeMapStyle(false);}frmModuleMap::~frmModuleMap{delete ui;}void frmModuleMap::showEvent(QShowEvent *){static bool isShow = false;if (!isShow) {isShow = true;QTimer::singleShot(100, this, SLOT(loadBg));}}void frmModuleMap::resizeEvent(QResizeEvent *){if (AppConfig::MapStyle == "image") {loadImage;} else {resizeMap;}}void frmModuleMap::initForm{isLoad = false;labMap = new QLabel;labMap-setObjectName("labMap");labMap-setAlignment(Qt::AlignCenter);labMap-setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);this-layout-addWidget(labMap);#ifdef echartsweb = new WebView(this);web-setLayout(ui-verticalLayout);connect(web, SIGNAL(loadFinished(bool)),this, SLOT(loadFinished));connect(web, SIGNAL(receiveDataFromJs(QString, QVariant)),this, SLOT(receiveDataFromJs(QString, QVariant)));#endif//样式改变了需要重新载入地图,因为颜色变了connect(AppEvent::Instance, SIGNAL(changeStyle), this, SLOT(loadBg));//地图样式改变connect(AppEvent::Instance, SIGNAL(changeMapStyle), this, SLOT(changeMapStyle));}void frmModuleMap::initBg{#ifdef echartsweb-setBgColor(AppConfig::ColorMainBg);#endif}void frmModuleMap::loadBg{if (AppConfig::MapStyle == "image") {loadImage;} else {loadMap;}}void frmModuleMap::loadImage{QString fileName = "bg_china1.png"if (AppConfig::ThemeName == "紫色风格") {fileName = "bg_china1.png"} else if (AppConfig::ThemeName == "蓝色风格") {fileName = "bg_china2.png"} else if (AppConfig::ThemeName == "深蓝风格") {fileName = "bg_china3.png"} else if (AppConfig::ThemeName == "黑色风格") {fileName = "bg_china4.png"}//等比例平滑缩放QPixmap pix(QString("%1/image_bigscreen/%2").arg(QUIHelper::appPath).arg(fileName));pix = pix.scaled(labMap-size, Qt::KeepAspectRatio, Qt::SmoothTransformation);labMap-setPixmap(pix);}void frmModuleMap::loadMap{#ifdef echartsQString fileName = QString("%1/map_echarts.html").arg(ConfigPath);url = "file:///" + fileName;Echarts::Instance-setHeight(this-height);Echarts::Instance-setFileName(fileName);Echarts::Instance-setSaveFile(SaveFile);Echarts::Instance-setZoom(1.2);Echarts::Instance-setMapJsName("china");Echarts::Instance-setMapAreaName("china");QStringList cityName, cityValue, cityPoint, cityColor, cityTip;cityName"上海""北京""成都""武汉""厦门""广州"cityValue"250""220""150""180""140""170"cityPoint"121.48,31.22""116.46,39.92""104.06,30.67""114.31,30.52""118.1,24.46""113.23,23.16"//设置颜色,也可以定义成不同的颜色,牛逼吧for (int i = 0; icityName.count; i++) {cityColorAppConfig::ColorPercent;}//设置提示信息,为空则按照默认规则,更牛逼吧//提示信息可以是html字符串(这样就强大到爆了) 换行符是 brfor (int i = 0; icityName.count; i++) {cityTipQString("%1 = %2%").arg(cityName.at(i)).arg(cityValue.at(i));}Echarts::Instance-setCityName(cityName);Echarts::Instance-setCityValue(cityValue);Echarts::Instance-setCityPoint(cityPoint);Echarts::Instance-setCityColor(cityColor);Echarts::Instance-setCityTip(cityTip);QString html;if (AppConfig::MapStyle == "point") {html = Echarts::Instance-newChartPoint;} else if (AppConfig::MapStyle == "move") {cityValue.clear;cityValue"0""0""0""0""0""1"Echarts::Instance-setCityValue(cityValue);html = Echarts::Instance-newChartMove("北京");} else if (AppConfig::MapStyle == "world") {loadMapWord;html = Echarts::Instance-newChartMove("中国");} else if (AppConfig::MapStyle == "area") {//如果要加载省份而不是市则设置 dirName和areaName 都是省份名称就行loadMapArea("江西", "吉安市");html = Echarts::Instance-newChartPoint;}//下面为两种方式加载网页,如果内容为空则加载网页文件否则加载内容//一般为了保密建议加载内容,这样看不到生成的网页文件if (Echarts::Instance-getSaveFile) {web-load(url);} else {QString baseUrl = QString("%1/").arg(ConfigPath);web-load("", html, baseUrl);//QString ));}}}
以上关于本文的内容,仅作参考!温馨提示:如遇专业性较强的问题(如:疾病、健康、理财等),还请咨询专业人士给予相关指导!
「辽宁龙网」www.liaoninglong.com小编还为您精选了以下内容,希望对您有所帮助:- 如何编制企业年鉴?
- 如何学习编写人工智能软件?
- 婚礼短信邀请函怎么写 编写短信请柬的注意事项
- 如何编写辟邪符
- Qt编写气体安全管理系统10-数据导出
- Qt编写安防视频监控系统54-轮询配置
- 嫦娥5号落月的视频是谁拍的?怎么会显示在指控大屏幕上?
- 怎么使用腾讯文档编写文档
- 可视化语音信箱是什么 可视化语音信箱设置方法
- 5.3英寸大屏+无边框:经典红圈呼吸灯nubia Z9首度曝光