Changeset 8548d739 in sasview


Ignore:
Timestamp:
Nov 29, 2016 6:08:29 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
ded2ce3
Parents:
adf81b8
git-author:
Piotr Rozyczko <rozyczko@…> (11/29/16 06:04:46)
git-committer:
Piotr Rozyczko <rozyczko@…> (11/29/16 06:08:29)
Message:

Further work on the main QStandardItemModel

Location:
src/sas/qtgui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/DataExplorer.py

    radf81b8 r8548d739  
    2323from sas.qtgui.Plotter2D import Plotter2D 
    2424from sas.qtgui.DroppableDataLoadWidget import DroppableDataLoadWidget 
    25  
    26 # This is how to get data1/2D from the model item 
    27 # data = [selected_items[0].child(0).data().toPyObject()] 
    2825 
    2926class DataExplorerWindow(DroppableDataLoadWidget): 
     
    629626 
    630627                try: 
    631                     is1D = isinstance(item.child(0).data().toPyObject(), Data1D) 
     628                    is1D = isinstance(GuiUtils.dataFromItem(item), Data1D) 
    632629                except AttributeError: 
    633630                    msg = "Bad structure of the data model." 
     
    643640 
    644641                try: 
    645                     is1D = isinstance(item.child(0).data().toPyObject(), Data1D) 
     642                    is1D = isinstance(GuiUtils.dataFromItem(item), Data1D) 
    646643                except AttributeError: 
    647644                    msg = "Bad structure of the data model." 
     
    657654                item.setCheckState(QtCore.Qt.Unchecked) 
    658655                try: 
    659                     is2D = isinstance(item.child(0).data().toPyObject(), Data2D) 
     656                    is2D = isinstance(GuiUtils.dataFromItem(item), Data2D) 
    660657                except AttributeError: 
    661658                    msg = "Bad structure of the data model." 
     
    671668 
    672669                try: 
    673                     is2D = isinstance(item.child(0).data().toPyObject(), Data2D) 
     670                    is2D = isinstance(GuiUtils.dataFromItem(item), Data2D) 
    674671                except AttributeError: 
    675672                    msg = "Bad structure of the data model." 
     
    715712            if orig_index: 
    716713                # Check the data to enable/disable actions 
    717                 is_2D = isinstance(model_item.child(0).data().toPyObject(), Data2D) 
     714                is_2D = isinstance(GuiUtils.dataFromItem(model_item), Data2D) 
    718715                self.actionQuick3DPlot.setEnabled(is_2D) 
    719716                self.actionEditMask.setEnabled(is_2D) 
     
    727724        index = self.treeView.selectedIndexes()[0] 
    728725        model_item = self.model.itemFromIndex(self.data_proxy.mapToSource(index)) 
    729         data = model_item.child(0).data().toPyObject() 
     726        data = GuiUtils.dataFromItem(model_item) 
    730727        if isinstance(data, Data1D): 
    731728            text_to_show = GuiUtils.retrieveData1d(data) 
     
    754751        index = self.treeView.selectedIndexes()[0] 
    755752        model_item = self.model.itemFromIndex(self.data_proxy.mapToSource(index)) 
    756         data = model_item.child(0).data().toPyObject() 
     753        data = GuiUtils.dataFromItem(model_item) 
    757754        if isinstance(data, Data1D): 
    758755            GuiUtils.saveData1D(data) 
     
    766763        index = self.treeView.selectedIndexes()[0] 
    767764        model_item = self.model.itemFromIndex(self.data_proxy.mapToSource(index)) 
    768         data = model_item.child(0).data().toPyObject() 
     765        data = GuiUtils.dataFromItem(model_item) 
    769766 
    770767        dimension = 1 if isinstance(data, Data1D) else 2 
  • src/sas/qtgui/GuiUtils.py

    r31c5b58 r8548d739  
    230230 
    231231 
    232 def updateModelItem(item, update_data, name=""): 
     232def updateModelItemWithPlot(item, update_data, name=""): 
    233233    """ 
    234234    Adds a checkboxed row named "name" to QStandardItem 
     
    264264    # Append the new row to the main item 
    265265    item.appendRow(checkbox_item) 
     266 
     267def updateModelItem(item, update_data, name=""): 
     268    """ 
     269    Adds a simple named child to QStandardItem 
     270    """ 
     271    assert isinstance(item, QtGui.QStandardItem) 
     272    assert isinstance(update_data, list) 
     273 
     274    # Add the actual Data1D/Data2D object 
     275    object_item = QtGui.QStandardItem() 
     276    object_item.setText(name) 
     277    object_item.setData(QtCore.QVariant(update_data)) 
     278 
     279    # Append the new row to the main item 
     280    item.appendRow(object_item) 
     281 
    266282 
    267283def plotsFromCheckedItems(model_item): 
     
    564580        except: 
    565581            pass 
     582 
     583def dataFromItem(item): 
     584    """ 
     585    Retrieve Data1D/2D component from QStandardItem. 
     586    The assumption - data stored in SasView standard, in child 0 
     587    """ 
     588    return item.child(0).data().toPyObject() 
  • src/sas/qtgui/Perspectives/Invariant/InvariantPerspective.py

    r31c5b58 r8548d739  
    275275 
    276276            # This needs to run in the main thread 
    277             reactor.callFromThread(GuiUtils.updateModelItem, self._model_item, variant_item, title) 
     277            reactor.callFromThread(GuiUtils.updateModelItemWithPlot, 
     278                    self._model_item, variant_item, title) 
    278279 
    279280        if self._high_extrapolate: 
     
    297298            variant_item = QtCore.QVariant(high_out_data) 
    298299            # This needs to run in the main thread 
    299             reactor.callFromThread(GuiUtils.updateModelItem, self._model_item, variant_item, title) 
     300            reactor.callFromThread(GuiUtils.updateModelItemWithPlot, 
     301                    self._model_item, variant_item, title) 
    300302 
    301303        item = QtGui.QStandardItem(str(float('%.5g'% volume_fraction))) 
     
    531533 
    532534        # Extract data on 1st child - this is the Data1D/2D component 
    533         data = self._model_item.child(0).data().toPyObject() 
     535        data = GuiUtils.dataFromItem(self._model_item) 
    534536        self.model.item(WIDGETS.W_FILENAME).setData(QtCore.QVariant(self._model_item.text())) 
    535537 
  • src/sas/qtgui/UnitTesting/GuiUtilsTest.py

    r31c5b58 r8548d739  
    7373            self.assertIn(signal, dir(com)) 
    7474 
    75  
    76     def testUpdateModelItem(self): 
    77         """ 
    78         Test the QModelItem update method 
     75    def testupdateModelItem(self): 
     76        """ 
     77        Test the generic QModelItem update method 
     78        """ 
     79        test_item = QtGui.QStandardItem() 
     80        test_list = ['aa', 4, True, ] 
     81        name = "Black Sabbath" 
     82 
     83        # update the item 
     84        updateModelItem(test_item, test_list, name) 
     85 
     86        # Make sure test_item got all data added 
     87        self.assertEqual(test_item.child(0).text(), name) 
     88        list_from_item = test_item.child(0).data().toList() 
     89        self.assertIsInstance(list_from_item, list) 
     90        self.assertEqual(list_from_item[0].toPyObject(), test_list[0]) 
     91        self.assertEqual(list_from_item[1].toPyObject(), test_list[1]) 
     92        self.assertEqual(list_from_item[2].toPyObject(), test_list[2]) 
     93 
     94    def testupdateModelItemWithPlot(self): 
     95        """ 
     96        Test the QModelItem checkbox update method 
    7997        """ 
    8098        test_item = QtGui.QStandardItem() 
     
    84102 
    85103        # update the item 
    86         updateModelItem(test_item, update_data, name) 
     104        updateModelItemWithPlot(test_item, update_data, name) 
    87105         
    88106        # Make sure test_item got all data added 
Note: See TracChangeset for help on using the changeset viewer.