Просмотр исходного кода

20241225 输入数据右键可删除行(只是视图上),有bug

rmy 5 месяцев назад
Родитель
Сommit
4585ebf448
5 измененных файлов: 84 добавлений и 6 удалений
  1. 6
    0
      Back/GC/GCshow.py
  2. 14
    1
      Back/GS/GSshow.py
  3. 14
    0
      Back/WD/WDshow.py
  4. 41
    1
      Front/main.py
  5. 9
    4
      Front/modules/ui_functions.py

+ 6
- 0
Back/GC/GCshow.py Просмотреть файл

@@ -1,6 +1,7 @@
1 1
 import sqlite3
2 2
 
3 3
 from PySide6.QtGui import QStandardItemModel, QStandardItem
4
+from PySide6.QtCore import QItemSelectionModel
4 5
 
5 6
 
6 7
 def main_function(ui, db_path, utf_en):
@@ -167,6 +168,11 @@ def search_show_function(ui, db_path, utf_en):
167 168
     ui.reconTableView1.setModel(output_model)
168 169
     ui.reconTableView1.show()
169 170
 
171
+    # 返回一个选择模型
172
+    selectionModel = QItemSelectionModel(input_model)  # Item选择模型
173
+    ui.resultTableView1.setSelectionModel(selectionModel)
174
+    return selectionModel
175
+
170 176
     # 关闭数据库连接
171 177
     cursor1.close()
172 178
     db1.close()

+ 14
- 1
Back/GS/GSshow.py Просмотреть файл

@@ -2,7 +2,7 @@ import sqlite3
2 2
 
3 3
 from PySide6.QtGui import QStandardItemModel
4 4
 from Back.Program_Run.data_show import *
5
-
5
+from PySide6.QtCore import QItemSelectionModel
6 6
 
7 7
 def main_function(ui, db_path, utf_en):
8 8
     # 就用已有的选项卡
@@ -84,6 +84,10 @@ li.checked::marker {{ content: "\\2612"; }}
84 84
 
85 85
     ui.printTableView.setHtml(str0)
86 86
 
87
+    # 关闭数据库连接
88
+    cursor1.close()
89
+    db1.close()
90
+
87 91
 
88 92
 def search_show_function(ui, db_path, utf_en):
89 93
     # 就用已有的选项卡
@@ -182,3 +186,12 @@ li.checked::marker {{ content: "\\2612"; }}
182 186
 <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">          </span><span style=" font-size:14pt; font-weight:700;">X、Y</span><span style=" font-size:14pt;">为{str1}已知系统的{str2}归算坐标。</span></p></body></html>"""
183 187
 
184 188
     ui.printTableView1.setHtml(str0)
189
+
190
+    # 关闭数据库连接
191
+    cursor1.close()
192
+    db1.close()
193
+
194
+    # 返回一个选择模型
195
+    selectionModel = QItemSelectionModel(model0)  # Item选择模型
196
+    ui.resultTableView1.setSelectionModel(selectionModel)
197
+    return selectionModel

+ 14
- 0
Back/WD/WDshow.py Просмотреть файл

@@ -2,6 +2,7 @@ from Back.Program_Run.data_show import *
2 2
 import sqlite3
3 3
 
4 4
 from PySide6.QtGui import QStandardItemModel
5
+from PySide6.QtCore import QItemSelectionModel
5 6
 
6 7
 
7 8
 # 计算结束后的显示
@@ -74,6 +75,10 @@ li.checked::marker { content: "\2612"; }
74 75
 <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">          </span><span style=" font-size:14pt; font-weight:700;">X、Y</span><span style=" font-size:14pt;">为""" + str1 + """已知系统的""" + str2 + """归算坐标。</span></p></body></html>"""
75 76
     ui.printTableView.setHtml(str0)
76 77
 
78
+    # 关闭数据库连接
79
+    cursor1.close()
80
+    db1.close()
81
+
77 82
 
78 83
 def search_show_function(ui, db_path, utf_en):
79 84
     # 只显示头两个tab
@@ -165,3 +170,12 @@ li.checked::marker { content: "\2612"; }
165 170
 <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">式中:</span><span style=" font-size:14pt; font-weight:700; color:#000000;">x、y</span><span style=" font-size:14pt;">为</span><span style=" font-size:14pt; color:#000000;">""" + str2 + """</span><span style=" font-size:14pt;">坐标;</span></p>
166 171
 <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">          </span><span style=" font-size:14pt; font-weight:700;">X、Y</span><span style=" font-size:14pt;">为""" + str1 + """已知系统的""" + str2 + """归算坐标。</span></p></body></html>"""
167 172
     ui.printTableView1.setHtml(str0)
173
+
174
+    # 关闭数据库连接
175
+    cursor1.close()
176
+    db1.close()
177
+
178
+    #返回一个选择模型
179
+    selectionModel = QItemSelectionModel(model0)  # Item选择模型
180
+    ui.resultTableView1.setSelectionModel(selectionModel)
181
+    return selectionModel

+ 41
- 1
Front/main.py Просмотреть файл

@@ -431,6 +431,24 @@ class MainWindow(QMainWindow):
431 431
         # tree_button.itemClicked.connect(self.itembuttonClick)
