Skip to content

Commit

Permalink
Merge pull request #3169 from SasView/fitting_widget_refactor_6
Browse files Browse the repository at this point in the history
Fitting widget refactor
  • Loading branch information
jamescrake-merani authored Mar 3, 2025
2 parents 8932b5b + b4e70b3 commit cdd6779
Show file tree
Hide file tree
Showing 9 changed files with 1,379 additions and 1,242 deletions.
5 changes: 5 additions & 0 deletions src/sas/qtgui/Perspectives/Fitting/FittingLogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def __init__(self, data=None):
if data is not None:
self.data_is_loaded = True
self.setDataProperties()
self.model_parameters = None
self.kernel_module = None
# List of all shell-unique parameters
self.shell_names = []
self.current_shell_displayed = 0

@property
def data(self):
Expand Down
4 changes: 2 additions & 2 deletions src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def setData(self, data_item=None, is_batch=False, tab_index=None):
return
if numpy.any(available_tabs):
first_good_tab = available_tabs.index(True)
self.tabs[first_good_tab].data = data
self.tabs[first_good_tab].dataFromItems(data)
tab_name = str(self.tabText(first_good_tab))
self.updateFitDict(data, tab_name)
else:
Expand All @@ -455,7 +455,7 @@ def swapData(self, data):
msg = "Data in Batch Fitting cannot be swapped"
raise RuntimeError(msg)

self.currentTab.data = data
self.currentTab.dataFromItems(data)
tab_name = str(self.tabText(self.currentIndex()))
self.updateFitDict(data, tab_name)

Expand Down
44 changes: 44 additions & 0 deletions src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from PySide6 import QtCore
from PySide6 import QtGui
from PySide6 import QtWidgets

import numpy

Expand Down Expand Up @@ -35,6 +36,28 @@
error_tooltip = 'Error value for fitted parameter'
header_error_caption = 'Error'

class ToolTippedItemModel(QtGui.QStandardItemModel):
"""
Subclass from QStandardItemModel to allow displaying tooltips in
QTableView model.
"""
def __init__(self, parent=None):
QtGui.QStandardItemModel.__init__(self, parent)

def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
"""
Displays tooltip for each column's header
:param section:
:param orientation:
:param role:
:return:
"""
if role == QtCore.Qt.ToolTipRole:
if orientation == QtCore.Qt.Horizontal:
return str(self.header_tooltips[section])

return QtGui.QStandardItemModel.headerData(self, section, orientation, role)

def replaceShellName(param_name, value):
"""
Updates parameter name from <param_name>[n_shell] to <param_name>value
Expand Down Expand Up @@ -1010,3 +1033,24 @@ def checkConstraints(symtab, constraints):
else:
return []

def setTableProperties(table):
"""
Setting table properties
"""
# Table properties
table.verticalHeader().setVisible(False)
table.setAlternatingRowColors(True)
table.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Expanding)
table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
table.resizeColumnsToContents()

# Header
header = table.horizontalHeader()
header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
header.ResizeMode(QtWidgets.QHeaderView.Interactive)

# Qt5: the following 2 lines crash - figure out why!
# Resize column 0 and 7 to content
# header.setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)
# header.setSectionResizeMode(7, QtWidgets.QHeaderView.ResizeToContents)

Loading

0 comments on commit cdd6779

Please sign in to comment.