mirror of https://github.com/m-labs/artiq.git
applets: use a different workaround to disable editing
True to itself, Qt did not miss the opportunity to trash widgets inside QTreeWidgetItems when they are moved by drag-and-drop. Problem known for more than 6 years and still not fixed as of Qt 5.7.
This commit is contained in:
parent
6144839beb
commit
4bdbc5b259
|
@ -76,8 +76,7 @@ class AppletsCCBDock(applets.AppletsDock):
|
||||||
self.ccbp_group_action.setEnabled(False)
|
self.ccbp_group_action.setEnabled(False)
|
||||||
else:
|
else:
|
||||||
self.ccbp_group_action.setEnabled(True)
|
self.ccbp_group_action.setEnabled(True)
|
||||||
print(item, item.ty)
|
ccbp = item.text(1)
|
||||||
ccbp = self.table.itemWidget(item, 1).text()
|
|
||||||
if ccbp == "":
|
if ccbp == "":
|
||||||
self.ccbp_group_none.setChecked(True)
|
self.ccbp_group_none.setChecked(True)
|
||||||
else:
|
else:
|
||||||
|
@ -89,7 +88,7 @@ class AppletsCCBDock(applets.AppletsDock):
|
||||||
item = self.table.selectedItems()[0]
|
item = self.table.selectedItems()[0]
|
||||||
if item.ty == "applet":
|
if item.ty == "applet":
|
||||||
item = item.parent()
|
item = item.parent()
|
||||||
self.table.itemWidget(item, 1).setText(ccbp)
|
item.setText(1, ccbp)
|
||||||
|
|
||||||
def get_ccpb_global(self):
|
def get_ccpb_global(self):
|
||||||
if self.ccbp_global_ignore.isChecked():
|
if self.ccbp_global_ignore.isChecked():
|
||||||
|
|
|
@ -376,6 +376,14 @@ class AppletsDock(QtWidgets.QDockWidget):
|
||||||
|
|
||||||
self.table.itemChanged.connect(self.item_changed)
|
self.table.itemChanged.connect(self.item_changed)
|
||||||
|
|
||||||
|
# HACK
|
||||||
|
self.table.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
|
||||||
|
self.table.itemDoubleClicked.connect(self.open_editor)
|
||||||
|
|
||||||
|
def open_editor(self, item, column):
|
||||||
|
if column != 1 or item.ty != "group":
|
||||||
|
self.table.editItem(item, column)
|
||||||
|
|
||||||
def get_spec(self, item):
|
def get_spec(self, item):
|
||||||
if item.applet_spec_ty == "command":
|
if item.applet_spec_ty == "command":
|
||||||
return {"ty": "command", "command": item.text(1)}
|
return {"ty": "command", "command": item.text(1)}
|
||||||
|
@ -505,7 +513,7 @@ class AppletsDock(QtWidgets.QDockWidget):
|
||||||
def new_group(self, name=None, attr="", parent=None):
|
def new_group(self, name=None, attr="", parent=None):
|
||||||
if name is None:
|
if name is None:
|
||||||
name = self.get_untitled()
|
name = self.get_untitled()
|
||||||
item = QtWidgets.QTreeWidgetItem([name])
|
item = QtWidgets.QTreeWidgetItem([name, attr])
|
||||||
item.ty = "group"
|
item.ty = "group"
|
||||||
item.setFlags(QtCore.Qt.ItemIsSelectable |
|
item.setFlags(QtCore.Qt.ItemIsSelectable |
|
||||||
QtCore.Qt.ItemIsEditable |
|
QtCore.Qt.ItemIsEditable |
|
||||||
|
@ -520,9 +528,6 @@ class AppletsDock(QtWidgets.QDockWidget):
|
||||||
self.table.addTopLevelItem(item)
|
self.table.addTopLevelItem(item)
|
||||||
else:
|
else:
|
||||||
parent.addChild(item)
|
parent.addChild(item)
|
||||||
# HACK: make the cell non-editable. Qt doesn't even provide
|
|
||||||
# a clean API for such a basic feature.
|
|
||||||
self.table.setItemWidget(item, 1, QtWidgets.QLabel(attr))
|
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def new_with_parent(self, cb, **kwargs):
|
def new_with_parent(self, cb, **kwargs):
|
||||||
|
@ -605,7 +610,7 @@ class AppletsDock(QtWidgets.QDockWidget):
|
||||||
state.append(("applet", uid, enabled, name, spec, geometry))
|
state.append(("applet", uid, enabled, name, spec, geometry))
|
||||||
elif cwi.ty == "group":
|
elif cwi.ty == "group":
|
||||||
name = cwi.text(0)
|
name = cwi.text(0)
|
||||||
attr = self.table.itemWidget(cwi, 1).text()
|
attr = cwi.text(1)
|
||||||
expanded = cwi.isExpanded()
|
expanded = cwi.isExpanded()
|
||||||
state_child = self.save_state_item(cwi)
|
state_child = self.save_state_item(cwi)
|
||||||
state.append(("group", name, attr, expanded, state_child))
|
state.append(("group", name, attr, expanded, state_child))
|
||||||
|
|
Loading…
Reference in New Issue