Changeset 63467b6 in sasview for src/sas/qtgui/Utilities


Ignore:
Timestamp:
Sep 27, 2018 4:20:24 AM (6 years ago)
Author:
Piotr Rozyczko <piotr.rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
4f8c17f
Parents:
dce68f6
Message:

Improved handling of 2d plot children. Refactored model tree search.

Location:
src/sas/qtgui/Utilities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Utilities/GuiUtils.py

    r8eea1b1 r63467b6  
    500500    return plot_data 
    501501 
     502def getChildrenFromItem(root): 
     503    """ 
     504    Recursively go down the model item looking for all children 
     505    """ 
     506    def recurse(parent): 
     507        for row in range(parent.rowCount()): 
     508            for column in range(parent.columnCount()): 
     509                child = parent.child(row, column) 
     510                yield child 
     511                if child.hasChildren(): 
     512                    yield from recurse(child) 
     513    if root is not None: 
     514        yield from recurse(root) 
     515 
    502516def plotsFromCheckedItems(model_item): 
    503517    """ 
     
    507521 
    508522    plot_data = [] 
     523 
    509524    # Iterate over model looking for items with checkboxes 
    510525    for index in range(model_item.rowCount()): 
    511526        item = model_item.item(index) 
    512  
    513         # Going 1 level deeper only 
    514         for index_2 in range(item.rowCount()): 
    515             item_2 = item.child(index_2) 
    516             if item_2 and item_2.isCheckable() and item_2.checkState() == QtCore.Qt.Checked: 
    517                 # TODO: assure item type is correct (either data1/2D or Plotter) 
    518                 plot_data.append((item_2, item_2.child(0).data())) 
    519  
    520         if item.isCheckable() and item.checkState() == QtCore.Qt.Checked: 
    521             # TODO: assure item type is correct (either data1/2D or Plotter) 
    522             plot_data.append((item, item.child(0).data())) 
     527        if item and item.isCheckable() and item.checkState() == QtCore.Qt.Checked: 
     528            data = item.child(0).data() 
     529            plot_data.append((item, data)) 
     530 
     531        items = list(getChildrenFromItem(item)) 
     532 
     533        for it in items: 
     534            if it.isCheckable() and it.checkState() == QtCore.Qt.Checked: 
     535                data = it.child(0).data() 
     536                plot_data.append((it, data)) 
    523537 
    524538    return plot_data 
  • src/sas/qtgui/Utilities/UnitTesting/GuiUtilsTest.py

    r57be490 r63467b6  
    195195        # Make sure only the checked data is present 
    196196        # FRIDAY IN 
    197         self.assertIn(test_list0, plot_list[1]) 
     197        self.assertIn(test_list0, plot_list[0]) 
    198198        # SATURDAY IN 
    199         self.assertIn(test_list1, plot_list[0]) 
     199        self.assertIn(test_list1, plot_list[1]) 
    200200        # MONDAY NOT IN 
    201201        self.assertNotIn(test_list2, plot_list[0]) 
Note: See TracChangeset for help on using the changeset viewer.