Changeset 00b7ddf0 in sasview
- Timestamp:
- Sep 4, 2018 5:51:03 AM (6 years ago)
- Branches:
- ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 700b03b
- Parents:
- ef3494b3
- git-author:
- Torin Cooper-Bennun <torin.cooper-bennun@…> (07/25/18 12:01:03)
- git-committer:
- Torin Cooper-Bennun <torin.cooper-bennun@…> (09/04/18 05:51:03)
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py ¶
rff3b293 r00b7ddf0 181 181 item_list[0].setCheckable(True) 182 182 model.appendRow(item_list) 183 184 def addHeadingRowToModel(model, name): 185 """adds a non-interactive top-level row to the model""" 186 header_row = [QtGui.QStandardItem() for i in range(5)] 187 header_row[0].setText(name) 188 189 font = header_row[0].font() 190 font.setBold(True) 191 header_row[0].setFont(font) 192 193 for item in header_row: 194 item.setEditable(False) 195 item.setCheckable(False) 196 item.setSelectable(False) 197 198 model.appendRow(header_row) 183 199 184 200 def addHeadersToModel(model): -
TabularUnified src/sas/qtgui/Perspectives/Fitting/FittingWidget.py ¶
ref3494b3 r00b7ddf0 669 669 Return list of all parameters for the current model 670 670 """ 671 return [self._model_model.item(row).text() for row in range(self._model_model.rowCount())] 671 return [self._model_model.item(row).text() 672 for row in range(self._model_model.rowCount()) 673 if self.isCheckable(row)] 672 674 673 675 def modifyViewOnRow(self, row, font=None, brush=None): … … 697 699 assert isinstance(constraint, Constraint) 698 700 assert 0 <= row <= self._model_model.rowCount() 701 assert self.isCheckable(row) 699 702 700 703 item = QtGui.QStandardItem() … … 717 720 max_col = self.lstParams.itemDelegate().param_max 718 721 for row in self.selectedParameters(): 722 assert(self.isCheckable(row)) 719 723 param = self._model_model.item(row, 0).text() 720 724 value = self._model_model.item(row, 1).text() … … 759 763 max_col = self.lstParams.itemDelegate().param_max 760 764 for row in range(self._model_model.rowCount()): 765 if not self.isCheckable(row): 766 continue 761 767 if not self.rowHasConstraint(row): 762 768 continue … … 787 793 For the given row, return its constraint, if any 788 794 """ 789 try:795 if self.isCheckable(row): 790 796 item = self._model_model.item(row, 1) 791 return item.child(0).data() 792 except AttributeError: 793 # return none when no constraints 794 return None 797 try: 798 return item.child(0).data() 799 except AttributeError: 800 # return none when no constraints 801 pass 802 return None 795 803 796 804 def rowHasConstraint(self, row): … … 798 806 Finds out if row of the main model has a constraint child 799 807 """ 800 item = self._model_model.item(row, 1) 801 if item.hasChildren(): 802 c = item.child(0).data() 803 if isinstance(c, Constraint): 804 return True 808 if self.isCheckable(row): 809 item = self._model_model.item(row, 1) 810 if item.hasChildren(): 811 c = item.child(0).data() 812 if isinstance(c, Constraint): 813 return True 805 814 return False 806 815 … … 809 818 Finds out if row of the main model has an active constraint child 810 819 """ 811 item = self._model_model.item(row, 1) 812 if item.hasChildren(): 813 c = item.child(0).data() 814 if isinstance(c, Constraint) and c.active: 815 return True 820 if self.isCheckable(row): 821 item = self._model_model.item(row, 1) 822 if item.hasChildren(): 823 c = item.child(0).data() 824 if isinstance(c, Constraint) and c.active: 825 return True 816 826 return False 817 827 … … 820 830 Finds out if row of the main model has an active, nontrivial constraint child 821 831 """ 822 item = self._model_model.item(row, 1) 823 if item.hasChildren(): 824 c = item.child(0).data() 825 if isinstance(c, Constraint) and c.func and c.active: 826 return True 832 if self.isCheckable(row): 833 item = self._model_model.item(row, 1) 834 if item.hasChildren(): 835 c = item.child(0).data() 836 if isinstance(c, Constraint) and c.func and c.active: 837 return True 827 838 return False 828 839 … … 1556 1567 # internal so can use closure for param_dict 1557 1568 param_name = str(self._model_model.item(row, 0).text()) 1558 if param_name not in list(param_dict.keys()):1569 if not self.isCheckable(row) or param_name not in list(param_dict.keys()): 1559 1570 return 1560 1571 # modify the param value … … 1568 1579 # Utility function for updateof polydispersity part of the main model 1569 1580 param_name = str(self._model_model.item(row, 0).text())+'.width' 1570 if param_name not in list(param_dict.keys()):1581 if not self.isCheckable(row) or param_name not in list(param_dict.keys()): 1571 1582 return 1572 1583 # modify the param value … … 1711 1722 """ 1712 1723 for row_i in range(self._magnet_model.rowCount()): 1713 func(row_i) 1724 if self.isCheckable(row_i): 1725 func(row_i) 1714 1726 1715 1727 def updateMagnetModelFromList(self, param_dict): … … 2031 2043 self.shell_names = self.shellNamesList() 2032 2044 2033 # Add a header 2034 header_row = [QtGui.QStandardItem() for i in range(5)] 2035 header_row[0].setText(self.kernel_module.name) 2036 font = header_row[0].font() 2037 font.setBold(True) 2038 header_row[0].setFont(font) 2039 for item in header_row: 2040 item.setEditable(False) 2041 item.setCheckable(False) 2042 item.setSelectable(False) 2043 2044 self._model_model.appendRow(header_row) 2045 2046 # Update the QModel 2045 # Get new rows for QModel 2047 2046 new_rows = FittingUtilities.addParametersToModel(self.model_parameters, self.kernel_module, self.is2D) 2048 2047 2048 # Add heading row 2049 FittingUtilities.addHeadingRowToModel(self._model_model, model_name) 2050 2051 # Update QModel 2049 2052 for row in new_rows: 2050 2053 self._model_model.appendRow(row) … … 2064 2067 self.kernel_module = MultiplicationModel(form_kernel, structure_kernel) 2065 2068 2066 # Add a header 2067 header_row = [QtGui.QStandardItem() for i in range(5)] 2068 header_row[0].setText(structure_kernel._model_info.name) 2069 font = header_row[0].font() 2070 font.setBold(True) 2071 header_row[0].setFont(font) 2072 for item in header_row: 2073 item.setEditable(False) 2074 item.setCheckable(False) 2075 item.setSelectable(False) 2076 2077 self._model_model.appendRow(header_row) 2078 2069 # Get new rows for QModel 2079 2070 new_rows = FittingUtilities.addSimpleParametersToModel(structure_parameters, self.is2D) 2071 2072 # Add heading row 2073 FittingUtilities.addHeadingRowToModel(self._model_model, structure_factor) 2074 2075 # Update QModel 2080 2076 for row in new_rows: 2081 2077 self._model_model.appendRow(row) … … 2517 2513 def updateFunctionCaption(row): 2518 2514 # Utility function for update of polydispersity function name in the main model 2515 if not self.isCheckable(row): 2516 return 2519 2517 param_name = str(self._model_model.item(row, 0).text()) 2520 2518 if param_name != param.name: -
TabularUnified src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py ¶
r6dbff18 r00b7ddf0 255 255 256 256 # We have 4 more rows now 257 self.assertEqual(self.widget._model_model.rowCount(), rowcount+ 4)257 self.assertEqual(self.widget._model_model.rowCount(), rowcount+5) 258 258 259 259 # Switch models … … 275 275 self.widget.cbStructureFactor.setCurrentIndex(last_index-1) 276 276 # Do we have all the rows? 277 self.assertEqual(self.widget._model_model.rowCount(), 4)277 self.assertEqual(self.widget._model_model.rowCount(), 5) 278 278 279 279 # Are the command buttons properly enabled? … … 496 496 Test opening of the load file dialog for 'array' polydisp. function 497 497 """ 498 499 # open a non-existent file 498 500 filename = os.path.join("UnitTesting", "testdata_noexist.txt") 501 with self.assertRaises(OSError, msg="testdata_noexist.txt should be a non-existent file"): 502 os.stat(filename) 499 503 QtWidgets.QFileDialog.getOpenFileName = MagicMock(return_value=(filename,'')) 500 504 self.widget.show() … … 512 516 513 517 # good file 518 # TODO: this depends on the working directory being src/sas/qtgui, 519 # TODO: which isn't convenient if you want to run this test suite 520 # TODO: individually 514 521 filename = os.path.join("UnitTesting", "testdata.txt") 522 try: 523 os.stat(filename) 524 except OSError: 525 self.assertTrue(False, "testdata.txt does not exist") 515 526 QtWidgets.QFileDialog.getOpenFileName = MagicMock(return_value=(filename,'')) 516 527 … … 1012 1023 1013 1024 # Check the model 1014 self.assertEqual(self.widget._model_model.rowCount(), 6)1025 self.assertEqual(self.widget._model_model.rowCount(), 7) 1015 1026 self.assertEqual(self.widget._model_model.columnCount(), 5) 1016 1027 … … 1128 1139 # two rows selected 1129 1140 index1 = self.widget.lstParams.model().index(1, 0, QtCore.QModelIndex()) 1130 index2 = self.widget.lstParams.model().index( 2, 0, QtCore.QModelIndex())1141 index2 = self.widget.lstParams.model().index(3, 0, QtCore.QModelIndex()) 1131 1142 selection_model = self.widget.lstParams.selectionModel() 1132 1143 selection_model.select(index1, selection_model.Select | selection_model.Rows) … … 1164 1175 # several random parameters 1165 1176 self.assertEqual(self.widget.getRowFromName('scale'), 0) 1166 self.assertEqual(self.widget.getRowFromName('length'), 5)1177 self.assertEqual(self.widget.getRowFromName('length'), 6) 1167 1178 1168 1179 def testGetParamNames(self): … … 1201 1212 # Create a constraint object 1202 1213 const = Constraint(parent=None, value=7.0) 1203 row = 21214 row = 3 1204 1215 1205 1216 spy = QtSignalSpy(self.widget, self.widget.constraintAddedSignal) … … 1220 1231 # assign complex constraint now 1221 1232 const = Constraint(parent=None, param='radius', func='5*sld') 1222 row = 41233 row = 5 1223 1234 # call the method tested 1224 1235 self.widget.addConstraintToRow(constraint=const, row=row) … … 1279 1290 self.widget.cbModel.setCurrentIndex(model_index) 1280 1291 1292 row1 = 1 1293 row2 = 5 1294 1295 param1 = "background" 1296 param2 = "radius" 1297 1298 #default_value1 = "0.001" 1299 default_value2 = "20" 1300 1281 1301 # select two rows 1282 row1 = 11283 row2 = 41284 1302 index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 1285 1303 index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) … … 1298 1316 1299 1317 # delete one of the constraints 1300 self.widget.deleteConstraintOnParameter(param= 'background')1318 self.widget.deleteConstraintOnParameter(param=param1) 1301 1319 1302 1320 # see that the other constraint is still present 1303 cons = self.widget.getConstraintForRow( 4) # 4 = radius1304 self.assertEqual(cons.param, "radius")1305 self.assertEqual(cons.value, "20")1321 cons = self.widget.getConstraintForRow(row2) 1322 self.assertEqual(cons.param, param2) 1323 self.assertEqual(cons.value, default_value2) 1306 1324 1307 1325 # kill the other constraint … … 1309 1327 1310 1328 # see that the other constraint is still present 1311 self.assertEqual(self.widget.getConstraintsForModel(), [( 'radius', None)])1329 self.assertEqual(self.widget.getConstraintsForModel(), [(param2, None)]) 1312 1330 1313 1331 def testGetConstraintForRow(self): … … 1329 1347 self.widget.cbModel.setCurrentIndex(model_index) 1330 1348 1349 row1 = 1 1350 row2 = 5 1351 1331 1352 # select two rows 1332 row1 = 11333 row2 = 41334 1353 index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 1335 1354 index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) … … 1341 1360 self.widget.addSimpleConstraint() 1342 1361 1343 con_list = [False, True, False, False, True, False]1362 con_list = [False, True, False, False, False, True, False] 1344 1363 new_list = [] 1345 1364 for row in range(self.widget._model_model.rowCount()): … … 1359 1378 self.widget.cbModel.setCurrentIndex(model_index) 1360 1379 1380 row1 = 1 1381 row2 = 5 1382 1361 1383 # select two rows 1362 row1 = 11363 row2 = 41364 1384 index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 1365 1385 index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) … … 1375 1395 constraint_objects[0].active = False 1376 1396 1377 con_list = [False, False, False, False, True, False]1397 con_list = [False, False, False, False, False, True, False] 1378 1398 new_list = [] 1379 1399 for row in range(self.widget._model_model.rowCount()): … … 1396 1416 self.assertEqual(self.widget.getConstraintsForModel(),[]) 1397 1417 1418 row1 = 1 1419 row2 = 5 1420 1421 param1 = "background" 1422 param2 = "radius" 1423 1424 default_value1 = "0.001" 1425 default_value2 = "20" 1426 1398 1427 # select two rows 1399 row1 = 11400 row2 = 41401 1428 index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 1402 1429 index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) … … 1410 1437 # simple constraints 1411 1438 # self.assertEqual(self.widget.getConstraintsForModel(), [('background', '0.001'), ('radius', '20')]) 1412 cons = self.widget.getConstraintForRow( 1) # 1 - background1413 self.assertEqual(cons.param, "background")1414 self.assertEqual(cons.value, "0.001")1415 cons = self.widget.getConstraintForRow( 4) # 4 = radius1416 self.assertEqual(cons.param, "radius")1417 self.assertEqual(cons.value, "20")1439 cons = self.widget.getConstraintForRow(row1) 1440 self.assertEqual(cons.param, param1) 1441 self.assertEqual(cons.value, default_value1) 1442 cons = self.widget.getConstraintForRow(row2) 1443 self.assertEqual(cons.param, param2) 1444 self.assertEqual(cons.value, default_value2) 1418 1445 1419 1446 objects = self.widget.getConstraintObjectsForModel() 1420 1447 self.assertEqual(len(objects), 2) 1421 self.assertEqual(objects[1].value, '20') 1422 self.assertEqual(objects[0].param, 'background') 1448 self.assertEqual(objects[1].value, default_value2) 1449 self.assertEqual(objects[0].param, param1) 1450 1451 row = 0 1452 param = "scale" 1453 func = "5*sld" 1423 1454 1424 1455 # add complex constraint 1425 const = Constraint(parent=None, param='scale', func='5*sld') 1426 row = 0 1456 const = Constraint(parent=None, param=param, func=func) 1427 1457 self.widget.addConstraintToRow(constraint=const, row=row) 1428 1458 #self.assertEqual(self.widget.getConstraintsForModel(),[('scale', '5*sld'), ('background', '0.001'), ('radius', None)]) 1429 cons = self.widget.getConstraintForRow( 4) # 4 = radius1430 self.assertEqual(cons.param, "radius")1431 self.assertEqual(cons.value, "20")1459 cons = self.widget.getConstraintForRow(row2) 1460 self.assertEqual(cons.param, param2) 1461 self.assertEqual(cons.value, default_value2) 1432 1462 1433 1463 objects = self.widget.getConstraintObjectsForModel() 1434 1464 self.assertEqual(len(objects), 3) 1435 self.assertEqual(objects[0].func, '5*sld')1465 self.assertEqual(objects[0].func, func) 1436 1466 1437 1467 def testReplaceConstraintName(self):
Note: See TracChangeset
for help on using the changeset viewer.