xviewer.h
public:XViewer(QWidget* parent = Q_NULLPTR);//编辑摄像机void SetCam(int index);//121
public slots:void AddCam(); //新增摄像机配置120void SetCam(); //121void DelCam(); //121
private:Ui::XViewerClass ui;QMenu left_menu_;
xviewer.cpp
void XViewer::SetCam(int index)//121
{auto c = XCameraConfig::Instance();QDialog dlg(this);dlg.resize(800, 200);QFormLayout lay;dlg.setLayout(&lay);// 标题1 输入框1// 标题2 输入框2QLineEdit name_edit;lay.addRow(C("名称"), &name_edit);QLineEdit url_edit;lay.addRow(C("主码流"), &url_edit);QLineEdit sub_url_edit;lay.addRow(C("辅码流"), &sub_url_edit);QLineEdit save_path_edit;lay.addRow(C("保存目录"), &save_path_edit);QPushButton save;save.setText(C("保存"));connect(&save, SIGNAL(clicked()), &dlg, SLOT(accept()));lay.addRow("", &save);//编辑 读入原数据显示if (index >= 0){auto cam = c->GetCam(index);name_edit.setText(C(cam.name));url_edit.setText(C(cam.url));sub_url_edit.setText(C(cam.sub_url));save_path_edit.setText(C(cam.save_path));}for (;;){if (dlg.exec() == QDialog::Accepted) //点击了保存{if (name_edit.text().isEmpty()){QMessageBox::information(0, "error", C("请输入名称"));continue;}if (url_edit.text().isEmpty()){QMessageBox::information(0, "error", C("请输入主码流"));continue;}if (sub_url_edit.text().isEmpty()){QMessageBox::information(0, "error", C("请输入辅码流"));continue;}if (save_path_edit.text().isEmpty()){QMessageBox::information(0, "error", C("请输入保存目录"));continue;}break;}return;}//存储数据XCameraData data;strcpy(data.name, name_edit.text().toLocal8Bit());strcpy(data.url, url_edit.text().toLocal8Bit());strcpy(data.sub_url, sub_url_edit.text().toLocal8Bit());strcpy(data.save_path, save_path_edit.text().toLocal8Bit());if (index >= 0) //修改{c->SetCam(index, data);}else //新增{c->Push(data); //插入数据}c->Save(CAM_CONF_PATH); //保存到文件RefreshCams(); //刷新显示
}void XViewer::AddCam()//120
{SetCam(-1);
}void XViewer::SetCam()//121
{int row = ui.cam_list->currentIndex().row();if (row < 0){QMessageBox::information(this, "error", C("请选择摄像机"));return;}SetCam(row);
}void XViewer::DelCam()//121
{int row = ui.cam_list->currentIndex().row();if (row < 0){QMessageBox::information(this, "error", C("请选择摄像机"));return;}stringstream ss;ss << "您确认需要删除摄像机"<< ui.cam_list->currentItem()->text().toLocal8Bit().constData();ss << "吗?";if (QMessageBox::information(this,"confirm",C(ss.str().c_str()),QMessageBox::Yes,QMessageBox::No) != QMessageBox::Yes){return;}XCameraConfig::Instance()->DelCam(row);RefreshCams();
}void XViewer::RefreshCams()
{auto c = XCameraConfig::Instance();ui.cam_list->clear();int count = c->GetCamCount();for (int i = 0; i < count; i++){auto cam = c->GetCam(i);auto item = new QListWidgetItem(QIcon(":/XViewer/img/cam.png"), C(cam.name));ui.cam_list->addItem(item);}
}//119
运行结果: