|
@@ -0,0 +1,112 @@
|
|
|
+#ifndef JIOMAPPAGE_H
|
|
|
+#define JIOMAPPAGE_H
|
|
|
+
|
|
|
+class JIoMapPage
|
|
|
+{
|
|
|
+public:
|
|
|
+ JIoMapPage();
|
|
|
+};
|
|
|
+
|
|
|
+#include <QApplication>
|
|
|
+#include <QTableWidget>
|
|
|
+#include <QHeaderView>
|
|
|
+#include <QVBoxLayout>
|
|
|
+#include <QPushButton>
|
|
|
+#include <QWidget>
|
|
|
+#include <QMessageBox>
|
|
|
+
|
|
|
+class GPITableWidget : public QWidget {
|
|
|
+ Q_OBJECT
|
|
|
+
|
|
|
+public:
|
|
|
+ GPITableWidget(QWidget* parent = nullptr) : QWidget(parent) {
|
|
|
+ // 创建主布局
|
|
|
+ QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
|
|
+
|
|
|
+ // 创建表格控件
|
|
|
+ tableWidget = new QTableWidget(this);
|
|
|
+
|
|
|
+ // 设置表格属性
|
|
|
+ tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
+ tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
+ tableWidget->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
|
|
|
+
|
|
|
+ // 设置表头
|
|
|
+ QStringList headers;
|
|
|
+ headers << "GPI名称" << "卡号" << "卡类型" << "GPI号" << "有效电平" << "状态";
|
|
|
+ tableWidget->setColumnCount(headers.size());
|
|
|
+ tableWidget->setHorizontalHeaderLabels(headers);
|
|
|
+
|
|
|
+ // 设置表头自适应
|
|
|
+ tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
|
+
|
|
|
+ // 添加按钮
|
|
|
+ QPushButton* addButton = new QPushButton("添加行", this);
|
|
|
+ QPushButton* deleteButton = new QPushButton("删除行", this);
|
|
|
+ QPushButton* saveButton = new QPushButton("保存数据", this);
|
|
|
+
|
|
|
+ // 按钮布局
|
|
|
+ QHBoxLayout* buttonLayout = new QHBoxLayout();
|
|
|
+ buttonLayout->addWidget(addButton);
|
|
|
+ buttonLayout->addWidget(deleteButton);
|
|
|
+ buttonLayout->addWidget(saveButton);
|
|
|
+
|
|
|
+ // 添加到主布局
|
|
|
+ mainLayout->addWidget(tableWidget);
|
|
|
+ mainLayout->addLayout(buttonLayout);
|
|
|
+
|
|
|
+ // 连接信号槽
|
|
|
+ connect(addButton, &QPushButton::clicked, this, &GPITableWidget::addRow);
|
|
|
+ connect(deleteButton, &QPushButton::clicked, this, &GPITableWidget::deleteRow);
|
|
|
+ connect(saveButton, &QPushButton::clicked, this, &GPITableWidget::saveData);
|
|
|
+
|
|
|
+ // 添加初始行
|
|
|
+ addRow();
|
|
|
+ }
|
|
|
+
|
|
|
+private slots:
|
|
|
+ void addRow() {
|
|
|
+ int row = tableWidget->rowCount();
|
|
|
+ tableWidget->insertRow(row);
|
|
|
+
|
|
|
+ // 为每一列创建项目
|
|
|
+ tableWidget->setItem(row, 0, new QTableWidgetItem("GPI_" + QString::number(row + 1)));
|
|
|
+ tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row + 1)));
|
|
|
+ tableWidget->setItem(row, 2, new QTableWidgetItem("类型" + QString::number((row % 3) + 1)));
|
|
|
+ tableWidget->setItem(row, 3, new QTableWidgetItem(QString::number(row + 101)));
|
|
|
+ tableWidget->setItem(row, 4, new QTableWidgetItem(row % 2 ? "高电平" : "低电平"));
|
|
|
+ tableWidget->setItem(row, 5, new QTableWidgetItem("未激活"));
|
|
|
+ }
|
|
|
+
|
|
|
+ void deleteRow() {
|
|
|
+ int currentRow = tableWidget->currentRow();
|
|
|
+ if (currentRow >= 0) {
|
|
|
+ tableWidget->removeRow(currentRow);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ QMessageBox::warning(this, "警告", "请先选择要删除的行");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void saveData() {
|
|
|
+ QString data;
|
|
|
+ for (int row = 0; row < tableWidget->rowCount(); ++row) {
|
|
|
+ for (int col = 0; col < tableWidget->columnCount(); ++col) {
|
|
|
+ QTableWidgetItem* item = tableWidget->item(row, col);
|
|
|
+ if (item) {
|
|
|
+ data += item->text() + "\t";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data += "\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ QMessageBox::information(this, "表格数据", "保存的数据:\n" + data);
|
|
|
+ // 实际应用中,这里可以将数据保存到文件或数据库
|
|
|
+ }
|
|
|
+
|
|
|
+private:
|
|
|
+ QTableWidget* tableWidget;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+#endif // JIOMAPPAGE_H
|