添加主界面逻辑
This commit is contained in:
parent
923b95bca6
commit
cf3b2c94d0
@ -16,16 +16,19 @@ SOURCES += \
|
|||||||
radial_vibration.cpp \
|
radial_vibration.cpp \
|
||||||
seismic_monitor.cpp \
|
seismic_monitor.cpp \
|
||||||
setpoint.cpp \
|
setpoint.cpp \
|
||||||
|
singlerelay.cpp \
|
||||||
tachometer.cpp \
|
tachometer.cpp \
|
||||||
velocity.cpp
|
velocity.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
acceleration.h \
|
acceleration.h \
|
||||||
|
data_config.h \
|
||||||
keyphase.h \
|
keyphase.h \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
radial_vibration.h \
|
radial_vibration.h \
|
||||||
seismic_monitor.h \
|
seismic_monitor.h \
|
||||||
setpoint.h \
|
setpoint.h \
|
||||||
|
singlerelay.h \
|
||||||
tachometer.h \
|
tachometer.h \
|
||||||
velocity.h
|
velocity.h
|
||||||
|
|
||||||
|
2053
acceleration.ui
2053
acceleration.ui
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
173
mainwindow.cpp
173
mainwindow.cpp
@ -2,6 +2,14 @@
|
|||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include "keyphase.h"
|
||||||
|
#include "singlerelay.h"
|
||||||
|
#include "tachometer.h"
|
||||||
|
#include "seismic_monitor.h"
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
@ -26,24 +34,64 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
btnGroup_slot->addButton(ui->pushButton_slot16);
|
btnGroup_slot->addButton(ui->pushButton_slot16);
|
||||||
btnGroup_slot->addButton(ui->pushButton_slot17);
|
btnGroup_slot->addButton(ui->pushButton_slot17);
|
||||||
|
|
||||||
|
ui->pushButton_slot->setChecked(true);
|
||||||
|
readJsonFile(QCoreApplication::applicationDirPath() + "\\config\\main.json");
|
||||||
createMenu();
|
createMenu();
|
||||||
|
|
||||||
|
connect(btnGroup_slot, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(OnButtonGroup(QAbstractButton *)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::readJsonFile(const QString &filePath)
|
||||||
|
{
|
||||||
|
// 创建文件对象
|
||||||
|
QFile file(filePath);
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
qDebug() << "Cannot open file for reading:" << filePath;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QString content = file.readAll();
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
QByteArray jsonData = content.toUtf8();
|
||||||
|
|
||||||
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
||||||
|
if (jsonDoc.isNull()) {
|
||||||
|
qDebug() << "Cannot parse JSON document";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!jsonDoc.isObject() && !jsonDoc.isArray()) {
|
||||||
|
qDebug() << "JSON document is not an object or an array";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int slot_id = 3;
|
||||||
|
QJsonArray jsonArray = jsonDoc.array();
|
||||||
|
for (const QJsonValue &value : jsonArray) {
|
||||||
|
SlotConfig slot_config;
|
||||||
|
if (value.isObject()) { // 处理数组中的对象,例如每个对象代表一个记录或用户等。
|
||||||
|
QJsonObject obj = value.toObject();
|
||||||
|
slot_config.slot = obj["slot"].toInt();
|
||||||
|
slot_config.slot_type = obj["slot_type"].toInt();
|
||||||
|
slot_config.chan_type = obj["chan_type"].toString();
|
||||||
|
slot_config.rack_type = obj["rack_type"].toString();
|
||||||
|
map_slot_config.insert(slot_id,slot_config);
|
||||||
|
slot_id ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
void MainWindow::createMenu()
|
void MainWindow::createMenu()
|
||||||
{
|
{
|
||||||
QList<QAbstractButton*> buttonList = btnGroup_slot->buttons();
|
QList<QAbstractButton*> buttonList = btnGroup_slot->buttons();
|
||||||
for (int i = 0; i < buttonList.count(); i++){
|
for (int i = 0; i < buttonList.count(); i++){
|
||||||
slot_type.insert(buttonList[i]->objectName(),"");
|
//buttonList[i]->setText(map_slot_config[i + 3].chan_type);
|
||||||
}
|
createMenu(QString("%1").arg(i + 1), (QPushButton*)buttonList[i]);
|
||||||
for (int i = 0; i < buttonList.count(); i++){
|
// else
|
||||||
if(slot_type[buttonList[i]->objectName()] == "")
|
// createMenuSet(QString("%1").arg(i + 1), (QPushButton*)buttonList[i]);
|
||||||
createMenu(QString("%1").arg(i + 1), (QPushButton*)buttonList[i]);
|
|
||||||
else
|
|
||||||
createMenuSet(QString("%1").arg(i + 1), (QPushButton*)buttonList[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void MainWindow::createMenu(const QString& rootTitle, QPushButton* parent )
|
void MainWindow::createMenu(const QString& rootTitle, QPushButton* parent )
|
||||||
@ -99,7 +147,9 @@ void MainWindow::createMenu(const QString& rootTitle, QPushButton* parent )
|
|||||||
QObject::connect(keyphasor_1, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
QObject::connect(keyphasor_1, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
||||||
QObject::connect(keyphasor_2, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
QObject::connect(keyphasor_2, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
||||||
QObject::connect(reset, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
QObject::connect(reset, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::createMenuSet(const QString& rootTitle, QPushButton* parent )
|
void MainWindow::createMenuSet(const QString& rootTitle, QPushButton* parent )
|
||||||
{
|
{
|
||||||
// 创建主菜单
|
// 创建主菜单
|
||||||
@ -146,14 +196,35 @@ void MainWindow::onMenuActionTriggered()
|
|||||||
while (menu) {
|
while (menu) {
|
||||||
QPushButton *button = qobject_cast<QPushButton*>(menu->parent());
|
QPushButton *button = qobject_cast<QPushButton*>(menu->parent());
|
||||||
if (button) {
|
if (button) {
|
||||||
qDebug() << "子菜单项被点击,所属按钮:" << button->objectName();
|
qDebug() << "子菜单项被点击,所属按钮:" << button->objectName() << action->text();
|
||||||
|
int slot_type = action->text().mid(1,2).toInt();
|
||||||
|
QString rack_type = action->text().right(action->text().length()-4);
|
||||||
|
int button_id = button->objectName().right(button->objectName().length()-15).toInt();
|
||||||
|
qDebug() << slot_type << rack_type << button_id << map_slot_config[button_id + 1].slot_type << map_slot_config[button_id + 2].slot_type << endl;
|
||||||
|
if(rack_type == "三冗余板卡" && (map_slot_config[button_id + 1].slot_type != 0 \
|
||||||
|
|| map_slot_config[button_id + 2].slot_type != 0)){
|
||||||
|
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠三冗余板卡配置,请在创建新配置之前移除现有的配置!");
|
||||||
|
return;
|
||||||
|
}else if(rack_type == "三冗余板卡" && map_slot_config[button_id + 1].slot_type == 0 \
|
||||||
|
&& map_slot_config[button_id + 2].slot_type == 0){
|
||||||
|
map_slot_config[button_id].slot_type = slot_type;
|
||||||
|
map_slot_config[button_id].rack_type = "TMR";
|
||||||
|
}
|
||||||
|
if(rack_type == "两板卡" && map_slot_config[button_id + 1].slot_type != 0 ){
|
||||||
|
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠两板卡配置,请在创建新配置之前移除现有的配置!");
|
||||||
|
return;
|
||||||
|
}else if(rack_type == "两板卡" && map_slot_config[button_id + 1].slot_type == 0){
|
||||||
|
map_slot_config[button_id].slot_type = slot_type;
|
||||||
|
map_slot_config[button_id].rack_type = "Double";
|
||||||
|
}
|
||||||
|
map_slot_config[button_id].slot_type = slot_type;
|
||||||
|
map_slot_config[button_id].rack_type = "Single";
|
||||||
button->setText(action->text());
|
button->setText(action->text());
|
||||||
slot_type[button->objectName()] = action->text();
|
|
||||||
QMenu* menu = button->menu();
|
QMenu* menu = button->menu();
|
||||||
if (!menu) {
|
if (!menu) {
|
||||||
qWarning() << "菜单为空,无法清除属性!";
|
qWarning() << "菜单为空,无法清除属性!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
clearMenuProperties(button->menu());
|
clearMenuProperties(button->menu());
|
||||||
createMenu();
|
createMenu();
|
||||||
break; // 找到按钮后,跳出循环
|
break; // 找到按钮后,跳出循环
|
||||||
@ -164,40 +235,94 @@ void MainWindow::onMenuActionTriggered()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::OnButtonGroup(QAbstractButton * slot_btn, bool checked)
|
void MainWindow::OnButtonGroup(QAbstractButton * slot_btn)
|
||||||
{
|
{
|
||||||
if(slot_btn != NULL)
|
if(slot_btn != NULL && ui->pushButton_chan->isChecked())
|
||||||
{
|
{
|
||||||
qDebug() << slot_btn->objectName();
|
QString object_name = slot_btn->objectName();
|
||||||
qDebug() << checked;
|
qDebug() << object_name << endl;
|
||||||
QString str;
|
int button_id = object_name.right(object_name.length()-15).toInt();
|
||||||
QList<QAbstractButton*> buttonList = btnGroup_slot->buttons();
|
SlotConfig slot_config = map_slot_config[button_id];
|
||||||
for (int i = 0; i < buttonList.count(); i++){
|
if (slot_config.slot_type == KEYPHASOR){
|
||||||
|
KeyPhase *key_phase = new KeyPhase();
|
||||||
|
key_phase->setWindowModality(Qt::ApplicationModal);
|
||||||
|
key_phase->show();
|
||||||
|
}else if (slot_config.slot_type == RELAY){
|
||||||
|
SingleRelay *single_relay = new SingleRelay();
|
||||||
|
single_relay->setWindowModality(Qt::ApplicationModal);
|
||||||
|
single_relay->show();
|
||||||
|
}else if (slot_config.slot_type == VIBRATE){
|
||||||
|
Seismic_monitor *seismic_monitor = new Seismic_monitor();
|
||||||
|
seismic_monitor->setWindowModality(Qt::ApplicationModal);
|
||||||
|
seismic_monitor->show();
|
||||||
|
}else if (slot_config.slot_type == RPM){
|
||||||
|
Tachometer *tachometer = new Tachometer();
|
||||||
|
tachometer->setWindowModality(Qt::ApplicationModal);
|
||||||
|
tachometer->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_pushButton_slot_clicked()
|
void MainWindow::on_pushButton_slot_clicked()
|
||||||
{
|
{
|
||||||
|
if(ui->pushButton_chan->isChecked())
|
||||||
|
ui->pushButton_chan->setChecked(false);
|
||||||
|
if(ui->pushButton_alarm->isChecked())
|
||||||
|
ui->pushButton_alarm->setChecked(false);
|
||||||
|
if(ui->pushButton_point_name->isChecked())
|
||||||
|
ui->pushButton_point_name->setChecked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_pushButton_chan_clicked()
|
void MainWindow::on_pushButton_chan_clicked()
|
||||||
{
|
{
|
||||||
|
if(ui->pushButton_slot->isChecked())
|
||||||
|
ui->pushButton_slot->setChecked(false);
|
||||||
|
if(ui->pushButton_alarm->isChecked())
|
||||||
|
ui->pushButton_alarm->setChecked(false);
|
||||||
|
if(ui->pushButton_point_name->isChecked())
|
||||||
|
ui->pushButton_point_name->setChecked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_pushButton_alarm_clicked()
|
void MainWindow::on_pushButton_alarm_clicked()
|
||||||
{
|
{
|
||||||
|
if(ui->pushButton_slot->isChecked())
|
||||||
|
ui->pushButton_slot->setChecked(false);
|
||||||
|
if(ui->pushButton_chan->isChecked())
|
||||||
|
ui->pushButton_chan->setChecked(false);
|
||||||
|
if(ui->pushButton_point_name->isChecked())
|
||||||
|
ui->pushButton_point_name->setChecked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_pushButton_point_name_clicked()
|
void MainWindow::on_pushButton_point_name_clicked()
|
||||||
{
|
{
|
||||||
|
if(ui->pushButton_slot->isChecked())
|
||||||
|
ui->pushButton_slot->setChecked(false);
|
||||||
|
if(ui->pushButton_chan->isChecked())
|
||||||
|
ui->pushButton_chan->setChecked(false);
|
||||||
|
if(ui->pushButton_alarm->isChecked())
|
||||||
|
ui->pushButton_alarm->setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::on_pushButton_save_clicked()
|
||||||
|
{
|
||||||
|
QJsonObject itemObj;
|
||||||
|
QJsonArray slotArray;
|
||||||
|
for(int i = 0; i < map_slot_config.size();i++){
|
||||||
|
itemObj["slot"] = map_slot_config[i+3].slot;
|
||||||
|
itemObj["slot_type"] = map_slot_config[i+3].slot_type;
|
||||||
|
itemObj["chan_type"] = map_slot_config[i+3].chan_type;
|
||||||
|
itemObj["rack_type"] = map_slot_config[i+3].rack_type;
|
||||||
|
slotArray.append(itemObj);
|
||||||
|
}
|
||||||
|
QJsonDocument jsonDoc;
|
||||||
|
jsonDoc.setArray(slotArray);
|
||||||
|
QFile file(QCoreApplication::applicationDirPath() + "\\config\\main.json");
|
||||||
|
file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(jsonDoc.toJson());
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include "data_config.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui { class MainWindow; }
|
namespace Ui { class MainWindow; }
|
||||||
@ -29,7 +30,7 @@ private:
|
|||||||
//声明菜单
|
//声明菜单
|
||||||
QMenu * button_menu;
|
QMenu * button_menu;
|
||||||
|
|
||||||
QMap<QString,QString> slot_type;
|
QMap<int,SlotConfig> map_slot_config;
|
||||||
|
|
||||||
QButtonGroup * btnGroup_slot = nullptr;
|
QButtonGroup * btnGroup_slot = nullptr;
|
||||||
|
|
||||||
@ -38,14 +39,17 @@ private:
|
|||||||
void createMenuSet(const QString& rootTitle, QPushButton* button = nullptr);
|
void createMenuSet(const QString& rootTitle, QPushButton* button = nullptr);
|
||||||
void clearMenuProperties(QMenu* menu);
|
void clearMenuProperties(QMenu* menu);
|
||||||
|
|
||||||
|
void readJsonFile(const QString &filePath);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void OnButtonGroup(QAbstractButton *, bool);
|
void OnButtonGroup(QAbstractButton *);
|
||||||
|
|
||||||
void onMenuActionTriggered();
|
void onMenuActionTriggered();
|
||||||
void on_pushButton_slot_clicked();
|
void on_pushButton_slot_clicked();
|
||||||
void on_pushButton_chan_clicked();
|
void on_pushButton_chan_clicked();
|
||||||
void on_pushButton_alarm_clicked();
|
void on_pushButton_alarm_clicked();
|
||||||
void on_pushButton_point_name_clicked();
|
void on_pushButton_point_name_clicked();
|
||||||
|
void on_pushButton_save_clicked();
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
<height>100</height>
|
<height>100</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QPushButton" name="pushButton_20">
|
<widget class="QPushButton" name="pushButton_save">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>20</x>
|
<x>20</x>
|
||||||
@ -54,7 +54,7 @@
|
|||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string>保存</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QPushButton" name="pushButton_21">
|
<widget class="QPushButton" name="pushButton_21">
|
||||||
@ -269,6 +269,9 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>板卡配置</string>
|
<string>板卡配置</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -282,6 +285,9 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>通道配置</string>
|
<string>通道配置</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -295,6 +301,9 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>触发配置</string>
|
<string>触发配置</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -308,6 +317,9 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>测点名称</string>
|
<string>测点名称</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
2132
seismic_monitor.ui
2132
seismic_monitor.ui
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user