@@ -168,6 +168,7 @@ class Menu(object):
168
168
VD_TREE_COL_DELETE = 3
169
169
VD_TREE_ROLE_IS_DUMMY_ROW = Qt .UserRole + 1
170
170
VD_TREE_ROLE_DO_INVERTED = Qt .UserRole + 2
171
+ VD_TREE_ROLE_IS_VIRTUAL_DEVICE = Qt .UserRole + 3
171
172
172
173
def _get_root_parent (item ):
173
174
while item .parent () is not None :
@@ -339,6 +340,7 @@ def on_virtual_devices_item_changed(self, item):
339
340
340
341
new_device_item = QStandardItem (new_vd_name )
341
342
remove_item = QStandardItem ()
343
+ remove_item .setData (True , self .VD_TREE_ROLE_IS_VIRTUAL_DEVICE )
342
344
remove_item .setIcon (QIcon (':qtutils/fugue/minus' ))
343
345
remove_item .setEditable (False )
344
346
remove_item .setToolTip ('Remove this virtual device' )
@@ -364,6 +366,8 @@ def on_treeView_virtual_devices_clicked(self, index):
364
366
elif item .column () == self .VD_TREE_COL_DN :
365
367
if index .row () < item .parent ().rowCount ()- 1 :
366
368
item .parent ().insertRow (index .row ()+ 1 , item .parent ().takeRow (index .row ()))
369
+ elif item .data (self .VD_TREE_ROLE_IS_VIRTUAL_DEVICE ) and item .column () == self .VD_TREE_COL_DELETE :
370
+ self .virtual_device_model .removeRows (index .row (), 1 )
367
371
elif item .column () == self .VD_TREE_COL_DELETE :
368
372
item .parent ().removeRow (index .row ())
369
373
@@ -372,7 +376,12 @@ def on_edit_virtual_devices(self, *args, **kwargs):
372
376
# This happens here so that the tree is up to date
373
377
for vd_name , vd in self .BLACS ['plugins' ][module ].get_save_virtual_devices ().items ():
374
378
device_item = QStandardItem (vd_name )
375
- self .virtual_device_model .appendRow ([device_item ])
379
+ remove_item = QStandardItem ()
380
+ remove_item .setData (True , self .VD_TREE_ROLE_IS_VIRTUAL_DEVICE )
381
+ remove_item .setIcon (QIcon (':qtutils/fugue/minus' ))
382
+ remove_item .setEditable (False )
383
+ remove_item .setToolTip ('Remove this virtual device' )
384
+ self .virtual_device_model .appendRow ([device_item , None , None , remove_item ])
376
385
377
386
analog_outputs = QStandardItem ('Analog Outputs' )
378
387
device_item .appendRow (analog_outputs )
0 commit comments