|
@@ -67,7 +67,7 @@ class MyTableModel(QAbstractTableModel):
|
67
|
67
|
return None
|
68
|
68
|
|
69
|
69
|
class TreeWidgetItem:
|
70
|
|
- def __init__(self, id: any, parent_id: any, name: str, icon: QIcon = None, extend: object = None):
|
|
70
|
+ def __init__(self, id: any, parent_id: any, name: str,icon: QIcon = None, extend: object = None):
|
71
|
71
|
"""
|
72
|
72
|
菜单数据接口
|
73
|
73
|
:param id: ID
|
|
@@ -83,7 +83,7 @@ class TreeWidgetItem:
|
83
|
83
|
# 实例化
|
84
|
84
|
self.treeWidgetItem = QTreeWidgetItem([self.name])
|
85
|
85
|
# 存储相关数据
|
86
|
|
- self.treeWidgetItem.setData(0, Qt.UserRole + 1, extend)
|
|
86
|
+ self.treeWidgetItem.setData(0, Qt.UserRole + 1,extend )
|
87
|
87
|
self.treeWidgetItem.setIcon(0, QIcon(':/icons/default.png'))
|
88
|
88
|
if icon is not None:
|
89
|
89
|
self.treeWidgetItem.setIcon(0, icon)
|
|
@@ -233,18 +233,31 @@ class MainWindow(QMainWindow):
|
233
|
233
|
self.data = sqltree
|
234
|
234
|
# 将按钮的点击信号绑定到当前类的点击信号
|
235
|
235
|
# 信号改为展示方法,这里同导出展示
|
236
|
|
- widgets.allTreeWidget.itemClicked.connect(lambda extend: print("单击->扩展数据为:", extend))
|
|
236
|
+ # widgets.allTreeWidget.itemClicked.connect(lambda extend: print("单击->扩展数据为:", extend))
|
|
237
|
+ widgets.allTreeWidget.itemClicked.connect(self.test_method)
|
237
|
238
|
widgets.allTreeWidget.itemDoubleClicked.connect(lambda extend: print("双击->扩展数据为:", extend))
|
238
|
239
|
self.__render_items(True)
|
239
|
240
|
|
240
|
241
|
self.bind()
|
241
|
242
|
|
|
243
|
+ def test_method(self):
|
|
244
|
+ print('ok')
|
242
|
245
|
|
|
246
|
+ #绑定组件
|
|
247
|
+ def bind(self):
|
|
248
|
+ # 计算
|
|
249
|
+ widgets.compute.clicked.connect(self.computeClick)
|
|
250
|
+ widgets.search.clicked.connect(self.searchClick)
|
|
251
|
+
|
|
252
|
+ #全部
|
243
|
253
|
def __render_items(self, is_clear: bool):
|
244
|
254
|
if is_clear:
|
245
|
255
|
widgets.allTreeWidget.clear()
|
|
256
|
+ widgets.qureyTreeWidget.clear()
|
246
|
257
|
widgets.allTreeWidget.setColumnCount(1)
|
247
|
258
|
widgets.allTreeWidget.setHeaderHidden(True)
|
|
259
|
+ widgets.qureyTreeWidget.setColumnCount(1)
|
|
260
|
+ widgets.qureyTreeWidget.setHeaderHidden(True)
|
248
|
261
|
if self.data.items is not None:
|
249
|
262
|
# 转为字典
|
250
|
263
|
mapping: dict[any, TreeWidgetItem] = dict(zip([i.id for i in self.data.items], self.data.items))
|
|
@@ -261,12 +274,30 @@ class MainWindow(QMainWindow):
|
261
|
274
|
# 挂载到树上
|
262
|
275
|
widgets.allTreeWidget.insertTopLevelItems(0, treeWidgetItems)
|
263
|
276
|
|
|
277
|
+ #搜索
|
|
278
|
+ def __render_items1(self, is_clear: bool):
|
|
279
|
+ if is_clear:
|
|
280
|
+ widgets.qureyTreeWidget.clear()
|
|
281
|
+ widgets.qureyTreeWidget.setColumnCount(1)
|
|
282
|
+ widgets.qureyTreeWidget.setHeaderHidden(True)
|
|
283
|
+ if self.data.items is not None:
|
|
284
|
+ # 转为字典
|
|
285
|
+ mapping: dict[any, TreeWidgetItem] = dict(zip([i.id for i in self.data.items], self.data.items))
|
|
286
|
+ # 树容器
|
|
287
|
+ treeWidgetItems: list[QTreeWidgetItem] = []
|
|
288
|
+ for d in self.data.items:
|
|
289
|
+ # 如果找不到父级项,则是根节点
|
|
290
|
+ parent: TreeWidgetItem = mapping.get(d.parent_id)
|
|
291
|
+ if parent is None:
|
|
292
|
+ treeWidgetItems.append(d.treeWidgetItem)
|
|
293
|
+ else:
|
|
294
|
+ parent.treeWidgetItem.addChild(d.treeWidgetItem)
|
|
295
|
+
|
|
296
|
+ # 挂载到树上
|
|
297
|
+ widgets.qureyTreeWidget.insertTopLevelItems(0, treeWidgetItems)
|
|
298
|
+
|
|
299
|
+
|
264
|
300
|
|
265
|
|
- #绑定组件
|
266
|
|
- def bind(self):
|
267
|
|
- # 计算
|
268
|
|
- widgets.compute.clicked.connect(self.computeClick)
|
269
|
|
- widgets.search.clicked.connect(self.searchClick)
|
270
|
301
|
|
271
|
302
|
#删除tableview
|
272
|
303
|
def delete_table_view(table_view):
|
|
@@ -518,7 +549,6 @@ class MainWindow(QMainWindow):
|
518
|
549
|
|
519
|
550
|
#设一个全局变量,存数据库中所有的包含内容(数据库-三种方法-表)
|
520
|
551
|
dblist = []
|
521
|
|
- global dblist
|
522
|
552
|
#初始化数据一览(数据库全展示)
|
523
|
553
|
def sql_init(self):
|
524
|
554
|
#初始化全部数据库
|
|
@@ -552,41 +582,41 @@ class MainWindow(QMainWindow):
|
552
|
582
|
result1 = cursor1.fetchall()
|
553
|
583
|
for re1 in result1:
|
554
|
584
|
str1 = re1[0].decode('utf-8')
|
555
|
|
- sqlitem.append(TreeWidgetItem(id, gcid, str1, icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil-file.png"),extend=str1))
|
|
585
|
+ sqlitem.append(TreeWidgetItem(id, gcid, str1, icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil-file.png")))
|
556
|
586
|
list1 = []
|
557
|
587
|
list1.append(dbname)
|
558
|
588
|
list1.append('水准测段高差稳定计算')
|
559
|
589
|
list1.append(str1)
|
560
|
|
- dblist.append(list1)
|
|
590
|
+ self.dblist.append(list1)
|
561
|
591
|
id = id + 1
|
562
|
592
|
sqlstr2 = 'SELECT TableName FROM GS_Input_Param;'
|
563
|
593
|
cursor1.execute(sqlstr2)
|
564
|
594
|
result2 = cursor1.fetchall()
|
565
|
595
|
for re2 in result2:
|
566
|
596
|
str2 = re2[0].decode('utf-8')
|
567
|
|
- sqlitem.append(TreeWidgetItem(id, gsid, str2, icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil-file.png"),extend=str2))
|
|
597
|
+ sqlitem.append(TreeWidgetItem(id, gsid, str2, icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil-file.png")))
|
568
|
598
|
list2 = []
|
569
|
599
|
list2.append(dbname)
|
570
|
600
|
list2.append('控制网复测平面基准计算')
|
571
|
601
|
list2.append(str2)
|
572
|
|
- dblist.append(list2)
|
|
602
|
+ self.dblist.append(list2)
|
573
|
603
|
id = id + 1
|
574
|
604
|
sqlstr3 = 'SELECT TableName FROM WD_Input_Param;'
|
575
|
605
|
cursor1.execute(sqlstr3)
|
576
|
606
|
result3 = cursor1.fetchall()
|
577
|
607
|
for re3 in result3:
|
578
|
608
|
str3 = re3[0].decode('utf-8')
|
579
|
|
- sqlitem.append(TreeWidgetItem(id, wdid, str3, icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil-file.png"),extend=str3))
|
|
609
|
+ sqlitem.append(TreeWidgetItem(id, wdid, str3, icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil-file.png")))
|
580
|
610
|
list3 = []
|
581
|
611
|
list3.append(dbname)
|
582
|
612
|
list3.append('平面控制网稳定性计算')
|
583
|
613
|
list3.append(str3)
|
584
|
|
- dblist.append(list3)
|
|
614
|
+ self.dblist.append(list3)
|
585
|
615
|
id = id + 1
|
586
|
616
|
return sqlitem
|
587
|
617
|
|
588
|
618
|
#关键词查询
|
589
|
|
- def sql_search(self):
|
|
619
|
+ def searchClick(self):
|
590
|
620
|
# GET BUTTON CLICKED
|
591
|
621
|
btn = self.sender()
|
592
|
622
|
btnName = btn.objectName()
|
|
@@ -595,7 +625,7 @@ class MainWindow(QMainWindow):
|
595
|
625
|
#符合的list
|
596
|
626
|
fhlist = []
|
597
|
627
|
#查询(待优化)
|
598
|
|
- for list1 in dblist:
|
|
628
|
+ for list1 in self.dblist:
|
599
|
629
|
for li in list1:
|
600
|
630
|
if text1 in li:
|
601
|
631
|
fhlist.append(list1)
|
|
@@ -608,30 +638,51 @@ class MainWindow(QMainWindow):
|
608
|
638
|
id = 1
|
609
|
639
|
pid = 0
|
610
|
640
|
fid = 0
|
|
641
|
+ zdy = []
|
611
|
642
|
for list2 in fhlist:
|
612
|
643
|
dbname = list2[0]
|
613
|
644
|
if dbname != str1:
|
614
|
645
|
str1 = dbname
|
|
646
|
+ pid = id
|
|
647
|
+ str2 = ''
|
615
|
648
|
sqlitem.append(TreeWidgetItem(id, 0, dbname, icon=QIcon(
|
616
|
649
|
"D:/4work_now/20240819GS/20241211/Front/images/icons/cil-clone.png")))
|
617
|
|
- pid = id
|
|
650
|
+ zdy1 = []
|
|
651
|
+ zdy1.append(id)
|
|
652
|
+ zdy1.append(0)
|
|
653
|
+ zdy1.append(dbname)
|
|
654
|
+ zdy.append(zdy1)
|
618
|
655
|
id = id + 1
|
619
|
656
|
mename = list2[1]
|
620
|
657
|
if mename != str2:
|
621
|
658
|
str2 = mename
|
|
659
|
+ fid = id
|
622
|
660
|
sqlitem.append(TreeWidgetItem(id, pid, mename, icon=QIcon(
|
623
|
661
|
"D:/4work_now/20240819GS/20241211/Front/images/icons/cil-description.png")))
|
624
|
|
- fid = id
|
|
662
|
+ zdy1 = []
|
|
663
|
+ zdy1.append(id)
|
|
664
|
+ zdy1.append(pid)
|
|
665
|
+ zdy1.append(mename)
|
|
666
|
+ zdy.append(zdy1)
|
625
|
667
|
id = id + 1
|
626
|
668
|
sqlitem.append(TreeWidgetItem(id, fid, list2[2], icon=QIcon(
|
627
|
669
|
"D:/4work_now/20240819GS/20241211/Front/images/icons/cil-file.png"), extend=list2[2]))
|
|
670
|
+ zdy1 = []
|
|
671
|
+ zdy1.append(id)
|
|
672
|
+ zdy1.append(fid)
|
|
673
|
+ zdy1.append(list2[2])
|
|
674
|
+ zdy.append(zdy1)
|
|
675
|
+ id = id + 1
|
628
|
676
|
#展示
|
629
|
|
-
|
630
|
|
-
|
631
|
|
-
|
632
|
|
-
|
633
|
|
-
|
634
|
|
-
|
|
677
|
+ self.itemClicked: Signal = Signal(object)
|
|
678
|
+ self.itemDoubleClicked: Signal = Signal(object)
|
|
679
|
+ sqltree = ElTreeData(items=sqlitem)
|
|
680
|
+ self.data = sqltree
|
|
681
|
+ # 将按钮的点击信号绑定到当前类的点击信号
|
|
682
|
+ # 信号改为展示方法,这里同导出展示
|
|
683
|
+ self.ui.qureyTreeWidget.itemClicked.connect(lambda extend: print("单击->扩展数据为:", extend))
|
|
684
|
+ self.ui.qureyTreeWidget.itemDoubleClicked.connect(lambda extend: print("双击->扩展数据为:", extend))
|
|
685
|
+ self.__render_items1(True)
|
635
|
686
|
|
636
|
687
|
#直接这个基础上改点选输出表格(未改)
|
637
|
688
|
def computeClick(self):
|