From 898fcb81332029d19acff1fc9098503ad1c33aba Mon Sep 17 00:00:00 2001 From: gangphon Date: Thu, 8 Sep 2022 23:22:59 +0800 Subject: [PATCH] =?UTF-8?q?ledset=E5=A2=9E=E5=8A=A0=E8=B5=B0=E7=82=B9?= =?UTF-8?q?=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ledset/basewin.cpp | 2 +- ledset/basewin.h | 2 +- ledset/expertsmartpointsetwin.cpp | 106 +++++++++++++++++++++++++----- ledset/expertsmartpointsetwin.h | 11 ++-- 4 files changed, 95 insertions(+), 26 deletions(-) diff --git a/ledset/basewin.cpp b/ledset/basewin.cpp index b2d3466..23e2a87 100644 --- a/ledset/basewin.cpp +++ b/ledset/basewin.cpp @@ -18,7 +18,7 @@ BaseWinBase::BaseWinBase(QWidget *that) : that(that) { center->installEventFilter(that); } -QHBoxLayout *BaseWinBase::addBtns(QHBoxLayout *hBox) { +QBoxLayout *BaseWinBase::addBtns(QBoxLayout *hBox) { if(hBox->count()==0) hBox->addStretch(); auto btn = new QPushButton("--"); btn->setProperty("ss", "min"); diff --git a/ledset/basewin.h b/ledset/basewin.h index 0db9e8e..0845760 100644 --- a/ledset/basewin.h +++ b/ledset/basewin.h @@ -8,7 +8,7 @@ class BaseWinBase { public: explicit BaseWinBase(QWidget *that); - QHBoxLayout *addBtns(QHBoxLayout *); + QBoxLayout *addBtns(QBoxLayout *); QWidget *center{0}; QPen borderPenAct{QColor{0x0077cc}}; QPen borderPenUnact{Qt::gray}; diff --git a/ledset/expertsmartpointsetwin.cpp b/ledset/expertsmartpointsetwin.cpp index 1d623c0..2a03a84 100644 --- a/ledset/expertsmartpointsetwin.cpp +++ b/ledset/expertsmartpointsetwin.cpp @@ -1,4 +1,5 @@ #include "expertsmartpointsetwin.h" +#include "gqt.h" #include #include #include @@ -6,7 +7,11 @@ #include #include #include -#include +#include +#include +#include +#include + ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent} { setWindowModality(Qt::WindowModal); setAttribute(Qt::WA_DeleteOnClose); @@ -46,7 +51,7 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent fdModuleWidth = new QSpinBox; fdModuleWidth->setRange(0, 9999); - fdModuleWidth->setValue(128); + fdModuleWidth->setValue(moduleWidth); hhhh->addWidget(fdModuleWidth); vvv->addLayout(hhhh); @@ -58,7 +63,7 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent fdModuleHeight = new QSpinBox; fdModuleHeight->setRange(0, 9999); - fdModuleHeight->setValue(64); + fdModuleHeight->setValue(moduleHeight); hhhh->addWidget(fdModuleHeight); vvv->addLayout(hhhh); @@ -68,9 +73,9 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent lb = new QLabel("数据组数: "); hhhh->addWidget(lb); - auto fdGrpCnt = new QSpinBox; + fdGrpCnt = new QSpinBox; fdGrpCnt->setRange(0, 9999); - fdGrpCnt->setValue(1); + fdGrpCnt->setValue(grpCnt); hhhh->addWidget(fdGrpCnt); vvv->addLayout(hhhh); @@ -362,6 +367,11 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent }); hhh->addWidget(btnReset); + auto btnOK = new QPushButton("完成"); + btnOK->setMinimumSize(90, 30); + connect(btnOK, &QPushButton::clicked, this, &ExpertSmartPointSetWin::save); + hhh->addWidget(btnOK); + hhh->addStretch(); vBox->addLayout(hhh); @@ -376,14 +386,30 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent if(row < 0) return; auto item = table->item(row, col); if(item) return; - auto cnt = tableRow->columnCount() + 1; - tableRow->setColumnCount(cnt); - tableRow->setItem(0, cnt-1, new QTableWidgetItem(QString::number(cnt))); - item = new QTableWidgetItem("√"); - item->setData(Qt::UserRole, QPoint{col, row}); - tableRow->setItem(1, cnt-1, item); - item = new QTableWidgetItem(QString::number(cnt - virtualCnt)); - table->setItem(row, col, item); + if(lines.isEmpty()) { + auto cnt = tableRow->columnCount() + 1; + tableRow->setColumnCount(cnt); + tableRow->setItem(0, cnt-1, new QTableWidgetItem(QString::number(cnt))); + item = new QTableWidgetItem("√"); + item->setData(Qt::UserRole, QPoint{col, row}); + tableRow->setItem(1, cnt-1, item); + auto realCnt = cnt - virtualCnt; + item = new QTableWidgetItem(QString::number(realCnt)); + table->setItem(row, col, item); + if(realCnt==moduleWidth) { + lines.append({col, row}); + QMessageBox::information(this, "提示", "列走完"); + } + } else if(lines.size() < scanCnt) { + lines.append({col, row}); + auto size = lines.size(); + item = new QTableWidgetItem("S"+QString::number(size)); + table->setItem(row, col, item); + if(size==scanCnt) { + QMessageBox::information(this, "提示", "行走完"); + save(); + } + } }); vBox->addWidget(table); @@ -420,21 +446,23 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent connect(btnPrev, &QPushButton::clicked, this, [stack, btnPrev, btnNext] { auto idx = stack->currentIndex(); stack->setCurrentIndex(--idx); - btnPrev->setVisible(idx > 0); - btnNext->setVisible(idx < stack->count()-1); + btnPrev->setEnabled(idx > 0); + btnNext->setEnabled(idx < stack->count()-1); }); connect(btnNext, &QPushButton::clicked, this, [this, stack, btnPrev, btnNext] { auto idx = stack->currentIndex(); if(idx==0) { moduleWidth = fdModuleWidth->value(); moduleHeight = fdModuleHeight->value(); + grpCnt = fdGrpCnt->value(); + scanCnt = (moduleHeight + 1) / grpCnt; } else if(idx==2) { table->setColumnCount(moduleWidth); table->setRowCount(moduleHeight); } stack->setCurrentIndex(++idx); - btnPrev->setVisible(idx > 0); - btnNext->setVisible(idx < stack->count()-1); + btnPrev->setEnabled(idx > 0); + btnNext->setEnabled(idx < stack->count()-1); }); auto btnCcl = new QPushButton("取消"); @@ -443,3 +471,47 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent hBox->addSpacing(30); } + +void ExpertSmartPointSetWin::save() { + auto dlg = new BaseDlg(this); + dlg->setWindowTitle("保存设置"); + + auto vBox = new VBox(dlg->center); + vBox->setContentsMargins(0,0,0,0); + + auto hBox = new HBox(vBox); + dlg->addBtns(hBox); + + vBox->addSpacing(20); + hBox = new HBox(vBox); + hBox->addWidget(new QLabel("文件名称: ")); + hBox->addWidget(new QLineEdit(QString("1X2_3扫").arg(moduleWidth).arg(moduleHeight).arg(scanCnt))); + + vBox->addSpacing(20); + hBox = new HBox(vBox); + hBox->addWidget(new QLabel("保存路径: ")); + auto fdPath = new QLineEdit(QApplication::applicationDirPath()+"/ModuleFiles"); + fdPath->setMinimumWidth(400); + hBox->addWidget(fdPath); + auto btnChoose = new QPushButton("选择路径"); + connect(btnChoose, &QPushButton::clicked, this, [this, fdPath] { + auto dir = QFileDialog::getExistingDirectory(this, "选择存储文件的目录", fdPath->text()); + }); + hBox->addWidget(btnChoose); + + vBox->addSpacing(20); + hBox = new HBox(vBox); + hBox->addStretch(); + + auto btnOK = new QPushButton("完成"); + btnOK->setMinimumSize(90, 30); + connect(btnOK, &QPushButton::clicked, dlg, &BaseDlg::accept); + hBox->addWidget(btnOK); + + auto btnBack = new QPushButton("返回"); + btnBack->setMinimumSize(90, 30); + connect(btnBack, &QPushButton::clicked, dlg, &BaseDlg::reject); + hBox->addWidget(btnBack); + + dlg->exec(); +} diff --git a/ledset/expertsmartpointsetwin.h b/ledset/expertsmartpointsetwin.h index bc96da2..3e205f6 100644 --- a/ledset/expertsmartpointsetwin.h +++ b/ledset/expertsmartpointsetwin.h @@ -14,21 +14,18 @@ public: QTableWidget::setItem(row, column, item); } }; -struct Point { - int x; - int y; - int c{0}; -}; class ExpertSmartPointSetWin : public BaseWin { Q_OBJECT public: explicit ExpertSmartPointSetWin(QWidget *parent = nullptr); + void save(); - QSpinBox *fdModuleWidth, *fdModuleHeight; + QSpinBox *fdModuleWidth, *fdModuleHeight, *fdGrpCnt; PointTable *table, *tableRow; int virtualCnt = 0; - int moduleWidth{0}, moduleHeight{0}; + QList lines; + int moduleWidth{16}, moduleHeight{8}, grpCnt{2}, scanCnt{4}; }; #endif // EXPERTSMARTPOINTSETWIN_H