Skip to content
Snippets Groups Projects
Commit f6410479 authored by Stephen's avatar Stephen
Browse files

Handle multi selection plotting and fitting

parent 8010d239
No related branches found
No related tags found
No related merge requests found
......@@ -390,7 +390,6 @@ class FittingContext(object):
:return: A list of matching fits
"""
for fit in self.fit_list:
print("INPUT WORKSPACES", fit.input_workspaces, "WORKSPACE LIST", input_workspace_list)
if fit.input_workspaces == input_workspace_list:
return fit
......
......@@ -409,7 +409,7 @@ class PlotWidgetPresenter(HomeTabSubWidget):
workspace_list = self.workspace_finder.get_workspace_list_to_plot(self._view.if_raw(),
self._view.get_selected())
for ws in self._model.plotted_workspaces:
for ws in self._model.plotted_workspaces + self._model.plotted_fit_workspaces:
if ws not in workspace_list:
self._model.remove_workspace_from_plot(ws, self._view.get_axes())
......@@ -433,15 +433,19 @@ class PlotWidgetPresenter(HomeTabSubWidget):
for workspace in workspace_list
if self.context.group_pair_context.get_equivalent_group_pair(workspace)}
def handle_plot_single_sequential_fit(self, workspace_list):
def handle_plot_single_sequential_fit(self, selected_workspaces):
errors = self._view.plot_options.get_errors()
fitted_workspace_list = []
workspace_list = []
# get corresponding fit for the workspace_list, if it exists
fit = self.context.fitting_context.find_fit_for_input_workspace_list(workspace_list)
if fit is not None:
fitted_workspace_list = fit.output_workspace_names
else:
fitted_workspace_list = []
for _, workspaces in selected_workspaces.items():
workspace_list += workspaces
fit = self.context.fitting_context.find_fit_for_input_workspace_list(workspaces)
if fit is not None:
fitted_workspace_list += fit.output_workspace_names
else:
fitted_workspace_list += []
for ws in self._model.plotted_workspaces:
if ws not in workspace_list:
......
......@@ -12,7 +12,6 @@ from qtpy.QtCore import Qt, Signal
class SequentialTableWidget(QtWidgets.QTableWidget):
keyUpDownPressed = Signal()
keyEnterPressed = Signal()
focusOut = Signal()
......@@ -20,9 +19,20 @@ class SequentialTableWidget(QtWidgets.QTableWidget):
def __init__(self, parent):
super(SequentialTableWidget, self).__init__(parent)
self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.setFocusPolicy(Qt.StrongFocus)
# Only accept the key press event if we are not blocking signals e.g due to a fit
def keyPressEvent(self, event):
if not self.signalsBlocked():
super(SequentialTableWidget, self).keyPressEvent(event)
def keyReleaseEvent(self, event):
if event.isAutoRepeat(): # Ignore somebody holding down keys
if self.signalsBlocked():
event.ignore()
if event.isAutoRepeat(): # Ignore somebody holding down keys
return
if event.key() in (Qt.Key_Up, Qt.Key_Down):
self.keyUpDownPressed.emit()
......@@ -30,8 +40,14 @@ class SequentialTableWidget(QtWidgets.QTableWidget):
self.keyEnterPressed.emit()
def focusOutEvent(self, event):
self.clearSelection()
self.focusOut.emit()
# not sure this is the best solution
pass
#self.clearSelection()
# self.focusOut.emit()
def set_selection_to_last_row(self):
self.setCurrentIndex(self.model().index(self.model().rowCount()-1, 0))
self.cellClicked.emit(self.model().rowCount()-1, 0)
def set_slot_key_up_down_pressed(self, slot):
self.keyUpDownPressed.connect(slot)
......@@ -41,5 +57,3 @@ class SequentialTableWidget(QtWidgets.QTableWidget):
def set_slot_for_focus_out_event(self, slot):
self.focusOut.connect(slot)
......@@ -7,6 +7,8 @@
from mantidqt.utils.observer_pattern import GenericObserver, GenericObserverWithArgPassing
from Muon.GUI.Common.thread_model_wrapper import ThreadModelWrapperWithOutput
from Muon.GUI.Common import thread_model
from collections import defaultdict
import functools
......@@ -50,7 +52,7 @@ class SeqFittingTabPresenter(object):
ws_names = self.get_workspaces_for_entry_in_fit_table(i)
fit_function = self.model.get_ws_fit_function(ws_names)
parameter_values.append([fit_function.getParameterValue(parameters[j]) for j in
range(number_of_parameters)])
range(number_of_parameters)])
self.view.set_fit_table_function_parameters(parameters, parameter_values)
......@@ -120,7 +122,13 @@ class SeqFittingTabPresenter(object):
return
workspace_names = []
for i in range(self.view.get_number_of_entries()):
rows = self.view.get_selected_rows()
if len(rows) == 0: # if none selected, assume we are doing a sequential fit over everything
self.selected_rows = [i for i in range(self.view.get_number_of_entries())]
else:
self.selected_rows = rows
for i in self.selected_rows:
workspace_names += [self.get_workspaces_for_entry_in_fit_table(i)]
calculation_function = functools.partial(
......@@ -139,19 +147,24 @@ class SeqFittingTabPresenter(object):
return
fit_functions, fit_statuses, fit_chi_squareds = self.fitting_calculation_model.result
row_number = 0
for fit_function, fit_status, fit_chi_squared in zip(fit_functions, fit_statuses, fit_chi_squareds):
for fit_function, fit_status, fit_chi_squared, row in zip(fit_functions, fit_statuses, fit_chi_squareds,
self.selected_rows):
number_of_parameters = fit_function.nParams()
parameters = [fit_function.parameterName(i) for i in range(number_of_parameters)]
parameter_values = [fit_function.getParameterValue(parameters[i]) for i in
range(number_of_parameters)]
self.view.set_fit_function_parameters(row_number, parameter_values)
self.view.set_fit_quality(row_number, fit_status, fit_chi_squared)
row_number += 1
self.view.set_fit_function_parameters(row, parameter_values)
self.view.set_fit_quality(row, fit_status, fit_chi_squared)
self.view.seq_fit_button.setEnabled(True)
self.view.fit_selected_button.setEnabled(True)
self.view.fit_results_table.blockSignals(False)
# if no row is selected (select the last)
if len(self.view.get_selected_rows()) == 0:
print("got here got here got here")
self.view.set_table_selection_to_last_row()
def handle_updated_fit_parameter_in_table(self, row, column):
# make sure its a parameter we changed
if column < 3:
......@@ -161,10 +174,14 @@ class SeqFittingTabPresenter(object):
self.model.update_ws_fit_function_parameters(workspaces, params)
def handle_fit_selected_in_table(self):
# print workspaces that are part of the fit
row = self.view.get_selected_row()
workspace_names = self.get_workspaces_for_entry_in_fit_table(row)
self.selected_sequential_fit_notifier.notify_subscribers(workspace_names)
rows = self.view.get_selected_rows()
workspace_names = []
workspaces = defaultdict(list)
for i, row in enumerate(rows):
workspaces[i] = self.get_workspaces_for_entry_in_fit_table(row)
workspace_names += self.get_workspaces_for_entry_in_fit_table(row)
self.selected_sequential_fit_notifier.notify_subscribers(workspaces)
def handle_leaving_table_focus(self):
self.leaving_sequential_table_notifer.notify_subscribers()
......
......@@ -37,6 +37,9 @@ class SeqFittingTabView(QtWidgets.QWidget, ui_seq_fitting_tab):
self.fit_results_table.resizeColumnsToContents()
self.setup_default_fit_results_table()
self.plot_fit_results_checkbox.setVisible(False)
self.fit_selected_button.setVisible(False)
def warning_popup(self, message):
warning(message, parent=self)
......@@ -48,9 +51,6 @@ class SeqFittingTabView(QtWidgets.QWidget, ui_seq_fitting_tab):
self.fit_results_table.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
self.fit_results_table.blockSignals(False)
self.fit_results_table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.fit_results_table.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
def set_fit_table_workspaces(self, runs, group_and_pairs):
self.fit_results_table.blockSignals(True)
self.fit_results_table.clearContents()
......@@ -152,6 +152,16 @@ class SeqFittingTabView(QtWidgets.QWidget, ui_seq_fitting_tab):
def get_selected_row(self):
return self.fit_results_table.selectionModel().currentIndex().row()
def get_selected_rows(self):
rowSelectionModels = self.fit_results_table.selectionModel().selectedRows()
selected_rows = []
for rowSelectionModel in rowSelectionModels:
selected_rows += [rowSelectionModel.row()]
return selected_rows
def set_table_selection_to_last_row(self):
self.fit_results_table.set_selection_to_last_row()
def is_plotting_checked(self):
return self.plot_fit_results_checkbox.isChecked()
......
......@@ -30,7 +30,7 @@ class SeqFittingTabWidget(object):
self.seq_fitting_tab_presenter.handle_fit_selected_in_table)
self.seq_fitting_tab_view.setup_slot_for_key_enter_pressed(
self.seq_fitting_tab_presenter.handle_single_fit_requested)
self.seq_fitting_tab_presenter.handle_sequential_fit_requested)
self.seq_fitting_tab_view.setup_slot_for_focus_out_event(
self.seq_fitting_tab_presenter.handle_leaving_table_focus)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment