Przeglądaj źródła

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

rmy 5 miesięcy temu
rodzic
commit
4585ebf448
5 zmienionych plików z 84 dodań i 6 usunięć
  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 Wyświetl plik

1
 import sqlite3
1
 import sqlite3
2
 
2
 
3
 from PySide6.QtGui import QStandardItemModel, QStandardItem
3
 from PySide6.QtGui import QStandardItemModel, QStandardItem
4
+from PySide6.QtCore import QItemSelectionModel
4
 
5
 
5
 
6
 
6
 def main_function(ui, db_path, utf_en):
7
 def main_function(ui, db_path, utf_en):
167
     ui.reconTableView1.setModel(output_model)
168
     ui.reconTableView1.setModel(output_model)
168
     ui.reconTableView1.show()
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
     cursor1.close()
177
     cursor1.close()
172
     db1.close()
178
     db1.close()

+ 14
- 1
Back/GS/GSshow.py Wyświetl plik

2
 
2
 
3
 from PySide6.QtGui import QStandardItemModel
3
 from PySide6.QtGui import QStandardItemModel
4
 from Back.Program_Run.data_show import *
4
 from Back.Program_Run.data_show import *
5
-
5
+from PySide6.QtCore import QItemSelectionModel
6
 
6
 
7
 def main_function(ui, db_path, utf_en):
7
 def main_function(ui, db_path, utf_en):
8
     # 就用已有的选项卡
8
     # 就用已有的选项卡
84
 
84
 
85
     ui.printTableView.setHtml(str0)
85
     ui.printTableView.setHtml(str0)
86
 
86
 
87
+    # 关闭数据库连接
88
+    cursor1.close()
89
+    db1.close()
90
+
87
 
91
 
88
 def search_show_function(ui, db_path, utf_en):
92
 def search_show_function(ui, db_path, utf_en):
89
     # 就用已有的选项卡
93
     # 就用已有的选项卡
182
 <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>"""
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
     ui.printTableView1.setHtml(str0)
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 Wyświetl plik

2
 import sqlite3
2
 import sqlite3
3
 
3
 
4
 from PySide6.QtGui import QStandardItemModel
4
 from PySide6.QtGui import QStandardItemModel
5
+from PySide6.QtCore import QItemSelectionModel
5
 
6
 
6
 
7
 
7
 # 计算结束后的显示
8
 # 计算结束后的显示
74
 <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
 <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
     ui.printTableView.setHtml(str0)
76
     ui.printTableView.setHtml(str0)
76
 
77
 
78
+    # 关闭数据库连接
79
+    cursor1.close()
80
+    db1.close()
81
+
77
 
82
 
78
 def search_show_function(ui, db_path, utf_en):
83
 def search_show_function(ui, db_path, utf_en):
79
     # 只显示头两个tab
84
     # 只显示头两个tab
165
 <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>
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
 <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>"""
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
     ui.printTableView1.setHtml(str0)
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 Wyświetl plik

431
         # tree_button.itemClicked.connect(self.itembuttonClick)
431
         # tree_button.itemClicked.connect(self.itembuttonClick)
432
         # tree_button.itemDoubleClicked.connect(self.itembuttonClick)
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
     def closeEvent(self, event):
452
     def closeEvent(self, event):
435
         # 停止监控
453
         # 停止监控
436
         self.observer.stop()
454
         self.observer.stop()
716
         # 隐藏默认label
734
         # 隐藏默认label
717
         self.ui.defaultLabel.setVisible(False)
735
         self.ui.defaultLabel.setVisible(False)
718
 
736
 
737
+
738
+
719
     # 全树的item展示
739
     # 全树的item展示
720
     def itembuttonClick(self):
740
     def itembuttonClick(self):
721
         # 判定是否获取的是根节点
741
         # 判定是否获取的是根节点
743
             inpath = os.path.abspath('../SQL')
763
             inpath = os.path.abspath('../SQL')
744
             file_path = inpath + '/' + str3 + '.db'
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
     # 搜索的item展示
781
     # 搜索的item展示
749
     def itembuttonClick1(self):
782
     def itembuttonClick1(self):
773
             file_path = inpath + '/' + str3 + '.db'
806
             file_path = inpath + '/' + str3 + '.db'
774
             # 数据库路径,哪种方法,表名
807
             # 数据库路径,哪种方法,表名
775
             UIFunctions.search_data_to_show(self, file_path, current_text, str1)
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
     def datainfo_keyPressEvent(self, event):
818
     def datainfo_keyPressEvent(self, event):

+ 9
- 4
Front/modules/ui_functions.py Wyświetl plik

20
 
20
 
21
 from main import *
21
 from main import *
22
 import importlib
22
 import importlib
23
+
24
+from select import select
25
+
23
 from Back.GC import GC, GCExport
26
 from Back.GC import GC, GCExport
24
 from Back.GS import GS, GSExport
27
 from Back.GS import GS, GSExport
25
 from Back.WD import WD, WDExport
28
 from Back.WD import WD, WDExport
365
     # 数据一览,点击查询
368
     # 数据一览,点击查询
366
     def search_data_to_show(self, file_path, current_text, tablename):
369
     def search_data_to_show(self, file_path, current_text, tablename):
367
         utf_en = tablename.encode('utf-8')  # 转换文件名为utf-8编码形式
370
         utf_en = tablename.encode('utf-8')  # 转换文件名为utf-8编码形式
368
-        # 高差部分我没改
369
         if current_text == "水准测段高差稳定计算":
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
         elif current_text == "控制网复测平面基准计算":
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
         elif current_text == "平面控制网稳定性计算":
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
     # END - GUI DEFINITIONS
380
     # END - GUI DEFINITIONS

Ładowanie…
Anuluj
Zapisz