432 432
         # tree_button.itemDoubleClicked.connect(self.itembuttonClick)
433 433
 
434
+
435
+    #单元格的右键
436
+    def show_custom_context_menu(self, pos):
437
+        # 创建一个右键菜单
438
+        menu = QMenu(self.ui.resultTableView1)
439
+        menu.setStyleSheet("QMenu { background-color: #FFFFFF; }")
440
+        # 获取选中单元格的索引
441
+        index = self.ui.resultTableView1.indexAt(pos)
442
+        # # 添加菜单项和对应的操作
443
+        # action_1 = QAction("操作1", self)
444
+        # action_1.triggered.connect(lambda: self.do_something(index))
445
+        # menu.addAction(action_1)
446
+        # 添加菜单项和对应的操作
447
+        action_1 = QAction("删除该行", self)
448
+        action_1.triggered.connect(self.seleceModel_itemclicked)
449
+        menu.addAction(action_1)
450
+        menu.exec(self.ui.resultTableView1.mapToGlobal(pos))
451
+
434 452
     def closeEvent(self, event):
435 453
         # 停止监控
436 454
         self.observer.stop()
@@ -716,6 +734,8 @@ class MainWindow(QMainWindow):
716 734
         # 隐藏默认label
717 735
         self.ui.defaultLabel.setVisible(False)
718 736
 
737
+
738
+
719 739
     # 全树的item展示
720 740
     def itembuttonClick(self):
721 741
         # 判定是否获取的是根节点
@@ -743,7 +763,20 @@ class MainWindow(QMainWindow):
743 763
             inpath = os.path.abspath('../SQL')
744 764
             file_path = inpath + '/' + str3 + '.db'
745 765
             # 数据库路径,哪种方法,表名
746
-            UIFunctions.search_data_to_show(self, file_path, current_text, str1)
766
+            self.selectModel = UIFunctions.search_data_to_show(self, file_path, current_text, str1)
767
+            # self.ui.resultTableView1.doubleClicked.connect(self.seleceModel_itemclicked)
768
+
769
+            # 设置右键菜单策略为CustomContextMenu
770
+            self.ui.resultTableView1.setContextMenuPolicy(Qt.CustomContextMenu)
771
+
772
+            # 关联自定义的右键菜单方法到customContextMenuRequested信号
773
+            self.ui.resultTableView1.customContextMenuRequested.connect(self.show_custom_context_menu)
774
+
775
+    #右键对应行可删除对应行(只是视图上)
776
+    def seleceModel_itemclicked(self):
777
+        curIndex = self.selectModel.currentIndex()
778
+        self.ui.resultTableView1.model().removeRow(curIndex.row())
779
+        kk = 1
747 780
 
748 781
     # 搜索的item展示
749 782
     def itembuttonClick1(self):
@@ -773,6 +806,13 @@ class MainWindow(QMainWindow):
773 806
             file_path = inpath + '/' + str3 + '.db'
774 807
             # 数据库路径,哪种方法,表名
775 808
             UIFunctions.search_data_to_show(self, file_path, current_text, str1)
809
+            # self.ui.resultTableView1.doubleClicked.connect(self.seleceModel_itemclicked)
810
+
811
+            # 设置右键菜单策略为CustomContextMenu
812
+            self.ui.resultTableView1.setContextMenuPolicy(Qt.CustomContextMenu)
813
+
814
+            # 关联自定义的右键菜单方法到customContextMenuRequested信号
815
+            self.ui.resultTableView1.customContextMenuRequested.connect(self.show_custom_context_menu)
776 816
 
777 817
     # 键盘回车事件,目前用于搜索按钮
778 818
     def datainfo_keyPressEvent(self, event):

+ 9
- 4
Front/modules/ui_functions.py Просмотреть файл

@@ -20,6 +20,9 @@ from PySide6.QtWidgets import QMessageBox
20 20
 
21 21
 from main import *
22 22
 import importlib
23
+
24
+from select import select
25
+
23 26
 from Back.GC import GC, GCExport
24 27
 from Back.GS import GS, GSExport
25 28
 from Back.WD import WD, WDExport
@@ -365,11 +368,13 @@ class UIFunctions(MainWindow):
365 368
     # 数据一览,点击查询
366 369
     def search_data_to_show(self, file_path, current_text, tablename):
367 370
         utf_en = tablename.encode('utf-8')  # 转换文件名为utf-8编码形式
368
-        # 高差部分我没改
369 371
         if current_text == "水准测段高差稳定计算":
370
-            GCshow.search_show_function(self.ui, file_path, utf_en)
372
+            selectModel = GCshow.search_show_function(self.ui, file_path, utf_en)
373
+            return selectModel
371 374
         elif current_text == "控制网复测平面基准计算":
372
-            GSshow.search_show_function(self.ui, file_path, utf_en)
375
+            selectModel = GSshow.search_show_function(self.ui, file_path, utf_en)
376
+            return selectModel
373 377
         elif current_text == "平面控制网稳定性计算":
374
-            WDshow.search_show_function(self.ui, file_path, utf_en)
378
+            selectModel = WDshow.search_show_function(self.ui, file_path, utf_en)
379
+            return selectModel
375 380
     # END - GUI DEFINITIONS

Загрузка…
Отмена
Сохранить