Changes in src/sas/qtgui/MainWindow/DataExplorer.py [fd7ef36:9463ca2] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/MainWindow/DataExplorer.py
rfd7ef36 r9463ca2 4 4 import time 5 5 import logging 6 import re 6 7 7 8 from PyQt5 import QtCore … … 36 37 # The controller which is responsible for managing signal slots connections 37 38 # for the gui and providing an interface to the data model. 39 40 # This matches the ID of a plot created using FittingLogic._create1DPlot, e.g. 41 # "5 [P(Q)] modelname" 42 # or 43 # "4 modelname". 44 # Useful for determining whether the plot in question is for an intermediate result, such as P(Q) or S(Q) in the 45 # case of a product model; the identifier for this is held in square brackets, as in the example above. 46 theory_plot_ID_pattern = re.compile(r"^([0-9]+)\s+(\[(.*)\]\s+)?(.*)$") 38 47 39 48 def __init__(self, parent=None, guimanager=None, manager=None): … … 385 394 # Notify the GuiManager about the send request 386 395 self._perspective().setData(data_item=selected_items, is_batch=self.chkBatch.isChecked()) 387 388 def freezeCheckedData(self):389 """390 Convert checked results (fitted model, residuals) into separate dataset.391 """392 outer_index = -1393 theories_copied = 0394 orig_model_size = self.model.rowCount()395 while outer_index < orig_model_size:396 outer_index += 1397 outer_item = self.model.item(outer_index)398 if not outer_item:399 continue400 if not outer_item.isCheckable():401 continue402 # Look for checked inner items403 inner_index = -1404 while inner_index < outer_item.rowCount():405 inner_item = outer_item.child(inner_index)406 inner_index += 1407 if not inner_item:408 continue409 if not inner_item.isCheckable():410 continue411 if inner_item.checkState() != QtCore.Qt.Checked:412 continue413 self.model.beginResetModel()414 theories_copied += 1415 new_item = self.cloneTheory(inner_item)416 self.model.appendRow(new_item)417 self.model.endResetModel()418 419 freeze_msg = ""420 if theories_copied == 0:421 return422 elif theories_copied == 1:423 freeze_msg = "1 theory copied to a separate data set"424 elif theories_copied > 1:425 freeze_msg = "%i theories copied to separate data sets" % theories_copied426 else:427 freeze_msg = "Unexpected number of theories copied: %i" % theories_copied428 raise AttributeError(freeze_msg)429 self.communicator.statusBarUpdateSignal.emit(freeze_msg)430 396 431 397 def freezeTheory(self, event): … … 572 538 else: 573 539 # Don't plot intermediate results, e.g. P(Q), S(Q) 574 match = GuiUtils.theory_plot_ID_pattern.match(plot_id)540 match = self.theory_plot_ID_pattern.match(plot_id) 575 541 # 2nd match group contains the identifier for the intermediate result, if present (e.g. "[P(Q)]") 576 542 if match and match.groups()[1] != None: … … 578 544 # 'sophisticated' test to generate standalone plot for residuals 579 545 if 'esiduals' in plot.title: 580 plot.yscale='linear' 581 self.plotData([(item, plot)]) 546 self.plotData([(item, plot)], transform=False) 582 547 else: 583 548 new_plots.append((item, plot)) … … 860 825 return wlist 861 826 862 def setItemsCheckability(self, model, dimension=None, checked=False):863 """864 For a given model, check or uncheck all items of given dimension865 """866 mode = QtCore.Qt.Checked if checked else QtCore.Qt.Unchecked867 868 assert isinstance(checked, bool)869 870 types = (None, Data1D, Data2D)871 assert dimension in types872 873 for index in range(model.rowCount()):874 item = model.item(index)875 if dimension is not None and not isinstance(GuiUtils.dataFromItem(item), dimension):876 continue877 if item.isCheckable() and item.checkState() != mode:878 item.setCheckState(mode)879 # look for all children880 for inner_index in range(item.rowCount()):881 child = item.child(inner_index)882 if child.isCheckable() and child.checkState() != mode:883 child.setCheckState(mode)884 885 827 def selectData(self, index): 886 828 """ … … 893 835 # Respond appropriately 894 836 if index == 0: 895 self.setItemsCheckability(self.model, checked=True) 896 837 # Select All 838 for index in range(self.model.rowCount()): 839 item = self.model.item(index) 840 if item.isCheckable() and item.checkState() == QtCore.Qt.Unchecked: 841 item.setCheckState(QtCore.Qt.Checked) 897 842 elif index == 1: 898 843 # De-select All 899 self.setItemsCheckability(self.model, checked=False) 844 for index in range(self.model.rowCount()): 845 item = self.model.item(index) 846 if item.isCheckable() and item.checkState() == QtCore.Qt.Checked: 847 item.setCheckState(QtCore.Qt.Unchecked) 900 848 901 849 elif index == 2: 902 850 # Select All 1-D 903 self.setItemsCheckability(self.model, dimension=Data1D, checked=True) 851 for index in range(self.model.rowCount()): 852 item = self.model.item(index) 853 item.setCheckState(QtCore.Qt.Unchecked) 854 855 try: 856 is1D = isinstance(GuiUtils.dataFromItem(item), Data1D) 857 except AttributeError: 858 msg = "Bad structure of the data model." 859 raise RuntimeError(msg) 860 861 if is1D: 862 item.setCheckState(QtCore.Qt.Checked) 904 863 905 864 elif index == 3: 906 865 # Unselect All 1-D 907 self.setItemsCheckability(self.model, dimension=Data1D, checked=False) 866 for index in range(self.model.rowCount()): 867 item = self.model.item(index) 868 869 try: 870 is1D = isinstance(GuiUtils.dataFromItem(item), Data1D) 871 except AttributeError: 872 msg = "Bad structure of the data model." 873 raise RuntimeError(msg) 874 875 if item.isCheckable() and item.checkState() == QtCore.Qt.Checked and is1D: 876 item.setCheckState(QtCore.Qt.Unchecked) 908 877 909 878 elif index == 4: 910 879 # Select All 2-D 911 self.setItemsCheckability(self.model, dimension=Data2D, checked=True) 880 for index in range(self.model.rowCount()): 881 item = self.model.item(index) 882 item.setCheckState(QtCore.Qt.Unchecked) 883 try: 884 is2D = isinstance(GuiUtils.dataFromItem(item), Data2D) 885 except AttributeError: 886 msg = "Bad structure of the data model." 887 raise RuntimeError(msg) 888 889 if is2D: 890 item.setCheckState(QtCore.Qt.Checked) 912 891 913 892 elif index == 5: 914 893 # Unselect All 2-D 915 self.setItemsCheckability(self.model, dimension=Data2D, checked=False) 894 for index in range(self.model.rowCount()): 895 item = self.model.item(index) 896 897 try: 898 is2D = isinstance(GuiUtils.dataFromItem(item), Data2D) 899 except AttributeError: 900 msg = "Bad structure of the data model." 901 raise RuntimeError(msg) 902 903 if item.isCheckable() and item.checkState() == QtCore.Qt.Checked and is2D: 904 item.setCheckState(QtCore.Qt.Unchecked) 916 905 917 906 else: … … 1281 1270 self.theory_model.appendRow(model_item) 1282 1271 1283 def deleteIntermediateTheoryPlotsByModelID(self, model_id):1284 """Given a model's ID, deletes all items in the theory item model which reference the same ID. Useful in the1285 case of intermediate results disappearing when changing calculations (in which case you don't want them to be1286 retained in the list)."""1287 items_to_delete = []1288 for r in range(self.theory_model.rowCount()):1289 item = self.theory_model.item(r, 0)1290 data = item.child(0).data()1291 if not hasattr(data, "id"):1292 return1293 match = GuiUtils.theory_plot_ID_pattern.match(data.id)1294 if match:1295 item_model_id = match.groups()[-1]1296 if item_model_id == model_id:1297 # Only delete those identified as an intermediate plot1298 if match.groups()[2] not in (None, ""):1299 items_to_delete.append(item)1300 1301 for item in items_to_delete:1302 self.theory_model.removeRow(item.row())
Note: See TracChangeset
for help on using the changeset viewer.