ISIS Reflectometry Plotting Tab Internals#
This document describes the implementation of the Plotting tab in the ISIS Reflectometry Interface. It is intended for developers changing the plotting workspace tree, plot output types, plot controls, or the connection to Mantid’s matplotlib plotting functions.
The implementation follows Model-View-Presenter (MVP):
the model owns plotting data and creates plot-ready workspaces;
the view owns Qt widgets and translates between Qt and view-facing data;
the presenter coordinates the model, view, batch interface, and plotting services.
The source is under
qt/scientific_interfaces/ISISReflectometry/GUI/Plotting. Shared plot
request and rendering code is under the adjacent GUI/Common directory.
Architecture#
The principal dependencies are:
BatchPresenter
|
v
PlottingPresenter
|
+-- owns --> PlottingWorkspaceTreePresenter --> IPlottingWorkspaceTreeView
|
+-- owns --> PlottingWorkspaceTree
|
+-- owns --> PlottingViewStateProvider --> PlotOutputTypeProperties
|
+-- uses --> IPlottingModel (PlottingModel)
|
+-- uses --> IPlotOptionsProvider (PlotOptionsProvider)
|
+-- uses --> IPlotter (Plotter)
|
+-- uses --> IActiveFigureMonitor (QtActiveFigureMonitor)
|
`-- updates --> IPlottingView (QtPlottingView)
|
`-- owns --> QtPlottingWorkspaceTreeView
Names in parentheses are the production implementations of the preceding
interfaces. PlottingViewStateProvider and
PlottingWorkspaceTree are concrete, presenter-owned collaborators and
therefore do not have interfaces.
PlottingWorkspaceTree is presenter-owned domain state rather than a Qt
tree model. The presenter converts this state into
PlottingWorkspaceTreeItemState objects through
PlottingViewStateProvider before passing it to the view. The provider
uses PlotOutputTypeProperties to determine selection eligibility and
muted state.
The tree presenter applies filtering and selection rules through
IPlottingWorkspaceTreeView; QtPlottingWorkspaceTreeView implements
that interface. It receives prepared labels and visual state, keeping tree
policy and Qt rendering separate.
The two providers perform different transformations:
PlottingViewStateProviderconverts model and presenter state into toolkit-independent state thatIPlottingViewcan display.PlotOptionsProviderconverts the user’s scientific output and layout selection into rendering options thatIPlottercan execute.
Key Terminology#
- Plot output type
The scientific result requested by the user: a reflectivity curve, detector map, spin asymmetry, or alignment plot. It is represented by
PlotOutputType.- Reduced workspace output type
The reduction-stage data represented by a plotting workspace tree item, such as
IvsQ,IvsLambda, orIvsQBinned. It is represented byReducedWorkspaceOutputTypeand is distinct from the requested plot output type.- Plotting workspace tree
The presenter-owned hierarchy of successful reduction groups, runs, ADS workspace groups, and workspaces that can supply data for plotting. A reduction group comes from the Runs table; an ADS workspace group is a Mantid
WorkspaceGroupcontaining workspaces.- Postprocessed reduction-group output
A stitched or otherwise group-level reduced workspace produced from multiple runs. It appears directly beneath a reduction group and can be excluded from output types for which it is not meaningful.
- Plot output selection
The user’s chosen
PlotOutputTypetogether with any output-specific detector-map or alignment axes. It is represented byPlotOutputSelection.- View state
Toolkit-independent labels, visibility, enabled state, muted state, and selection modes calculated by
PlottingViewStateProviderfor the Qt view to apply.- Plot options
The rendering configuration calculated by
PlotOptionsProvider, including layout, style, axis metadata, error bars, markers, and title. It is represented byPlotOptions.
Model Files#
The model directory contains data derived from completed reductions and the operations that prepare selected data for plotting.
model/PlottingWorkspace.h#
Defines the domain types shared by the plotting model and presenter:
PlottingWorkspaceTreeItemTypeidentifies reduction groups, runs, ADS workspace groups, and individual workspaces in the hierarchy.ReducedWorkspaceOutputTypeidentifies the reduced output represented by a workspace item, such asIvsQ,IvsLambda, orIvsQBinned.PlottingWorkspaceTreeItemis one node in the model-side hierarchy. It contains domain data only and has no selection or display state.PlottingWorkspacecontains the metadata needed to turn one reduced workspace into a requested plot output. This includes its ADS name, run numbers, containing workspace group, and period number.
model/IPlottingModel.h and model/PlottingModel.h/.cpp#
Defines:
IPlottingModel, the presenter-facing interface for obtaining plot-ready ADS workspace names; andPlottingModel, the implementation that either selects existing reduced workspaces or generates derived plotting workspaces.
PlottingModel::workspacesForPlotting dispatches according to the
selected PlotOutputType:
reflectivity curves use the selected reduced workspace names directly;
spin asymmetry creates a cached workspace from the up and down members of a polarization workspace group;
alignment creates a detector profile and optional fitted-peak workspaces from the corresponding raw time-of-flight workspace;
detector maps extract detector spectra, optionally convert the x axis to wavelength, and create the selected numeric y axis.
Generated workspaces have private ISIS Reflectometry prefixes and are reused if
they already exist in the ADS. The model uses run and period metadata from
PlottingWorkspace to find the matching raw workspace in TOF or
__TOF.
model/PlottingWorkspaceTree.h/.cpp#
PlottingWorkspaceTree owns the plotting workspace hierarchy and a
name-to-PlottingWorkspace lookup. rebuild derives both
collections from a RunsTable:
only successful reduction groups and rows are considered;
an output is added only when its named workspace still exists in the ADS;
ADS workspace groups are expanded into child workspace items;
run-number and period metadata is read from matrix workspaces;
empty runs and groups are omitted.
items exposes the hierarchy to the presenter.
plottingWorkspacesForNames resolves leaf names selected in the view back
to their model metadata. It preserves the order supplied by the view and ignores
names that are not in the current tree.
Presenter Files#
The presenter directory contains orchestration and all policy that determines what the user may select or plot.
presenter/IPlottingPresenter.h#
Defines IPlottingPresenter, the interface used by
BatchPresenter. It receives the parent batch presenter, processing
state changes, instrument changes, and updated RunsTable data. This
allows the Batch component to coordinate the tab without depending on
PlottingPresenter directly.
presenter/PlottingPresenter.h/.cpp#
Defines PlottingPresenter, which coordinates the complete tab workflow.
Its responsibilities are to:
subscribe to view notifications and active-figure changes;
enable or disable plot output selection while reduction or autoreduction runs;
rebuild the model-side plotting workspace tree when the runs table changes;
ask
PlottingViewStateProviderfor output-specific tree and control state;resolve the user’s selected workspace names;
request plot-ready workspaces from
IPlottingModel;request rendering options from
IPlotOptionsProvider;warn before creating five or more plot items; and
submit one or more
PlotRequestobjects toIPlotter.
An individual layout is submitted as one request per workspace. Overplot and tiled layouts are submitted as one request containing all selected workspaces.
presenter/PlottingWorkspaceTreePresenter.h/.cpp#
PlottingPresenter owns PlottingWorkspaceTreePresenter, which
owns the evaluated tree and filter state.
It:
prepares column labels as
std::stringvalues;applies regular-expression and reduced-output filters, retaining the last valid expression while incomplete syntax is edited;
propagates selection to visible, eligible descendants; and
resolves selected workspace names and ADS workspace-group counts, including complete groups required for spin asymmetry.
Filtering preserves hidden selections. The presenter uses row paths and
IPlottingWorkspaceTreeView, with no Qt types.
presenter/PlottingPresenterFactory.h#
Defines PlottingPresenterFactory, which owns the production
Plotter, PlotOptionsProvider, and PlottingModel, and
injects them into a new PlottingPresenter.
BatchPresenterFactory uses this factory when constructing a Batch tab.
presenter/PlotOutputTypeProperties.h/.cpp#
Defines:
PlotOutputTypeCapabilities, the flags describing support for overplotting, adding to an existing figure, postprocessed reduction-group outputs, and multi-plot selection based on ADS workspace groups;PlotOutputTypeProperties, the display name, accepted plotting workspace tree item types, accepted reduced workspace output types, and capabilities for onePlotOutputType; andplotOutputTypeProperties, the lookup that returns the configured properties for an output type.
The presenter and PlottingViewStateProvider query these properties
instead of containing output-type conditionals. This is the main extension
point for tree selection and action behavior when adding another plot output
type.
presenter/PlottingViewStateProvider.h/.cpp#
Defines PlottingViewStateProvider, the stateless provider for tab control
state and output-specific tree eligibility. For the plotting workspace tree, it
converts model-side PlottingWorkspaceTreeItem objects into view-facing
PlottingWorkspaceTreeItemState objects for the selected output type. It
evaluates whether each node:
is included by the output type;
is a postprocessed reduction-group output that must be excluded;
can be selected directly;
can contribute when an ancestor is selected; and
should be visually muted.
Keeping this policy in the presenter layer means that
PlottingWorkspaceTree knows nothing about GUI selection behavior.
The same provider creates state for the other parts of the Plotting tab:
plot output selector labels;
visibility of detector-map and alignment controls; and
enabled states for the Individual, Overplot, and Tiled actions, plus enabled and checked states for the vertical-tiling and add-to-existing options.
Action state depends on processing state, selected workspace and ADS workspace-group counts, output-type capabilities, and compatibility with the active Reflectometry figure. When adding to an existing figure, one selected item is enough for a tiled or overplot request because the figure already contains a plot.
presenter/QtActiveFigureMonitor.h/.cpp#
Defines:
IActiveFigureMonitor, the interface for notifications that the active matplotlib figure may have changed; andQtActiveFigureMonitor, which bridges active-order changes from Workbench’s global figure manager observer facility to Qt.
The presenter uses these notifications to refresh add-to-existing and overplot action state immediately when plots are opened, focused, or closed outside the tab.
View Files#
The view directory contains Qt widgets and simple data transferred from the presenter to the view.
view/IPlottingView.h#
Defines:
PlottingViewSubscriber, the user-action notifications implemented by the presenter; andIPlottingView, the state setters and user-input getters used by the presenter.
The interface uses standard C++ and plotting domain types. Qt is limited to the
plot parent QWidget required by the plotting service.
view/PlottingViewState.h#
Defines the toolkit-independent types produced by
PlottingViewStateProvider:
PlotOutputTypeViewItempairs an output type with the label displayed in the selector;PlotOutputControlsStatecontrols visibility of output-specific controls;PlotActionStatecontrols enabled and checked states for plotting actions;PlottingWorkspaceTreeSelectionModespecifies whether a plotting workspace tree row can be selected directly and through a parent, through a parent only, or neither; andPlottingWorkspaceTreeItemStateis one evaluated node containing its label, domain metadata, children, muted state, and selection mode.
These types let the presenter update related controls without exposing Qt types. The Qt view applies the decisions but does not recalculate them.
view/IPlottingWorkspaceTreeView.h#
Defines the toolkit-independent tree contract and its click/selection
notifications. Nodes are identified by row paths.
PlottingWorkspaceTreeViewItem contains prepared column labels, children,
and muted state. The view renders these values and applies visibility and
selection commands.
view/QtPlottingView.h/.cpp#
Defines QtPlottingView, the QWidget implementation of
IPlottingView used as the Plotting tab. It:
initialises controls defined in
PlottingWidget.ui;connects Qt signals to
PlottingViewSubscribernotifications;applies presenter-provided control state;
exposes the child tree view and reads filter, output, axes, and layout inputs;
owns
QtPlottingWorkspaceTreeView; anddisplays the confirmation dialog for large plot requests.
The view reports user actions but does not decide which actions or tree entries are valid.
view/QtPlottingWorkspaceTreeView.h/.cpp#
QtPlottingWorkspaceTreeView implements IPlottingWorkspaceTreeView
and owns the QStandardItemModel. It converts prepared strings to
QString, creates rows, and reuses palette-aware muted-row styling.
It translates Qt indexes and input events into row paths and presenter
notifications using viewportEvent. After handling a selection change,
it emits workspaceSelectionChanged, which QtPlottingView
forwards to the tab presenter without accessing the selection model.
view/PlottingWidget.ui#
Qt Designer definition for the Plotting tab. It declares the plotting workspace
tree; the IvsQBinned, IvsLambda, and IvsQ filters; the
Item-column regular-expression filter; the plot output selector; detector-map
and alignment axis controls; plotting buttons; vertical-tiling checkbox;
shared axis checkboxes; and add-to-existing checkbox.
Integration and Build Files#
Plotting/CMakeLists.txt#
Lists plotting sources, headers, the Qt MOC input, and
PlottingWidget.ui, then exports those lists to the enclosing
ISISReflectometry CMake configuration.
Batch/BatchPresenter.h/.cpp and BatchPresenterFactory.h#
These existing Batch files integrate the new component. The factory constructs
the plotting presenter from the plotting view. BatchPresenter owns it,
supplies the parent presenter, forwards instrument and processing state, and
calls updatePlottingWorkspaces whenever reduction state or relevant ADS
state changes.
Batch/IBatchView.h and Batch/QtBatchView.h/.cpp#
These existing view files expose and construct the QtPlottingView as one
of the Batch tab’s child tabs.
Test Files#
The focused test files are:
test/Plotting/PlottingWorkspaceTreeTest.h, covering hierarchy and metadata construction from runs-table and ADS state;test/Plotting/PlottingModelTest.h, covering workspace selection and generation for each output type;test/Plotting/PlottingViewStateProviderTest.h, covering plot action enablement and output-specific plotting workspace tree item state;test/Plotting/PlottingPresenterTest.h, covering Batch and view notifications, display-state updates, request construction, and plotting orchestration;test/Plotting/PlottingWorkspaceTreePresenterTest.h, covering prepared labels, filtering, and tree selection rules;test/Plotting/QtPlottingViewTest.h, covering Qt controls, tree rendering, input translation, and selection notifications;test/Common/PlotOptionsProviderTest.h, covering instrument output availability and output-to-options conversion; andtest/Common/PlotterTest.h, covering plot route selection and post-plotting behavior through the Python plotting boundary.
TestHelpers/PlottingTestHelpers.h provides readable equality matchers
and formatted diagnostics for plotting workspace tree expectations. The test
files are registered in test/CMakeLists.txt.
test/Plotting/PlottingWorkspaceTreeTestHelpers.h shares tree fixtures
between presenter and Qt integration tests.
End-to-End Operation#
Construction#
QtBatchViewconstructsQtPlottingView, which owns the tree widget.BatchPresenterFactoryasksPlottingPresenterFactoryto create the presenter for that view.PlottingPresenterFactoryinjects itsPlottingModel,PlotOptionsProvider, andPlotterinto the presenter. The presenter directly owns itsPlottingWorkspaceTree,PlottingViewStateProvider, andPlottingWorkspaceTreePresenter. The tree presenter uses the child view exposed byIPlottingView.The plotting presenter subscribes to the view and to active-figure changes through
QtActiveFigureMonitor.BatchPresentertakes ownership of the plotting presenter and passes itself as the parent coordinator.
Performing a reduction#
The user requests processing from the Runs tab. The Runs presenter forwards the request to
BatchPresenter, which coordinates the job manager and algorithm runner.When a row or group algorithm completes,
BatchPresenter::notifyAlgorithmCompleteupdates reduction state in the job manager and refreshes the Runs view.The Batch presenter calls
updatePlottingWorkspaces. The same refresh is made after an algorithm error, batch load, row or group edits, settings changes, workspace deletion or rename, and ADS clearing.updatePlottingWorkspacespasses the current modelRunsTabletoPlottingPresenter::notifyRunsTableChanged.
Updating the plotting workspace tree#
PlottingPresenterasksPlottingWorkspaceTreeto rebuild from the runs table.The tree walks reduction groups and rows that completed successfully and checks each recorded output against the ADS.
Existing ADS workspace groups are expanded. Each selectable leaf is recorded as a
PlottingWorkspacewith run, containing-group, and period metadata.The presenter reads the currently selected
PlotOutputTypeand asksPlottingViewStateProvider::plottingWorkspaceTreeItemStatesto evaluate the hierarchy usingPlotOutputTypeProperties.The presenter passes the resulting item states to its
PlottingWorkspaceTreePresenter, which prepares display labels and passes them to the tree widget.The widget rebuilds its
QStandardItemModel. The tree presenter then applies filters throughIPlottingWorkspaceTreeViewand expands the tree.
User interaction#
When the instrument changes, the presenter asks
IPlotOptionsProvider::availableTypesfor supported plot output types. It then asksPlottingViewStateProvider::outputTypeViewItemsto pair those domain values with labels for the plot output selector.Changing output type clears the current tree selection. The presenter then asks
PlottingViewStateProviderto rebuild the plotting workspace tree item states, output-control visibility, and plotting action state.The tree widget forwards row clicks to
PlottingWorkspaceTreePresenter. Parent selection propagates only to visible, eligible descendants. Workspace groups requiring complete selection resolve all required members when read.Changing a workspace output-type checkbox or the Item-column regular expression notifies
PlottingPresenter, which passes the filter inputs to its tree presenter. This reapplies visibility and expands the tree. Hidden rows retain their selection state.The widget’s
workspaceSelectionChangedsignal reachesPlottingPresenterthroughQtPlottingView. The presenter obtains selected leaf names and ADS workspace-group counts from its tree presenter and asksPlottingViewStateProvider::plotActionStatefor a newPlotActionState.The active-figure monitor causes the same action-state calculation when the current matplotlib figure changes. Add-to-existing is enabled only for a compatible Reflectometry figure and output type. Overplotting additionally requires Mantid to report that the active axes are compatible.
Creating the plot#
Clicking Individual, Overplot, or Tiled sends the corresponding
PlotLayoutnotification toPlottingPresenter.The presenter resolves selected leaf names through
PlottingWorkspaceTree::plottingWorkspacesForNamesand reads the current plot output and axis selections from the view.PlottingModel::workspacesForPlottingreturns existing reduced workspace names or creates the derived workspaces required for the selected output.The presenter passes the view’s
PlotOutputSelectionand requested layout toIPlotOptionsProvider::optionsFor. The productionPlotOptionsProviderreturns the axis, style, marker, error-bar, and title configuration asPlotOptions.For a request of five or more plot items, the view asks the user to confirm.
The presenter creates
PlotRequestobjects and callsIPlotter::plot. Individual plots are sent separately; overplot and tiled outputs are sent together.Plotterevaluates and dispatches the request. Colorfill requests use Mantid’spcolormesh; vertical or workspace-group tiling uses custom tiled axes; tiled additions create axes on the active Reflectometry figure; other line requests use the standard Mantid plotting function.Post-plot processing labels the correct axes, adds any configured marker, marks the figure as owned by this interface, and assigns the Reflectometry window as its transient parent.
The presenter refreshes active-figure compatibility so the controls reflect the newly created or updated plot, then asks
PlottingViewStateProviderfor refreshed action state.
Adding a Plot Output Type#
When extending the tab with another output type, update each responsibility at its existing boundary:
Add the scientific selection type and any required controls to
PlotOptions.hand the view.Add selection and action capabilities to
PlotOutputTypeProperties.cpp.Add plot-ready workspace creation or selection to
PlottingModel.cpp.Add rendering options and instrument availability to
PlotOptions.cppandPlotOptionsProvider.cpp.Add focused model, presenter/state-provider, options-provider, view, and plotter tests for behavior introduced at each boundary.