source: sasview/src/sas/qtgui/Plotting/SlicerModel.py @ 4ea8020

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 4ea8020 was d6b8a1d, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

More Qt5 related fixes

  • Property mode set to 100644
File size: 1.9 KB
Line 
1from PyQt5 import QtGui
2from PyQt5 import QtCore
3
4import sas.qtgui.Utilities.GuiUtils as GuiUtils
5
6class SlicerModel(object):
7    def __init__(self):
8        # Model representation of local parameters
9        self._model = QtGui.QStandardItemModel()
10
11        self.update_model = True
12        self._model.itemChanged.connect(self.setParamsFromModel)
13
14    def setModelFromParams(self):
15        """
16        Set up the Qt model for data handling between controls
17        """
18        parameters = self.getParams()
19        self._model.removeRows( 0, self._model.rowCount() )
20        # Crete/overwrite model items
21        for parameter in list(parameters.keys()):
22            item1 = QtGui.QStandardItem(parameter)
23            item2 = QtGui.QStandardItem(GuiUtils.formatNumber(parameters[parameter]))
24            self._model.appendRow([item1, item2])
25        self._model.setHeaderData(0, QtCore.Qt.Horizontal, "Parameter")
26        self._model.setHeaderData(1, QtCore.Qt.Horizontal, "Value")
27
28    def setParamsFromModel(self, item):
29        """
30        Set up the params dictionary based on the model content.
31        """
32        params = self.getParams()
33        index = self._model.indexFromItem(item)
34        row_index = index.row()
35        param_name = str(self._model.item(row_index, 0).text())
36        params[param_name] = float(self._model.item(row_index, 1).text())
37
38        self.update_model = False
39        self.setParams(params)
40        self.update_model = True
41
42    def model(self):
43        '''getter for the model'''
44        return self._model
45
46    def getParams(self):
47        ''' pure virtual '''
48        raise NotImplementedError("Parameter getter must be implemented in derived class.")
49
50    def setParams(self):
51        ''' pure virtual '''
52        raise NotImplementedError("Parameter setter must be implemented in derived class.")
53
54    def validate(self):
55        ''' pure virtual '''
56        raise NotImplementedError("Validator must be implemented in derived class.")
57
Note: See TracBrowser for help on using the repository browser.