2024-12-18 16:46:39 +08:00
|
|
|
#ifndef TMRRELAYASSOCIATION_H
|
|
|
|
#define TMRRELAYASSOCIATION_H
|
|
|
|
|
|
|
|
#include <QDialog>
|
2025-04-19 16:25:33 +08:00
|
|
|
#include <QButtonGroup>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include "data_config.h"
|
|
|
|
#include "config_mgr.h"
|
|
|
|
#include <QStandardItemModel> //数据模型类
|
|
|
|
#include <QTreeView>
|
2025-04-19 19:54:56 +08:00
|
|
|
#include "tmrrelayassociation_data.h"
|
2024-12-18 16:46:39 +08:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class TMRRelayAssociation;
|
|
|
|
}
|
2025-04-19 16:25:33 +08:00
|
|
|
struct ExprNode {
|
|
|
|
QString value;
|
|
|
|
QList<ExprNode*> children;
|
|
|
|
};
|
2025-04-21 17:23:38 +08:00
|
|
|
struct ExprValidationResult {
|
|
|
|
bool isValid;
|
|
|
|
int errorPos;
|
|
|
|
QString errorMsg;
|
|
|
|
};
|
2025-04-19 16:25:33 +08:00
|
|
|
class DropTreeModel : public QStandardItemModel {
|
|
|
|
public:
|
|
|
|
using QStandardItemModel::QStandardItemModel;
|
|
|
|
|
|
|
|
QStringList mimeTypes() const override {
|
|
|
|
return { "application/x-custom" };
|
|
|
|
}
|
|
|
|
|
|
|
|
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
|
|
|
|
int row, int column, const QModelIndex &parent) override {
|
|
|
|
if (!data->hasFormat("application/x-custom"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QByteArray rawData = data->data("application/x-custom");
|
|
|
|
QString customText = QString::fromUtf8(rawData);
|
|
|
|
|
|
|
|
QStandardItem *newItem = new QStandardItem(customText);
|
|
|
|
newItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable |
|
|
|
|
Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
|
|
|
|
|
|
|
QStandardItem *parentItem = this->itemFromIndex(parent);
|
|
|
|
if (!parentItem) parentItem = this->invisibleRootItem();
|
|
|
|
|
|
|
|
if (row < 0)
|
|
|
|
parentItem->appendRow(newItem);
|
|
|
|
else
|
|
|
|
parentItem->insertRow(row, newItem);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::DropActions supportedDropActions() const override {
|
|
|
|
return Qt::CopyAction;
|
|
|
|
}
|
|
|
|
};
|
2024-12-18 16:46:39 +08:00
|
|
|
|
|
|
|
class TMRRelayAssociation : public QDialog
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2025-04-19 16:25:33 +08:00
|
|
|
explicit TMRRelayAssociation(int slot,int cardtype,QWidget *parent = nullptr);
|
2024-12-18 16:46:39 +08:00
|
|
|
~TMRRelayAssociation();
|
2025-04-19 16:25:33 +08:00
|
|
|
int slot_no;
|
|
|
|
CardType car_type;
|
|
|
|
private slots:
|
|
|
|
void on_pushButton_cancel_clicked();
|
|
|
|
|
|
|
|
void on_pushButton_confirm_clicked();
|
|
|
|
|
|
|
|
void onComboBoxIndexChanged(int index);
|
|
|
|
|
|
|
|
void OnButtonGroup(QAbstractButton *);
|
2024-12-18 16:46:39 +08:00
|
|
|
|
2025-04-19 16:25:33 +08:00
|
|
|
|
|
|
|
void on_pushButton_and_clicked();
|
|
|
|
|
|
|
|
void on_pushButton_or_clicked();
|
|
|
|
|
|
|
|
void on_treeView_Relay_customContextMenuRequested(const QPoint &pos);
|
|
|
|
void slotDeleteItem();
|
2025-04-21 17:23:38 +08:00
|
|
|
void on_checkBox_sgcc_stateChanged(int arg1);
|
|
|
|
|
|
|
|
void on_pushButton_logic_clicked();
|
|
|
|
|
2024-12-18 16:46:39 +08:00
|
|
|
private:
|
|
|
|
Ui::TMRRelayAssociation *ui;
|
2025-04-19 16:25:33 +08:00
|
|
|
QButtonGroup * btnGroup_slot = nullptr;
|
|
|
|
DraggableListWidget *list_widget_available = nullptr;
|
|
|
|
int current_index;
|
|
|
|
QTreeView *treeView_relay;
|
|
|
|
QStandardItemModel *model_Relay;
|
2025-04-19 19:54:56 +08:00
|
|
|
std::shared_ptr<TmrrelayassociationData> relay_data = nullptr;
|
2025-04-19 16:25:33 +08:00
|
|
|
|
|
|
|
void Init();
|
|
|
|
void buildTreeFromExpression(QTreeView *treeView, const QString &expr);
|
|
|
|
ExprNode* parseExpression(const QString& expr, int& pos);
|
|
|
|
QStandardItem* buildItemTree(ExprNode* node);
|
|
|
|
void setExpressionToTreeView(QTreeView* treeView, const QString& expr);
|
|
|
|
QStandardItem* parseExpression(const QString &expr);
|
|
|
|
QString buildLogicExpression(QStandardItem *item);
|
2025-04-21 17:23:38 +08:00
|
|
|
ExprValidationResult validateLogicExpression(const QString& expr);
|
2024-12-18 16:46:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TMRRELAYASSOCIATION_H
|