123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- #include "JIoMapPage.h"
- #include <Machine.h>
- #include <QJsonObject>
- JIoMapPage::JIoMapPage() {}
- QWidget* JIoMapPage::CreateIoPage(const CONFIG_BASE_STRUCT& control)
- {
- // 1.用到表中的变量
- QString strName = control.strName.c_str();
- // 2. 创建垂直布局
- QHBoxLayout* pHLayout = new QHBoxLayout();
- IoStateLab* pIoState = new IoStateLab();
- pIoState->setIoName(strName);
- QLabel* pAxisNmae = new QLabel();
- QString strAxisName = tr("AxisNmae:", "轴名称:");
- strAxisName += strName;
- pAxisNmae->setText(strAxisName);
- //QLabel* pLow = new QLabel();
- //pLow->setText(tr("Voltage status", "电压状态"));
- //QComboBox* pComBox = new QComboBox();
- //pComBox->addItem(tr("Low", "低电平"));
- //pComBox->addItem(tr("High","高电平"));
- //pComBox->setCurrentIndex(1);
- //// 连接信号和槽
- //connect(pComBox, &QComboBox::currentTextChanged, []() {
- // });
- // 轴名称
- pHLayout->addWidget(pAxisNmae);
- //// 电平组合
- //pHLayout->addWidget(pLow);
- //pHLayout->addWidget(pComBox);
- // 改变状态标记
- pHLayout->addWidget(pIoState);
- QWidget* pWidget = new QWidget;
- pWidget->setLayout(pHLayout);
- return pWidget;
- }
- QWidget* JIoMapPage::CreateAxisTestPage(const CONFIG_BASE_STRUCT& control)
- {
- // 1.用到表中的变量
- QString strName = control.strName.c_str();
- QHBoxLayout* pHLayout = new QHBoxLayout();
- QLabel* pAxisNmae = new QLabel();
- QString strAxisName = tr("AxisNmae:", "轴名称:");
- strAxisName += strName;
- pAxisNmae->setText(strAxisName);
- pHLayout->addWidget(pAxisNmae);
- QLineEdit* pCardNumberType = new QLineEdit(tr("Card Number Type", "卡号类型"));
- pCardNumberType->setText("0");
- pHLayout->addWidget(pCardNumberType);
- QLineEdit* pCardNumber = new QLineEdit(tr("Card Number", "卡号"));
- pCardNumber->setText("0");
- pHLayout->addWidget(pCardNumberType);
- QPushButton* pTest = new QPushButton(tr("Axis Test","轴测试"));
- QObject::connect(pTest, &QPushButton::clicked, [strName]()
- {
- ns_module::CViewMotion::GetInstance()->ShowMotionAdjustPage(strName.toStdString());
- });
- pHLayout->addWidget(pTest);
- QWidget* pWidget = new QWidget;
- pWidget->setLayout(pHLayout);
- return pWidget;
- }
- void JIoMapPage::JCreateMenu(QWidget* pWidget)
- {
- // 设置上下文菜单策略
- pWidget->setContextMenuPolicy(Qt::CustomContextMenu);
- // 连接信号到槽函数
- connect(pWidget, &QWidget::customContextMenuRequested, [=](const QPoint& pos)
- {
- QMenu menu;
- QAction* pGetAct = menu.addAction(tr("Get","获取"));
- QAction* pSetUpAct = menu.addAction(tr("set up","设置"));
- QAction* pDefValUpAct = menu.addAction(tr("default value", "默认值"));
- // 连接动作的触发信号
- connect(pGetAct, &QAction::triggered, []() { qDebug() << "Get"; });
- connect(pSetUpAct, &QAction::triggered, []() { qDebug() << "set up"; });
- connect(pDefValUpAct, &QAction::triggered, []() { qDebug() << "default value"; });
- // 显示菜单
- menu.exec(pWidget->mapToGlobal(pos));
- });
- }
- void JIoMapPage::JCreateMenu(QWidget* pWidget, ST_DEFAULT_VAL defaultVal)
- {
- pWidget->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(pWidget, &QWidget::customContextMenuRequested, [=](const QPoint& pos)
- {
- QMenu menu;
- QAction* pDefValUpAct = menu.addAction(tr("default value", "默认值"));
- connect(pDefValUpAct, &QAction::triggered, [defaultVal]()
- {
- if (!defaultVal.fieldDefult.isEmpty())
- {
- defaultVal.lineEdit->setText(defaultVal.fieldDefult);
- }
- });
- menu.exec(pWidget->mapToGlobal(pos));
- });
- }
- QLabel* JIoMapPage::JCreateName0(const QString& fieldDescribe, const QString& fieldDescribe_Eng, int nlanguage)
- {
- QLabel* pNameLable = new QLabel();
- if (nlanguage == 0)
- {
- pNameLable->setText(fieldDescribe_Eng);
- if (fieldDescribe_Eng.isEmpty())
- {
- pNameLable->setText(fieldDescribe);
- }
- }
- else
- {
- pNameLable->setText(fieldDescribe);
- if (fieldDescribe.isEmpty())
- {
- pNameLable->setText(fieldDescribe_Eng);
- }
- }
- pNameLable->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
- pNameLable->setFixedHeight(24);
- pNameLable->setMinimumWidth(120);
- return pNameLable;
- }
- AutoResizeLabel* JIoMapPage::JCreateJText(const QString& name)
- {
- AutoResizeLabel* pLabel = new AutoResizeLabel();
- pLabel->setText(name);
- pLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
- //pLabel->setFixedHeight(24);
- //pLabel->setMinimumWidth(120);
- return pLabel;
- }
- QList<ST_DATA_ITEM> JIoMapPage::parseJsonToDataList(const QString& jsonString)
- {
- QList<ST_DATA_ITEM> dataList;
- QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonString.toUtf8());
- if (jsonDoc.isNull() || !jsonDoc.isArray())
- {
- qWarning() << "解析失败或JSON不是数组";
- return dataList;
- }
- QJsonArray jsonArray = jsonDoc.array();
- // 遍历数组
- for (const QJsonValue& val : jsonArray)
- {
- if (val.isObject())
- {
- QJsonObject obj = val.toObject();
- ST_DATA_ITEM item;
- item.key = obj.value("key").toString();
- item.value = obj.value("value").toString();
- dataList.append(item);
- }
- }
- return dataList;
- }
|