|
@@ -624,13 +624,13 @@ class MainWindow(QMainWindow):
|
624
|
624
|
# menu.addAction(action_1)
|
625
|
625
|
# 添加菜单项和对应的操作
|
626
|
626
|
action_1 = QAction("删除该行", self)
|
627
|
|
- action_1.triggered.connect(self.seleceModel_itemclicked)
|
|
627
|
+ action_1.triggered.connect(self.del_Dataclicked)
|
628
|
628
|
menu.addAction(action_1)
|
629
|
629
|
action_2 = QAction("编辑单元格", self)
|
630
|
|
- action_2.triggered.connect(self.seleceModel_itemclicked)
|
|
630
|
+ action_2.triggered.connect(self.del_Dataclicked)
|
631
|
631
|
menu.addAction(action_2)
|
632
|
632
|
action_3 = QAction("添加数据", self)
|
633
|
|
- action_3.triggered.connect(self.seleceModel_itemclicked)
|
|
633
|
+ action_3.triggered.connect(self.add_Dataclicked)
|
634
|
634
|
menu.addAction(action_3)
|
635
|
635
|
menu.exec(self.ui.resultTableView1.mapToGlobal(pos))
|
636
|
636
|
|
|
@@ -920,6 +920,8 @@ class MainWindow(QMainWindow):
|
920
|
920
|
search_button.itemDoubleClicked.connect(self.itembuttonClick1)
|
921
|
921
|
# 隐藏默认label
|
922
|
922
|
self.ui.defaultLabel.setVisible(False)
|
|
923
|
+ #清空搜索框内容
|
|
924
|
+ self.ui.lineEdit_2.clear()
|
923
|
925
|
|
924
|
926
|
# 全树的item展示
|
925
|
927
|
def itembuttonClick(self):
|
|
@@ -984,7 +986,7 @@ class MainWindow(QMainWindow):
|
984
|
986
|
inpath = os.path.abspath('../SQL')
|
985
|
987
|
file_path = inpath + '/' + str3 + '.db'
|
986
|
988
|
# 数据库路径,哪种方法,表名
|
987
|
|
- UIFunctions.search_data_to_show(self, file_path, current_text, str1)
|
|
989
|
+ self.selectModel = UIFunctions.search_data_to_show(self, file_path, current_text, str1)
|
988
|
990
|
# self.ui.resultTableView1.doubleClicked.connect(self.seleceModel_itemclicked)
|
989
|
991
|
|
990
|
992
|
# 设置右键菜单策略为CustomContextMenu
|
|
@@ -1000,23 +1002,24 @@ class MainWindow(QMainWindow):
|
1000
|
1002
|
if widgets.lineEdit_2.text():
|
1001
|
1003
|
# 模拟 search 按钮点击事件
|
1002
|
1004
|
self.ui.search.click()
|
|
1005
|
+ #用于编辑完成操作
|
1003
|
1006
|
else:
|
1004
|
1007
|
# 调用默认的 keyPressEvent 处理其他按键事件
|
1005
|
1008
|
super(widgets.datainfo.__class__, widgets.datainfo).keyPressEvent(event)
|
1006
|
1009
|
|
1007
|
|
- # 右键对应行可删除对应行(所有的,搜索的再写一份,免得弄错)
|
1008
|
|
- def seleceModel_itemclicked(self):
|
1009
|
|
- selected_items = widgets.allTreeWidget.selectedItems()
|
1010
|
|
- item = selected_items[0]
|
1011
|
|
- data = item.data(0, Qt.UserRole + 1)
|
|
1010
|
+ # 右键对应行可删除对应行
|
|
1011
|
+ def del_Dataclicked(self):
|
|
1012
|
+ select_item = self.ui.allTreeWidget.currentItem()
|
|
1013
|
+ if select_item == None:
|
|
1014
|
+ select_item = self.ui.qureyTreeWidget.currentItem()
|
1012
|
1015
|
# 获取数据库路径和表名
|
1013
|
|
- dbname = data['listData'][0]
|
1014
|
|
- tablename = data['listData'][2]
|
1015
|
|
- dbpath = os.path.join(os.path.abspath('../SQL'), f"{dbname}.db")
|
|
1016
|
+ tablename = select_item.text(0)
|
1016
|
1017
|
tablename_utf8 = tablename.encode('utf-8')
|
1017
|
1018
|
# 获取父节点
|
1018
|
|
- parent_item = item.parent()
|
|
1019
|
+ parent_item = select_item.parent()
|
1019
|
1020
|
parent_name = parent_item.text(0)
|
|
1021
|
+ dbname = parent_item.parent().text(0)
|
|
1022
|
+ dbpath = os.path.join(os.path.abspath('../SQL'), f"{dbname}.db")
|
1020
|
1023
|
curIndex = self.selectModel.currentIndex()
|
1021
|
1024
|
# self.ui.resultTableView1.model().removeRow(curIndex.row())
|
1022
|
1025
|
col = curIndex.column()
|
|
@@ -1025,6 +1028,33 @@ class MainWindow(QMainWindow):
|
1025
|
1028
|
UIFunctions.del_row_from_db(self, row, parent_name, tablename_utf8, dbpath)
|
1026
|
1029
|
# 1秒后自动跳转
|
1027
|
1030
|
QTimer.singleShot(1000, lambda: self.simulateButtonClick("btn_new"))
|
|
1031
|
+ # 刷新树和tableview
|
|
1032
|
+ self.refresh_tree()
|
|
1033
|
+
|
|
1034
|
+ # 数据库路径,哪种方法,表名
|
|
1035
|
+ self.selectModel = UIFunctions.search_data_to_show(self, dbpath, parent_name, tablename)
|
|
1036
|
+ # self.ui.resultTableView1.doubleClicked.connect(self.seleceModel_itemclicked)
|
|
1037
|
+
|
|
1038
|
+ # 设置右键菜单策略为CustomContextMenu
|
|
1039
|
+ self.ui.resultTableView1.setContextMenuPolicy(Qt.CustomContextMenu)
|
|
1040
|
+
|
|
1041
|
+ # 关联自定义的右键菜单方法到customContextMenuRequested信号
|
|
1042
|
+ self.ui.resultTableView1.customContextMenuRequested.connect(self.show_custom_context_menu)
|
|
1043
|
+
|
|
1044
|
+ def test(self):
|
|
1045
|
+ print('1')
|
|
1046
|
+
|
|
1047
|
+ def add_Dataclicked(self):
|
|
1048
|
+ #获取显示用的model
|
|
1049
|
+ inputmodel = self.ui.resultTableView1.model()
|
|
1050
|
+ rowcount = inputmodel.rowCount()
|
|
1051
|
+ colcount = inputmodel.columnCount()
|
|
1052
|
+ #添加一行
|
|
1053
|
+ self.ui.resultTableView1.model().insertRow(rowcount)
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
|
1028
|
1058
|
|
1029
|
1059
|
|
1030
|
1060
|
if __name__ == "__main__":
|