Changeset 085e3c9d in sasview


Ignore:
Timestamp:
Jul 10, 2018 4:21:02 AM (6 years ago)
Author:
Torin Cooper-Bennun <torin.cooper-bennun@…>
Branches:
ESS_GUI_iss959
Parents:
6052c02
Message:

improve S(Q) tab tree functionality

Location:
src/sas/qtgui/Perspectives/Fitting
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r6052c02 r085e3c9d  
    333333            QTreeView::item:hover { 
    334334                background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1); 
    335                 border: 1px solid #bfcde4; 
     335                /* border: 1px solid #bfcde4; */ 
    336336            } 
    337337 
     
    371371        # Structure factor options model (TEMPORARY EXAMPLE) 
    372372 
    373         header_list = ["Property", "Value"] 
     373        header_list = ["Property", "Option", "Custom value"] 
    374374        num_cols = len(header_list) 
    375375        self._structure_model.setHorizontalHeaderLabels(header_list) 
     
    381381        ] 
    382382 
    383         # these are just an example 
    384383        param_vals = [ 
    385             "P(Q)S(Q)", 
     384            "P(Q)*S(Q)", 
    386385            "ER_mean_curvature", 
    387             "VR_something_or_other" 
     386            "VR_something" 
    388387        ] 
    389388 
     
    402401                item2.setText(val) 
    403402 
    404                 item_toplevel.appendRow([item1, item2]) 
     403                item3 = QtGui.QStandardItem() 
     404                item3.setEditable(False) 
     405 
     406                item_toplevel.appendRow([item1, item2, item3]) 
    405407 
    406408            row_toplevel = [item_toplevel] 
     
    412414            self._structure_model.appendRow(row_toplevel) 
    413415 
    414         self.lstStructureOptions.setModel(self._structure_model) 
    415         self.lstStructureOptions.setItemDelegate(StructureViewDelegate(self)) 
    416         self.lstStructureOptions.setAlternatingRowColors(True) 
    417         self.lstStructureOptions.setStyleSheet(stylesheet) 
     416        self._structure_model.itemChanged.connect( 
     417           self.onStructureViewItemChanged 
     418        ) 
     419 
     420        view = self.lstStructureOptions 
     421 
     422        view.setModel(self._structure_model) 
     423        view.setItemDelegate(StructureViewDelegate(self)) 
     424 
     425        view.setAlternatingRowColors(True) 
     426        view.setSizePolicy( 
     427            QtWidgets.QSizePolicy.MinimumExpanding, 
     428            QtWidgets.QSizePolicy.Expanding 
     429        ) 
     430        view.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) 
     431 
     432        # resize all columns 
     433        for col in range(view.header().count()): 
     434            view.resizeColumnToContents(col) 
     435 
     436        view.setStyleSheet(stylesheet) 
     437 
     438        header = view.header() 
     439        #header.setSectionResizeMode(QtWidgets.QHeaderView.Interactive) 
     440        header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents) 
     441        font = header.font() 
     442        font.setBold(True) 
     443        header.setFont(font) 
     444 
     445        view.expandAll() 
    418446 
    419447    def initializeCategoryCombo(self): 
     
    10601088                if func is not None: 
    10611089                    self.communicate.statusBarUpdateSignal.emit("Active constrain: "+func) 
     1090 
     1091    def onStructureViewItemChanged(self, item): 
     1092        """ 
     1093        Make changes as necessary when an item is modified in the structure 
     1094        factor options view. 
     1095        """ 
     1096        if -1 in [item.row(), item.column()]: 
     1097            # not a child item (ignore) 
     1098            return 
     1099 
     1100        # TODO: replace magic numbers, strings with stored params 
     1101        if item.column() == 1: 
     1102            custom_val_item = item.parent().child(item.row(), 2) 
     1103            if item.text() == "custom": 
     1104                custom_val_item.setEditable(True) 
     1105                custom_val_item.setText("type here") 
     1106            else: 
     1107                custom_val_item.setEditable(False) 
     1108                custom_val_item.setText("") 
    10621109 
    10631110    def replaceConstraintName(self, old_name, new_name=""): 
  • src/sas/qtgui/Perspectives/Fitting/ViewDelegate.py

    r6052c02 r085e3c9d  
    308308    def createEditor(self, parent, option, index): 
    309309        """ 
    310         Override generic createEditor -- certain elements have 
    311         combo boxes 
    312         """ 
     310        Override generic createEditor -- certain elements have combo boxes 
     311        """ 
     312        print("gotta create me an editor") 
    313313 
    314314        model = self.fittingWidget.structureView.model() 
    315315 
    316         if not index.parent(): 
     316        if index.parent(): 
    317317            # we only care about child items since we don't edit top-level 
    318318            # items in this view anyway 
    319             return super(QtWidgets.QStyledItemDelegate, self).createEditor( 
    320                 parent, option, index 
    321             ) 
    322  
    323         # navigate to the parameter name through the parent item (it'll be 
    324         # on the same row, but col. 0) 
    325         parent_item = model.itemFromIndex(index.parent()) 
    326         param_item = parent_item.child(index.row(), 0) 
    327  
    328         #item = model.itemFromIndex(index) 
    329         #print("item (row) [param]: \"{}\" ({}) [{}]".format( 
    330         #    item.text(), index.row(), param_item.text()) 
    331         #) 
    332  
    333         if param_item.text() in ["effective radius", "volume fraction"]: 
    334             # we want a combo box for these 
    335             return QtWidgets.QComboBox(parent) 
     319            print("the item has a parent") 
     320 
     321            if index.column() == 1: 
     322                print("the item's col. is 1") 
     323                # col. 1 contains elements that may be combo boxes 
     324 
     325                # navigate to the parameter name through the parent item (it'll 
     326                # be on the same row, but col. 0) 
     327                parent_item = model.itemFromIndex(index.parent()) 
     328                param_item = parent_item.child(index.row(), 0) 
     329 
     330                if param_item.text() == "mixture": 
     331                    print("gonna do a mixture combo box") 
     332                    # TODO: ONLY TEMPORARY EXAMPLE STUFF HERE RIGHT NOW 
     333                    cbox = QtWidgets.QComboBox(parent) 
     334                    cbox.addItems([ 
     335                        "P(Q)*S(Q)", 
     336                        "P(Q)+S(Q)", 
     337                        "custom" 
     338                    ]) 
     339                    return cbox 
     340 
     341                elif param_item.text() == "effective radius": 
     342                    print("gonna do an effective radius combo box") 
     343                    # TODO: ONLY TEMPORARY EXAMPLE STUFF HERE RIGHT NOW 
     344                    cbox = QtWidgets.QComboBox(parent) 
     345                    cbox.addItems([ 
     346                        "ER_mean_curvature", 
     347                        "ER_equivalent_sphere", 
     348                        "ER_maximum_radius", 
     349                        "ER_minimum_radius" 
     350                    ]) 
     351                    return cbox 
     352 
     353                elif param_item.text() == "volume fraction": 
     354                    print("gonna do a volume fraction combo box") 
     355                    # TODO: ONLY TEMPORARY EXAMPLE STUFF HERE RIGHT NOW 
     356                    cbox = QtWidgets.QComboBox(parent) 
     357                    cbox.addItems([ 
     358                        "VR_something", 
     359                        "VR_something_else", 
     360                        "VR_something_completely_different" 
     361                    ]) 
     362                    return cbox 
    336363 
    337364        # return default otherwise 
     365        print("let's do a normal thing instead") 
    338366        return super(StructureViewDelegate, self).createEditor( 
    339367            parent, option, index 
Note: See TracChangeset for help on using the changeset viewer.