ledset增加虚点
This commit is contained in:
parent
dd833d40f1
commit
0cb51c6e2a
|
@ -2,12 +2,11 @@
|
||||||
#include <QStackedLayout>
|
#include <QStackedLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QRadioButton>
|
#include <QRadioButton>
|
||||||
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
#include <QDebug>
|
||||||
ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent} {
|
ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent} {
|
||||||
setWindowModality(Qt::WindowModal);
|
setWindowModality(Qt::WindowModal);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
@ -215,10 +214,12 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent
|
||||||
auto hhhh = new QHBoxLayout;
|
auto hhhh = new QHBoxLayout;
|
||||||
hhhh->addStretch();
|
hhhh->addStretch();
|
||||||
auto fdSta1 = new QRadioButton("状态1");
|
auto fdSta1 = new QRadioButton("状态1");
|
||||||
|
fdSta1->setChecked(true);
|
||||||
hhhh->addWidget(fdSta1);
|
hhhh->addWidget(fdSta1);
|
||||||
hhhh->addStretch();
|
hhhh->addStretch();
|
||||||
|
|
||||||
auto fdR1 = new QRadioButton("红");
|
auto fdR1 = new QRadioButton("红");
|
||||||
|
fdR1->setChecked(true);
|
||||||
hhhh->addWidget(fdR1);
|
hhhh->addWidget(fdR1);
|
||||||
hhhh->addSpacing(20);
|
hhhh->addSpacing(20);
|
||||||
|
|
||||||
|
@ -248,6 +249,7 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent
|
||||||
hhhh->addSpacing(20);
|
hhhh->addSpacing(20);
|
||||||
|
|
||||||
auto fdG2 = new QRadioButton("绿");
|
auto fdG2 = new QRadioButton("绿");
|
||||||
|
fdG2->setChecked(true);
|
||||||
hhhh->addWidget(fdG2);
|
hhhh->addWidget(fdG2);
|
||||||
hhhh->addSpacing(20);
|
hhhh->addSpacing(20);
|
||||||
|
|
||||||
|
@ -277,6 +279,7 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent
|
||||||
hhhh->addSpacing(20);
|
hhhh->addSpacing(20);
|
||||||
|
|
||||||
auto fdB3 = new QRadioButton("蓝");
|
auto fdB3 = new QRadioButton("蓝");
|
||||||
|
fdB3->setChecked(true);
|
||||||
hhhh->addWidget(fdB3);
|
hhhh->addWidget(fdB3);
|
||||||
hhhh->addSpacing(20);
|
hhhh->addSpacing(20);
|
||||||
|
|
||||||
|
@ -312,46 +315,93 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent
|
||||||
|
|
||||||
auto hhh = new QHBoxLayout;
|
auto hhh = new QHBoxLayout;
|
||||||
|
|
||||||
|
auto btnUndo = new QPushButton("回撤");
|
||||||
|
btnUndo->setMinimumSize(90, 30);
|
||||||
|
connect(btnUndo, &QPushButton::clicked, this, [this] {
|
||||||
|
auto lastIdx = tableRow->columnCount()-1;
|
||||||
|
if(lastIdx==-1) return;
|
||||||
|
auto last = tableRow->item(1, lastIdx);
|
||||||
|
if(last->text()=="×") {
|
||||||
|
virtualCnt--;
|
||||||
|
} else {
|
||||||
|
auto point = last->data(Qt::UserRole).toPoint();
|
||||||
|
table->setItem(point.y(), point.x(), 0);
|
||||||
|
if(lastIdx==virtualCnt) table->selectionModel()->clearCurrentIndex();
|
||||||
|
else {
|
||||||
|
for(int i=lastIdx-1; i>-1; i--) {
|
||||||
|
auto item = tableRow->item(1, i);
|
||||||
|
if(item->text()=="×") continue;
|
||||||
|
auto point = item->data(Qt::UserRole).toPoint();
|
||||||
|
table->setCurrentCell(point.y(), point.x());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tableRow->setColumnCount(lastIdx);
|
||||||
|
});
|
||||||
|
hhh->addWidget(btnUndo);
|
||||||
|
|
||||||
|
auto btnAddVoid = new QPushButton("插入虚点");
|
||||||
|
btnAddVoid->setMinimumSize(90, 30);
|
||||||
|
connect(btnAddVoid, &QPushButton::clicked, this, [this] {
|
||||||
|
virtualCnt++;
|
||||||
|
auto cnt = tableRow->columnCount();
|
||||||
|
tableRow->setColumnCount(cnt+1);
|
||||||
|
tableRow->setItem(0, cnt, new QTableWidgetItem(QString::number(cnt+1)));
|
||||||
|
auto item = new QTableWidgetItem("×");
|
||||||
|
tableRow->setItem(1, cnt, item);
|
||||||
|
});
|
||||||
|
hhh->addWidget(btnAddVoid);
|
||||||
|
|
||||||
auto btnReset = new QPushButton("重新走点");
|
auto btnReset = new QPushButton("重新走点");
|
||||||
btnReset->setMinimumSize(90, 30);
|
btnReset->setMinimumSize(90, 30);
|
||||||
connect(btnReset, &QPushButton::clicked, this, [this] {
|
connect(btnReset, &QPushButton::clicked, this, [this] {
|
||||||
table->clearContents();
|
table->clearContents();
|
||||||
points.clear();
|
tableRow->setColumnCount(0);
|
||||||
|
virtualCnt = 0;
|
||||||
});
|
});
|
||||||
hhh->addWidget(btnReset);
|
hhh->addWidget(btnReset);
|
||||||
|
|
||||||
auto btnUndo = new QPushButton("回撤");
|
|
||||||
btnUndo->setMinimumSize(90, 30);
|
|
||||||
connect(btnUndo, &QPushButton::clicked, this, [this] {
|
|
||||||
if(points.isEmpty()) return;
|
|
||||||
auto last = points.takeLast();
|
|
||||||
table->setItem(last.y(), last.x(), 0);
|
|
||||||
if(points.isEmpty()) table->selectionModel()->clearCurrentIndex();
|
|
||||||
else {
|
|
||||||
last = points.last();
|
|
||||||
table->setCurrentCell(last.y(), last.x());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
hhh->addWidget(btnUndo);
|
|
||||||
|
|
||||||
hhh->addStretch();
|
hhh->addStretch();
|
||||||
vBox->addLayout(hhh);
|
vBox->addLayout(hhh);
|
||||||
|
|
||||||
table = new PointTable;
|
table = new PointTable;
|
||||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
table->setSelectionMode(QTableWidget::SingleSelection);
|
||||||
table->horizontalHeader()->setDefaultSectionSize(40);
|
table->horizontalHeader()->setDefaultSectionSize(40);
|
||||||
table->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
|
table->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
|
||||||
table->verticalHeader()->setMinimumWidth(40);
|
table->verticalHeader()->setMinimumWidth(40);
|
||||||
table->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
|
table->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
|
||||||
table->setSelectionMode(QTableWidget::SingleSelection);
|
|
||||||
connect(table, &QTableWidget::currentCellChanged, this, [this](int row, int col) {
|
connect(table, &QTableWidget::currentCellChanged, this, [this](int row, int col) {
|
||||||
if(row < 0) return;
|
if(row < 0) return;
|
||||||
auto item = table->item(row, col);
|
auto item = table->item(row, col);
|
||||||
if(item) return;
|
if(item) return;
|
||||||
points.append({col, row});
|
auto cnt = tableRow->columnCount() + 1;
|
||||||
table->setItem(row, col, new QTableWidgetItem(QString::number(points.size())));
|
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);
|
||||||
});
|
});
|
||||||
vBox->addWidget(table);
|
vBox->addWidget(table);
|
||||||
|
|
||||||
|
tableRow = new PointTable(2, 0);
|
||||||
|
tableRow->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
tableRow->setSelectionMode(QTableWidget::NoSelection);
|
||||||
|
tableRow->horizontalHeader()->setDefaultSectionSize(40);
|
||||||
|
tableRow->horizontalHeader()->setVisible(false);
|
||||||
|
tableRow->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
||||||
|
tableRow->verticalHeader()->setMinimumWidth(120);
|
||||||
|
tableRow->setMaximumHeight(80);
|
||||||
|
auto item = tableRow->verticalHeaderItem(0);
|
||||||
|
if(item==0) tableRow->setVerticalHeaderItem(0, item = new QTableWidgetItem());
|
||||||
|
item->setText("第一扫灯数:");
|
||||||
|
item = tableRow->verticalHeaderItem(1);
|
||||||
|
if(item==0) tableRow->setVerticalHeaderItem(1, item = new QTableWidgetItem());
|
||||||
|
item->setText("实: 虚:");
|
||||||
|
vBox->addWidget(tableRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto hBox = new QHBoxLayout;
|
auto hBox = new QHBoxLayout;
|
||||||
|
|
|
@ -8,11 +8,17 @@
|
||||||
class PointTable : public QTableWidget {
|
class PointTable : public QTableWidget {
|
||||||
public:
|
public:
|
||||||
explicit PointTable(QWidget *parent = nullptr) : QTableWidget{parent} {}
|
explicit PointTable(QWidget *parent = nullptr) : QTableWidget{parent} {}
|
||||||
|
PointTable(int rows, int columns, QWidget *parent = nullptr) : QTableWidget{rows, columns, parent} {}
|
||||||
void setItem(int row, int column, QTableWidgetItem *item) {
|
void setItem(int row, int column, QTableWidgetItem *item) {
|
||||||
if(item) item->setTextAlignment(Qt::AlignCenter);
|
if(item) item->setTextAlignment(Qt::AlignCenter);
|
||||||
QTableWidget::setItem(row, column, item);
|
QTableWidget::setItem(row, column, item);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
struct Point {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int c{0};
|
||||||
|
};
|
||||||
|
|
||||||
class ExpertSmartPointSetWin : public BaseWin {
|
class ExpertSmartPointSetWin : public BaseWin {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -20,8 +26,8 @@ public:
|
||||||
explicit ExpertSmartPointSetWin(QWidget *parent = nullptr);
|
explicit ExpertSmartPointSetWin(QWidget *parent = nullptr);
|
||||||
|
|
||||||
QSpinBox *fdModuleWidth, *fdModuleHeight;
|
QSpinBox *fdModuleWidth, *fdModuleHeight;
|
||||||
PointTable *table;
|
PointTable *table, *tableRow;
|
||||||
QList<QPoint> points;
|
int virtualCnt = 0;
|
||||||
int moduleWidth{0}, moduleHeight{0};
|
int moduleWidth{0}, moduleHeight{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,25 @@
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
|
|
||||||
|
Table::Table(std::initializer_list<ColAttr> colAttrs, QWidget *parent) : QTableWidget{0, (int)colAttrs.size(), parent} {
|
||||||
|
int i = 0;
|
||||||
|
for(typename std::initializer_list<ColAttr>::const_iterator it = colAttrs.begin(); it != colAttrs.end(); ++it) {
|
||||||
|
auto item = horizontalHeaderItem(i);
|
||||||
|
if(item==0) setHorizontalHeaderItem(i, item = new QTableWidgetItem());
|
||||||
|
item->setText(it->text);
|
||||||
|
item->setData(0x99, it->width);
|
||||||
|
if(it->width > 0) horizontalHeader()->resizeSection(i, it->width);
|
||||||
|
else if(it->width < 0) {
|
||||||
|
if(it->width == Stretch) horizontalHeader()->setSectionResizeMode(i, QHeaderView::Stretch);
|
||||||
|
if(it->width == ResizeToContents) horizontalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
|
||||||
|
}
|
||||||
|
mFieldMap.insert(it->field, i++);
|
||||||
|
}
|
||||||
|
}
|
||||||
int Table::sizeHintForColumn(int column) const {
|
int Table::sizeHintForColumn(int column) const {
|
||||||
auto item = horizontalHeaderItem(column);
|
auto item = horizontalHeaderItem(column);
|
||||||
if(!item) return QTableWidget::sizeHintForColumn(column);
|
if(item==0) return QTableWidget::sizeHintForColumn(column);
|
||||||
int width = item->data(0x99).toInt();
|
int width = item->data(0x99).toInt();
|
||||||
if(!width) return QTableWidget::sizeHintForColumn(column);
|
if(width==0) return QTableWidget::sizeHintForColumn(column);
|
||||||
auto header = horizontalHeader();
|
auto header = horizontalHeader();
|
||||||
if(header->sectionResizeMode(column)!=QHeaderView::ResizeToContents) return QTableWidget::sizeHintForColumn(column);
|
if(header->sectionResizeMode(column)!=QHeaderView::ResizeToContents) return QTableWidget::sizeHintForColumn(column);
|
||||||
int colCnt = columnCount();
|
int colCnt = columnCount();
|
||||||
|
|
|
@ -17,26 +17,9 @@ public:
|
||||||
ResizeToContents
|
ResizeToContents
|
||||||
};
|
};
|
||||||
explicit Table(QWidget *parent = nullptr) : QTableWidget{parent} {}
|
explicit Table(QWidget *parent = nullptr) : QTableWidget{parent} {}
|
||||||
Table(std::initializer_list<ColAttr> colAttrs, QWidget *parent = nullptr) : QTableWidget{0, (int)colAttrs.size(), parent} {
|
Table(std::initializer_list<ColAttr> colAttrs, QWidget *parent = nullptr);
|
||||||
int i = 0;
|
|
||||||
for(typename std::initializer_list<ColAttr>::const_iterator it = colAttrs.begin(); it != colAttrs.end(); ++it) {
|
|
||||||
auto item = horizontalHeaderItem(i);
|
|
||||||
if(!item) {
|
|
||||||
item = new QTableWidgetItem();
|
|
||||||
item->setData(0x99, it->width);
|
|
||||||
setHorizontalHeaderItem(i, item);
|
|
||||||
}
|
|
||||||
item->setText(it->text);
|
|
||||||
if(it->width > 0) horizontalHeader()->resizeSection(i, it->width);
|
|
||||||
else if(it->width < 0) {
|
|
||||||
if(it->width == Stretch) horizontalHeader()->setSectionResizeMode(i, QHeaderView::Stretch);
|
|
||||||
if(it->width == ResizeToContents) horizontalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
|
|
||||||
}
|
|
||||||
mFieldMap.insert(it->field, i++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Table *setDefs() {
|
inline Table *setDefs() {
|
||||||
setSelectionBehavior(QTableWidget::SelectRows);
|
setSelectionBehavior(QTableWidget::SelectRows);
|
||||||
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
setAlternatingRowColors(true);
|
setAlternatingRowColors(true);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user