Changeset d3c0b95 in sasview
- Timestamp:
- Jan 10, 2018 5:15:53 AM (7 years ago)
- 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:
- e147ce2
- Parents:
- eae226b
- git-author:
- Piotr Rozyczko <rozyczko@…> (01/10/18 05:05:35)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (01/10/18 05:15:53)
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
reae226b rd3c0b95 462 462 self.options_widget.plot_signal.connect(self.onOptionsUpdate) 463 463 464 def modelName(self): 465 """ 466 Returns model name, by default M<tab#>, e.g. M1, M2 467 """ 468 return "M%i" % self.tab_id 469 470 def nameForFittedData(self, name): 471 """ 472 Generate name for the current fit 473 """ 474 if self.is2D: 475 name += "2d" 476 name = "%s [%s]" % (self.modelName(), name) 477 return name 478 464 479 def showModelContextMenu(self, position): 465 466 #rows = len([s.row() for s in self.lstParams.selectionModel().selectedRows()]) 480 """ 481 Show context specific menu in the parameter table. 482 When clicked on parameter(s): fitting/constraints options 483 When clicked on white space: model description 484 """ 467 485 rows = [s.row() for s in self.lstParams.selectionModel().selectedRows()] 468 486 menu = self.showModelDescription() if not rows else self.modelContextMenu(rows) … … 475 493 def modelContextMenu(self, rows): 476 494 """ 477 Create context menu for the given model495 Create context menu for the parameter selection 478 496 """ 479 497 menu = QtWidgets.QMenu() … … 482 500 param_string = "parameter " if num_rows==1 else "parameters " 483 501 to_string = "to its current value" if num_rows==1 else "to their current values" 502 has_constraints = any([self.rowHasConstraint(i) for i in rows]) 484 503 485 504 self.actionSelect = QtWidgets.QAction(self) … … 511 530 menu.addSeparator() 512 531 513 if self.rowHasConstraint(rows[0]):532 if has_constraints: 514 533 menu.addAction(self.actionRemoveConstraint) 534 #if num_rows == 1: 535 # menu.addAction(self.actionEditConstraint) 515 536 else: 516 537 menu.addAction(self.actionConstrain) 517 if num_rows == 2:518 menu.addAction(self.actionMutualMultiConstrain)538 if num_rows == 2: 539 menu.addAction(self.actionMutualMultiConstrain) 519 540 520 541 # Define the callbacks … … 549 570 item = QtGui.QStandardItem() 550 571 item.setData(constraint) 572 551 573 # Which row is the constrained parameter in? 552 553 574 row = self.rowFromName(constraint.param) 554 575 self._model_model.item(row, 1).setChild(0, item) 555 576 #self.constraintAddedSignal.emit([row]) 577 556 578 # Show visual hints for the constraint 557 579 font = QtGui.QFont() … … 560 582 self.modifyViewOnRow(row, font=font, brush=brush) 561 583 562 # Pass the constraint to the parser584 # Notify the user 563 585 self.communicate.statusBarUpdateSignal.emit('Constraints added') 564 586 565 587 def rowFromName(self, name): 566 588 """ 567 given parameter name get the row number in self._model_model589 Given parameter name get the row number in self._model_model 568 590 """ 569 591 for row in range(self._model_model.rowCount()): … … 596 618 Adds a constraint on a single parameter. 597 619 """ 620 min_col = self.lstParams.itemDelegate().param_min 621 max_col = self.lstParams.itemDelegate().param_max 598 622 for row in self.selectedParameters(): 599 623 param = self._model_model.item(row, 0).text() 600 624 value = self._model_model.item(row, 1).text() 601 min = self._model_model.item(row, 2).text()602 max = self._model_model.item(row, 3).text()625 min = self._model_model.item(row, min_col).text() 626 max = self._model_model.item(row, max_col).text() 603 627 # Create a Constraint object 604 628 constraint = Constraint(param=param, value=value, min=min, max=max) … … 608 632 self._model_model.item(row, 1).setChild(0, item) 609 633 # Set min/max to the value constrained 610 self._model_model.item(row, 2).setText(value)611 self._model_model.item(row, 3).setText(value)634 self._model_model.item(row, min_col).setText(value) 635 self._model_model.item(row, max_col).setText(value) 612 636 #self.constraintAddedSignal.emit([row]) 613 637 # Show visual hints for the constraint … … 623 647 Delete constraints from selected parameters. 624 648 """ 649 min_col = self.lstParams.itemDelegate().param_min 650 max_col = self.lstParams.itemDelegate().param_max 625 651 for row in self.selectedParameters(): 626 652 # Get the Constraint object from of the model item 627 653 item = self._model_model.item(row, 1) 654 if not item.hasChildren(): 655 continue 628 656 constraint = item.child(0).data() 657 if constraint is None: 658 continue 659 if not isinstance(constraint, Constraint): 660 continue 629 661 # Retrieve old values and put them on the model 630 662 if constraint.min is not None: 631 self._model_model.item(row, 2).setText(constraint.min)663 self._model_model.item(row, min_col).setText(constraint.min) 632 664 if constraint.max is not None: 633 self._model_model.item(row, 3).setText(constraint.max)665 self._model_model.item(row, max_col).setText(constraint.max) 634 666 # Remove constraint item 635 667 item.removeRow(0) … … 639 671 pass 640 672 673 def getConstraintForRow(self, row): 674 """ 675 For the given row, return its constraint, if any 676 """ 677 try: 678 item = self._model_model.item(row, 1) 679 return item.child(0).data() 680 except AttributeError: 681 # return none when no constraints 682 return None 683 641 684 def rowHasConstraint(self, row): 642 685 """ … … 648 691 def selectParameters(self): 649 692 """ 650 Selected parameter s arechosen for fitting693 Selected parameter is chosen for fitting 651 694 """ 652 695 status = QtCore.Qt.Checked … … 662 705 def selectedParameters(self): 663 706 """ Returns list of selected (highlighted) parameters """ 664 return [s.row() for s in self.lstParams.selectionModel().selectedRows() if self.isCheckable(s.row())] 707 return [s.row() for s in self.lstParams.selectionModel().selectedRows() 708 if self.isCheckable(s.row())] 665 709 666 710 def setParameterSelection(self, status=QtCore.Qt.Unchecked): … … 671 715 for row in self.selectedParameters(): 672 716 self._model_model.item(row, 0).setCheckState(status) 673 pass 717 pass # debugger hook 718 719 def getConstraintsForModel(self): 720 """ 721 Return a list of tuples. Each tuple contains constraints mapped as 722 ('constrained parameter', 'function to constrain') 723 e.g. [('sld','5*sld_solvent')] 724 """ 725 model_name = self.modelName() 726 self.kernel_module.name = model_name 727 param_number = self._model_model.rowCount() 728 params = [(self._model_model.item(s, 0).text(), 729 model_name+"."+self._model_model.item(s, 1).child(0).data().func) 730 for s in range(param_number) if self.rowHasConstraint(s)] 731 return params 674 732 675 733 def showModelDescription(self): … … 936 994 # These should be updating somehow? 937 995 fit_id = 0 938 constraints = []996 constraints = self.getConstraintsForModel() 939 997 smearer = None 940 998 page_id = [210] … … 1607 1665 if isChecked(row_index)] 1608 1666 1609 def nameForFittedData(self, name):1610 """1611 Generate name for the current fit1612 """1613 if self.is2D:1614 name += "2d"1615 name = "M%i [%s]" % (self.tab_id, name)1616 return name1617 1618 1667 def createNewIndex(self, fitted_data): 1619 1668 """ -
src/sas/qtgui/Perspectives/Fitting/MultiConstraint.py
reae226b rd3c0b95 29 29 30 30 self.cmdOK.clicked.connect(self.accept) 31 self.cmdHelp.clicked.connect(self.onHelp) 31 32 self.cmdRevert.clicked.connect(self.revert) 32 33 self.txtConstraint.editingFinished.connect(self.validateFormula) … … 122 123 return True 123 124 125 def onHelp(self): 126 """ 127 Display related help section 128 """ 129 try: 130 location = GuiUtils.HELP_DIRECTORY_LOCATION + \ 131 "/user/sasgui/perspectives/fitting/fitting_help.html#simultaneous-fits-with-constraints" 132 133 self.manager._helpView.load(QtCore.QUrl(location)) 134 self.manager._helpView.show() 135 except AttributeError: 136 # No manager defined - testing and standalone runs 137 pass 124 138 125 139 -
src/sas/qtgui/Perspectives/Fitting/UI/MultiConstraintUI.ui
reae226b rd3c0b95 4 4 <widget class="QDialog" name="MultiConstraintUI"> 5 5 <property name="windowModality"> 6 <enum>Qt:: WindowModal</enum>6 <enum>Qt::ApplicationModal</enum> 7 7 </property> 8 8 <property name="geometry"> … … 150 150 <property name="text"> 151 151 <string>OK</string> 152 </property> 153 </widget> 154 </item> 155 <item> 156 <widget class="QPushButton" name="cmdCancel"> 157 <property name="text"> 158 <string>Cancel</string> 159 </property> 160 </widget> 161 </item> 162 <item> 163 <widget class="QPushButton" name="cmdHelp"> 164 <property name="text"> 165 <string>Help</string> 152 166 </property> 153 167 </widget> … … 175 189 </hints> 176 190 </connection> 191 <connection> 192 <sender>cmdCancel</sender> 193 <signal>clicked()</signal> 194 <receiver>MultiConstraintUI</receiver> 195 <slot>reject()</slot> 196 <hints> 197 <hint type="sourcelabel"> 198 <x>187</x> 199 <y>121</y> 200 </hint> 201 <hint type="destinationlabel"> 202 <x>184</x> 203 <y>71</y> 204 </hint> 205 </hints> 206 </connection> 177 207 </connections> 178 208 </ui>
Note: See TracChangeset
for help on using the changeset viewer.