移动的坐标和存入数据库的坐标的合法性检测
This commit is contained in:
@ -521,23 +521,43 @@ class CoordinateTableWidget(QWidget):
|
||||
|
||||
self.mainLayout.addLayout(btnLayout)
|
||||
|
||||
# 数据保存到数据库,获取数据时调用
|
||||
def get_ui_data(self):
|
||||
"""从表格UI中获取数据 [[行索引row_idx, x, y, z, rx, ry, rz], ......]"""
|
||||
row_count = self.table.rowCount()
|
||||
column_count = self.table.columnCount()
|
||||
# column_count = self.table.columnCount()
|
||||
data_rows = []
|
||||
for row_idx in range(row_count):
|
||||
row_data = [row_idx]
|
||||
for col_idx in range(column_count):
|
||||
row_data = [row_idx] # 先保存行索引
|
||||
is_valid_row = True # 标记当前行是否完全有效
|
||||
|
||||
# 这里只有前6列是 x, y, rx, ry, rz
|
||||
# 目前 从ui获取的 需要保存到数据库的 只有 x, y, z, rx, ry, rz
|
||||
# 故这里为 0到5
|
||||
for col_idx in range(6):
|
||||
item = self.table.item(row_idx, col_idx)
|
||||
|
||||
# 数据合法性和完整性判定: 保证获取到的是有效数据
|
||||
row_data.append(
|
||||
item.text().strip() if item and item.text().strip() else "-9999"
|
||||
) # 该表格为空,填充 -9999
|
||||
# 数据合法性和完整性判定(检查): 保证获取到的是有效数据
|
||||
# 对于非法数据 和 不完整数据,不保存在数据库
|
||||
# 1、判断填写的 x, y, z, rx, ry, rz中是否有为空的坐标
|
||||
if not item or not item.text().strip():
|
||||
is_valid_row = False
|
||||
break # 跳过这一行数据,保存下一行数据
|
||||
|
||||
# 2、检查填写的坐标是否都为数字
|
||||
coord_str = item.text().strip()
|
||||
try:
|
||||
coord_num = float(coord_str) # 尝试转换为数字
|
||||
except ValueError:
|
||||
is_valid_row = False
|
||||
break # 跳过这一行数据,保存下一行数据
|
||||
|
||||
# 保存单个坐标,浮点类型
|
||||
row_data.append(coord_num)
|
||||
|
||||
# 放入这一行的数据 行索引row_idx, x, y, z, rx, ry, rz
|
||||
data_rows.append(row_data)
|
||||
if is_valid_row: # 有效,才保存到数据库
|
||||
data_rows.append(row_data)
|
||||
|
||||
return data_rows
|
||||
|
||||
@ -728,13 +748,29 @@ class CoordinateTableWidget(QWidget):
|
||||
for col_idx in range(6): # 0-5 ,这些列为坐标 x, y, z, rx, ry, rz
|
||||
item = self.table.item(row_idx, col_idx)
|
||||
|
||||
# 坐标合法性监测
|
||||
# 坐标合法性检查
|
||||
# 1、判断填写的 x, y, z, rx, ry, rz中是否为空
|
||||
if not item or not item.text().strip():
|
||||
self.status_label.setText(
|
||||
f"移动失败:第{row_idx+1}行有坐标为空,请检查!!!"
|
||||
)
|
||||
return
|
||||
|
||||
row_coordinate.append(item.text().strip())
|
||||
# 2、检查填写的坐标是否都为数字
|
||||
coord_str = item.text().strip()
|
||||
try:
|
||||
coord_num = float(coord_str) # 尝试转换为数字
|
||||
except ValueError:
|
||||
self.status_label.setText(
|
||||
f"移动失败:第{row_idx+1}行第{col_idx+1}列坐标不是有效数字,请检查!!!"
|
||||
)
|
||||
return
|
||||
# 放入单个坐标(浮点类型),如 x
|
||||
row_coordinate.append(coord_num)
|
||||
|
||||
# 放入这一行的坐标
|
||||
# 结果:[[x1, y1, z1, rx1, ry1, rz1], ......]
|
||||
# 里面的 x1等都为字符串类型
|
||||
# 最终结果:[[x1, y1, z1, rx1, ry1, rz1], ......]
|
||||
# x1等都为浮点类型
|
||||
coordinate_rows.append(row_coordinate)
|
||||
# 发送移动到这些坐标的信号
|
||||
self.move_to_coodinate_signal.emit(coordinate_rows)
|
||||
@ -749,7 +785,7 @@ class CoordinateTableWidget(QWidget):
|
||||
# 获取UI数据
|
||||
data_rows = self.get_ui_data()
|
||||
if not data_rows:
|
||||
self.status_label.setText("没有数据需要保存")
|
||||
self.status_label.setText("没有数据可以保存, 请检查数据有效性!!!")
|
||||
return
|
||||
|
||||
# 创建数据库操作线程并启动
|
||||
@ -1187,6 +1223,8 @@ class CoordinateFormsWidget(QWidget):
|
||||
# def test(form_obj: CoordinateTableWidget):
|
||||
# form_obj.update_table_data([666, 666, 666, 666, 666, 666])
|
||||
|
||||
# 移动
|
||||
|
||||
|
||||
# if __name__ == "__main__":
|
||||
# app = QApplication(sys.argv)
|
||||
|
||||
Reference in New Issue
Block a user