添加主界面逻辑
This commit is contained in:
parent
923b95bca6
commit
cf3b2c94d0
@ -16,16 +16,19 @@ SOURCES += \
|
||||
radial_vibration.cpp \
|
||||
seismic_monitor.cpp \
|
||||
setpoint.cpp \
|
||||
singlerelay.cpp \
|
||||
tachometer.cpp \
|
||||
velocity.cpp
|
||||
|
||||
HEADERS += \
|
||||
acceleration.h \
|
||||
data_config.h \
|
||||
keyphase.h \
|
||||
mainwindow.h \
|
||||
radial_vibration.h \
|
||||
seismic_monitor.h \
|
||||
setpoint.h \
|
||||
singlerelay.h \
|
||||
tachometer.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 <QDebug>
|
||||
#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)
|
||||
: QMainWindow(parent)
|
||||
@ -26,24 +34,64 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
btnGroup_slot->addButton(ui->pushButton_slot16);
|
||||
btnGroup_slot->addButton(ui->pushButton_slot17);
|
||||
|
||||
ui->pushButton_slot->setChecked(true);
|
||||
readJsonFile(QCoreApplication::applicationDirPath() + "\\config\\main.json");
|
||||
createMenu();
|
||||
|
||||
connect(btnGroup_slot, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(OnButtonGroup(QAbstractButton *)));
|
||||
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
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()
|
||||
{
|
||||
QList<QAbstractButton*> buttonList = btnGroup_slot->buttons();
|
||||
for (int i = 0; i < buttonList.count(); i++){
|
||||
slot_type.insert(buttonList[i]->objectName(),"");
|
||||
}
|
||||
for (int i = 0; i < buttonList.count(); i++){
|
||||
if(slot_type[buttonList[i]->objectName()] == "")
|
||||
createMenu(QString("%1").arg(i + 1), (QPushButton*)buttonList[i]);
|
||||
else
|
||||
createMenuSet(QString("%1").arg(i + 1), (QPushButton*)buttonList[i]);
|
||||
//buttonList[i]->setText(map_slot_config[i + 3].chan_type);
|
||||
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 )
|
||||
@ -99,7 +147,9 @@ void MainWindow::createMenu(const QString& rootTitle, QPushButton* parent )
|
||||
QObject::connect(keyphasor_1, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
||||
QObject::connect(keyphasor_2, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
||||
QObject::connect(reset, &QAction::triggered,this, &MainWindow::onMenuActionTriggered);
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::createMenuSet(const QString& rootTitle, QPushButton* parent )
|
||||
{
|
||||
// 创建主菜单
|
||||
@ -146,14 +196,35 @@ void MainWindow::onMenuActionTriggered()
|
||||
while (menu) {
|
||||
QPushButton *button = qobject_cast<QPushButton*>(menu->parent());
|
||||
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());
|
||||
slot_type[button->objectName()] = action->text();
|
||||
QMenu* menu = button->menu();
|
||||
if (!menu) {
|
||||
qWarning() << "菜单为空,无法清除属性!";
|
||||
return;
|
||||
}
|
||||
qWarning() << "菜单为空,无法清除属性!";
|
||||
return;
|
||||
}
|
||||
clearMenuProperties(button->menu());
|
||||
createMenu();
|
||||
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();
|
||||
qDebug() << checked;
|
||||
QString str;
|
||||
QList<QAbstractButton*> buttonList = btnGroup_slot->buttons();
|
||||
for (int i = 0; i < buttonList.count(); i++){
|
||||
|
||||
QString object_name = slot_btn->objectName();
|
||||
qDebug() << object_name << endl;
|
||||
int button_id = object_name.right(object_name.length()-15).toInt();
|
||||
SlotConfig slot_config = map_slot_config[button_id];
|
||||
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()
|
||||
{
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
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 <QButtonGroup>
|
||||
#include <QPushButton>
|
||||
#include "data_config.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
@ -29,7 +30,7 @@ private:
|
||||
//声明菜单
|
||||
QMenu * button_menu;
|
||||
|
||||
QMap<QString,QString> slot_type;
|
||||
QMap<int,SlotConfig> map_slot_config;
|
||||
|
||||
QButtonGroup * btnGroup_slot = nullptr;
|
||||
|
||||
@ -38,14 +39,17 @@ private:
|
||||
void createMenuSet(const QString& rootTitle, QPushButton* button = nullptr);
|
||||
void clearMenuProperties(QMenu* menu);
|
||||
|
||||
void readJsonFile(const QString &filePath);
|
||||
|
||||
private slots:
|
||||
|
||||
void OnButtonGroup(QAbstractButton *, bool);
|
||||
void OnButtonGroup(QAbstractButton *);
|
||||
|
||||
void onMenuActionTriggered();
|
||||
void on_pushButton_slot_clicked();
|
||||
void on_pushButton_chan_clicked();
|
||||
void on_pushButton_alarm_clicked();
|
||||
void on_pushButton_point_name_clicked();
|
||||
void on_pushButton_save_clicked();
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -32,7 +32,7 @@
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
<widget class="QPushButton" name="pushButton_20">
|
||||
<widget class="QPushButton" name="pushButton_save">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
@ -54,7 +54,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
<string>保存</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_21">
|
||||
@ -269,6 +269,9 @@
|
||||
<property name="text">
|
||||
<string>板卡配置</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -282,6 +285,9 @@
|
||||
<property name="text">
|
||||
<string>通道配置</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -295,6 +301,9 @@
|
||||
<property name="text">
|
||||
<string>触发配置</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -308,6 +317,9 @@
|
||||
<property name="text">
|
||||
<string>测点名称</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</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