diff --git a/qt/applications/workbench/workbench/plotting/figurewindow.py b/qt/applications/workbench/workbench/plotting/figurewindow.py index 1afe52c0d1434e1b44b778152a52ac51b89074da..11952fb67465bd91c0f9603de5eb5a57bc0a928e 100644 --- a/qt/applications/workbench/workbench/plotting/figurewindow.py +++ b/qt/applications/workbench/workbench/plotting/figurewindow.py @@ -58,3 +58,49 @@ class FigureWindow(QMainWindow): self.visibility_changed.emit() QMainWindow.showEvent(self, event) + def dragEnterEvent(self, event): + """ + Accepts drag events if the event contains text and no + urls. + + :param event: A QDragEnterEvent instance for the most + recent drag + """ + data = event.mimeData() + if data.hasText() and not data.hasUrls(): + event.acceptProposedAction() + + def dropEvent(self, event): + """ + If the event data contains a workspace reference then + request a plot of the workspace. + + :param event: A QDropEvent containing the MIME + data of the action + """ + self._plot_on_here(event.mimeData().text().split('\n')) + QMainWindow.dropEvent(self, event) + + # private api + + def _plot_on_here(self, names): + """ + Assume the list of strings refer to workspace names and they are to be plotted + on this figure. If the current figure contains an image plot then + a new image plot will replace the current image. If the current figure + contains a line plot then the user will be asked what should be plotted and this + will overplot onto the figure. If the first line of the plot + :param names: A list of workspace names + """ + if len(names) == 0: + return + # local import to avoid circular import with FigureManager + from workbench.plotting.functions import pcolormesh_from_names, plot_from_names + + fig = self._canvas.figure + fig_type = figure_type(fig) + if fig_type == FigureType.Image: + pcolormesh_from_names(names, fig=fig) + else: + plot_from_names(names, errors=(fig_type == FigureType.Errorbar), + overplot=True, fig=fig)