1280 lines
52 KiB
C++
1280 lines
52 KiB
C++
#include "QtParameterSettings.h"
|
|
#include "QScreen"
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
QtParameterSettings::QtParameterSettings(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
{
|
|
ui.setupUi(this);
|
|
this->setMouseTracking(true);
|
|
ui.centralWidget->setMouseTracking(true);
|
|
ui.frame->setMouseTracking(true);
|
|
ui.title->setMouseTracking(true);
|
|
|
|
ui.gridLayout;
|
|
//第0行,下拉框;第1行,垂直空格
|
|
//第2行,相机参数
|
|
//for (int i = 0; i < 3; i++)
|
|
////if(0)
|
|
//{
|
|
// for (int j = 0; j < 2; j++)
|
|
// {
|
|
// QGroupBox* myGroupBox = new QGroupBox(ui.groupBox_cameraCfg);
|
|
// QTableWidget* mytableWidget = new QTableWidget();
|
|
// QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
|
// sizePolicy1.setHorizontalStretch(0);
|
|
// sizePolicy1.setVerticalStretch(0);
|
|
// mytableWidget->setSizePolicy(sizePolicy1);
|
|
|
|
// mytableWidget->setColumnCount(2);
|
|
// mytableWidget->setMouseTracking(true);
|
|
// mytableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); // 整行选中
|
|
// mytableWidget->horizontalHeader()->setSectionsClickable(false);
|
|
// mytableWidget->verticalHeader()->hide();
|
|
// mytableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
// //mytableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
|
// //mytableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
// //mytableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
|
// QStringList list;
|
|
// list << "参数名" << "参数值" ;
|
|
// mytableWidget->setHorizontalHeaderLabels(list);
|
|
|
|
// QVBoxLayout* horizontalLayout = new QVBoxLayout(myGroupBox);
|
|
// horizontalLayout->addWidget(mytableWidget);
|
|
// ui.gridLayout->addWidget(myGroupBox, 2 + i, j);
|
|
// myGroupBox->setTitle("相机" + QString::number(i * 2 + j + 1));
|
|
// QPushButton* myButton = new QPushButton();
|
|
// horizontalLayout->addWidget(myButton);
|
|
// myButton->setText("增加一行");
|
|
// connect(myButton, &QPushButton::clicked, [=]() {
|
|
// mytableWidget->setRowCount(mytableWidget->rowCount() + 1);
|
|
// int rowNum = mytableWidget->rowCount();
|
|
// QTableWidgetItem* m_Item0 = new QTableWidgetItem;
|
|
// //m_Item0->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
// m_Item0->setText("参数名参数名参数名参数名参数名"+QString::number(rowNum ));
|
|
// mytableWidget->setItem(rowNum-1, 0, m_Item0);
|
|
|
|
// //QString nowTime = QDateTime::currentDateTime().toString("yyyy-MM-dd");
|
|
// QTableWidgetItem* m_Item1 = new QTableWidgetItem;
|
|
// //m_Item1->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
// m_Item1->setText("参数值参数值参数值参数值" + QString::number(rowNum ));
|
|
// mytableWidget->setItem(rowNum-1, 1, m_Item1);
|
|
// });
|
|
// QPushButton* mydelButton = new QPushButton();
|
|
// horizontalLayout->addWidget(mydelButton);
|
|
// mydelButton->setText("删除一行");
|
|
// connect(mydelButton, &QPushButton::clicked, [=]() {
|
|
// mytableWidget->removeRow(mytableWidget->currentRow());
|
|
// });
|
|
// }
|
|
//}
|
|
|
|
ui.label_icon->setStyleSheet("image: url(./Icon/logo_Dongsheng.png);");
|
|
programObj = load_camera_cfg("camera_cfg.json");
|
|
|
|
initWindow(programObj);
|
|
|
|
ui.pushButton_saveCfg->setStyleSheet("QPushButton{background-color:rgb(68, 74, 80);border-radius:10px;}"
|
|
"QPushButton:hover{ background-color: rgb(0, 0, 0); border:none; color:rgb(255, 255, 255); }");
|
|
//保存
|
|
connect(ui.pushButton_saveCfg, &QPushButton::clicked, [=]() {
|
|
saveProgramObj();
|
|
});
|
|
|
|
ui.pushButton_giveup->setStyleSheet("QPushButton{background-color:rgb(68, 74, 80);border-radius:10px;}"
|
|
"QPushButton:hover{ background-color: rgb(0, 0, 0); border:none; color:rgb(255, 255, 255); }");
|
|
connect(ui.pushButton_giveup, &QPushButton::clicked, [=]() {
|
|
programObj = load_camera_cfg(cfg_name);
|
|
initWindow(programObj);
|
|
});
|
|
|
|
ui.pushButton_min->setText("");
|
|
ui.pushButton_close->setText("");
|
|
ui.pushButton_max->setText("");
|
|
|
|
ui.pushButton_min->setStyleSheet("background-color:transparent;image: url(./Icon/min_n.png);");
|
|
ui.pushButton_close->setStyleSheet("background-color:transparent;image: url(./Icon/close_n.png);");
|
|
ui.pushButton_max->setStyleSheet("background-color:transparent;image: url(./Icon/Max_n.png);");
|
|
|
|
connect(ui.pushButton_min, &QPushButton::clicked, [=]() {
|
|
this->showMinimized();
|
|
qApp->processEvents();
|
|
});
|
|
connect(ui.pushButton_close, &QPushButton::clicked, [=]() {
|
|
this->close();
|
|
qApp->processEvents();
|
|
});
|
|
|
|
QScreen* screen = QGuiApplication::primaryScreen();
|
|
QSize screenSize = screen->size();
|
|
static int screenWidth = screenSize.width();
|
|
static int screenHeight = screenSize.height();
|
|
qDebug() << "Screen resolution: " << screenWidth << "x" << screenHeight;
|
|
|
|
static int maxClickedNum = 1;
|
|
connect(ui.pushButton_max, &QPushButton::clicked, [=]() {
|
|
if (maxClickedNum)
|
|
{
|
|
//ui.pushButton_max->setStyleSheet("background-color:transparent;image: url(Max_n.png);");
|
|
//ui.pushButton_max->setToolTip(tr("向下还原"));
|
|
setWindowFlags(Qt::FramelessWindowHint); //隐藏标题栏
|
|
this->showMaximized();
|
|
maxClickedNum = 0;
|
|
}
|
|
else {
|
|
//ui.pushButton_max->setStyleSheet("background-color:transparent;image: url(Max_n.png);");
|
|
//ui.pushButton_max->setToolTip(tr("最大化"));
|
|
setWindowFlags(Qt::FramelessWindowHint); //隐藏标题栏
|
|
this->showNormal();
|
|
this->resize(screenWidth / 3 * 2, screenHeight / 3 * 2);
|
|
this->move(screenWidth / 5, screenHeight / 5);
|
|
maxClickedNum = 1;
|
|
}
|
|
qApp->processEvents();
|
|
});
|
|
setWindowFlags(Qt::FramelessWindowHint); //隐藏标题栏
|
|
//this->showNormal();
|
|
this->resize(screenWidth / 3 * 2, screenHeight / 3 * 2);
|
|
this->move(screenWidth / 5, screenHeight / 5);
|
|
|
|
}
|
|
|
|
|
|
void QtParameterSettings::initWindow(QJsonObject program_Obj)
|
|
{
|
|
currentPage_cameraNum = 0;
|
|
current_programObj = program_Obj;
|
|
|
|
cameraCfgWindowQueue;
|
|
algorithmCfgWindowQueue;
|
|
|
|
delete ui.tabWidget_algorithm;
|
|
ui.tabWidget_algorithm = new QTabWidget(ui.groupBox_algorithmCfg);
|
|
ui.tabWidget_algorithm->setObjectName(QString::fromUtf8("tabWidget_algorithm"));
|
|
ui.tab_2 = new QWidget();
|
|
ui.tab_2->setObjectName(QString::fromUtf8("tab_2"));
|
|
ui.tabWidget_algorithm->addTab(ui.tab_2, QString("第1页"));
|
|
|
|
ui.gridLayout_2->addWidget(ui.tabWidget_algorithm, 2, 1, 1, 1);
|
|
//ui.tabWidget_camera->removeTab(0);
|
|
ui.groupBox_algorithmCfg->setTitle("算法参数");
|
|
//ui.groupBox_algorithmCfg->setStyleSheet("border:none");
|
|
|
|
ui.tabWidget_algorithm->setDocumentMode(true);
|
|
ui.tabWidget_algorithm->setStyleSheet("QTabWidget#tabWidget{background-color:rgb(68, 74, 80);}\
|
|
QTabBar::tab{background-color:rgb(68, 74, 80);}\
|
|
QTabBar::tab::selected{background-color:rgb(0,100,200);}");
|
|
|
|
//delete ui.tabWidget_camera;
|
|
ui.tabWidget_camera = new QTabWidget(ui.groupBox_cameraCfg);
|
|
ui.tabWidget_camera->setObjectName(QString::fromUtf8("tabWidget_camera"));
|
|
ui.tab = new QWidget();
|
|
ui.tab->setObjectName(QString::fromUtf8("tab"));
|
|
ui.tabWidget_camera->addTab(ui.tab, QString("第1页"));
|
|
|
|
ui.gridLayout->addWidget(ui.tabWidget_camera, 2, 1, 1, 1);
|
|
|
|
ui.groupBox_cameraCfg->setTitle("相机参数");
|
|
|
|
ui.tabWidget_camera->setDocumentMode(true);
|
|
ui.tabWidget_camera->setStyleSheet("QTabWidget#tabWidget{background-color:rgb(68, 74, 80);}\
|
|
border - top:1px solid #000000; \
|
|
border - left:1px solid #000000; \
|
|
border - right:1px solid #000000; \
|
|
border - bottom: 1px solid #000000;}\
|
|
QTabBar::tab{background-color:rgb(68, 74, 80);}\
|
|
QTabBar::tab::selected{background-color:rgb(0,100,200);}\
|
|
QTabWidget::tab-bar{border: 0px;}");
|
|
|
|
|
|
|
|
//ui.tabWidget_camera->setCurrentIndex(0);
|
|
for (int i = 0; i < cameraCfgWindowQueue.size(); i++)
|
|
{
|
|
//delete cameraCfgWindowQueue[i].myAddButton;
|
|
//delete cameraCfgWindowQueue[i].myDelButton;
|
|
//delete cameraCfgWindowQueue[i].myTbleWidget;
|
|
//delete cameraCfgWindowQueue[i].myQGroupBox;
|
|
//cameraCfgWindowQueue[i].myTbleWidget->setRowCount(0);
|
|
|
|
//for (int j = cameraCfgWindowQueue[i].myTbleWidget->rowCount() - 1; j >= 0; j--)
|
|
// cameraCfgWindowQueue[i].myTbleWidget->removeRow(j);
|
|
|
|
if ((i % 6 == 5 || i== cameraCfgWindowQueue.size()-1)&& i > 5)
|
|
{
|
|
ui.tabWidget_camera->removeTab(i / 6);
|
|
//delete ui.tabWidget_camera->widget(i / 6);
|
|
}
|
|
}
|
|
qApp->processEvents();
|
|
currentPage_cameraNum = 0;
|
|
cameraCfgWindowQueue.clear();
|
|
|
|
//ui.tabWidget_algorithm->setCurrentIndex(0);
|
|
|
|
for (int i = 0; i < algorithmCfgWindowQueue.size(); i++)
|
|
{
|
|
if (i % 6 == 0&& i>5)
|
|
ui.tabWidget_algorithm->removeTab(i / 6);
|
|
/*delete algorithmCfgWindowQueue[i].myAddButton;
|
|
delete algorithmCfgWindowQueue[i].myDelButton;
|
|
delete algorithmCfgWindowQueue[i].myTbleWidget;
|
|
delete algorithmCfgWindowQueue[i].myQGroupBox;*/
|
|
}
|
|
|
|
//ui.tabWidget_camera->removeTab(0);
|
|
currentPage_algorithmNum = 0;
|
|
algorithmCfgWindowQueue.clear();
|
|
old_cameraParameterMap.clear();
|
|
old_AlgorithmParameterMap.clear();
|
|
|
|
|
|
stationArray = current_programObj.value("工站列表").toArray();
|
|
int allCameraNum = 0;
|
|
int allAlgorithmNum = 0;
|
|
int rowIndex = 0;
|
|
QGridLayout* QL_camera=nullptr;
|
|
QGridLayout* QL_Algorithm = nullptr;
|
|
//分开设置,关闭窗口释放ui.tabWidget_camera不崩溃;
|
|
for (int SA = 0; SA < stationArray.size(); SA++)
|
|
{
|
|
QJsonObject stationObj = stationArray[SA].toObject();
|
|
QString stationKey = stationObj.value("工站名").toString();
|
|
|
|
QJsonArray cameraListArray = stationObj.value("相机模块列表").toArray();
|
|
for (int CA = 0; CA < cameraListArray.size(); CA++)
|
|
{
|
|
QJsonObject cameraObj = cameraListArray[CA].toObject();
|
|
allCameraNum++;
|
|
if (allCameraNum % 6 == 1)//6个一页
|
|
{
|
|
//添加新页;
|
|
;
|
|
//QWidget* newTabWidget = new QWidget();
|
|
//ui.tabWidget_camera->addTab(newTabWidget, "第"+QString::number(allCameraNum / 6 + 1)+"页");
|
|
//ui.tabWidget_camera->setCurrentIndex(allCameraNum / 6);
|
|
QWidget* newTabWidget;
|
|
if (allCameraNum > 6)
|
|
{
|
|
QSpacerItem* VSpacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
|
QL_camera->addItem(VSpacer,6,0);
|
|
|
|
newTabWidget = new QWidget;// (ui.tabWidget_camera);
|
|
ui.tabWidget_camera->addTab(newTabWidget, "第" + QString::number(allCameraNum / 6 + 1) + "页");
|
|
ui.tabWidget_camera->setCurrentIndex(allCameraNum / 6);
|
|
//newTabWidget->setObjectName
|
|
}
|
|
else
|
|
newTabWidget = ui.tabWidget_camera->widget(0);
|
|
QL_camera = new QGridLayout(newTabWidget);
|
|
}
|
|
if (allCameraNum == 1);
|
|
|
|
//第一页
|
|
//if (allCameraNum <= 6)
|
|
{
|
|
currentPage_cameraNum++;
|
|
setCameraTableWidget(allCameraNum, stationKey, cameraObj, QL_camera);
|
|
}
|
|
}
|
|
//stationKey_cameraListObj_Map.insert(stationKey, cameraListObj);
|
|
}
|
|
|
|
|
|
for (int SA = 0; SA < stationArray.size(); SA++)
|
|
{
|
|
QJsonObject stationObj = stationArray[SA].toObject();
|
|
QString stationKey = stationObj.value("工站名").toString();
|
|
|
|
QJsonArray AlgorithmListArray = stationObj.value("算法列表").toArray();
|
|
for (int CA = 0; CA < AlgorithmListArray.size(); CA++)
|
|
{
|
|
QJsonObject AlgorithmObj = AlgorithmListArray[CA].toObject();
|
|
allAlgorithmNum++;
|
|
if (allAlgorithmNum % 6 == 1)//6个一页
|
|
{
|
|
//添加新页;
|
|
;
|
|
//QWidget* newTabWidget = new QWidget();
|
|
//ui.tabWidget_camera->addTab(newTabWidget, "第"+QString::number(allAlgorithmNum / 6 + 1)+"页");
|
|
//ui.tabWidget_camera->setCurrentIndex(allAlgorithmNum / 6);
|
|
QWidget* newTabWidget;
|
|
if (allAlgorithmNum > 6)
|
|
{
|
|
QSpacerItem* VSpacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
|
QL_Algorithm->addItem(VSpacer, 6, 0);
|
|
|
|
newTabWidget = new QWidget;// (ui.tabWidget_camera);
|
|
ui.tabWidget_algorithm->addTab(newTabWidget, "第" + QString::number(allAlgorithmNum / 6 + 1) + "页");
|
|
ui.tabWidget_algorithm->setCurrentIndex(allAlgorithmNum / 6);
|
|
//newTabWidget->setObjectName
|
|
}
|
|
else
|
|
newTabWidget = ui.tabWidget_algorithm->widget(0);
|
|
QL_Algorithm = new QGridLayout(newTabWidget);
|
|
}
|
|
//if (allAlgorithmNum == 1);
|
|
|
|
//第一页
|
|
//if (allCameraNum <= 6)
|
|
{
|
|
currentPage_algorithmNum++;
|
|
setAlgorithmTableWidget(allAlgorithmNum, stationKey, AlgorithmObj, QL_Algorithm);
|
|
}
|
|
}
|
|
}
|
|
|
|
//QSpacerItem* VSpacer = new QSpacerItem(5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
|
//if(QL_camera!=nullptr)QL_camera->addItem(VSpacer, QL_camera->rowCount()+1, 0);
|
|
//if (QL_Algorithm!=nullptr)QL_Algorithm->addItem(VSpacer, QL_Algorithm->rowCount() + 1, 0);
|
|
ui.tabWidget_camera->setCurrentIndex(0);
|
|
ui.tabWidget_algorithm->setCurrentIndex(0);
|
|
}
|
|
|
|
|
|
void QtParameterSettings::clearCameraTableWidget()
|
|
{
|
|
/*for (int i = 0; i < camera_queueTbleWidget.size(); i++)
|
|
if (camera_queueTbleWidget[i])
|
|
delete camera_queueTbleWidget[i];
|
|
for (int i = 0; i < camera_queueAddButton.size(); i++)
|
|
if (camera_queueAddButton[i])
|
|
delete camera_queueAddButton[i];
|
|
for (int i = 0; i < camera_queueDelButton.size(); i++)
|
|
if (camera_queueDelButton[i])
|
|
delete camera_queueDelButton[i];
|
|
camera_queueTbleWidget.clear();
|
|
camera_queueAddButton.clear();
|
|
camera_queueDelButton.clear();*/
|
|
|
|
}
|
|
|
|
void QtParameterSettings::setCameraTableWidget(int allNum, QString stationKey, QJsonObject cameraObj, QGridLayout* QL1)
|
|
{
|
|
|
|
QTableWidget* TbleWidget=new QTableWidget;
|
|
QPushButton* AddButton;
|
|
QPushButton* DelButton;
|
|
|
|
CfgWindow myCfgWindow;
|
|
myCfgWindow.myAddButton = new QPushButton();
|
|
myCfgWindow.myDelButton = new QPushButton();
|
|
//if (currentPage_cameraNum <= 6)
|
|
myCfgWindow.myQGroupBox = new QGroupBox();// (ui.tabWidget_camera->currentWidget());// (ui.groupBox_cameraCfg);
|
|
/*else
|
|
{
|
|
|
|
}*/
|
|
myCfgWindow.myTbleWidget = new QTableWidget();
|
|
myCfgWindow.obj = cameraObj;
|
|
myCfgWindow.stationName = stationKey;
|
|
myCfgWindow.Key = cameraObj.value("相机key").toString();
|
|
myCfgWindow.Name = cameraObj.value("界面窗口名称").toString();
|
|
|
|
cameraCfgWindowQueue.enqueue(myCfgWindow);
|
|
|
|
QGroupBox* myGroupBox = cameraCfgWindowQueue[currentPage_cameraNum - 1].myQGroupBox;
|
|
QTableWidget* mytableWidget = cameraCfgWindowQueue[currentPage_cameraNum - 1].myTbleWidget;
|
|
QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
|
sizePolicy1.setHorizontalStretch(0);
|
|
sizePolicy1.setVerticalStretch(0);
|
|
mytableWidget->setSizePolicy(sizePolicy1);
|
|
|
|
mytableWidget->setColumnCount(2);
|
|
mytableWidget->setMouseTracking(true);
|
|
mytableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); // 整行选中
|
|
mytableWidget->horizontalHeader()->setSectionsClickable(false);
|
|
mytableWidget->verticalHeader()->hide();
|
|
mytableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
//mytableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
|
//mytableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
//mytableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
|
QStringList list;
|
|
list << "参数名" << "参数值";
|
|
mytableWidget->setHorizontalHeaderLabels(list);
|
|
|
|
QVBoxLayout* horizontalLayout = new QVBoxLayout(myGroupBox);
|
|
QSpacerItem* VSpacer = new QSpacerItem(10, 10, QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
horizontalLayout->addItem(VSpacer);
|
|
horizontalLayout->addWidget(mytableWidget);
|
|
int i = (currentPage_cameraNum-1) / 2;
|
|
int j = (currentPage_cameraNum - 1) % 2;
|
|
//ui.gridLayout->addWidget(myGroupBox, 2 + i, j);
|
|
|
|
|
|
//QGridLayout* HL1 = new QGridLayout(ui.tabWidget_camera->currentWidget());
|
|
QL1->addWidget(myCfgWindow.myQGroupBox, 2 + i, j);
|
|
|
|
myGroupBox->setTitle(myCfgWindow.Name);
|
|
myGroupBox->setStyleSheet("background-color: rgb(32,36,40);color: rgb(229, 229, 229);border-radius:5px;border-color: rgb(0, 0, 0)");
|
|
|
|
mytableWidget->setStyleSheet(QString::fromUtf8("gridline-color: rgb(0, 0, 0);\n"
|
|
"color: rgb(220, 220, 220);\n"
|
|
"border-radius:1px;\n"
|
|
"border-color: rgb(0, 0, 0);background-color: rgb(50,55,56);"));
|
|
|
|
mytableWidget->horizontalHeader()->setStyleSheet(
|
|
"QHeaderView::section{"
|
|
"border-top:1px solid #000000;"
|
|
"border-left:1px solid #000000;"
|
|
"border-right:1px solid #000000;"
|
|
"border-bottom: 1px solid #000000;"
|
|
"background-color:rgb(50,55,56);"
|
|
"padding:4px;"
|
|
"}"
|
|
);
|
|
mytableWidget->verticalHeader()->setStyleSheet(
|
|
"QHeaderView::section{"
|
|
"border-top:1px solid #000000;"
|
|
"border-left:1px solid #000000;"
|
|
"border-right:1px solid #000000;"
|
|
"border-bottom: 1px solid #000000;"
|
|
"background-color:rgb(50,55,56);"
|
|
"padding:4px;"
|
|
"}"
|
|
);
|
|
|
|
|
|
/*currentPage_camera_queueGroupBox.enqueue(myGroupBox);
|
|
currentPage_camera_queueTbleWidget.enqueue(mytableWidget);
|
|
currentPage_camera_queueAddButton.enqueue(myAddButton);
|
|
currentPage_camera_queueDelButton.enqueue(mydelButton);*/
|
|
|
|
QMap<QString, QString> one_cameraParameterMap;
|
|
QJsonArray ParameterArray = cameraObj.value("相机参数").toArray();
|
|
for (int T = 0; T < ParameterArray.size(); T++)
|
|
{
|
|
QJsonObject ParameterObj = ParameterArray[T].toObject();
|
|
mytableWidget->setRowCount(mytableWidget->rowCount() + 1);
|
|
int rowNum = mytableWidget->rowCount();
|
|
QTableWidgetItem* m_Item0 = new QTableWidgetItem;
|
|
//m_Item0->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
m_Item0->setText(ParameterObj.value("参数名").toString());
|
|
mytableWidget->setItem(rowNum - 1, 0, m_Item0);
|
|
|
|
//QString nowTime = QDateTime::currentDateTime().toString("yyyy-MM-dd");
|
|
QTableWidgetItem* m_Item1 = new QTableWidgetItem;
|
|
//m_Item1->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
QString ParameterValue;
|
|
QJsonArray ParameterValueArray = ParameterObj.value("相机参数值").toArray();
|
|
for (int P = 0; P < ParameterValueArray.size(); P++)
|
|
{
|
|
if (P > 0)ParameterValue.append(",");
|
|
ParameterValue.append(ParameterValueArray[P].toString());
|
|
}
|
|
m_Item1->setText(ParameterValue);
|
|
mytableWidget->setItem(rowNum - 1, 1, m_Item1);
|
|
one_cameraParameterMap.insert(ParameterObj.value("参数名").toString(), ParameterValue);
|
|
}
|
|
int rowc=mytableWidget->rowCount();
|
|
old_cameraParameterMap.insert(myCfgWindow.Name,one_cameraParameterMap);
|
|
|
|
QHBoxLayout* horizontalLayout_X = new QHBoxLayout();
|
|
QPushButton* myAddButton = cameraCfgWindowQueue[currentPage_cameraNum - 1].myAddButton;
|
|
horizontalLayout_X->addWidget(myAddButton);
|
|
myAddButton->setText("增加一行");
|
|
myAddButton->setStyleSheet("QPushButton{background-color:rgb(68, 74, 80);border-radius:10px;}"
|
|
"QPushButton:hover{ background-color: rgb(0, 0, 0); border:none; color:rgb(255, 255, 255); }");
|
|
//myAddButton->setStyleSheet("background-color: rgb(50,55,56);color: rgb(229, 229, 229);border-radius:5px;border-color: rgb(0, 0, 0)");
|
|
myAddButton->setMinimumSize(QSize(50, 30));
|
|
|
|
QPushButton* mydelButton = cameraCfgWindowQueue[currentPage_cameraNum - 1].myDelButton;
|
|
horizontalLayout_X->addWidget(mydelButton);
|
|
mydelButton->setText("删除一行");
|
|
mydelButton->setStyleSheet("QPushButton{background-color:rgb(68, 74, 80);border-radius:10px;}"
|
|
"QPushButton:hover{ background-color: rgb(0, 0, 0); border:none; color:rgb(255, 255, 255); }");
|
|
//mydelButton->setStyleSheet("background-color: rgb(50,55,56);color: rgb(229, 229, 229);border-radius:5px;border-color: rgb(0, 0, 0)");
|
|
mydelButton->setMinimumSize(QSize(50, 30));
|
|
horizontalLayout->addLayout(horizontalLayout_X);
|
|
|
|
//添加
|
|
connect(myAddButton, &QPushButton::clicked, [=]() {
|
|
mytableWidget->setRowCount(mytableWidget->rowCount() + 1);
|
|
int rowNum = mytableWidget->rowCount();
|
|
QTableWidgetItem* m_Item0 = new QTableWidgetItem;
|
|
//m_Item0->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
m_Item0->setText("");
|
|
mytableWidget->setItem(rowNum - 1, 0, m_Item0);
|
|
|
|
//QString nowTime = QDateTime::currentDateTime().toString("yyyy-MM-dd");
|
|
QTableWidgetItem* m_Item1 = new QTableWidgetItem;
|
|
//m_Item1->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
m_Item1->setText("");
|
|
mytableWidget->setItem(rowNum - 1, 1, m_Item1);
|
|
});
|
|
|
|
//删除
|
|
connect(mydelButton, &QPushButton::clicked, [=]() {
|
|
QJsonObject cameraObj=cameraCfgWindowQueue[currentPage_cameraNum - 1].obj;
|
|
QJsonArray ParameterArray = cameraObj.value("相机参数").toArray();
|
|
QJsonArray newParameterArray;
|
|
for (int T = 0; T < ParameterArray.size(); T++)
|
|
{
|
|
if (mytableWidget->rowCount() < 1 || mytableWidget->currentRow()<0)
|
|
return;
|
|
QJsonObject ParameterObj = ParameterArray[T].toObject();
|
|
QString ParameterName = ParameterObj.value("参数名").toString();
|
|
QString checkName = mytableWidget->item(mytableWidget->currentRow(), 0)->text();
|
|
if (checkName != ParameterName)
|
|
newParameterArray.append(ParameterObj);
|
|
else
|
|
qDebug() << "删除成功,参数名为:"<< ParameterName;
|
|
}
|
|
//cameraCfgWindowQueue[currentPage_cameraNum - 1].obj.insert("相机参数", newParameterArray);
|
|
mytableWidget->removeRow(mytableWidget->currentRow());
|
|
|
|
});
|
|
|
|
//修改
|
|
connect(mytableWidget, &QTableWidget::currentItemChanged, [=]() {
|
|
QJsonArray newParameterArray;
|
|
for (int i = 0; i < mytableWidget->rowCount(); i++)
|
|
{
|
|
QJsonObject ParameterObj;
|
|
QJsonArray ParameterValueArray;
|
|
QString ParameterValue = mytableWidget->item(i, 1)->text();
|
|
QStringList ParameterValueList = ParameterValue.split(",");
|
|
for (int L = 0; L < ParameterValueList.size(); L++)
|
|
ParameterValueArray.append(ParameterValueList[L]);
|
|
ParameterObj.insert(mytableWidget->item(i, 0)->text(), ParameterValueArray);
|
|
newParameterArray.append(ParameterObj);
|
|
}
|
|
//cameraCfgWindowQueue[currentPage_cameraNum - 1].obj.insert("相机参数", newParameterArray);
|
|
});
|
|
|
|
}
|
|
|
|
|
|
void QtParameterSettings::setAlgorithmTableWidget(int allNum, QString stationKey, QJsonObject AlgorithmObj, QGridLayout* QL1)
|
|
|
|
{
|
|
|
|
QTableWidget* TbleWidget = new QTableWidget;
|
|
QPushButton* AddButton;
|
|
QPushButton* DelButton;
|
|
|
|
CfgWindow myCfgWindow;
|
|
myCfgWindow.myAddButton = new QPushButton();
|
|
myCfgWindow.myDelButton = new QPushButton();
|
|
//if (currentPage_algorithmNum <= 6)
|
|
myCfgWindow.myQGroupBox = new QGroupBox();// (ui.tabWidget_camera->currentWidget());// (ui.groupBox_cameraCfg);
|
|
/*else
|
|
{
|
|
|
|
}*/
|
|
myCfgWindow.myTbleWidget = new QTableWidget();
|
|
myCfgWindow.obj = AlgorithmObj;
|
|
myCfgWindow.stationName = stationKey;
|
|
myCfgWindow.Key = AlgorithmObj.value("算法名称").toString();
|
|
myCfgWindow.Name = AlgorithmObj.value("算法名称").toString();
|
|
|
|
algorithmCfgWindowQueue.enqueue(myCfgWindow);
|
|
|
|
QGroupBox* myGroupBox = algorithmCfgWindowQueue[currentPage_algorithmNum - 1].myQGroupBox;
|
|
QTableWidget* mytableWidget = algorithmCfgWindowQueue[currentPage_algorithmNum - 1].myTbleWidget;
|
|
QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
|
sizePolicy1.setHorizontalStretch(0);
|
|
sizePolicy1.setVerticalStretch(0);
|
|
mytableWidget->setSizePolicy(sizePolicy1);
|
|
|
|
mytableWidget->setColumnCount(2);
|
|
mytableWidget->setMouseTracking(true);
|
|
mytableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); // 整行选中
|
|
mytableWidget->horizontalHeader()->setSectionsClickable(false);
|
|
mytableWidget->verticalHeader()->hide();
|
|
mytableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
//mytableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
|
//mytableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
//mytableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
|
QStringList list;
|
|
list << "参数名" << "参数值";
|
|
mytableWidget->setHorizontalHeaderLabels(list);
|
|
|
|
QVBoxLayout* horizontalLayout = new QVBoxLayout(myGroupBox);
|
|
QSpacerItem* VSpacer = new QSpacerItem(10, 10, QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
horizontalLayout->addItem(VSpacer);
|
|
horizontalLayout->addWidget(mytableWidget);
|
|
int i = (currentPage_algorithmNum - 1) / 2;
|
|
int j = (currentPage_algorithmNum - 1) % 2;
|
|
//ui.gridLayout->addWidget(myGroupBox, 2 + i, j);
|
|
|
|
|
|
//QGridLayout* HL1 = new QGridLayout(ui.tabWidget_camera->currentWidget());
|
|
QL1->addWidget(myCfgWindow.myQGroupBox, 2 + i, j);
|
|
|
|
myGroupBox->setTitle(myCfgWindow.Name);
|
|
|
|
myGroupBox->setStyleSheet("background-color: rgb(32,36,40);color: rgb(229, 229, 229);border-radius:5px;border-color: rgb(0, 0, 0)");
|
|
|
|
mytableWidget->setStyleSheet(QString::fromUtf8("gridline-color: rgb(0, 0, 0);\n"
|
|
"color: rgb(220, 220, 220);\n"
|
|
"border-radius:1px;\n"
|
|
"border-color: rgb(0, 0, 0);background-color: rgb(50,55,56);"));
|
|
|
|
mytableWidget->horizontalHeader()->setStyleSheet(
|
|
"QHeaderView::section{"
|
|
"border-top:1px solid #000000;"
|
|
"border-left:1px solid #000000;"
|
|
"border-right:1px solid #000000;"
|
|
"border-bottom: 1px solid #000000;"
|
|
"background-color:rgb(50,55,56);"
|
|
"padding:4px;"
|
|
"}"
|
|
);
|
|
mytableWidget->verticalHeader()->setStyleSheet(
|
|
"QHeaderView::section{"
|
|
"border-top:1px solid #000000;"
|
|
"border-left:1px solid #000000;"
|
|
"border-right:1px solid #000000;"
|
|
"border-bottom: 1px solid #000000;"
|
|
"background-color:rgb(50,55,56);"
|
|
"padding:4px;"
|
|
"}"
|
|
);
|
|
|
|
|
|
/*currentPage_camera_queueGroupBox.enqueue(myGroupBox);
|
|
currentPage_camera_queueTbleWidget.enqueue(mytableWidget);
|
|
currentPage_camera_queueAddButton.enqueue(myAddButton);
|
|
currentPage_camera_queueDelButton.enqueue(mydelButton);*/
|
|
|
|
QMap<QString, QString> one_AlgorithmParameterMap;
|
|
QJsonArray ParameterArray = AlgorithmObj.value("算法初始化参数").toArray();
|
|
for (int T = 0; T < ParameterArray.size(); T++)
|
|
{
|
|
QJsonObject ParameterObj = ParameterArray[T].toObject();
|
|
|
|
mytableWidget->setRowCount(mytableWidget->rowCount() + 1);
|
|
int rowNum = mytableWidget->rowCount();
|
|
QTableWidgetItem* m_Item0 = new QTableWidgetItem;
|
|
//m_Item0->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
m_Item0->setText(ParameterObj.value("算法参数名").toString());
|
|
mytableWidget->setItem(rowNum - 1, 0, m_Item0);
|
|
|
|
//QString nowTime = QDateTime::currentDateTime().toString("yyyy-MM-dd");
|
|
QTableWidgetItem* m_Item1 = new QTableWidgetItem;
|
|
//m_Item1->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
QString ParameterValue;
|
|
QJsonArray ParameterValueArray = ParameterObj.value("算法参数值").toArray();
|
|
for (int P = 0; P < ParameterValueArray.size(); P++)
|
|
{
|
|
if (P > 0)ParameterValue.append(",");
|
|
ParameterValue.append(ParameterValueArray[P].toString());
|
|
}
|
|
m_Item1->setText(ParameterValue);
|
|
mytableWidget->setItem(rowNum - 1, 1, m_Item1);
|
|
one_AlgorithmParameterMap.insert(ParameterObj.value("算法参数名").toString(), ParameterValue);
|
|
}
|
|
old_AlgorithmParameterMap.insert(myCfgWindow.Name, one_AlgorithmParameterMap);
|
|
|
|
|
|
QHBoxLayout* horizontalLayout_X = new QHBoxLayout();
|
|
QPushButton* myAddButton = algorithmCfgWindowQueue[currentPage_algorithmNum - 1].myAddButton;
|
|
horizontalLayout_X->addWidget(myAddButton);
|
|
myAddButton->setText("增加一行");
|
|
myAddButton->setStyleSheet("QPushButton{background-color:rgb(68, 74, 80);border-radius:10px;}"
|
|
"QPushButton:hover{ background-color: rgb(0, 0, 0); border:none; color:rgb(255, 255, 255); }");
|
|
//myAddButton->setStyleSheet("background-color: rgb(50,55,56);color: rgb(229, 229, 229);border-radius:5px;border-color: rgb(0, 0, 0)");
|
|
myAddButton->setMinimumSize(QSize(50, 30));
|
|
|
|
QPushButton* mydelButton = algorithmCfgWindowQueue[currentPage_algorithmNum - 1].myDelButton;
|
|
horizontalLayout_X->addWidget(mydelButton);
|
|
mydelButton->setText("删除一行");
|
|
mydelButton->setStyleSheet("QPushButton{background-color:rgb(68, 74, 80);border-radius:10px;}"
|
|
"QPushButton:hover{ background-color: rgb(0, 0, 0); border:none; color:rgb(255, 255, 255); }");
|
|
//mydelButton->setStyleSheet("background-color: rgb(50,55,56);color: rgb(229, 229, 229);border-radius:5px;border-color: rgb(0, 0, 0)");
|
|
mydelButton->setMinimumSize(QSize(50, 30));
|
|
horizontalLayout->addLayout(horizontalLayout_X);
|
|
|
|
//添加
|
|
connect(myAddButton, &QPushButton::clicked, [=]() {
|
|
mytableWidget->setRowCount(mytableWidget->rowCount() + 1);
|
|
int rowNum = mytableWidget->rowCount();
|
|
QTableWidgetItem* m_Item0 = new QTableWidgetItem;
|
|
//m_Item0->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
m_Item0->setText("");
|
|
mytableWidget->setItem(rowNum - 1, 0, m_Item0);
|
|
|
|
//QString nowTime = QDateTime::currentDateTime().toString("yyyy-MM-dd");
|
|
QTableWidgetItem* m_Item1 = new QTableWidgetItem;
|
|
//m_Item1->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
m_Item1->setText("");
|
|
mytableWidget->setItem(rowNum - 1, 1, m_Item1);
|
|
});
|
|
|
|
//删除
|
|
connect(mydelButton, &QPushButton::clicked, [=]() {
|
|
QJsonObject cameraObj = algorithmCfgWindowQueue[currentPage_algorithmNum - 1].obj;
|
|
QJsonArray ParameterArray = cameraObj.value("算法初始化参数").toArray();
|
|
QJsonArray newParameterArray;
|
|
for (int T = 0; T < ParameterArray.size(); T++)
|
|
{
|
|
if (mytableWidget->rowCount() < 1 || mytableWidget->currentRow() < 0)
|
|
return;
|
|
QJsonObject ParameterObj = ParameterArray[T].toObject();
|
|
QString ParameterName = ParameterObj.value("算法参数名").toString();
|
|
QString checkName = mytableWidget->item(mytableWidget->currentRow(), 0)->text();
|
|
if (checkName != ParameterName)
|
|
newParameterArray.append(ParameterObj);
|
|
else
|
|
qDebug() << "删除成功,算法参数名为:" << ParameterName;
|
|
}
|
|
//algorithmCfgWindowQueue[currentPage_algorithmNum - 1].obj.insert("相机参数", newParameterArray);
|
|
mytableWidget->removeRow(mytableWidget->currentRow());
|
|
|
|
});
|
|
|
|
//修改
|
|
connect(mytableWidget, &QTableWidget::currentItemChanged, [=]() {
|
|
QJsonArray newParameterArray;
|
|
for (int i = 0; i < mytableWidget->rowCount(); i++)
|
|
{
|
|
QJsonObject ParameterObj;
|
|
QJsonArray ParameterValueArray;
|
|
QString ParameterValue = mytableWidget->item(i, 1)->text();
|
|
QStringList ParameterValueList = ParameterValue.split(",");
|
|
for (int L = 0; L < ParameterValueList.size(); L++)
|
|
ParameterValueArray.append(ParameterValueList[L]);
|
|
ParameterObj.insert(mytableWidget->item(i, 0)->text(), ParameterValueArray);
|
|
newParameterArray.append(ParameterObj);
|
|
}
|
|
//algorithmCfgWindowQueue[currentPage_cameraNum - 1].obj.insert("相机参数", newParameterArray);
|
|
});
|
|
|
|
}
|
|
|
|
|
|
void QtParameterSettings::saveProgramObj()
|
|
{
|
|
//内存中的数据写到文件
|
|
QJsonDocument olddoc(programObj);
|
|
//将json对象转换成字符串
|
|
QByteArray olddata = olddoc.toJson();
|
|
QFile oldfile(BackUp_json_cfg_file_path);
|
|
oldfile.open(QIODevice::WriteOnly);
|
|
oldfile.write(olddata);
|
|
oldfile.close();
|
|
|
|
//改变的列表
|
|
QStringList changeList;
|
|
QString nowTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz");
|
|
//相机:界面列表数据,写入
|
|
for (int ccw = 0; ccw < cameraCfgWindowQueue.size(); ccw++)
|
|
{
|
|
QJsonArray newParameterArray;
|
|
int myrowCount = cameraCfgWindowQueue[ccw].myTbleWidget->rowCount();
|
|
for (int i = 0; i < myrowCount; i++)
|
|
{
|
|
QJsonObject ParameterObj;
|
|
QJsonArray ParameterValueArray;
|
|
QString ParameterKey = cameraCfgWindowQueue[ccw].myTbleWidget->item(i, 0)->text();
|
|
QString ParameterValue = cameraCfgWindowQueue[ccw].myTbleWidget->item(i, 1)->text();
|
|
QStringList ParameterValueList = ParameterValue.split(",");
|
|
for (int L = 0; L < ParameterValueList.size(); L++)
|
|
ParameterValueArray.append(ParameterValueList[L]);
|
|
ParameterObj.insert("参数名", ParameterKey);
|
|
ParameterObj.insert("相机参数值", ParameterValueArray);
|
|
newParameterArray.append(ParameterObj);
|
|
|
|
if (old_cameraParameterMap.value(cameraCfgWindowQueue[ccw].Name).keys().contains(ParameterKey))
|
|
{
|
|
QString oldValue = old_cameraParameterMap.value(cameraCfgWindowQueue[ccw].Name).value(ParameterKey);
|
|
if (oldValue != ParameterValue)
|
|
{
|
|
QString changeData = cameraCfgWindowQueue[ccw].Name + ",参数:" + ParameterKey + " 旧值:" + oldValue + " 修改为:" + ParameterValue;
|
|
changeList.append(QString("[%1] [参数修改] %2").arg(nowTime).arg(changeData));
|
|
}
|
|
}
|
|
}
|
|
cameraCfgWindowQueue[ccw].obj.insert("相机参数", newParameterArray);
|
|
}
|
|
//算法:界面列表数据,写入
|
|
for (int ccw = 0; ccw < algorithmCfgWindowQueue.size(); ccw++)
|
|
{
|
|
QJsonArray newParameterArray;
|
|
int myrowCount = algorithmCfgWindowQueue[ccw].myTbleWidget->rowCount();
|
|
for (int i = 0; i < myrowCount; i++)
|
|
{
|
|
QJsonObject ParameterObj;
|
|
QJsonArray ParameterValueArray;
|
|
QString ParameterKey = algorithmCfgWindowQueue[ccw].myTbleWidget->item(i, 0)->text();
|
|
QString ParameterValue = algorithmCfgWindowQueue[ccw].myTbleWidget->item(i, 1)->text();
|
|
QStringList ParameterValueList = ParameterValue.split(",");
|
|
for (int L = 0; L < ParameterValueList.size(); L++)
|
|
ParameterValueArray.append(ParameterValueList[L]);
|
|
ParameterObj.insert("算法参数名", algorithmCfgWindowQueue[ccw].myTbleWidget->item(i, 0)->text());
|
|
ParameterObj.insert("算法参数值", ParameterValueArray);
|
|
newParameterArray.append(ParameterObj);
|
|
|
|
if (old_AlgorithmParameterMap.value(algorithmCfgWindowQueue[ccw].Name).keys().contains(ParameterKey))
|
|
{
|
|
QString oldValue = old_AlgorithmParameterMap.value(algorithmCfgWindowQueue[ccw].Name).value(ParameterKey);
|
|
if (oldValue != ParameterValue)
|
|
{
|
|
QString changeData = algorithmCfgWindowQueue[ccw].Name + ",参数:" + ParameterKey + " 旧值:" + oldValue + " 修改为:" + ParameterValue;
|
|
changeList.append(QString("[%1] [参数修改] %2").arg(nowTime).arg(changeData));
|
|
}
|
|
}
|
|
}
|
|
algorithmCfgWindowQueue[ccw].obj.insert("算法初始化参数", newParameterArray);
|
|
}
|
|
|
|
if (changeList.size() > 0)
|
|
{
|
|
//保存log及界面打印
|
|
emit dataChange(changeList);
|
|
}
|
|
QStringList moduleKeyList;
|
|
QJsonArray newstationArray;
|
|
for (int SA = 0; SA < stationArray.size(); SA++)
|
|
{
|
|
QJsonObject stationObj = stationArray[SA].toObject();
|
|
QString stationKey = stationObj.value("工站名").toString();
|
|
QJsonArray cameraListArray = stationObj.value("相机模块列表").toArray();
|
|
//QQueue< QJsonObject>cameraListObj;
|
|
QJsonArray newcameraListArray;
|
|
for (int CA = 0; CA < cameraListArray.size(); CA++)
|
|
{
|
|
QJsonObject cameraObj = cameraListArray[CA].toObject();
|
|
QString camerakey = cameraObj.value("相机key").toString();
|
|
QJsonObject new_cameraObj;
|
|
for (int ccw = 0; ccw < cameraCfgWindowQueue.size(); ccw++)
|
|
{
|
|
if (camerakey == cameraCfgWindowQueue[ccw].Key)
|
|
{
|
|
new_cameraObj = cameraCfgWindowQueue[ccw].obj;
|
|
break;
|
|
}
|
|
}
|
|
if (cameraObj != new_cameraObj)
|
|
{
|
|
moduleKeyList.append(camerakey);
|
|
qDebug() << __FUNCTION__ << " line:" << __LINE__ << " obj change,camerakey:" << camerakey;
|
|
}
|
|
newcameraListArray.append(new_cameraObj);
|
|
}
|
|
|
|
//算法部分
|
|
QJsonArray algorithmListArray = stationObj.value("算法列表").toArray();
|
|
//QQueue< QJsonObject>cameraListObj;
|
|
QJsonArray newalgorithmListArray;
|
|
for (int CA = 0; CA < algorithmListArray.size(); CA++)
|
|
{
|
|
QJsonObject algorithmObj = algorithmListArray[CA].toObject();
|
|
QString algorithmkey = algorithmObj.value("算法名称").toString();
|
|
QJsonObject new_algorithmObj;
|
|
for (int ccw = 0; ccw < algorithmCfgWindowQueue.size(); ccw++)
|
|
{
|
|
if (algorithmkey == algorithmCfgWindowQueue[ccw].Key && stationKey== algorithmCfgWindowQueue[ccw].stationName)
|
|
{
|
|
new_algorithmObj = algorithmCfgWindowQueue[ccw].obj;
|
|
break;
|
|
}
|
|
}
|
|
if (algorithmObj != new_algorithmObj)
|
|
{
|
|
moduleKeyList.append(algorithmkey);
|
|
qDebug() << __FUNCTION__ << " line:" << __LINE__ << " obj change,algorithmkey:" << algorithmkey;
|
|
}
|
|
newalgorithmListArray.append(new_algorithmObj);
|
|
}
|
|
stationObj.insert("相机模块列表", newcameraListArray);
|
|
stationObj.insert("算法列表", newalgorithmListArray);
|
|
newstationArray.append(stationObj);
|
|
}
|
|
stationArray = newstationArray;
|
|
|
|
QJsonObject newprogramObj = programObj;
|
|
newprogramObj.insert("工站列表", newstationArray);
|
|
|
|
if (newprogramObj != programObj)
|
|
{
|
|
//内存中的数据写到文件
|
|
QJsonDocument doc(newprogramObj);
|
|
//将json对象转换成字符串
|
|
QByteArray data = doc.toJson();
|
|
QFile file(json_cfg_file_path);
|
|
file.open(QIODevice::WriteOnly);
|
|
file.write(data);
|
|
file.close();
|
|
|
|
emit reLoadJsonSetParameter(moduleKeyList);
|
|
}
|
|
}
|
|
|
|
QJsonObject QtParameterSettings::load_camera_cfg(QString cfg)
|
|
{
|
|
cfg_name = cfg;
|
|
QDir dir = QApplication::applicationDirPath();
|
|
currPath = dir.path();
|
|
json_cfg_file_path = currPath + "/config/" + cfg;//camera_cfg.json";
|
|
QString tmpDate = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz");
|
|
BackUp_json_cfg_file_path= currPath + "/config/backup/" + tmpDate+"_"+ cfg;
|
|
|
|
QJsonObject json_object;
|
|
try
|
|
{
|
|
QJsonParseError jsonError;
|
|
if (json_cfg_file_path.isEmpty())
|
|
{
|
|
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " JsonPath is null!";
|
|
return json_object;
|
|
}
|
|
|
|
QFile JsonFile;
|
|
JsonFile.setFileName(json_cfg_file_path);
|
|
if (!JsonFile.isReadable())
|
|
{
|
|
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " camera_cfg.json not isReadable!";
|
|
//return json_object;
|
|
}
|
|
JsonFile.open(QIODevice::ReadOnly);
|
|
|
|
QByteArray m_Byte = JsonFile.readAll();
|
|
if (m_Byte.isEmpty())
|
|
{
|
|
qDebug() << __FUNCTION__ << " line:" << __LINE__ << json_cfg_file_path + " Content is empty";
|
|
JsonFile.close();
|
|
return json_object;
|
|
}
|
|
|
|
QJsonDocument jsonDocument(QJsonDocument::fromJson(m_Byte, &jsonError));
|
|
|
|
if (!jsonDocument.isNull() && jsonError.error == QJsonParseError::NoError)
|
|
{
|
|
if (jsonDocument.isObject())
|
|
{
|
|
json_object = jsonDocument.object();
|
|
JsonFile.close();
|
|
return json_object;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
qCritical() << __FUNCTION__ << " line:" << __LINE__ << json_cfg_file_path + " is error!";
|
|
}
|
|
JsonFile.close();
|
|
|
|
}
|
|
catch (QString ev)
|
|
{
|
|
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " ev:" << ev;
|
|
}
|
|
programObj = json_object;
|
|
return json_object;
|
|
}
|
|
|
|
|
|
|
|
QtParameterSettings::~QtParameterSettings()
|
|
{
|
|
for (int i = 0; i < algorithmCfgWindowQueue.size(); i++)
|
|
{
|
|
delete algorithmCfgWindowQueue[i].myAddButton;
|
|
delete algorithmCfgWindowQueue[i].myDelButton;
|
|
delete algorithmCfgWindowQueue[i].myTbleWidget;
|
|
delete algorithmCfgWindowQueue[i].myQGroupBox;
|
|
}
|
|
for (int i = 0; i < cameraCfgWindowQueue.size(); i++)
|
|
{
|
|
delete cameraCfgWindowQueue[i].myAddButton;
|
|
delete cameraCfgWindowQueue[i].myDelButton;
|
|
delete cameraCfgWindowQueue[i].myTbleWidget;
|
|
delete cameraCfgWindowQueue[i].myQGroupBox;
|
|
}
|
|
for (int i = 0; i < algorithmCfgWindowQueue.size(); i++)
|
|
algorithmCfgWindowQueue.dequeue();
|
|
for (int i = 0; i < cameraCfgWindowQueue.size(); i++)
|
|
cameraCfgWindowQueue.dequeue();
|
|
ui.tabWidget_algorithm = nullptr;
|
|
//delete ui.tabWidget_algorithm;
|
|
//ui.tabWidget_algorithm = new QTabWidget(ui.groupBox_algorithmCfg);
|
|
//ui.tabWidget_algorithm->setObjectName(QString::fromUtf8("tabWidget_algorithm"));
|
|
//ui.tab_2 = new QWidget();
|
|
//ui.tab_2->setObjectName(QString::fromUtf8("tab_2"));
|
|
//ui.tabWidget_algorithm->addTab(ui.tab_2, QString("第1页"));
|
|
|
|
//ui.gridLayout_2->addWidget(ui.tabWidget_algorithm, 2, 1, 1, 1);
|
|
////ui.tabWidget_camera->removeTab(0);
|
|
//ui.groupBox_algorithmCfg->setTitle("算法参数");
|
|
|
|
|
|
ui.tabWidget_camera = nullptr;
|
|
|
|
delete ui.tabWidget_camera;
|
|
//ui.tabWidget_camera = new QTabWidget(ui.groupBox_cameraCfg);
|
|
//ui.tabWidget_camera->setObjectName(QString::fromUtf8("tabWidget_camera"));
|
|
//ui.tab = new QWidget();
|
|
//ui.tab->setObjectName(QString::fromUtf8("tab"));
|
|
//ui.tabWidget_camera->addTab(ui.tab, QString("第1页"));
|
|
|
|
//ui.gridLayout->addWidget(ui.tabWidget_camera, 2, 1, 1, 1);
|
|
|
|
//ui.groupBox_cameraCfg->setTitle("相机参数");
|
|
|
|
////ui.tabWidget_camera->setCurrentIndex(0);
|
|
//for (int i = 0; i < cameraCfgWindowQueue.size(); i++)
|
|
//{
|
|
// //delete cameraCfgWindowQueue[i].myAddButton;
|
|
// //delete cameraCfgWindowQueue[i].myDelButton;
|
|
// //delete cameraCfgWindowQueue[i].myTbleWidget;
|
|
// //delete cameraCfgWindowQueue[i].myQGroupBox;
|
|
// //cameraCfgWindowQueue[i].myTbleWidget->setRowCount(0);
|
|
|
|
// //for (int j = cameraCfgWindowQueue[i].myTbleWidget->rowCount() - 1; j >= 0; j--)
|
|
// // cameraCfgWindowQueue[i].myTbleWidget->removeRow(j);
|
|
|
|
// if ((i % 6 == 5 || i == cameraCfgWindowQueue.size() - 1) && i > 5)
|
|
// {
|
|
// ui.tabWidget_camera->removeTab(i / 6);
|
|
// //delete ui.tabWidget_camera->widget(i / 6);
|
|
// }
|
|
//}
|
|
qApp->processEvents();
|
|
currentPage_cameraNum = 0;
|
|
cameraCfgWindowQueue.clear();
|
|
|
|
//ui.tabWidget_algorithm->setCurrentIndex(0);
|
|
|
|
//for (int i = 0; i < algorithmCfgWindowQueue.size(); i++)
|
|
//{
|
|
// if (i % 6 == 0 && i > 5)
|
|
// ui.tabWidget_algorithm->removeTab(i / 6);
|
|
// /*delete algorithmCfgWindowQueue[i].myAddButton;
|
|
// delete algorithmCfgWindowQueue[i].myDelButton;
|
|
// delete algorithmCfgWindowQueue[i].myTbleWidget;
|
|
// delete algorithmCfgWindowQueue[i].myQGroupBox;*/
|
|
//}
|
|
|
|
//ui.tabWidget_camera->removeTab(0);
|
|
currentPage_algorithmNum = 0;
|
|
algorithmCfgWindowQueue.clear();
|
|
qApp->processEvents();
|
|
}
|
|
|
|
|
|
#define MOUSE_MARGIN 2
|
|
//计算鼠标位置
|
|
QtParameterSettings::MousePoss QtParameterSettings::calcmouseposs(QPoint p)
|
|
{
|
|
QtParameterSettings::MousePoss mp;
|
|
if (p.x() < MOUSE_MARGIN && p.y() < MOUSE_MARGIN)
|
|
mp = QtParameterSettings::MousePoss::LeftUp; //左上
|
|
else if (p.x() > MOUSE_MARGIN && p.y() < MOUSE_MARGIN && p.x() < this->width() - MOUSE_MARGIN)
|
|
mp = QtParameterSettings::MousePoss::Up; //上
|
|
else if (p.x() > this->width() - MOUSE_MARGIN && p.y() < MOUSE_MARGIN)
|
|
mp = QtParameterSettings::MousePoss::RightUp; //右上
|
|
else if (p.x() > this->width() - MOUSE_MARGIN && p.y() > MOUSE_MARGIN && p.y() < this->height() - MOUSE_MARGIN)
|
|
mp = QtParameterSettings::MousePoss::Right; //右
|
|
else if (p.x() > this->width() - MOUSE_MARGIN && p.y() > this->height() - MOUSE_MARGIN)
|
|
mp = QtParameterSettings::MousePoss::RightDown; //右下
|
|
else if (p.x() > MOUSE_MARGIN && p.x() < this->width() - MOUSE_MARGIN && p.y() > this->height() - MOUSE_MARGIN)
|
|
mp = QtParameterSettings::MousePoss::Down; //下
|
|
else if (p.x() < MOUSE_MARGIN && p.y() > this->height() - MOUSE_MARGIN)
|
|
mp = QtParameterSettings::MousePoss::LeftDown; //左下
|
|
else if (p.x() < MOUSE_MARGIN && p.y() < this->height() - MOUSE_MARGIN && p.y() > MOUSE_MARGIN)
|
|
mp = QtParameterSettings::MousePoss::Left; //左
|
|
else
|
|
mp = QtParameterSettings::MousePoss::Middle; //中间
|
|
return mp;
|
|
}
|
|
//修改鼠标样式
|
|
void QtParameterSettings::setCursorType(QtParameterSettings::MousePoss type)
|
|
{
|
|
Qt::CursorShape cursor;
|
|
switch (type)
|
|
{
|
|
case QtParameterSettings::MousePoss::LeftUp:
|
|
case QtParameterSettings::MousePoss::RightDown:
|
|
cursor = Qt::SizeFDiagCursor;
|
|
break;
|
|
case QtParameterSettings::MousePoss::Up:
|
|
case QtParameterSettings::MousePoss::Down:
|
|
cursor = Qt::SizeVerCursor;
|
|
break;
|
|
case QtParameterSettings::MousePoss::RightUp:
|
|
case QtParameterSettings::MousePoss::LeftDown:
|
|
cursor = Qt::SizeBDiagCursor;
|
|
break;
|
|
case QtParameterSettings::MousePoss::Right:
|
|
case QtParameterSettings::MousePoss::Left:
|
|
cursor = Qt::SizeHorCursor;
|
|
break;
|
|
default:
|
|
cursor = Qt::ArrowCursor;
|
|
break;
|
|
}
|
|
setCursor(cursor);
|
|
}
|
|
//改变窗口的大小
|
|
void QtParameterSettings::changeWindowSize(QtParameterSettings::MousePoss type, QRect& wid, QPoint ptemp, int minWidth, int minHeight)
|
|
{
|
|
switch (type)//改变窗口的大小
|
|
{
|
|
case QtParameterSettings::MousePoss::LeftUp:
|
|
{
|
|
QPoint pos = wid.topLeft();
|
|
|
|
if (wid.width() > minWidth || ptemp.x() < 0)
|
|
pos.rx() = pos.rx() + ptemp.x();
|
|
if (wid.height() > minHeight || ptemp.y() < 0)
|
|
pos.ry() = pos.ry() + ptemp.y();
|
|
|
|
wid.setTopLeft(pos);
|
|
break;//左上角
|
|
}
|
|
case QtParameterSettings::MousePoss::RightUp:
|
|
{
|
|
QPoint pos = wid.topRight();
|
|
|
|
if (wid.width() > minWidth || ptemp.x() > 0)
|
|
pos.rx() = pos.rx() + ptemp.x();
|
|
if (wid.height() > minHeight || ptemp.y() < 0)
|
|
pos.ry() = pos.ry() + ptemp.y();
|
|
|
|
wid.setTopRight(pos);
|
|
break;//右上角
|
|
}
|
|
case QtParameterSettings::MousePoss::LeftDown:
|
|
{
|
|
QPoint pos = wid.bottomLeft();
|
|
|
|
if (wid.width() > minWidth || ptemp.x() < 0)
|
|
pos.rx() = pos.rx() + ptemp.x();
|
|
if (wid.height() > minHeight || ptemp.y() > 0)
|
|
pos.ry() = pos.ry() + ptemp.y();
|
|
|
|
wid.setBottomLeft(pos);
|
|
break;//左下角
|
|
}
|
|
case QtParameterSettings::MousePoss::RightDown:
|
|
{
|
|
QPoint pos = wid.bottomRight();
|
|
|
|
if (wid.width() > minWidth || ptemp.x() > 0)
|
|
pos.rx() = pos.rx() + ptemp.x();
|
|
if (wid.height() > minHeight || ptemp.y() > 0)
|
|
pos.ry() = pos.ry() + ptemp.y();
|
|
|
|
wid.setBottomRight(pos);
|
|
break;//右下角
|
|
}
|
|
case QtParameterSettings::MousePoss::Up:
|
|
{
|
|
int topY = wid.top();
|
|
if (wid.height() > minHeight || ptemp.y() < 0)
|
|
topY = topY + ptemp.y();
|
|
|
|
wid.setTop(topY);
|
|
break;//上
|
|
}
|
|
case QtParameterSettings::MousePoss::Left:
|
|
{
|
|
int leftX = wid.left();
|
|
|
|
if (wid.width() > minWidth || ptemp.x() < 0)
|
|
leftX = leftX + ptemp.x();
|
|
|
|
wid.setLeft(leftX);
|
|
break;//左
|
|
}
|
|
case QtParameterSettings::MousePoss::Right:
|
|
{
|
|
int rightX = wid.right();
|
|
|
|
if (wid.width() > minWidth || ptemp.x() > 0)
|
|
rightX = rightX + ptemp.x();
|
|
|
|
wid.setRight(rightX);
|
|
break;//右
|
|
}
|
|
case QtParameterSettings::MousePoss::Down:
|
|
{
|
|
int botY = wid.bottom();
|
|
if (wid.height() > minHeight || ptemp.y() > 0)
|
|
botY = botY + ptemp.y();
|
|
|
|
wid.setBottom(botY);
|
|
break;//下
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
//三个鼠标事件的重写
|
|
void QtParameterSettings::mousePressEvent(QMouseEvent* e)
|
|
{
|
|
|
|
if (e->button() == Qt::LeftButton) //鼠标左键按下
|
|
{
|
|
m_lastPos = e->globalPos();
|
|
e->ignore();
|
|
}
|
|
|
|
|
|
}
|
|
//鼠标移动
|
|
void QtParameterSettings::mouseMoveEvent(QMouseEvent* e)
|
|
{
|
|
//最大化状态,鼠标是否在标题栏,拖拽还原
|
|
if (this->isMaximized())
|
|
{
|
|
if (ui.title->geometry().contains(this->mapFromGlobal(QCursor::pos())) && e->buttons() == Qt::LeftButton)
|
|
{
|
|
QPoint ptemp = e->globalPos();
|
|
if (ptemp != m_lastPos)
|
|
{
|
|
this->showNormal();
|
|
}
|
|
}
|
|
}
|
|
QtParameterSettings::MousePoss curPos = calcmouseposs(e->pos());
|
|
if (!e->buttons())
|
|
{
|
|
setCursorType(curPos);
|
|
mp_curPos = curPos;
|
|
}
|
|
|
|
if (e->buttons() == Qt::LeftButton) //坐标左键按下并移动
|
|
{
|
|
QPoint ptemp = e->globalPos();
|
|
ptemp = ptemp - m_lastPos; //鼠标移动的偏移量
|
|
if (mp_curPos == QtParameterSettings::MousePoss::Middle && ui.title->geometry().contains(this->mapFromGlobal(QCursor::pos()))
|
|
&& !ui.pushButton_max->geometry().contains(this->mapFromGlobal(QCursor::pos()))
|
|
&& !ui.pushButton_min->geometry().contains(this->mapFromGlobal(QCursor::pos()))
|
|
&& !ui.pushButton_close->geometry().contains(this->mapFromGlobal(QCursor::pos())))
|
|
{
|
|
move(ptemp + pos());
|
|
}
|
|
else
|
|
{
|
|
QRect wid = geometry();
|
|
int minWidth = this->minimumWidth();
|
|
int minHeight = this->minimumHeight();
|
|
if (ptemp.x() < 50 && ptemp.x() > -50)
|
|
{
|
|
changeWindowSize(mp_curPos, wid, ptemp, minWidth, minHeight);
|
|
//更新大小
|
|
setGeometry(wid);
|
|
}
|
|
}
|
|
m_lastPos = e->globalPos();
|
|
}
|
|
e->ignore();
|
|
}
|
|
//鼠标释放
|
|
void QtParameterSettings::mouseReleaseEvent(QMouseEvent* e)
|
|
{
|
|
if (e->button() == Qt::LeftButton && ui.title->geometry().contains(this->mapFromGlobal(QCursor::pos()))
|
|
&& !ui.pushButton_max->geometry().contains(this->mapFromGlobal(QCursor::pos()))
|
|
&& !ui.pushButton_min->geometry().contains(this->mapFromGlobal(QCursor::pos()))
|
|
&& !ui.pushButton_close->geometry().contains(this->mapFromGlobal(QCursor::pos()))) //鼠标左键释放
|
|
{
|
|
int dx = e->globalX() - m_lastPos.x();
|
|
int dy = e->globalY() - m_lastPos.y();
|
|
move(x() + dx, y() + dy);
|
|
}
|
|
QApplication::restoreOverrideCursor();//恢复鼠标指针性状
|
|
e->ignore();
|
|
} |