地图监控主要是提供一个地图(能够是平面的也能够是立体彩色的,通常建议鸟瞰图,有3D感),而后设备在对应的地图上,能够切换地图来查看对应区域的设备,通常来讲一个区域会有一个地图文件,设备在地图上实时显示当前采集到的值,还会有对应的单位,若是发生报警,对应的地图自动切换到最前面显示,设备点闪烁,发出报警声音,双击对应的设备点还能够回控设备好比进行参数设置等。node
相似的功能需求在不少系统中会用到,好比安防、环境监测、温湿度监控等,这里提个小经验就是,之前实现这个功能,都是先将设备点自定义控件放到一个容器widget中,而后加入一个label控件用来显示地图,后面发如今Qt中的控件,只要是继承自widget的,都是容器,只须要在实例化设备点自定义控件的时候设置父类为label便可,而不像.NET中容器是容器,label不多是容器。这种特性可使得复杂的组合控件很是巧妙的实现,好比文本框加到按钮中,或者搜索框右侧的搜索图标能够直接放一个按钮进去就行。mysql
通用按钮地图控件是开源的,效果图以下: linux
效果开源:https://gitee.com/feiyangqingyun/QWidgetDemo https://github.com/feiyangqingyun/QWidgetDemo 文件名称:buttondefencec++
体验地址:https://gitee.com/feiyangqingyun/QWidgetExe https://github.com/feiyangqingyun/QWidgetExe 文件名称:bin_sams.zipgit
void DeviceHelper::initDeviceMap(QListWidget *listWidget) { listWidget->clear(); listWidget->setViewMode(QListView::IconMode); listWidget->setResizeMode(QListView::Adjust); listWidget->setMovement(QListView::Static); listWidget->setIconSize(QSize(App::RightWidth - 20, App::RightWidth - 20)); int count = DBData::MapNames.count(); for (int i = 0; i < count; i++) { QString imageName = DBData::MapNames.at(i); QPixmap pix = DeviceMap::Instance()->getMapPix(imageName); //取文件名的前字符+末尾字符 QString itemName = imageName; if (imageName.length() > 18) { itemName = QString("%1...%2").arg(imageName.left(8)).arg(imageName.right(10)); } QListWidgetItem *listItem = new QListWidgetItem(listWidget, i); listItem->setIcon(QIcon(pix)); listItem->setText(itemName); listItem->setData(Qt::UserRole, imageName); listItem->setTextAlignment(Qt::AlignCenter); } } void DeviceHelper::initDeviceMapCurrent(const QString &imgName) { if (labMap == NULL) { return; } initDeviceMapCurrent(labMap, imgName); } void DeviceHelper::initDeviceMapCurrent(QLabel *label, const QString &imgName) { App::CurrentImage = imgName; label->setProperty("image", imgName); //优先取带防区线条的图像 QString mapName = "normal_" + imgName; if (DeviceMap::Instance()->existMapPix(mapName)) { label->setPixmap(DeviceMap::Instance()->getMapPix(mapName)); } else { label->setPixmap(DeviceMap::Instance()->getMapPix(imgName)); } QList<ButtonDefence *> btns = label->findChildren<ButtonDefence *>(); foreach (ButtonDefence *btn, btns) { btn->setVisible(btn->property("nodeImage").toString() == imgName); } }