wzp 3 месяцев назад
Родитель
Сommit
226d507393
5 измененных файлов: 90 добавлений и 6 удалений
  1. 6
    0
      Back/GC/GCshow.py
  2. 14
    1
      Back/GS/GSshow.py
  3. 14
    0
      Back/WD/WDshow.py
  4. 47
    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

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

@@ -469,6 +469,30 @@ class MainWindow(QMainWindow):
469 469
         # tree_button.itemClicked.connect(self.itembuttonClick)
470 470
         # tree_button.itemDoubleClicked.connect(self.itembuttonClick)
471 471
 
472
+
473
+    #单元格的右键
474
+    def show_custom_context_menu(self, pos):
475
+        # 创建一个右键菜单
476
+        menu = QMenu(self.ui.resultTableView1)
477
+        menu.setStyleSheet("QMenu { background-color: #FFFFFF; }")
478
+        # 获取选中单元格的索引
479
+        index = self.ui.resultTableView1.indexAt(pos)
480
+        # # 添加菜单项和对应的操作
481
+        # action_1 = QAction("操作1", self)
482
+        # action_1.triggered.connect(lambda: self.do_something(index))
483
+        # menu.addAction(action_1)
484
+        # 添加菜单项和对应的操作
485
+        action_1 = QAction("删除该行", self)
486
+        action_1.triggered.connect(self.seleceModel_itemclicked)
487
+        menu.addAction(action_1)
488
+        action_2 = QAction("编辑单元格", self)
489
+        action_2.triggered.connect(self.seleceModel_itemclicked)
490
+        menu.addAction(action_2)
491
+        action_3 = QAction("添加数据", self)
492
+        action_3.triggered.connect(self.seleceModel_itemclicked)
493
+        menu.addAction(action_3)
494
+        menu.exec(self.ui.resultTableView1.mapToGlobal(pos))
495
+
472 496
     def closeEvent(self, event):
473 497
         # 停止监控
474 498
         self.observer.stop()
@@ -754,6 +778,8 @@ class MainWindow(QMainWindow):
754 778
         # 隐藏默认label
755 779
         self.ui.defaultLabel.setVisible(False)
756 780
 
781
+
782
+
757 783
     # 全树的item展示
758 784
     def itembuttonClick(self):
759 785
         # 判定是否获取的是根节点
@@ -781,7 +807,20 @@ class MainWindow(QMainWindow):
781 807
             inpath = os.path.abspath('../SQL')
782 808
             file_path = inpath + '/' + str3 + '.db'
783 809
             # 数据库路径,哪种方法,表名
784
-            UIFunctions.search_data_to_show(self, file_path, current_text, str1)
810
+            self.selectModel = UIFunctions.search_data_to_show(self, file_path, current_text, str1)
811
+            # self.ui.resultTableView1.doubleClicked.connect(self.seleceModel_itemclicked)
812
+
813
+            # 设置右键菜单策略为CustomContextMenu
814
+            self.ui.resultTableView1.setContextMenuPolicy(Qt.CustomContextMenu)
815
+
816
+            # 关联自定义的右键菜单方法到customContextMenuRequested信号
817
+            self.ui.resultTableView1.customContextMenuRequested.connect(self.show_custom_context_menu)
818
+
819
+    #右键对应行可删除对应行(只是视图上)
820
+    def seleceModel_itemclicked(self):
821
+        curIndex = self.selectModel.currentIndex()
822
+        self.ui.resultTableView1.model().removeRow(curIndex.row())
823
+        kk = 1
785 824
 
786 825
     # 搜索的item展示
787 826
     def itembuttonClick1(self):
@@ -811,6 +850,13 @@ class MainWindow(QMainWindow):
811 850
             file_path = inpath + '/' + str3 + '.db'
812 851
             # 数据库路径,哪种方法,表名
813 852
             UIFunctions.search_data_to_show(self, file_path, current_text, str1)
853
+            # self.ui.resultTableView1.doubleClicked.connect(self.seleceModel_itemclicked)
854
+
855
+            # 设置右键菜单策略为CustomContextMenu
856
+            self.ui.resultTableView1.setContextMenuPolicy(Qt.CustomContextMenu)
857
+
858
+            # 关联自定义的右键菜单方法到customContextMenuRequested信号
859
+            self.ui.resultTableView1.customContextMenuRequested.connect(self.show_custom_context_menu)
814 860
 
815 861
     # 键盘回车事件,目前用于搜索按钮
816 862
     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

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