diff --git a/MantidPlot/CMakeLists.txt b/MantidPlot/CMakeLists.txt index 4903ff36886a69a6700cc90a8b2d7a9f6f8a4a1e..5662d5fb874524cf0feed00ceba335b173793931 100644 --- a/MantidPlot/CMakeLists.txt +++ b/MantidPlot/CMakeLists.txt @@ -82,7 +82,6 @@ set ( QTIPLOT_SRCS src/ApplicationWindow.cpp src/Note.cpp src/nrutil.cpp src/OpenProjectDialog.cpp - src/pixmaps.cpp src/Plot3DDialog.cpp src/Plot.cpp src/PlotCurve.cpp @@ -159,12 +158,12 @@ if ( CMAKE_COMPILER_IS_GNUCXX ) PROPERTIES COMPILE_FLAGS -Wno-cast-qual ) endif () -set ( MANTID_SRCS src/Mantid/AlgorithmMonitor.cpp +set ( MANTID_SRCS src/Mantid/AlgorithmDockWidget.cpp + src/Mantid/AlgorithmMonitor.cpp src/Mantid/AlgorithmHistoryWindow.cpp src/Mantid/ErrorBarSettings.cpp src/Mantid/FirstTimeSetup.cpp src/Mantid/FitParameterTie.cpp - src/Mantid/FlowLayout.cpp src/Mantid/IFunctionWrapper.cpp src/Mantid/ImportWorkspaceDlg.cpp src/Mantid/InputHistory.cpp @@ -174,7 +173,6 @@ set ( MANTID_SRCS src/Mantid/AlgorithmMonitor.cpp src/Mantid/MantidAbout.cpp src/Mantid/MantidApplication.cpp src/Mantid/MantidCurve.cpp - src/Mantid/MantidDock.cpp src/Mantid/MantidMatrix.cpp src/Mantid/MantidMatrixCurve.cpp src/Mantid/MantidMatrixDxExtensionHandler.cpp @@ -186,17 +184,14 @@ set ( MANTID_SRCS src/Mantid/AlgorithmMonitor.cpp src/Mantid/MantidMatrixDialog.cpp src/Mantid/MantidSampleLogDialog.cpp src/Mantid/MantidSampleMaterialDialog.cpp - src/Mantid/MantidSurfacePlotDialog.cpp src/Mantid/MantidGroupPlotGenerator.cpp src/Mantid/MantidUI.cpp src/Mantid/MantidTable.cpp - src/Mantid/MantidWSIndexDialog.cpp src/Mantid/PeakPickerTool.cpp src/Mantid/Preferences.cpp src/Mantid/RemoveErrorsDialog.cpp src/Mantid/SampleLogDialogBase.cpp src/Mantid/UserFitFunctionDialog.cpp - src/Mantid/WorkspaceIcons.cpp src/Mantid/InstrumentWidget/InstrumentWindow.cpp ) @@ -282,7 +277,6 @@ set ( QTIPLOT_HDRS src/ApplicationWindow.h src/Note.h src/nrutil.h src/OpenProjectDialog.h - src/pixmaps.h src/Plot3DDialog.h src/PlotCurve.h src/PlotDialog.h @@ -358,7 +352,6 @@ set ( MANTID_HDRS src/Mantid/AlgorithmMonitor.h src/Mantid/ErrorBarSettings.h src/Mantid/FirstTimeSetup.h src/Mantid/FitParameterTie.h - src/Mantid/FlowLayout.h src/Mantid/IFunctionWrapper.h src/Mantid/ImportWorkspaceDlg.h src/Mantid/IMantidMatrixExtensionHandler.h @@ -369,7 +362,6 @@ set ( MANTID_HDRS src/Mantid/AlgorithmMonitor.h src/Mantid/MantidAbout.h src/Mantid/MantidApplication.h src/Mantid/MantidCurve.h - src/Mantid/MantidDock.h src/Mantid/MantidMatrixCurve.h src/Mantid/MantidMatrixDxExtensionHandler.h src/Mantid/MantidMatrixExtensionRequest.h @@ -383,17 +375,14 @@ set ( MANTID_HDRS src/Mantid/AlgorithmMonitor.h src/Mantid/MantidMatrixFunction.h src/Mantid/MantidSampleLogDialog.h src/Mantid/MantidSampleMaterialDialog.h - src/Mantid/MantidSurfacePlotDialog.h src/Mantid/MantidGroupPlotGenerator.h src/Mantid/MantidUI.h - src/Mantid/MantidWSIndexDialog.h src/Mantid/MantidTable.h src/Mantid/PeakPickerTool.h src/Mantid/Preferences.h src/Mantid/RemoveErrorsDialog.h src/Mantid/SampleLogDialogBase.h src/Mantid/UserFitFunctionDialog.h - src/Mantid/WorkspaceIcons.h src/Mantid/InstrumentWidget/InstrumentWindow.h ) @@ -591,7 +580,8 @@ set ( QTIPLOT_MOC_FILES src/ApplicationWindow.h src/lib/3rdparty/qtcolorpicker/src/qtcolorpicker.h ) -set ( MANTID_MOC_FILES src/Mantid/AlgorithmMonitor.h +set ( MANTID_MOC_FILES src/Mantid/AlgorithmDockWidget.h + src/Mantid/AlgorithmMonitor.h src/Mantid/AlgorithmHistoryWindow.h src/Mantid/ErrorBarSettings.h src/Mantid/FirstTimeSetup.h @@ -603,7 +593,6 @@ set ( MANTID_MOC_FILES src/Mantid/AlgorithmMonitor.h src/Mantid/MantidAbout.h src/Mantid/MantidApplication.h src/Mantid/MantidCurve.h - src/Mantid/MantidDock.h src/Mantid/MantidMatrixCurve.h src/Mantid/MantidMDCurve.h src/Mantid/MantidMDCurveDialog.h @@ -613,9 +602,7 @@ set ( MANTID_MOC_FILES src/Mantid/AlgorithmMonitor.h src/Mantid/MantidMatrixModel.h src/Mantid/MantidSampleLogDialog.h src/Mantid/MantidSampleMaterialDialog.h - src/Mantid/MantidSurfacePlotDialog.h src/Mantid/MantidUI.h - src/Mantid/MantidWSIndexDialog.h src/Mantid/MantidTable.h src/Mantid/PeakPickerTool.h src/Mantid/RemoveErrorsDialog.h diff --git a/MantidPlot/pymantidplot/__init__.py b/MantidPlot/pymantidplot/__init__.py index 53c0133a6f5a1073cfa59f8fc12f3dfc4153df56..5b0bac7dab7f37b1421dcd65058bad00679247f6 100644 --- a/MantidPlot/pymantidplot/__init__.py +++ b/MantidPlot/pymantidplot/__init__.py @@ -301,6 +301,37 @@ def plotTableColumns(table, columns, type = -1): else: return graph +# Set some aliases for Layer enumerations so that old code will still work +Layer = _qti.Layer +Layer.Log10 = mantidqtpython.GraphOptions.Log10 +Layer.Linear = mantidqtpython.GraphOptions.Linear +Layer.Left = mantidqtpython.GraphOptions.Left +Layer.Right = mantidqtpython.GraphOptions.Right +Layer.Bottom = mantidqtpython.GraphOptions.Bottom +Layer.Top = mantidqtpython.GraphOptions.Top +Layer.Line = mantidqtpython.GraphOptions.Line +Layer.Scatter = mantidqtpython.GraphOptions.Scatter +Layer.LineSymbols = mantidqtpython.GraphOptions.LineSymbols +Layer.VerticalBars = mantidqtpython.GraphOptions.VerticalBars +Layer.Area = mantidqtpython.GraphOptions.Area +Layer.Pie = mantidqtpython.GraphOptions.Pie +Layer.VerticalDropLines = mantidqtpython.GraphOptions.VerticalDropLines +Layer.Spline = mantidqtpython.GraphOptions.Spline +Layer.HorizontalSteps = mantidqtpython.GraphOptions.HorizontalSteps +Layer.Histogram = mantidqtpython.GraphOptions.Histogram +Layer.HorizontalBars = mantidqtpython.GraphOptions.HorizontalBars +Layer.VectXYXY = mantidqtpython.GraphOptions.VectXYXY +Layer.ErrorBars = mantidqtpython.GraphOptions.ErrorBars +Layer.Box = mantidqtpython.GraphOptions.Box +Layer.VectXYAM = mantidqtpython.GraphOptions.VectXYAM +Layer.VerticalSteps = mantidqtpython.GraphOptions.VerticalSteps +Layer.ColorMap = mantidqtpython.GraphOptions.ColorMap +Layer.GrayScale = mantidqtpython.GraphOptions.GrayScale +Layer.ColorMapContour = mantidqtpython.GraphOptions.ColorMapContour +Layer.Contour = mantidqtpython.GraphOptions.Contour +Layer.Function = mantidqtpython.GraphOptions.Function +Layer.ImagePlot = mantidqtpython.GraphOptions.ImagePlot +Layer.User = mantidqtpython.GraphOptions.User # ---------------------------------------------------------------------------------------------------- # IPython auto-complete can't handle enumerations as defaults @@ -885,15 +916,6 @@ MantidUIImports = [ for name in MantidUIImports: globals()[name] = getattr(_qti.app.mantidUI, name) -# Set some aliases for Layer enumerations so that old code will still work -Layer = _qti.Layer -Layer.Log10 = mantidqtpython.GraphOptions.Log10 -Layer.Linear = mantidqtpython.GraphOptions.Linear -Layer.Left = mantidqtpython.GraphOptions.Left -Layer.Right = mantidqtpython.GraphOptions.Right -Layer.Bottom = mantidqtpython.GraphOptions.Bottom -Layer.Top = mantidqtpython.GraphOptions.Top - DistrFlag = mantidqtpython.MantidQt.DistributionFlag DistrFlag.DistrDefault = mantidqtpython.MantidQt.DistributionDefault DistrFlag.DistrTrue = mantidqtpython.MantidQt.DistributionTrue diff --git a/MantidPlot/src/ApplicationWindow.cpp b/MantidPlot/src/ApplicationWindow.cpp index f304aee942ea9ad8ee078e6fc76b863be69222bb..8e469c1f9ac39bbbaa666d475f6e2fc9cff1a9b3 100644 --- a/MantidPlot/src/ApplicationWindow.cpp +++ b/MantidPlot/src/ApplicationWindow.cpp @@ -30,7 +30,7 @@ * * ***************************************************************************/ #include "ApplicationWindow.h" -#include "pixmaps.h" +#include <MantidQtAPI/pixmaps.h> #include "CurvesDialog.h" #include "PlotDialog.h" #include "AxesDialog.h" @@ -828,7 +828,7 @@ void ApplicationWindow::initGlobalConstants() { d_print_cropmarks = false; d_synchronize_graph_scales = true; - defaultCurveStyle = static_cast<int>(Graph::Line); + defaultCurveStyle = static_cast<int>(GraphOptions::Line); defaultCurveLineWidth = 1; defaultSymbolSize = 7; @@ -1812,18 +1812,18 @@ void ApplicationWindow::plot3DTrajectory() { tr("You must select exactly one column for plotting!")); // Mantid } -void ApplicationWindow::plotBoxDiagram() { generate2DGraph(Graph::Box); } +void ApplicationWindow::plotBoxDiagram() { generate2DGraph(GraphOptions::Box); } void ApplicationWindow::plotVerticalBars() { - generate2DGraph(Graph::VerticalBars); + generate2DGraph(GraphOptions::VerticalBars); } void ApplicationWindow::plotHorizontalBars() { - generate2DGraph(Graph::HorizontalBars); + generate2DGraph(GraphOptions::HorizontalBars); } MultiLayer *ApplicationWindow::plotHistogram() { - return generate2DGraph(Graph::Histogram); + return generate2DGraph(GraphOptions::Histogram); } MultiLayer *ApplicationWindow::plotHistogram(Matrix *m) { @@ -1846,7 +1846,7 @@ MultiLayer *ApplicationWindow::plotHistogram(Matrix *m) { return g; } -void ApplicationWindow::plotArea() { generate2DGraph(Graph::Area); } +void ApplicationWindow::plotArea() { generate2DGraph(GraphOptions::Area); } void ApplicationWindow::plotPie() { Table *table = dynamic_cast<Table *>(activeWindow(TableWindow)); @@ -1862,31 +1862,31 @@ void ApplicationWindow::plotPie() { QStringList s = table->selectedColumns(); if (s.count() > 0) { - multilayerPlot(table, s, Graph::Pie, table->topSelectedRow(), + multilayerPlot(table, s, GraphOptions::Pie, table->topSelectedRow(), table->bottomSelectedRow()); } else QMessageBox::warning(this, tr("MantidPlot - Error"), tr("Please select a column to plot!")); // Mantid } -void ApplicationWindow::plotL() { generate2DGraph(Graph::Line); } +void ApplicationWindow::plotL() { generate2DGraph(GraphOptions::Line); } -void ApplicationWindow::plotP() { generate2DGraph(Graph::Scatter); } +void ApplicationWindow::plotP() { generate2DGraph(GraphOptions::Scatter); } -void ApplicationWindow::plotLP() { generate2DGraph(Graph::LineSymbols); } +void ApplicationWindow::plotLP() { generate2DGraph(GraphOptions::LineSymbols); } void ApplicationWindow::plotVerticalDropLines() { - generate2DGraph(Graph::VerticalDropLines); + generate2DGraph(GraphOptions::VerticalDropLines); } -void ApplicationWindow::plotSpline() { generate2DGraph(Graph::Spline); } +void ApplicationWindow::plotSpline() { generate2DGraph(GraphOptions::Spline); } void ApplicationWindow::plotVertSteps() { - generate2DGraph(Graph::VerticalSteps); + generate2DGraph(GraphOptions::VerticalSteps); } void ApplicationWindow::plotHorSteps() { - generate2DGraph(Graph::HorizontalSteps); + generate2DGraph(GraphOptions::HorizontalSteps); } void ApplicationWindow::plotVectXYXY() { @@ -1898,7 +1898,7 @@ void ApplicationWindow::plotVectXYXY() { QStringList s = table->selectedColumns(); if (s.count() == 4) { - multilayerPlot(table, s, Graph::VectXYXY, table->topSelectedRow(), + multilayerPlot(table, s, GraphOptions::VectXYXY, table->topSelectedRow(), table->bottomSelectedRow()); } else QMessageBox::warning( @@ -1915,7 +1915,7 @@ void ApplicationWindow::plotVectXYAM() { QStringList s = table->selectedColumns(); if (s.count() == 4) { - multilayerPlot(table, s, Graph::VectXYAM, table->topSelectedRow(), + multilayerPlot(table, s, GraphOptions::VectXYAM, table->topSelectedRow(), table->bottomSelectedRow()); } else QMessageBox::warning( @@ -2185,7 +2185,7 @@ void ApplicationWindow::remove3DMatrixPlots(Matrix *m) { QList<Graph *> layers = ml->layersList(); foreach (Graph *g, layers) { for (int i = 0; i < g->curves(); i++) { - if (g->curveType(i) == Graph::Histogram) { + if (g->curveType(i) == GraphOptions::Histogram) { QwtHistogram *h = dynamic_cast<QwtHistogram *>(g->plotItem(i)); if (h && h->matrix() == m) g->removeCurve(i); @@ -2223,7 +2223,7 @@ void ApplicationWindow::updateMatrixPlots(MdiSubWindow *window) { QList<Graph *> layers = ml->layersList(); foreach (Graph *g, layers) { for (int i = 0; i < g->curves(); i++) { - if (g->curveType(i) == Graph::Histogram) { + if (g->curveType(i) == GraphOptions::Histogram) { QwtHistogram *h = dynamic_cast<QwtHistogram *>(g->plotItem(i)); if (h && h->matrix() == m) h->loadData(); @@ -2713,15 +2713,16 @@ void ApplicationWindow::loadScriptRepo() { } void ApplicationWindow::polishGraph(Graph *g, int style) { - if (style == Graph::VerticalBars || style == Graph::HorizontalBars || - style == Graph::Histogram) { + if (style == GraphOptions::VerticalBars || + style == GraphOptions::HorizontalBars || + style == GraphOptions::Histogram) { QList<int> ticksList; int ticksStyle = ScaleDraw::Out; ticksList << ticksStyle << ticksStyle << ticksStyle << ticksStyle; g->setMajorTicksType(ticksList); g->setMinorTicksType(ticksList); } - if (style == Graph::HorizontalBars) { + if (style == GraphOptions::HorizontalBars) { g->setAxisTitle(QwtPlot::xBottom, tr("X Axis Title")); g->setAxisTitle(QwtPlot::yLeft, tr("Y Axis Title")); } @@ -4188,7 +4189,7 @@ ApplicationWindow *ApplicationWindow::plotFile(const QString &fn) { app->d_ASCII_import_comments, app->d_ASCII_comment_string, app->d_ASCII_import_read_only, Table::Overwrite, app->d_eol); t->setCaptionPolicy(MdiSubWindow::Both); - app->multilayerPlot(t, t->YColumns(), Graph::LineSymbols); + app->multilayerPlot(t, t->YColumns(), GraphOptions::LineSymbols); QApplication::restoreOverrideCursor(); return 0; } @@ -5106,7 +5107,8 @@ void ApplicationWindow::readSettings() { settings.endGroup(); // General settings.beginGroup("/Curves"); - defaultCurveStyle = settings.value("/Style", Graph::LineSymbols).toInt(); + defaultCurveStyle = + settings.value("/Style", GraphOptions::LineSymbols).toInt(); defaultCurveLineWidth = settings.value("/LineWidth", 1).toDouble(); defaultSymbolSize = settings.value("/SymbolSize", 3).toInt(); applyCurveStyleToMantid = settings.value("/ApplyMantid", true).toBool(); @@ -7073,7 +7075,7 @@ void ApplicationWindow::plotStackedLayers() { } void ApplicationWindow::plotStackedHistograms() { - multilayerPlot(1, -1, Graph::Histogram); + multilayerPlot(1, -1, GraphOptions::Histogram); } void ApplicationWindow::showMatrixDialog() { @@ -7288,10 +7290,10 @@ void ApplicationWindow::showCurveContextMenu(int curveKey) { curveMenu.addAction(actionHideCurve); actionHideCurve->setData(curveKey); - if (g->visibleCurves() > 1 && c->type() == Graph::Function) { + if (g->visibleCurves() > 1 && c->type() == GraphOptions::Function) { curveMenu.addAction(actionHideOtherCurves); actionHideOtherCurves->setData(curveKey); - } else if (c->type() != Graph::Function) { + } else if (c->type() != GraphOptions::Function) { if ((g->visibleCurves() - c->errorBarsList().count()) > 1) { curveMenu.addAction(actionHideOtherCurves); actionHideOtherCurves->setData(curveKey); @@ -7308,11 +7310,11 @@ void ApplicationWindow::showCurveContextMenu(int curveKey) { curveMenu.addAction(actionCopySelection); } - if (c->type() == Graph::Function) { + if (c->type() == GraphOptions::Function) { curveMenu.addSeparator(); curveMenu.addAction(actionEditFunction); actionEditFunction->setData(curveKey); - } else if (c->type() != Graph::ErrorBars) { + } else if (c->type() != GraphOptions::ErrorBars) { if (g->activeTool()) { if (g->activeTool()->rtti() == PlotToolInterface::Rtti_RangeSelector || g->activeTool()->rtti() == PlotToolInterface::Rtti_DataPicker) { @@ -7427,7 +7429,7 @@ void ApplicationWindow::showCurveWorksheet(Graph *g, int curveIndex) { if (sp && sp->matrix()) sp->matrix()->showMaximized(); - if (pc && pc->type() == Graph::Function) + if (pc && pc->type() == GraphOptions::Function) g->createTable(pc); if (!pc && !sp) @@ -7723,8 +7725,8 @@ void ApplicationWindow::showFitDialog() { else if (w->inherits("Table")) { Table *t = dynamic_cast<Table *>(w); if (t) - plot = - multilayerPlot(t, t->drawableColumnSelection(), Graph::LineSymbols); + plot = multilayerPlot(t, t->drawableColumnSelection(), + GraphOptions::LineSymbols); } if (!plot) @@ -13094,7 +13096,7 @@ Graph3D *ApplicationWindow::plot3DMatrix(Matrix *m, int style) { MultiLayer *ApplicationWindow::plotGrayScale(Matrix *m) { if (!m) { // Mantid - MultiLayer *plot = mantidUI->plotSpectrogram(Graph::GrayScale); + MultiLayer *plot = mantidUI->plotSpectrogram(GraphOptions::GrayScale); if (plot) return plot; m = dynamic_cast<Matrix *>(activeWindow(MatrixWindow)); @@ -13102,13 +13104,13 @@ MultiLayer *ApplicationWindow::plotGrayScale(Matrix *m) { return 0; } - return plotSpectrogram(m, Graph::GrayScale); + return plotSpectrogram(m, GraphOptions::GrayScale); } MultiLayer *ApplicationWindow::plotContour(Matrix *m) { if (!m) { // Mantid - MultiLayer *plot = mantidUI->plotSpectrogram(Graph::Contour); + MultiLayer *plot = mantidUI->plotSpectrogram(GraphOptions::Contour); if (plot) return plot; m = dynamic_cast<Matrix *>(activeWindow(MatrixWindow)); @@ -13116,13 +13118,13 @@ MultiLayer *ApplicationWindow::plotContour(Matrix *m) { return 0; } - return plotSpectrogram(m, Graph::Contour); + return plotSpectrogram(m, GraphOptions::Contour); } MultiLayer *ApplicationWindow::plotColorMap(Matrix *m) { if (!m) { // Mantid - MultiLayer *plot = mantidUI->plotSpectrogram(Graph::ColorMapContour); + MultiLayer *plot = mantidUI->plotSpectrogram(GraphOptions::ColorMapContour); if (plot) return plot; m = dynamic_cast<Matrix *>(activeWindow(MatrixWindow)); @@ -13130,7 +13132,7 @@ MultiLayer *ApplicationWindow::plotColorMap(Matrix *m) { return 0; } - return plotSpectrogram(m, Graph::ColorMapContour); + return plotSpectrogram(m, GraphOptions::ColorMapContour); } MultiLayer *ApplicationWindow::plotNoContourColorMap(Matrix *m) { @@ -13139,9 +13141,9 @@ MultiLayer *ApplicationWindow::plotNoContourColorMap(Matrix *m) { m = qobject_cast<Matrix *>(activeWindow(MatrixWindow)); } if (m) { - ml = plotSpectrogram(m, Graph::ColorMap); + ml = plotSpectrogram(m, GraphOptions::ColorMap); } else { - ml = mantidUI->plotSpectrogram(Graph::ColorMap); + ml = mantidUI->plotSpectrogram(GraphOptions::ColorMap); } if (!ml) { QApplication::restoreOverrideCursor(); @@ -13163,7 +13165,7 @@ MultiLayer *ApplicationWindow::plotImage(Matrix *m) { plot = g->activeGraph(); setPreferences(plot); - Spectrogram *s = plot->plotSpectrogram(m, Graph::GrayScale); + Spectrogram *s = plot->plotSpectrogram(m, GraphOptions::GrayScale); if (!s) { QApplication::restoreOverrideCursor(); return 0; @@ -13175,7 +13177,7 @@ MultiLayer *ApplicationWindow::plotImage(Matrix *m) { qMax(m->yStart(), m->yEnd()), 0.0, 5, 5, GraphOptions::Linear, true); } else { - g = mantidUI->plotSpectrogram(Graph::GrayScale); + g = mantidUI->plotSpectrogram(GraphOptions::GrayScale); if (!g) { QApplication::restoreOverrideCursor(); return 0; @@ -13197,10 +13199,10 @@ MultiLayer *ApplicationWindow::plotImage(Matrix *m) { } MultiLayer *ApplicationWindow::plotSpectrogram(Matrix *m, - Graph::CurveType type) { - if (type == Graph::ImagePlot) + GraphOptions::CurveType type) { + if (type == GraphOptions::ImagePlot) return plotImage(m); - else if (type == Graph::Histogram) + else if (type == GraphOptions::Histogram) return plotHistogram(m); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); @@ -13290,7 +13292,7 @@ void ApplicationWindow::deleteFitTables() { if (!curve) continue; - if (curve->type() != Graph::Function) { + if (curve->type() != GraphOptions::Function) { auto dc = dynamic_cast<DataCurve *>(c); if (!dc) continue; @@ -14855,7 +14857,7 @@ bool ApplicationWindow::validFor2DPlot(Table *table) { return true; } -MultiLayer *ApplicationWindow::generate2DGraph(Graph::CurveType type) { +MultiLayer *ApplicationWindow::generate2DGraph(GraphOptions::CurveType type) { MdiSubWindow *w = activeWindow(); if (!w) return 0; @@ -15828,7 +15830,7 @@ MultiLayer *ApplicationWindow::waterfallPlot(Table *t, g->setTitle(QString::null); g->setMargin(0); g->setFrame(0); - g->addCurves(t, list, Graph::Line); + g->addCurves(t, list, GraphOptions::Line); g->setWaterfallOffset(10, 20); initMultilayerPlot(ml); diff --git a/MantidPlot/src/ApplicationWindow.h b/MantidPlot/src/ApplicationWindow.h index 6da6a2c7b36780cefa89c0513c431cd78f9da469..6b83b835f6a73a5c455fca20b6116b7277c99eea 100644 --- a/MantidPlot/src/ApplicationWindow.h +++ b/MantidPlot/src/ApplicationWindow.h @@ -241,7 +241,7 @@ public slots: * @param fn :: is read as a data file with the default column separator (as *set by the user) * and inserted as a table into a new, empty project. - * This table is then plotted with the Graph::LineSymbols style. + * This table is then plotted with the GraphOptions::LineSymbols style. */ ApplicationWindow *plotFile(const QString &fn); @@ -313,7 +313,7 @@ public slots: void deleteLayer(); //! Creates a new spectrogram graph - MultiLayer *plotSpectrogram(Matrix *m, Graph::CurveType type); + MultiLayer *plotSpectrogram(Matrix *m, GraphOptions::CurveType type); MultiLayer *plotGrayScale(Matrix *m = 0); MultiLayer *plotContour(Matrix *m = 0); MultiLayer *plotColorMap(Matrix *m = 0); @@ -542,7 +542,7 @@ public slots: // error if not bool validFor2DPlot(Table *table); //! Generate a new 2D graph - MultiLayer *generate2DGraph(Graph::CurveType type); + MultiLayer *generate2DGraph(GraphOptions::CurveType type); //@} //! \name Image Analysis diff --git a/MantidPlot/src/AssociationsDialog.cpp b/MantidPlot/src/AssociationsDialog.cpp index f6f7448781abe478e5c6f75d75d965fab56ef003..6be133e2fa006a7febe3ec983cbfe0cea4c6e6b9 100644 --- a/MantidPlot/src/AssociationsDialog.cpp +++ b/MantidPlot/src/AssociationsDialog.cpp @@ -28,23 +28,23 @@ * * ***************************************************************************/ #include "AssociationsDialog.h" -#include "Table.h" +#include "BoxCurve.h" #include "FunctionCurve.h" #include "PlotCurve.h" -#include "BoxCurve.h" #include "QwtErrorPlotCurve.h" #include "QwtPieCurve.h" +#include "Table.h" #include "VectorCurve.h" +#include <QApplication> +#include <QEvent> +#include <QHeaderView> #include <QLabel> +#include <QLayout> #include <QListWidget> +#include <QMessageBox> #include <QPushButton> #include <QTableWidget> -#include <QHeaderView> -#include <QEvent> -#include <QLayout> -#include <QApplication> -#include <QMessageBox> AssociationsDialog::AssociationsDialog(Graph *g, Qt::WFlags fl) : QDialog(g, fl) { @@ -382,7 +382,7 @@ void AssociationsDialog::setGraph(Graph *g) { continue; auto dataCurve = dynamic_cast<const DataCurve *>(it); - if (dataCurve && dataCurve->type() != Graph::Function) { + if (dataCurve && dataCurve->type() != GraphOptions::Function) { QString s = dataCurve->plotAssociation(); if (auto table = dataCurve->table()) { QString tableName = table->objectName(); diff --git a/MantidPlot/src/BoxCurve.cpp b/MantidPlot/src/BoxCurve.cpp index 7defb084400dc0538eeb6fbf117460ef1c943d6a..3131653c9b12d1326080fa402be22520d23f666a 100644 --- a/MantidPlot/src/BoxCurve.cpp +++ b/MantidPlot/src/BoxCurve.cpp @@ -48,7 +48,7 @@ BoxCurve::BoxCurve(Table *t, const QString &name, int startRow, int endRow) w_coeff = 95.0; b_width = 80; - setType(Graph::Box); + setType(GraphOptions::Box); setStyle(QwtPlotCurve::UserCurve); } diff --git a/MantidPlot/src/ConfigDialog.cpp b/MantidPlot/src/ConfigDialog.cpp index f4ee8bb25c7ce63bec7cb773f8f50564a1dae39f..032912b7ef8db18881a14e6f7f740ee2fecf60b7 100644 --- a/MantidPlot/src/ConfigDialog.cpp +++ b/MantidPlot/src/ConfigDialog.cpp @@ -28,61 +28,62 @@ Description : Preferences dialog ***************************************************************************/ #include "ConfigDialog.h" #include "ApplicationWindow.h" -#include "MultiLayer.h" -#include "Graph.h" -#include "Matrix.h" -#include "ColorButton.h" #include "ColorBox.h" -#include "pixmaps.h" -#include "MantidQtMantidWidgets/DoubleSpinBox.h" -#include "SendToProgramDialog.h" +#include "ColorButton.h" +#include "Graph.h" #include "Mantid/MantidUI.h" +#include "MantidQtMantidWidgets/DoubleSpinBox.h" #include "MantidQtMantidWidgets/FitPropertyBrowser.h" +#include "Matrix.h" +#include "MultiLayer.h" +#include "SendToProgramDialog.h" +#include <MantidQtAPI/pixmaps.h> -#include <QLocale> -#include <QPushButton> -#include <QLabel> -#include <QLineEdit> -#include <QGridLayout> -#include <QGroupBox> -#include <QFont> -#include <QFontDialog> -#include <QTabWidget> -#include <QTreeWidget> -#include <QStackedWidget> -#include <QWidget> -#include <QComboBox> -#include <QSpinBox> -#include <QRadioButton> -#include <QStyleFactory> -#include <QRegExp> -#include <QMessageBox> -#include <QTranslator> #include <QApplication> +#include <QComboBox> #include <QDir> -#include <QPixmap> +#include <QFileDialog> +#include <QFont> +#include <QFontDialog> +#include <QFontMetrics> +#include <QGridLayout> +#include <QGroupBox> #include <QHBoxLayout> -#include <QVBoxLayout> +#include <QLabel> +#include <QLineEdit> #include <QListWidget> -#include <QFontMetrics> -#include <QFileDialog> -#include <QRegExp> +#include <QLocale> +#include <QMessageBox> #include <QMouseEvent> +#include <QPixmap> +#include <QPushButton> +#include <QRadioButton> +#include <QRegExp> +#include <QRegExp> +#include <QSpinBox> +#include <QStackedWidget> #include <QStringList> +#include <QStyleFactory> +#include <QTabWidget> +#include <QTranslator> +#include <QTreeWidget> +#include <QVBoxLayout> +#include <QWidget> -#include "MantidKernel/ConfigService.h" -#include "MantidKernel/FacilityInfo.h" +#include "MantidAPI/AlgorithmFactory.h" #include "MantidAPI/FunctionFactory.h" #include "MantidAPI/IBackgroundFunction.h" -#include "MantidAPI/AlgorithmFactory.h" #include "MantidAPI/IPeakFunction.h" -#include "MantidQtMantidWidgets/InstrumentSelector.h" +#include "MantidKernel/ConfigService.h" +#include "MantidKernel/FacilityInfo.h" #include "MantidQtAPI/MdConstants.h" -#include "MantidQtAPI/MdSettings.h" #include "MantidQtAPI/MdPlottingCmapsProvider.h" +#include "MantidQtAPI/MdSettings.h" +#include "MantidQtMantidWidgets/InstrumentSelector.h" #include <limits> +using namespace MantidQt::API; using Mantid::Kernel::ConfigService; ConfigDialog::ConfigDialog(QWidget *parent, Qt::WFlags fl) @@ -2338,25 +2339,25 @@ void ConfigDialog::languageChange() { boxCurveStyle->addItem(getQPixmap("hBars_xpm"), tr(" Horizontal Bars")); int style = app->defaultCurveStyle; - if (style == Graph::Line) + if (style == GraphOptions::Line) boxCurveStyle->setCurrentIndex(0); - else if (style == Graph::Scatter) + else if (style == GraphOptions::Scatter) boxCurveStyle->setCurrentIndex(1); - else if (style == Graph::LineSymbols) + else if (style == GraphOptions::LineSymbols) boxCurveStyle->setCurrentIndex(2); - else if (style == Graph::VerticalDropLines) + else if (style == GraphOptions::VerticalDropLines) boxCurveStyle->setCurrentIndex(3); - else if (style == Graph::Spline) + else if (style == GraphOptions::Spline) boxCurveStyle->setCurrentIndex(4); - else if (style == Graph::VerticalSteps) + else if (style == GraphOptions::VerticalSteps) boxCurveStyle->setCurrentIndex(5); - else if (style == Graph::HorizontalSteps) + else if (style == GraphOptions::HorizontalSteps) boxCurveStyle->setCurrentIndex(6); - else if (style == Graph::Area) + else if (style == GraphOptions::Area) boxCurveStyle->setCurrentIndex(7); - else if (style == Graph::VerticalBars) + else if (style == GraphOptions::VerticalBars) boxCurveStyle->setCurrentIndex(8); - else if (style == Graph::HorizontalBars) + else if (style == GraphOptions::HorizontalBars) boxCurveStyle->setCurrentIndex(9); // plots 3D @@ -2884,34 +2885,34 @@ int ConfigDialog::curveStyle() { int style = 0; switch (boxCurveStyle->currentIndex()) { case 0: - style = Graph::Line; + style = GraphOptions::Line; break; case 1: - style = Graph::Scatter; + style = GraphOptions::Scatter; break; case 2: - style = Graph::LineSymbols; + style = GraphOptions::LineSymbols; break; case 3: - style = Graph::VerticalDropLines; + style = GraphOptions::VerticalDropLines; break; case 4: - style = Graph::Spline; + style = GraphOptions::Spline; break; case 5: - style = Graph::VerticalSteps; + style = GraphOptions::VerticalSteps; break; case 6: - style = Graph::HorizontalSteps; + style = GraphOptions::HorizontalSteps; break; case 7: - style = Graph::Area; + style = GraphOptions::Area; break; case 8: - style = Graph::VerticalBars; + style = GraphOptions::VerticalBars; break; case 9: - style = Graph::HorizontalBars; + style = GraphOptions::HorizontalBars; break; } return style; diff --git a/MantidPlot/src/Convolution.cpp b/MantidPlot/src/Convolution.cpp index d4ee2fdcd43f3ac81e7857577fef6f5dc0a8deef..3ccf258bd310f02fe02cb8987f5c90784fb8731d 100644 --- a/MantidPlot/src/Convolution.cpp +++ b/MantidPlot/src/Convolution.cpp @@ -27,13 +27,13 @@ * * ***************************************************************************/ #include "Convolution.h" +#include "ColorBox.h" #include "MultiLayer.h" #include "Plot.h" #include "PlotCurve.h" -#include "ColorBox.h" -#include <QMessageBox> #include <QLocale> +#include <QMessageBox> #include <gsl/gsl_fft_halfcomplex.h> Convolution::Convolution(ApplicationWindow *parent, Table *t, @@ -169,7 +169,7 @@ void Convolution::addResultCurve() { new DataCurve(d_table, d_table->colName(cols), d_table->colName(cols2)); c->setData(x_temp.data(), d_x, d_n); // c->setData(x_temp, d_x, d_n); c->setPen(QPen(ColorBox::color(d_curveColorIndex), 1)); - d_output_graph->insertPlotItem(c, Graph::Line); + d_output_graph->insertPlotItem(c, GraphOptions::Line); d_output_graph->updatePlot(); } } diff --git a/MantidPlot/src/Correlation.cpp b/MantidPlot/src/Correlation.cpp index 74fb43d699a9009656b6ed7f59a9709a5f3b4276..7f57d71170cc054c973bbb541276abdd7737ef19 100644 --- a/MantidPlot/src/Correlation.cpp +++ b/MantidPlot/src/Correlation.cpp @@ -27,12 +27,12 @@ * * ***************************************************************************/ #include "Correlation.h" +#include "ColorBox.h" #include "MultiLayer.h" #include "Plot.h" #include "PlotCurve.h" -#include "ColorBox.h" -#include <QMessageBox> #include <QLocale> +#include <QMessageBox> #include <gsl/gsl_fft_halfcomplex.h> @@ -191,7 +191,7 @@ void Correlation::addResultCurve() { c->setData(x_temp.data(), y_temp.data(), d_n); // c->setData(x_temp, y_temp, d_n); c->setPen(QPen(ColorBox::color(d_curveColorIndex), 1)); - d_output_graph->insertPlotItem(c, Graph::Line); + d_output_graph->insertPlotItem(c, GraphOptions::Line); d_output_graph->updatePlot(); } } diff --git a/MantidPlot/src/CurvesDialog.cpp b/MantidPlot/src/CurvesDialog.cpp index 398d61b02c74cf230888293035effa1eb8bdf6c5..06883f8b5d29a919dde28101fd945b2a994a15ca 100644 --- a/MantidPlot/src/CurvesDialog.cpp +++ b/MantidPlot/src/CurvesDialog.cpp @@ -28,32 +28,34 @@ * * ***************************************************************************/ #include "CurvesDialog.h" -#include "Graph.h" -#include "Table.h" -#include "Matrix.h" -#include "FunctionCurve.h" -#include "PlotCurve.h" #include "ApplicationWindow.h" #include "Folder.h" -#include "pixmaps.h" +#include "FunctionCurve.h" +#include "Graph.h" #include "Mantid/MantidMatrixCurve.h" +#include "Matrix.h" +#include "PlotCurve.h" +#include "Table.h" +#include <MantidQtAPI/pixmaps.h> -#include <QPushButton> -#include <QLabel> -#include <QComboBox> #include <QCheckBox> #include <QCloseEvent> +#include <QComboBox> #include <QContextMenuEvent> +#include <QGroupBox> +#include <QKeySequence> +#include <QLabel> #include <QLayout> #include <QListWidget> -#include <QGroupBox> +#include <QMenu> #include <QPixmap> +#include <QPushButton> #include <QShortcut> -#include <QKeySequence> -#include <QMenu> #include <QMessageBox> +using namespace MantidQt::API; + CurvesDialog::CurvesDialog(ApplicationWindow *app, Graph *g, Qt::WFlags fl) : QDialog(g, fl), d_app(app), d_graph(g) { if (!app) { @@ -206,7 +208,7 @@ void CurvesDialog::showCurveBtn(int) { } PlotCurve *c = dynamic_cast<PlotCurve *>(it); - if (c && c->type() == Graph::Function) { + if (c && c->type() == GraphOptions::Function) { btnEditFunction->setEnabled(true); btnAssociations->setEnabled(false); btnRange->setEnabled(false); @@ -216,7 +218,7 @@ void CurvesDialog::showCurveBtn(int) { btnAssociations->setEnabled(true); btnRange->setEnabled(true); - if (c && c->type() == Graph::ErrorBars) + if (c && c->type() == GraphOptions::ErrorBars) btnRange->setEnabled(false); } @@ -289,25 +291,25 @@ void CurvesDialog::init() { } int style = d_app->defaultCurveStyle; - if (style == Graph::Line) + if (style == GraphOptions::Line) boxStyle->setCurrentIndex(0); - else if (style == Graph::Scatter) + else if (style == GraphOptions::Scatter) boxStyle->setCurrentIndex(1); - else if (style == Graph::LineSymbols) + else if (style == GraphOptions::LineSymbols) boxStyle->setCurrentIndex(2); - else if (style == Graph::VerticalDropLines) + else if (style == GraphOptions::VerticalDropLines) boxStyle->setCurrentIndex(3); - else if (style == Graph::Spline) + else if (style == GraphOptions::Spline) boxStyle->setCurrentIndex(4); - else if (style == Graph::VerticalSteps) + else if (style == GraphOptions::VerticalSteps) boxStyle->setCurrentIndex(5); - else if (style == Graph::HorizontalSteps) + else if (style == GraphOptions::HorizontalSteps) boxStyle->setCurrentIndex(6); - else if (style == Graph::Area) + else if (style == GraphOptions::Area) boxStyle->setCurrentIndex(7); - else if (style == Graph::VerticalBars) + else if (style == GraphOptions::VerticalBars) boxStyle->setCurrentIndex(8); - else if (style == Graph::HorizontalBars) + else if (style == GraphOptions::HorizontalBars) boxStyle->setCurrentIndex(9); QList<MdiSubWindow *> wList = d_app->windowsList(); @@ -372,13 +374,13 @@ bool CurvesDialog::addCurve(const QString &name) { switch (boxMatrixStyle->currentIndex()) { case 0: - d_graph->plotSpectrogram(m, Graph::ColorMap); + d_graph->plotSpectrogram(m, GraphOptions::ColorMap); break; case 1: - d_graph->plotSpectrogram(m, Graph::Contour); + d_graph->plotSpectrogram(m, GraphOptions::Contour); break; case 2: - d_graph->plotSpectrogram(m, Graph::GrayScale); + d_graph->plotSpectrogram(m, GraphOptions::GrayScale); break; case 3: d_graph->addHistogram(m); @@ -404,23 +406,25 @@ bool CurvesDialog::addCurve(const QString &name) { cl.sSize = d_app->defaultSymbolSize; cl.sType = symbol; - if (style == Graph::Line) + if (style == GraphOptions::Line) cl.sType = 0; - else if (style == Graph::VerticalBars || style == Graph::HorizontalBars) { + else if (style == GraphOptions::VerticalBars || + style == GraphOptions::HorizontalBars) { cl.filledArea = 1; cl.lCol = 0; cl.aCol = color; cl.sType = 0; - } else if (style == Graph::Area) { + } else if (style == GraphOptions::Area) { cl.filledArea = 1; cl.aCol = color; cl.sType = 0; - } else if (style == Graph::VerticalDropLines) + } else if (style == GraphOptions::VerticalDropLines) cl.connectType = 2; - else if (style == Graph::VerticalSteps || style == Graph::HorizontalSteps) { + else if (style == GraphOptions::VerticalSteps || + style == GraphOptions::HorizontalSteps) { cl.connectType = 3; cl.sType = 0; - } else if (style == Graph::Spline) + } else if (style == GraphOptions::Spline) cl.connectType = 5; d_graph->updateCurveLayout(c, &cl); @@ -493,34 +497,34 @@ int CurvesDialog::curveStyle() { int style = 0; switch (boxStyle->currentIndex()) { case 0: - style = Graph::Line; + style = GraphOptions::Line; break; case 1: - style = Graph::Scatter; + style = GraphOptions::Scatter; break; case 2: - style = Graph::LineSymbols; + style = GraphOptions::LineSymbols; break; case 3: - style = Graph::VerticalDropLines; + style = GraphOptions::VerticalDropLines; break; case 4: - style = Graph::Spline; + style = GraphOptions::Spline; break; case 5: - style = Graph::VerticalSteps; + style = GraphOptions::VerticalSteps; break; case 6: - style = Graph::HorizontalSteps; + style = GraphOptions::HorizontalSteps; break; case 7: - style = Graph::Area; + style = GraphOptions::Area; break; case 8: - style = Graph::VerticalBars; + style = GraphOptions::VerticalBars; break; case 9: - style = Graph::HorizontalBars; + style = GraphOptions::HorizontalBars; break; } return style; @@ -537,7 +541,7 @@ void CurvesDialog::showCurveRange(bool on) { continue; auto plotCurve = dynamic_cast<PlotCurve *>(it); - if (plotCurve && plotCurve->type() != Graph::Function) { + if (plotCurve && plotCurve->type() != GraphOptions::Function) { if (DataCurve *c = dynamic_cast<DataCurve *>(it)) { lst << c->title().text() + "[" + QString::number(c->startRow() + 1) + ":" + QString::number(c->endRow() + 1) + "]"; diff --git a/MantidPlot/src/DataPickerTool.cpp b/MantidPlot/src/DataPickerTool.cpp index fb8eeb12e16e747ecd74525b06cff6a3f925fd77..84f7eedbd223b3259af0f7f595b830d0bd3c9bc3 100644 --- a/MantidPlot/src/DataPickerTool.cpp +++ b/MantidPlot/src/DataPickerTool.cpp @@ -27,13 +27,13 @@ * * ***************************************************************************/ #include "DataPickerTool.h" +#include "ApplicationWindow.h" +#include "FunctionCurve.h" #include "Graph.h" #include "Plot.h" -#include "pixmaps.h" -#include "FunctionCurve.h" #include "PlotCurve.h" #include "QwtErrorPlotCurve.h" -#include "ApplicationWindow.h" +#include <MantidQtAPI/pixmaps.h> #include <QApplication> #include <QClipboard> @@ -46,6 +46,8 @@ #include <qwt_plot_picker.h> #include <qwt_symbol.h> +using namespace MantidQt::API; + DataPickerTool::DataPickerTool(Graph *graph, ApplicationWindow *app, Mode mode, const QObject *status_target, const char *status_slot) @@ -139,7 +141,7 @@ void DataPickerTool::setSelection(QwtPlotCurve *curve, int point_index) { QPoint(plot()->transform(xAxis(), d_selected_curve->x(d_selected_point)), plot()->transform(yAxis(), d_selected_curve->y(d_selected_point))); - if (plotCurve && plotCurve->type() == Graph::Function) { + if (plotCurve && plotCurve->type() == GraphOptions::Function) { QLocale locale = d_app->locale(); emit statusText( QString("%1[%2]: x=%3; y=%4") diff --git a/MantidPlot/src/Filter.cpp b/MantidPlot/src/Filter.cpp index 257b2e22e38cc923c579a5deafea0bf6ccba3a9b..b0ef2c829473bbf9c58a0abbf3d487f2d47be5ed 100644 --- a/MantidPlot/src/Filter.cpp +++ b/MantidPlot/src/Filter.cpp @@ -27,16 +27,16 @@ * * ***************************************************************************/ #include "Filter.h" -#include "LegendWidget.h" #include "ColorBox.h" -#include "Table.h" #include "FunctionCurve.h" -#include "PlotCurve.h" +#include "LegendWidget.h" #include "MultiLayer.h" +#include "PlotCurve.h" +#include "Table.h" #include <QApplication> -#include <QMessageBox> #include <QLocale> +#include <QMessageBox> #include <gsl/gsl_sort.h> @@ -359,7 +359,7 @@ QwtPlotCurve *Filter::addResultCurve(double *x, double *y) { if (!d_output_graph) d_output_graph = createOutputGraph()->activeGraph(); - d_output_graph->insertPlotItem(c, Graph::Line); + d_output_graph->insertPlotItem(c, GraphOptions::Line); d_output_graph->updatePlot(); } return dynamic_cast<QwtPlotCurve *>(c); diff --git a/MantidPlot/src/Fit.cpp b/MantidPlot/src/Fit.cpp index e40ea5e8ec8d7d73d97513bdd005dd8dde837a6b..2de8071432617be2cff9a5cfcc5b8dc5c1a41f8b 100644 --- a/MantidPlot/src/Fit.cpp +++ b/MantidPlot/src/Fit.cpp @@ -27,24 +27,24 @@ * * ***************************************************************************/ #include "Fit.h" -#include "fit_gsl.h" -#include "Table.h" -#include "Matrix.h" -#include "QwtErrorPlotCurve.h" -#include "FunctionCurve.h" #include "ColorBox.h" -#include "MultiLayer.h" #include "FitModelHandler.h" +#include "FunctionCurve.h" #include "Mantid/MantidCurve.h" +#include "Matrix.h" +#include "MultiLayer.h" +#include "QwtErrorPlotCurve.h" +#include "Table.h" +#include "fit_gsl.h" -#include <gsl/gsl_statistics.h> #include <gsl/gsl_blas.h> +#include <gsl/gsl_statistics.h> #include <gsl/gsl_version.h> #include <QApplication> -#include <QMessageBox> #include <QDateTime> #include <QLocale> +#include <QMessageBox> #include <QTextStream> Fit::Fit(ApplicationWindow *parent, Graph *g, const QString &name) @@ -235,7 +235,7 @@ void Fit::setDataCurve(int curve, double start, double end) { PlotCurve *plotCurve = dynamic_cast<PlotCurve *>(d_curve); DataCurve *dataCurve = dynamic_cast<DataCurve *>(d_curve); // if it is a DataCurve (coming from a Table) - if (plotCurve && dataCurve && plotCurve->type() != Graph::Function) { + if (plotCurve && dataCurve && plotCurve->type() != GraphOptions::Function) { QList<DataCurve *> lst = dataCurve->errorBarsList(); foreach (DataCurve *c, lst) { QwtErrorPlotCurve *er = dynamic_cast<QwtErrorPlotCurve *>(c); @@ -441,7 +441,7 @@ bool Fit::setWeightingData(WeightingMethod w, const QString &colName) { bool error = true; QwtErrorPlotCurve *er = 0; - if (dataCurve && dataCurve->type() != Graph::Function) { + if (dataCurve && dataCurve->type() != GraphOptions::Function) { QList<DataCurve *> lst = dataCurve->errorBarsList(); foreach (DataCurve *c, lst) { er = dynamic_cast<QwtErrorPlotCurve *>(c); @@ -722,7 +722,7 @@ void Fit::insertFitFunctionCurve(const QString &name, double *x, double *y, c->setData(x, y, d_points); c->setRange(d_x[0], d_x[d_n - 1]); c->setFormula(formula); - d_output_graph->insertPlotItem(c, Graph::Line); + d_output_graph->insertPlotItem(c, GraphOptions::Line); d_output_graph->addFitCurve(c); } diff --git a/MantidPlot/src/FitDialog.cpp b/MantidPlot/src/FitDialog.cpp index 9a1ba117e903e57557916d8d4ead3e7e1f3f9081..225ae7a19cd01d48428e05622155d3b66fe02a3d 100644 --- a/MantidPlot/src/FitDialog.cpp +++ b/MantidPlot/src/FitDialog.cpp @@ -27,46 +27,48 @@ * * ***************************************************************************/ #include "FitDialog.h" -#include "pixmaps.h" -#include "MyParser.h" #include "ApplicationWindow.h" #include "ColorBox.h" +#include "ExponentialFit.h" #include "Fit.h" +#include "LogisticFit.h" +#include "MantidQtMantidWidgets/DoubleSpinBox.h" +#include "Matrix.h" #include "MultiPeakFit.h" -#include "ExponentialFit.h" -#include "PolynomialFit.h" -#include "PluginFit.h" +#include "MyParser.h" #include "NonLinearFit.h" +#include "PluginFit.h" +#include "PolynomialFit.h" #include "SigmoidalFit.h" -#include "LogisticFit.h" -#include "Matrix.h" -#include "MantidQtMantidWidgets/DoubleSpinBox.h" +#include <MantidQtAPI/pixmaps.h> -#include <QListWidget> #include <QCloseEvent> -#include <QTableWidget> +#include <QComboBox> +#include <QFileDialog> +#include <QGroupBox> #include <QHeaderView> -#include <QLineEdit> +#include <QLabel> #include <QLayout> -#include <QSpinBox> +#include <QLibrary> +#include <QLineEdit> +#include <QListWidget> +#include <QLocale> +#include <QMessageBox> #include <QPushButton> -#include <QLabel> +#include <QRadioButton> +#include <QSpinBox> #include <QStackedWidget> +#include <QTableWidget> #include <QWidget> -#include <QMessageBox> -#include <QComboBox> #include <QWidgetList> -#include <QRadioButton> -#include <QFileDialog> -#include <QGroupBox> -#include <QLibrary> -#include <QLocale> #include <stdio.h> #include <qwt_plot_curve.h> #include "MantidQtAPI/FileDialogHandler.h" +using namespace MantidQt::API; + FitDialog::FitDialog(Graph *g, QWidget *parent, Qt::WFlags fl) : QDialog(parent, fl) { setObjectName("FitDialog"); diff --git a/MantidPlot/src/Folder.cpp b/MantidPlot/src/Folder.cpp index 80547bf97924d50013f981f24c0ee4792e3d0e86..850623f572e14cc91e619a00f740b732a612dc41 100644 --- a/MantidPlot/src/Folder.cpp +++ b/MantidPlot/src/Folder.cpp @@ -28,13 +28,14 @@ * Boston, MA 02110-1301 USA * * * ***************************************************************************/ -#include "ApplicationWindow.h" #include "Folder.h" -#include "pixmaps.h" - +#include "ApplicationWindow.h" +#include <MantidQtAPI/pixmaps.h> #include <QApplication> #include <QDateTime> +using namespace MantidQt::API; + Folder::Folder(Folder *parent, const QString &name) : QObject(parent), birthdate(QDateTime::currentDateTime().toString(Qt::LocalDate)), diff --git a/MantidPlot/src/FunctionCurve.cpp b/MantidPlot/src/FunctionCurve.cpp index 01d9304bfd0fd5f2c7eab07bb044a061a3001aef..46ff376e7223b96b31f2a9a393c4f2aa64a93e28 100644 --- a/MantidPlot/src/FunctionCurve.cpp +++ b/MantidPlot/src/FunctionCurve.cpp @@ -28,27 +28,27 @@ * * ***************************************************************************/ #include "FunctionCurve.h" +#include "MantidAPI/FunctionDomain1D.h" +#include "MantidAPI/FunctionFactory.h" +#include "MantidAPI/FunctionValues.h" #include "MyParser.h" -#include <MantidAPI/MatrixWorkspace.h> #include <MantidAPI/AnalysisDataService.h> #include <MantidAPI/IFunction.h> -#include "MantidAPI/FunctionFactory.h" -#include "MantidAPI/FunctionDomain1D.h" -#include "MantidAPI/FunctionValues.h" +#include <MantidAPI/MatrixWorkspace.h> #include <QMessageBox> FunctionCurve::FunctionCurve(const QString &name) : PlotCurve(name), d_function_type(Normal), d_variable("x"), d_formulas(), d_from(0.0), d_to(0.0), m_identifier(NULL) { - setType(Graph::Function); + setType(GraphOptions::Function); } FunctionCurve::FunctionCurve(const FunctionType &t, const QString &name) : PlotCurve(name), d_function_type(t), d_variable("x"), d_formulas(), d_from(0.0), d_to(0.0), m_identifier(NULL) { // d_variable = "x"; - setType(Graph::Function); + setType(GraphOptions::Function); } /** @@ -66,7 +66,7 @@ FunctionCurve::FunctionCurve(const Mantid::API::IFunction *fun, : PlotCurve(name), d_function_type(FunctionCurve::Normal), d_variable(""), // This indicates that mu::Parser is not used d_from(0), d_to(0), m_identifier(fun) { - setType(Graph::Function); + setType(GraphOptions::Function); // Save construction information in d_formulas d_formulas << "Mantid" << QString::fromStdString(fun->asString()) << wsName diff --git a/MantidPlot/src/Graph.cpp b/MantidPlot/src/Graph.cpp index 0e1958960ee51a8e86e9654f58111afccf107d46..15010d5b5fc86f025f337fdb90fb5fc1034ae284 100644 --- a/MantidPlot/src/Graph.cpp +++ b/MantidPlot/src/Graph.cpp @@ -31,41 +31,41 @@ #include "MantidQtAPI/qwt_compat.h" #include <QVarLengthArray> -#include "pixmaps.h" +#include "ApplicationWindow.h" +#include "ArrowMarker.h" +#include "BoxCurve.h" +#include "CanvasPicker.h" +#include "ColorBox.h" +#include "FunctionCurve.h" #include "Graph.h" #include "Grid.h" -#include "CanvasPicker.h" -#include "QwtErrorPlotCurve.h" -#include "LegendWidget.h" -#include "ArrowMarker.h" -#include "cursors.h" -#include "ScalePicker.h" -#include "TitlePicker.h" -#include "QwtPieCurve.h" #include "ImageMarker.h" +#include "LegendWidget.h" +#include "MantidQtAPI/ScaleEngine.h" +#include "PatternBox.h" +#include "PlotCurve.h" #include "QwtBarCurve.h" -#include "BoxCurve.h" +#include "QwtErrorPlotCurve.h" #include "QwtHistogram.h" -#include "VectorCurve.h" +#include "QwtPieCurve.h" +#include "RangeSelectorTool.h" #include "ScaleDraw.h" -#include "ColorBox.h" -#include "PatternBox.h" -#include "SymbolBox.h" -#include "FunctionCurve.h" -#include "Spectrogram.h" +#include "ScalePicker.h" #include "SelectionMoveResizer.h" -#include "RangeSelectorTool.h" -#include "PlotCurve.h" -#include "ApplicationWindow.h" -#include "MantidQtAPI/ScaleEngine.h" +#include "Spectrogram.h" +#include "SymbolBox.h" +#include "TitlePicker.h" +#include "VectorCurve.h" +#include "cursors.h" +#include <MantidQtAPI/pixmaps.h> -#include "MantidAPI/AnalysisDataService.h" -#include "Mantid/MantidMatrixCurve.h" +#include "Mantid/ErrorBarSettings.h" #include "Mantid/MantidMDCurve.h" +#include "Mantid/MantidMatrixCurve.h" +#include "MantidAPI/AnalysisDataService.h" #include "MantidQtAPI/PlotAxis.h" #include "MantidQtAPI/QwtRasterDataMD.h" #include "MantidQtAPI/QwtWorkspaceSpectrumData.h" -#include "Mantid/ErrorBarSettings.h" #include "MantidQtAPI/TSVSerialiser.h" @@ -77,16 +77,16 @@ #include <QBitmap> #include <QClipboard> #include <QCursor> +#include <QFileInfo> #include <QImage> +#include <QImageWriter> +#include <QLocale> +#include <QMenu> #include <QMessageBox> -#include <QPixmap> #include <QPainter> -#include <QMenu> -#include <QTextStream> -#include <QLocale> +#include <QPixmap> #include <QPrintDialog> -#include <QImageWriter> -#include <QFileInfo> +#include <QTextStream> #if QT_VERSION >= 0x040300 #include <QSvgGenerator> @@ -99,16 +99,19 @@ #if QWT_VERSION >= 0x050200 #include <qwt_plot_rescaler.h> #endif -#include <qwt_scale_widget.h> +#include <qwt_color_map.h> #include <qwt_scale_engine.h> +#include <qwt_scale_widget.h> #include <qwt_text_label.h> -#include <qwt_color_map.h> #include <climits> #include <math.h> -#include <stdlib.h> -#include <stdio.h> #include <stddef.h> +#include <stdio.h> +#include <stdlib.h> + +using namespace MantidQt::API; +using CurveType = GraphOptions::CurveType; // We can safely ignore warnings about assuming signed overflow does not occur // from qvector.h @@ -1398,7 +1401,7 @@ QStringList Graph::analysableCurvesList() { QList<int> keys = d_plot->curveKeys(); for (int i = 0; i < (int)keys.count(); i++) { QwtPlotCurve *c = d_plot->curve(keys[i]); - if (c && c_type[i] != ErrorBars) + if (c && c_type[i] != CurveType::ErrorBars) cList << c->title().text(); } return cList; @@ -1691,7 +1694,7 @@ void Graph::deselectCurves() { PlotCurve *c = dynamic_cast<PlotCurve *>(i); DataCurve *dc = dynamic_cast<DataCurve *>(i); if (c && dc && i->rtti() != QwtPlotItem::Rtti_PlotSpectrogram && - c->type() != Graph::Function && dc->hasSelectedLabels()) { + c->type() != GraphOptions::Function && dc->hasSelectedLabels()) { dc->setLabelsSelected(false); return; } @@ -1704,7 +1707,7 @@ DataCurve *Graph::selectedCurveLabels() { PlotCurve *c = dynamic_cast<PlotCurve *>(i); DataCurve *dc = dynamic_cast<DataCurve *>(i); if (dc && c && i->rtti() != QwtPlotItem::Rtti_PlotSpectrogram && - c->type() != Graph::Function && dc->hasSelectedLabels()) + c->type() != GraphOptions::Function && dc->hasSelectedLabels()) return dc; } return NULL; @@ -1776,7 +1779,7 @@ QString Graph::legendText() { for (int i = 0; i < n_curves; i++) { const QwtPlotCurve *c = curve(i); if (c && c->rtti() != QwtPlotItem::Rtti_PlotSpectrogram && - c_type[i] != ErrorBars) { + c_type[i] != GraphOptions::ErrorBars) { text += "\\l("; text += QString::number(i + 1); text += ")%("; @@ -1818,7 +1821,7 @@ void Graph::updateCurvesData(Table *w, const QString &yColName) { if (!c) continue; - if (c->type() == Function) + if (c->type() == GraphOptions::Function) continue; DataCurve *dc = dynamic_cast<DataCurve *>(it); @@ -1974,9 +1977,9 @@ QString Graph::saveCurveLayout(int index) { QwtPlotCurve *c = dynamic_cast<QwtPlotCurve *>(curve(index)); if (c) { s += QString::number(style) + "\t"; - if (style == Spline) + if (style == GraphOptions::Spline) s += "5\t"; - else if (style == VerticalSteps) + else if (style == GraphOptions::VerticalSteps) s += "6\t"; else s += QString::number(c->style()) + "\t"; @@ -1998,11 +2001,13 @@ QString Graph::saveCurveLayout(int index) { s += QString::number(ColorBox::colorIndex(c->brush().color())) + "\t"; s += QString::number(PatternBox::patternIndex(c->brush().style())) + "\t"; - if (style <= LineSymbols || style == Box) + if (style <= GraphOptions::LineSymbols || style == GraphOptions::Box) s += QString::number(symbol.pen().widthF()) + "\t"; } - if (style == VerticalBars || style == HorizontalBars || style == Histogram) { + if (style == GraphOptions::VerticalBars || + style == GraphOptions::HorizontalBars || + style == GraphOptions::Histogram) { QwtBarCurve *b = dynamic_cast<QwtBarCurve *>(c); if (b) { s += QString::number(b->gap()) + "\t"; @@ -2010,7 +2015,7 @@ QString Graph::saveCurveLayout(int index) { } } - if (style == Histogram) { + if (style == GraphOptions::Histogram) { QwtHistogram *h = dynamic_cast<QwtHistogram *>(c); if (h) { s += QString::number(h->autoBinning()) + "\t"; @@ -2018,7 +2023,8 @@ QString Graph::saveCurveLayout(int index) { s += QString::number(h->begin()) + "\t"; s += QString::number(h->end()) + "\t"; } - } else if (style == VectXYXY || style == VectXYAM) { + } else if (style == GraphOptions::VectXYXY || + style == GraphOptions::VectXYAM) { VectorCurve *v = dynamic_cast<VectorCurve *>(c); if (v) { s += v->color().name() + "\t"; @@ -2031,11 +2037,11 @@ QString Graph::saveCurveLayout(int index) { v->plotAssociation().split(",", QString::SkipEmptyParts); s += colsList[2].remove("(X)").remove("(A)") + "\t"; s += colsList[3].remove("(Y)").remove("(M)"); - if (style == VectXYAM) + if (style == GraphOptions::VectXYAM) s += "\t" + QString::number(v->position()); s += "\t"; } - } else if (style == Box) { + } else if (style == GraphOptions::Box) { BoxCurve *b = static_cast<BoxCurve *>(c); if (b) { s += QString::number(SymbolBox::symbolIndex(b->maxStyle())) + "\t"; @@ -2287,37 +2293,39 @@ CurveLayout Graph::initCurveLayout(int style, int curves) { cl.symCol = color; cl.fillCol = color; - if (style == Graph::Line) + if (style == GraphOptions::Line) cl.sType = 0; - else if (style == Graph::Scatter) + else if (style == GraphOptions::Scatter) cl.connectType = 0; - else if (style == Graph::VerticalDropLines) + else if (style == GraphOptions::VerticalDropLines) cl.connectType = 2; - else if (style == Graph::HorizontalSteps || style == Graph::VerticalSteps) { + else if (style == GraphOptions::HorizontalSteps || + style == GraphOptions::VerticalSteps) { cl.connectType = 3; cl.sType = 0; - } else if (style == Graph::Spline) + } else if (style == GraphOptions::Spline) cl.connectType = 5; - else if (curves && - (style == Graph::VerticalBars || style == Graph::HorizontalBars)) { + else if (curves && (style == GraphOptions::VerticalBars || + style == GraphOptions::HorizontalBars)) { cl.filledArea = 1; cl.lCol = 0; // black color pen cl.aCol = i + 1; cl.sType = 0; - if (c_type[i] == Graph::VerticalBars || style == Graph::HorizontalBars) { + if (c_type[i] == GraphOptions::VerticalBars || + style == GraphOptions::HorizontalBars) { QwtBarCurve *b = dynamic_cast<QwtBarCurve *>(curve(i)); if (b) { b->setGap(qRound(100 * (1 - 1.0 / (double)curves))); b->setOffset(-50 * (curves - 1) + i * 100); } } - } else if (style == Graph::Histogram) { + } else if (style == GraphOptions::Histogram) { cl.filledArea = 1; cl.lCol = i + 1; // start with red color pen cl.aCol = i + 1; // start with red fill color cl.aStyle = 4; cl.sType = 0; - } else if (style == Graph::Area) { + } else if (style == GraphOptions::Area) { cl.filledArea = 1; cl.aCol = color; cl.sType = 0; @@ -2349,14 +2357,14 @@ void Graph::updateCurveLayout(PlotCurve *c, const CurveLayout *cL) { QPen(ColorBox::color(cL->lCol), cL->lWidth, getPenStyle(cL->lStyle))); switch (c_type[index]) { - case Scatter: + case GraphOptions::Scatter: c->setStyle(QwtPlotCurve::NoCurve); break; - case Spline: + case GraphOptions::Spline: c->setStyle(QwtPlotCurve::Lines); c->setCurveAttribute(QwtPlotCurve::Fitted, true); break; - case VerticalSteps: + case GraphOptions::VerticalSteps: c->setStyle(QwtPlotCurve::Steps); c->setCurveAttribute(QwtPlotCurve::Inverted, true); break; @@ -2403,7 +2411,8 @@ QwtErrorPlotCurve *Graph::addErrorBars(const QString &yColName, Table *errTable, QList<int> keys = d_plot->curveKeys(); for (int i = 0; i < n_curves; i++) { DataCurve *c = dynamic_cast<DataCurve *>(d_plot->curve(keys[i])); - if (c && c->title().text() == yColName && c_type[i] != ErrorBars) { + if (c && c->title().text() == yColName && + c_type[i] != GraphOptions::ErrorBars) { return addErrorBars(c->xColumnName(), yColName, errTable, errColName, type, width, cap, color, through, minus, plus); } @@ -2424,7 +2433,7 @@ QwtErrorPlotCurve *Graph::addErrorBars(const QString &xColName, QwtErrorPlotCurve *er = new QwtErrorPlotCurve(type, errTable, errColName); c_type.resize(++n_curves); - c_type[n_curves - 1] = ErrorBars; + c_type[n_curves - 1] = GraphOptions::ErrorBars; c_keys.resize(n_curves); c_keys[n_curves - 1] = d_plot->insertCurve(er); @@ -2503,7 +2512,7 @@ QwtPieCurve *Graph::plotPie(Table *w, const QString &name, const QPen &pen, c_keys[n_curves - 1] = d_plot->insertCurve(pie); c_type.resize(n_curves); - c_type[n_curves - 1] = Pie; + c_type[n_curves - 1] = GraphOptions::Pie; pie->loadData(); pie->setPen(pen); @@ -2543,7 +2552,7 @@ QwtPieCurve *Graph::plotPie(Table *w, const QString &name, int startRow, c_keys[n_curves - 1] = d_plot->insertCurve(pie); c_type.resize(n_curves); - c_type[n_curves - 1] = Pie; + c_type[n_curves - 1] = GraphOptions::Pie; pie->loadData(); pie->initLabels(); @@ -2564,11 +2573,11 @@ void Graph::insertPlotItem(QwtPlotItem *i, int type) { bool Graph::addCurves(Table *w, const QStringList &names, int style, double lWidth, int sSize, int startRow, int endRow) { - if (style == Pie) + if (style == GraphOptions::Pie) plotPie(w, names[0], startRow, endRow); - else if (style == Box) + else if (style == GraphOptions::Box) plotBoxDiagram(w, names, startRow, endRow); - else if (style == VectXYXY || style == VectXYAM) + else if (style == GraphOptions::VectXYXY || style == GraphOptions::VectXYAM) plotVectorCurve(w, names, style, startRow, endRow); else { QStringList drawableNames; @@ -2778,13 +2787,13 @@ PlotCurve *Graph::insertCurve(Table *w, const QString &xColName, Y.resize(size); DataCurve *c = 0; - if (style == VerticalBars) { + if (style == GraphOptions::VerticalBars) { c = new QwtBarCurve(QwtBarCurve::Vertical, w, xColName, yColName, startRow, endRow); - } else if (style == HorizontalBars) { + } else if (style == GraphOptions::HorizontalBars) { c = new QwtBarCurve(QwtBarCurve::Horizontal, w, xColName, yColName, startRow, endRow); - } else if (style == Histogram) { + } else if (style == GraphOptions::Histogram) { c = new QwtHistogram(w, xColName, yColName, startRow, endRow); QwtHistogram *histo = dynamic_cast<QwtHistogram *>(c); if (histo) @@ -2799,13 +2808,13 @@ PlotCurve *Graph::insertCurve(Table *w, const QString &xColName, c->setPen(QPen(Qt::black, widthLine)); - if (style == HorizontalBars) + if (style == GraphOptions::HorizontalBars) c->setData(Y.data(), X.data(), size); - else if (style != Histogram) + else if (style != GraphOptions::Histogram) c->setData(X.data(), Y.data(), size); if (xColType == Table::Text) { - if (style == HorizontalBars) + if (style == GraphOptions::HorizontalBars) d_plot->setAxisScaleDraw(QwtPlot::yLeft, new ScaleDraw(d_plot, xLabels, xColName)); else @@ -2813,13 +2822,13 @@ PlotCurve *Graph::insertCurve(Table *w, const QString &xColName, new ScaleDraw(d_plot, xLabels, xColName)); } else if (xColType == Table::Time) { QString fmtInfo = time0.toString() + ";" + date_time_fmt; - if (style == HorizontalBars) + if (style == GraphOptions::HorizontalBars) setLabelsDateTimeFormat(QwtPlot::yLeft, ScaleDraw::Time, fmtInfo); else setLabelsDateTimeFormat(QwtPlot::xBottom, ScaleDraw::Time, fmtInfo); } else if (xColType == Table::Date) { QString fmtInfo = date0.toString(Qt::ISODate) + ";" + date_time_fmt; - if (style == HorizontalBars) + if (style == GraphOptions::HorizontalBars) setLabelsDateTimeFormat(QwtPlot::yLeft, ScaleDraw::Date, fmtInfo); else setLabelsDateTimeFormat(QwtPlot::xBottom, ScaleDraw::Date, fmtInfo); @@ -2834,7 +2843,8 @@ PlotCurve *Graph::insertCurve(Table *w, const QString &xColName, } PlotCurve *Graph::insertCurve(QString workspaceName, int index, bool err, - Graph::CurveType style, bool distribution) { + GraphOptions::CurveType style, + bool distribution) { return (new MantidMatrixCurve(workspaceName, this, index, MantidMatrixCurve::Spectrum, err, distribution, style)); @@ -2918,7 +2928,7 @@ QwtHistogram *Graph::addHistogram(Matrix *m) { c->loadData(); c_type.resize(++n_curves); - c_type[n_curves - 1] = Histogram; + c_type[n_curves - 1] = GraphOptions::Histogram; c_keys.resize(n_curves); c_keys[n_curves - 1] = d_plot->insertCurve(c); @@ -2941,7 +2951,7 @@ QwtHistogram *Graph::restoreHistogram(Matrix *m, const QStringList &l) { h->setVisible(l.last().toInt()); c_type.resize(++n_curves); - c_type[n_curves - 1] = Histogram; + c_type[n_curves - 1] = GraphOptions::Histogram; c_keys.resize(n_curves); c_keys[n_curves - 1] = d_plot->insertCurve(h); return h; @@ -2956,7 +2966,7 @@ VectorCurve *Graph::plotVectorCurve(Table *w, const QStringList &colList, endRow = w->numRows() - 1; VectorCurve *v = 0; - if (style == VectXYAM) + if (style == GraphOptions::VectXYAM) v = new VectorCurve(VectorCurve::XYAM, w, colList[0].toAscii().constData(), colList[1].toAscii().constData(), colList[2].toAscii().constData(), @@ -3110,7 +3120,7 @@ void Graph::removeCurves(const QString &s) { continue; PlotCurve *pc = dynamic_cast<PlotCurve *>(it); - if (!pc || pc->type() == Function) + if (!pc || pc->type() == GraphOptions::Function) continue; DataCurve *dc = dynamic_cast<DataCurve *>(it); @@ -3146,10 +3156,10 @@ void Graph::removeCurve(int index) { removeLegendItem(index); if (it->rtti() != QwtPlotItem::Rtti_PlotSpectrogram) { - if (c->type() == ErrorBars) { + if (c->type() == GraphOptions::ErrorBars) { QwtErrorPlotCurve *epc = dynamic_cast<QwtErrorPlotCurve *>(it); epc->detachFromMasterCurve(); - } else if (c->type() != Function && dc) { + } else if (c->type() != GraphOptions::Function && dc) { dc->clearErrorBars(); dc->clearLabels(); } @@ -3200,7 +3210,7 @@ void Graph::removeSpectrogram(Spectrogram *sp) { } void Graph::removeLegendItem(int index) { - if (!d_legend || c_type[index] == ErrorBars) + if (!d_legend || c_type[index] == GraphOptions::ErrorBars) return; if (isPiePlot()) { @@ -3253,7 +3263,7 @@ void Graph::removeLegendItem(int index) { void Graph::addLegendItem() { const int curveIndex = n_curves - 1; - if (c_type[curveIndex] == ErrorBars) + if (c_type[curveIndex] == GraphOptions::ErrorBars) return; if (d_legend) { QString text = d_legend->text(); @@ -3503,7 +3513,7 @@ QString Graph::generateFunctionName(const QString &name) { if (!c) continue; - if (c->type() == Function) + if (c->type() == GraphOptions::Function) lst << c->title().text(); } @@ -3528,7 +3538,7 @@ FunctionCurve *Graph::addFunction(const QStringList &formulas, double start, c->loadData(points); c_type.resize(++n_curves); - c_type[n_curves - 1] = Line; + c_type[n_curves - 1] = GraphOptions::Line; c_keys.resize(n_curves); c_keys[n_curves - 1] = d_plot->insertCurve(c); @@ -3742,7 +3752,7 @@ void Graph::scaleFonts(double factor) { foreach (QwtPlotItem *i, curves) { DataCurve *dc = dynamic_cast<DataCurve *>(i); if (dc && dc->rtti() != QwtPlotItem::Rtti_PlotSpectrogram && - dc->type() != Graph::Function && dc->hasLabels()) { + dc->type() != GraphOptions::Function && dc->hasLabels()) { QFont font = dc->labelsFont(); font.setPointSizeF(factor * font.pointSizeF()); dc->setLabelsFont(font); @@ -4122,11 +4132,11 @@ void Graph::copy(Graph *g) { c_type.resize(n_curves); c_type[i] = g->curveType(i); - if (style == Pie) { + if (style == GraphOptions::Pie) { c = new QwtPieCurve(cv->table(), cv->title().text(), cv->startRow(), cv->endRow()); c_keys[i] = d_plot->insertCurve(c); - } else if (style == Function) { + } else if (style == GraphOptions::Function) { c = new FunctionCurve(cv->title().text()); c_keys[i] = d_plot->insertCurve(c); FunctionCurve *fc = dynamic_cast<FunctionCurve *>(c); @@ -4135,7 +4145,8 @@ void Graph::copy(Graph *g) { if (fcCV) fc->copy(fcCV); } - } else if (style == VerticalBars || style == HorizontalBars) { + } else if (style == GraphOptions::VerticalBars || + style == GraphOptions::HorizontalBars) { QwtBarCurve *bc = dynamic_cast<QwtBarCurve *>(cv); if (bc) { c = new QwtBarCurve(bc->orientation(), cv->table(), cv->xColumnName(), @@ -4146,7 +4157,7 @@ void Graph::copy(Graph *g) { if (cvBC) bc->copy(cvBC); } - } else if (style == ErrorBars) { + } else if (style == GraphOptions::ErrorBars) { QwtErrorPlotCurve *er = dynamic_cast<QwtErrorPlotCurve *>(cv); if (er) { DataCurve *master_curve = masterCurve(er); @@ -4160,7 +4171,7 @@ void Graph::copy(Graph *g) { } } } - } else if (style == Histogram) { + } else if (style == GraphOptions::Histogram) { QwtHistogram *h = dynamic_cast<QwtHistogram *>(cv); if (h && h->matrix()) c = new QwtHistogram(h->matrix()); @@ -4173,9 +4184,10 @@ void Graph::copy(Graph *g) { QwtHistogram *cQH = dynamic_cast<QwtHistogram *>(c); if (cQH && h) cQH->copy(h); - } else if (style == VectXYXY || style == VectXYAM) { + } else if (style == GraphOptions::VectXYXY || + style == GraphOptions::VectXYAM) { VectorCurve::VectorStyle vs = VectorCurve::XYXY; - if (style == VectXYAM) + if (style == GraphOptions::VectXYAM) vs = VectorCurve::XYAM; VectorCurve *cvVC = dynamic_cast<VectorCurve *>(cv); if (cvVC) { @@ -4191,7 +4203,7 @@ void Graph::copy(Graph *g) { if (cVC) // it really should be, just did 'c = new VectorCurve(...' cVC->copy(cvVC); } - } else if (style == Box) { + } else if (style == GraphOptions::Box) { c = new BoxCurve(cv->table(), cv->title().text(), cv->startRow(), cv->endRow()); c_keys[i] = d_plot->insertCurve(c); @@ -4209,14 +4221,16 @@ void Graph::copy(Graph *g) { c_keys[i] = d_plot->insertCurve(c); } - if (c_type[i] != Box && c_type[i] != ErrorBars) { + if (c_type[i] != GraphOptions::Box && + c_type[i] != GraphOptions::ErrorBars) { if (c) { c->setData(x.data(), y.data(), n); - if (c->type() != Function && c->type() != Pie) { + if (c->type() != GraphOptions::Function && + c->type() != GraphOptions::Pie) { DataCurve *dc = dynamic_cast<DataCurve *>(c); if (dc) dc->clone(cv); - } else if (c->type() == Pie) { + } else if (c->type() == GraphOptions::Pie) { QwtPieCurve *cPie = dynamic_cast<QwtPieCurve *>(c); if (cPie) { QwtPieCurve *cvPie = dynamic_cast<QwtPieCurve *>(cv); @@ -4255,7 +4269,7 @@ void Graph::copy(Graph *g) { c_keys[i] = d_plot->insertCurve(sp); QwtScaleWidget *rightAxis = sp->plot()->axisWidget(QwtPlot::yRight); - if (g->curveType(i) == ColorMap) + if (g->curveType(i) == GraphOptions::ColorMap) rightAxis->setColorBarEnabled(true); else rightAxis->setColorBarEnabled(false); @@ -4384,7 +4398,7 @@ void Graph::plotBoxDiagram(Table *w, const QStringList &names, int startRow, c_keys.resize(++n_curves); c_keys[n_curves - 1] = d_plot->insertCurve(c); c_type.resize(n_curves); - c_type[n_curves - 1] = Box; + c_type[n_curves - 1] = GraphOptions::Box; c->setData(QwtSingleArrayData(double(j + 1), QwtArray<double>(), 0)); c->loadData(); @@ -4416,10 +4430,13 @@ void Graph::setCurveStyle(int index, int s) { return; int curve_type = c_type[index]; - if (curve_type == VerticalBars || curve_type == HorizontalBars || - curve_type == Histogram || curve_type == Pie || curve_type == Box || - curve_type == ErrorBars || curve_type == VectXYXY || - curve_type == VectXYAM) + if (curve_type == GraphOptions::VerticalBars || + curve_type == GraphOptions::HorizontalBars || + curve_type == GraphOptions::Histogram || + curve_type == GraphOptions::Pie || curve_type == GraphOptions::Box || + curve_type == GraphOptions::ErrorBars || + curve_type == GraphOptions::VectXYXY || + curve_type == GraphOptions::VectXYAM) return; // these are not line styles, but distinct curve types and this // function must not change the curve type @@ -4429,24 +4446,24 @@ void Graph::setCurveStyle(int index, int s) { if (s == 5) { // ancient spline style in Qwt 4.2.0 s = QwtPlotCurve::Lines; c->setCurveAttribute(QwtPlotCurve::Fitted, true); - c_type[index] = Spline; + c_type[index] = GraphOptions::Spline; } else if (s == 6) { // Vertical Steps s = QwtPlotCurve::Steps; c->setCurveAttribute(QwtPlotCurve::Inverted, false); - c_type[index] = VerticalSteps; + c_type[index] = GraphOptions::VerticalSteps; } else if (s == QwtPlotCurve::Steps) { // Horizontal Steps - c_type[index] = HorizontalSteps; + c_type[index] = GraphOptions::HorizontalSteps; c->setCurveAttribute(QwtPlotCurve::Inverted, true); } else if (s == QwtPlotCurve::Sticks) - c_type[index] = VerticalDropLines; + c_type[index] = GraphOptions::VerticalDropLines; else { // QwtPlotCurve::Lines || QwtPlotCurve::Dots if (c->symbol().style() == QwtSymbol::NoSymbol) - c_type[index] = Line; + c_type[index] = GraphOptions::Line; else if (c->symbol().style() != QwtSymbol::NoSymbol && (QwtPlotCurve::CurveStyle)s == QwtPlotCurve::NoCurve) - c_type[index] = Scatter; + c_type[index] = GraphOptions::Scatter; else - c_type[index] = LineSymbols; + c_type[index] = GraphOptions::LineSymbols; } c->setStyle((QwtPlotCurve::CurveStyle)s); @@ -4501,7 +4518,7 @@ BoxCurve *Graph::openBoxDiagram(Table *w, const QStringList &l, c_keys.resize(++n_curves); c_keys[n_curves - 1] = d_plot->insertCurve(c); c_type.resize(n_curves); - c_type[n_curves - 1] = Box; + c_type[n_curves - 1] = GraphOptions::Box; c->setData(QwtSingleArrayData(l[1].toDouble(), QwtArray<double>(), 0)); c->setData(QwtSingleArrayData(l[1].toDouble(), QwtArray<double>(), 0)); @@ -4568,8 +4585,9 @@ void Graph::guessUniqueCurveLayout(int &colorIndex, int &symbolIndex) { int curve_index = n_curves - 1; if (curve_index >= 0 && - c_type[curve_index] == - ErrorBars) { // find out the pen color of the master curve + c_type[curve_index] == GraphOptions::ErrorBars) { // find out the pen + // color of the master + // curve QwtErrorPlotCurve *er = dynamic_cast<QwtErrorPlotCurve *>(d_plot->curve(c_keys[curve_index])); if (!er) @@ -4615,7 +4633,8 @@ void Graph::deleteFitCurves() { } Spectrogram *Graph::plotSpectrogram(Matrix *m, CurveType type) { - if (type != GrayScale && type != ColorMap && type != Contour) + if (type != GraphOptions::GrayScale && type != GraphOptions::ColorMap && + type != GraphOptions::Contour) return 0; Spectrogram *d_spectrogram = new Spectrogram(m); @@ -4625,7 +4644,8 @@ Spectrogram *Graph::plotSpectrogram(Function2D *f, int nrows, int ncols, double left, double top, double width, double height, double minz, double maxz, CurveType type) { - if (type != GrayScale && type != ColorMap && type != Contour) + if (type != GraphOptions::GrayScale && type != GraphOptions::ColorMap && + type != GraphOptions::Contour) return 0; Spectrogram *d_spectrogram = @@ -4643,8 +4663,10 @@ Spectrogram *Graph::plotSpectrogram(Function2D *f, int nrows, int ncols, bool Graph::isSpectrogram() { #if QWT_VERSION >= 0x050200 for (int i = 0; i < c_type.count(); i++) { - if (!(c_type[i] == GrayScale || c_type[i] == ColorMap || - c_type[i] == Contour || c_type[i] == ColorMapContour)) + if (!(c_type[i] == GraphOptions::GrayScale || + c_type[i] == GraphOptions::ColorMap || + c_type[i] == GraphOptions::Contour || + c_type[i] == GraphOptions::ColorMapContour)) return false; } return true; @@ -4671,8 +4693,8 @@ Spectrogram *Graph::spectrogram() { Spectrogram *Graph::plotSpectrogram(Function2D *f, int nrows, int ncols, QwtDoubleRect bRect, double minz, double maxz, CurveType type) { - if (type != GrayScale && type != ColorMap && type != Contour && - type != ColorMapContour) + if (type != GraphOptions::GrayScale && type != GraphOptions::ColorMap && + type != GraphOptions::Contour && type != GraphOptions::ColorMapContour) return 0; Spectrogram *d_spectrogram = @@ -4683,18 +4705,18 @@ Spectrogram *Graph::plotSpectrogram(Function2D *f, int nrows, int ncols, Spectrogram *Graph::plotSpectrogram(Spectrogram *d_spectrogram, CurveType type) { - if (type == GrayScale) + if (type == GraphOptions::GrayScale) d_spectrogram->setGrayScale(); - else if (type == Contour) { + else if (type == GraphOptions::Contour) { d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ImageMode, false); d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ContourMode, true); - } else if (type == ColorMap) { + } else if (type == GraphOptions::ColorMap) { d_spectrogram->mutableColorMap().changeScaleType(GraphOptions::Linear); d_spectrogram->setDefaultColorMap(); d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ImageMode, true); d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ContourMode, false); - } else if (type == ColorMapContour) { + } else if (type == GraphOptions::ColorMapContour) { d_spectrogram->mutableColorMap().changeScaleType(GraphOptions::Linear); d_spectrogram->setDefaultColorMap(); d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ImageMode, true); @@ -4709,13 +4731,13 @@ Spectrogram *Graph::plotSpectrogram(Spectrogram *d_spectrogram, QwtScaleWidget *rightAxis = d_plot->axisWidget(QwtPlot::yRight); if (!rightAxis) return 0; - rightAxis->setColorBarEnabled(type != Contour); - d_plot->enableAxis(QwtPlot::yRight, type != Contour); + rightAxis->setColorBarEnabled(type != GraphOptions::Contour); + d_plot->enableAxis(QwtPlot::yRight, type != GraphOptions::Contour); // Ensure that labels are shown on color scale axis enableAxisLabels(QwtPlot::yRight); // d_spectrogram->setDefaultColorMap(); - if (type == GrayScale) + if (type == GraphOptions::GrayScale) rightAxis->setColorBarEnabled( false); // rightAxis->setColorMap(d_spectrogram->data().range(),d_spectrogram->colorMap()); else @@ -4893,7 +4915,8 @@ void Graph::updateCurveNames(const QString &oldName, const QString &newName, continue; DataCurve *c = dynamic_cast<DataCurve *>(it); - if (c && c->type() != Function && c->plotAssociation().contains(oldName)) + if (c && c->type() != GraphOptions::Function && + c->plotAssociation().contains(oldName)) c->updateColumnNames(oldName, newName, updateTableName); } d_plot->replot(); @@ -4973,7 +4996,7 @@ void Graph::setGrayScale() { } PlotCurve *c = dynamic_cast<PlotCurve *>(it); - if (!c || c->type() == ErrorBars) + if (!c || c->type() == GraphOptions::ErrorBars) continue; QPen pen = c->pen(); @@ -5010,7 +5033,7 @@ void Graph::setGrayScale() { continue; PlotCurve *c = dynamic_cast<PlotCurve *>(it); - if (c && c->type() == ErrorBars) { + if (c && c->type() == GraphOptions::ErrorBars) { // QtiPlot: ErrorBarsCurve *er = (ErrorBarsCurve *) it; QwtErrorPlotCurve *er = dynamic_cast<QwtErrorPlotCurve *>(it); if (!er) @@ -5044,7 +5067,7 @@ void Graph::setIndexedColors() { continue; PlotCurve *c = dynamic_cast<PlotCurve *>(it); - if (!c || c->type() == ErrorBars) + if (!c || c->type() == GraphOptions::ErrorBars) continue; QPen pen = c->pen(); @@ -5076,7 +5099,7 @@ void Graph::setIndexedColors() { continue; PlotCurve *c = dynamic_cast<PlotCurve *>(it); - if (c && c->type() == ErrorBars) { + if (c && c->type() == GraphOptions::ErrorBars) { // QtiPlot: ErrorBarsCurve *er = (ErrorBarsCurve *) it; QwtErrorPlotCurve *er = dynamic_cast<QwtErrorPlotCurve *>(it); if (!er) @@ -5101,7 +5124,7 @@ DataCurve *Graph::masterCurve(QwtErrorPlotCurve *er) { if (it->rtti() == QwtPlotItem::Rtti_PlotSpectrogram) continue; PlotCurve *pc = dynamic_cast<PlotCurve *>(it); - if (!pc || pc->type() == Function) + if (!pc || pc->type() == GraphOptions::Function) continue; DataCurve *dc = dynamic_cast<DataCurve *>(it); @@ -5124,7 +5147,7 @@ DataCurve *Graph::masterCurve(const QString &xColName, if (it->rtti() == QwtPlotItem::Rtti_PlotSpectrogram) continue; PlotCurve *pc = dynamic_cast<PlotCurve *>(it); - if (!pc || pc->type() == Function) + if (!pc || pc->type() == GraphOptions::Function) continue; DataCurve *dc = dynamic_cast<DataCurve *>(it); @@ -5267,7 +5290,7 @@ void Graph::setCurrentFont(const QFont &f) { DataCurve *dc = dynamic_cast<DataCurve *>(i); PlotCurve *pc = dynamic_cast<PlotCurve *>(i); if (pc && dc && i->rtti() != QwtPlotItem::Rtti_PlotSpectrogram && - pc->type() != Graph::Function) { + pc->type() != GraphOptions::Function) { if (dc->hasSelectedLabels()) { dc->setLabelsFont(f); d_plot->replot(); @@ -6015,7 +6038,8 @@ void Graph::loadFromProject(const std::string &lines, ApplicationWindow *app, Table *table = app->table(tableName); if (table) { PlotCurve *c = NULL; - if (plotType == Graph::VectXYXY || plotType == Graph::VectXYAM) { + if (plotType == GraphOptions::VectXYXY || + plotType == GraphOptions::VectXYAM) { QStringList colsList; colsList << curveValues[1] << curveValues[2]; colsList << curveValues[20] << curveValues[21]; @@ -6026,7 +6050,7 @@ void Graph::loadFromProject(const std::string &lines, ApplicationWindow *app, c = reinterpret_cast<PlotCurve *>( plotVectorCurve(table, colsList, plotType, startRow, endRow)); - if (plotType == Graph::VectXYXY) { + if (plotType == GraphOptions::VectXYXY) { updateVectorsLayout( curveID, curveValues[15], curveValues[16].toDouble(), curveValues[17].toInt(), curveValues[18].toInt(), @@ -6037,7 +6061,7 @@ void Graph::loadFromProject(const std::string &lines, ApplicationWindow *app, curveValues[17].toInt(), curveValues[18].toInt(), curveValues[19].toInt(), curveValues[22].toInt()); } - } else if (plotType == Graph::Box) { + } else if (plotType == GraphOptions::Box) { c = reinterpret_cast<PlotCurve *>( openBoxDiagram(table, curveValues, fileVersion)); } else { @@ -6048,7 +6072,7 @@ void Graph::loadFromProject(const std::string &lines, ApplicationWindow *app, startRow, endRow)); } - if (plotType == Graph::Histogram) { + if (plotType == GraphOptions::Histogram) { QwtHistogram *h = dynamic_cast<QwtHistogram *>(curve(curveID)); if (h) { h->setBinning(curveValues[17].toInt(), curveValues[18].toDouble(), @@ -6058,8 +6082,9 @@ void Graph::loadFromProject(const std::string &lines, ApplicationWindow *app, } } - if (plotType == Graph::VerticalBars || - plotType == Graph::HorizontalBars || plotType == Graph::Histogram) { + if (plotType == GraphOptions::VerticalBars || + plotType == GraphOptions::HorizontalBars || + plotType == GraphOptions::Histogram) { setBarsGap(curveID, curveValues[15].toInt(), curveValues[16].toInt()); } @@ -6070,7 +6095,7 @@ void Graph::loadFromProject(const std::string &lines, ApplicationWindow *app, curveValues[curveValues.count() - 4].toInt()); c->setVisible(curveValues.last().toInt()); } - } else if (plotType == Graph::Histogram) { + } else if (plotType == GraphOptions::Histogram) { Matrix *m = app->matrix(tableName); QwtHistogram *h = restoreHistogram(m, curveValues); updateCurveLayout(h, &cl); @@ -6114,11 +6139,11 @@ void Graph::loadFromProject(const std::string &lines, ApplicationWindow *app, cl.aCol = aCol; cl.aStyle = aStyle; - if (curveStyle == Graph::Box) { + if (curveStyle == GraphOptions::Box) { float penWidth; tsv >> penWidth; cl.penWidth = penWidth; - } else if (curveStyle <= Graph::LineSymbols) { + } else if (curveStyle <= GraphOptions::LineSymbols) { float penWidth; tsv >> penWidth; cl.penWidth = penWidth; @@ -6200,7 +6225,7 @@ void Graph::loadFromProject(const std::string &lines, ApplicationWindow *app, if (!s) continue; - plotSpectrogram(s, Graph::ColorMap); + plotSpectrogram(s, GraphOptions::ColorMap); s->loadFromProject(*it); curveID++; } @@ -6537,10 +6562,11 @@ CurveLayout Graph::fillCurveSettings(const QStringList &curve, int fileVersion, cl.aStyle = curve[14 + offset].toInt(); if (curve.count() < 16) cl.penWidth = cl.lWidth; - else if ((fileVersion >= 79) && (curve[3 + offset].toInt() == Graph::Box)) + else if ((fileVersion >= 79) && + (curve[3 + offset].toInt() == GraphOptions::Box)) cl.penWidth = curve[15 + offset].toFloat(); else if ((fileVersion >= 78) && - (curve[3 + offset].toInt() <= Graph::LineSymbols)) + (curve[3 + offset].toInt() <= GraphOptions::LineSymbols)) cl.penWidth = curve[15 + offset].toFloat(); else cl.penWidth = cl.lWidth; @@ -6599,7 +6625,7 @@ std::string Graph::saveCurve(int i) { auto c = dynamic_cast<DataCurve *>(it); if (c) { QString s; - if (c->type() == Box) + if (c->type() == GraphOptions::Box) s += "curve\t" + QString::number(c->x(0)) + "\t" + c->title().text() + "\t"; else diff --git a/MantidPlot/src/Graph.h b/MantidPlot/src/Graph.h index abeb93df44609d9f64e989fc7798435b8e4f304d..e0ef6c981410927b6bfc6e6583f8be237aeb1cb3 100644 --- a/MantidPlot/src/Graph.h +++ b/MantidPlot/src/Graph.h @@ -29,32 +29,32 @@ #ifndef GRAPH_H #define GRAPH_H +#include <QEvent> #include <QList> #include <QPointer> #include <QPrinter> -#include <QVector> -#include <QEvent> -#include <QSettings> #include <QSet> +#include <QSettings> +#include <QVector> -#include <qwt_text.h> +#include <qwt_global.h> #include <qwt_plot.h> -#include <qwt_plot_marker.h> #include <qwt_plot_curve.h> -#include <qwt_plot_panner.h> #include <qwt_plot_magnifier.h> -#include <qwt_global.h> +#include <qwt_plot_marker.h> +#include <qwt_plot_panner.h> +#include <qwt_text.h> #if QWT_VERSION >= 0x050200 #include <qwt_plot_rescaler.h> #endif -#include "Plot.h" -#include "Table.h" #include "AxesDialog.h" -#include "PlotToolInterface.h" -#include "MultiLayer.h" -#include "ScaleDraw.h" #include "MantidQtAPI/GraphOptions.h" #include "MantidQtAPI/ScaleEngine.h" +#include "MultiLayer.h" +#include "Plot.h" +#include "PlotToolInterface.h" +#include "ScaleDraw.h" +#include "Table.h" #include <boost/shared_ptr.hpp> #include <set> @@ -164,32 +164,6 @@ public: enum Ticks { NoTicks = 0, Out = 1, InOut = 2, In = 3 }; enum MarkerType { None = -1, Text = 0, Arrow = 1, Image = 2 }; - enum CurveType { - Unspecified = -1, - Line, - Scatter, - LineSymbols, - VerticalBars, - Area, - Pie, - VerticalDropLines, - Spline, - HorizontalSteps, - Histogram, - HorizontalBars, - VectXYXY, - ErrorBars, - Box, - VectXYAM, - VerticalSteps, - ColorMap, - GrayScale, - ColorMapContour, - Contour, - Function, - ImagePlot, - User - }; bool hasSynchronizedScaleDivisions() { return d_synchronize_scales; }; void setSynchronizedScaleDivisions(bool on) { d_synchronize_scales = on; }; @@ -260,7 +234,9 @@ public slots: //! \name Pie Curves //@{ //! Returns true if this Graph is a pie plot, false otherwise. - bool isPiePlot() { return (c_type.count() == 1 && c_type[0] == Pie); }; + bool isPiePlot() { + return (c_type.count() == 1 && c_type[0] == GraphOptions::Pie); + }; //! Used when creating a pie plot. QwtPieCurve *plotPie(Table *w, const QString &name, int startRow = 0, int endRow = -1); @@ -289,11 +265,12 @@ public slots: PlotCurve *insertCurve(Table *w, const QString &xColName, const QString &yColName, int style, int startRow = 0, int endRow = -1); - PlotCurve *insertCurve(QString workspaceName, int index, bool err = false, - Graph::CurveType style = Graph::Unspecified, - bool distribution = false); + PlotCurve * + insertCurve(QString workspaceName, int index, bool err = false, + GraphOptions::CurveType style = GraphOptions::Unspecified, + bool distribution = false); PlotCurve *insertCurve(PlotCurve *c, int lineWidth = -1, - int curveType = User); + int curveType = GraphOptions::User); void insertPlotItem(QwtPlotItem *i, int type); void insertCurve(Graph *g, int i); @@ -830,18 +807,18 @@ public slots: //! Returns a pointer to a 2D plot, if the Graph has one Spectrogram *spectrogram(); //! Add a spectrogram to the graph - Spectrogram *plotSpectrogram(Matrix *m, CurveType type); + Spectrogram *plotSpectrogram(Matrix *m, GraphOptions::CurveType type); Spectrogram *plotSpectrogram(Function2D *f, int nrows, int ncols, double left, double top, double width, double height, double minz, double maxz, - CurveType type); // Mantid + GraphOptions::CurveType type); // Mantid Spectrogram *plotSpectrogram(Function2D *f, int nrows, int ncols, QwtDoubleRect bRect, double minz, double maxz, - CurveType type); // Mantid + GraphOptions::CurveType type); // Mantid // Spectrogram* plotSpectrogram(UserHelperFunction *f,int nrows, int // ncols,QwtDoubleRect bRect,double minz,double maxz,CurveType type);//Mantid Spectrogram *plotSpectrogram(Spectrogram *d_spectrogram, - CurveType type); // Mantid + GraphOptions::CurveType type); // Mantid //! Add a matrix histogram to the graph QwtHistogram *addHistogram(Matrix *m); //! Restores a histogram from a project file. @@ -1007,6 +984,6 @@ private: boost::shared_ptr<Mantid::Kernel::Unit> m_yUnits; }; -Q_DECLARE_METATYPE(Graph::CurveType) +Q_DECLARE_METATYPE(GraphOptions::CurveType) #endif // GRAPH_H diff --git a/MantidPlot/src/LegendWidget.cpp b/MantidPlot/src/LegendWidget.cpp index 89d634b24e3dfd1af091896920ed80453f3542a8..b825d023684531ee0fa3efa09e2d24ec46181e70 100644 --- a/MantidPlot/src/LegendWidget.cpp +++ b/MantidPlot/src/LegendWidget.cpp @@ -27,23 +27,23 @@ * * ***************************************************************************/ #include "LegendWidget.h" +#include "ApplicationWindow.h" #include "QwtPieCurve.h" -#include "VectorCurve.h" #include "SelectionMoveResizer.h" -#include "ApplicationWindow.h" +#include "VectorCurve.h" -#include <QPainter> +#include <QApplication> +#include <QMessageBox> #include <QPaintEvent> +#include <QPainter> #include <QPolygon> -#include <QMessageBox> -#include <QApplication> -#include <qwt_plot.h> -#include <qwt_scale_widget.h> +#include <qwt_layout_metrics.h> #include <qwt_painter.h> -#include <qwt_plot_layout.h> +#include <qwt_plot.h> #include <qwt_plot_canvas.h> -#include <qwt_layout_metrics.h> +#include <qwt_plot_layout.h> +#include <qwt_scale_widget.h> #include <qwt_symbol.h> LegendWidget::LegendWidget(Plot *plot) @@ -231,12 +231,13 @@ void LegendWidget::drawSymbol(PlotCurve *c, int point, QPainter *p, int x, if (!c || c->rtti() == QwtPlotItem::Rtti_PlotSpectrogram) return; - if (c->type() == Graph::VectXYXY || c->type() == Graph::VectXYAM) { + if (c->type() == GraphOptions::VectXYXY || + c->type() == GraphOptions::VectXYAM) { drawVector(c, p, x, y, l); return; } - if (c->type() == Graph::Pie) { + if (c->type() == GraphOptions::Pie) { QwtPieCurve *pie = dynamic_cast<QwtPieCurve *>(c); if (!pie) return; @@ -257,7 +258,7 @@ void LegendWidget::drawSymbol(PlotCurve *c, int point, QPainter *p, int x, p->save(); if (c->style() != 0) { p->setPen(pen); - if (br.style() != Qt::NoBrush || c->type() == Graph::Box) { + if (br.style() != Qt::NoBrush || c->type() == GraphOptions::Box) { QRect lr = QRect(x, y - 4, l, 10); p->setBrush(br); QwtPainter::drawRect(p, lr); @@ -520,7 +521,7 @@ int LegendWidget::symbolsMaxWidth() { int point = 0; PlotCurve *c = getCurve(s.mid(pos1 + 1, pos2 - pos1 - 1), point); - if (c && c->type() == Graph::Pie) { + if (c && c->type() == GraphOptions::Pie) { maxL = 2 * d_text->font().pointSize(); // 10; line_length = 0; s = s.right(s.length() - pos2 - 1); @@ -528,9 +529,11 @@ int LegendWidget::symbolsMaxWidth() { } if (c && c->rtti() != QwtPlotItem::Rtti_PlotSpectrogram) { - if (c->type() == Graph::Pie || c->type() == Graph::VerticalBars || - c->type() == Graph::HorizontalBars || - c->type() == Graph::Histogram || c->type() == Graph::Box) { + if (c->type() == GraphOptions::Pie || + c->type() == GraphOptions::VerticalBars || + c->type() == GraphOptions::HorizontalBars || + c->type() == GraphOptions::Histogram || + c->type() == GraphOptions::Box) { maxL = 2 * d_text->font().pointSize(); // 10; line_length = 0; } else { @@ -574,7 +577,7 @@ QString LegendWidget::parse(const QString &str) { if (c) { if (lst.count() == 1) s = s.replace(pos, pos2 - pos + 1, c->title().text()); - else if (lst.count() == 3 && c->type() == Graph::Pie) { + else if (lst.count() == 3 && c->type() == GraphOptions::Pie) { if (auto dc = dynamic_cast<DataCurve *>(c)) { Table *t = dc->table(); int col = t->colIndex(c->title().text()); diff --git a/MantidPlot/src/Mantid/AlgorithmDockWidget.cpp b/MantidPlot/src/Mantid/AlgorithmDockWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a58653032080dfc0b16869e7c7a32b686b36e732 --- /dev/null +++ b/MantidPlot/src/Mantid/AlgorithmDockWidget.cpp @@ -0,0 +1,113 @@ +#include "AlgorithmDockWidget.h" +#include "MantidUI.h" + +//-------------------- AlgorithmDockWidget ----------------------// +/** Create a QDockWidget containing: +* The AlgorithmSelectorWidget +* The progress bar and Details button +*/ +AlgorithmDockWidget::AlgorithmDockWidget(MantidUI *mui, ApplicationWindow *w) + : QDockWidget(w), m_progressBar(NULL), m_algID(), m_mantidUI(mui) { + setWindowTitle(tr("Algorithms")); + setObjectName( + "exploreAlgorithms"); // this is needed for QMainWindow::restoreState() + setMinimumHeight(150); + setMinimumWidth(200); + w->addDockWidget(Qt::RightDockWidgetArea, this); //*/ + + // Add the AlgorithmSelectorWidget + m_selector = new MantidQt::MantidWidgets::AlgorithmSelectorWidget(this); + connect(m_selector, SIGNAL(executeAlgorithm(const QString &, const int)), + m_mantidUI, SLOT(showAlgorithmDialog(const QString &, const int))); + + m_runningLayout = new QHBoxLayout(); + m_runningLayout->setObjectName("testA"); + + m_runningButton = new QPushButton("Details"); + m_runningLayout->addStretch(); + m_runningLayout->addWidget(m_runningButton); + connect(m_runningButton, SIGNAL(clicked()), m_mantidUI, + SLOT(showAlgMonitor())); + + QFrame *f = new QFrame(this); + QVBoxLayout *layout = new QVBoxLayout(f); + layout->setSpacing(4); + layout->setMargin(4); + f->setLayout(layout); + layout->setMargin(0); + layout->addWidget(m_selector); + layout->addLayout(m_runningLayout); + + setWidget(f); +} + +/** Update the list of algorithms in the dock */ +void AlgorithmDockWidget::update() { m_selector->update(); } + +void AlgorithmDockWidget::updateProgress(void *alg, const double p, + const QString &msg, + double estimatedTime, + int progressPrecision) { + if (m_algID.empty()) + return; + if (alg == m_algID.first() && p >= 0 && p <= 100 && m_progressBar) { + m_progressBar->setValue(static_cast<int>(p)); + // Make the progress string + std::ostringstream mess; + mess << msg.toStdString(); + mess.precision(progressPrecision); + mess << " " << std::fixed << p << "%"; + if (estimatedTime > 0.5) { + mess.precision(0); + mess << " (~"; + if (estimatedTime < 60) + mess << static_cast<int>(estimatedTime) << "s"; + else if (estimatedTime < 60 * 60) { + int min = static_cast<int>(estimatedTime / 60); + int sec = static_cast<int>(estimatedTime - min * 60); + mess << min << "m" << std::setfill('0') << std::setw(2) << sec << "s"; + } else { + int hours = static_cast<int>(estimatedTime / 3600); + int min = static_cast<int>((estimatedTime - hours * 3600) / 60); + mess << hours << "h" << std::setfill('0') << std::setw(2) << min << "h"; + } + mess << ")"; + } + QString formatStr = QString::fromStdString(mess.str()); + m_progressBar->setFormat(formatStr); + } +} + +void AlgorithmDockWidget::algorithmStarted(void *alg) { + m_algID.push_front(alg); + hideProgressBar(); + showProgressBar(); +} + +void AlgorithmDockWidget::algorithmFinished(void *alg) { + if (m_algID.empty()) + return; + m_algID.removeAll(alg); + hideProgressBar(); +} + +void AlgorithmDockWidget::showProgressBar() { + if (m_progressBar == NULL) { + // insert progress bar + m_progressBar = new QProgressBar(); + m_progressBar->setAlignment(Qt::AlignHCenter); + m_runningLayout->insertWidget(1, m_progressBar); + // remove the stretch item + m_runningLayout->removeItem(m_runningLayout->takeAt(0)); + } +} + +void AlgorithmDockWidget::hideProgressBar() { + if (m_progressBar && m_algID.empty()) { + m_runningLayout->insertStretch(0); + m_runningLayout->removeWidget(m_progressBar); + m_progressBar->close(); + delete m_progressBar; + m_progressBar = NULL; + } +} \ No newline at end of file diff --git a/MantidPlot/src/Mantid/AlgorithmDockWidget.h b/MantidPlot/src/Mantid/AlgorithmDockWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..db309d63cba217676337d37ca27770f94af09c46 --- /dev/null +++ b/MantidPlot/src/Mantid/AlgorithmDockWidget.h @@ -0,0 +1,38 @@ +#ifndef ALGORITHMDOCKWIDGET_H +#define ALGORITHMDOCKWIDGET_H + +#include "MantidQtMantidWidgets/AlgorithmSelectorWidget.h" +#include <QDockWidget> + +class MantidUI; +class ApplicationWindow; +class QPushButton; +class QProgressBar; +class QHBoxLayout; + +class AlgorithmDockWidget : public QDockWidget { + Q_OBJECT +public: + AlgorithmDockWidget(MantidUI *mui, ApplicationWindow *w); +public slots: + void update(); + void updateProgress(void *alg, const double p, const QString &msg, + double estimatedTime, int progressPrecision); + void algorithmStarted(void *alg); + void algorithmFinished(void *alg); + +protected: + void showProgressBar(); + void hideProgressBar(); + + MantidQt::MantidWidgets::AlgorithmSelectorWidget *m_selector; + QPushButton *m_runningButton; + QProgressBar *m_progressBar; + QHBoxLayout *m_runningLayout; + QList<void *> m_algID; + friend class MantidUI; + +private: + MantidUI *m_mantidUI; +}; +#endif // ALGORITHMDOCKWIDGET_H \ No newline at end of file diff --git a/MantidPlot/src/Mantid/AlgorithmMonitor.cpp b/MantidPlot/src/Mantid/AlgorithmMonitor.cpp index 9e9dd1fe74ddd5102553009f39db2c658d974be9..e115b040c72cf1a0e0c7fa30a2915b54e4caeead 100644 --- a/MantidPlot/src/Mantid/AlgorithmMonitor.cpp +++ b/MantidPlot/src/Mantid/AlgorithmMonitor.cpp @@ -1,6 +1,5 @@ #include "AlgorithmMonitor.h" #include "MantidUI.h" -#include "MantidDock.h" #include "MantidAPI/AlgorithmManager.h" #include "MantidKernel/PropertyManager.h" #include "MantidKernel/MaskedProperty.h" diff --git a/MantidPlot/src/Mantid/MantidCurve.cpp b/MantidPlot/src/Mantid/MantidCurve.cpp index 2cfc217bddd1edab54ebf56cb1d67cccb5cd3b66..f93b369d8549e58b6263124b749936b7ad1694ca 100644 --- a/MantidPlot/src/Mantid/MantidCurve.cpp +++ b/MantidPlot/src/Mantid/MantidCurve.cpp @@ -6,8 +6,8 @@ #include "MantidAPI/AnalysisDataService.h" #include "MantidQtAPI/MantidQwtWorkspaceData.h" -#include "../Graph.h" #include "../ApplicationWindow.h" +#include "../Graph.h" #include "../MultiLayer.h" #include "ErrorBarSettings.h" #include "MantidKernel/CPUTimer.h" @@ -39,11 +39,11 @@ Helper method to apply a chosen style. @param ml : pointer to multilayer object @param lineWidth: ref to linewidth, which may be internally adjusted */ -void MantidCurve::applyStyleChoice(Graph::CurveType style, MultiLayer *ml, - int &lineWidth) { +void MantidCurve::applyStyleChoice(GraphOptions::CurveType style, + MultiLayer *ml, int &lineWidth) { - if (style == Graph::Unspecified) - style = static_cast<Graph::CurveType>( + if (style == GraphOptions::Unspecified) + style = static_cast<GraphOptions::CurveType>( ml->applicationWindow()->defaultCurveStyle); QwtPlotCurve::CurveStyle qwtStyle; @@ -51,20 +51,20 @@ void MantidCurve::applyStyleChoice(Graph::CurveType style, MultiLayer *ml, const QwtSymbol symbol(QwtSymbol::Ellipse, QBrush(Qt::black), QPen(), QSize(symbolSize, symbolSize)); switch (style) { - case Graph::Line: + case GraphOptions::Line: qwtStyle = QwtPlotCurve::Lines; break; - case Graph::Scatter: + case GraphOptions::Scatter: qwtStyle = QwtPlotCurve::NoCurve; this->setSymbol(symbol); break; - case Graph::LineSymbols: + case GraphOptions::LineSymbols: qwtStyle = QwtPlotCurve::Lines; this->setSymbol(symbol); break; case 15: qwtStyle = QwtPlotCurve::Steps; - break; // should be Graph::HorizontalSteps but it doesn't work + break; // should be GraphOptions::HorizontalSteps but it doesn't work default: qwtStyle = QwtPlotCurve::Lines; break; diff --git a/MantidPlot/src/Mantid/MantidCurve.h b/MantidPlot/src/Mantid/MantidCurve.h index 8f158965e8d63200d50723dd078c0066e0fb85ce..9572c104f2d37d9336242db4b62052851e3b8ac5 100644 --- a/MantidPlot/src/Mantid/MantidCurve.h +++ b/MantidPlot/src/Mantid/MantidCurve.h @@ -2,9 +2,9 @@ #define MANTIDPLOT_MANTIDCURVE_H #include "../PlotCurve.h" -#include "MantidQtAPI/WorkspaceObserver.h" #include "MantidAPI/Workspace_fwd.h" #include "MantidQtAPI/MantidQwtWorkspaceData.h" +#include "MantidQtAPI/WorkspaceObserver.h" class Graph; class ErrorBarSettings; @@ -81,7 +81,8 @@ protected: -------------------------------------------------------------------------------------*/ /// Apply the style choice - void applyStyleChoice(Graph::CurveType style, MultiLayer *ml, int &lineWidth); + void applyStyleChoice(GraphOptions::CurveType style, MultiLayer *ml, + int &lineWidth); /// Make a name for a copied curve static QString createCopyName(const QString &curveName); @@ -106,7 +107,7 @@ private: mutable QwtDoubleRect m_boundingRect; // To ensure that all MantidCurves can work with Mantid Workspaces. - virtual void init(Graph *g, bool distr, Graph::CurveType style) = 0; + virtual void init(Graph *g, bool distr, GraphOptions::CurveType style) = 0; }; #endif diff --git a/MantidPlot/src/Mantid/MantidDock.cpp b/MantidPlot/src/Mantid/MantidDock.cpp index 94a0c75ff06cf483389b40f68b74c1cd266e4334..33713e175abfca37148d3b28f9c413d21e6e8719 100644 --- a/MantidPlot/src/Mantid/MantidDock.cpp +++ b/MantidPlot/src/Mantid/MantidDock.cpp @@ -1,14 +1,15 @@ #include "MantidDock.h" -#include "MantidUI.h" -#include "MantidMatrix.h" #include "../ApplicationWindow.h" #include "../pixmaps.h" -#include "MantidWSIndexDialog.h" #include "FlowLayout.h" -#include "WorkspaceIcons.h" #include "MantidGroupPlotGenerator.h" +#include "MantidMatrix.h" +#include "MantidTreeWidget.h" +#include "MantidTreeWidgetItem.h" +#include "MantidUI.h" +#include "MantidWSIndexDialog.h" +#include "WorkspaceIcons.h" -#include <MantidAPI/FileProperty.h> #include "MantidAPI/IMDEventWorkspace.h" #include "MantidAPI/IMDHistoWorkspace.h" @@ -16,12 +17,17 @@ #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/WorkspaceGroup.h" #include "MantidGeometry/Instrument.h" +#include <MantidAPI/FileProperty.h> #include <MantidKernel/make_unique.h> -#include <MantidQtMantidWidgets/LineEditWithClear.h> #include <MantidQtAPI/InterfaceManager.h> +#include <MantidQtMantidWidgets/LineEditWithClear.h> #include <Poco/Path.h> +#include <QFileDialog> +#include <QMenu> +#include <QSignalMapper> + #ifdef MAKE_VATES #include "vtkPVDisplayInformation.h" #endif @@ -36,7 +42,6 @@ using namespace Mantid::Geometry; namespace { /// static logger for dock widget Mantid::Kernel::Logger docklog("MantidDockWidget"); -Mantid::Kernel::Logger treelog("MantidTreeWidget"); WorkspaceIcons WORKSPACE_ICONS = WorkspaceIcons(); } @@ -1050,14 +1055,14 @@ void MantidDockWidget::sortDescending() { void MantidDockWidget::chooseByName() { if (isTreeUpdating()) return; - m_tree->setSortScheme(ByName); + m_tree->setSortScheme(MantidItemSortScheme::ByName); m_tree->sort(); } void MantidDockWidget::chooseByLastModified() { if (isTreeUpdating()) return; - m_tree->setSortScheme(ByLastModified); + m_tree->setSortScheme(MantidItemSortScheme::ByLastModified); m_tree->sort(); } @@ -1533,536 +1538,4 @@ void MantidDockWidget::plotContour() { plotter->plotContour(wsGroup, options); } } -} - -//------------ MantidTreeWidget -----------------------// - -MantidTreeWidget::MantidTreeWidget(MantidDockWidget *w, MantidUI *mui) - : QTreeWidget(w), m_dockWidget(w), m_mantidUI(mui), - m_ads(Mantid::API::AnalysisDataService::Instance()), m_sortScheme() { - setObjectName("WorkspaceTree"); - setSelectionMode(QAbstractItemView::ExtendedSelection); - setSortOrder(Qt::AscendingOrder); - setAcceptDrops(true); -} - -/** -* Accept a drag move event and selects whether to accept the action -* @param de :: The drag move event -*/ -void MantidTreeWidget::dragMoveEvent(QDragMoveEvent *de) { - // The event needs to be accepted here - if (de->mimeData()->hasUrls()) - de->accept(); -} - -/** -* Accept a drag enter event and selects whether to accept the action -* @param de :: The drag enter event -*/ -void MantidTreeWidget::dragEnterEvent(QDragEnterEvent *de) { - // Set the drop action to be the proposed action. - if (de->mimeData()->hasUrls()) - de->acceptProposedAction(); -} - -/** -* Accept a drag drop event and process the data appropriately -* @param de :: The drag drop event -*/ -void MantidTreeWidget::dropEvent(QDropEvent *de) { - QStringList filenames; - const QMimeData *mimeData = de->mimeData(); - if (mimeData->hasUrls()) { - QList<QUrl> urlList = mimeData->urls(); - for (int i = 0; i < urlList.size(); ++i) { - QString fName = urlList[i].toLocalFile(); - if (fName.size() > 0) { - filenames.append(fName); - } - } - } - de->acceptProposedAction(); - - for (int i = 0; i < filenames.size(); ++i) { - try { - QFileInfo fi(filenames[i]); - QString basename = fi.baseName(); - IAlgorithm_sptr alg = m_mantidUI->createAlgorithm("Load"); - alg->initialize(); - alg->setProperty("Filename", filenames[i].toStdString()); - alg->setProperty("OutputWorkspace", basename.toStdString()); - m_mantidUI->executeAlgorithmAsync(alg, true); - } catch (std::runtime_error &error) { - treelog.error() << "Failed to Load the file " - << filenames[i].toStdString() - << " . The reason for failure is: " << error.what() - << '\n'; - } catch (std::logic_error &error) { - treelog.error() << "Failed to Load the file " - << filenames[i].toStdString() - << " . The reason for failure is: " << error.what() - << '\n'; - } catch (std::exception &error) { - treelog.error() << "Failed to Load the file " - << filenames[i].toStdString() - << " . The reason for failure is: " << error.what() - << '\n'; - } - } -} - -void MantidTreeWidget::mousePressEvent(QMouseEvent *e) { - if (e->button() == Qt::LeftButton) { - if (!itemAt(e->pos())) - selectionModel()->clear(); - m_dragStartPosition = e->pos(); - } - - QTreeWidget::mousePressEvent(e); -} - -void MantidTreeWidget::mouseMoveEvent(QMouseEvent *e) { - if (!(e->buttons() & Qt::LeftButton)) - return; - if ((e->pos() - m_dragStartPosition).manhattanLength() < - QApplication::startDragDistance()) - return; - - // Start dragging - QDrag *drag = new QDrag(this); - QMimeData *mimeData = new QMimeData; - - QStringList wsnames = getSelectedWorkspaceNames(); - if (wsnames.size() == 0) - return; - QString importStatement = ""; - foreach (const QString wsname, wsnames) { - QString prefix = ""; - if (wsname[0].isDigit()) - prefix = "ws"; - if (importStatement.size() > 0) - importStatement += "\n"; - importStatement += prefix + wsname + " = mtd[\"" + wsname + "\"]"; - } - - mimeData->setText(importStatement); - mimeData->setObjectName("MantidWorkspace"); - - drag->setMimeData(mimeData); - - Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction); - (void)dropAction; -} - -void MantidTreeWidget::mouseDoubleClickEvent(QMouseEvent *e) { - try { - QString wsName = m_mantidUI->getSelectedWorkspaceName(); - Mantid::API::WorkspaceGroup_sptr grpWSPstr; - grpWSPstr = boost::dynamic_pointer_cast<WorkspaceGroup>( - m_ads.retrieve(wsName.toStdString())); - if (!grpWSPstr) { - if (!wsName.isEmpty()) { - m_mantidUI->importWorkspace(wsName, false); - return; - } - } - } catch (Mantid::Kernel::Exception::NotFoundError &) { - return; - } - QTreeWidget::mouseDoubleClickEvent(e); -} - -/** -* Returns a list of all selected workspaces. It does NOT -* extract child workspaces from groups - it only returns -* exactly what has been selected. -*/ -QStringList MantidTreeWidget::getSelectedWorkspaceNames() const { - QStringList names; - - foreach (const auto selectedItem, this->selectedItems()) { - if (selectedItem) - names.append(selectedItem->text(0)); - } - - return names; -} - -/** - * Filter the list of selected workspace names to account for any - * non-MatrixWorkspaces that may have been selected. In particular - * WorkspaceGroups (the children of which are to be included if they are - * MatrixWorkspaces) and TableWorkspaces (which are implicitly excluded). - * We only want workspaces we can actually plot! - */ -QList<MatrixWorkspace_const_sptr> -MantidTreeWidget::getSelectedMatrixWorkspaces() const { - // Check for any selected WorkspaceGroup names and replace with the names of - // their children. - QSet<QString> selectedWsNames; - foreach (const QString wsName, this->getSelectedWorkspaceNames()) { - const auto groupWs = boost::dynamic_pointer_cast<const WorkspaceGroup>( - m_ads.retrieve(wsName.toStdString())); - if (groupWs) { - const auto childWsNames = groupWs->getNames(); - for (auto childWsName : childWsNames) { - selectedWsNames.insert(QString::fromStdString(childWsName)); - } - } else { - selectedWsNames.insert(wsName); - } - } - - // Get the names of, and pointers to, the MatrixWorkspaces only. - QList<MatrixWorkspace_const_sptr> selectedMatrixWsList; - QList<QString> selectedMatrixWsNameList; - foreach (const auto selectedWsName, selectedWsNames) { - const auto matrixWs = boost::dynamic_pointer_cast<const MatrixWorkspace>( - m_ads.retrieve(selectedWsName.toStdString())); - if (matrixWs) { - selectedMatrixWsList.append(matrixWs); - } - } - return selectedMatrixWsList; -} - -/** -* Allows users to choose spectra from the selected workspaces by presenting them -* with a dialog box. Skips showing the dialog box and automatically chooses -* workspace index 0 for all selected workspaces if one or more of the them are -* single-spectrum workspaces. -* -* @param showWaterfallOpt If true, show the waterfall option on the dialog -* @param showPlotAll :: [input] If true, show the "Plot All" button on the -* dialog -* @param showTiledOpt :: [input] If true, show the "Tiled" option on the dialog -* @return :: A MantidWSIndexDialog::UserInput structure listing the selected -* options -*/ -MantidWSIndexWidget::UserInput MantidTreeWidget::chooseSpectrumFromSelected( - bool showWaterfallOpt, bool showPlotAll, bool showTiledOpt) const { - auto selectedMatrixWsList = getSelectedMatrixWorkspaces(); - QList<QString> selectedMatrixWsNameList; - foreach (const auto matrixWs, selectedMatrixWsList) { - selectedMatrixWsNameList.append(QString::fromStdString(matrixWs->name())); - } - - // Check to see if all workspaces have only a single spectrum ... - bool allSingleWorkspaces = true; - foreach (const auto selectedMatrixWs, selectedMatrixWsList) { - if (selectedMatrixWs->getNumberHistograms() != 1) { - allSingleWorkspaces = false; - break; - } - } - - // ... and if so, just return all workspace names mapped to workspace index 0; - if (allSingleWorkspaces) { - const std::set<int> SINGLE_SPECTRUM = {0}; - QMultiMap<QString, std::set<int>> spectrumToPlot; - foreach (const auto selectedMatrixWs, selectedMatrixWsList) { - spectrumToPlot.insert(QString::fromStdString(selectedMatrixWs->name()), - SINGLE_SPECTRUM); - } - MantidWSIndexWidget::UserInput selections; - selections.plots = spectrumToPlot; - selections.waterfall = false; - selections.tiled = false; - return selections; - } - - // Else, one or more workspaces - MantidWSIndexDialog *dio = - new MantidWSIndexDialog(m_mantidUI, 0, selectedMatrixWsNameList, - showWaterfallOpt, showPlotAll, showTiledOpt); - dio->exec(); - return dio->getSelections(); -} - -/** -* Allows users to choose spectra from the selected workspaces by presenting them -* with a dialog box, and also allows choice of a log to plot against and a name -* for this axis. -* @param type :: [input] Type of plot (for dialog title) -* @param nWorkspaces :: [input] Number of workspaces in selected group -* @returns :: A structure listing the selected options -*/ -MantidSurfacePlotDialog::UserInputSurface -MantidTreeWidget::choosePlotOptions(const QString &type, - int nWorkspaces) const { - auto selectedMatrixWsList = getSelectedMatrixWorkspaces(); - QList<QString> selectedMatrixWsNameList; - foreach (const auto matrixWs, selectedMatrixWsList) { - selectedMatrixWsNameList.append(QString::fromStdString(matrixWs->name())); - } - MantidSurfacePlotDialog *dlg = new MantidSurfacePlotDialog( - m_mantidUI, 0, selectedMatrixWsNameList, type); - dlg->exec(); - auto selections = dlg->getSelections(); - std::string errors = - MantidGroupPlotGenerator::validatePlotOptions(selections, nWorkspaces); - if (!errors.empty()) { - MantidSurfacePlotDialog::showPlotOptionsError(errors.c_str()); - } - return selections; -} - -/** -* Allows users to choose spectra from the selected workspaces by presenting them -* with a dialog box, and also allows choice of a log to plot against and a name -* for this axis. -* @param nWorkspaces :: [input] Number of workspaces in selected group -* @returns :: A structure listing the selected options -*/ -MantidSurfacePlotDialog::UserInputSurface -MantidTreeWidget::chooseSurfacePlotOptions(int nWorkspaces) const { - return choosePlotOptions("Surface", nWorkspaces); -} - -/** -* Allows users to choose spectra from the selected workspaces by presenting them -* with a dialog box, and also allows choice of a log to plot against and a name -* for this axis. -* @param nWorkspaces :: [input] Number of workspaces in selected group -* @returns :: A structure listing the selected options -*/ -MantidSurfacePlotDialog::UserInputSurface -MantidTreeWidget::chooseContourPlotOptions(int nWorkspaces) const { - return choosePlotOptions("Contour", nWorkspaces); -} - -void MantidTreeWidget::setSortScheme(MantidItemSortScheme sortScheme) { - m_sortScheme = sortScheme; -} - -void MantidTreeWidget::setSortOrder(Qt::SortOrder sortOrder) { - m_sortOrder = sortOrder; -} - -Qt::SortOrder MantidTreeWidget::getSortOrder() const { return m_sortOrder; } - -MantidItemSortScheme MantidTreeWidget::getSortScheme() const { - return m_sortScheme; -} - -/** -* Sort the items according to the current sort scheme and order. -*/ -void MantidTreeWidget::sort() { sortItems(sortColumn(), m_sortOrder); } - -/** -* Log a warning message. -* @param msg :: A message to log. -*/ -void MantidTreeWidget::logWarningMessage(const std::string &msg) { - treelog.warning(msg); -} - -//-------------------- MantidTreeWidgetItem ----------------------// -/**Constructor. -* Must be passed its parent MantidTreeWidget, to facilitate correct sorting. -*/ -MantidTreeWidgetItem::MantidTreeWidgetItem(MantidTreeWidget *parent) - : QTreeWidgetItem(parent), m_parent(parent), m_sortPos(0) {} - -/**Constructor. -* Must be passed its parent MantidTreeWidget, to facilitate correct sorting. -*/ -MantidTreeWidgetItem::MantidTreeWidgetItem(QStringList list, - MantidTreeWidget *parent) - : QTreeWidgetItem(list), m_parent(parent), m_sortPos(0) {} - -/**Overidden operator. -* Must be passed its parent MantidTreeWidget, to facilitate correct sorting. -*/ -bool MantidTreeWidgetItem::operator<(const QTreeWidgetItem &other) const { - // If this and/or other has been set to have a Qt::UserRole, then - // it has an accompanying sort order that we must maintain, no matter - // what the user has seletected in terms of order or scheme. - - bool thisShouldBeSorted = m_sortPos == 0; - const MantidTreeWidgetItem *mantidOther = - dynamic_cast<const MantidTreeWidgetItem *>(&other); - int otherSortPos = mantidOther ? mantidOther->getSortPos() : 0; - bool otherShouldBeSorted = otherSortPos == 0; - - // just in case m_parent is NULL. I think I saw this once but cannot - // reproduce. - if (!m_parent) - return false; - - if (!thisShouldBeSorted && !otherShouldBeSorted) { - if (m_parent->getSortOrder() == Qt::AscendingOrder) - return m_sortPos < otherSortPos; - else - return m_sortPos >= otherSortPos; - } else if (thisShouldBeSorted && !otherShouldBeSorted) { - if (m_parent->getSortOrder() == Qt::AscendingOrder) - return false; - else - return true; - } else if (!thisShouldBeSorted && otherShouldBeSorted) { - if (m_parent->getSortOrder() == Qt::AscendingOrder) - return true; - else - return false; - } - - // If both should be sorted, and the scheme is set to ByName ... - if (m_parent->getSortScheme() == ByName) { - if (QString::compare(text(0), other.text(0), Qt::CaseInsensitive) < 0) - return true; - return false; - } - // ... else both should be sorted and the scheme is set to ByLastModified. - else { - try { - if (childCount() > 0 && other.childCount() > 0) { - const QTreeWidgetItem *other_ptr = &other; - - try { - return getLastModified(this) < getLastModified(other_ptr); - } catch (std::out_of_range &e) { - m_parent->logWarningMessage(e.what()); - return false; - } - } - } catch (Mantid::Kernel::Exception::NotFoundError &) { - ; - } - return false; - } -} - -/**Finds the date and time of the last modification made to the workspace who's -* details -* are found in the given QTreeWidgetItem. -*/ -DateAndTime MantidTreeWidgetItem::getLastModified(const QTreeWidgetItem *item) { - QVariant userData = item->data(0, Qt::UserRole); - if (userData.isNull()) - return DateAndTime(); // now - - Workspace_sptr workspace = userData.value<Workspace_sptr>(); - const Mantid::API::WorkspaceHistory &wsHist = workspace->getHistory(); - if (wsHist.empty()) - return DateAndTime(); // now - - const size_t indexOfLast = wsHist.size() - 1; - const auto lastAlgHist = wsHist.getAlgorithmHistory(indexOfLast); - return lastAlgHist->executionDate(); -} - -//-------------------- AlgorithmDockWidget ----------------------// -/** Create a QDockWidget containing: -* The AlgorithmSelectorWidget -* The progress bar and Details button -*/ -AlgorithmDockWidget::AlgorithmDockWidget(MantidUI *mui, ApplicationWindow *w) - : QDockWidget(w), m_progressBar(NULL), m_algID(), m_mantidUI(mui) { - setWindowTitle(tr("Algorithms")); - setObjectName( - "exploreAlgorithms"); // this is needed for QMainWindow::restoreState() - setMinimumHeight(150); - setMinimumWidth(200); - w->addDockWidget(Qt::RightDockWidgetArea, this); //*/ - - // Add the AlgorithmSelectorWidget - m_selector = new MantidQt::MantidWidgets::AlgorithmSelectorWidget(this); - connect(m_selector, SIGNAL(executeAlgorithm(const QString &, const int)), - m_mantidUI, SLOT(showAlgorithmDialog(const QString &, const int))); - - m_runningLayout = new QHBoxLayout(); - m_runningLayout->setObjectName("testA"); - - m_runningButton = new QPushButton("Details"); - m_runningLayout->addStretch(); - m_runningLayout->addWidget(m_runningButton); - connect(m_runningButton, SIGNAL(clicked()), m_mantidUI, - SLOT(showAlgMonitor())); - - QFrame *f = new QFrame(this); - QVBoxLayout *layout = new QVBoxLayout(f); - layout->setSpacing(4); - layout->setMargin(4); - f->setLayout(layout); - layout->setMargin(0); - layout->addWidget(m_selector); - layout->addLayout(m_runningLayout); - - setWidget(f); -} - -/** Update the list of algorithms in the dock */ -void AlgorithmDockWidget::update() { m_selector->update(); } - -void AlgorithmDockWidget::updateProgress(void *alg, const double p, - const QString &msg, - double estimatedTime, - int progressPrecision) { - if (m_algID.empty()) - return; - if (alg == m_algID.first() && p >= 0 && p <= 100 && m_progressBar) { - m_progressBar->setValue(static_cast<int>(p)); - // Make the progress string - std::ostringstream mess; - mess << msg.toStdString(); - mess.precision(progressPrecision); - mess << " " << std::fixed << p << "%"; - if (estimatedTime > 0.5) { - mess.precision(0); - mess << " (~"; - if (estimatedTime < 60) - mess << static_cast<int>(estimatedTime) << "s"; - else if (estimatedTime < 60 * 60) { - int min = static_cast<int>(estimatedTime / 60); - int sec = static_cast<int>(estimatedTime - min * 60); - mess << min << "m" << std::setfill('0') << std::setw(2) << sec << "s"; - } else { - int hours = static_cast<int>(estimatedTime / 3600); - int min = static_cast<int>((estimatedTime - hours * 3600) / 60); - mess << hours << "h" << std::setfill('0') << std::setw(2) << min << "h"; - } - mess << ")"; - } - QString formatStr = QString::fromStdString(mess.str()); - m_progressBar->setFormat(formatStr); - } -} - -void AlgorithmDockWidget::algorithmStarted(void *alg) { - m_algID.push_front(alg); - hideProgressBar(); - showProgressBar(); -} - -void AlgorithmDockWidget::algorithmFinished(void *alg) { - if (m_algID.empty()) - return; - m_algID.removeAll(alg); - hideProgressBar(); -} - -void AlgorithmDockWidget::showProgressBar() { - if (m_progressBar == NULL) { - // insert progress bar - m_progressBar = new QProgressBar(); - m_progressBar->setAlignment(Qt::AlignHCenter); - m_runningLayout->insertWidget(1, m_progressBar); - // remove the stretch item - m_runningLayout->removeItem(m_runningLayout->takeAt(0)); - } -} - -void AlgorithmDockWidget::hideProgressBar() { - if (m_progressBar && m_algID.empty()) { - m_runningLayout->insertStretch(0); - m_runningLayout->removeWidget(m_progressBar); - m_progressBar->close(); - delete m_progressBar; - m_progressBar = NULL; - } -} - -//-------------------- ----------------------// +} \ No newline at end of file diff --git a/MantidPlot/src/Mantid/MantidDock.h b/MantidPlot/src/Mantid/MantidDock.h index 2a566e46762fdd53ade8f12711b9394f4017dfcc..a1b9e26c290f172298c0e078b387253cb7daf2a1 100644 --- a/MantidPlot/src/Mantid/MantidDock.h +++ b/MantidPlot/src/Mantid/MantidDock.h @@ -9,19 +9,12 @@ #include "MantidAPI/MatrixWorkspace_fwd.h" #include "MantidAPI/WorkspaceGroup_fwd.h" -#include "MantidQtMantidWidgets/AlgorithmSelectorWidget.h" - -#include "Mantid/MantidWSIndexDialog.h" -#include "Mantid/MantidSurfacePlotDialog.h" - #include <QActionGroup> #include <QAtomicInt> #include <QComboBox> #include <QDockWidget> #include <QList> #include <QPoint> -#include <QTreeWidget> -#include <QTreeWidgetItem> #include <QSortFilterProxyModel> #include <QStringList> #include <QMap> @@ -33,6 +26,7 @@ class ApplicationWindow; class MantidTreeWidgetItem; class MantidTreeWidget; class QLabel; +class QFileDialog; class QMenu; class QPushButton; class QTreeWidget; @@ -165,92 +159,4 @@ private: QMap<QString, QString> m_renameMap; }; -class MantidTreeWidget : public QTreeWidget { - Q_OBJECT - -public: - MantidTreeWidget(MantidDockWidget *w, MantidUI *mui); - void mousePressEvent(QMouseEvent *e) override; - void mouseMoveEvent(QMouseEvent *e) override; - void mouseDoubleClickEvent(QMouseEvent *e) override; - - QStringList getSelectedWorkspaceNames() const; - MantidWSIndexWidget::UserInput - chooseSpectrumFromSelected(bool showWaterfallOpt = true, - bool showPlotAll = true, - bool showTiledOpt = true) const; - void setSortScheme(MantidItemSortScheme); - void setSortOrder(Qt::SortOrder); - MantidItemSortScheme getSortScheme() const; - Qt::SortOrder getSortOrder() const; - void logWarningMessage(const std::string &); - void disableNodes(bool); - void sort(); - void dropEvent(QDropEvent *de) override; - QList<boost::shared_ptr<const Mantid::API::MatrixWorkspace>> - getSelectedMatrixWorkspaces() const; - MantidSurfacePlotDialog::UserInputSurface - chooseSurfacePlotOptions(int nWorkspaces) const; - MantidSurfacePlotDialog::UserInputSurface - chooseContourPlotOptions(int nWorkspaces) const; - -protected: - void dragMoveEvent(QDragMoveEvent *de) override; - void dragEnterEvent(QDragEnterEvent *de) override; - MantidSurfacePlotDialog::UserInputSurface - choosePlotOptions(const QString &type, int nWorkspaces) const; - -private: - QPoint m_dragStartPosition; - MantidDockWidget *m_dockWidget; - MantidUI *m_mantidUI; - Mantid::API::AnalysisDataServiceImpl &m_ads; - MantidItemSortScheme m_sortScheme; - Qt::SortOrder m_sortOrder; -}; - -/**A class derived from QTreeWidgetItem, to accomodate - * sorting on the items in a MantidTreeWidget. - */ -class MantidTreeWidgetItem : public QTreeWidgetItem { -public: - explicit MantidTreeWidgetItem(MantidTreeWidget *); - MantidTreeWidgetItem(QStringList, MantidTreeWidget *); - void disableIfNode(bool); - void setSortPos(int o) { m_sortPos = o; } - int getSortPos() const { return m_sortPos; } - -private: - bool operator<(const QTreeWidgetItem &other) const override; - MantidTreeWidget *m_parent; - static Mantid::Kernel::DateAndTime getLastModified(const QTreeWidgetItem *); - int m_sortPos; -}; - -class AlgorithmDockWidget : public QDockWidget { - Q_OBJECT -public: - AlgorithmDockWidget(MantidUI *mui, ApplicationWindow *w); -public slots: - void update(); - void updateProgress(void *alg, const double p, const QString &msg, - double estimatedTime, int progressPrecision); - void algorithmStarted(void *alg); - void algorithmFinished(void *alg); - -protected: - void showProgressBar(); - void hideProgressBar(); - - MantidQt::MantidWidgets::AlgorithmSelectorWidget *m_selector; - QPushButton *m_runningButton; - QProgressBar *m_progressBar; - QHBoxLayout *m_runningLayout; - QList<void *> m_algID; - friend class MantidUI; - -private: - MantidUI *m_mantidUI; -}; - #endif diff --git a/MantidPlot/src/Mantid/MantidGroupPlotGenerator.cpp b/MantidPlot/src/Mantid/MantidGroupPlotGenerator.cpp index 1f798100abb6baf61c79657e9c5b6bcd4e3745bb..3e47e7fdf171f8652e136690e9d0852149000f8b 100644 --- a/MantidPlot/src/Mantid/MantidGroupPlotGenerator.cpp +++ b/MantidPlot/src/Mantid/MantidGroupPlotGenerator.cpp @@ -3,7 +3,9 @@ #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/Run.h" #include "MantidAPI/WorkspaceFactory.h" +#include <MantidQtMantidWidgets/MantidDisplayBase.h> +using namespace MantidQt::MantidWidgets; using Mantid::API::WorkspaceGroup_const_sptr; using Mantid::API::WorkspaceGroup_sptr; using Mantid::API::MatrixWorkspace_const_sptr; @@ -15,7 +17,7 @@ using Mantid::API::ExperimentInfo; * Constructor * @param mantidUI :: [input] Pointer to the Mantid UI */ -MantidGroupPlotGenerator::MantidGroupPlotGenerator(MantidUI *mantidUI) +MantidGroupPlotGenerator::MantidGroupPlotGenerator(MantidDisplayBase *mantidUI) : m_mantidUI(mantidUI) {} /** @@ -74,7 +76,8 @@ void MantidGroupPlotGenerator::plot( plot->setYAxisLabel(options.axisName); plot->setResolution(1); // If auto-set too high, appears empty } else if (graphType == Type::Contour) { - MultiLayer *plot = matrixToPlot->plotGraph2D(Graph::ColorMapContour); + MultiLayer *plot = + matrixToPlot->plotGraph2D(GraphOptions::ColorMapContour); plot->activeGraph()->setXAxisTitle(xLabelQ); plot->activeGraph()->setYAxisTitle(options.axisName); plot->activeGraph()->setTitle(QString("Contour ").append(title)); diff --git a/MantidPlot/src/Mantid/MantidGroupPlotGenerator.h b/MantidPlot/src/Mantid/MantidGroupPlotGenerator.h index ff864c2b69f85dfd34d0f02cbcdb58a36823f6c2..a58bfb1c7371190104dfdb1bcbf9111357c9bba3 100644 --- a/MantidPlot/src/Mantid/MantidGroupPlotGenerator.h +++ b/MantidPlot/src/Mantid/MantidGroupPlotGenerator.h @@ -1,10 +1,10 @@ #ifndef MANTIDGROUPPLOTGENERATOR_H_ #define MANTIDGROUPPLOTGENERATOR_H_ -#include "MantidSurfacePlotDialog.h" -#include "MantidMatrix.h" #include "Graph3D.h" #include "MantidAPI/NumericAxis.h" +#include "MantidMatrix.h" +#include <MantidQtMantidWidgets/MantidSurfacePlotDialog.h> /** * This utility class generates a surface or contour plot from a group of @@ -13,40 +13,46 @@ class MantidGroupPlotGenerator { public: /// Constructor - explicit MantidGroupPlotGenerator(MantidUI *mantidUI); + explicit MantidGroupPlotGenerator( + MantidQt::MantidWidgets::MantidDisplayBase *mantidUI); /// Plots a surface from the given workspace group - void - plotSurface(const Mantid::API::WorkspaceGroup_const_sptr &wsGroup, - const MantidSurfacePlotDialog::UserInputSurface &options) const; + void plotSurface( + const Mantid::API::WorkspaceGroup_const_sptr &wsGroup, + const MantidQt::MantidWidgets::MantidSurfacePlotDialog::UserInputSurface & + options) const; /// Plots a contour plot from the given workspace group - void - plotContour(const Mantid::API::WorkspaceGroup_const_sptr &wsGroup, - const MantidSurfacePlotDialog::UserInputSurface &options) const; + void plotContour( + const Mantid::API::WorkspaceGroup_const_sptr &wsGroup, + const MantidQt::MantidWidgets::MantidSurfacePlotDialog::UserInputSurface & + options) const; /// Tests if WorkspaceGroup contains only MatrixWorkspaces static bool groupIsAllMatrixWorkspaces( const Mantid::API::WorkspaceGroup_const_sptr &wsGroup); /// Validates the given options and returns an error string - static std::string - validatePlotOptions(MantidSurfacePlotDialog::UserInputSurface &options, - int nWorkspaces); + static std::string validatePlotOptions( + MantidQt::MantidWidgets::MantidSurfacePlotDialog::UserInputSurface & + options, + int nWorkspaces); private: /// Type of graph to plot enum class Type { Surface, Contour }; /// Plots a graph from the given workspace group - void plot(Type graphType, - const Mantid::API::WorkspaceGroup_const_sptr &wsGroup, - const MantidSurfacePlotDialog::UserInputSurface &options) const; + void plot( + Type graphType, const Mantid::API::WorkspaceGroup_const_sptr &wsGroup, + const MantidQt::MantidWidgets::MantidSurfacePlotDialog::UserInputSurface & + options) const; /// Creates a single workspace to plot from const Mantid::API::MatrixWorkspace_sptr createWorkspaceForGroupPlot( boost::shared_ptr<const Mantid::API::WorkspaceGroup> wsGroup, - const MantidSurfacePlotDialog::UserInputSurface &options, + const MantidQt::MantidWidgets::MantidSurfacePlotDialog::UserInputSurface & + options, QString *xAxisTitle) const; /// Returns a single log value from the given workspace @@ -68,7 +74,7 @@ private: void convertXData(Mantid::API::MatrixWorkspace_sptr ws, Type graphType) const; /// Pointer to the Mantid UI - MantidUI *const m_mantidUI; + MantidQt::MantidWidgets::MantidDisplayBase *const m_mantidUI; }; #endif diff --git a/MantidPlot/src/Mantid/MantidMDCurve.cpp b/MantidPlot/src/Mantid/MantidMDCurve.cpp index 7a199c3cf50f19bdce8c4b3321ff07988afb497d..06aaa39dccc150e05685aa1da10cf14e3e4c0ba2 100644 --- a/MantidPlot/src/Mantid/MantidMDCurve.cpp +++ b/MantidPlot/src/Mantid/MantidMDCurve.cpp @@ -1,13 +1,13 @@ #include "MantidMDCurve.h" -#include "MantidAPI/IMDWorkspace.h" +#include "../ApplicationWindow.h" +#include "../Graph.h" +#include "../MultiLayer.h" +#include "ErrorBarSettings.h" +#include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/IMDIterator.h" +#include "MantidAPI/IMDWorkspace.h" #include <qpainter.h> #include <qwt_symbol.h> -#include "MantidAPI/AnalysisDataService.h" -#include "ErrorBarSettings.h" -#include "../Graph.h" -#include "../ApplicationWindow.h" -#include "../MultiLayer.h" using namespace Mantid::API; using namespace MantidQt::API; @@ -27,7 +27,7 @@ Mantid::Kernel::Logger g_log("MantidMDCurve"); * workspace */ MantidMDCurve::MantidMDCurve(const QString &wsName, Graph *g, bool err, - bool distr, Graph::CurveType style) + bool distr, GraphOptions::CurveType style) : MantidCurve(wsName, err), m_wsName(wsName) { if (!g) { throw std::invalid_argument( @@ -53,7 +53,7 @@ MantidMDCurve::MantidMDCurve(const MantidMDCurve &c) * @param distr :: True if this is a distribution * @param style :: The graph style to use */ -void MantidMDCurve::init(Graph *g, bool distr, Graph::CurveType style) { +void MantidMDCurve::init(Graph *g, bool distr, GraphOptions::CurveType style) { UNUSED_ARG(distr); IMDWorkspace_const_sptr ws = boost::dynamic_pointer_cast<IMDWorkspace>( AnalysisDataService::Instance().retrieve(m_wsName.toStdString())); @@ -76,7 +76,7 @@ void MantidMDCurve::init(Graph *g, bool distr, Graph::CurveType style) { int lineWidth = 1; MultiLayer *ml = dynamic_cast<MultiLayer *>(g->parent()->parent()->parent()); - if (ml && (style == Graph::Unspecified || + if (ml && (style == GraphOptions::Unspecified || ml->applicationWindow()->applyCurveStyleToMantid)) { // FIXME: Style HorizontalSteps does NOT seem to be applied applyStyleChoice(style, ml, lineWidth); diff --git a/MantidPlot/src/Mantid/MantidMDCurve.h b/MantidPlot/src/Mantid/MantidMDCurve.h index d0a31faa0e4900b32985a7e342bc1a9e465040f9..813692275e272ac37ffbd3b73bc7daa4d1a53010 100644 --- a/MantidPlot/src/Mantid/MantidMDCurve.h +++ b/MantidPlot/src/Mantid/MantidMDCurve.h @@ -1,10 +1,10 @@ #ifndef MANTID_MD_CURVE_H #define MANTID_MD_CURVE_H -#include "MantidCurve.h" -#include <boost/shared_ptr.hpp> #include "MantidAPI/IMDWorkspace.h" +#include "MantidCurve.h" #include "MantidQtAPI/MantidQwtIMDWorkspaceData.h" +#include <boost/shared_ptr.hpp> // Forward definitions class MantidUI; @@ -42,7 +42,7 @@ public: /// More complex constructor setting some defaults for the curve MantidMDCurve(const QString &wsName, Graph *g, bool err = false, bool distr = false, - Graph::CurveType style = Graph::HorizontalSteps); + GraphOptions::CurveType style = GraphOptions::HorizontalSteps); /// Copy constructor MantidMDCurve(const MantidMDCurve &c); @@ -90,7 +90,7 @@ private: using PlotCurve::draw; // Avoid Intel compiler warning /// Init the curve - void init(Graph *g, bool distr, Graph::CurveType style) override; + void init(Graph *g, bool distr, GraphOptions::CurveType style) override; /// Handles delete notification void postDeleteHandle(const std::string &wsName) override { diff --git a/MantidPlot/src/Mantid/MantidMatrix.cpp b/MantidPlot/src/Mantid/MantidMatrix.cpp index 0899f9cc2c45b8a10df82c2ce3baf6afdebef48f..886a0030b2f9c13b48cce97f933d4debde37bb3e 100644 --- a/MantidPlot/src/Mantid/MantidMatrix.cpp +++ b/MantidPlot/src/Mantid/MantidMatrix.cpp @@ -1,14 +1,14 @@ -#include "MantidKernel/Logger.h" -#include "MantidMatrixModel.h" #include "MantidMatrix.h" -#include "MantidMatrixFunction.h" -#include "MantidUI.h" -#include "../Graph3D.h" #include "../ApplicationWindow.h" +#include "../Graph3D.h" #include "../Spectrogram.h" +#include "MantidKernel/Logger.h" #include "MantidMatrixDialog.h" +#include "MantidMatrixFunction.h" +#include "MantidMatrixModel.h" +#include "MantidUI.h" #include "Preferences.h" -#include "../pixmaps.h" +#include <MantidQtAPI/pixmaps.h> #include "MantidQtAPI/TSVSerialiser.h" @@ -22,7 +22,6 @@ #include <QScrollBar> -#include <stdlib.h> #include <algorithm> #include <limits> #include <cmath> @@ -712,7 +711,7 @@ void MantidMatrix::attachMultilayer(MultiLayer *ml) { @param type :: The "curve" type. @return Pointer to the created graph. */ -MultiLayer *MantidMatrix::plotGraph2D(Graph::CurveType type) { +MultiLayer *MantidMatrix::plotGraph2D(GraphOptions::CurveType type) { if (numRows() == 1) { QMessageBox::critical(0, "MantidPlot - Error", "Cannot plot a workspace with only one spectrum."); @@ -735,7 +734,8 @@ MultiLayer *MantidMatrix::plotGraph2D(Graph::CurveType type) { } Spectrogram *MantidMatrix::plotSpectrogram(Graph *plot, ApplicationWindow *app, - Graph::CurveType type, bool project, + GraphOptions::CurveType type, + bool project, const ProjectData *const prjData) { app->setPreferences(plot); diff --git a/MantidPlot/src/Mantid/MantidMatrix.h b/MantidPlot/src/Mantid/MantidMatrix.h index a48cc2ad7ba6d3e14740763216b104ef6de38c58..5b227af6a47526c3515c29ca8874e38c0628336a 100644 --- a/MantidPlot/src/Mantid/MantidMatrix.h +++ b/MantidPlot/src/Mantid/MantidMatrix.h @@ -9,29 +9,29 @@ #include "MantidMatrixModel.h" #include "MantidMatrixTabExtension.h" -#include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/FrameworkManager.h" -#include "MantidAPI/MatrixWorkspace_fwd.h" -#include "MantidQtAPI/WorkspaceObserver.h" #include "../ContourLinesEditor.h" #include "../Graph.h" #include "../MdiSubWindow.h" #include "../UserFunction.h" +#include "MantidAPI/AnalysisDataService.h" +#include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/MatrixWorkspace_fwd.h" +#include "MantidQtAPI/WorkspaceObserver.h" #include <Poco/NObserver.h> -#include <QHeaderView> -#include <QTableView> -#include <QPrinter> -#include <QMessageBox> #include <QAction> -#include <QVector> -#include <QThread> +#include <QHeaderView> #include <QMap> +#include <QMessageBox> #include <QPointer> +#include <QPrinter> +#include <QTableView> +#include <QThread> +#include <QVector> -#include <qwt_double_rect.h> #include <qwt_color_map.h> +#include <qwt_double_rect.h> class QLabel; class QStackedWidget; @@ -126,7 +126,7 @@ public: Graph3D *plotGraph3D(int style); // Creates a MultiLayer graph and plots this MantidMatrix as a Spectrogram - MultiLayer *plotGraph2D(Graph::CurveType type); + MultiLayer *plotGraph2D(GraphOptions::CurveType type); void setBinGraph(MultiLayer *ml, Table *t = 0); @@ -162,7 +162,7 @@ public: const std::string &getWorkspaceName(); Spectrogram *plotSpectrogram(Graph *plot, ApplicationWindow *app, - Graph::CurveType type, bool project, + GraphOptions::CurveType type, bool project, const ProjectData *const prjdata); /// Add a multilayer as a dependent mdi sub-window. This method is addeed to /// fix a crash (ticket #5732). diff --git a/MantidPlot/src/Mantid/MantidMatrixCurve.cpp b/MantidPlot/src/Mantid/MantidMatrixCurve.cpp index e231cc577d42f408889bad903721010caac95b6c..bbb80525696f0e63eb499b84f6a8723adb230081 100644 --- a/MantidPlot/src/Mantid/MantidMatrixCurve.cpp +++ b/MantidPlot/src/Mantid/MantidMatrixCurve.cpp @@ -7,11 +7,11 @@ #include "MantidAPI/Axis.h" #include "MantidAPI/MatrixWorkspace.h" -#include "MantidQtAPI/QwtWorkspaceSpectrumData.h" #include "MantidQtAPI/QwtWorkspaceBinData.h" +#include "MantidQtAPI/QwtWorkspaceSpectrumData.h" -#include "../Graph.h" #include "../ApplicationWindow.h" +#include "../Graph.h" #include "../MultiLayer.h" #include "ErrorBarSettings.h" #include "MantidKernel/ReadLock.h" @@ -43,7 +43,7 @@ Mantid::Kernel::Logger g_log("MantidMatrixCurve"); MantidMatrixCurve::MantidMatrixCurve(const QString &, const QString &wsName, Graph *g, int index, IndexDir indexType, bool err, bool distr, - Graph::CurveType style) + GraphOptions::CurveType style) : MantidCurve(err), m_wsName(wsName), m_index(index), m_indexType(indexType) { if (!g) { @@ -67,7 +67,7 @@ MantidMatrixCurve::MantidMatrixCurve(const QString &, const QString &wsName, */ MantidMatrixCurve::MantidMatrixCurve(const QString &wsName, Graph *g, int index, IndexDir indexType, bool err, bool distr, - Graph::CurveType style) + GraphOptions::CurveType style) : MantidCurve(err), m_wsName(wsName), m_index(index), m_indexType(indexType) { init(g, distr, style); @@ -91,7 +91,8 @@ MantidMatrixCurve::MantidMatrixCurve(const MantidMatrixCurve &c) * @param distr :: True for a distribution * @param style :: The curve type to use */ -void MantidMatrixCurve::init(Graph *g, bool distr, Graph::CurveType style) { +void MantidMatrixCurve::init(Graph *g, bool distr, + GraphOptions::CurveType style) { // Will throw if name not found but return NULL ptr if the type is incorrect MatrixWorkspace_const_sptr workspace = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( @@ -152,7 +153,7 @@ void MantidMatrixCurve::init(Graph *g, bool distr, Graph::CurveType style) { int lineWidth = 1; MultiLayer *ml = dynamic_cast<MultiLayer *>(g->parent()->parent()->parent()); - if (ml && (style == Graph::Unspecified || + if (ml && (style == GraphOptions::Unspecified || ml->applicationWindow()->applyCurveStyleToMantid)) { applyStyleChoice(style, ml, lineWidth); } else if (matrixWS->isHistogramData() && !matrixWS->isDistribution()) { diff --git a/MantidPlot/src/Mantid/MantidMatrixCurve.h b/MantidPlot/src/Mantid/MantidMatrixCurve.h index 18ad396dd762578e5d279dc9921171c1df69cfd9..04be27f88d3a3db2ca3ca798df2f2891b5c17dfe 100644 --- a/MantidPlot/src/Mantid/MantidMatrixCurve.h +++ b/MantidPlot/src/Mantid/MantidMatrixCurve.h @@ -1,10 +1,10 @@ #ifndef MANTID_MATRIX_CURVE_H #define MANTID_MATRIX_CURVE_H -#include "MantidCurve.h" -#include <boost/shared_ptr.hpp> #include "MantidAPI/MatrixWorkspace.h" +#include "MantidCurve.h" #include "MantidKernel/Unit.h" +#include <boost/shared_ptr.hpp> // Forward definitions class MantidUI; @@ -53,12 +53,12 @@ public: MantidMatrixCurve(const QString &name, const QString &wsName, Graph *g, int index, IndexDir indexType, bool err = false, bool distr = false, - Graph::CurveType style = Graph::Unspecified); + GraphOptions::CurveType style = GraphOptions::Unspecified); /// More complex constructor setting some defaults for the curve MantidMatrixCurve(const QString &wsName, Graph *g, int index, IndexDir indexType, bool err = false, bool distr = false, - Graph::CurveType style = Graph::Unspecified); + GraphOptions::CurveType style = GraphOptions::Unspecified); /// Copy constructor MantidMatrixCurve(const MantidMatrixCurve &c); @@ -129,7 +129,7 @@ private: using PlotCurve::draw; // Avoid Intel compiler warning /// Init the curve - void init(Graph *g, bool distr, Graph::CurveType style) override; + void init(Graph *g, bool distr, GraphOptions::CurveType style) override; /// Handles delete notification void postDeleteHandle(const std::string &wsName) override { diff --git a/MantidPlot/src/Mantid/MantidUI.cpp b/MantidPlot/src/Mantid/MantidUI.cpp index 1e8ba6c029392a78626faefa303a80f309267d94..9d94ea9d412d8db4741b59e96d07497cbca226f8 100644 --- a/MantidPlot/src/Mantid/MantidUI.cpp +++ b/MantidPlot/src/Mantid/MantidUI.cpp @@ -1,40 +1,43 @@ // Python header must go first #include "MantidQtAPI/PythonThreading.h" -#include "MantidUI.h" -#include "MantidMatrix.h" -#include "MantidDock.h" -#include "ImportWorkspaceDlg.h" -#include "AlgorithmMonitor.h" -#include "MantidSampleLogDialog.h" -#include "MantidSampleMaterialDialog.h" +#include "AlgorithmDockWidget.h" #include "AlgorithmHistoryWindow.h" -#include "MantidMatrixCurve.h" +#include "AlgorithmMonitor.h" +#include "ImportWorkspaceDlg.h" +#include "MantidGroupPlotGenerator.h" #include "MantidMDCurve.h" #include "MantidMDCurveDialog.h" +#include "MantidMatrix.h" +#include "MantidMatrixCurve.h" #include "MantidQtMantidWidgets/FitPropertyBrowser.h" +#include "MantidQtMantidWidgets/MantidSurfacePlotDialog.h" +#include "MantidQtMantidWidgets/MantidWSIndexDialog.h" +#include "MantidSampleLogDialog.h" +#include "MantidSampleMaterialDialog.h" #include "MantidTable.h" +#include "MantidUI.h" #include "ProjectSerialiser.h" #include "../../MantidQt/MantidWidgets/ui_SequentialFitDialog.h" -#include "../Spectrogram.h" -#include "../pixmaps.h" -#include "../ScriptingWindow.h" #include "../Folder.h" +#include "../ScriptingWindow.h" +#include "../Spectrogram.h" #include "../TiledWindow.h" +#include "MantidQtAPI/pixmaps.h" +#include "Mantid/InstrumentWidget/InstrumentWindow.h" #include "MantidAPI/Axis.h" #include "MantidAPI/TextAxis.h" -#include "MantidKernel/Property.h" #include "MantidKernel/ConfigService.h" #include "MantidKernel/DateAndTime.h" +#include "MantidKernel/DateAndTime.h" #include "MantidKernel/EnvironmentHistory.h" #include "MantidKernel/FacilityInfo.h" #include "MantidKernel/LogFilter.h" -#include "Mantid/InstrumentWidget/InstrumentWindow.h" -#include "MantidKernel/DateAndTime.h" -#include "MantidKernel/UnitConversion.h" +#include "MantidKernel/Property.h" #include "MantidKernel/TimeSeriesProperty.h" +#include "MantidKernel/UnitConversion.h" #include "InstrumentWidget/InstrumentWindow.h" @@ -43,25 +46,27 @@ #include "MantidQtAPI/PlotAxis.h" #include "MantidQtAPI/VatesViewerInterface.h" +#include "MantidQtMantidWidgets/MantidTreeWidget.h" +#include "MantidQtMantidWidgets/WorkspacePresenter/QWorkspaceDockView.h" + #include "MantidAPI/CompositeFunction.h" -#include "MantidAPI/ITableWorkspace.h" -#include "MantidAPI/IMDHistoWorkspace.h" #include "MantidAPI/IMDEventWorkspace.h" +#include "MantidAPI/IMDHistoWorkspace.h" #include "MantidAPI/IPeaksWorkspace.h" #include "MantidAPI/Run.h" -#include <QMessageBox> -#include <QTextEdit> #include <QListWidget> #include <QMdiArea> +#include <QMenu> #include <QMenuBar> -#include <QApplication> +#include <QMessageBox> +#include <QMessageBox> +#include <QTextEdit> +#include <QTextEdit> #include <QToolBar> -#include <QMenu> -#include <QInputDialog> -#include <qwt_plot_curve.h> #include <algorithm> +#include <qwt_plot_curve.h> #include <time.h> #ifdef _WIN32 @@ -69,9 +74,9 @@ #endif #include <algorithm> +#include <fstream> #include <locale> #include <set> -#include <fstream> #include <sstream> #include <boost/tokenizer.hpp> @@ -79,8 +84,8 @@ #include <Poco/ActiveResult.h> #include "MantidAPI/IMDWorkspace.h" -#include "MantidQtSliceViewer/SliceViewerWindow.h" #include "MantidQtFactory/WidgetFactory.h" +#include "MantidQtSliceViewer/SliceViewerWindow.h" #include "MantidQtSpectrumViewer/SpectrumView.h" #include <typeinfo> @@ -88,7 +93,11 @@ using namespace std; using namespace Mantid::API; +using namespace MantidQt::API; using namespace MantidQt::MantidWidgets; +using MantidQt::MantidWidgets::MantidWSIndexDialog; +using MantidQt::MantidWidgets::MantidSurfacePlotDialog; +using MantidQt::MantidWidgets::MantidTreeWidget; using Mantid::Kernel::DateAndTime; using MantidQt::SliceViewer::SliceViewerWindow; @@ -157,14 +166,14 @@ bool workspaceIsFitResult(const QString &wsName) { } /// Return curve type for spectrum of a set of fit results -Graph::CurveType getCurveTypeForFitResult(const size_t spectrum) { +GraphOptions::CurveType getCurveTypeForFitResult(const size_t spectrum) { switch (spectrum) { case 0: - return Graph::CurveType::LineSymbols; + return GraphOptions::CurveType::LineSymbols; case 1: - return Graph::CurveType::Line; + return GraphOptions::CurveType::Line; default: - return Graph::CurveType::Unspecified; + return GraphOptions::CurveType::Unspecified; } } } @@ -172,15 +181,6 @@ Graph::CurveType getCurveTypeForFitResult(const size_t spectrum) { MantidUI::MantidUI(ApplicationWindow *aw) : m_finishedLoadDAEObserver(*this, &MantidUI::handleLoadDAEFinishedNotification), - m_addObserver(*this, &MantidUI::handleAddWorkspace), - m_replaceObserver(*this, &MantidUI::handleReplaceWorkspace), - m_deleteObserver(*this, &MantidUI::handleDeleteWorkspace), - m_clearADSObserver(*this, &MantidUI::handleClearADS), - m_renameObserver(*this, &MantidUI::handleRenameWorkspace), - m_groupworkspacesObserver(*this, &MantidUI::handleGroupWorkspaces), - m_ungroupworkspaceObserver(*this, &MantidUI::handleUnGroupWorkspace), - m_workspaceGroupUpdateObserver(*this, - &MantidUI::handleWorkspaceGroupUpdate), m_configServiceObserver(*this, &MantidUI::handleConfigServiceUpdate), m_appWindow(aw), m_lastShownInstrumentWin(NULL), m_lastShownSliceViewWin(NULL), m_lastShownSpectrumViewerWin(NULL), @@ -200,7 +200,8 @@ MantidUI::MantidUI(ApplicationWindow *aw) qRegisterMetaType<std::string>(); } - m_exploreMantid = new MantidDockWidget(this, aw); + m_exploreMantid = boost::make_shared<QWorkspaceDockView>(this, aw); + m_exploreMantid->init(); m_exploreAlgorithms = new AlgorithmDockWidget(this, aw); actionCopyRowToTable = new QAction(this); @@ -263,16 +264,10 @@ MantidUI::MantidUI(ApplicationWindow *aw) SLOT(updateProgress(void *, double, const QString &, double, int)), Qt::QueuedConnection); - connect(this, SIGNAL(ADS_updated()), appWindow(), SLOT(modifiedProject())); m_algMonitor->start(); mantidMenu = new QMenu(m_appWindow); mantidMenu->setObjectName("mantidMenu"); - // for activating the keyboard shortcut for Clear All Memory even if no - // clciking on Mantid Menu - // Ticket #672 - // connect(mantidMenu, SIGNAL(aboutToShow()), this, - // SLOT(mantidMenuAboutToShow())); mantidMenuAboutToShow(); QShortcut *sc = @@ -288,15 +283,6 @@ MantidUI::MantidUI(ApplicationWindow *aw) // Should it be moved to the constructor? void MantidUI::init() { - AnalysisDataServiceImpl &dataStore = AnalysisDataService::Instance(); - dataStore.notificationCenter.addObserver(m_addObserver); - dataStore.notificationCenter.addObserver(m_replaceObserver); - dataStore.notificationCenter.addObserver(m_deleteObserver); - dataStore.notificationCenter.addObserver(m_clearADSObserver); - dataStore.notificationCenter.addObserver(m_renameObserver); - dataStore.notificationCenter.addObserver(m_groupworkspacesObserver); - dataStore.notificationCenter.addObserver(m_ungroupworkspaceObserver); - dataStore.notificationCenter.addObserver(m_workspaceGroupUpdateObserver); Mantid::Kernel::ConfigService::Instance().addObserver( m_configServiceObserver); @@ -334,7 +320,7 @@ void MantidUI::x_range_from_picker(double xmin, double xmax) { void MantidUI::updateAlgorithms() { m_exploreAlgorithms->update(); } /// Updates the workspace tree -void MantidUI::updateWorkspaces() { m_exploreMantid->updateTree(); } +void MantidUI::updateWorkspaces() { m_exploreMantid->refreshWorkspaces(); } /// Show / hide the AlgorithmDockWidget void MantidUI::showAlgWidget(bool on) { @@ -408,20 +394,6 @@ MantidUI::~MantidUI() { Mantid::Kernel::ConfigService::Instance().removeObserver( m_configServiceObserver); - Mantid::API::AnalysisDataService::Instance() - .notificationCenter.removeObserver(m_groupworkspacesObserver); - Mantid::API::AnalysisDataService::Instance() - .notificationCenter.removeObserver(m_ungroupworkspaceObserver); - Mantid::API::AnalysisDataService::Instance() - .notificationCenter.removeObserver(m_workspaceGroupUpdateObserver); - Mantid::API::AnalysisDataService::Instance() - .notificationCenter.removeObserver(m_addObserver); - Mantid::API::AnalysisDataService::Instance() - .notificationCenter.removeObserver(m_replaceObserver); - Mantid::API::AnalysisDataService::Instance() - .notificationCenter.removeObserver(m_deleteObserver); - Mantid::API::AnalysisDataService::Instance() - .notificationCenter.removeObserver(m_clearADSObserver); delete m_fitFunction; } @@ -453,6 +425,10 @@ QStringList MantidUI::getAlgorithmNames() { */ int MantidUI::runningAlgCount() const { return m_algMonitor->count(); } +/** +* Alerts applicationWindow that the ADS has been modified. +*/ +void MantidUI::updateProject() { m_appWindow->modifiedProject(); } /** * Ticket #678 */ @@ -469,8 +445,35 @@ void MantidUI::deleteWorkspace(const QString &workspaceName) { executeAlgorithmAsync(alg); } +void MantidUI::deleteWorkspaces(const QStringList &wsNames) { + MantidMatrix *m = dynamic_cast<MantidMatrix *>(m_appWindow->activeWindow()); + + try { + if (!wsNames.isEmpty()) { + for (auto &ws : wsNames) { + deleteWorkspace(ws); + } + } else if ((m && + (strcmp(m->metaObject()->className(), "MantidMatrix") == 0)) && + !m->workspaceName().isEmpty()) { + deleteWorkspace(m->workspaceName()); + } + } catch (...) { + QMessageBox::warning(m_appWindow, "", + "Could not delete selected workspaces."); + } +} + +/** +getSelectedWorkspaceName +*/ QString MantidUI::getSelectedWorkspaceName() { - QString str = m_exploreMantid->getSelectedWorkspaceName(); + auto names = m_exploreMantid->getSelectedWorkspaceNames(); + QString str; + + if (!names.empty()) + str = QString::fromStdString(names[0]); + if (str.isEmpty()) { // Check if a mantid matrix is selected MantidMatrix *m = qobject_cast<MantidMatrix *>(appWindow()->activeWindow()); @@ -528,7 +531,7 @@ Graph3D *MantidUI::plot3DMatrix(int style) { return 0; } -MultiLayer *MantidUI::plotSpectrogram(Graph::CurveType type) { +MultiLayer *MantidUI::plotSpectrogram(GraphOptions::CurveType type) { MantidMatrix *m = dynamic_cast<MantidMatrix *>(appWindow()->activeWindow()); if (m) { return drawSingleColorFillPlot( @@ -1429,7 +1432,9 @@ MantidUI::createDetectorTable(const QString &wsName, * Triggered by a delete key press, and attempts to delete a workspace if it * passes the focus checks */ -void MantidUI::deletePressEvent() { m_exploreMantid->deleteWorkspaces(); } +void MantidUI::deletePressEvent() { + m_exploreMantid->onClickDeleteWorkspaces(); +} /** * Check if drop event can be accepted @@ -1562,7 +1567,7 @@ void MantidUI::showAlgorithmDialog(const QString &algName, int version) { * attached to the finish notification * @param version :: version number, -1 for latest */ -void MantidUI::showAlgorithmDialog(QString algName, +void MantidUI::showAlgorithmDialog(const QString &algName, QHash<QString, QString> paramList, Mantid::API::AlgorithmObserver *obs, int version) { @@ -1781,10 +1786,8 @@ void MantidUI::groupWorkspaces() { try { std::string sgrpName("NewGroup"); QString qwsGrpName = QString::fromStdString(sgrpName); - std::vector<std::string> inputWSVec; // get selected workspaces - QList<QTreeWidgetItem *> selectedItems = - m_exploreMantid->m_tree->selectedItems(); + auto selectedItems = m_exploreMantid->getSelectedWorkspaceNames(); if (selectedItems.size() < 2) { throw std::runtime_error("Select atleast two workspaces to group "); } @@ -1797,12 +1800,11 @@ void MantidUI::groupWorkspaces() { return; } // - copyWorkspacestoVector(selectedItems, inputWSVec); std::string algName("GroupWorkspaces"); Mantid::API::IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create(algName, 1); alg->initialize(); - alg->setProperty("InputWorkspaces", inputWSVec); + alg->setProperty("InputWorkspaces", selectedItems); alg->setPropertyValue("OutputWorkspace", sgrpName); // execute the algorithm bool bStatus = alg->execute(); @@ -1830,14 +1832,13 @@ void MantidUI::groupWorkspaces() { } void MantidUI::ungroupWorkspaces() { try { - QList<QTreeWidgetItem *> selectedItems = - m_exploreMantid->m_tree->selectedItems(); - if (selectedItems.isEmpty()) { + auto selectedItems = m_exploreMantid->getSelectedWorkspaceNames(); + if (selectedItems.empty()) { throw std::runtime_error("Select a group workspace to Ungroup."); } // workspace name - std::string wsname = selectedItems[0]->text(0).toStdString(); + std::string wsname = selectedItems[0]; std::string algName("UnGroupWorkspace"); Mantid::API::IAlgorithm_sptr alg = @@ -1961,44 +1962,6 @@ void MantidUI::showCritical(const QString &text) { void MantidUI::showAlgMonitor() { m_algMonitor->showDialog(); } -void MantidUI::handleAddWorkspace(Mantid::API::WorkspaceAddNotification_ptr) { - emit ADS_updated(); -} - -void MantidUI::handleReplaceWorkspace( - Mantid::API::WorkspaceAfterReplaceNotification_ptr) { - emit ADS_updated(); -} - -void MantidUI::handleDeleteWorkspace( - Mantid::API::WorkspacePostDeleteNotification_ptr) { - emit ADS_updated(); -} - -void MantidUI::handleClearADS(Mantid::API::ClearADSNotification_ptr) { - emit workspaces_cleared(); -} - -void MantidUI::handleRenameWorkspace( - Mantid::API::WorkspaceRenameNotification_ptr msg) { - emit workspace_renamed(QString::fromStdString(msg->objectName()), - QString::fromStdString(msg->newObjectName())); - emit ADS_updated(); -} -void MantidUI::handleGroupWorkspaces( - Mantid::API::WorkspacesGroupedNotification_ptr) { - emit ADS_updated(); -} -void MantidUI::handleUnGroupWorkspace( - Mantid::API::WorkspaceUnGroupingNotification_ptr) { - emit ADS_updated(); -} - -void MantidUI::handleWorkspaceGroupUpdate( - Mantid::API::GroupUpdatedNotification_ptr) { - emit ADS_updated(); -} - void MantidUI::handleConfigServiceUpdate( Mantid::Kernel::ConfigValChangeNotification_ptr pNf) { if (pNf->key() == "pythonscripts.directories") { @@ -2201,7 +2164,8 @@ void MantidUI::menuMantidMatrixAboutToShow() { menuMantidMatrix->addAction(action); action = new QAction("Plot spectrum...", this); - connect(action, SIGNAL(triggered()), m_exploreMantid, SLOT(plotSpectra())); + connect(action, SIGNAL(triggered()), m_exploreMantid.get(), + SLOT(plotSpectra())); menuMantidMatrix->addAction(action); action = new QAction("Plot as waterfall", this); @@ -2232,7 +2196,7 @@ void MantidUI::menuMantidMatrixAboutToShow() { menuMantidMatrix->addSeparator(); action = new QAction("Delete", this); - connect(action, SIGNAL(triggered()), m_exploreMantid, + connect(action, SIGNAL(triggered()), m_exploreMantid.get(), SLOT(deleteWorkspaces())); menuMantidMatrix->addAction(action); } @@ -2687,7 +2651,7 @@ void MantidUI::importNumSeriesLog(const QString &wsName, const QString &logName, colNames << t->colName(3); } colNames << t->colName(1); - MultiLayer *ml = appWindow()->multilayerPlot(t, colNames, Graph::Line); + MultiLayer *ml = appWindow()->multilayerPlot(t, colNames, GraphOptions::Line); // ml->askOnCloseEvent(false); ml->setAttribute(Qt::WA_DeleteOnClose); @@ -2923,7 +2887,7 @@ MultiLayer *MantidUI::createGraphFromTable(Table *t, int type) { } } - MultiLayer *ml = appWindow()->multilayerPlot(t, lst, Graph::Line); + MultiLayer *ml = appWindow()->multilayerPlot(t, lst, GraphOptions::Line); Graph *g = ml->activeGraph(); appWindow()->polishGraph(g, type); for (int i = 0; i < g->curves(); i++) @@ -2966,8 +2930,9 @@ Ignored if plotWindow == NULL MultiLayer *MantidUI::plot1D(const QStringList &ws_names, const QList<int> &indexList, bool spectrumPlot, MantidQt::DistributionFlag distr, bool errs, - Graph::CurveType style, MultiLayer *plotWindow, - bool clearWindow, bool waterfallPlot) { + GraphOptions::CurveType style, + MultiLayer *plotWindow, bool clearWindow, + bool waterfallPlot) { // Convert the list into a map (with the same workspace as key in each case) QMultiMap<QString, int> pairs; QListIterator<QString> ws_itr(ws_names); @@ -3020,7 +2985,7 @@ MultiLayer *MantidUI::plot1D(const QMultiMap<QString, set<int>> &toPlot, } // Pass over to the overloaded method - return plot1D(pairs, spectrumPlot, distr, errs, Graph::Unspecified, + return plot1D(pairs, spectrumPlot, distr, errs, GraphOptions::Unspecified, plotWindow, clearWindow, waterfallPlot); } @@ -3051,7 +3016,7 @@ MultiLayer *MantidUI::plot1D(const QString &wsName, } // Pass over to the overloaded method - return plot1D(pairs, spectrumPlot, distr, errs, Graph::Unspecified, + return plot1D(pairs, spectrumPlot, distr, errs, GraphOptions::Unspecified, plotWindow, clearWindow, waterfallPlot); } @@ -3071,8 +3036,9 @@ not NULL - plotWindow MultiLayer *MantidUI::plot1D(const QMultiMap<QString, int> &toPlot, bool spectrumPlot, MantidQt::DistributionFlag distr, bool errs, - Graph::CurveType style, MultiLayer *plotWindow, - bool clearWindow, bool waterfallPlot) { + GraphOptions::CurveType style, + MultiLayer *plotWindow, bool clearWindow, + bool waterfallPlot) { if (toPlot.size() == 0) return NULL; @@ -3230,7 +3196,7 @@ void MantidUI::showSequentialPlot( * @param curveType :: The curve type for each of the plots */ void MantidUI::drawColorFillPlots(const QStringList &wsNames, - Graph::CurveType curveType) { + GraphOptions::CurveType curveType) { int nPlots = wsNames.size(); if (nPlots > 1) { QList<MultiLayer *> plots; @@ -3293,7 +3259,7 @@ void MantidUI::drawColorFillPlots(const QStringList &wsNames, * @returns A pointer to the created plot */ MultiLayer *MantidUI::drawSingleColorFillPlot(const QString &wsName, - Graph::CurveType curveType, + GraphOptions::CurveType curveType, MultiLayer *window, bool hidden) { auto workspace = boost::dynamic_pointer_cast<const Mantid::API::MatrixWorkspace>( @@ -3545,8 +3511,8 @@ void MantidUI::plotLayerOfMultilayer(MultiLayer *multi, const bool plotErrors, QString legendText = wsName + '\n'; int curveIndex(0); for (const int spec : spectra) { - const auto plotType = - isFitResult ? getCurveTypeForFitResult(spec) : Graph::Unspecified; + const auto plotType = isFitResult ? getCurveTypeForFitResult(spec) + : GraphOptions::Unspecified; layer->insertCurve(wsName, spec, plotErrors, plotType, plotDist); legendText += "\\l(" + QString::number(++curveIndex) + ")" + getLegendKey(wsName, spec) + "\n"; @@ -3733,7 +3699,12 @@ bool MantidUI::workspacesDockPlot1To1() { * @returns :: Name of selected workspace group, or empty if no group selected */ QString MantidUI::getSelectedGroupName() const { - const QString &sel = m_exploreMantid->getSelectedWorkspaceName(); + auto selNames = m_exploreMantid->getSelectedWorkspaceNames(); + QString sel; + + if (selNames.size() > 0) + sel = QString::fromStdString(selNames[0]); + WorkspaceGroup_const_sptr gWs; if (!sel.isEmpty() && AnalysisDataService::Instance().doesExist(sel.toStdString())) { @@ -3887,7 +3858,7 @@ void MantidUI::memoryImage() { } } } - appWindow()->plotSpectrogram(m, Graph::ColorMap); + appWindow()->plotSpectrogram(m, GraphOptions::ColorMap); } void MantidUI::memoryImage2() { @@ -3954,3 +3925,77 @@ void MantidUI::test() { } std::cerr << "Failed...\n"; } + +void MantidUI::updateRecentFilesList(const QString &fname) { + m_appWindow->updateRecentFilesList(fname); +} + +MantidSurfacePlotDialog * +MantidUI::createSurfacePlotDialog(int flags, QStringList wsNames, + const QString &plotType) { + QList<QString> names; + + for (auto &name : wsNames) + names.append(name); + + return new MantidSurfacePlotDialog(this, static_cast<Qt::WFlags>(flags), + names, plotType); +} + +MantidWSIndexDialog *MantidUI::createWorkspaceIndexDialog(int flags, + QStringList wsNames, + bool showWaterfall, + bool showPlotAll) { + QList<QString> names; + + for (auto &name : wsNames) + names.append(name); + + return new MantidWSIndexDialog(m_appWindow, static_cast<Qt::WFlags>(flags), + names, showWaterfall, showPlotAll); +} + +void MantidUI::showSurfacePlot() { + // find the workspace group clicked on + auto wksp = m_exploreMantid->getSelectedWorkspace(); + + if (wksp) { + const auto wsGroup = + boost::dynamic_pointer_cast<const WorkspaceGroup>(wksp); + if (wsGroup) { + auto options = m_exploreMantid->chooseSurfacePlotOptions( + wsGroup->getNumberOfEntries()); + + // TODO: Figure out how to get rid of MantidUI dependency here. + auto plotter = + Mantid::Kernel::make_unique<MantidGroupPlotGenerator>(this); + plotter->plotSurface(wsGroup, options); + } + } +} + +void MantidUI::showContourPlot() { + auto wksp = m_exploreMantid->getSelectedWorkspace(); + + if (wksp) { + const auto wsGroup = + boost::dynamic_pointer_cast<const WorkspaceGroup>(wksp); + if (wsGroup) { + auto options = m_exploreMantid->chooseContourPlotOptions( + wsGroup->getNumberOfEntries()); + + // TODO: Figure out how to remove the MantidUI dependency + auto plotter = + Mantid::Kernel::make_unique<MantidGroupPlotGenerator>(this); + plotter->plotContour(wsGroup, options); + } + } +} + +QWidget *MantidUI::getParent() { return m_appWindow; } + +#ifdef MAKE_VATES +bool MantidUI::doesVatesSupportOpenGL() { + return vtkPVDisplayInformation::SupportsOpenGLLocally(); +} +#endif \ No newline at end of file diff --git a/MantidPlot/src/Mantid/MantidUI.h b/MantidPlot/src/Mantid/MantidUI.h index c7f642c7dc85059fc3b87a70525c2cc3ca4cf051..23b2dda0dd6eff2b6593144380d2b8128ac6effd 100644 --- a/MantidPlot/src/Mantid/MantidUI.h +++ b/MantidPlot/src/Mantid/MantidUI.h @@ -7,38 +7,42 @@ #include "../ApplicationWindow.h" #include "../Graph.h" #include "MantidQtAPI/IProjectSerialisable.h" +#include "MantidQtMantidWidgets/MantidDisplayBase.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/Algorithm.h" -#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AlgorithmFactory.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" +#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/IMDWorkspace.h" #include "MantidAPI/IPeaksWorkspace_fwd.h" #include "MantidAPI/MatrixWorkspace_fwd.h" #include "MantidAPI/Workspace_fwd.h" #include "MantidQtAPI/AlgorithmDialog.h" -#include "MantidQtAPI/QwtWorkspaceSpectrumData.h" #include "MantidQtAPI/MantidAlgorithmMetatype.h" +#include "MantidQtAPI/QwtWorkspaceSpectrumData.h" #include <Poco/NObserver.h> #include <QApplication> #include <QDockWidget> -#include <QTreeWidget> -#include <QProgressDialog> #include <QMap> #include <QMutex> +#include <QProgressDialog> +#include <QTreeWidget> #include <unordered_map> +#ifdef MAKE_VATES +#include "vtkPVDisplayInformation.h" +#endif + //---------------------------------- // Forward declarations //---------------------------------- class Graph3D; class ScriptingEnv; class MantidMatrix; -class MantidDockWidget; class AlgorithmDockWidget; class RemoteClusterDockWidget; class AlgorithmMonitor; @@ -50,6 +54,7 @@ class Message; } namespace MantidWidgets { class FitPropertyBrowser; +class QWorkspaceDockView; } namespace SliceViewer { class SliceViewerWindow; @@ -102,7 +107,8 @@ Code Documentation is available at: <http://doxygen.mantidproject.org> Q_DECLARE_METATYPE(Mantid::API::MatrixWorkspace_sptr) Q_DECLARE_METATYPE(Mantid::API::MatrixWorkspace_const_sptr) -class MantidUI : public QObject { +class MantidUI : public QObject, + public MantidQt::MantidWidgets::MantidDisplayBase { Q_OBJECT public: @@ -136,27 +142,38 @@ public: // Returns the number of algorithms currently executing int runningAlgCount() const; + void updateProject() override; // Create an algorithm using Mantid FrameworkManager // Create a pointer to the named algorithm and version Mantid::API::IAlgorithm_sptr createAlgorithm(const QString &algName, - int version = -1); + int version = -1) override; // Execute algorithm asinchronously bool executeAlgorithmAsync(Mantid::API::IAlgorithm_sptr alg, - const bool wait = false); + const bool wait = false) override; // Gets a pointer to workspace workspaceName - Mantid::API::Workspace_const_sptr getWorkspace(const QString &workspaceName); + Mantid::API::Workspace_const_sptr + getWorkspace(const QString &workspaceName) override; + + QWidget *getParent() override; // Deletes workspace from QtiPlot void deleteWorkspace(const QString &workspaceName); + // Delete multiple workspaces from QtiPlot + void deleteWorkspaces(const QStringList &wsNames = QStringList()) override; + // Returns the name of selected workspace in exploreMantid window QString getSelectedWorkspaceName(); // Returns the pointer of workspace selected in exploreMantid window Mantid::API::Workspace_const_sptr getSelectedWorkspace(); + // Convenience method for updating the list of recent filenames in + // ApplicationWindow + void updateRecentFilesList(const QString &fname) override; + // Returns the name and version of the algorithm selected in algorithm dock // window void getSelectedAlgorithm(QString &algName, int &version); @@ -180,7 +197,7 @@ public: Graph3D *plot3DMatrix(int style); // Creates a 2D plot in QtiPlot if the active window is a MantidMatrix - MultiLayer *plotSpectrogram(Graph::CurveType type); + MultiLayer *plotSpectrogram(GraphOptions::CurveType type); /// Create a Table form specified spectra in a MatrixWorkspace Table *createTableFromSpectraList(const QString &tableName, @@ -192,6 +209,12 @@ public: // Table. Table *createTableFromSelectedRows(MantidMatrix *m, bool errs = true, bool binCentres = false); + MantidQt::MantidWidgets::MantidSurfacePlotDialog * + createSurfacePlotDialog(int flags, QStringList wsNames, + const QString &plotType) override; + MantidQt::MantidWidgets::MantidWSIndexDialog * + createWorkspaceIndexDialog(int flags, QStringList wsNames, bool showWaterfall, + bool showPlotAll) override; /// Create a 1d graph form a Table MultiLayer *createGraphFromTable(Table *t, int type = 0); @@ -235,13 +258,21 @@ public: MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, bool errs = false, MultiLayer *plotWindow = nullptr); + void showSurfacePlot() override; + void showContourPlot() override; + +#ifdef MAKE_VATES + bool doesVatesSupportOpenGL() override; +#endif + public slots: // Create a 1d graph form specified MatrixWorkspace and index MultiLayer * plot1D(const QStringList &wsnames, const QList<int> &indexList, bool spectrumPlot, MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, - bool errs = true, Graph::CurveType style = Graph::Unspecified, + bool errs = true, + GraphOptions::CurveType style = GraphOptions::Unspecified, MultiLayer *plotWindow = NULL, bool clearWindow = false, bool waterfallPlot = false); @@ -255,7 +286,8 @@ public slots: MultiLayer * plot1D(const QMultiMap<QString, int> &toPlot, bool spectrumPlot, MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, - bool errs = false, Graph::CurveType style = Graph::Unspecified, + bool errs = false, + GraphOptions::CurveType style = GraphOptions::Unspecified, MultiLayer *plotWindow = NULL, bool clearWindow = false, bool waterfallPlot = false); @@ -263,16 +295,17 @@ public slots: plot1D(const QMultiMap<QString, std::set<int>> &toPlot, bool spectrumPlot, MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, bool errs = false, MultiLayer *plotWindow = NULL, - bool clearWindow = false, bool waterfallPlot = false); + bool clearWindow = false, bool waterfallPlot = false) override; /// Draw a color fill plot for each of the listed workspaces - void drawColorFillPlots(const QStringList &wsNames, - Graph::CurveType curveType = Graph::ColorMap); + void drawColorFillPlots( + const QStringList &wsNames, + GraphOptions::CurveType curveType = GraphOptions::ColorMap) override; /// Draw a color fill plot for the named workspace - MultiLayer * - drawSingleColorFillPlot(const QString &wsName, - Graph::CurveType curveType = Graph::ColorMap, - MultiLayer *window = NULL, bool hidden = false); + MultiLayer *drawSingleColorFillPlot( + const QString &wsName, + GraphOptions::CurveType curveType = GraphOptions::ColorMap, + MultiLayer *window = NULL, bool hidden = false); // Create a 1d graph form specified spectra in a MatrixWorkspace MultiLayer *plotSpectraRange( @@ -305,7 +338,7 @@ public slots: /// indices and optionally the data for that detector Table *createDetectorTable(const QString &wsName, const std::vector<int> &indices, - bool include_data = false); + bool include_data = false) override; /// Create the instrument detector table from a MatrixWorkspace Table *createDetectorTable(const QString &wsName, const Mantid::API::MatrixWorkspace_sptr &ws, @@ -322,7 +355,7 @@ public slots: // Clear the UB via the ClearUB algorithm void clearUB(const QStringList &workspaces); // ***** ***** // - void renameWorkspace(QStringList = QStringList()); + void renameWorkspace(QStringList = QStringList()) override; /** * Set the currently used fit property browser. Is needed because e.g. Muon @@ -361,8 +394,8 @@ public: void loadWSFromFile(const std::string &wsname, const std::string &fileName); void saveProject(bool save); - void enableSaveNexus(const QString &wsName); - void disableSaveNexus(); + void enableSaveNexus(const QString &wsName) override; + void disableSaveNexus() override; signals: // A signal to indicate that we want a script to produce a dialog @@ -377,10 +410,6 @@ signals: // main one // (e.g. handlers of algorithm notifications) - void workspaces_cleared(); - void ADS_updated(); - void workspace_renamed(QString, QString); - void needToCreateLoadDAEMantidMatrix(const QString &); // Display a critical error dialog box @@ -400,31 +429,31 @@ public slots: MantidQt::MantidWidgets::FitPropertyBrowser *fitbrowser); // Import the workspace selected in the Workspace dock window - void importWorkspace(); - void importBoxDataTable(); - void importTransposed(); + void importWorkspace() override; + void importBoxDataTable() override; + void importTransposed() override; // Invoke the Vates Simple User Interface - void showVatesSimpleInterface(); + void showVatesSimpleInterface() override; // Invoke the plot of MD intensity vs non-integrated dimension. - void showMDPlot(); + void showMDPlot() override; // Invoke a grid showing a table of MD summary list data. - void showListData(); + void showListData() override; // SpectrumViewer - void showSpectrumViewer(); + void showSpectrumViewer() override; // SliceViewer - void showSliceViewer(); + void showSliceViewer() override; // #539: For adding Workspace History display to MantidPlot - void showAlgorithmHistory(); + void showAlgorithmHistory() override; // Import a workspace wsName void importWorkspace(const QString &wsName, bool showDlg = true, - bool makeVisible = true); + bool makeVisible = true) override; // Create a MantidMatrix from workspace wsName MantidMatrix *importMatrixWorkspace(const QString &wsName, int lower = -1, @@ -434,7 +463,8 @@ public slots: // Create a MantidMatrix from workspace MantidMatrix * importMatrixWorkspace(const Mantid::API::MatrixWorkspace_sptr workspace, - int lower = -1, int upper = -1, bool showDlg = true); + int lower = -1, int upper = -1, + bool showDlg = true) override; // Create a Table from workspace wsName Table *importTableWorkspace(const QString &wsName, bool showDlg = true, @@ -458,13 +488,14 @@ public slots: void convertToWaterfall(MultiLayer *ml); // Execute algorithm given name and version - void showAlgorithmDialog(const QString &algName, int version = -1); + void showAlgorithmDialog(const QString &algName, int version = -1) override; // Execute an algorithm with the given parameter list - void showAlgorithmDialog(QString algName, QHash<QString, QString> paramList, + void showAlgorithmDialog(const QString &algName, + QHash<QString, QString> paramList, Mantid::API::AlgorithmObserver *obs = NULL, - int version = -1); + int version = -1) override; // Execute an algorithm - void executeAlgorithm(Mantid::API::IAlgorithm_sptr alg); + void executeAlgorithm(Mantid::API::IAlgorithm_sptr alg) override; // Find the name of the first input workspace for an algorithm QString @@ -484,16 +515,16 @@ public slots: void showMantidInstrument(); // Show instrument for the selected workspace - void showMantidInstrumentSelected(); + void showMantidInstrumentSelected() override; // Show instrument. Workspace name is passed as the argument void showMantidInstrument(const QString &); // Show log files for selected workspace - void showLogFileWindow(); + void showLogFileWindow() override; // Show sample material window for selected workspace - void showSampleMaterialWindow(); + void showSampleMaterialWindow() override; void insertMenu(); @@ -543,47 +574,6 @@ private: Poco::NObserver<MantidUI, Mantid::API::Algorithm::FinishedNotification> m_finishedLoadDAEObserver; - void handleAddWorkspace(Mantid::API::WorkspaceAddNotification_ptr pNf); - Poco::NObserver<MantidUI, Mantid::API::WorkspaceAddNotification> - m_addObserver; - - void handleReplaceWorkspace( - Mantid::API::WorkspaceAfterReplaceNotification_ptr pNf); - Poco::NObserver<MantidUI, Mantid::API::WorkspaceAfterReplaceNotification> - m_replaceObserver; - - void - handleDeleteWorkspace(Mantid::API::WorkspacePostDeleteNotification_ptr pNf); - Poco::NObserver<MantidUI, Mantid::API::WorkspacePostDeleteNotification> - m_deleteObserver; - - void handleClearADS(Mantid::API::ClearADSNotification_ptr pNf); - Poco::NObserver<MantidUI, Mantid::API::ClearADSNotification> - m_clearADSObserver; - - // handles rename workspace notification - void handleRenameWorkspace(Mantid::API::WorkspaceRenameNotification_ptr pNf); - Poco::NObserver<MantidUI, Mantid::API::WorkspaceRenameNotification> - m_renameObserver; - - // handles notification send by Groupworkspaces algorithm - void - handleGroupWorkspaces(Mantid::API::WorkspacesGroupedNotification_ptr pNf); - Poco::NObserver<MantidUI, Mantid::API::WorkspacesGroupedNotification> - m_groupworkspacesObserver; - - // handles notification send by UnGroupworkspaces algorithm - void - handleUnGroupWorkspace(Mantid::API::WorkspaceUnGroupingNotification_ptr pNf); - Poco::NObserver<MantidUI, Mantid::API::WorkspaceUnGroupingNotification> - m_ungroupworkspaceObserver; - - // handles notification send by a WorkspaceGroup instance - void - handleWorkspaceGroupUpdate(Mantid::API::GroupUpdatedNotification_ptr pNf); - Poco::NObserver<MantidUI, Mantid::API::GroupUpdatedNotification> - m_workspaceGroupUpdateObserver; - // handles notification send by ConfigService, change on // pythonscripts.directories void handleConfigServiceUpdate( @@ -632,8 +622,9 @@ private: // Private variables - ApplicationWindow *m_appWindow; // QtiPlot main ApplicationWindow - MantidDockWidget *m_exploreMantid; // Dock window for manipulating workspaces + ApplicationWindow *m_appWindow; // QtiPlot main ApplicationWindow + boost::shared_ptr<MantidQt::MantidWidgets::QWorkspaceDockView> + m_exploreMantid; // Dock window for manipulating workspaces AlgorithmDockWidget *m_exploreAlgorithms; // Dock window for using algorithms RemoteClusterDockWidget * m_exploreRemoteTasks; // Dock window for using remote tasks diff --git a/MantidPlot/src/Mantid/PeakPickerTool.cpp b/MantidPlot/src/Mantid/PeakPickerTool.cpp index c12ec30569f8fef53da162f68e3b139cd81917eb..084ff8b1e0b6b1a27ed0e3778f8c9c7cd0ee0260 100644 --- a/MantidPlot/src/Mantid/PeakPickerTool.cpp +++ b/MantidPlot/src/Mantid/PeakPickerTool.cpp @@ -1,26 +1,26 @@ #include "PeakPickerTool.h" +#include "../FunctionCurve.h" #include "MantidMatrixCurve.h" -#include "MantidUI.h" #include "MantidQtMantidWidgets/FitPropertyBrowser.h" #include "MantidQtMantidWidgets/MuonFitPropertyBrowser.h" -#include "../FunctionCurve.h" #include "MantidQtMantidWidgets/PropertyHandler.h" +#include "MantidUI.h" #include "MantidAPI/CompositeFunction.h" -#include "MantidAPI/IPeakFunction.h" #include "MantidAPI/FunctionFactory.h" +#include "MantidAPI/IPeakFunction.h" #include "MantidKernel/Exception.h" #include "MantidKernel/Logger.h" #include "qwt_painter.h" -#include <QPainter> -#include <QList> -#include <QToolBar> #include <QAction> -#include <QMenu> -#include <QMouseEvent> #include <QInputDialog> +#include <QList> +#include <QMenu> #include <QMessageBox> +#include <QMouseEvent> +#include <QPainter> +#include <QToolBar> namespace { /// static logger @@ -532,7 +532,7 @@ void PeakPickerTool::algorithmFinished(const QString &out) { // and change to line. auto *curve = new MantidMatrixCurve("", out, graph(), 1, MantidMatrixCurve::Spectrum, - false, m_shouldBeNormalised, Graph::Line); + false, m_shouldBeNormalised, GraphOptions::Line); m_curveNames.append(curve->title().text()); if (m_fitPropertyBrowser->plotDiff()) { curve = diff --git a/MantidPlot/src/Matrix.cpp b/MantidPlot/src/Matrix.cpp index f7f89b4092a5157e6597cdffddf3ded27ce8f869..8e46d83879f5b9d804e17c98e2f794e82b380f8d 100644 --- a/MantidPlot/src/Matrix.cpp +++ b/MantidPlot/src/Matrix.cpp @@ -30,49 +30,50 @@ #include "ApplicationWindow.h" #include "Graph.h" -#include "muParserScript.h" #include "MantidKernel/Strings.h" +#include "MantidQtAPI/TSVSerialiser.h" #include "MatrixCommand.h" -#include "pixmaps.h" #include "ScriptingEnv.h" -#include "MantidQtAPI/TSVSerialiser.h" +#include "muParserScript.h" +#include <MantidQtAPI/pixmaps.h> -#include <QtGlobal> -#include <QTextStream> -#include <QList> -#include <QEvent> -#include <QContextMenuEvent> -#include <QVBoxLayout> -#include <QMouseEvent> -#include <QHeaderView> #include <QApplication> -#include <QVarLengthArray> #include <QClipboard> -#include <QShortcut> -#include <QPrinter> -#include <QPrintDialog> -#include <QPainter> -#include <QLocale> +#include <QContextMenuEvent> +#include <QEvent> +#include <QFile> +#include <QHeaderView> +#include <QImageWriter> #include <QItemDelegate> #include <QLabel> +#include <QList> +#include <QLocale> +#include <QMouseEvent> +#include <QPainter> +#include <QPrintDialog> +#include <QPrinter> +#include <QShortcut> #include <QStackedWidget> -#include <QImageWriter> #include <QSvgGenerator> -#include <QFile> +#include <QTextStream> #include <QUndoStack> +#include <QVBoxLayout> +#include <QVarLengthArray> +#include <QtGlobal> #include <boost/algorithm/string.hpp> -#include <stdlib.h> #include <stdio.h> +#include <stdlib.h> -#include <gsl/gsl_math.h> #include <gsl/gsl_linalg.h> +#include <gsl/gsl_math.h> // Register the window into the WindowFactory DECLARE_WINDOW(Matrix) using namespace Mantid; +using namespace MantidQt::API; Matrix::Matrix(ScriptingEnv *env, const QString &label, QWidget *parent, const QString &name, Qt::WFlags f) diff --git a/MantidPlot/src/MultiLayer.cpp b/MantidPlot/src/MultiLayer.cpp index 284537bd137ed45faff60570a8a72f1b782fbcb5..04f45975ba2afa0af14a0723fb7caff33c310c5a 100644 --- a/MantidPlot/src/MultiLayer.cpp +++ b/MantidPlot/src/MultiLayer.cpp @@ -27,21 +27,21 @@ * Boston, MA 02110-1301 USA * * * ***************************************************************************/ -#include <QVector> -#include <QWidgetList> -#include <QPrinter> -#include <QPrintDialog> #include <QApplication> -#include <QMessageBox> #include <QBitmap> +#include <QCheckBox> +#include <QClipboard> +#include <QGroupBox> #include <QImageWriter> +#include <QMessageBox> #include <QPainter> #include <QPicture> -#include <QClipboard> -#include <QCheckBox> -#include <QGroupBox> -#include <QSpinBox> +#include <QPrintDialog> +#include <QPrinter> #include <QSize> +#include <QSpinBox> +#include <QVector> +#include <QWidgetList> #include <cmath> #include <limits> @@ -57,21 +57,22 @@ #include <qwt_scale_widget.h> #include <qwt_text_label.h> +#include "ApplicationWindow.h" +#include "LegendWidget.h" #include "MultiLayer.h" #include "Plot.h" -#include "LegendWidget.h" #include "SelectionMoveResizer.h" -#include "ApplicationWindow.h" #include <ColorButton.h> -#include "Mantid/MantidDock.h" -#include "Mantid/MantidMatrixCurve.h" #include "Mantid/MantidMDCurve.h" +#include "Mantid/MantidMatrixCurve.h" +#include <MantidQtMantidWidgets/MantidTreeWidget.h> -#include <gsl/gsl_vector.h> #include "Mantid/MantidMDCurveDialog.h" -#include "Mantid/MantidWSIndexDialog.h" #include "MantidQtSliceViewer/LinePlotOptions.h" +#include <MantidQtMantidWidgets/MantidTreeWidget.h> +#include <MantidQtMantidWidgets/MantidWSIndexDialog.h> +#include <gsl/gsl_vector.h> #include "MantidQtAPI/TSVSerialiser.h" @@ -79,6 +80,7 @@ DECLARE_WINDOW(MultiLayer) using namespace Mantid; +using namespace MantidQt::MantidWidgets; namespace { /// static logger diff --git a/MantidPlot/src/MultiLayer.h b/MantidPlot/src/MultiLayer.h index 893710c22927be8255baf1cf4bb29b8ce6f76ceb..af1f3cddaa36d324365bbab832e254bc14e6aed7 100644 --- a/MantidPlot/src/MultiLayer.h +++ b/MantidPlot/src/MultiLayer.h @@ -43,12 +43,17 @@ class QLabel; class LayerButton; class SelectionMoveResizer; class LegendWidget; -class MantidTreeWidget; class MantidMDCurve; class MantidMatrixCurve; class QSize; class WaterfallFillDialog; +namespace MantidQt { +namespace MantidWidgets { +class MantidTreeWidget; +} +} + /** * \brief An MDI window (MdiSubWindow) managing one or more Graph objects. * @@ -222,10 +227,10 @@ signals: private: /// Handle dropping of additional curves onto a MantidMDCurve. void dropOntoMDCurve(Graph *g, MantidMDCurve *originalCurve, - MantidTreeWidget *tree); + MantidQt::MantidWidgets::MantidTreeWidget *tree); /// Handle dropping of additional curves onto a MantidMatrixCurve void dropOntoMatrixCurve(Graph *g, MantidMatrixCurve *originalCurve, - MantidTreeWidget *tree); + MantidQt::MantidWidgets::MantidTreeWidget *tree); //! \name Event Handlers //@{ diff --git a/MantidPlot/src/MultiPeakFit.cpp b/MantidPlot/src/MultiPeakFit.cpp index 276e647acfbe8c4bf4376d4545bddc26eb601197..0c4430690f7b455e77d26bc123ddc5e05911637d 100644 --- a/MantidPlot/src/MultiPeakFit.cpp +++ b/MantidPlot/src/MultiPeakFit.cpp @@ -29,11 +29,11 @@ * * ***************************************************************************/ #include "MultiPeakFit.h" -#include "fit_gsl.h" -#include "PlotCurve.h" -#include "FunctionCurve.h" #include "ColorBox.h" +#include "FunctionCurve.h" #include "MultiLayer.h" +#include "PlotCurve.h" +#include "fit_gsl.h" #include <gsl/gsl_statistics.h> @@ -232,7 +232,7 @@ void MultiPeakFit::insertPeakFunctionCurve(double *x, double *y, int peak) { } c->setFormula( formula.replace("--", "+").replace("-+", "-").replace("+-", "-")); - d_output_graph->insertPlotItem(c, Graph::Line); + d_output_graph->insertPlotItem(c, GraphOptions::Line); d_output_graph->addFitCurve(c); } @@ -355,7 +355,7 @@ void MultiPeakFit::generateFitCurve() { else c->setPen(QPen(ColorBox::color(d_curveColorIndex), 1)); c->setData(X.data(), Y.data(), d_points); // c->setData(X, Y, d_points); - d_output_graph->insertPlotItem(c, Graph::Line); + d_output_graph->insertPlotItem(c, GraphOptions::Line); d_output_graph->addFitCurve(c); if (generate_peak_curves) { @@ -368,7 +368,7 @@ void MultiPeakFit::generateFitCurve() { c->setPen(QPen(ColorBox::color(d_peaks_color), 1)); c->setData(X.data(), Y.data(), d_points); // c->setData(X, Y, d_points); - d_output_graph->insertPlotItem(c, Graph::Line); + d_output_graph->insertPlotItem(c, GraphOptions::Line); d_output_graph->addFitCurve(c); } } diff --git a/MantidPlot/src/MultiPeakFitTool.cpp b/MantidPlot/src/MultiPeakFitTool.cpp index c79cb713aba4cac88bbae1f72e78ce2bf188491d..7b6d161f747d7f997e712edb7fe7735d68dba90c 100644 --- a/MantidPlot/src/MultiPeakFitTool.cpp +++ b/MantidPlot/src/MultiPeakFitTool.cpp @@ -29,17 +29,19 @@ * * ***************************************************************************/ #include "MultiPeakFitTool.h" -#include "RangeSelectorTool.h" #include "ApplicationWindow.h" #include "DataPickerTool.h" #include "Plot.h" +#include "RangeSelectorTool.h" #include "cursors.h" -#include <qwt_plot_curve.h> #include <QApplication> +#include <qwt_plot_curve.h> #include <gsl/gsl_statistics.h> +using namespace MantidQt::API; + MultiPeakFitTool::MultiPeakFitTool(Graph *graph, ApplicationWindow *app, MultiPeakFit::PeakProfile profile, int num_peaks, const QObject *status_target, diff --git a/MantidPlot/src/Plot.cpp b/MantidPlot/src/Plot.cpp index 7187075685ee455f10f8756fb152cecfddbf93ff..a3be139f0c2e782496fc8e6fc505a8db820d4456 100644 --- a/MantidPlot/src/Plot.cpp +++ b/MantidPlot/src/Plot.cpp @@ -27,26 +27,26 @@ * Boston, MA 02110-1301 USA * * * ***************************************************************************/ -#include "MantidQtAPI/qwt_compat.h" #include "Plot.h" #include "Graph.h" #include "Grid.h" -#include "ScaleDraw.h" -#include "Spectrogram.h" -#include "PlotCurve.h" #include "LegendWidget.h" #include "MantidQtAPI/ScaleEngine.h" +#include "MantidQtAPI/qwt_compat.h" +#include "PlotCurve.h" +#include "ScaleDraw.h" +#include "Spectrogram.h" -#include <qwt_plot.h> #include <qwt_painter.h> +#include <qwt_plot.h> #include <qwt_plot_canvas.h> #include <qwt_plot_layout.h> -#include <qwt_scale_widget.h> #include <qwt_scale_map.h> +#include <qwt_scale_widget.h> #include <qwt_text_label.h> -#include <QPainter> #include <QMessageBox> +#include <QPainter> #include <limits> @@ -503,7 +503,7 @@ int Plot::closestCurve(int xpos, int ypos, int &dist, int &point) { PlotCurve *c = static_cast<PlotCurve *>(item); DataCurve *dc = dynamic_cast<DataCurve *>(item); if (dc) { - if (c->type() != Graph::Function && dc->hasLabels() && + if (c->type() != GraphOptions::Function && dc->hasLabels() && dc->selectedLabels(QPoint(xpos, ypos))) { dist = 0; return iter.key(); @@ -515,7 +515,7 @@ int Plot::closestCurve(int xpos, int ypos, int &dist, int &point) { double cx = map[c->xAxis()].xTransform(c->x(i)) - double(xpos); double cy = map[c->yAxis()].xTransform(c->y(i)) - double(ypos); double f = qwtSqr(cx) + qwtSqr(cy); - if (f < dmin && c->type() != Graph::ErrorBars) { + if (f < dmin && c->type() != GraphOptions::ErrorBars) { dmin = f; key = iter.key(); point = i; @@ -691,7 +691,7 @@ void Plot::updateCurveLabels() { foreach (QwtPlotItem *i, curves) { DataCurve *dc = dynamic_cast<DataCurve *>(i); if (dc && i->rtti() != QwtPlotItem::Rtti_PlotSpectrogram && - dc->type() != Graph::Function && dc->hasLabels()) + dc->type() != GraphOptions::Function && dc->hasLabels()) dc->updateLabelsPosition(); } } diff --git a/MantidPlot/src/PlotCurve.cpp b/MantidPlot/src/PlotCurve.cpp index f72cd52a577dcfa465f37b95ba907cc4970b0ef4..13b4499cfa2682f814ce2af9c33de42e5c6e8ce2 100644 --- a/MantidPlot/src/PlotCurve.cpp +++ b/MantidPlot/src/PlotCurve.cpp @@ -66,9 +66,9 @@ QString PlotCurve::saveCurveLayout() { int style = g->curveType(index); QString s = "<Style>" + QString::number(style) + "</Style>\n"; - if (style == Graph::Spline) + if (style == GraphOptions::Spline) s += "<LineStyle>5</LineStyle>\n"; - else if (style == Graph::VerticalSteps) + else if (style == GraphOptions::VerticalSteps) s += "<LineStyle>6</LineStyle>\n"; else s += "<LineStyle>" + QString::number(this->style()) + "</LineStyle>\n"; @@ -473,7 +473,7 @@ void DataCurve::loadData() { QStringList xLabels, yLabels; // store text labels // int xAxis = QwtPlot::xBottom; - // if (d_type == Graph::HorizontalBars) + // if (d_type == GraphOptions::HorizontalBars) // xAxis = QwtPlot::yLeft; QTime time0; @@ -547,7 +547,7 @@ void DataCurve::loadData() { remove(); return; } else { - if (d_type == Graph::HorizontalBars) { + if (d_type == GraphOptions::HorizontalBars) { setData(Y.data(), X.data(), size); foreach (DataCurve *c, d_error_bars) c->setData(Y.data(), X.data(), size); @@ -558,7 +558,7 @@ void DataCurve::loadData() { } if (xColType == Table::Text) { - if (d_type == Graph::HorizontalBars) + if (d_type == GraphOptions::HorizontalBars) g->setLabelsTextFormat(QwtPlot::yLeft, ScaleDraw::Text, d_x_column, xLabels); else @@ -566,7 +566,7 @@ void DataCurve::loadData() { xLabels); } else if (xColType == Table::Time || xColType == Table::Date) { int axis = QwtPlot::xBottom; - if (d_type == Graph::HorizontalBars) + if (d_type == GraphOptions::HorizontalBars) axis = QwtPlot::yLeft; ScaleDraw *old_sd = static_cast<ScaleDraw *>(plot->axisScaleDraw(axis)); ScaleDraw *sd = new ScaleDraw(plot, old_sd); @@ -646,8 +646,8 @@ int DataCurve::tableRow(int point) const { for (int i = d_start_row; i <= d_end_row; i++) { QDate d = QDate::fromString(d_table->text(i, xcol), format); if (d.isValid()) { - if (d_type == Graph::HorizontalBars && date0.daysTo(d) == y(point) && - d_table->cell(i, ycol) == x(point)) + if (d_type == GraphOptions::HorizontalBars && + date0.daysTo(d) == y(point) && d_table->cell(i, ycol) == x(point)) return i; else if (date0.daysTo(d) == x(point) && d_table->cell(i, ycol) == y(point)) @@ -660,8 +660,8 @@ int DataCurve::tableRow(int point) const { for (int i = d_start_row; i <= d_end_row; i++) { QTime t = QTime::fromString(d_table->text(i, xcol), format); if (t.isValid()) { - if (d_type == Graph::HorizontalBars && t0.msecsTo(t) == y(point) && - d_table->cell(i, ycol) == x(point)) + if (d_type == GraphOptions::HorizontalBars && + t0.msecsTo(t) == y(point) && d_table->cell(i, ycol) == x(point)) return i; if (t0.msecsTo(t) == x(point) && d_table->cell(i, ycol) == y(point)) return i; @@ -910,8 +910,8 @@ QString DataCurve::saveToString() { if (d_skip_symbols > 1) s += "<SkipPoints>" + QString::number(d_skip_symbols) + "</SkipPoints>\n"; - if (d_labels_list.isEmpty() || type() == Graph::Function || - type() == Graph::Box) + if (d_labels_list.isEmpty() || type() == GraphOptions::Function || + type() == GraphOptions::Box) return s; s = "<CurveLabels>\n"; @@ -999,10 +999,11 @@ void DataCurve::setLabelsSelected(bool on) { bool DataCurve::validCurveType() const { int style = type(); - return !(style == Graph::Function || style == Graph::Box || - style == Graph::Pie || style == Graph::ErrorBars || - style == Graph::ColorMap || style == Graph::GrayScale || - style == Graph::Contour || style == Graph::ImagePlot); + return !(style == GraphOptions::Function || style == GraphOptions::Box || + style == GraphOptions::Pie || style == GraphOptions::ErrorBars || + style == GraphOptions::ColorMap || + style == GraphOptions::GrayScale || style == GraphOptions::Contour || + style == GraphOptions::ImagePlot); } void DataCurve::moveLabels(const QPoint &pos) { diff --git a/MantidPlot/src/PlotDialog.cpp b/MantidPlot/src/PlotDialog.cpp index 393dcab828d91285493804d6ef54242ba8b901d0..cebc468f8f45f53042c4421336d7e9e85a3feec6 100644 --- a/MantidPlot/src/PlotDialog.cpp +++ b/MantidPlot/src/PlotDialog.cpp @@ -26,52 +26,53 @@ * Boston, MA 02110-1301 USA * * * ***************************************************************************/ -#include "ApplicationWindow.h" #include "PlotDialog.h" +#include "ApplicationWindow.h" +#include "BoxCurve.h" #include "ColorBox.h" #include "ColorButton.h" +#include "ColorMapEditor.h" +#include "ContourLinesEditor.h" +#include "Folder.h" +#include "FunctionCurve.h" +#include "MantidQtMantidWidgets/DoubleSpinBox.h" +#include "MyParser.h" #include "PatternBox.h" +#include "PenStyleBox.h" +#include "QwtErrorPlotCurve.h" +#include "QwtHistogram.h" +#include "QwtPieCurve.h" +#include "Spectrogram.h" #include "SymbolBox.h" #include "Table.h" -#include "MyParser.h" -#include "QwtHistogram.h" #include "VectorCurve.h" -#include "QwtErrorPlotCurve.h" -#include "BoxCurve.h" -#include "FunctionCurve.h" -#include "Spectrogram.h" -#include "QwtPieCurve.h" -#include "ColorMapEditor.h" -#include "pixmaps.h" -#include "MantidQtMantidWidgets/DoubleSpinBox.h" -#include "Folder.h" -#include "ContourLinesEditor.h" -#include "PenStyleBox.h" +#include <MantidQtAPI/pixmaps.h> -#include <QTreeWidget> -#include <QLineEdit> -#include <QLayout> -#include <QSpinBox> +#include "MantidKernel/ConfigService.h" +#include "MantidQtAPI/MantidColorMap.h" #include <QCheckBox> -#include <QPushButton> -#include <QRadioButton> -#include <QLabel> -#include <QWidget> -#include <QMessageBox> #include <QComboBox> -#include <QWidgetList> +#include <QDateTime> +#include <QDoubleSpinBox> #include <QFileDialog> -#include <QGroupBox> #include <QFontDialog> -#include <QShortcut> +#include <QGroupBox> #include <QKeySequence> -#include <QDoubleSpinBox> +#include <QLabel> +#include <QLayout> +#include <QLineEdit> #include <QMenu> -#include <QDateTime> -#include "MantidKernel/ConfigService.h" -#include "MantidQtAPI/MantidColorMap.h" +#include <QMessageBox> +#include <QPushButton> +#include <QRadioButton> +#include <QShortcut> +#include <QSpinBox> +#include <QTreeWidget> +#include <QWidget> +#include <QWidgetList> using Mantid::Kernel::ConfigService; +using namespace MantidQt::API; PlotDialog::PlotDialog(bool showExtended, ApplicationWindow *app, MultiLayer *ml, Qt::WFlags fl) @@ -336,7 +337,7 @@ void PlotDialog::showPlotAssociations(QTreeWidgetItem *item, int) { PlotCurve *pc = dynamic_cast<PlotCurve *>(it); if (!pc) return; - if (pc->type() == Graph::Function) { + if (pc->type() == GraphOptions::Function) { FunctionDialog *fd = d_app->showFunctionDialog(ctit->graph(), ctit->plotItemIndex()); @@ -367,7 +368,7 @@ void PlotDialog::editCurve() { hide(); if (d_app) { - if (curveType == Graph::Function) { + if (curveType == GraphOptions::Function) { FunctionDialog *fd = d_app->showFunctionDialog(item->graph(), index); if (fd) connect(reinterpret_cast<QObject *>(fd), SIGNAL(destroyed()), this, @@ -395,12 +396,14 @@ void PlotDialog::changePlotType(int plotType) { return; int curveType = item->plotItemType(); - if (curveType == Graph::ColorMap || curveType == Graph::Contour || - curveType == Graph::GrayScale) + if (curveType == GraphOptions::ColorMap || + curveType == GraphOptions::Contour || + curveType == GraphOptions::GrayScale) clearTabWidget(); - else if (curveType == Graph::VectXYAM || curveType == Graph::VectXYXY) { - if ((plotType && curveType == Graph::VectXYAM) || - (!plotType && curveType == Graph::VectXYXY)) + else if (curveType == GraphOptions::VectXYAM || + curveType == GraphOptions::VectXYXY) { + if ((plotType && curveType == GraphOptions::VectXYAM) || + (!plotType && curveType == GraphOptions::VectXYXY)) return; clearTabWidget(); @@ -411,10 +414,10 @@ void PlotDialog::changePlotType(int plotType) { return; if (plotType) { - graph->setCurveType(item->plotItemIndex(), Graph::VectXYAM); + graph->setCurveType(item->plotItemIndex(), GraphOptions::VectXYAM); v->setVectorStyle(VectorCurve::XYAM); } else { - graph->setCurveType(item->plotItemIndex(), Graph::VectXYXY); + graph->setCurveType(item->plotItemIndex(), GraphOptions::VectXYXY); v->setVectorStyle(VectorCurve::XYXY); } customVectorsPage(plotType); @@ -427,11 +430,11 @@ void PlotDialog::changePlotType(int plotType) { boxConnect->setCurrentIndex(1); // show line for Line and LineSymbol plots QwtSymbol s = QwtSymbol(QwtSymbol::Ellipse, QBrush(), QPen(), QSize(9, 9)); - if (plotType == Graph::Line) + if (plotType == GraphOptions::Line) s.setStyle(QwtSymbol::NoSymbol); - else if (plotType == Graph::Scatter) + else if (plotType == GraphOptions::Scatter) graph->setCurveStyle(item->plotItemIndex(), QwtPlotCurve::NoCurve); - else if (plotType == Graph::LineSymbols) + else if (plotType == GraphOptions::LineSymbols) graph->setCurveStyle(item->plotItemIndex(), QwtPlotCurve::Lines); graph->setCurveSymbol(item->plotItemIndex(), s); @@ -464,11 +467,11 @@ void PlotDialog::setPlotType(int plotType, int curveNum, const QString &color) { return; QwtSymbol s = QwtSymbol(QwtSymbol::Ellipse, QBrush(), QPen(), QSize(5, 5)); - if (plotType == Graph::Line) + if (plotType == GraphOptions::Line) s.setStyle(QwtSymbol::NoSymbol); - else if (plotType == Graph::Scatter) + else if (plotType == GraphOptions::Scatter) graph->setCurveStyle(item->plotItemIndex(), QwtPlotCurve::NoCurve); - else if (plotType == Graph::LineSymbols) + else if (plotType == GraphOptions::LineSymbols) graph->setCurveStyle(item->plotItemIndex(), QwtPlotCurve::Lines); if (color != "Default") @@ -1544,7 +1547,7 @@ void PlotDialog::contextMenuEvent(QContextMenuEvent *e) { PlotCurve *pc = dynamic_cast<PlotCurve *>(it); if (!pc) return; - if (pc->type() == Graph::Function) + if (pc->type() == GraphOptions::Function) contextMenu.addAction(tr("&Edit..."), this, SLOT(editCurve())); else contextMenu.addAction(tr("&Plot Associations..."), this, @@ -1649,7 +1652,7 @@ void PlotDialog::updateTabWindow(QTreeWidgetItem *currentItem, } void PlotDialog::insertTabs(int plot_type) { - if (plot_type == Graph::Pie) { + if (plot_type == GraphOptions::Pie) { privateTabWidget->addTab(piePage, tr("Pattern")); privateTabWidget->addTab(pieGeometryPage, tr("Pie Geometry")); privateTabWidget->addTab(pieLabelsPage, tr("Labels")); @@ -1659,30 +1662,30 @@ void PlotDialog::insertTabs(int plot_type) { } privateTabWidget->addTab(axesPage, tr("Axes")); - if (plot_type == Graph::Line) { + if (plot_type == GraphOptions::Line) { boxConnect->setEnabled(true); privateTabWidget->addTab(linePage, tr("Line")); const int index = privateTabWidget->indexOf(linePage); privateTabWidget->setCurrentIndex(index); - } else if (plot_type == Graph::Scatter) { + } else if (plot_type == GraphOptions::Scatter) { boxConnect->setEnabled(true); privateTabWidget->addTab(symbolPage, tr("Symbol")); const int index = privateTabWidget->indexOf(symbolPage); privateTabWidget->setCurrentIndex(index); - } else if (plot_type == Graph::LineSymbols) { + } else if (plot_type == GraphOptions::LineSymbols) { boxConnect->setEnabled(true); privateTabWidget->addTab(linePage, tr("Line")); privateTabWidget->addTab(symbolPage, tr("Symbol")); const int index = privateTabWidget->indexOf(symbolPage); privateTabWidget->setCurrentIndex(index); - } else if (plot_type == Graph::VerticalBars || - plot_type == Graph::HorizontalBars || - plot_type == Graph::Histogram) { + } else if (plot_type == GraphOptions::VerticalBars || + plot_type == GraphOptions::HorizontalBars || + plot_type == GraphOptions::Histogram) { boxConnect->setEnabled(false); privateTabWidget->addTab(linePage, tr("Pattern")); privateTabWidget->addTab(spacingPage, tr("Spacing")); - if (plot_type == Graph::Histogram) { + if (plot_type == GraphOptions::Histogram) { privateTabWidget->addTab(histogramPage, tr("Histogram Data")); const int index = privateTabWidget->indexOf(histogramPage); privateTabWidget->setCurrentIndex(index); @@ -1690,18 +1693,19 @@ void PlotDialog::insertTabs(int plot_type) { const int index = privateTabWidget->indexOf(linePage); privateTabWidget->setCurrentIndex(index); } - } else if (plot_type == Graph::VectXYXY || plot_type == Graph::VectXYAM) { + } else if (plot_type == GraphOptions::VectXYXY || + plot_type == GraphOptions::VectXYAM) { boxConnect->setEnabled(true); privateTabWidget->addTab(linePage, tr("Line")); privateTabWidget->addTab(vectPage, tr("Vector")); - customVectorsPage(plot_type == Graph::VectXYAM); + customVectorsPage(plot_type == GraphOptions::VectXYAM); const int index = privateTabWidget->indexOf(vectPage); privateTabWidget->setCurrentIndex(index); - } else if (plot_type == Graph::ErrorBars) { + } else if (plot_type == GraphOptions::ErrorBars) { privateTabWidget->addTab(errorsPage, tr("Error Bars")); const int index = privateTabWidget->indexOf(errorsPage); privateTabWidget->setCurrentIndex(index); - } else if (plot_type == Graph::Box) { + } else if (plot_type == GraphOptions::Box) { boxConnect->setEnabled(false); privateTabWidget->addTab(linePage, tr("Pattern")); privateTabWidget->addTab(boxPage, tr("Box/Whiskers")); @@ -1709,9 +1713,10 @@ void PlotDialog::insertTabs(int plot_type) { const int index = privateTabWidget->indexOf(linePage); privateTabWidget->setCurrentIndex(index); return; - } else if (plot_type == Graph::ColorMap || plot_type == Graph::GrayScale || - plot_type == Graph::Contour || - plot_type == Graph::ColorMapContour) { + } else if (plot_type == GraphOptions::ColorMap || + plot_type == GraphOptions::GrayScale || + plot_type == GraphOptions::Contour || + plot_type == GraphOptions::ColorMapContour) { privateTabWidget->addTab(spectrogramPage, tr("Colors")); setColorMapName(); privateTabWidget->addTab(contourLinesPage, tr("Contour Lines")); @@ -1732,7 +1737,7 @@ void PlotDialog::insertTabs(int plot_type) { const DataCurve *c = dynamic_cast<const DataCurve *>(ctit->plotItem()); if (!c) return; - if (c && c->type() != Graph::Function) { + if (c && c->type() != GraphOptions::Function) { privateTabWidget->addTab(labelsPage, tr("Labels")); if (c->hasSelectedLabels()) { const int index = privateTabWidget->indexOf(labelsPage); @@ -1787,25 +1792,28 @@ int PlotDialog::setPlotType(CurveTreeItem *item) { if (curveType >= 0) { boxPlotType->clear(); - if (curveType == Graph::ErrorBars) + if (curveType == GraphOptions::ErrorBars) boxPlotType->addItem(tr("Error Bars")); - else if (curveType == Graph::Pie) + else if (curveType == GraphOptions::Pie) boxPlotType->addItem(tr("Pie")); - else if (curveType == Graph::VerticalBars) + else if (curveType == GraphOptions::VerticalBars) boxPlotType->addItem(tr("Vertical Bars")); - else if (curveType == Graph::HorizontalBars) + else if (curveType == GraphOptions::HorizontalBars) boxPlotType->addItem(tr("Horizontal Bars")); - else if (curveType == Graph::Histogram) + else if (curveType == GraphOptions::Histogram) boxPlotType->addItem(tr("Histogram")); - else if (curveType == Graph::VectXYXY || curveType == Graph::VectXYAM) { + else if (curveType == GraphOptions::VectXYXY || + curveType == GraphOptions::VectXYAM) { boxPlotType->addItem(tr("Vector XYXY")); boxPlotType->addItem(tr("Vector XYAM")); - if (curveType == Graph::VectXYAM) + if (curveType == GraphOptions::VectXYAM) boxPlotType->setCurrentIndex(1); - } else if (curveType == Graph::Box) + } else if (curveType == GraphOptions::Box) boxPlotType->addItem(tr("Box")); - else if (curveType == Graph::ColorMap || curveType == Graph::GrayScale || - curveType == Graph::Contour || curveType == Graph::ColorMapContour) + else if (curveType == GraphOptions::ColorMap || + curveType == GraphOptions::GrayScale || + curveType == GraphOptions::Contour || + curveType == GraphOptions::ColorMapContour) boxPlotType->insertItem(-1, tr("Contour") + " / " + tr("Image")); else { boxPlotType->addItem(tr("Line")); @@ -1819,13 +1827,13 @@ int PlotDialog::setPlotType(CurveTreeItem *item) { QwtSymbol s = c->symbol(); if (s.style() == QwtSymbol::NoSymbol) { boxPlotType->setCurrentIndex(0); - return Graph::Line; + return GraphOptions::Line; } else if (c->style() == QwtPlotCurve::NoCurve) { boxPlotType->setCurrentIndex(1); - return Graph::Scatter; + return GraphOptions::Scatter; } else { boxPlotType->setCurrentIndex(2); - return Graph::LineSymbols; + return GraphOptions::LineSymbols; } } } @@ -1991,13 +1999,13 @@ void PlotDialog::setActiveCurve(CurveTreeItem *item) { if (!c) return; - if (c->type() == Graph::Function) + if (c->type() == GraphOptions::Function) btnEditCurve->setText(tr("&Edit...")); else btnEditCurve->setText(tr("&Plot Associations...")); int curveType = item->plotItemType(); - if (curveType == Graph::Pie) { + if (curveType == GraphOptions::Pie) { QwtPieCurve *pie = dynamic_cast<QwtPieCurve *>(i); if (!pie) return; @@ -2038,9 +2046,9 @@ void PlotDialog::setActiveCurve(CurveTreeItem *item) { } // line page int style = c->style(); - if (curveType == Graph::Spline) + if (curveType == GraphOptions::Spline) style = 5; - else if (curveType == Graph::VerticalSteps) + else if (curveType == GraphOptions::VerticalSteps) style = 6; boxConnect->setCurrentIndex(style); setPenStyle(c->pen().style()); @@ -2063,11 +2071,12 @@ void PlotDialog::setActiveCurve(CurveTreeItem *item) { boxFillColor->setEnabled(s.brush() != Qt::NoBrush); boxFillColor->setColor(s.brush().color()); - if (c->type() == Graph::Function) + if (c->type() == GraphOptions::Function) return; - if (curveType == Graph::VerticalBars || curveType == Graph::HorizontalBars || - curveType == Graph::Histogram) { // spacing page + if (curveType == GraphOptions::VerticalBars || + curveType == GraphOptions::HorizontalBars || + curveType == GraphOptions::Histogram) { // spacing page QwtBarCurve *b = dynamic_cast<QwtBarCurve *>(i); if (b) { gapBox->setValue(b->gap()); @@ -2075,7 +2084,7 @@ void PlotDialog::setActiveCurve(CurveTreeItem *item) { } } - if (curveType == Graph::Histogram) { // Histogram page + if (curveType == GraphOptions::Histogram) { // Histogram page QwtHistogram *h = dynamic_cast<QwtHistogram *>(i); if (h) { automaticBox->setChecked(h->autoBinning()); @@ -2086,8 +2095,8 @@ void PlotDialog::setActiveCurve(CurveTreeItem *item) { } } - if (curveType == Graph::VectXYXY || - curveType == Graph::VectXYAM) { // Vector page + if (curveType == GraphOptions::VectXYXY || + curveType == GraphOptions::VectXYAM) { // Vector page VectorCurve *v = dynamic_cast<VectorCurve *>(i); if (v) { vectColorBox->setColor(v->color()); @@ -2100,7 +2109,7 @@ void PlotDialog::setActiveCurve(CurveTreeItem *item) { } } - if (curveType == Graph::ErrorBars) { + if (curveType == GraphOptions::ErrorBars) { QwtErrorPlotCurve *err = dynamic_cast<QwtErrorPlotCurve *>(i); if (err) { widthBox->blockSignals(true); @@ -2128,7 +2137,7 @@ void PlotDialog::setActiveCurve(CurveTreeItem *item) { return; } - if (curveType == Graph::Box) { + if (curveType == GraphOptions::Box) { BoxCurve *b = dynamic_cast<BoxCurve *>(i); if (b) { boxMaxStyle->setStyle(b->maxStyle()); @@ -2465,7 +2474,7 @@ bool PlotDialog::acceptParams() { QString table = t[0]; QStringList cols = t[1].split(",", QString::SkipEmptyParts); - if (graph->curveType(index) == Graph::VectXYXY) { + if (graph->curveType(index) == GraphOptions::VectXYXY) { xEndCol = xEndCol.remove(table + "_") + "(X)"; yEndCol = yEndCol.remove(table + "_") + "(Y)"; } else { @@ -3011,7 +3020,7 @@ void LayerItem::insertCurvesList() { if (it->rtti() == QwtPlotItem::Rtti_PlotCurve) { PlotCurve *c = dynamic_cast<PlotCurve *>(it); DataCurve *dc = dynamic_cast<DataCurve *>(it); - if (c && dc && c->type() != Graph::Function && dc->table()) { + if (c && dc && c->type() != GraphOptions::Function && dc->table()) { QString s = dc->plotAssociation(); QString table = dc->table()->name(); plotAssociation = table + ": " + s.remove(table + "_"); diff --git a/MantidPlot/src/QwtBarCurve.cpp b/MantidPlot/src/QwtBarCurve.cpp index f708849dce9dd18400c2c7eb630915467d6ed0f3..54c05370ba2351cc8a9ff4822e08c9c7142ccf39 100644 --- a/MantidPlot/src/QwtBarCurve.cpp +++ b/MantidPlot/src/QwtBarCurve.cpp @@ -42,9 +42,9 @@ QwtBarCurve::QwtBarCurve(BarStyle style, Table *t, const QString &xColName, setStyle(QwtPlotCurve::UserCurve); if (bar_style == Vertical) - setType(Graph::VerticalBars); + setType(GraphOptions::VerticalBars); else - setType(Graph::HorizontalBars); + setType(GraphOptions::HorizontalBars); } void QwtBarCurve::copy(const QwtBarCurve *b) { diff --git a/MantidPlot/src/QwtErrorPlotCurve.cpp b/MantidPlot/src/QwtErrorPlotCurve.cpp index e233e344f077633af393109d33746baf91bcbe30..4c1e17910ecc2734ecdf9ee57f3e5ca8a3e79fbd 100644 --- a/MantidPlot/src/QwtErrorPlotCurve.cpp +++ b/MantidPlot/src/QwtErrorPlotCurve.cpp @@ -38,14 +38,14 @@ QwtErrorPlotCurve::QwtErrorPlotCurve(int orientation, Table *t, const QString &name) : DataCurve(t, QString(), name), ErrorBarSettings(), d_master_curve(NULL) { type = orientation; - setType(Graph::ErrorBars); + setType(GraphOptions::ErrorBars); setStyle(QwtPlotCurve::UserCurve); } QwtErrorPlotCurve::QwtErrorPlotCurve(Table *t, const QString &name) : DataCurve(t, QString(), name), ErrorBarSettings(), d_master_curve(NULL) { type = Vertical; - setType(Graph::ErrorBars); + setType(GraphOptions::ErrorBars); setStyle(QwtPlotCurve::UserCurve); } @@ -86,9 +86,9 @@ void QwtErrorPlotCurve::drawErrorBars(QPainter *painter, double d_xOffset = 0.0; double d_yOffset = 0.0; - if (d_master_curve->type() == Graph::VerticalBars) + if (d_master_curve->type() == GraphOptions::VerticalBars) d_xOffset = (static_cast<QwtBarCurve *>(d_master_curve))->dataOffset(); - else if (d_master_curve->type() == Graph::HorizontalBars) + else if (d_master_curve->type() == GraphOptions::HorizontalBars) d_yOffset = (static_cast<QwtBarCurve *>(d_master_curve))->dataOffset(); int skipPoints = d_master_curve->skipSymbolsCount(); diff --git a/MantidPlot/src/QwtHistogram.cpp b/MantidPlot/src/QwtHistogram.cpp index f5ab340d37a037424b6a8b8fb7504dccef8135df..df018542befb7b11ea1bc50b25b60dda151af12e 100644 --- a/MantidPlot/src/QwtHistogram.cpp +++ b/MantidPlot/src/QwtHistogram.cpp @@ -31,8 +31,8 @@ #include "Matrix.h" #include "MatrixModel.h" #include <QPainter> -#include <gsl/gsl_vector.h> #include <gsl/gsl_histogram.h> +#include <gsl/gsl_vector.h> QwtHistogram::QwtHistogram(Table *t, const QString &xColName, const QString &name, int startRow, int endRow) @@ -40,7 +40,7 @@ QwtHistogram::QwtHistogram(Table *t, const QString &xColName, d_autoBin(false), d_bin_size(0.0), d_begin(0.0), d_end(0.0), d_mean(0.0), d_standard_deviation(0.0), d_min(0.0), d_max(0.0) { d_matrix = 0; - setType(Graph::Histogram); + setType(GraphOptions::Histogram); setStyle(QwtPlotCurve::UserCurve); } @@ -53,7 +53,7 @@ QwtHistogram::QwtHistogram(Matrix *m) if (m) { d_autoBin = true; d_matrix = m; - setType(Graph::Histogram); + setType(GraphOptions::Histogram); setStyle(QwtPlotCurve::UserCurve); } } diff --git a/MantidPlot/src/QwtPieCurve.cpp b/MantidPlot/src/QwtPieCurve.cpp index 80fcb78f936f089a50797c65959dada55f3f72de..31d65c53108573e8db0b1e5e6ba14163e217df31 100644 --- a/MantidPlot/src/QwtPieCurve.cpp +++ b/MantidPlot/src/QwtPieCurve.cpp @@ -30,10 +30,10 @@ #include "ColorBox.h" #include "Table.h" +#include <QApplication> #include <QCloseEvent> -#include <QPainter> #include <QMessageBox> -#include <QApplication> +#include <QPainter> QwtPieCurve::QwtPieCurve(Table *t, const QString &name, int startRow, int endRow) @@ -45,7 +45,7 @@ QwtPieCurve::QwtPieCurve(Table *t, const QString &name, int startRow, setPen(QPen(QColor(Qt::black), 1, Qt::SolidLine)); setBrush(QBrush(Qt::SolidPattern)); setStyle(QwtPlotCurve::UserCurve); - setType(Graph::Pie); + setType(GraphOptions::Pie); d_table_rows = QVarLengthArray<int>(0); } diff --git a/MantidPlot/src/RangeSelectorTool.cpp b/MantidPlot/src/RangeSelectorTool.cpp index 3719e4d1d5ee31f24d2bc7b76be75b9b6a079665..af013fe7f4249c10e762181e457f3932a4cdb82c 100644 --- a/MantidPlot/src/RangeSelectorTool.cpp +++ b/MantidPlot/src/RangeSelectorTool.cpp @@ -32,15 +32,17 @@ #include "PlotCurve.h" #include "cursors.h" -#include <qwt_symbol.h> -#include <QPoint> #include <QApplication> #include <QClipboard> -#include <QKeyEvent> -#include <QMessageBox> #include <QEvent> +#include <QKeyEvent> #include <QLocale> +#include <QMessageBox> +#include <QPoint> #include <QTextStream> +#include <qwt_symbol.h> + +using namespace MantidQt::API; RangeSelectorTool::RangeSelectorTool(Graph *graph, const QObject *status_target, const char *status_slot) @@ -164,7 +166,8 @@ void RangeSelectorTool::setActivePoint(int point) { void RangeSelectorTool::emitStatusText() { QLocale locale = d_graph->plotWidget()->locale(); - if ((static_cast<PlotCurve *>(d_selected_curve))->type() == Graph::Function) { + if ((static_cast<PlotCurve *>(d_selected_curve))->type() == + GraphOptions::Function) { emit statusText( QString("%1 <=> %2[%3]: x=%4; y=%5") .arg(d_active_marker.xValue() > d_inactive_marker.xValue() @@ -296,7 +299,8 @@ void RangeSelectorTool::clearSelection() { if (!d_selected_curve) return; - if ((static_cast<PlotCurve *>(d_selected_curve))->type() != Graph::Function) { + if ((static_cast<PlotCurve *>(d_selected_curve))->type() != + GraphOptions::Function) { Table *t = (static_cast<DataCurve *>(d_selected_curve))->table(); if (!t) return; @@ -351,7 +355,8 @@ void RangeSelectorTool::pasteSelection() { if (text.isEmpty()) return; - if ((static_cast<PlotCurve *>(d_selected_curve))->type() == Graph::Function) + if ((static_cast<PlotCurve *>(d_selected_curve))->type() == + GraphOptions::Function) return; Table *t = (static_cast<DataCurve *>(d_selected_curve))->table(); @@ -424,7 +429,8 @@ void RangeSelectorTool::setCurveRange() { if (!d_selected_curve) return; - if ((static_cast<PlotCurve *>(d_selected_curve))->type() != Graph::Function) { + if ((static_cast<PlotCurve *>(d_selected_curve))->type() != + GraphOptions::Function) { (static_cast<DataCurve *>(d_selected_curve)) ->setRowRange(qMin(d_active_point, d_inactive_point), qMax(d_active_point, d_inactive_point)); diff --git a/MantidPlot/src/ScreenPickerTool.cpp b/MantidPlot/src/ScreenPickerTool.cpp index d31f729af94952a357ef071eab27e691b367e0a1..5f15c1da043c3761f8abd200aa7fb19c30442c32 100644 --- a/MantidPlot/src/ScreenPickerTool.cpp +++ b/MantidPlot/src/ScreenPickerTool.cpp @@ -28,14 +28,16 @@ ***************************************************************************/ #include "ScreenPickerTool.h" #include "ApplicationWindow.h" -#include "SymbolBox.h" -#include "Table.h" #include "Graph.h" #include "Plot.h" #include "PlotCurve.h" -#include "pixmaps.h" -#include <qwt_symbol.h> +#include "SymbolBox.h" +#include "Table.h" +#include <MantidQtAPI/pixmaps.h> #include <QKeyEvent> +#include <qwt_symbol.h> + +using namespace MantidQt::API; ScreenPickerTool::ScreenPickerTool(Graph *graph, const QObject *status_target, const char *status_slot) @@ -162,7 +164,7 @@ void DrawPointTool::appendPoint(const QwtDoublePoint &pos) { QwtSymbol(QwtSymbol::Ellipse, QBrush(Qt::black), QPen(Qt::black, d_app->defaultCurveLineWidth), QSize(d_app->defaultSymbolSize, d_app->defaultSymbolSize))); - d_graph->insertPlotItem(d_curve, Graph::LineSymbols); + d_graph->insertPlotItem(d_curve, GraphOptions::LineSymbols); } d_curve->setFullRange(); diff --git a/MantidPlot/src/ScriptOutputDisplay.cpp b/MantidPlot/src/ScriptOutputDisplay.cpp index 2841d5dd1c6a1f4daca9421f43932b4347452d43..39825ddb9f186efc474904ded0d1f9daec0b33d0 100644 --- a/MantidPlot/src/ScriptOutputDisplay.cpp +++ b/MantidPlot/src/ScriptOutputDisplay.cpp @@ -1,16 +1,18 @@ #include "ScriptOutputDisplay.h" #include "TextFileIO.h" -#include "pixmaps.h" +#include <MantidQtAPI/pixmaps.h> #include <QDateTime> -#include <QMenu> #include <QFileDialog> #include <QKeyEvent> -#include <QPrinter> +#include <QMenu> #include <QPrintDialog> +#include <QPrinter> #include <QWheelEvent> +using namespace MantidQt::API; + /** * Constructor * @param title :: The title diff --git a/MantidPlot/src/ScriptingWindow.cpp b/MantidPlot/src/ScriptingWindow.cpp index b969fe735d5d39b09e6e070c3077e3f1bee84536..646be1e419741ee2e7a7d1694c5e66a61cef1bb9 100644 --- a/MantidPlot/src/ScriptingWindow.cpp +++ b/MantidPlot/src/ScriptingWindow.cpp @@ -3,11 +3,11 @@ //------------------------------------------- #include "ScriptingWindow.h" #include "ApplicationWindow.h" +#include "MantidQtAPI/TSVSerialiser.h" #include "MultiTabScriptInterpreter.h" -#include "ScriptingEnv.h" #include "ScriptFileInterpreter.h" -#include "MantidQtAPI/TSVSerialiser.h" -#include "pixmaps.h" +#include "ScriptingEnv.h" +#include <MantidQtAPI/pixmaps.h> // Mantid #include "MantidKernel/ConfigService.h" @@ -19,23 +19,24 @@ #include "MantidQtMantidWidgets/ScriptEditor.h" // Qt -#include <QTextEdit> -#include <QMenuBar> -#include <QMenu> #include <QAction> +#include <QApplication> #include <QCloseEvent> -#include <QSettings> -#include <QPrintDialog> -#include <QPrinter> #include <QDateTime> #include <QFileDialog> +#include <QList> +#include <QMenu> +#include <QMenuBar> #include <QMessageBox> -#include <QApplication> +#include <QPrintDialog> +#include <QPrinter> +#include <QSettings> +#include <QTextEdit> #include <QTextStream> -#include <QList> #include <QUrl> using namespace Mantid; +using namespace MantidQt::API; namespace { /// static logger diff --git a/MantidPlot/src/SendToProgramDialog.cpp b/MantidPlot/src/SendToProgramDialog.cpp index eccb97c096e37211a3096d90ef73fa46774ff0e7..49915986141aa1f3ebefe0c5e60370d1901bb2a4 100644 --- a/MantidPlot/src/SendToProgramDialog.cpp +++ b/MantidPlot/src/SendToProgramDialog.cpp @@ -1,25 +1,27 @@ #include "SendToProgramDialog.h" #include "ConfigDialog.h" -#include "pixmaps.h" -#include "MantidKernel/ConfigService.h" #include "MantidAPI/AlgorithmManager.h" +#include "MantidKernel/ConfigService.h" +#include <MantidQtAPI/pixmaps.h> -#include <QPushButton> +#include <QComboBox> +#include <QFileDialog> #include <QGridLayout> #include <QGroupBox> -#include <QWidget> -#include <QComboBox> #include <QHBoxLayout> -#include <QVBoxLayout> #include <QMessageBox> +#include <QPixmap> +#include <QPushButton> #include <QStringList> #include <QTextEdit> -#include <QFileDialog> -#include <QPixmap> +#include <QVBoxLayout> #include <QVector> +#include <QWidget> #include <map> +using namespace MantidQt::API; + /** * Constructor when adding a new program to the send to list */ diff --git a/MantidPlot/src/Table.cpp b/MantidPlot/src/Table.cpp index bdca85f5f52d5379475714614c027e0ff0849dbd..1bbb828586400d3ff89ccc1a95842749ac70b970 100644 --- a/MantidPlot/src/Table.cpp +++ b/MantidPlot/src/Table.cpp @@ -30,35 +30,35 @@ * * ***************************************************************************/ #include "Table.h" -#include "SortDialog.h" -#include "ImportASCIIDialog.h" -#include "muParserScript.h" #include "ApplicationWindow.h" -#include "pixmaps.h" +#include "ImportASCIIDialog.h" #include "MantidQtAPI/TSVSerialiser.h" +#include "SortDialog.h" +#include "muParserScript.h" +#include <MantidQtAPI/pixmaps.h> +#include <QApplication> +#include <QClipboard> #include <QContextMenuEvent> -#include <QMessageBox> #include <QDateTime> -#include <QTextStream> -#include <QClipboard> -#include <QApplication> -#include <QPainter> #include <QEvent> -#include <QLayout> -#include <QPrintDialog> -#include <QLocale> -#include <QShortcut> -#include <QProgressDialog> #include <QFile> #include <QHeaderView> +#include <QLayout> +#include <QLocale> +#include <QMessageBox> #include <QModelIndex> +#include <QPainter> +#include <QPrintDialog> +#include <QProgressDialog> +#include <QShortcut> +#include <QTextStream> #include <QVector> -#include <gsl/gsl_vector.h> #include <gsl/gsl_sort.h> #include <gsl/gsl_sort_vector.h> +#include <gsl/gsl_vector.h> #include <boost/algorithm/string.hpp> @@ -70,6 +70,7 @@ DECLARE_WINDOW(Table) using namespace Mantid; +using namespace MantidQt::API; Table::Table(ScriptingEnv *env, int rows, int cols, const QString &label, QWidget *parent, const QString &name, Qt::WFlags f) diff --git a/MantidPlot/src/TranslateCurveTool.cpp b/MantidPlot/src/TranslateCurveTool.cpp index 964a727df99a32b676832432f4e90ad4550e6fdc..152e0cac146f9bde70eed3e3686f115a0b0dc1ac 100644 --- a/MantidPlot/src/TranslateCurveTool.cpp +++ b/MantidPlot/src/TranslateCurveTool.cpp @@ -29,16 +29,16 @@ * * ***************************************************************************/ #include "TranslateCurveTool.h" -#include "Graph.h" -#include "PlotCurve.h" -#include "FunctionCurve.h" #include "ApplicationWindow.h" -#include "cursors.h" #include "DataPickerTool.h" +#include "FunctionCurve.h" +#include "Graph.h" +#include "PlotCurve.h" #include "ScreenPickerTool.h" -#include <limits> -#include <QMessageBox> +#include "cursors.h" #include <QLocale> +#include <QMessageBox> +#include <limits> #include <qwt_plot_curve.h> TranslateCurveTool::TranslateCurveTool(Graph *graph, ApplicationWindow *app, @@ -68,7 +68,7 @@ void TranslateCurveTool::selectCurvePoint(QwtPlotCurve *curve, if (!d_sub_tool) return; DataCurve *c = dynamic_cast<DataCurve *>(curve); - if (c && c->type() != Graph::Function) { + if (c && c->type() != GraphOptions::Function) { Table *t = c->table(); if (!t) @@ -119,7 +119,7 @@ void TranslateCurveTool::selectDestination(const QwtDoublePoint &point) { // Phase 3: execute the translation if (auto c = dynamic_cast<PlotCurve *>(d_selected_curve)) { - if (c->type() == Graph::Function) { + if (c->type() == GraphOptions::Function) { if (d_dir == Horizontal) { QMessageBox::warning( d_app, tr("MantidPlot - Warning"), diff --git a/MantidPlot/src/VectorCurve.cpp b/MantidPlot/src/VectorCurve.cpp index 27a044ac9db56fd719d6eb241ded6c93da3d58d3..262e01b3dbd0bce330a0b9f91af13295c8d44a2d 100644 --- a/MantidPlot/src/VectorCurve.cpp +++ b/MantidPlot/src/VectorCurve.cpp @@ -29,9 +29,9 @@ ***************************************************************************/ #include "VectorCurve.h" -#include <qwt_painter.h> -#include <qwt_double_rect.h> #include <QPainter> +#include <qwt_double_rect.h> +#include <qwt_painter.h> VectorCurve::VectorCurve(VectorStyle style, Table *t, const QString &xColName, const char *name, const QString &endCol1, @@ -41,9 +41,9 @@ VectorCurve::VectorCurve(VectorStyle style, Table *t, const QString &xColName, d_headLength(4), d_headAngle(45), d_position(Tail), d_end_x_a(endCol1), d_end_y_m(endCol2) { if (style == XYXY) - setType(Graph::VectXYXY); + setType(GraphOptions::VectXYXY); else if (style == XYAM) - setType(Graph::VectXYAM); + setType(GraphOptions::VectXYAM); } void VectorCurve::copy(const VectorCurve *vc) { diff --git a/MantidPlot/src/cursors.h b/MantidPlot/src/cursors.h index 6bcacc896e2d574b38cf652317bdb55679995f67..86c32118eb9d25d6e715ff5f38db7138270ba86f 100644 --- a/MantidPlot/src/cursors.h +++ b/MantidPlot/src/cursors.h @@ -7,4 +7,4 @@ ***************************************************************************/ -#include "pixmaps.h" +#include <MantidQtAPI/pixmaps.h> diff --git a/MantidPlot/src/importOPJ.cpp b/MantidPlot/src/importOPJ.cpp index bfe8ffdbee6221187aa871707e2402bfebaff83f..124156127f7f34620318fb390f9c5d4bf0f38f70 100644 --- a/MantidPlot/src/importOPJ.cpp +++ b/MantidPlot/src/importOPJ.cpp @@ -32,28 +32,28 @@ #include <cmath> -#include <QRegExp> -#include <QMessageBox> -#include <QDockWidget> -#include <QLocale> -#include <QDate> -#include <QDir> -#include <QTemporaryFile> +#include "ArrowMarker.h" +#include "ColorBox.h" +#include "Folder.h" +#include "FunctionCurve.h" +#include "Grid.h" +#include "ImageMarker.h" +#include "LegendWidget.h" #include "Matrix.h" #include "MatrixModel.h" -#include "ColorBox.h" #include "MultiLayer.h" #include "Note.h" -#include "Folder.h" +#include "QwtErrorPlotCurve.h" #include "QwtHistogram.h" #include "QwtPieCurve.h" #include "VectorCurve.h" -#include "FunctionCurve.h" -#include "QwtErrorPlotCurve.h" -#include "LegendWidget.h" -#include "Grid.h" -#include "ArrowMarker.h" -#include "ImageMarker.h" +#include <QDate> +#include <QDir> +#include <QDockWidget> +#include <QLocale> +#include <QMessageBox> +#include <QRegExp> +#include <QTemporaryFile> #include "qwt_plot_canvas.h" #include "qwt_plot_layout.h" @@ -534,7 +534,7 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { ml->setCaptionPolicy((MdiSubWindow::CaptionPolicy)opj.graphTitle(g)); ml->setBirthDate(JulianDateTime2String(opj.graphCreationDate(g))); - ml->hide(); //!hack used in order to avoid resize and repaint events + ml->hide(); //! hack used in order to avoid resize and repaint events ml->setWindowLabel(opj.graphLabel(g)); rect graphRect = opj.graphRect(g); @@ -578,42 +578,42 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { int color = 0; switch (opj.curveType(g, l, c)) { case OPJFile::Line: - style = Graph::Line; + style = GraphOptions::Line; break; case OPJFile::Scatter: - style = Graph::Scatter; + style = GraphOptions::Scatter; break; case OPJFile::LineSymbol: - style = Graph::LineSymbols; + style = GraphOptions::LineSymbols; break; case OPJFile::ErrorBar: case OPJFile::XErrorBar: - style = Graph::ErrorBars; + style = GraphOptions::ErrorBars; break; case OPJFile::Column: - style = Graph::VerticalBars; + style = GraphOptions::VerticalBars; break; case OPJFile::Bar: - style = Graph::HorizontalBars; + style = GraphOptions::HorizontalBars; break; case OPJFile::Histogram: - style = Graph::Histogram; + style = GraphOptions::Histogram; break; case OPJFile::Pie: - style = Graph::Pie; + style = GraphOptions::Pie; break; case OPJFile::Box: - style = Graph::Box; + style = GraphOptions::Box; break; case OPJFile::FlowVector: - style = Graph::VectXYXY; + style = GraphOptions::VectXYXY; break; case OPJFile::Vector: - style = Graph::VectXYAM; + style = GraphOptions::VectXYAM; break; case OPJFile::Area: case OPJFile::AreaStack: - style = Graph::Area; + style = GraphOptions::Area; break; case OPJFile::TextPlot: style = OPJFile::TextPlot; @@ -629,7 +629,7 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { switch (data[0].toAscii()) { case 'T': tableName = data.right(data.length() - 2); - if (style == Graph::ErrorBars) { + if (style == GraphOptions::ErrorBars) { int flags = opj.curveSymbolType(g, l, c); curve = graph->addErrorBars( tableName + "_" + opj.curveXColName(g, l, c), @@ -639,15 +639,15 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { int(ceil(opj.curveLineWidth(g, l, c))), int(ceil(opj.curveSymbolSize(g, l, c))), QColor(Qt::black), (flags & 0x40) == 0x40, (flags & 2) == 2, (flags & 1) == 1); - } else if (style == Graph::Histogram) + } else if (style == GraphOptions::Histogram) curve = graph->insertCurve( mw->table(tableName), tableName + "_" + opj.curveYColName(g, l, c), style); - else if (style == Graph::Pie || style == Graph::Box) { + else if (style == GraphOptions::Pie || style == GraphOptions::Box) { QStringList names; names << (tableName + "_" + opj.curveYColName(g, l, c)); graph->addCurves(mw->table(tableName), names, style); - } else if (style == Graph::VectXYXY) { + } else if (style == GraphOptions::VectXYXY) { QStringList names; vectorProperties vector = opj.curveVectorProperties(g, l, c); names << (tableName + "_" + opj.curveXColName(g, l, c)) @@ -656,7 +656,7 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { << (tableName + "_" + QString(vector.endYColName.c_str())); graph->addCurves(mw->table(tableName), names, style); - } else if (style == Graph::VectXYAM) { + } else if (style == GraphOptions::VectXYAM) { QStringList names; vectorProperties vector = opj.curveVectorProperties(g, l, c); names << (tableName + "_" + opj.curveXColName(g, l, c)) @@ -725,8 +725,9 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { cl.sSize = int(ceil(opj.curveSymbolSize(g, l, c))); cl.penWidth = float(opj.curveSymbolThickness(g, l, c)); color = opj.curveSymbolColor(g, l, c); - if ((style == Graph::Scatter || style == Graph::LineSymbols || - style == Graph::Area) && + if ((style == GraphOptions::Scatter || + style == GraphOptions::LineSymbols || + style == GraphOptions::Area) && color == 0xF7) // 0xF7 -Automatic color color = auto_color++; cl.symCol = color; @@ -793,8 +794,9 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { case 10: case 11: color = opj.curveSymbolFillColor(g, l, c); - if ((style == Graph::Scatter || style == Graph::LineSymbols || - style == Graph::Area) && + if ((style == GraphOptions::Scatter || + style == GraphOptions::LineSymbols || + style == GraphOptions::Area) && color == 0xF7) // 0xF7 -Automatic color color = 17; // depend on Origin settings - not stored in file cl.fillCol = color; @@ -808,9 +810,10 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { cl.lCol = (color == 0xF7 ? 0 : color); // 0xF7 -Automatic color int linestyle = opj.curveLineStyle(g, l, c); cl.filledArea = - (opj.curveIsFilledArea(g, l, c) || style == Graph::VerticalBars || - style == Graph::HorizontalBars || style == Graph::Histogram || - style == Graph::Pie) + (opj.curveIsFilledArea(g, l, c) || + style == GraphOptions::VerticalBars || + style == GraphOptions::HorizontalBars || + style == GraphOptions::Histogram || style == GraphOptions::Pie) ? 1 : 0; if (cl.filledArea) { @@ -852,9 +855,10 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { color = (cl.aStyle == 0 ? opj.curveFillAreaColor(g, l, c) : opj.curveFillPatternColor(g, l, c)); cl.aCol = (color == 0xF7 ? 0 : color); // 0xF7 -Automatic color - if (style == Graph::VerticalBars || - style == Graph::HorizontalBars || style == Graph::Histogram || - style == Graph::Pie) { + if (style == GraphOptions::VerticalBars || + style == GraphOptions::HorizontalBars || + style == GraphOptions::Histogram || + style == GraphOptions::Pie) { color = opj.curveFillPatternBorderColor(g, l, c); cl.lCol = (color == 0xF7 ? 0 : color); // 0xF7 -Automatic color color = (cl.aStyle == 0 ? opj.curveFillAreaColor(g, l, c) @@ -887,11 +891,12 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { } graph->updateCurveLayout(curve, &cl); - if (style == Graph::VerticalBars || style == Graph::HorizontalBars) { + if (style == GraphOptions::VerticalBars || + style == GraphOptions::HorizontalBars) { QwtBarCurve *b = static_cast<QwtBarCurve *>(graph->curve(c)); if (b) b->setGap(qRound(100 - opj.curveSymbolSize(g, l, c) * 10)); - } else if (style == Graph::Histogram) { + } else if (style == GraphOptions::Histogram) { QwtHistogram *h = static_cast<QwtHistogram *>(graph->curve(c)); if (h) { vector<double> bin = opj.layerHistogram(g, l); @@ -899,7 +904,7 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { h->setBinning(false, bin[0], bin[1], bin[2]); h->loadData(); } - } else if (style == Graph::Pie) { + } else if (style == GraphOptions::Pie) { QwtPieCurve *p = static_cast<QwtPieCurve *>(graph->curve(c)); switch (linestyle) { case OPJFile::Solid: @@ -945,7 +950,8 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { opj.curvePieProperties(g, l, c).format_categories); p->setFixedLabelsPosition( opj.curvePieProperties(g, l, c).position_associate); - } else if (style == Graph::VectXYXY || style == Graph::VectXYAM) { + } else if (style == GraphOptions::VectXYXY || + style == GraphOptions::VectXYAM) { vectorProperties vector = opj.curveVectorProperties(g, l, c); graph->updateVectorsLayout( c, ColorBox::color(cl.symCol), ceil(vector.width), @@ -981,12 +987,12 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { vector<int> ticksX = opj.layerXTicks(g, l); graphLayerRange rangeY = opj.layerYRange(g, l); vector<int> ticksY = opj.layerYTicks(g, l); - if (style == Graph::HorizontalBars) { + if (style == GraphOptions::HorizontalBars) { graph->setScale(0, rangeX.min, rangeX.max, rangeX.step, ticksX[0], ticksX[1], opj.layerXScale(g, l)); graph->setScale(2, rangeY.min, rangeY.max, rangeY.step, ticksY[0], ticksY[1], opj.layerYScale(g, l)); - } else if (style != Graph::Box) { + } else if (style != GraphOptions::Box) { graphAxisBreak breakX = opj.layerXBreak(g, l); graphAxisBreak breakY = opj.layerYBreak(g, l); @@ -1167,7 +1173,7 @@ bool ImportOPJ::importGraphs(const OPJFile &opj) { // add texts vector<text> texts = opj.layerTexts(g, l); - if (style != Graph::Pie) { + if (style != GraphOptions::Pie) { for (size_t i = 0; i < texts.size(); ++i) { addText(texts[i], graph, 0, layerRect, fFontScaleFactor, fXScale, fYScale); diff --git a/MantidPlot/src/qti.sip b/MantidPlot/src/qti.sip index 97803375bfa16827ea23d6559c2dfe331a09766f..6ebefc7df62fdf8c0b8930aeaf77391d395e94cd 100644 --- a/MantidPlot/src/qti.sip +++ b/MantidPlot/src/qti.sip @@ -701,9 +701,6 @@ class Graph : QWidget /PyName=Layer/ %End public: enum TicksStyle{NoTicks = 0, Out = 1, InOut = 2, In = 3}; - enum CurveType{Line, Scatter, LineSymbols, VerticalBars, Area, Pie, VerticalDropLines, - Spline, HorizontalSteps, Histogram, HorizontalBars, VectXYXY, ErrorBars, - Box, VectXYAM, VerticalSteps, ColorMap, GrayScale, ColorMapContour, Contour, Function, ImagePlot}; bool isPiePlot(); SIP_PYOBJECT pieLegendText() /PyName=pieLegend/; @@ -713,7 +710,7 @@ public: bool insertCurve(Table*, const QString&, int style = 1, int startRow = 0, int endRow = -1); bool insertCurve(Table*, const QString&, const QString&, int style = 1, int startRow = 0, int endRow = -1); - bool insertCurve(QString, int, bool=false, Graph::CurveType style = Graph::Unspecified, bool=false); + bool insertCurve(QString, int, bool=false, GraphOptions::CurveType style = GraphOptions::Unspecified, bool=false); void insertCurve(Graph*, int); bool addCurves(Table*, SIP_PYTUPLE, int=0, double=1, int=3, int=0, int=-1); %MethodCode @@ -1195,7 +1192,7 @@ public: %End Matrix* importImage(const QString&); - MultiLayer* plotSpectrogram(Matrix*, Graph::CurveType = Graph::ColorMap) /PyName=plot/; + MultiLayer* plotSpectrogram(Matrix*, GraphOptions::CurveType = GraphOptions::ColorMap) /PyName=plot/; Graph3D* newPlot3D(); Graph3D* plotXYZ(Table* table, const QString&, int = 0) /PyName=plot3D/; @@ -1362,7 +1359,7 @@ public: double dataE(int,int) const; //int indexX(int,double) const; Graph3D* plotGraph3D(int = 3); - MultiLayer* plotGraph2D(Graph::CurveType = Graph::ColorMap); + MultiLayer* plotGraph2D(GraphOptions::CurveType = GraphOptions::ColorMap); void goToTab(const QString &); void goTo(int,int) /PyName = selectCell/; void goToRow(int) /PyName = selectRow/; @@ -1477,11 +1474,11 @@ public: // Plotting methods MultiLayer *plot1D(const QList<QString> &wsnames, const QList<int> &, bool spectrumPlot, MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, - bool errs = true, Graph::CurveType style = Graph::Unspecified, + bool errs = true, GraphOptions::CurveType style = GraphOptions::Unspecified, MultiLayer *plotWindow = NULL, bool clearWindow = false, bool waterfallPlot = false); - MultiLayer* drawSingleColorFillPlot(const QString & name, Graph::CurveType style = Graph::ColorMap, + MultiLayer* drawSingleColorFillPlot(const QString & name, GraphOptions::CurveType style = GraphOptions::ColorMap, MultiLayer* window = NULL); MultiLayer* plotMDList(const QList<QString>& wsNames, const int plotAxis, diff --git a/MantidQt/API/CMakeLists.txt b/MantidQt/API/CMakeLists.txt index f05390cf2486ec1d319ec1a92a87cf5a7eaa1917..f6cdaa1ed48eb1eae067d824aeece59f653ea6b8 100644 --- a/MantidQt/API/CMakeLists.txt +++ b/MantidQt/API/CMakeLists.txt @@ -8,6 +8,7 @@ src/FilePropertyWidget.cpp src/GenericDialog.cpp src/HelpWindow.cpp + src/FlowLayout.cpp src/InterfaceFactory.cpp src/InterfaceManager.cpp src/ListPropertyWidget.cpp @@ -24,6 +25,7 @@ src/MdSettings.cpp src/Message.cpp src/OptionsPropertyWidget.cpp + src/pixmaps.cpp src/PlotAxis.cpp src/PowerScaleEngine.cpp src/PropertyWidget.cpp @@ -48,6 +50,7 @@ src/VatesViewerInterface.cpp src/WidgetScrollbarDecorator.cpp src/WorkspaceObserver.cpp + src/WorkspaceIcons.cpp ) set ( MOC_FILES @@ -87,6 +90,7 @@ set ( INC_FILES inc/MantidQtAPI/BatchAlgorithmRunner.h inc/MantidQtAPI/DllOption.h inc/MantidQtAPI/FileDialogHandler.h + inc/MantidQtAPI/FlowLayout.h inc/MantidQtAPI/GraphOptions.h inc/MantidQtAPI/DistributionOptions.h inc/MantidQtAPI/HelpWindow.h @@ -101,6 +105,7 @@ set ( INC_FILES inc/MantidQtAPI/MdConstants.h inc/MantidQtAPI/MdPlottingCmapsProvider.h inc/MantidQtAPI/MdSettings.h + inc/MantidQtAPI/pixmaps.h inc/MantidQtAPI/PlotAxis.h inc/MantidQtAPI/PowerScaleEngine.h inc/MantidQtAPI/PropertyWidgetFactory.h @@ -118,6 +123,7 @@ set ( INC_FILES inc/MantidQtAPI/TSVSerialiser.h inc/MantidQtAPI/qwt_compat.h inc/MantidQtAPI/WidgetScrollbarDecorator.h + inc/MantidQtAPI/WorkspaceIcons.h ) set ( UI_FILES diff --git a/MantidPlot/src/Mantid/FlowLayout.h b/MantidQt/API/inc/MantidQtAPI/FlowLayout.h similarity index 95% rename from MantidPlot/src/Mantid/FlowLayout.h rename to MantidQt/API/inc/MantidQtAPI/FlowLayout.h index 6dfd605e1e13929a3831c8791d8c7210e9b8047a..c189190c067940bdd9e17b3203d9fd2a70f94370 100644 --- a/MantidPlot/src/Mantid/FlowLayout.h +++ b/MantidQt/API/inc/MantidQtAPI/FlowLayout.h @@ -41,10 +41,15 @@ #ifndef FLOWLAYOUT_H #define FLOWLAYOUT_H +#include "MantidQtAPI/DllOption.h" #include <QLayout> #include <QRect> +#include <QStyle> #include <QWidgetItem> -class FlowLayout : public QLayout { + +namespace MantidQt { +namespace API { +class EXPORT_OPT_MANTIDQT_API FlowLayout : public QLayout { public: FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1); @@ -72,5 +77,7 @@ private: int m_hSpace; int m_vSpace; }; +} +} #endif diff --git a/MantidQt/API/inc/MantidQtAPI/GraphOptions.h b/MantidQt/API/inc/MantidQtAPI/GraphOptions.h index 53e952bde26867e54a3424dcecd25b34577db395..62d196995a0931d529bbd1d243e0bed6fccf7653 100644 --- a/MantidQt/API/inc/MantidQtAPI/GraphOptions.h +++ b/MantidQt/API/inc/MantidQtAPI/GraphOptions.h @@ -16,6 +16,36 @@ enum ScaleType { Linear = 0, Log10, Power }; * Axis choice */ enum Axis { Left, Right, Bottom, Top }; + +/** +* Graph curve type +*/ +enum CurveType { + Unspecified = -1, + Line, + Scatter, + LineSymbols, + VerticalBars, + Area, + Pie, + VerticalDropLines, + Spline, + HorizontalSteps, + Histogram, + HorizontalBars, + VectXYXY, + ErrorBars, + Box, + VectXYAM, + VerticalSteps, + ColorMap, + GrayScale, + ColorMapContour, + Contour, + Function, + ImagePlot, + User +}; } #endif // MANTIDSCALETYPE_H_ diff --git a/MantidPlot/src/Mantid/WorkspaceIcons.h b/MantidQt/API/inc/MantidQtAPI/WorkspaceIcons.h similarity index 64% rename from MantidPlot/src/Mantid/WorkspaceIcons.h rename to MantidQt/API/inc/MantidQtAPI/WorkspaceIcons.h index 68d75f8cced7ea178101ad2508e72d0dc8b02df7..877542fbf2647947f495f3c7229249943d994444 100644 --- a/MantidPlot/src/Mantid/WorkspaceIcons.h +++ b/MantidQt/API/inc/MantidQtAPI/WorkspaceIcons.h @@ -1,14 +1,17 @@ -#ifndef WORKSPACEICONS_H_ -#define WORKSPACEICONS_H_ +#ifndef MANTIDQT_API_WORKSPACEICONS_H_ +#define MANTIDQT_API_WORKSPACEICONS_H_ +#include "DllOption.h" #include <QMap> #include <QPixmap> +namespace MantidQt { +namespace API { /** * Defines a mapping between a workspace ID and a pixmap * to use for an icon. */ -class WorkspaceIcons { +class EXPORT_OPT_MANTIDQT_API WorkspaceIcons { public: WorkspaceIcons(); @@ -22,5 +25,6 @@ private: /// Internal map instance QMap<std::string, std::string> m_idToPixmapName; }; - -#endif +} +} +#endif // MANTIDQT_API_WORKSPACEICONS_H_ diff --git a/MantidPlot/src/pixmaps.h b/MantidQt/API/inc/MantidQtAPI/pixmaps.h similarity index 89% rename from MantidPlot/src/pixmaps.h rename to MantidQt/API/inc/MantidQtAPI/pixmaps.h index d0083c720570da2f00bbde1acbc1ca0b751737b0..9aecd3794b44fd617c0b615023dd5204425e4926 100644 --- a/MantidPlot/src/pixmaps.h +++ b/MantidQt/API/inc/MantidQtAPI/pixmaps.h @@ -28,12 +28,17 @@ * * ***************************************************************************/ -#ifndef PIXMAPS_H -#define PIXMAPS_H +#ifndef MANTIDQT_API_PIXMAPS_H +#define MANTIDQT_API_PIXMAPS_H +#include <MantidQtAPI/DllOption.h> #include "qpixmap.h" +namespace MantidQt { +namespace API { /** Function that returns a QPixmap given a string name. */ -QPixmap getQPixmap(const std::string &name); +EXPORT_OPT_MANTIDQT_API QPixmap getQPixmap(const std::string &name); +} +} -#endif +#endif // MANTIDQT_API_PIXMAPS_H diff --git a/MantidPlot/src/Mantid/FlowLayout.cpp b/MantidQt/API/src/FlowLayout.cpp similarity index 98% rename from MantidPlot/src/Mantid/FlowLayout.cpp rename to MantidQt/API/src/FlowLayout.cpp index e45d988c836642a8d3647312db757ecc1a422dd0..41aee2ade0cf98fdba320549ec8d503230f8d9b9 100644 --- a/MantidPlot/src/Mantid/FlowLayout.cpp +++ b/MantidQt/API/src/FlowLayout.cpp @@ -40,7 +40,10 @@ #include <QtGui> -#include "FlowLayout.h" +#include "MantidQtAPI/FlowLayout.h" + +namespace MantidQt { +namespace API { FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing) : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing) { setContentsMargins(margin, margin, margin, margin); @@ -160,3 +163,5 @@ int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const { return static_cast<QLayout *>(parent)->spacing(); } } +} +} \ No newline at end of file diff --git a/MantidPlot/src/Mantid/WorkspaceIcons.cpp b/MantidQt/API/src/WorkspaceIcons.cpp similarity index 94% rename from MantidPlot/src/Mantid/WorkspaceIcons.cpp rename to MantidQt/API/src/WorkspaceIcons.cpp index 114d7e46590f75a40ade7bb2a9d9393e4a13f3f7..ebc388cf8f0c1d2f4f2898b3bbd590e38c9523a5 100644 --- a/MantidPlot/src/Mantid/WorkspaceIcons.cpp +++ b/MantidQt/API/src/WorkspaceIcons.cpp @@ -1,9 +1,11 @@ //----------------------------------------------------------------------------- // Includes //----------------------------------------------------------------------------- -#include "WorkspaceIcons.h" -#include "../pixmaps.h" +#include "MantidQtAPI/WorkspaceIcons.h" +#include "MantidQtAPI/pixmaps.h" +namespace MantidQt { +namespace API { //----------------------------------------------------------------------------- // Public member functions //----------------------------------------------------------------------------- @@ -53,3 +55,5 @@ void WorkspaceIcons::initInternalLookup() { m_idToPixmapName["MDHistoWorkspace"] = "mantid_mdws_xpm"; m_idToPixmapName["MDEventWorkspace"] = "mantid_mdws_xpm"; } +} +} diff --git a/MantidPlot/src/pixmaps.cpp b/MantidQt/API/src/pixmaps.cpp similarity index 99% rename from MantidPlot/src/pixmaps.cpp rename to MantidQt/API/src/pixmaps.cpp index 0d2a02e4a2f65786d942e88023fff67b39ee72fb..d9aca682285e91ef1c91298bc7163aadf5400113 100644 --- a/MantidPlot/src/pixmaps.cpp +++ b/MantidQt/API/src/pixmaps.cpp @@ -6,11 +6,13 @@ * Author: janik */ -#include "pixmaps.h" +#include "MantidQtAPI/pixmaps.h" #include <sstream> #include <stdexcept> +namespace MantidQt{ +namespace API{ //================================================================================== // xpms from other spots in the files @@ -13000,3 +13002,5 @@ QPixmap getQPixmap(const std::string &name) } +} +} \ No newline at end of file diff --git a/MantidQt/MantidWidgets/CMakeLists.txt b/MantidQt/MantidWidgets/CMakeLists.txt index 3cec1635965fcd4ddb074d912dbe76c8b39bb48e..e1a947158e21eb28c66a71c498940b443a6c2189 100644 --- a/MantidQt/MantidWidgets/CMakeLists.txt +++ b/MantidQt/MantidWidgets/CMakeLists.txt @@ -84,10 +84,14 @@ set ( SRC_FILES src/InstrumentView/XIntegrationControl.cpp src/LineEditWithClear.cpp src/LogValueSelector.cpp + src/MantidTreeWidget.cpp + src/MantidTreeWidgetItem.cpp src/MWDiag.cpp src/MWRunFiles.cpp src/MWView.cpp src/MantidHelpWindow.cpp + src/MantidSurfacePlotDialog.cpp + src/MantidWSIndexDialog.cpp src/MessageDisplay.cpp src/MultifitSetupDialog.cpp src/MuonFitDataSelector.cpp @@ -115,6 +119,9 @@ set ( SRC_FILES src/WorkspaceSelector.cpp src/pqHelpWindow.cxx src/pythonCalc.cpp + src/WorkspacePresenter/WorkspacePresenter.cpp + src/WorkspacePresenter/ADSAdapter.cpp + src/WorkspacePresenter/QWorkspaceDockView.cpp ) # Header files with Q_OBJECT that qmake will "moc" @@ -145,6 +152,9 @@ set ( MOC_FILES inc/MantidQtMantidWidgets/InstrumentSelector.h inc/MantidQtMantidWidgets/IndirectInstrumentConfig.h inc/MantidQtMantidWidgets/InputController.h + inc/MantidQtMantidWidgets/MantidSurfacePlotDialog.h + inc/MantidQtMantidWidgets/MantidWSIndexDialog.h + inc/MantidQtMantidWidgets/MantidTreeWidget.h inc/MantidQtMantidWidgets/MantidHelpWindow.h inc/MantidQtMantidWidgets/MessageDisplay.h inc/MantidQtMantidWidgets/MultifitSetupDialog.h @@ -197,8 +207,9 @@ set ( MOC_FILES inc/MantidQtMantidWidgets/InstrumentView/Shape2DCollection.h inc/MantidQtMantidWidgets/InstrumentView/UnwrappedSurface.h inc/MantidQtMantidWidgets/InstrumentView/UCorrectionDialog.h - inc/MantidQtMantidWidgets/InstrumentView/XIntegrationControl.h + inc/MantidQtMantidWidgets/InstrumentView/XIntegrationControl.h inc/MantidQtMantidWidgets/LogValueSelector.h + inc/MantidQtMantidWidgets/WorkspacePresenter/QWorkspaceDockView.h ) # Add the include files are NOT already in MOC_FILES @@ -299,11 +310,19 @@ set ( INC_FILES inc/MantidQtMantidWidgets/InstrumentView/Viewport.h inc/MantidQtMantidWidgets/InstrumentView/XIntegrationControl.h inc/MantidQtMantidWidgets/LogValueSelector.h + inc/MantidQtMantidWidgets/MantidDisplayBase.h + inc/MantidQtMantidWidgets/MantidTreeWidgetItem.h inc/MantidQtMantidWidgets/MuonFitDataSelector.h inc/MantidQtMantidWidgets/MuonFunctionBrowser.h inc/MantidQtMantidWidgets/ProgressPresenter.h - inc/MantidQtMantidWidgets/ProgressableView.h - inc/MantidQtMantidWidgets/WidgetDllOption.h + inc/MantidQtMantidWidgets/ProgressableView.h + inc/MantidQtMantidWidgets/ProgressPresenter.h + inc/MantidQtMantidWidgets/WorkspacePresenter/ViewNotifiable.h + inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspaceProviderNotifiable.h + inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspacePresenter.h + inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspaceProvider.h + inc/MantidQtMantidWidgets/WorkspacePresenter/ADSAdapter.h + inc/MantidQtMantidWidgets/WorkspacePresenter/IWorkspaceDockView.h ) # QtDesigner UI files to process @@ -341,7 +360,7 @@ set ( TEST_PY_FILES ) set ( TEST_FILES - AlgorithmHintStrategyTest.h + AlgorithmHintStrategyTest.h DataProcessorUI/DataProcessorPostprocessingAlgorithmTest.h DataProcessorUI/DataProcessorPreprocessingAlgorithmTest.h DataProcessorUI/DataProcessorProcessingAlgorithmBaseTest.h @@ -355,6 +374,8 @@ set ( TEST_FILES DataProcessorUI/ParseKeyValueStringTest.h DataProcessorUI/QDataProcessorOneLevelTreeModelTest.h DataProcessorUI/QDataProcessorTwoLevelTreeModelTest.h + WorkspacePresenter/WorkspacePresenterTest.h + WorkspacePresenter/ADSAdapterTest.h ) find_package (Qt4 REQUIRED QtHelp QtWebKit QtNetwork QUIET) diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/ColorBarWidget.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/ColorBarWidget.h index 9ee42ea6eceb84b8b0b1763f273fc5977834d1fd..3a1bba8ffa677d2fbc25de56cb54c0eef53be60c 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/ColorBarWidget.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/ColorBarWidget.h @@ -1,12 +1,12 @@ #ifndef MANTID_MANTIDWIDGETS_COLORBARWIDGET_H_ #define MANTID_MANTIDWIDGETS_COLORBARWIDGET_H_ -#include <QtGui/QWidget> -#include "ui_ColorBarWidget.h" -#include <qwt_scale_widget.h> #include "MantidQtAPI/MantidColorMap.h" -#include <QtGui> #include "MantidQtMantidWidgets/WidgetDllOption.h" +#include "ui_ColorBarWidget.h" +#include <QtGui/QWidget> +#include <QtGui> +#include <qwt_scale_widget.h> namespace MantidQt { namespace MantidWidgets { diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidDisplayBase.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidDisplayBase.h new file mode 100644 index 0000000000000000000000000000000000000000..bbb57ba1b21b69e39b9c482bfa76e3684f655ef1 --- /dev/null +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidDisplayBase.h @@ -0,0 +1,137 @@ +#ifndef MANTID_MANTIDWIDGETS_MANTIDDISPLAYBASE_H_ +#define MANTID_MANTIDWIDGETS_MANTIDDISPLAYBASE_H_ + +#include "MantidKernel/System.h" +#include <MantidAPI/AlgorithmObserver.h> +#include <MantidAPI/IAlgorithm_fwd.h> +#include <MantidQtAPI/DistributionOptions.h> +#include <MantidQtAPI/GraphOptions.h> +#include <map> +#include <set> +#include <string> +#include <unordered_map> +#include <vector> + +template <class Key, class T> class QHash; +template <class Key, class T> class QMultiMap; +class QString; +class QStringList; +class Table; +class MultiLayer; +class MantidMatrix; + +namespace MantidQt { +namespace MantidWidgets { + +class MantidSurfacePlotDialog; +class MantidWSIndexDialog; + +/** +\class MantidBase +\brief Contains display methods which will be used by +QWorkspaceDockView. +\author Lamar Moore +\date 24-08-2016 +\version 1.0 + + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +*/ +class DLLExport MantidDisplayBase { +public: + virtual ~MantidDisplayBase() = default; + + // Data display and saving methods + virtual void updateRecentFilesList(const QString &fname) = 0; + virtual void enableSaveNexus(const QString &wsName) = 0; + virtual void disableSaveNexus() = 0; + virtual void deleteWorkspaces(const QStringList &wsNames = QStringList()) = 0; + virtual void importWorkspace() = 0; + virtual MantidMatrix * + importMatrixWorkspace(const Mantid::API::MatrixWorkspace_sptr workspace, + int lower = -1, int upper = -1, + bool showDlg = true) = 0; + virtual void importWorkspace(const QString &wsName, bool showDlg = true, + bool makeVisible = true) = 0; + virtual void renameWorkspace(QStringList = QStringList()) = 0; + virtual void showMantidInstrumentSelected() = 0; + virtual Table *createDetectorTable(const QString &wsName, + const std::vector<int> &indices, + bool include_data = false) = 0; + virtual void importBoxDataTable() = 0; + virtual void showListData() = 0; + virtual void importTransposed() = 0; + + // Algorithm Display and Execution Methods + virtual Mantid::API::IAlgorithm_sptr createAlgorithm(const QString &algName, + int version = -1) = 0; + virtual void showAlgorithmDialog(const QString &algName, + int version = -1) = 0; + virtual void showAlgorithmDialog(const QString &algName, + QHash<QString, QString> paramList, + Mantid::API::AlgorithmObserver *obs = NULL, + int version = -1) = 0; + virtual void executeAlgorithm(Mantid::API::IAlgorithm_sptr alg) = 0; + virtual bool executeAlgorithmAsync(Mantid::API::IAlgorithm_sptr alg, + const bool wait = false) = 0; + + virtual Mantid::API::Workspace_const_sptr + getWorkspace(const QString &workspaceName) = 0; + + virtual QWidget *getParent() = 0; + + // Plotting Methods + virtual MultiLayer * + plot1D(const QMultiMap<QString, std::set<int>> &toPlot, bool spectrumPlot, + MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, + bool errs = false, MultiLayer *plotWindow = NULL, + bool clearWindow = false, bool waterfallPlot = false) = 0; + virtual void drawColorFillPlots( + const QStringList &wsNames, + GraphOptions::CurveType curveType = GraphOptions::ColorMap) = 0; + virtual void showMDPlot() = 0; + virtual void showSurfacePlot() = 0; + virtual void showContourPlot() = 0; + + // Interface Methods + virtual void showVatesSimpleInterface() = 0; + virtual void showSpectrumViewer() = 0; + virtual void showSliceViewer() = 0; + virtual void showLogFileWindow() = 0; + virtual void showSampleMaterialWindow() = 0; + virtual void showAlgorithmHistory() = 0; + + virtual MantidSurfacePlotDialog * + createSurfacePlotDialog(int flags, QStringList wsNames, + const QString &plotType) = 0; + virtual MantidWSIndexDialog *createWorkspaceIndexDialog(int flags, + QStringList wsNames, + bool showWaterfall, + bool showPlotAll) = 0; + + virtual void updateProject() = 0; +#ifdef MAKE_VATES + virtual bool doesVatesSupportOpenGL() = 0; +#endif +}; +} +} +#endif // MANTID_MANTIDWIDGETS_MANTIDDISPLAYBASE_H_ \ No newline at end of file diff --git a/MantidPlot/src/Mantid/MantidSurfacePlotDialog.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidSurfacePlotDialog.h similarity index 83% rename from MantidPlot/src/Mantid/MantidSurfacePlotDialog.h rename to MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidSurfacePlotDialog.h index 052e8bceb9f8c21cef3e641ddfdcd9694d787986..f89539d94d0c8ed89e40709fe686d540d3fc5923 100644 --- a/MantidPlot/src/Mantid/MantidSurfacePlotDialog.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidSurfacePlotDialog.h @@ -1,8 +1,13 @@ -#ifndef MANTIDSURFACEPLOTDIALOG_H_ -#define MANTIDSURFACEPLOTDIALOG_H_ +#ifndef MANTIDQT_MANTIDWIDGETS_MANTIDSURFACEPLOTDIALOG_H_ +#define MANTIDQT_MANTIDWIDGETS_MANTIDSURFACEPLOTDIALOG_H_ -#include <QComboBox> +#include "MantidQtMantidWidgets/WidgetDllOption.h" #include "MantidWSIndexDialog.h" +#include <QComboBox> + +namespace MantidQt { +namespace MantidWidgets { +class MantidDisplayBase; /** * The MantidSurfacePlotDialog offers the same functionality of choosing a @@ -14,7 +19,8 @@ * - The user is offered the choice of only those logs that have single values * per workspace. */ -class MantidSurfacePlotDialog : public QDialog { +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS MantidSurfacePlotDialog + : public QDialog { Q_OBJECT public: @@ -29,7 +35,7 @@ public: /// Constructor - same parameters as one of the parent constructors, along /// with a list of the names of workspaces to be plotted. - MantidSurfacePlotDialog(MantidUI *parent, Qt::WFlags flags, + MantidSurfacePlotDialog(MantidDisplayBase *parent, Qt::WFlags flags, QList<QString> wsNames, const QString &plotType); /// Returns a structure holding all of the selected options UserInputSurface getSelections() const; @@ -65,7 +71,7 @@ private: /// Returns the input custom log values const std::set<double> getCustomLogValues() const; /// A pointer to the parent MantidUI object - MantidUI *m_mantidUI; + MantidDisplayBase *m_mantidUI; /// A list of names of workspaces which are to be plotted. QList<QString> m_wsNames; /// Set to true when user accepts input @@ -80,5 +86,6 @@ private: /// Minimum width for dialog to fit title in static const int MINIMUM_WIDTH; }; - -#endif +} +} +#endif // MANTIDQT_MANTIDWIDGETS_MANTIDSURFACEPLOTDIALOG_H_ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidTreeWidget.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidTreeWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..7b2d596df8ec9b635183e6996db8f4be104fe8b7 --- /dev/null +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidTreeWidget.h @@ -0,0 +1,64 @@ +#ifndef MANTIDQT_MANTIDWIDGETS_MANTIDTREEWIDGET_H +#define MANTIDQT_MANTIDWIDGETS_MANTIDTREEWIDGET_H + +#include "MantidQtMantidWidgets/WidgetDllOption.h" +#include <MantidAPI/AnalysisDataService.h> +#include <MantidAPI/MatrixWorkspace_fwd.h> +#include <MantidQtMantidWidgets/MantidSurfacePlotDialog.h> +#include <MantidQtMantidWidgets/MantidWSIndexDialog.h> + +#include <QTreeWidget> +#include <boost/shared_ptr.hpp> + +namespace MantidQt { +namespace MantidWidgets { +class MantidDisplayBase; +class QWorkspaceDockView; + +enum class MantidItemSortScheme { ByName, ByLastModified }; + +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS MantidTreeWidget : public QTreeWidget { + Q_OBJECT + +public: + MantidTreeWidget(QWorkspaceDockView *w, MantidDisplayBase *mui); + void mousePressEvent(QMouseEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void mouseDoubleClickEvent(QMouseEvent *e) override; + + QStringList getSelectedWorkspaceNames() const; + MantidWSIndexWidget::UserInput + chooseSpectrumFromSelected(bool showWaterfallOpt = true, + bool showPlotAll = true) const; + void setSortScheme(MantidItemSortScheme); + void setSortOrder(Qt::SortOrder); + MantidItemSortScheme getSortScheme() const; + Qt::SortOrder getSortOrder() const; + void logWarningMessage(const std::string &); + void disableNodes(bool); + void sort(); + void dropEvent(QDropEvent *de) override; + QList<boost::shared_ptr<const Mantid::API::MatrixWorkspace>> + getSelectedMatrixWorkspaces() const; + MantidSurfacePlotDialog::UserInputSurface + chooseSurfacePlotOptions(int nWorkspaces) const; + MantidSurfacePlotDialog::UserInputSurface + chooseContourPlotOptions(int nWorkspaces) const; + +protected: + void dragMoveEvent(QDragMoveEvent *de) override; + void dragEnterEvent(QDragEnterEvent *de) override; + MantidSurfacePlotDialog::UserInputSurface + choosePlotOptions(const QString &type, int nWorkspaces) const; + +private: + QPoint m_dragStartPosition; + QWorkspaceDockView *m_dockWidget; + MantidDisplayBase *m_mantidUI; + Mantid::API::AnalysisDataServiceImpl &m_ads; + MantidItemSortScheme m_sortScheme; + Qt::SortOrder m_sortOrder; +}; +} +} +#endif // MANTIDQT_MANTIDWIDGETS_MANTIDTREEWIDGET_H \ No newline at end of file diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidTreeWidgetItem.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidTreeWidgetItem.h new file mode 100644 index 0000000000000000000000000000000000000000..69743ed5f8749f485806326d846cceebbf3011a0 --- /dev/null +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidTreeWidgetItem.h @@ -0,0 +1,33 @@ +#ifndef MANTIDTREEWIDGETITEM_H +#define MANTIDTREEWIDGETITEM_H + +#include "MantidQtMantidWidgets/WidgetDllOption.h" +#include <MantidKernel/DateAndTime.h> +#include <MantidQtAPI/WorkspaceObserver.h> +#include <QTreeWidgetItem> + +namespace MantidQt { +namespace MantidWidgets { +class MantidTreeWidget; + +/**A class derived from QTreeWidgetItem, to accomodate +* sorting on the items in a MantidTreeWidget. +*/ +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS MantidTreeWidgetItem + : public QTreeWidgetItem { +public: + explicit MantidTreeWidgetItem(MantidTreeWidget *); + MantidTreeWidgetItem(QStringList, MantidTreeWidget *); + void disableIfNode(bool); + void setSortPos(int o) { m_sortPos = o; } + int getSortPos() const { return m_sortPos; } + +private: + bool operator<(const QTreeWidgetItem &other) const override; + MantidTreeWidget *m_parent; + static Mantid::Kernel::DateAndTime getLastModified(const QTreeWidgetItem *); + int m_sortPos; +}; +} +} +#endif // MANTIDTREEWIDGETITEM_H \ No newline at end of file diff --git a/MantidPlot/src/Mantid/MantidWSIndexDialog.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidWSIndexDialog.h similarity index 77% rename from MantidPlot/src/Mantid/MantidWSIndexDialog.h rename to MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidWSIndexDialog.h index e421b670121fb6aba7632aec149ce9d5e75dfe88..dc12a80cef3d927e77a66a457843a90a082344f3 100644 --- a/MantidPlot/src/Mantid/MantidWSIndexDialog.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MantidWSIndexDialog.h @@ -4,74 +4,89 @@ //---------------------------------- // Includes //---------------------------------- +#include "MantidQtMantidWidgets/WidgetDllOption.h" #include <QCheckBox> #include <QDialog> -#include <QString> -#include <QList> #include <QLabel> -#include <QVBoxLayout> #include <QLineEdit> -#include <QValidator> +#include <QList> #include <QMap> +#include <QString> +#include <QVBoxLayout> +#include <QValidator> #include <set> -#include "MantidUI.h" - +namespace MantidQt { +namespace MantidWidgets { //---------------------------------- // Forward declarations //---------------------------------- class IntervalList; /** - The MantidWSIndexDialog class presents users with a dialog so that they may - specify which workspace indices / spectra IDs are to be plotted by Mantid. - - They are prompted with the available range(s) of indices/IDs they can plot. - They must enter a range(s) that is(are) enclosed within those ranges. - - "Ranges" are of a format you've probably seen when inputting page numbers to - print into a word processing program or similar, i.e. "2, 4-6" to print out - pages 2, 4, 5 and 6. - - Ranges are defined by the "Interval" and "IntervalList" classes. - - The IntervalListValidator class overrides QValidator, and allows Mantid - to assertain whether a user has attempted to input a valid range or not. - Altering this class will affect the behaviour of what is allowed to be + The MantidWSIndexDialog class presents users with a dialog so that + they may + specify which workspace indices / spectra IDs are to be plotted by + Mantid. + + They are prompted with the available range(s) of indices/IDs they + can plot. + They must enter a range(s) that is(are) enclosed within those + ranges. + + "Ranges" are of a format you've probably seen when inputting page + numbers to + print into a word processing program or similar, i.e. "2, 4-6" to + print out + pages 2, 4, 5 and 6. + + Ranges are defined by the "Interval" and "IntervalList" classes. + + The IntervalListValidator class overrides QValidator, and allows + Mantid + to assertain whether a user has attempted to input a valid range or + not. + Altering this class will affect the behaviour of what is allowed to + be typed, - and what inputs allow the "OK" button to be pressed. + and what inputs allow the "OK" button to be pressed. - TODO - perhaps the interval objects are useful elsewhere, in which case + TODO - perhaps the interval objects are useful elsewhere, in which + case those - three classes are best in thier own header and source. + three classes are best in thier own header and source. - @author Peter G Parker, ISIS, RAL - @date 2011/10/06 + @author Peter G Parker, ISIS, RAL + @date 2011/10/06 - Copyright © 2009 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge + Copyright © 2009 ISIS Rutherford Appleton Laboratory, NScD Oak + Ridge National Laboratory & European Spallation Source - This file is part of Mantid. + This file is part of Mantid. - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. + You should have received a copy of the GNU General Public License + along with this program. If not, see + <http://www.gnu.org/licenses/>. - File change history is stored at: <https://github.com/mantidproject/mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> + File change history is stored at: + <https://github.com/mantidproject/mantid> + Code Documentation is available at: + <http://doxygen.mantidproject.org> */ -class Interval { +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS Interval { public: /// Constructor - starting and ending at single. explicit Interval(int single); @@ -97,7 +112,8 @@ public: /// Returns a set of ints that represents the interval. std::set<int> getIntSet() const; - /// Returns true if this interval completely contains the interval passed to + /// Returns true if this interval completely contains the interval passed + /// to /// it, else false. bool contains(const Interval &) const; @@ -114,7 +130,7 @@ private: int m_start, m_end; }; -class IntervalList { +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS IntervalList { public: /// Constructor - with empty list. IntervalList(void); @@ -133,7 +149,8 @@ public: /// Returns a string that represents the IntervalList, of the form /// "0, 2-5, 8, 10-12". String is cut short by default to 6 intervals. std::string toStdString(int numOfIntervals = 6) const; - /// Convenience function that returns the contents of toStdString as a QString + /// Convenience function that returns the contents of toStdString as a + /// QString /// object. QString toQString(int numOfIntervals = 6) const; @@ -147,24 +164,28 @@ public: void addIntervals(QString); /// Adds an IntervalList to this IntervalList. void addIntervalList(const IntervalList &); - /// Replaces the current list with the list belonging to given IntervalList + /// Replaces the current list with the list belonging to given + /// IntervalList /// object. void setIntervalList(const IntervalList &); /// Returns a set of ints that represents the interval. std::set<int> getIntSet() const; - /// Returns true if this interval list completely contains the interval passed + /// Returns true if this interval list completely contains the interval + /// passed /// to it, else false. bool contains(const Interval &) const; - /// Returns true if this interval list completely contains the interval list + /// Returns true if this interval list completely contains the interval + /// list /// passed to it, else false. bool contains(const IntervalList &) const; /// Returns true if the QString can be parsed into an IntervalList, else /// false. static bool isParsable(const QString &); - /// Returns true if the QString can be parsed into an IntervalList which can + /// Returns true if the QString can be parsed into an IntervalList which + /// can /// then be contained /// in the IntervalList given, else false. static bool isParsable(const QString &, const IntervalList &); @@ -181,7 +202,8 @@ private: QList<Interval> m_list; }; -class IntervalListValidator : public QValidator { +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS IntervalListValidator + : public QValidator { Q_OBJECT public: @@ -197,15 +219,17 @@ private: IntervalList m_intervalList; }; -class MantidWSIndexWidget : public QWidget { +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS MantidWSIndexWidget : public QWidget { Q_OBJECT - /** Auxiliar class to wrap the QLine allowing to have a warn to the user for + /** Auxiliar class to wrap the QLine allowing to have a warn to the user + * for * invalid inputs. */ class QLineEditWithErrorMark : public QWidget { public: - /// constructor that will join togheter the QLineEdit and an 'invisible' * + /// constructor that will join togheter the QLineEdit and an 'invisible' + /// * /// label. explicit QLineEditWithErrorMark(QWidget *parent = 0); /// virtual destructor to allow Qt to deallocate all objects @@ -223,8 +247,8 @@ class MantidWSIndexWidget : public QWidget { public: /** - * POD structure to hold all user-selected input - */ + * POD structure to hold all user-selected input + */ struct UserInput { QMultiMap<QString, std::set<int>> plots; bool waterfall; @@ -272,11 +296,13 @@ private: /// Check to see if all workspaces have a spectrum axis void checkForSpectraAxes(); - /// Generates an IntervalList which defines which workspace indices the user + /// Generates an IntervalList which defines which workspace indices the + /// user /// can /// ask to plot. void generateWsIndexIntervals(); - /// Generates an IntervalList which defines which spectra IDs the user can ask + /// Generates an IntervalList which defines which spectra IDs the user can + /// ask /// to plot. void generateSpectraNumIntervals(); @@ -307,13 +333,12 @@ private: IntervalList m_wsIndexChoice, m_spectraIdChoice; }; -class MantidWSIndexDialog : public QDialog { +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS MantidWSIndexDialog : public QDialog { Q_OBJECT public: /// Constructor - has a list of the names of workspaces to be plotted. - MantidWSIndexDialog(MantidUI *parent, Qt::WFlags flags, - QList<QString> wsNames, + MantidWSIndexDialog(QWidget *parent, Qt::WFlags flags, QList<QString> wsNames, const bool showWaterfallOption = false, const bool showPlotAll = true, const bool showTiledOption = false); @@ -339,8 +364,6 @@ private: void init(); /// Initializes the layout of the buttons void initButtons(); - /// A pointer to the parent MantidUI object - MantidUI *m_mantidUI; /// Do we allow the display of the "Plot all" button bool m_plotAll; /// Qt objects @@ -348,5 +371,6 @@ private: QHBoxLayout *m_buttonBox; QVBoxLayout *m_outer; }; - +} +} #endif // MANTIDWSINDEXDIALOG_H_ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/ADSAdapter.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/ADSAdapter.h new file mode 100644 index 0000000000000000000000000000000000000000..545a9eb447d76b35b9248f16fb93585ac08b70ba --- /dev/null +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/ADSAdapter.h @@ -0,0 +1,100 @@ +#ifndef MANTID_MANTIDWIDGETS_ADSADAPTER_H_ +#define MANTID_MANTIDWIDGETS_ADSADAPTER_H_ + +#include "MantidQtMantidWidgets/WidgetDllOption.h" +#include "MantidQtMantidWidgets/WorkspacePresenter/WorkspaceProvider.h" +#include <MantidQtAPI/WorkspaceObserver.h> +#include <Poco/NObserver.h> + +namespace MantidQt { +namespace MantidWidgets { +/** +\class ADSAdapter +\author Lamar Moore +\date 24-08-2016 +\version 1.0 + + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +*/ +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS ADSAdapter : public WorkspaceProvider { +public: + explicit ADSAdapter(); + ~ADSAdapter() override; + void registerPresenter(Presenter_wptr presenter) override; + bool doesWorkspaceExist(const std::string &wsname) const override; + + std::map<std::string, Mantid::API::Workspace_sptr> + topLevelItems() const override; + + std::string getOldName() const override; + std::string getNewName() const override; + +private: + std::string m_oldName; + std::string m_newName; + + Presenter_wptr m_presenter; + + Presenter_sptr lockPresenter(); + + // ADS Notification Handlers + void handleAddWorkspace(Mantid::API::WorkspaceAddNotification_ptr pNf); + Poco::NObserver<ADSAdapter, Mantid::API::WorkspaceAddNotification> + m_addObserver; + + void handleReplaceWorkspace( + Mantid::API::WorkspaceAfterReplaceNotification_ptr pNf); + Poco::NObserver<ADSAdapter, Mantid::API::WorkspaceAfterReplaceNotification> + m_replaceObserver; + + void + handleDeleteWorkspace(Mantid::API::WorkspacePostDeleteNotification_ptr pNf); + Poco::NObserver<ADSAdapter, Mantid::API::WorkspacePostDeleteNotification> + m_deleteObserver; + + void handleClearADS(Mantid::API::ClearADSNotification_ptr pNf); + Poco::NObserver<ADSAdapter, Mantid::API::ClearADSNotification> + m_clearADSObserver; + + void handleRenameWorkspace(Mantid::API::WorkspaceRenameNotification_ptr pNf); + Poco::NObserver<ADSAdapter, Mantid::API::WorkspaceRenameNotification> + m_renameObserver; + + void + handleGroupWorkspaces(Mantid::API::WorkspacesGroupedNotification_ptr pNf); + Poco::NObserver<ADSAdapter, Mantid::API::WorkspacesGroupedNotification> + m_groupworkspacesObserver; + + void + handleUnGroupWorkspace(Mantid::API::WorkspaceUnGroupingNotification_ptr pNf); + Poco::NObserver<ADSAdapter, Mantid::API::WorkspaceUnGroupingNotification> + m_ungroupworkspaceObserver; + + void + handleWorkspaceGroupUpdate(Mantid::API::GroupUpdatedNotification_ptr pNf); + Poco::NObserver<ADSAdapter, Mantid::API::GroupUpdatedNotification> + m_workspaceGroupUpdateObserver; +}; +} // namespace MantidWidgets +} // namespace MantidQt + +#endif // MANTID_MANTIDWIDGETS_ADSADAPTER_H_ \ No newline at end of file diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/IWorkspaceDockView.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/IWorkspaceDockView.h new file mode 100644 index 0000000000000000000000000000000000000000..5f67ee91f2e7b88ed165e439c98f0da77dd9bfad --- /dev/null +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/IWorkspaceDockView.h @@ -0,0 +1,115 @@ +#ifndef MANTIDQT_MANTIDWIDGETS_IWORKSPACEDOCKVIEW_H_ +#define MANTIDQT_MANTIDWIDGETS_IWORKSPACEDOCKVIEW_H_ + +#include <MantidAPI/IAlgorithm_fwd.h> +#include <MantidAPI/Workspace_fwd.h> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <map> + +namespace MantidQt { +namespace MantidWidgets { + +class WorkspaceProviderNotifiable; +class ViewNotifiable; + +using WorkspacePresenterWN_wptr = boost::weak_ptr<WorkspaceProviderNotifiable>; +using WorkspacePresenterVN_sptr = boost::shared_ptr<ViewNotifiable>; +using StringList = std::vector<std::string>; +/** +\class IWorkspaceDockView +\author Lamar Moore +\date 24-08-2016 +\version 1.0 + + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +*/ +class IWorkspaceDockView { +public: + enum class SortDirection { Ascending, Descending }; + enum class SortCriteria { ByName, ByLastModified }; + enum class SaveFileType { Nexus, ASCII, ASCIIv1 }; + + virtual ~IWorkspaceDockView(){}; + + virtual void init() = 0; + virtual WorkspacePresenterWN_wptr getPresenterWeakPtr() = 0; + + virtual bool askUserYesNo(const std::string &caption, + const std::string &message) const = 0; + virtual void showCriticalUserMessage(const std::string &caption, + const std::string &message) const = 0; + virtual void showLoadDialog() = 0; + virtual void showLiveDataDialog() = 0; + virtual void showRenameDialog(const StringList &wsNames) = 0; + virtual void recordWorkspaceRename(const std::string &oldName, + const std::string &newName) = 0; + virtual void enableDeletePrompt(bool enable) = 0; + virtual bool isPromptDelete() const = 0; + virtual bool deleteConfirmation() const = 0; + virtual void deleteWorkspaces(const StringList &wsNames) = 0; + virtual void clearView() = 0; + virtual SortDirection getSortDirection() const = 0; + virtual SortCriteria getSortCriteria() const = 0; + virtual void sortWorkspaces(SortCriteria criteria, + SortDirection direction) = 0; + virtual SaveFileType getSaveFileType() const = 0; + virtual void saveWorkspace(SaveFileType type) = 0; + virtual void saveWorkspaces(const StringList &wsNames) = 0; + virtual std::string getFilterText() const = 0; + virtual void filterWorkspaces(const std::string &filterText) = 0; + virtual StringList getSelectedWorkspaceNames() const = 0; + virtual Mantid::API::Workspace_sptr getSelectedWorkspace() const = 0; + virtual void refreshWorkspaces() = 0; + virtual void updateTree( + const std::map<std::string, Mantid::API::Workspace_sptr> &items) = 0; + + // Workspace Context Menu Handlers + virtual void popupContextMenu() = 0; + virtual void showWorkspaceData() = 0; + virtual void showInstrumentView() = 0; + virtual void saveToProgram() = 0; + virtual void plotSpectrum(bool showErrors) = 0; + virtual void showColourFillPlot() = 0; + virtual void showDetectorsTable() = 0; + virtual void showBoxDataTable() = 0; + virtual void showVatesGUI() = 0; + virtual void showMDPlot() = 0; + virtual void showListData() = 0; + virtual void showSpectrumViewer() = 0; + virtual void showSliceViewer() = 0; + virtual void showLogs() = 0; + virtual void showSampleMaterialWindow() = 0; + virtual void showAlgorithmHistory() = 0; + virtual void showTransposed() = 0; + virtual void convertToMatrixWorkspace() = 0; + virtual void convertMDHistoToMatrixWorkspace() = 0; + virtual void showSurfacePlot() = 0; + virtual void showContourPlot() = 0; + + virtual bool executeAlgorithmAsync(Mantid::API::IAlgorithm_sptr alg, + const bool wait = true) = 0; +}; +} // namespace MantidWidgets +} // namespace MantidQt + +#endif // MANTIDQT_MANTIDWIDGETS_IWORKSPACEDOCKVIEW_H_ \ No newline at end of file diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/QWorkspaceDockView.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/QWorkspaceDockView.h new file mode 100644 index 0000000000000000000000000000000000000000..3c272c5087d9b6efe7dccf6c3079ae17532fbc36 --- /dev/null +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/QWorkspaceDockView.h @@ -0,0 +1,294 @@ +#ifndef MANTIDQT_MANTIDWIDGETS_QWORKSPACEDOCKVIEW_H +#define MANTIDQT_MANTIDWIDGETS_QWORKSPACEDOCKVIEW_H + +#include "MantidQtMantidWidgets/WidgetDllOption.h" + +#include <MantidAPI/ExperimentInfo.h> +#include <MantidAPI/IAlgorithm_fwd.h> +#include <MantidAPI/IMDEventWorkspace_fwd.h> +#include <MantidAPI/IMDWorkspace.h> +#include <MantidAPI/IPeaksWorkspace_fwd.h> +#include <MantidAPI/ITableWorkspace_fwd.h> +#include <MantidAPI/MatrixWorkspace_fwd.h> +#include <MantidAPI/WorkspaceGroup_fwd.h> + +#include <MantidQtMantidWidgets/MantidSurfacePlotDialog.h> +#include <MantidQtMantidWidgets/WorkspacePresenter/IWorkspaceDockView.h> +#include <QDockWidget> +#include <QMap> +#include <QMetaType> +#include <boost/enable_shared_from_this.hpp> +#include <boost/shared_ptr.hpp> +#include <map> + +class QMainWindow; +class QLabel; +class QFileDialog; +class QLineEdit; +class QActionGroup; +class QMenu; +class QPushButton; +class QTreeWidget; +class QTreeWidgetItem; +class QProgressBar; +class QVBoxLayout; +class QHBoxLayout; +class QSignalMapper; +class QSortFilterProxyModel; + +using TopLevelItems = std::map<std::string, Mantid::API::Workspace_sptr>; +Q_DECLARE_METATYPE(TopLevelItems) + +namespace MantidQt { +namespace MantidWidgets { +class MantidDisplayBase; +class MantidTreeWidgetItem; +class MantidTreeWidget; + +/** +\class QWorkspaceDockView +\author Lamar Moore +\date 24-08-2016 +\version 1.0 + + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +*/ +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS QWorkspaceDockView + : public QDockWidget, + public IWorkspaceDockView, + public boost::enable_shared_from_this<QWorkspaceDockView> { + Q_OBJECT +public: + explicit QWorkspaceDockView(MantidQt::MantidWidgets::MantidDisplayBase *mui, + QMainWindow *parent); + ~QWorkspaceDockView(); + void dropEvent(QDropEvent *de) override; + void init() override; + MantidQt::MantidWidgets::WorkspacePresenterWN_wptr + getPresenterWeakPtr() override; + + MantidSurfacePlotDialog::UserInputSurface + chooseContourPlotOptions(int nWorkspaces) const; + MantidSurfacePlotDialog::UserInputSurface + chooseSurfacePlotOptions(int nWorkspaces) const; + + SortDirection getSortDirection() const override; + SortCriteria getSortCriteria() const override; + void sortWorkspaces(SortCriteria criteria, SortDirection direction) override; + + MantidQt::MantidWidgets::StringList + getSelectedWorkspaceNames() const override; + Mantid::API::Workspace_sptr getSelectedWorkspace() const override; + + bool askUserYesNo(const std::string &caption, + const std::string &message) const override; + void showCriticalUserMessage(const std::string &caption, + const std::string &message) const override; + + void showLoadDialog() override; + void showLiveDataDialog() override; + void + showRenameDialog(const MantidQt::MantidWidgets::StringList &wsNames) override; + void enableDeletePrompt(bool enable) override; + bool isPromptDelete() const override; + bool deleteConfirmation() const override; + void + deleteWorkspaces(const MantidQt::MantidWidgets::StringList &wsNames) override; + void clearView() override; + std::string getFilterText() const override; + SaveFileType getSaveFileType() const override; + void saveWorkspace(SaveFileType type) override; + void + saveWorkspaces(const MantidQt::MantidWidgets::StringList &wsNames) override; + void filterWorkspaces(const std::string &filterText) override; + void recordWorkspaceRename(const std::string &oldName, + const std::string &newName) override; + void refreshWorkspaces() override; + + // Context Menu Handlers + void popupContextMenu() override; + void showWorkspaceData() override; + void saveToProgram() override; + void showInstrumentView() override; + void plotSpectrum(bool showErrors) override; + void showColourFillPlot() override; + void showDetectorsTable() override; + void showBoxDataTable() override; + void showVatesGUI() override; + void showMDPlot() override; + void showListData() override; + void showSpectrumViewer() override; + void showSliceViewer() override; + void showLogs() override; + void showSampleMaterialWindow() override; + void showAlgorithmHistory() override; + void showTransposed() override; + void convertToMatrixWorkspace() override; + void convertMDHistoToMatrixWorkspace() override; + void showSurfacePlot() override; + void showContourPlot() override; + + bool executeAlgorithmAsync(Mantid::API::IAlgorithm_sptr alg, + const bool wait = true) override; + +private: + bool hasUBMatrix(const std::string &wsName); + void addSaveMenuOption(QString algorithmString, QString menuEntryName = ""); + void setTreeUpdating(const bool state); + inline bool isTreeUpdating() const { return m_treeUpdating; } + void updateTree(const TopLevelItems &items) override; + void populateTopLevel(const TopLevelItems &topLevelItems, + const QStringList &expanded); + MantidTreeWidgetItem * + addTreeEntry(const std::pair<std::string, Mantid::API::Workspace_sptr> &item, + QTreeWidgetItem *parent = NULL); + bool shouldBeSelected(QString name) const; + void createWorkspaceMenuActions(); + void createSortMenuActions(); + void setItemIcon(QTreeWidgetItem *item, const std::string &wsID); + + void addMatrixWorkspaceMenuItems( + QMenu *menu, + const Mantid::API::MatrixWorkspace_const_sptr &matrixWS) const; + void addMDEventWorkspaceMenuItems( + QMenu *menu, + const Mantid::API::IMDEventWorkspace_const_sptr &mdeventWS) const; + void addMDHistoWorkspaceMenuItems( + QMenu *menu, const Mantid::API::IMDWorkspace_const_sptr &WS) const; + void addPeaksWorkspaceMenuItems( + QMenu *menu, const Mantid::API::IPeaksWorkspace_const_sptr &WS) const; + void addWorkspaceGroupMenuItems( + QMenu *menu, const Mantid::API::WorkspaceGroup_const_sptr &groupWS) const; + void addTableWorkspaceMenuItems(QMenu *menu) const; + void addClearMenuItems(QMenu *menu, const QString &wsName); + + void excludeItemFromSort(MantidTreeWidgetItem *item); + + void setupWidgetLayout(); + void setupLoadButtonMenu(); + void setupConnections(); + +public slots: + void clickedWorkspace(QTreeWidgetItem *, int); + void saveWorkspaceCollection(); + void onClickDeleteWorkspaces(); + void renameWorkspace(); + void populateChildData(QTreeWidgetItem *item); + void onClickSaveToProgram(const QString &name); + void sortAscending(); + void sortDescending(); + void chooseByName(); + void chooseByLastModified(); + +protected slots: + void popupMenu(const QPoint &pos); + void workspaceSelected(); + +private slots: + void handleShowSaveAlgorithm(); + void treeSelectionChanged(); + void onClickGroupButton(); + void onClickLoad(); + void onLoadAccept(); + void onClickLiveData(); + void onClickShowData(); + void onClickShowInstrument(); + void onClickShowBoxData(); + void onClickShowVates(); + void onClickShowMDPlot(); + void onClickShowListData(); + void onClickShowSpectrumViewer(); + void onClickShowSliceViewer(); + void onClickShowFileLog(); + void onClickSaveNexusWorkspace(); + void onClickShowTransposed(); + void onClickPlotSpectra(); + void onClickPlotSpectraErr(); + void onClickDrawColorFillPlot(); + void onClickShowDetectorTable(); + void onClickConvertToMatrixWorkspace(); + void onClickConvertMDHistoToMatrixWorkspace(); + void onClickShowAlgHistory(); + void onClickShowSampleMaterial(); + void onClickPlotSurface(); + void onClickPlotContour(); + void onClickClearUB(); + void incrementUpdateCount(); + void filterWorkspaceTree(const QString &text); + +private: + MantidQt::MantidWidgets::WorkspacePresenterVN_sptr m_presenter; + +protected: + MantidTreeWidget *m_tree; + +private: + QString selectedWsName; + QPoint m_menuPosition; + QString m_programName; + MantidDisplayBase *const m_mantidUI; + + std::string m_filteredText; + QPushButton *m_loadButton; + QPushButton *m_saveButton; + QMenu *m_loadMenu, *m_saveToProgram, *m_sortMenu, *m_saveMenu; + QPushButton *m_deleteButton; + QPushButton *m_groupButton; + QPushButton *m_sortButton; + QLineEdit *m_workspaceFilter; + QSignalMapper *m_programMapper; + QActionGroup *m_sortChoiceGroup; + QFileDialog *m_saveFolderDialog; + + // Context-menu actions + QAction *m_showData, *m_showInst, *m_plotSpec, *m_plotSpecErr, + *m_showDetectors, *m_showBoxData, *m_showVatesGui, *m_showSpectrumViewer, + *m_showSliceViewer, *m_colorFill, *m_showLogs, *m_showSampleMaterial, + *m_showHist, *m_showMDPlot, *m_showListData, *m_saveNexus, *m_rename, + *m_delete, *m_program, *m_ascendingSortAction, *m_descendingSortAction, + *m_byNameChoice, *m_byLastModifiedChoice, *m_showTransposed, + *m_convertToMatrixWorkspace, *m_convertMDHistoToMatrixWorkspace, + *m_clearUB, *m_plotSurface, *m_plotContour; + + QAtomicInt m_updateCount; + bool m_treeUpdating; + bool m_promptDelete; + QMainWindow *m_appParent; + SaveFileType m_saveFileType; + SortCriteria m_sortCriteria; + SortDirection m_sortDirection; + /// Temporarily keeps names of selected workspaces during tree update + /// in order to restore selection after update + QStringList m_selectedNames; + /// Keep a map of renamed workspaces between updates + QHash<QString, QString> m_renameMap; + +private slots: + void handleUpdateTree(const TopLevelItems &); + void handleClearView(); +signals: + void signalClearView(); + void signalUpdateTree(const TopLevelItems &); +}; +} +} +#endif // MANTIDQT_MANTIDWIDGETS_QWORKSPACEDOCKVIEW_H \ No newline at end of file diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/ViewNotifiable.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/ViewNotifiable.h new file mode 100644 index 0000000000000000000000000000000000000000..e368471a7f8082e9aa41fc3a3f59253c169a7c0e --- /dev/null +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/ViewNotifiable.h @@ -0,0 +1,80 @@ +#ifndef MANTID_MANTIDWIDGETS_VIEWNOTIFIABLE_H_ +#define MANTID_MANTIDWIDGETS_VIEWNOTIFIABLE_H_ +/** +\class ViewNotifiable +\brief Mixin class allows view notifications +\author Lamar Moore +\date 24-08-2016 +\version 1.0 + + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +*/ +namespace MantidQt { +namespace MantidWidgets { + +class ViewNotifiable { +public: + virtual ~ViewNotifiable() {} + + enum class Flag { + LoadWorkspace, + LoadLiveDataWorkspace, + RenameWorkspace, + DeleteWorkspaces, + GroupWorkspaces, + UngroupWorkspaces, + SortWorkspaces, + SaveSingleWorkspace, + SaveWorkspaceCollection, + FilterWorkspaces, + PopulateAndShowWorkspaceContextMenu, + SaveToProgram, + ShowWorkspaceData, + ShowInstrumentView, + PlotSpectrum, + PlotSpectrumWithErrors, + ShowColourFillPlot, + ShowDetectorsTable, + ShowBoxDataTable, + ShowVatesGUI, + ShowMDPlot, + ShowListData, + ShowSpectrumViewer, + ShowSliceViewer, + ShowLogs, + ShowSampleMaterialWindow, + ShowAlgorithmHistory, + ShowTransposed, + ConvertToMatrixWorkspace, + ConvertMDHistoToMatrixWorkspace, + ClearUBMatrix, + ShowSurfacePlot, + ShowContourPlot, + RefreshWorkspaces + }; + + virtual void notifyFromView(Flag flag) = 0; +}; + +} // namespace MantidWidgets +} // namespace MantidQt +#endif // MANTID_MANTIDWIDGETS_VIEWNOTIFIABLE_H_ \ No newline at end of file diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspaceDockMockObjects.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspaceDockMockObjects.h new file mode 100644 index 0000000000000000000000000000000000000000..483e827c67457079615cd0e09337368771d0ade1 --- /dev/null +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspaceDockMockObjects.h @@ -0,0 +1,112 @@ +#ifndef MANTIDQT_MANTIDWIDGETS_WORKSPACEDOCKMOCKOBJECTS_H +#define MANTIDQT_MANTIDWIDGETS_WORKSPACEDOCKMOCKOBJECTS_H + +#include "MantidKernel/WarningSuppressions.h" +#include "MantidKernel/make_unique.h" +#include <MantidAPI/Workspace.h> +#include <MantidQtMantidWidgets/WorkspacePresenter/IWorkspaceDockView.h> +#include <MantidQtMantidWidgets/WorkspacePresenter/WorkspacePresenter.h> +#include <boost/enable_shared_from_this.hpp> +#include <boost/make_shared.hpp> +#include <gmock/gmock.h> + +using namespace MantidQt::MantidWidgets; + +GCC_DIAG_OFF_SUGGEST_OVERRIDE + +class MockMantidDisplayBase; + +class MockWorkspaceDockView + : public IWorkspaceDockView, + public boost::enable_shared_from_this<MockWorkspaceDockView> { +public: + MockWorkspaceDockView() {} + ~MockWorkspaceDockView() override {} + + void init() override { + auto presenter = boost::make_shared<WorkspacePresenter>(shared_from_this()); + m_presenter = boost::dynamic_pointer_cast<ViewNotifiable>(presenter); + presenter->init(); + } + + MOCK_CONST_METHOD2(askUserYesNo, bool(const std::string &caption, + const std::string &message)); + MOCK_CONST_METHOD2(showCriticalUserMessage, void(const std::string &caption, + const std::string &message)); + + MOCK_METHOD0(showLoadDialog, void()); + MOCK_METHOD0(showLiveDataDialog, void()); + MOCK_CONST_METHOD0(isPromptDelete, bool()); + MOCK_CONST_METHOD0(deleteConfirmation, bool()); + MOCK_METHOD1(deleteWorkspaces, void(const StringList &wsNames)); + MOCK_METHOD0(clearView, void()); + MOCK_METHOD2(recordWorkspaceRename, + void(const std::string &oldName, const std::string &newName)); + MOCK_METHOD1(showRenameDialog, void(const StringList &wsNames)); + MOCK_CONST_METHOD0(getSortDirection, SortDirection()); + MOCK_CONST_METHOD0(getSortCriteria, SortCriteria()); + MOCK_METHOD2(sortWorkspaces, + void(IWorkspaceDockView::SortCriteria criteria, + IWorkspaceDockView::SortDirection direction)); + MOCK_CONST_METHOD0(getSaveFileType, SaveFileType()); + MOCK_METHOD1(saveWorkspace, void(SaveFileType type)); + MOCK_METHOD1(saveWorkspaces, void(const StringList &wsNames)); + MOCK_METHOD1( + updateTree, + void(const std::map<std::string, Mantid::API::Workspace_sptr> &items)); + + MOCK_CONST_METHOD0(getFilterText, std::string()); + MOCK_METHOD1(filterWorkspaces, void(const std::string &filterText)); + + MOCK_CONST_METHOD0(getSelectedWorkspaceNames, StringList()); + MOCK_CONST_METHOD0(getSelectedWorkspace, Mantid::API::Workspace_sptr()); + + // Context Menu Handlers + MOCK_METHOD0(popupContextMenu, void()); + MOCK_METHOD0(showWorkspaceData, void()); + MOCK_METHOD0(showInstrumentView, void()); + MOCK_METHOD0(saveToProgram, void()); + MOCK_METHOD1(plotSpectrum, void(bool showErrors)); + MOCK_METHOD0(showColourFillPlot, void()); + MOCK_METHOD0(showDetectorsTable, void()); + MOCK_METHOD0(showBoxDataTable, void()); + MOCK_METHOD0(showVatesGUI, void()); + MOCK_METHOD0(showMDPlot, void()); + MOCK_METHOD0(showListData, void()); + MOCK_METHOD0(showSpectrumViewer, void()); + MOCK_METHOD0(showSliceViewer, void()); + MOCK_METHOD0(showLogs, void()); + MOCK_METHOD0(showSampleMaterialWindow, void()); + MOCK_METHOD0(showAlgorithmHistory, void()); + MOCK_METHOD0(showTransposed, void()); + MOCK_METHOD0(convertToMatrixWorkspace, void()); + MOCK_METHOD0(convertMDHistoToMatrixWorkspace, void()); + MOCK_METHOD0(showSurfacePlot, void()); + MOCK_METHOD0(showContourPlot, void()); + + MOCK_METHOD2(executeAlgorithmAsync, + bool(Mantid::API::IAlgorithm_sptr alg, const bool wait)); + + // Methods which are not to be mocked + void enableDeletePrompt(bool) override {} + WorkspacePresenterWN_wptr getPresenterWeakPtr() override { + return boost::dynamic_pointer_cast<WorkspacePresenter>(m_presenter); + } + + void refreshWorkspaces() override {} + + WorkspacePresenterVN_sptr getPresenterSharedPtr() { return m_presenter; } + +private: + WorkspacePresenterVN_sptr m_presenter; +}; + +class MockWorkspaceProviderNotifiable : public WorkspaceProviderNotifiable { +public: + ~MockWorkspaceProviderNotifiable() override {} + MOCK_METHOD1(notifyFromWorkspaceProvider, void(Flag flag)); +}; + +GCC_DIAG_ON_SUGGEST_OVERRIDE + +#endif // MANTIDQT_MANTIDWIDGETS_WORKSPACEDOCKMOCKOBJECTS_H \ No newline at end of file diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspacePresenter.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspacePresenter.h new file mode 100644 index 0000000000000000000000000000000000000000..60698106db3ad59afbc709c2c9dc93b4fa40ae5e --- /dev/null +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspacePresenter.h @@ -0,0 +1,114 @@ +#ifndef MANTIDQT_MANTIDWIDGETS_WORKSPACEPRESENTER_H_ +#define MANTIDQT_MANTIDWIDGETS_WORKSPACEPRESENTER_H_ + +#include "MantidQtMantidWidgets/WidgetDllOption.h" +#include "MantidQtMantidWidgets/WorkspacePresenter/ViewNotifiable.h" +#include "MantidQtMantidWidgets/WorkspacePresenter/WorkspaceProvider.h" +#include "MantidQtMantidWidgets/WorkspacePresenter/WorkspaceProviderNotifiable.h" +#include <boost/weak_ptr.hpp> +#include <memory> + +namespace MantidQt { +namespace MantidWidgets { + +class IWorkspaceDockView; +class WorkspaceProvider; + +using DockView_sptr = boost::shared_ptr<IWorkspaceDockView>; +using DockView_wptr = boost::weak_ptr<IWorkspaceDockView>; +using ADSAdapter_uptr = std::unique_ptr<WorkspaceProvider>; +/** +\class WorkspacePresenter +\brief Presenter class for Workspace dock in MantidPlot UI +\author Lamar Moore +\date 24-08-2016 +\version 1.0 + + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +*/ +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS WorkspacePresenter + : public WorkspaceProviderNotifiable, + public ViewNotifiable { +public: + explicit WorkspacePresenter(DockView_wptr view); + ~WorkspacePresenter() override; + + void init(); + + void + notifyFromWorkspaceProvider(WorkspaceProviderNotifiable::Flag flag) override; + void notifyFromView(ViewNotifiable::Flag flag) override; + +private: + void loadWorkspace(); + void loadLiveData(); + void renameWorkspace(); + void groupWorkspaces(); + void ungroupWorkspaces(); + void sortWorkspaces(); + void deleteWorkspaces(); + void saveSingleWorkspace(); + void saveWorkspaceCollection(); + void filterWorkspaces(); + void populateAndShowWorkspaceContextMenu(); + void showWorkspaceData(); + void showInstrumentView(); + void saveToProgram(); + void plotSpectrum(); + void plotSpectrumWithErrors(); + void showColourFillPlot(); + void showDetectorsTable(); + void showBoxDataTable(); + void showVatesGUI(); + void showMDPlot(); + void showListData(); + void showSpectrumViewer(); + void showSliceViewer(); + void showLogs(); + void showSampleMaterialWindow(); + void showAlgorithmHistory(); + void showTransposed(); + void convertToMatrixWorkspace(); + void convertMDHistoToMatrixWorkspace(); + void clearUBMatrix(); + void showSurfacePlot(); + void showContourPlot(); + void refreshWorkspaces(); + + void workspaceLoaded(); + void workspaceRenamed(); + void workspacesGrouped(); + void workspacesUngrouped(); + void workspaceGroupUpdated(); + void workspacesDeleted(); + void workspacesCleared(); + + DockView_sptr lockView(); + void updateView(); + +private: + DockView_wptr m_view; + ADSAdapter_uptr m_adapter; +}; +} // namespace MantidWidgets +} // namespace MantidQt +#endif // MANTIDQT_MANTIDWIDGETS_WORKSPACEPRESENTER_H_ \ No newline at end of file diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspaceProvider.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspaceProvider.h new file mode 100644 index 0000000000000000000000000000000000000000..880bdc4e5a1febf468c314ece10fee94893bf229 --- /dev/null +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspaceProvider.h @@ -0,0 +1,58 @@ +#ifndef MANTID_MANTIDWIDGETS_WORKSPACEPROVIDER_H_ +#define MANTID_MANTIDWIDGETS_WORKSPACEPROVIDER_H_ + +#include <MantidAPI/Workspace_fwd.h> +#include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <map> + +namespace MantidQt { +namespace MantidWidgets { + +class WorkspaceProviderNotifiable; + +using Presenter_sptr = boost::shared_ptr<WorkspaceProviderNotifiable>; +using Presenter_wptr = boost::weak_ptr<WorkspaceProviderNotifiable>; + +/** +\class WorkspaceProvider +\author Lamar Moore +\date 24-08-2016 +\version 1.0 + + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +*/ +class WorkspaceProvider { +public: + virtual ~WorkspaceProvider() = default; + + virtual void registerPresenter(Presenter_wptr presenter) = 0; + virtual bool doesWorkspaceExist(const std::string &wsname) const = 0; + virtual std::map<std::string, Mantid::API::Workspace_sptr> + topLevelItems() const = 0; + virtual std::string getOldName() const = 0; + virtual std::string getNewName() const = 0; +}; + +} // namespace MantidWidgets +} // namespace MantidQt +#endif // MANTID_MANTIDWIDGETS_WORKSPACEPROVIDER_H_ \ No newline at end of file diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspaceProviderNotifiable.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspaceProviderNotifiable.h new file mode 100644 index 0000000000000000000000000000000000000000..ae0633dc8ebc596a41315c8d6a048c0ae784235b --- /dev/null +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspacePresenter/WorkspaceProviderNotifiable.h @@ -0,0 +1,55 @@ +#ifndef MANTID_MANTIDWIDGETS_WORKSPACEPROVIDERNOTIFIABLE_H_ +#define MANTID_MANTIDWIDGETS_WORKSPACEPROVIDERNOTIFIABLE_H_ + +/** +\class WorkspaceProviderNotifiable +\brief Mixin class allows ADS notifications +\author Lamar Moore +\date 24-08-2016 +\version 1.0 + + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +*/ +namespace MantidQt { +namespace MantidWidgets { + +class WorkspaceProviderNotifiable { +public: + virtual ~WorkspaceProviderNotifiable() {} + + enum class Flag { + WorkspaceLoaded, + WorkspaceRenamed, + WorkspaceDeleted, + WorkspacesCleared, + WorkspacesGrouped, + WorkspacesUngrouped, + WorkspaceGroupUpdated, + GenericUpdateNotification + }; + + virtual void notifyFromWorkspaceProvider(Flag flag) = 0; +}; + +} // namespace MantidWidgets +} // namespace MantidQt +#endif // MANTID_MANTIDWIDGETS_ADSNOTIFIABLE_H_ \ No newline at end of file diff --git a/MantidPlot/src/Mantid/MantidSurfacePlotDialog.cpp b/MantidQt/MantidWidgets/src/MantidSurfacePlotDialog.cpp similarity index 96% rename from MantidPlot/src/Mantid/MantidSurfacePlotDialog.cpp rename to MantidQt/MantidWidgets/src/MantidSurfacePlotDialog.cpp index a8f7da5ed3f94e3da8fca88000622e06daa63d31..9d48784ae6b9f38fa21a8498ce795a02031e238d 100644 --- a/MantidPlot/src/Mantid/MantidSurfacePlotDialog.cpp +++ b/MantidQt/MantidWidgets/src/MantidSurfacePlotDialog.cpp @@ -1,13 +1,17 @@ -#include "MantidSurfacePlotDialog.h" -#include "MantidAPI/IMDWorkspace.h" +#include "MantidQtMantidWidgets/MantidSurfacePlotDialog.h" #include "MantidAPI/ExperimentInfo.h" +#include "MantidAPI/IMDWorkspace.h" +#include "MantidQtMantidWidgets/MantidDisplayBase.h" #include "MantidAPI/Run.h" #include <QMessageBox> +#include <QPushButton> using Mantid::API::IMDWorkspace; using Mantid::API::IMDWorkspace_sptr; using Mantid::API::ExperimentInfo; +namespace MantidQt { +namespace MantidWidgets { /// The string "Workspace index" const QString MantidSurfacePlotDialog::WORKSPACE_INDEX = "Workspace index"; @@ -24,11 +28,11 @@ const int MantidSurfacePlotDialog::MINIMUM_WIDTH = 275; * @param wsNames :: the names of the workspaces to be plotted * @param plotType :: Type of plot (for window title) */ -MantidSurfacePlotDialog::MantidSurfacePlotDialog(MantidUI *mui, +MantidSurfacePlotDialog::MantidSurfacePlotDialog(MantidDisplayBase *mui, Qt::WFlags flags, QList<QString> wsNames, const QString &plotType) - : QDialog(mui->appWindow(), flags), m_widget(this, flags, wsNames, false), + : QDialog(mui->getParent(), flags), m_widget(this, flags, wsNames, false), m_mantidUI(mui), m_wsNames(wsNames), m_accepted(false) { // Set up UI. init(plotType); @@ -264,3 +268,5 @@ void MantidSurfacePlotDialog::showPlotOptionsError(const QString &message) { errorMessage.exec(); } } +} +} \ No newline at end of file diff --git a/MantidQt/MantidWidgets/src/MantidTreeWidget.cpp b/MantidQt/MantidWidgets/src/MantidTreeWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9fc61e81803584d07408a31abc7950c63c23770f --- /dev/null +++ b/MantidQt/MantidWidgets/src/MantidTreeWidget.cpp @@ -0,0 +1,357 @@ +#include "MantidQtMantidWidgets/MantidTreeWidget.h" +#include <MantidQtMantidWidgets/WorkspacePresenter/QWorkspaceDockView.h> + +#include "MantidAPI/MatrixWorkspace.h" +#include "MantidAPI/MatrixWorkspace.h" +#include "MantidAPI/WorkspaceGroup.h" +#include "MantidQtMantidWidgets/MantidDisplayBase.h" + +#include <QApplication> +#include <QDragMoveEvent> +#include <QFileInfo> +#include <QList> +#include <QUrl> + +using namespace Mantid::API; + +namespace { +Mantid::Kernel::Logger treelog("MantidTreeWidget"); +} + +namespace MantidQt { +namespace MantidWidgets { + +MantidTreeWidget::MantidTreeWidget(QWorkspaceDockView *w, + MantidDisplayBase *mui) + : QTreeWidget(w), m_dockWidget(w), m_mantidUI(mui), + m_ads(Mantid::API::AnalysisDataService::Instance()), m_sortScheme() { + setObjectName("WorkspaceTree"); + setSelectionMode(QAbstractItemView::ExtendedSelection); + setSortOrder(Qt::AscendingOrder); + setAcceptDrops(true); +} + +/** +* Accept a drag move event and selects whether to accept the action +* @param de :: The drag move event +*/ +void MantidTreeWidget::dragMoveEvent(QDragMoveEvent *de) { + // The event needs to be accepted here + if (de->mimeData()->hasUrls()) + de->accept(); +} + +/** +* Accept a drag enter event and selects whether to accept the action +* @param de :: The drag enter event +*/ +void MantidTreeWidget::dragEnterEvent(QDragEnterEvent *de) { + // Set the drop action to be the proposed action. + if (de->mimeData()->hasUrls()) + de->acceptProposedAction(); +} + +/** +* Accept a drag drop event and process the data appropriately +* @param de :: The drag drop event +*/ +void MantidTreeWidget::dropEvent(QDropEvent *de) { + QStringList filenames; + const QMimeData *mimeData = de->mimeData(); + if (mimeData->hasUrls()) { + QList<QUrl> urlList = mimeData->urls(); + for (int i = 0; i < urlList.size(); ++i) { + QString fName = urlList[i].toLocalFile(); + if (fName.size() > 0) { + filenames.append(fName); + } + } + } + de->acceptProposedAction(); + + for (int i = 0; i < filenames.size(); ++i) { + try { + QFileInfo fi(filenames[i]); + QString basename = fi.baseName(); + auto alg = m_mantidUI->createAlgorithm("Load"); + alg->initialize(); + alg->setProperty("Filename", filenames[i].toStdString()); + alg->setProperty("OutputWorkspace", basename.toStdString()); + m_mantidUI->executeAlgorithmAsync(alg, true); + } catch (std::runtime_error &error) { + treelog.error() << "Failed to Load the file " + << filenames[i].toStdString() + << " . The reason for failure is: " << error.what() + << '\n'; + } catch (std::logic_error &error) { + treelog.error() << "Failed to Load the file " + << filenames[i].toStdString() + << " . The reason for failure is: " << error.what() + << '\n'; + } catch (std::exception &error) { + treelog.error() << "Failed to Load the file " + << filenames[i].toStdString() + << " . The reason for failure is: " << error.what() + << '\n'; + } + } +} + +void MantidTreeWidget::mousePressEvent(QMouseEvent *e) { + if (e->button() == Qt::LeftButton) { + if (!itemAt(e->pos())) + selectionModel()->clear(); + m_dragStartPosition = e->pos(); + } + + QTreeWidget::mousePressEvent(e); +} + +void MantidTreeWidget::mouseMoveEvent(QMouseEvent *e) { + if (!(e->buttons() & Qt::LeftButton)) + return; + if ((e->pos() - m_dragStartPosition).manhattanLength() < + QApplication::startDragDistance()) + return; + + // Start dragging + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + QStringList wsnames = getSelectedWorkspaceNames(); + if (wsnames.size() == 0) + return; + QString importStatement = ""; + foreach (const QString wsname, wsnames) { + QString prefix = ""; + if (wsname[0].isDigit()) + prefix = "ws"; + if (importStatement.size() > 0) + importStatement += "\n"; + importStatement += prefix + wsname + " = mtd[\"" + wsname + "\"]"; + } + + mimeData->setText(importStatement); + mimeData->setObjectName("MantidWorkspace"); + + drag->setMimeData(mimeData); + + Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction); + (void)dropAction; +} + +void MantidTreeWidget::mouseDoubleClickEvent(QMouseEvent *e) { + try { + std::string wsName = m_dockWidget->getSelectedWorkspaceNames()[0]; + Mantid::API::WorkspaceGroup_sptr grpWSPstr; + grpWSPstr = + boost::dynamic_pointer_cast<WorkspaceGroup>(m_ads.retrieve(wsName)); + if (!grpWSPstr) { + if (!wsName.empty()) { + m_mantidUI->importWorkspace(QString::fromStdString(wsName), false); + return; + } + } + } catch (Mantid::Kernel::Exception::NotFoundError &) { + return; + } + QTreeWidget::mouseDoubleClickEvent(e); +} + +/** +* Returns a list of all selected workspaces. It does NOT +* extract child workspaces from groups - it only returns +* exactly what has been selected. +*/ +QStringList MantidTreeWidget::getSelectedWorkspaceNames() const { + QStringList names; + + foreach (const auto selectedItem, this->selectedItems()) { + if (selectedItem) + names.append(selectedItem->text(0)); + } + + return names; +} + +/** +* Filter the list of selected workspace names to account for any +* non-MatrixWorkspaces that may have been selected. In particular +* WorkspaceGroups (the children of which are to be included if they are +* MatrixWorkspaces) and TableWorkspaces (which are implicitly excluded). +* We only want workspaces we can actually plot! +*/ +QList<MatrixWorkspace_const_sptr> +MantidTreeWidget::getSelectedMatrixWorkspaces() const { + // Check for any selected WorkspaceGroup names and replace with the names of + // their children. + QSet<QString> selectedWsNames; + foreach (const QString wsName, this->getSelectedWorkspaceNames()) { + const auto groupWs = boost::dynamic_pointer_cast<const WorkspaceGroup>( + m_ads.retrieve(wsName.toStdString())); + if (groupWs) { + const auto childWsNames = groupWs->getNames(); + for (auto childWsName : childWsNames) { + selectedWsNames.insert(QString::fromStdString(childWsName)); + } + } else { + selectedWsNames.insert(wsName); + } + } + + // Get the names of, and pointers to, the MatrixWorkspaces only. + QList<MatrixWorkspace_const_sptr> selectedMatrixWsList; + QList<QString> selectedMatrixWsNameList; + foreach (const auto selectedWsName, selectedWsNames) { + const auto matrixWs = boost::dynamic_pointer_cast<const MatrixWorkspace>( + m_ads.retrieve(selectedWsName.toStdString())); + if (matrixWs) { + selectedMatrixWsList.append(matrixWs); + } + } + return selectedMatrixWsList; +} + +/** +* Allows users to choose spectra from the selected workspaces by presenting them +* with a dialog box. Skips showing the dialog box and automatically chooses +* workspace index 0 for all selected workspaces if one or more of the them are +* single-spectrum workspaces. +* +* @param showWaterfallOpt If true, show the waterfall option on the dialog +* @param showPlotAll :: [input] If true, show the "Plot All" button on the +* dialog +* @return :: A MantidWSIndexDialog::UserInput structure listing the selected +* options +*/ +MantidWSIndexWidget::UserInput +MantidTreeWidget::chooseSpectrumFromSelected(bool showWaterfallOpt, + bool showPlotAll) const { + auto selectedMatrixWsList = getSelectedMatrixWorkspaces(); + QList<QString> selectedMatrixWsNameList; + foreach (const auto matrixWs, selectedMatrixWsList) { + selectedMatrixWsNameList.append(QString::fromStdString(matrixWs->name())); + } + + // Check to see if all workspaces have only a single spectrum ... + bool allSingleWorkspaces = true; + foreach (const auto selectedMatrixWs, selectedMatrixWsList) { + if (selectedMatrixWs->getNumberHistograms() != 1) { + allSingleWorkspaces = false; + break; + } + } + + // ... and if so, just return all workspace names mapped to workspace index 0; + if (allSingleWorkspaces) { + const std::set<int> SINGLE_SPECTRUM = {0}; + QMultiMap<QString, std::set<int>> spectrumToPlot; + foreach (const auto selectedMatrixWs, selectedMatrixWsList) { + spectrumToPlot.insert(QString::fromStdString(selectedMatrixWs->name()), + SINGLE_SPECTRUM); + } + MantidWSIndexWidget::UserInput selections; + selections.plots = spectrumToPlot; + selections.waterfall = false; + return selections; + } + + // Else, one or more workspaces + auto dio = m_mantidUI->createWorkspaceIndexDialog( + 0, selectedMatrixWsNameList, showWaterfallOpt, showPlotAll); + dio->exec(); + return dio->getSelections(); +} + +/** +* Allows users to choose spectra from the selected workspaces by presenting them +* with a dialog box, and also allows choice of a log to plot against and a name +* for this axis. +* @param type :: [input] Type of plot (for dialog title) +* @param nWorkspaces :: [input] Number of workspaces in selected group +* @returns :: A structure listing the selected options +*/ +MantidSurfacePlotDialog::UserInputSurface +MantidTreeWidget::choosePlotOptions(const QString &type, + int nWorkspaces) const { + auto selectedMatrixWsList = getSelectedMatrixWorkspaces(); + QList<QString> selectedMatrixWsNameList; + foreach (const auto matrixWs, selectedMatrixWsList) { + selectedMatrixWsNameList.append(QString::fromStdString(matrixWs->name())); + } + auto *dlg = + m_mantidUI->createSurfacePlotDialog(0, selectedMatrixWsNameList, type); + dlg->exec(); + auto selections = dlg->getSelections(); + std::stringstream err; + + if (selections.accepted) { + if (selections.logName == MantidSurfacePlotDialog::CUSTOM) { + // Check number of values supplied + if (static_cast<int>(selections.customLogValues.size()) != nWorkspaces) { + err << "Number of custom log values must be equal to " + "number of workspaces in group"; + selections.accepted = false; + } + } + } + + auto errors = err.str(); + if (!errors.empty()) { + MantidSurfacePlotDialog::showPlotOptionsError(errors.c_str()); + } + return selections; +} + +/** +* Allows users to choose spectra from the selected workspaces by presenting them +* with a dialog box, and also allows choice of a log to plot against and a name +* for this axis. +* @param nWorkspaces :: [input] Number of workspaces in selected group +* @returns :: A structure listing the selected options +*/ +MantidSurfacePlotDialog::UserInputSurface +MantidTreeWidget::chooseSurfacePlotOptions(int nWorkspaces) const { + return choosePlotOptions("Surface", nWorkspaces); +} + +/** +* Allows users to choose spectra from the selected workspaces by presenting them +* with a dialog box, and also allows choice of a log to plot against and a name +* for this axis. +* @param nWorkspaces :: [input] Number of workspaces in selected group +* @returns :: A structure listing the selected options +*/ +MantidSurfacePlotDialog::UserInputSurface +MantidTreeWidget::chooseContourPlotOptions(int nWorkspaces) const { + return choosePlotOptions("Contour", nWorkspaces); +} + +void MantidTreeWidget::setSortScheme(MantidItemSortScheme sortScheme) { + m_sortScheme = sortScheme; +} + +void MantidTreeWidget::setSortOrder(Qt::SortOrder sortOrder) { + m_sortOrder = sortOrder; +} + +Qt::SortOrder MantidTreeWidget::getSortOrder() const { return m_sortOrder; } + +MantidItemSortScheme MantidTreeWidget::getSortScheme() const { + return m_sortScheme; +} + +/** +* Sort the items according to the current sort scheme and order. +*/ +void MantidTreeWidget::sort() { sortItems(sortColumn(), m_sortOrder); } + +/** +* Log a warning message. +* @param msg :: A message to log. +*/ +void MantidTreeWidget::logWarningMessage(const std::string &msg) { + treelog.warning(msg); +} +} +} \ No newline at end of file diff --git a/MantidQt/MantidWidgets/src/MantidTreeWidgetItem.cpp b/MantidQt/MantidWidgets/src/MantidTreeWidgetItem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eed5ee7694e3f0f25a8f75263acd06e986e33218 --- /dev/null +++ b/MantidQt/MantidWidgets/src/MantidTreeWidgetItem.cpp @@ -0,0 +1,105 @@ +#include "MantidQtMantidWidgets/MantidTreeWidgetItem.h" +#include "MantidQtMantidWidgets/MantidTreeWidget.h" + +#include <MantidAPI/Workspace.h> + +using namespace Mantid::Kernel; +using namespace Mantid::API; + +namespace MantidQt { +namespace MantidWidgets { +/**Constructor. +* Must be passed its parent MantidTreeWidget, to facilitate correct sorting. +*/ +MantidTreeWidgetItem::MantidTreeWidgetItem(MantidTreeWidget *parent) + : QTreeWidgetItem(parent), m_parent(parent), m_sortPos(0) {} + +/**Constructor. +* Must be passed its parent MantidTreeWidget, to facilitate correct sorting. +*/ +MantidTreeWidgetItem::MantidTreeWidgetItem(QStringList list, + MantidTreeWidget *parent) + : QTreeWidgetItem(list), m_parent(parent), m_sortPos(0) {} + +/**Overidden operator. +* Must be passed its parent MantidTreeWidget, to facilitate correct sorting. +*/ +bool MantidTreeWidgetItem::operator<(const QTreeWidgetItem &other) const { + // If this and/or other has been set to have a Qt::UserRole, then + // it has an accompanying sort order that we must maintain, no matter + // what the user has seletected in terms of order or scheme. + + bool thisShouldBeSorted = m_sortPos == 0; + const MantidTreeWidgetItem *mantidOther = + dynamic_cast<const MantidTreeWidgetItem *>(&other); + int otherSortPos = mantidOther ? mantidOther->getSortPos() : 0; + bool otherShouldBeSorted = otherSortPos == 0; + + // just in case m_parent is NULL. I think I saw this once but cannot + // reproduce. + if (!m_parent) + return false; + + if (!thisShouldBeSorted && !otherShouldBeSorted) { + if (m_parent->getSortOrder() == Qt::AscendingOrder) + return m_sortPos < otherSortPos; + else + return m_sortPos >= otherSortPos; + } else if (thisShouldBeSorted && !otherShouldBeSorted) { + if (m_parent->getSortOrder() == Qt::AscendingOrder) + return false; + else + return true; + } else if (!thisShouldBeSorted && otherShouldBeSorted) { + if (m_parent->getSortOrder() == Qt::AscendingOrder) + return true; + else + return false; + } + + // If both should be sorted, and the scheme is set to ByName ... + if (m_parent->getSortScheme() == MantidItemSortScheme::ByName) { + if (QString::compare(text(0), other.text(0), Qt::CaseInsensitive) < 0) + return true; + return false; + } + // ... else both should be sorted and the scheme is set to ByLastModified. + else { + try { + if (childCount() > 0 && other.childCount() > 0) { + const QTreeWidgetItem *other_ptr = &other; + + try { + return getLastModified(this) < getLastModified(other_ptr); + } catch (std::out_of_range &e) { + m_parent->logWarningMessage(e.what()); + return false; + } + } + } catch (Mantid::Kernel::Exception::NotFoundError &) { + ; + } + return false; + } +} + +/**Finds the date and time of the last modification made to the workspace who's +* details +* are found in the given QTreeWidgetItem. +*/ +DateAndTime MantidTreeWidgetItem::getLastModified(const QTreeWidgetItem *item) { + QVariant userData = item->data(0, Qt::UserRole); + if (userData.isNull()) + return DateAndTime(); // now + + Workspace_sptr workspace = userData.value<Workspace_sptr>(); + const Mantid::API::WorkspaceHistory &wsHist = workspace->getHistory(); + if (wsHist.empty()) + return DateAndTime(); // now + + const size_t indexOfLast = wsHist.size() - 1; + const auto lastAlgHist = wsHist.getAlgorithmHistory(indexOfLast); + return lastAlgHist->executionDate(); +} +} +} diff --git a/MantidPlot/src/Mantid/MantidWSIndexDialog.cpp b/MantidQt/MantidWidgets/src/MantidWSIndexDialog.cpp similarity index 98% rename from MantidPlot/src/Mantid/MantidWSIndexDialog.cpp rename to MantidQt/MantidWidgets/src/MantidWSIndexDialog.cpp index 987f0cc0823dd41bc5c49fce56e503dc80aea69e..03f7883d3fa109d5d25c265d37a265b4ab05a476 100644 --- a/MantidPlot/src/Mantid/MantidWSIndexDialog.cpp +++ b/MantidQt/MantidWidgets/src/MantidWSIndexDialog.cpp @@ -1,19 +1,21 @@ //---------------------------------- // Includes //---------------------------------- -#include "MantidWSIndexDialog.h" -#include "MantidUI.h" +#include "MantidQtMantidWidgets/MantidWSIndexDialog.h" #include "MantidAPI/Axis.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/SpectraDetectorTypes.h" -#include <stdlib.h> +#include <QPalette> +#include <QPushButton> #include <QRegExp> #include <QtAlgorithms> #include <boost/lexical_cast.hpp> #include <exception> -#include <QPalette> +#include <stdlib.h> +namespace MantidQt { +namespace MantidWidgets { //---------------------------------- // MantidWSIndexWidget methods //---------------------------------- @@ -360,21 +362,21 @@ bool MantidWSIndexWidget::usingSpectraNumbers() const { //---------------------------------- /** * Construct an object of this type - * @param mui :: The MantidUI area + * @param parent :: The MantidUI area * @param flags :: Window flags that are passed the the QDialog constructor * @param wsNames :: the names of the workspaces to be plotted * @param showWaterfallOption :: If true the waterfall checkbox is created * @param showPlotAll :: If true the "Plot all" button is created * @param showTiledOption :: If true the "Tiled" checkbox is created */ -MantidWSIndexDialog::MantidWSIndexDialog(MantidUI *mui, Qt::WFlags flags, +MantidWSIndexDialog::MantidWSIndexDialog(QWidget *parent, Qt::WFlags flags, QList<QString> wsNames, const bool showWaterfallOption, const bool showPlotAll, const bool showTiledOption) - : QDialog(mui->appWindow(), flags), + : QDialog(parent, flags), m_widget(this, flags, wsNames, showWaterfallOption, showTiledOption), - m_mantidUI(mui), m_plotAll(showPlotAll) { + m_plotAll(showPlotAll) { // Set up UI. init(); } @@ -854,3 +856,5 @@ void MantidWSIndexWidget::QLineEditWithErrorMark::setError(QString error) { m_validLbl->setToolTip(error.trimmed()); } } +} +} diff --git a/MantidQt/MantidWidgets/src/WorkspacePresenter/ADSAdapter.cpp b/MantidQt/MantidWidgets/src/WorkspacePresenter/ADSAdapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..844e1bcad117a4045e06d1d1efd48672cb3e99d3 --- /dev/null +++ b/MantidQt/MantidWidgets/src/WorkspacePresenter/ADSAdapter.cpp @@ -0,0 +1,131 @@ +#include "MantidQtMantidWidgets/WorkspacePresenter/ADSAdapter.h" +#include "MantidQtMantidWidgets/WorkspacePresenter/WorkspaceProviderNotifiable.h" +#include <MantidAPI/AnalysisDataService.h> + +using namespace Mantid::API; +using namespace MantidQt::MantidWidgets; + +namespace MantidQt { +namespace MantidWidgets { + +ADSAdapter::ADSAdapter() + : m_addObserver(*this, &ADSAdapter::handleAddWorkspace), + m_replaceObserver(*this, &ADSAdapter::handleReplaceWorkspace), + m_deleteObserver(*this, &ADSAdapter::handleDeleteWorkspace), + m_clearADSObserver(*this, &ADSAdapter::handleClearADS), + m_renameObserver(*this, &ADSAdapter::handleRenameWorkspace), + m_groupworkspacesObserver(*this, &ADSAdapter::handleGroupWorkspaces), + m_ungroupworkspaceObserver(*this, &ADSAdapter::handleUnGroupWorkspace), + m_workspaceGroupUpdateObserver(*this, + &ADSAdapter::handleWorkspaceGroupUpdate) { + // Register all observers. + auto &nc = AnalysisDataService::Instance().notificationCenter; + nc.addObserver(m_addObserver); + nc.addObserver(m_replaceObserver); + nc.addObserver(m_deleteObserver); + nc.addObserver(m_clearADSObserver); + nc.addObserver(m_renameObserver); + nc.addObserver(m_groupworkspacesObserver); + nc.addObserver(m_ungroupworkspaceObserver); + nc.addObserver(m_workspaceGroupUpdateObserver); +} + +ADSAdapter::~ADSAdapter() { + // remove all observers + auto &nc = AnalysisDataService::Instance().notificationCenter; + nc.removeObserver(m_addObserver); + nc.removeObserver(m_replaceObserver); + nc.removeObserver(m_deleteObserver); + nc.removeObserver(m_clearADSObserver); + nc.removeObserver(m_renameObserver); + nc.removeObserver(m_groupworkspacesObserver); + nc.removeObserver(m_ungroupworkspaceObserver); + nc.removeObserver(m_workspaceGroupUpdateObserver); +} + +void ADSAdapter::registerPresenter(Presenter_wptr presenter) { + m_presenter = std::move(presenter); +} + +bool ADSAdapter::doesWorkspaceExist(const std::string &wsname) const { + return AnalysisDataService::Instance().doesExist(wsname); +} + +std::map<std::string, Mantid::API::Workspace_sptr> +ADSAdapter::topLevelItems() const { + return AnalysisDataService::Instance().topLevelItems(); +} + +/// Locks the presenter as shared_ptr for use internally. +Presenter_sptr ADSAdapter::lockPresenter() { + auto psptr = m_presenter.lock(); + + if (psptr == nullptr) + throw std::runtime_error("Unable to obtain reference to presenter"); + + return std::move(psptr); +} + +std::string ADSAdapter::getOldName() const { return m_oldName; } +std::string ADSAdapter::getNewName() const { return m_newName; } + +// ADS Observation methods +void ADSAdapter::handleAddWorkspace(Mantid::API::WorkspaceAddNotification_ptr) { + auto presenter = lockPresenter(); + presenter->notifyFromWorkspaceProvider( + WorkspaceProviderNotifiable::Flag::WorkspaceLoaded); +} + +void ADSAdapter::handleReplaceWorkspace( + Mantid::API::WorkspaceAfterReplaceNotification_ptr) { + auto presenter = lockPresenter(); + presenter->notifyFromWorkspaceProvider( + WorkspaceProviderNotifiable::Flag::GenericUpdateNotification); +} + +void ADSAdapter::handleDeleteWorkspace( + Mantid::API::WorkspacePostDeleteNotification_ptr) { + auto presenter = lockPresenter(); + presenter->notifyFromWorkspaceProvider( + WorkspaceProviderNotifiable::Flag::WorkspaceDeleted); +} + +void ADSAdapter::handleClearADS(Mantid::API::ClearADSNotification_ptr) { + auto presenter = lockPresenter(); + presenter->notifyFromWorkspaceProvider( + WorkspaceProviderNotifiable::Flag::WorkspacesCleared); +} + +void ADSAdapter::handleRenameWorkspace( + Mantid::API::WorkspaceRenameNotification_ptr pNf) { + // store old and new names when workspace rename occurs. + m_oldName = pNf->objectName(); + m_newName = pNf->newObjectName(); + auto presenter = lockPresenter(); + presenter->notifyFromWorkspaceProvider( + WorkspaceProviderNotifiable::Flag::WorkspaceRenamed); +} + +void ADSAdapter::handleGroupWorkspaces( + Mantid::API::WorkspacesGroupedNotification_ptr) { + auto presenter = lockPresenter(); + presenter->notifyFromWorkspaceProvider( + WorkspaceProviderNotifiable::Flag::WorkspacesGrouped); +} + +void ADSAdapter::handleUnGroupWorkspace( + Mantid::API::WorkspaceUnGroupingNotification_ptr) { + auto presenter = lockPresenter(); + presenter->notifyFromWorkspaceProvider( + WorkspaceProviderNotifiable::Flag::WorkspacesUngrouped); +} + +void ADSAdapter::handleWorkspaceGroupUpdate( + Mantid::API::GroupUpdatedNotification_ptr) { + auto presenter = lockPresenter(); + presenter->notifyFromWorkspaceProvider( + WorkspaceProviderNotifiable::Flag::WorkspaceGroupUpdated); +} + +} // namespace MantidQt +} // namespace MantidWidgets \ No newline at end of file diff --git a/MantidQt/MantidWidgets/src/WorkspacePresenter/QWorkspaceDockView.cpp b/MantidQt/MantidWidgets/src/WorkspacePresenter/QWorkspaceDockView.cpp new file mode 100644 index 0000000000000000000000000000000000000000..79a98677fafd5323b9311b737919edc0cd36862b --- /dev/null +++ b/MantidQt/MantidWidgets/src/WorkspacePresenter/QWorkspaceDockView.cpp @@ -0,0 +1,1708 @@ +#include "MantidQtMantidWidgets/WorkspacePresenter/QWorkspaceDockView.h" +#include <MantidGeometry/Instrument.h> +#include <MantidKernel/make_unique.h> +#include <MantidQtAPI/AlgorithmDialog.h> +#include <MantidQtAPI/AlgorithmInputHistory.h> +#include <MantidQtAPI/FlowLayout.h> +#include <MantidQtAPI/InterfaceManager.h> +#include <MantidQtAPI/WorkspaceIcons.h> +#include <MantidQtAPI/pixmaps.h> +#include <MantidQtMantidWidgets/LineEditWithClear.h> +#include <MantidQtMantidWidgets/MantidDisplayBase.h> +#include <MantidQtMantidWidgets/MantidTreeWidget.h> +#include <MantidQtMantidWidgets/MantidTreeWidgetItem.h> +#include <MantidQtMantidWidgets/WorkspacePresenter/ADSAdapter.h> +#include <MantidQtMantidWidgets/WorkspacePresenter/WorkspacePresenter.h> + +#include <MantidAPI/FileProperty.h> +#include <MantidAPI/IMDEventWorkspace.h> +#include <MantidAPI/IPeaksWorkspace.h> +#include <MantidAPI/MatrixWorkspace.h> +#include <MantidAPI/WorkspaceGroup.h> + +#include <Poco/Path.h> + +#include <QFileDialog> +#include <QHash> +#include <QMainWindow> +#include <QMenu> +#include <QMessageBox> +#include <QPushButton> +#include <QSignalMapper> + +using namespace MantidQt::API; +using namespace Mantid::API; +using namespace Mantid::Kernel; + +namespace { +/// static logger for dock widget +Mantid::Kernel::Logger docklog("MantidDockWidget"); + +WorkspaceIcons WORKSPACE_ICONS = WorkspaceIcons(); + +bool isAllMatrixWorkspaces(const WorkspaceGroup_const_sptr &wsGroup) { + bool allMatrixWSes = false; + + if (wsGroup) { + if (!wsGroup->isEmpty()) { + allMatrixWSes = true; + for (int index = 0; index < wsGroup->getNumberOfEntries(); index++) { + if (nullptr == boost::dynamic_pointer_cast<MatrixWorkspace>( + wsGroup->getItem(index))) { + allMatrixWSes = false; + break; + } + } + } + } + + return allMatrixWSes; +} +} + +namespace MantidQt { +namespace MantidWidgets { + +QWorkspaceDockView::QWorkspaceDockView(MantidDisplayBase *mui, + QMainWindow *parent) + : QDockWidget(tr("Workspaces"), parent), m_mantidUI(mui), m_updateCount(0), + m_treeUpdating(false), m_promptDelete(false), + m_saveFileType(SaveFileType::Nexus), m_sortCriteria(SortCriteria::ByName), + m_sortDirection(SortDirection::Ascending) { + setObjectName( + "exploreMantid"); // this is needed for QMainWindow::restoreState() + setMinimumHeight(150); + setMinimumWidth(200); + parent->addDockWidget(Qt::RightDockWidgetArea, this); + + m_appParent = parent; + + m_saveMenu = new QMenu(this); + + setupWidgetLayout(); + setupLoadButtonMenu(); + + // Dialog box used for user to specify folder to save multiple workspaces into + m_saveFolderDialog = new QFileDialog; + m_saveFolderDialog->setFileMode(QFileDialog::DirectoryOnly); + m_saveFolderDialog->setOption(QFileDialog::ShowDirsOnly); + + // To be able to use them in queued signals they need to be registered + static bool registered_addtional_types = false; + if (!registered_addtional_types) { + registered_addtional_types = true; + qRegisterMetaType<TopLevelItems>(); + } + + // SET UP SORT + createSortMenuActions(); + createWorkspaceMenuActions(); + + setupConnections(); + + m_tree->setDragEnabled(true); +} + +QWorkspaceDockView::~QWorkspaceDockView() {} + +/** +* Accept a drag drop event and process the data appropriately +* @param de :: The drag drop event +*/ +void QWorkspaceDockView::dropEvent(QDropEvent *de) { m_tree->dropEvent(de); } + +void QWorkspaceDockView::setupWidgetLayout() { + QFrame *f = new QFrame(this); + setWidget(f); + + m_tree = new MantidTreeWidget(this, m_mantidUI); + m_tree->setHeaderLabel("Workspaces"); + + FlowLayout *buttonLayout = new FlowLayout(); + m_loadButton = new QPushButton("Load"); + m_saveButton = new QPushButton("Save"); + m_deleteButton = new QPushButton("Delete"); + m_groupButton = new QPushButton("Group"); + m_sortButton = new QPushButton("Sort"); + + if (m_groupButton) + m_groupButton->setEnabled(false); + m_deleteButton->setEnabled(false); + m_saveButton->setEnabled(false); + + buttonLayout->addWidget(m_loadButton); + buttonLayout->addWidget(m_deleteButton); + buttonLayout->addWidget(m_groupButton); + buttonLayout->addWidget(m_sortButton); + buttonLayout->addWidget(m_saveButton); + + m_workspaceFilter = new MantidQt::MantidWidgets::LineEditWithClear(); + m_workspaceFilter->setPlaceholderText("Filter Workspaces"); + m_workspaceFilter->setToolTip("Type here to filter the workspaces"); + + QVBoxLayout *layout = new QVBoxLayout(); + f->setLayout(layout); + layout->setSpacing(0); + layout->setMargin(0); + layout->addLayout(buttonLayout); + layout->addWidget(m_workspaceFilter); + layout->addWidget(m_tree); +} + +void QWorkspaceDockView::setupLoadButtonMenu() { + m_loadMenu = new QMenu(this); + + QAction *loadFileAction = new QAction("File", this); + QAction *liveDataAction = new QAction("Live Data", this); + connect(loadFileAction, SIGNAL(triggered()), this, SLOT(onClickLoad())); + connect(liveDataAction, SIGNAL(triggered()), this, SLOT(onClickLiveData())); + + m_loadMenu->addAction(loadFileAction); + m_loadMenu->addAction(liveDataAction); + m_loadButton->setMenu(m_loadMenu); +} + +void QWorkspaceDockView::setupConnections() { + connect(m_workspaceFilter, SIGNAL(textChanged(const QString &)), this, + SLOT(filterWorkspaceTree(const QString &))); + connect(m_deleteButton, SIGNAL(clicked()), this, + SLOT(onClickDeleteWorkspaces())); + connect(m_tree, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, + SLOT(clickedWorkspace(QTreeWidgetItem *, int))); + connect(m_tree, SIGNAL(itemSelectionChanged()), this, + SLOT(workspaceSelected())); + connect(m_groupButton, SIGNAL(clicked()), this, SLOT(onClickGroupButton())); + + m_tree->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_tree, SIGNAL(customContextMenuRequested(const QPoint &)), this, + SLOT(popupMenu(const QPoint &))); + connect(this, SIGNAL(signalUpdateTree(const TopLevelItems &)), this, + SLOT(handleUpdateTree(const TopLevelItems &)), Qt::QueuedConnection); + + connect(this, SIGNAL(signalClearView()), this, SLOT(handleClearView()), + Qt::QueuedConnection); + connect(m_tree, SIGNAL(itemSelectionChanged()), this, + SLOT(treeSelectionChanged())); + connect(m_tree, SIGNAL(itemExpanded(QTreeWidgetItem *)), this, + SLOT(populateChildData(QTreeWidgetItem *))); +} + +/** +* Flips the flag indicating whether a tree update is in progress. Actions such +* as sorting +* are disabled while an update is in progress. +* @param state The required state for the flag +*/ +void QWorkspaceDockView::setTreeUpdating(const bool state) { + m_treeUpdating = state; +} + +void QWorkspaceDockView::incrementUpdateCount() { m_updateCount.ref(); } + +void QWorkspaceDockView::init() { + auto presenter = boost::make_shared<WorkspacePresenter>(shared_from_this()); + m_presenter = boost::dynamic_pointer_cast<ViewNotifiable>(presenter); + presenter->init(); +} + +WorkspacePresenterWN_wptr QWorkspaceDockView::getPresenterWeakPtr() { + return boost::dynamic_pointer_cast<WorkspacePresenter>(m_presenter); +} + +MantidSurfacePlotDialog::UserInputSurface +QWorkspaceDockView::chooseContourPlotOptions(int nWorkspaces) const { + return m_tree->chooseContourPlotOptions(nWorkspaces); +} + +MantidSurfacePlotDialog::UserInputSurface +QWorkspaceDockView::chooseSurfacePlotOptions(int nWorkspaces) const { + return m_tree->chooseSurfacePlotOptions(nWorkspaces); +} + +/** Returns the names of the selected workspaces +* in the dock. +*/ +StringList QWorkspaceDockView::getSelectedWorkspaceNames() const { + auto items = m_tree->selectedItems(); + StringList names; + + for (auto &item : items) + names.push_back(item->text(0).toStdString()); + + return names; +} + +/** Returns a pointer to the selected workspace (the first if multiple +* workspaces selected) +*/ +Mantid::API::Workspace_sptr QWorkspaceDockView::getSelectedWorkspace() const { + auto items = m_tree->selectedItems(); + auto data = items[0]->data(0, Qt::UserRole).value<Workspace_sptr>(); + + return data; +} + +bool QWorkspaceDockView::askUserYesNo(const std::string &caption, + const std::string &message) const { + return QMessageBox::question(m_appParent, QString::fromStdString(caption), + QString::fromStdString(message), + QMessageBox::Yes, + QMessageBox::No) == QMessageBox::Yes; +} + +void QWorkspaceDockView::showCriticalUserMessage( + const std::string &caption, const std::string &message) const { + QMessageBox::critical(m_appParent, QString::fromStdString(caption), + QString::fromStdString(message)); +} + +void QWorkspaceDockView::onLoadAccept() { + QObject *sender = QObject::sender(); + MantidQt::API::AlgorithmDialog *dlg = + reinterpret_cast<MantidQt::API::AlgorithmDialog *>(sender); + if (!dlg) + return; // should never happen + + QString fn = MantidQt::API::AlgorithmInputHistory::Instance().previousInput( + "Load", "Filename"); + + m_mantidUI->updateRecentFilesList(fn); +} + +void QWorkspaceDockView::showLoadDialog() { + QMetaObject::invokeMethod(dynamic_cast<QObject *>(m_mantidUI), + "showAlgorithmDialog", Qt::QueuedConnection, + Q_ARG(QString, "Load")); +} + +void QWorkspaceDockView::showLiveDataDialog() { + QMetaObject::invokeMethod(dynamic_cast<QObject *>(m_mantidUI), + "showAlgorithmDialog", Qt::QueuedConnection, + Q_ARG(QString, "StartLiveData")); +} + +void QWorkspaceDockView::renameWorkspace() { + m_presenter->notifyFromView(ViewNotifiable::Flag::RenameWorkspace); +} + +void QWorkspaceDockView::showRenameDialog(const StringList &wsNames) { + QStringList names; + + for (auto &ws : wsNames) + names.append(QString::fromStdString(ws)); + + m_mantidUI->renameWorkspace(names); +} + +/** +* Save the old and the new name in m_renameMap. This is needed to restore +* selection +* of the renamed workspace (if it was selected before renaming). +* @param oldName :: Old name of a renamed workspace. +* @param newName :: New name of a renamed workspace. +*/ +void QWorkspaceDockView::recordWorkspaceRename(const std::string &oldName, + const std::string &newName) { + QString qs_oldName = QString::fromStdString(oldName); + QString qs_newName = QString::fromStdString(newName); + + // check if old_name has been recently a new name + QList<QString> oldNames = m_renameMap.keys(qs_oldName); + // non-empty list of oldNames become new_name + if (!oldNames.isEmpty()) { + for (auto &name : oldNames) + m_renameMap[name] = qs_newName; + } else { + // record a new rename pair + m_renameMap[qs_oldName] = qs_newName; + } +} + +void QWorkspaceDockView::refreshWorkspaces() { + m_presenter->notifyFromView(ViewNotifiable::Flag::RefreshWorkspaces); +} + +void QWorkspaceDockView::enableDeletePrompt(bool enable) { + m_promptDelete = enable; +} + +bool QWorkspaceDockView::isPromptDelete() const { return m_promptDelete; } + +bool QWorkspaceDockView::deleteConfirmation() const { + return askUserYesNo( + "Delete Workspaces", + "Are you sure you want to delete the selected Workspaces?\n\nThis " + "prompt can be disabled from:\nPreferences->General->Confirmations"); +} + +void QWorkspaceDockView::deleteWorkspaces(const StringList &wsNames) { + QStringList names; + for (auto &ws : wsNames) + names.append(QString::fromStdString(ws)); + m_mantidUI->deleteWorkspaces(names); +} + +void QWorkspaceDockView::clearView() { emit signalClearView(); } + +void QWorkspaceDockView::sortAscending() { + m_sortDirection = SortDirection::Ascending; + m_presenter->notifyFromView(ViewNotifiable::Flag::SortWorkspaces); +} + +void QWorkspaceDockView::sortDescending() { + m_sortDirection = SortDirection::Descending; + m_presenter->notifyFromView(ViewNotifiable::Flag::SortWorkspaces); +} + +void QWorkspaceDockView::chooseByName() { + m_sortCriteria = SortCriteria::ByName; + m_presenter->notifyFromView(ViewNotifiable::Flag::SortWorkspaces); +} + +void QWorkspaceDockView::chooseByLastModified() { + m_sortCriteria = SortCriteria::ByLastModified; + m_presenter->notifyFromView(ViewNotifiable::Flag::SortWorkspaces); +} + +void QWorkspaceDockView::excludeItemFromSort(MantidTreeWidgetItem *item) { + static int counter = 1; + + item->setSortPos(counter); + + counter++; +} + +QWorkspaceDockView::SortDirection QWorkspaceDockView::getSortDirection() const { + return m_sortDirection; +} + +QWorkspaceDockView::SortCriteria QWorkspaceDockView::getSortCriteria() const { + return m_sortCriteria; +} + +void QWorkspaceDockView::sortWorkspaces(SortCriteria criteria, + SortDirection direction) { + if (isTreeUpdating()) + return; + m_tree->setSortScheme(criteria == SortCriteria::ByName + ? MantidItemSortScheme::ByName + : MantidItemSortScheme::ByLastModified); + m_tree->setSortOrder(direction == SortDirection::Ascending + ? Qt::AscendingOrder + : Qt::DescendingOrder); + m_tree->sort(); +} + +void QWorkspaceDockView::saveWorkspaceCollection() { + m_presenter->notifyFromView(ViewNotifiable::Flag::SaveWorkspaceCollection); +} + +void QWorkspaceDockView::handleShowSaveAlgorithm() { + QAction *sendingAction = dynamic_cast<QAction *>(sender()); + + if (sendingAction) { + QString actionName = sendingAction->text(); + + if (actionName.compare("Nexus") == 0) + m_saveFileType = SaveFileType::Nexus; + else if (actionName.compare("ASCII") == 0) + m_saveFileType = SaveFileType::ASCII; + else if (actionName.compare("ASCII v1")) + m_saveFileType = SaveFileType::ASCIIv1; + } + + m_presenter->notifyFromView(ViewNotifiable::Flag::SaveSingleWorkspace); +} + +QWorkspaceDockView::SaveFileType QWorkspaceDockView::getSaveFileType() const { + return m_saveFileType; +} + +void QWorkspaceDockView::saveWorkspace(SaveFileType type) { + int version = -1; + std::string algorithmName; + + switch (type) { + case SaveFileType::Nexus: + algorithmName = "SaveNexus"; + break; + case SaveFileType::ASCIIv1: + version = 1; + case SaveFileType::ASCII: + algorithmName = "SaveAscii"; + break; + } + + m_mantidUI->showAlgorithmDialog(QString::fromStdString(algorithmName), + version); +} + +void QWorkspaceDockView::saveWorkspaces(const StringList &wsNames) { + QList<QTreeWidgetItem *> items = m_tree->selectedItems(); + if (items.size() < 2) + return; + + m_saveFolderDialog->setWindowTitle("Select save folder"); + m_saveFolderDialog->setLabelText(QFileDialog::Accept, "Select"); + auto res = m_saveFolderDialog->exec(); + auto folder = m_saveFolderDialog->selectedFiles()[0].toStdString(); + + IAlgorithm_sptr saveAlg = AlgorithmManager::Instance().create("SaveNexus"); + saveAlg->initialize(); + + if (res == QFileDialog::Accepted) { + for (auto &wsName : wsNames) { + std::string filename = folder + "/" + wsName + ".nxs"; + try { + saveAlg->setProperty("InputWorkspace", wsName); + saveAlg->setProperty("Filename", filename); + saveAlg->execute(); + } catch (std::runtime_error &rte) { + docklog.error() << "Error saving workspace " << wsName << ": " + << rte.what() << '\n'; + } + } + } +} + +std::string QWorkspaceDockView::getFilterText() const { + return m_workspaceFilter->text().toStdString(); +} + +void QWorkspaceDockView::filterWorkspaces(const std::string &filterText) { + const QString text = QString::fromStdString(filterText).trimmed(); + QRegExp filterRegEx(text, Qt::CaseInsensitive); + + // show all items + QTreeWidgetItemIterator it(m_tree); + while (*it) { + (*it)->setHidden(false); + ++it; + } + + int hiddenCount = 0; + QList<QTreeWidgetItem *> visibleGroups; + if (!text.isEmpty()) { + // Loop over everything (currently loaded) and top level + // find out what is already expanded + QStringList expanded; + int n = m_tree->topLevelItemCount(); + for (int i = 0; i < n; ++i) { + auto item = m_tree->topLevelItem(i); + if (item->isExpanded()) { + expanded << item->text(0); + } else { + // expand everything that is at the top level (as we lazy load this is + // required) + item->setExpanded(true); + } + } + + // filter based on the string + QTreeWidgetItemIterator it(m_tree, QTreeWidgetItemIterator::All); + while (*it) { + QTreeWidgetItem *item = (*it); + QVariant userData = item->data(0, Qt::UserRole); + + if (!userData.isNull()) { + Workspace_sptr workspace = userData.value<Workspace_sptr>(); + if (workspace) { + // I am a workspace + if (item->text(0).contains(filterRegEx)) { + // my name does match the filter + if (auto group = + boost::dynamic_pointer_cast<WorkspaceGroup>(workspace)) { + // I am a group, I will want my children to be visible + // but I cannot do that until this iterator has finished + // store this pointer in a list for processing later + visibleGroups.append(item); + item->setHidden(false); + } + + if (item->parent() == NULL) { + // No parent, I am a top level workspace - show me + item->setHidden(false); + } else { + // I am a child workspace of a group + // I match, so I want my parent to remain visible as well. + item->setHidden(false); + if (item->parent()->isHidden()) { + // I was previously hidden, show me and set to be expanded + --hiddenCount; + item->parent()->setHidden(false); + expanded << item->parent()->text(0); + } + } + } else { + // my name does not match the filter - hide me + item->setHidden(true); + ++hiddenCount; + } + } + } + ++it; + } + + // make children of visible groups visible + for (auto itGroup = visibleGroups.begin(); itGroup != visibleGroups.end(); + ++itGroup) { + QTreeWidgetItem *group = (*itGroup); + for (int i = 0; i < group->childCount(); i++) { + QTreeWidgetItem *child = group->child(i); + if (child->isHidden()) { + // I was previously hidden, show me + --hiddenCount; + child->setHidden(false); + } + } + } + + // set the expanded state + for (int i = 0; i < n; ++i) { + auto item = m_tree->topLevelItem(i); + item->setExpanded(expanded.contains(item->text(0))); + } + } + + // display a message if items are hidden + if (hiddenCount > 0) { + QString headerString = + QString("Workspaces (%1 filtered)").arg(QString::number(hiddenCount)); + m_tree->headerItem()->setText(0, headerString); + } else { + m_tree->headerItem()->setText(0, "Workspaces"); + } +} + +/** +* Set tree item's icon based on the ID of the workspace. +* @param item :: A workspace tree item. +* @param wsID :: An icon type code. +*/ +void QWorkspaceDockView::setItemIcon(QTreeWidgetItem *item, + const std::string &wsID) { + try { + item->setIcon(0, QIcon(WORKSPACE_ICONS.getIcon(wsID))); + } catch (std::runtime_error &) { + docklog.warning() << "Cannot find icon for workspace ID '" << wsID << "'\n"; + } +} + +/** +* Create the action items associated with the dock +*/ +void QWorkspaceDockView::createWorkspaceMenuActions() { + m_showData = new QAction(tr("Show Data"), this); + connect(m_showData, SIGNAL(triggered()), this, SLOT(onClickShowData())); + + m_showInst = new QAction(tr("Show Instrument"), this); + connect(m_showInst, SIGNAL(triggered()), this, SLOT(onClickShowInstrument())); + + m_plotSpec = new QAction(tr("Plot Spectrum..."), this); + connect(m_plotSpec, SIGNAL(triggered()), this, SLOT(onClickPlotSpectra())); + + m_plotSpecErr = new QAction(tr("Plot Spectrum with Errors..."), this); + connect(m_plotSpecErr, SIGNAL(triggered()), this, + SLOT(onClickPlotSpectraErr())); + + m_colorFill = new QAction(tr("Color Fill Plot"), this); + connect(m_colorFill, SIGNAL(triggered()), this, + SLOT(onClickDrawColorFillPlot())); + + m_showDetectors = new QAction(tr("Show Detectors"), this); + connect(m_showDetectors, SIGNAL(triggered()), this, + SLOT(onClickShowDetectorTable())); + + m_showBoxData = new QAction(tr("Show Box Data Table"), this); + connect(m_showBoxData, SIGNAL(triggered()), this, SLOT(onClickShowBoxData())); + + m_showVatesGui = new QAction(tr("Show Vates Simple Interface"), this); + { + QIcon icon; + icon.addFile( + QString::fromUtf8(":/VatesSimpleGuiViewWidgets/icons/pvIcon.png"), + QSize(), QIcon::Normal, QIcon::Off); + m_showVatesGui->setIcon(icon); + } + connect(m_showVatesGui, SIGNAL(triggered()), this, SLOT(onClickShowVates())); + + m_showMDPlot = new QAction(tr("Plot MD"), this); + connect(m_showMDPlot, SIGNAL(triggered()), this, SLOT(onClickShowMDPlot())); + + m_showListData = new QAction(tr("List Data"), this); + connect(m_showListData, SIGNAL(triggered()), this, + SLOT(onClickShowListData())); + + m_showSpectrumViewer = new QAction(tr("Show Spectrum Viewer"), this); + connect(m_showSpectrumViewer, SIGNAL(triggered()), this, + SLOT(onClickShowSpectrumViewer())); + + m_showSliceViewer = new QAction(tr("Show Slice Viewer"), this); + { + QIcon icon; + icon.addFile( + QString::fromUtf8(":/SliceViewer/icons/SliceViewerWindow_icon.png"), + QSize(), QIcon::Normal, QIcon::Off); + m_showSliceViewer->setIcon(icon); + } + connect(m_showSliceViewer, SIGNAL(triggered()), this, + SLOT(onClickShowSliceViewer())); + + m_showLogs = new QAction(tr("Sample Logs..."), this); + connect(m_showLogs, SIGNAL(triggered()), this, SLOT(onClickShowFileLog())); + + m_showSampleMaterial = new QAction(tr("Sample Material..."), this); + connect(m_showSampleMaterial, SIGNAL(triggered()), this, + SLOT(onClickShowSampleMaterial())); + + m_showHist = new QAction(tr("Show History"), this); + connect(m_showHist, SIGNAL(triggered()), this, SLOT(onClickShowAlgHistory())); + + m_saveNexus = new QAction(tr("Save Nexus"), this); + connect(m_saveNexus, SIGNAL(triggered()), this, + SLOT(onClickSaveNexusWorkspace())); + + m_rename = new QAction(tr("Rename"), this); + connect(m_rename, SIGNAL(triggered()), this, SLOT(renameWorkspace())); + + m_delete = new QAction(tr("Delete"), this); + connect(m_delete, SIGNAL(triggered()), this, SLOT(onClickDeleteWorkspaces())); + + m_showTransposed = new QAction(tr("Show Transposed"), this); + connect(m_showTransposed, SIGNAL(triggered()), this, + SLOT(onClickShowTransposed())); + + m_convertToMatrixWorkspace = + new QAction(tr("Convert to MatrixWorkspace"), this); + m_convertToMatrixWorkspace->setIcon(QIcon(getQPixmap("mantid_matrix_xpm"))); + connect(m_convertToMatrixWorkspace, SIGNAL(triggered()), this, + SLOT(onClickConvertToMatrixWorkspace())); + + m_convertMDHistoToMatrixWorkspace = + new QAction(tr("Convert to MatrixWorkspace"), this); + m_convertMDHistoToMatrixWorkspace->setIcon( + QIcon(getQPixmap("mantid_matrix_xpm"))); + connect(m_convertMDHistoToMatrixWorkspace, SIGNAL(triggered()), this, + SLOT(onClickConvertMDHistoToMatrixWorkspace())); + + m_clearUB = new QAction(tr("Clear UB Matrix"), this); + connect(m_clearUB, SIGNAL(triggered()), this, SLOT(onClickClearUB())); + + m_plotSurface = new QAction(tr("Plot Surface from Group"), this); + connect(m_plotSurface, SIGNAL(triggered()), this, SLOT(onClickPlotSurface())); + + m_plotContour = new QAction(tr("Plot Contour from Group"), this); + connect(m_plotContour, SIGNAL(triggered()), this, SLOT(onClickPlotContour())); +} + +/** +* Create actions for sorting. +*/ +void QWorkspaceDockView::createSortMenuActions() { + m_sortCriteria = SortCriteria::ByName; + m_sortMenu = new QMenu(this); + + QAction *m_ascendingSortAction = new QAction("Ascending", this); + QAction *m_descendingSortAction = new QAction("Descending", this); + QAction *m_byNameChoice = new QAction("Name", this); + QAction *m_byLastModifiedChoice = new QAction("Last Modified", this); + + m_ascendingSortAction->setCheckable(true); + m_ascendingSortAction->setEnabled(true); + + m_descendingSortAction->setCheckable(true); + m_descendingSortAction->setEnabled(true); + + QActionGroup *sortDirectionGroup = new QActionGroup(m_sortMenu); + sortDirectionGroup->addAction(m_ascendingSortAction); + sortDirectionGroup->addAction(m_descendingSortAction); + sortDirectionGroup->setExclusive(true); + m_ascendingSortAction->setChecked(true); + + m_byNameChoice->setCheckable(true); + m_byNameChoice->setEnabled(true); + + m_byLastModifiedChoice->setCheckable(true); + m_byLastModifiedChoice->setEnabled(true); + + m_sortChoiceGroup = new QActionGroup(m_sortMenu); + m_sortChoiceGroup->addAction(m_byNameChoice); + m_sortChoiceGroup->addAction(m_byLastModifiedChoice); + m_sortChoiceGroup->setExclusive(true); + m_byNameChoice->setChecked(true); + + connect(m_ascendingSortAction, SIGNAL(triggered()), this, + SLOT(sortAscending())); + connect(m_descendingSortAction, SIGNAL(triggered()), this, + SLOT(sortDescending())); + connect(m_byNameChoice, SIGNAL(triggered()), this, SLOT(chooseByName())); + connect(m_byLastModifiedChoice, SIGNAL(triggered()), this, + SLOT(chooseByLastModified())); + + m_sortMenu->addActions(sortDirectionGroup->actions()); + m_sortMenu->addSeparator(); + m_sortMenu->addActions(m_sortChoiceGroup->actions()); + m_sortButton->setMenu(m_sortMenu); +} + +/** +* When an item is expanded, populate the child data for this item +* @param item :: The tree item being expanded +*/ +void QWorkspaceDockView::populateChildData(QTreeWidgetItem *item) { + QVariant userData = item->data(0, Qt::UserRole); + if (userData.isNull()) + return; + + // Clear it first + while (item->childCount() > 0) { + auto *widgetItem = item->takeChild(0); + delete widgetItem; + } + + Workspace_sptr workspace = userData.value<Workspace_sptr>(); + + if (auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(workspace)) { + const size_t nmembers = group->getNumberOfEntries(); + for (size_t i = 0; i < nmembers; ++i) { + auto ws = group->getItem(i); + auto *node = addTreeEntry(std::make_pair(ws->name(), ws), item); + excludeItemFromSort(node); + if (shouldBeSelected(node->text(0))) + node->setSelected(true); + } + } else { + QString details; + try { + details = workspace->toString().c_str(); + } catch (std::runtime_error &e) { + details = QString("Error: %1").arg(e.what()); + } + QStringList rows = + details.split(QLatin1Char('\n'), QString::SkipEmptyParts); + rows.append(QString("Memory used: ") + + workspace->getMemorySizeAsStr().c_str()); + + auto iend = rows.constEnd(); + for (auto itr = rows.constBegin(); itr != iend; ++itr) { + MantidTreeWidgetItem *data = + new MantidTreeWidgetItem(QStringList(*itr), m_tree); + data->setFlags(Qt::NoItemFlags); + excludeItemFromSort(data); + item->addChild(data); + } + } +} + +/** +* Update the workspace tree to match the current state of the ADS. +* It is important that the workspace tree is modified only by this method. +* @param items Items which are currently in the ADS. +*/ +void QWorkspaceDockView::updateTree(const TopLevelItems &items) { + incrementUpdateCount(); + emit signalUpdateTree(items); +} + +/** +* Clears the tree and re-populates it with the given top level items +* @param topLevelItems The map of names to workspaces +* @param expanded Names of items who should expanded after being populated +*/ +void QWorkspaceDockView::populateTopLevel(const TopLevelItems &topLevelItems, + const QStringList &expanded) { + // collect names of selected workspaces + QList<QTreeWidgetItem *> selected = m_tree->selectedItems(); + m_selectedNames.clear(); // just in case + foreach (QTreeWidgetItem *item, selected) { + m_selectedNames << item->text(0); + } + + // populate the tree from scratch + m_tree->clear(); + auto iend = topLevelItems.end(); + for (auto it = topLevelItems.begin(); it != iend; ++it) { + auto *node = addTreeEntry(*it); + QString name = node->text(0); + if (expanded.contains(name)) + node->setExpanded(true); + // see if item must be selected + if (shouldBeSelected(name)) + node->setSelected(true); + } + m_selectedNames.clear(); + m_renameMap.clear(); + + // apply any filtering + filterWorkspaceTree(m_workspaceFilter->text()); +} + +/** +* Adds a node for the given named item, including a single child ID item to make +* each node have a expandable button +* and allowing plotting to work from non-expanded items +* @param item A name/workspace pair to add. +* @param parent If not null then add the new items as a child of the given item +*/ +MantidTreeWidgetItem *QWorkspaceDockView::addTreeEntry( + const std::pair<std::string, Mantid::API::Workspace_sptr> &item, + QTreeWidgetItem *parent) { + MantidTreeWidgetItem *node = + new MantidTreeWidgetItem(QStringList(item.first.c_str()), m_tree); + node->setData(0, Qt::UserRole, QVariant::fromValue(item.second)); + + // A a child ID item so that it becomes expandable. Using the correct ID is + // needed when plotting from non-expanded groups. + const std::string wsID = item.second->id(); + MantidTreeWidgetItem *idNode = + new MantidTreeWidgetItem(QStringList(wsID.c_str()), m_tree); + idNode->setFlags(Qt::NoItemFlags); + node->addChild(idNode); + setItemIcon(node, wsID); + + if (parent) { + parent->addChild(node); + } else { + m_tree->addTopLevelItem(node); + } + return node; +} + +/** +* Check if a workspace should be selected after dock update. +* @param name :: Name of a workspace to check. +*/ +bool QWorkspaceDockView::shouldBeSelected(QString name) const { + QStringList renamed = m_renameMap.keys(name); + if (!renamed.isEmpty()) { + foreach (QString oldName, renamed) { + if (m_selectedNames.contains(oldName)) { + return true; + } + } + } else if (m_selectedNames.contains(name)) { + return true; + } + return false; +} + +void QWorkspaceDockView::treeSelectionChanged() { + // get selected workspaces + auto items = m_tree->selectedItems(); + + if (m_groupButton) { + if (items.size() == 1) { + // check it's group + auto wsSptr = + items.first()->data(0, Qt::UserRole).value<Workspace_sptr>(); + auto grpSptr = boost::dynamic_pointer_cast<WorkspaceGroup>(wsSptr); + if (grpSptr) { + m_groupButton->setText("Ungroup"); + m_groupButton->setEnabled(true); + } else + m_groupButton->setEnabled(false); + + } else if (items.size() >= 2) { + m_groupButton->setText("Group"); + m_groupButton->setEnabled(true); + } else if (items.size() == 0) { + m_groupButton->setText("Group"); + m_groupButton->setEnabled(false); + } + } + + if (m_deleteButton) + m_deleteButton->setEnabled(items.size() > 0); + + if (m_saveButton) + m_saveButton->setEnabled(items.size() > 0); + + if (items.size() > 0) { + auto item = *(items.begin()); + m_mantidUI->enableSaveNexus(item->text(0)); + } else { + m_mantidUI->disableSaveNexus(); + } +} + +/** +* Add the actions that are appropriate for a MatrixWorkspace +* @param menu :: The menu to store the items +* @param matrixWS :: The workspace related to the menu +*/ +void QWorkspaceDockView::addMatrixWorkspaceMenuItems( + QMenu *menu, + const Mantid::API::MatrixWorkspace_const_sptr &matrixWS) const { + // Add all options except plot of we only have 1 value + menu->addAction(m_showData); + menu->addAction(m_showInst); + // Disable the 'show instrument' option if a workspace doesn't have an + // instrument attached + m_showInst->setEnabled(matrixWS->getInstrument() && + !matrixWS->getInstrument()->getName().empty()); + menu->addSeparator(); + menu->addAction(m_plotSpec); + menu->addAction(m_plotSpecErr); + + // Don't plot a spectrum if only one X value + m_plotSpec->setEnabled(matrixWS->blocksize() > 1); + m_plotSpecErr->setEnabled(matrixWS->blocksize() > 1); + + menu->addAction(m_showSpectrumViewer); // The 2D spectrum viewer + + menu->addAction(m_colorFill); + // Show the color fill plot if you have more than one histogram + m_colorFill->setEnabled( + (matrixWS->axes() > 1 && matrixWS->getNumberHistograms() > 1)); + menu->addAction(m_showSliceViewer); // The 2D slice viewer + menu->addSeparator(); + menu->addAction(m_showDetectors); + menu->addAction(m_showLogs); + menu->addAction(m_showSampleMaterial); + menu->addAction(m_showHist); + menu->addAction(m_saveNexus); +} + +/** +* Add the actions that are appropriate for a MDEventWorkspace +* @param menu :: The menu to store the items +* @param WS :: The workspace related to the menu +*/ +void QWorkspaceDockView::addMDEventWorkspaceMenuItems( + QMenu *menu, const Mantid::API::IMDEventWorkspace_const_sptr &WS) const { + Q_UNUSED(WS); + + // menu->addAction(m_showBoxData); // Show MD Box data (for debugging only) + menu->addAction(m_showVatesGui); // Show the Vates simple interface + if (!MantidQt::API::InterfaceManager::hasVatesLibraries()) { + m_showVatesGui->setEnabled(false); +#ifdef MAKE_VATES + } else if (!m_mantidUI->doesVatesSupportOpenGL()) { + m_showVatesGui->setEnabled(false); +#endif + } else { + std::size_t nDim = WS->getNonIntegratedDimensions().size(); + m_showVatesGui->setEnabled(nDim >= 3 && nDim < 5); + } + menu->addAction(m_showSliceViewer); // The 2D slice viewer + menu->addAction(m_showHist); // Algorithm history + menu->addAction(m_showListData); // Show data in table + menu->addAction(m_showLogs); +} + +void QWorkspaceDockView::addMDHistoWorkspaceMenuItems( + QMenu *menu, const Mantid::API::IMDWorkspace_const_sptr &WS) const { + Q_UNUSED(WS); + menu->addAction(m_showHist); // Algorithm history + menu->addAction(m_showVatesGui); // Show the Vates simple interface + if (!MantidQt::API::InterfaceManager::hasVatesLibraries()) { + m_showVatesGui->setEnabled(false); +#ifdef MAKE_VATES + } else if (!m_mantidUI->doesVatesSupportOpenGL()) { + m_showVatesGui->setEnabled(false); +#endif + } else { + std::size_t nDim = WS->getNonIntegratedDimensions().size(); + m_showVatesGui->setEnabled(nDim >= 3 && nDim < 5); + } + menu->addAction(m_showSliceViewer); // The 2D slice viewer + menu->addAction(m_showMDPlot); // A plot of intensity vs bins + menu->addAction(m_showListData); // Show data in table + menu->addAction(m_convertMDHistoToMatrixWorkspace); + menu->addAction(m_showLogs); +} + +/** Add the actions that are appropriate for a PeaksWorkspace +* @param menu :: The menu to store the items +* @param WS :: The workspace related to the menu +*/ +void QWorkspaceDockView::addPeaksWorkspaceMenuItems( + QMenu *menu, const Mantid::API::IPeaksWorkspace_const_sptr &WS) const { + Q_UNUSED(WS); + menu->addAction(m_showData); + menu->addSeparator(); + menu->addAction(m_showDetectors); + menu->addAction(m_showHist); +} + +/** +* Add the actions that are appropriate for a WorkspaceGroup +* @param menu :: The menu to store the items +* @param groupWS :: [input] Workspace group related to the menu +*/ +void QWorkspaceDockView::addWorkspaceGroupMenuItems( + QMenu *menu, const WorkspaceGroup_const_sptr &groupWS) const { + m_plotSpec->setEnabled(true); + menu->addAction(m_plotSpec); + m_plotSpecErr->setEnabled(true); + menu->addAction(m_plotSpecErr); + menu->addAction(m_colorFill); + m_colorFill->setEnabled(true); + + // If appropriate, add "plot surface" and "plot contour" options + // Only add these if: + // - there are >2 workspaces in group + // - all are MatrixWorkspaces (otherwise they can't be plotted) + // - only one group is selected + if (m_tree->selectedItems().size() == 1) { + if (groupWS && groupWS->getNumberOfEntries() > 2) { + if (isAllMatrixWorkspaces(groupWS)) { + menu->addAction(m_plotSurface); + m_plotSurface->setEnabled(true); + menu->addAction(m_plotContour); + m_plotContour->setEnabled(true); + } + } + } + + menu->addSeparator(); + menu->addAction(m_saveNexus); +} + +/** +* Add the actions that are appropriate for a MatrixWorkspace +* @param menu :: The menu to store the items +*/ +void QWorkspaceDockView::addTableWorkspaceMenuItems(QMenu *menu) const { + menu->addAction(m_showData); + menu->addAction(m_showTransposed); + menu->addAction(m_showHist); + menu->addAction(m_saveNexus); + menu->addAction(m_convertToMatrixWorkspace); +} + +/** +* Add menu for clearing workspace items. +* @param menu : Parent menu. +* @param wsName : Name of the selected workspace. +*/ +void QWorkspaceDockView::addClearMenuItems(QMenu *menu, const QString &wsName) { + QMenu *clearMenu = new QMenu(tr("Clear Options"), this); + + m_clearUB->setEnabled(hasUBMatrix(wsName.toStdString())); + + clearMenu->addAction(m_clearUB); + menu->addMenu(clearMenu); +} + +bool QWorkspaceDockView::hasUBMatrix(const std::string &wsName) { + bool hasUB = false; + auto alg = m_mantidUI->createAlgorithm("HasUB"); + + if (alg) { + alg->setLogging(false); + alg->setPropertyValue("Workspace", wsName); + executeAlgorithmAsync(alg, true); + hasUB = alg->getProperty("HasUB"); + } + return hasUB; +} + +/** +* Adds an algorithm to the save menu. +* +* @param algorithmString Algorithm string in format ALGO_NAME.VERSION or +* ALGO_NAME +* @param menuEntryName Text to be shown in menu +*/ +void QWorkspaceDockView::addSaveMenuOption(QString algorithmString, + QString menuEntryName) { + // Default to algo string if no entry name given + if (menuEntryName.isEmpty()) + menuEntryName = algorithmString; + + // Create the action and add data + QAction *saveAction = new QAction(menuEntryName, this); + saveAction->setData(QVariant(algorithmString)); + + // Connect the tigger slot to show algorithm dialog + connect(saveAction, SIGNAL(triggered()), this, + SLOT(handleShowSaveAlgorithm())); + + // Add it to the menu + m_saveMenu->addAction(saveAction); +} + +/** +* Filter workspaces based on the string provided +* @param text : the string to filter on. +*/ +void QWorkspaceDockView::filterWorkspaceTree(const QString &text) { + m_filteredText = text.toStdString(); + m_presenter->notifyFromView(ViewNotifiable::Flag::FilterWorkspaces); +} + +/// Handles delete button/menu item triggers +void QWorkspaceDockView::onClickDeleteWorkspaces() { + m_presenter->notifyFromView(ViewNotifiable::Flag::DeleteWorkspaces); +} + +void QWorkspaceDockView::clickedWorkspace(QTreeWidgetItem *item, int) { + Q_UNUSED(item); +} + +void QWorkspaceDockView::workspaceSelected() { + auto selectedNames = getSelectedWorkspaceNames(); + if (selectedNames.empty()) + return; + + // If there are multiple workspaces selected group and save as Nexus + if (selectedNames.size() > 1) { + connect(m_saveButton, SIGNAL(clicked()), this, + SLOT(saveWorkspaceCollection())); + + // Don't display as a group + m_saveButton->setMenu(NULL); + } else { + // Don't run the save group function when clicked + disconnect(m_saveButton, SIGNAL(clicked()), this, + SLOT(saveWorkspaceCollection())); + + // Remove all existing save algorithms from list + m_saveMenu->clear(); + + // Add some save algorithms + addSaveMenuOption("SaveNexus", "Nexus"); + addSaveMenuOption("SaveAscii", "ASCII"); + addSaveMenuOption("SaveAscii.1", "ASCII v1"); + + // Set the button to show the menu + m_saveButton->setMenu(m_saveMenu); + } + + auto wsName = selectedNames[0]; + // TODO: Wire signal correctly in applicationwindow + m_mantidUI->enableSaveNexus(QString::fromStdString(wsName)); +} + +/// Handles group button clicks +void QWorkspaceDockView::onClickGroupButton() { + if (m_groupButton) { + QString qButtonName = m_groupButton->text(); + if (qButtonName == "Group") { + m_presenter->notifyFromView(ViewNotifiable::Flag::GroupWorkspaces); + } else if (qButtonName == "Ungroup") { + m_presenter->notifyFromView(ViewNotifiable::Flag::UngroupWorkspaces); + } + } +} + +/// Handles Load File menu trigger +void QWorkspaceDockView::onClickLoad() { + m_presenter->notifyFromView(ViewNotifiable::Flag::LoadWorkspace); +} + +/// handles Live Data menu trigger +void QWorkspaceDockView::onClickLiveData() { + m_presenter->notifyFromView(ViewNotifiable::Flag::LoadLiveDataWorkspace); +} + +// Asynchronous signal handlers +/// Handle asynchronous tree update. +void QWorkspaceDockView::handleUpdateTree(const TopLevelItems &items) { + m_mantidUI->updateProject(); + // do not update until the counter is zero + if (m_updateCount.deref()) + return; + + // find all expanded top-level entries + QStringList expanded; + int n = m_tree->topLevelItemCount(); + for (int i = 0; i < n; ++i) { + auto item = m_tree->topLevelItem(i); + if (item->isExpanded()) { + expanded << item->text(0); + } + } + + // create a new tree + setTreeUpdating(true); + populateTopLevel(items, expanded); + setTreeUpdating(false); + + // Re-sort + m_tree->sort(); +} + +void QWorkspaceDockView::handleClearView() { + m_mantidUI->updateProject(); + m_tree->clear(); +} + +// Context Menu Methods + +/// Handles display of the workspace context menu. +void QWorkspaceDockView::popupMenu(const QPoint &pos) { + m_menuPosition = pos; + m_presenter->notifyFromView( + ViewNotifiable::Flag::PopulateAndShowWorkspaceContextMenu); +} + +void QWorkspaceDockView::popupContextMenu() { + QTreeWidgetItem *treeItem = m_tree->itemAt(m_menuPosition); + selectedWsName = ""; + if (treeItem) + selectedWsName = treeItem->text(0); + else + m_tree->selectionModel()->clear(); + + QMenu *menu(nullptr); + + // If no workspace is here then have load raw and dae + if (selectedWsName.isEmpty()) + menu = m_loadMenu; + else { // else show instrument, sample logs and delete + // Fresh menu + menu = new QMenu(this); + menu->setObjectName("WorkspaceContextMenu"); + auto mantidTreeItem = dynamic_cast<MantidTreeWidgetItem *>(treeItem); + auto ws = mantidTreeItem->data(0, Qt::UserRole) + .value<Mantid::API::Workspace_sptr>(); + + // Add the items that are appropriate for the type + if (auto matrixWS = + boost::dynamic_pointer_cast<const Mantid::API::MatrixWorkspace>( + ws)) { + addMatrixWorkspaceMenuItems(menu, matrixWS); + } else if (auto mdeventWS = + boost::dynamic_pointer_cast<const IMDEventWorkspace>(ws)) { + addMDEventWorkspaceMenuItems(menu, mdeventWS); + } else if (auto mdWS = + boost::dynamic_pointer_cast<const IMDWorkspace>(ws)) { + addMDHistoWorkspaceMenuItems(menu, mdWS); + } else if (auto peaksWS = + boost::dynamic_pointer_cast<const IPeaksWorkspace>(ws)) { + addPeaksWorkspaceMenuItems(menu, peaksWS); + } else if (auto groupWS = + boost::dynamic_pointer_cast<const WorkspaceGroup>(ws)) { + addWorkspaceGroupMenuItems(menu, groupWS); + } else if (boost::dynamic_pointer_cast<const Mantid::API::ITableWorkspace>( + ws)) { + addTableWorkspaceMenuItems(menu); + } + addClearMenuItems(menu, selectedWsName); + + // Get the names of the programs for the send to option + std::vector<std::string> programNames = + (Mantid::Kernel::ConfigService::Instance().getKeys( + "workspace.sendto.name")); + bool firstPass(true); + // Check to see if any options aren't visible + for (auto &programName : programNames) { + std::string visible = Mantid::Kernel::ConfigService::Instance().getString( + "workspace.sendto." + programName + ".visible"); + std::string target = Mantid::Kernel::ConfigService::Instance().getString( + "workspace.sendto." + programName + ".target"); + if (Mantid::Kernel::ConfigService::Instance().isExecutable(target) && + visible == "Yes") { + bool compatible(true); + std::string saveUsing( + Mantid::Kernel::ConfigService::Instance().getString( + "workspace.sendto." + programName + ".saveusing")); + try { + Mantid::API::IAlgorithm_sptr alg = + Mantid::API::AlgorithmManager::Instance().create(saveUsing); + alg->setPropertyValue("InputWorkspace", selectedWsName.toStdString()); + } catch (std::exception &) { + compatible = false; + } + if (compatible) { + if (firstPass) { + m_saveToProgram = new QMenu(tr("Send to"), this); + menu->addMenu(m_saveToProgram); + + // Sub-menu for program list + m_programMapper = new QSignalMapper(this); + } + QString name = QString::fromStdString(programName); + // Setup new menu option for the program + m_program = new QAction(name, this); + connect(m_program, SIGNAL(triggered()), m_programMapper, SLOT(map())); + // Send name of program when clicked + m_programMapper->setMapping(m_program, name); + m_saveToProgram->addAction(m_program); + + // Set first pass to false so that it doesn't set up another menu + // entry for all programs. + firstPass = false; + } + } + } + + // Tell the button what to listen for and what to do once clicked (if there + // is anything to connect it will be set to false) + if (!firstPass) + connect(m_programMapper, SIGNAL(mapped(const QString &)), this, + SLOT(onClickSaveToProgram(const QString &))); + + // Rename is valid for all workspace types + menu->addAction(m_rename); + // separate delete + menu->addSeparator(); + menu->addAction(m_delete); + } + + // Show the menu at the cursor's current position + menu->popup(QCursor::pos()); +} + +void QWorkspaceDockView::onClickShowData() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowWorkspaceData); +} + +void QWorkspaceDockView::showWorkspaceData() { m_mantidUI->importWorkspace(); } + +void QWorkspaceDockView::onClickShowInstrument() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowInstrumentView); +} + +void QWorkspaceDockView::showInstrumentView() { + m_mantidUI->showMantidInstrumentSelected(); +} + +void QWorkspaceDockView::onClickSaveToProgram(const QString &name) { + m_programName = name; + m_presenter->notifyFromView(ViewNotifiable::Flag::SaveToProgram); +} + +/** +* Saves a workspace based on the program the user chooses to save to. +*/ +void QWorkspaceDockView::saveToProgram() { + // Create a map for the keys and details to go into + std::map<std::string, std::string> programKeysAndDetails; + programKeysAndDetails["name"] = m_programName.toStdString(); + + // Get a list of the program detail keys (mandatory - target, saveusing) + // (optional - arguments, save parameters, workspace type) + std::vector<std::string> programKeys = + (Mantid::Kernel::ConfigService::Instance().getKeys( + ("workspace.sendto." + programKeysAndDetails.find("name")->second))); + + for (size_t i = 0; i < programKeys.size(); i++) { + // Assign a key to its value using the map + programKeysAndDetails[programKeys[i]] = + (Mantid::Kernel::ConfigService::Instance().getString( + ("workspace.sendto." + programKeysAndDetails.find("name")->second + + "." + programKeys[i]))); + } + + // Check to see if mandatory information is included + if ((programKeysAndDetails.count("name") != 0) && + (programKeysAndDetails.count("target") != 0) && + (programKeysAndDetails.count("saveusing") != 0)) { + std::string expTarget = + Poco::Path::expand(programKeysAndDetails.find("target")->second); + + QFileInfo target = QString::fromStdString(expTarget); + if (target.exists()) { + try { + // Convert to QString and create Algorithm + QString saveUsing = QString::fromStdString( + programKeysAndDetails.find("saveusing")->second); + + // Create a new save based on what files the new program can open + auto alg = m_mantidUI->createAlgorithm(saveUsing); + + // Get the file extention based on the workspace + Property *prop = alg->getProperty("Filename"); + FileProperty *fileProp = dynamic_cast<FileProperty *>(prop); + std::string ext; + if (fileProp) { + ext = fileProp->getDefaultExt(); + } + + // Save as.. default save + the file type i.e .nxs + alg->setPropertyValue( + "fileName", "auto_save_" + selectedWsName.toStdString() + ext); + + // Save the workspace + alg->setPropertyValue("InputWorkspace", selectedWsName.toStdString()); + + // If there are any save parameters + if (programKeysAndDetails.count("saveparameters") != 0) { + QString saveParametersGrouped = QString::fromStdString( + programKeysAndDetails.find("saveparameters")->second); + QStringList saveParameters = saveParametersGrouped.split(','); + + // For each one found split it up and assign the parameter + for (int i = 0; i < saveParameters.size(); i++) { + QStringList sPNameAndDetail = saveParameters[i].split('='); + std::string saveParameterName = + sPNameAndDetail[0].trimmed().toStdString(); + std::string saveParameterDetail = + sPNameAndDetail[1].trimmed().toStdString(); + if (saveParameterDetail == "True") + alg->setProperty(saveParameterName, true); + else if (saveParameterDetail == "False") + alg->setProperty(saveParameterName, false); + else // if not true or false then must be a value + { + alg->setPropertyValue(saveParameterName, saveParameterDetail); + } + } + } + + // Execute the save + executeAlgorithmAsync(alg, true); + + // Get the save location of the file (should be default Mantid folder) + QString savedFile = + QString::fromStdString(alg->getProperty("Filename")); + QStringList arguments; + + // Arguments for the program to take. Default will be the file anyway. + if (programKeysAndDetails.count("arguments") != 0) { + QString temp = QString::fromStdString( + programKeysAndDetails.find("arguments")->second); + temp.replace(QString("[file]"), savedFile); + // temp.replace(QString("[user]"), user; + arguments = temp.split(","); + } else + arguments.insert(0, savedFile); + + // convert the list into a standard vector for compatibility with Poco + std::vector<std::string> argumentsV; + + for (int i = 0; i < arguments.size(); i++) { + argumentsV.assign(1, (arguments[i].toStdString())); + } + + // Execute the program + try { + Mantid::Kernel::ConfigService::Instance().launchProcess(expTarget, + argumentsV); + } catch (std::runtime_error &) { + QMessageBox::information( + this, "Error", "User tried to open program from: " + + QString::fromStdString(expTarget) + + " There was an error opening the program. " + "Please check the target and arguments list " + "to ensure that these are correct"); + } + } catch (std::exception &) { + QMessageBox::information( + this, "Mantid - Send to Program", + "A file property wasn't found. Please check that the correct" + + QString("save algorithm was used.\n(View -> Preferences -> " + "Mantid -> SendTo -> Edit -> SaveUsing)")); + } + } else + QMessageBox::information(this, "Target Path Error", + "User tried to open program from: " + + QString::fromStdString(expTarget) + + " The target file path for the program " + "can't be found. Please check that the full " + "path is correct"); + } +} + +void QWorkspaceDockView::onClickPlotSpectra() { + m_presenter->notifyFromView(ViewNotifiable::Flag::PlotSpectrum); +} + +void QWorkspaceDockView::onClickPlotSpectraErr() { + m_presenter->notifyFromView(ViewNotifiable::Flag::PlotSpectrumWithErrors); +} + +/** Plots a single spectrum from each selected workspace +* @param showErrors If true, show error bars. Otherswise no error bars are +* displayed. +*/ +void QWorkspaceDockView::plotSpectrum(bool showErrors) { + const auto userInput = m_tree->chooseSpectrumFromSelected(); + // An empty map will be returned if the user clicks cancel in the spectrum + // selection + if (userInput.plots.empty()) + return; + + bool spectrumPlot(true), clearWindow(false); + MultiLayer *window(NULL); + m_mantidUI->plot1D(userInput.plots, spectrumPlot, + MantidQt::DistributionDefault, showErrors, window, + clearWindow, userInput.waterfall); +} + +void QWorkspaceDockView::onClickDrawColorFillPlot() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowColourFillPlot); +} + +/** +* Draw a color fill plot of the workspaces that are currently selected. +* NOTE: The drawing of 2D plots is currently intimately linked with MantidMatrix +* meaning +* that one of these must be generated first! +*/ +void QWorkspaceDockView::showColourFillPlot() { + // Get the selected workspaces + auto items = m_tree->selectedItems(); + if (items.empty()) + return; + + // Extract child workspace names from any WorkspaceGroups selected. + // Use a list to preserve workspace order. + QStringList allWsNames; + + for (auto &item : items) { + auto ws = item->data(0, Qt::UserRole).value<Workspace_sptr>(); + + if (auto wsGroup = boost::dynamic_pointer_cast<WorkspaceGroup>(ws)) { + for (auto &name : wsGroup->getNames()) + allWsNames.append(QString::fromStdString(name)); + } else + allWsNames.append(item->text(0)); + } + + // remove duplicate workspace entries + allWsNames.removeDuplicates(); + + m_mantidUI->drawColorFillPlots(allWsNames); +} + +void QWorkspaceDockView::onClickShowDetectorTable() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowDetectorsTable); +} + +void QWorkspaceDockView::showDetectorsTable() { + // get selected workspace + auto ws = getSelectedWorkspaceNames()[0]; + m_mantidUI->createDetectorTable(QString::fromStdString(ws), + std::vector<int>(), false); +} + +void QWorkspaceDockView::onClickShowBoxData() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowBoxDataTable); +} + +void QWorkspaceDockView::showBoxDataTable() { + m_mantidUI->importBoxDataTable(); +} + +void QWorkspaceDockView::onClickShowVates() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowVatesGUI); +} + +void QWorkspaceDockView::showVatesGUI() { + m_mantidUI->showVatesSimpleInterface(); +} + +void QWorkspaceDockView::onClickShowMDPlot() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowMDPlot); +} + +void QWorkspaceDockView::showMDPlot() { m_mantidUI->showMDPlot(); } + +void QWorkspaceDockView::onClickShowListData() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowListData); +} + +void QWorkspaceDockView::showListData() { m_mantidUI->showListData(); } + +void QWorkspaceDockView::onClickShowSpectrumViewer() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowSpectrumViewer); +} + +void QWorkspaceDockView::showSpectrumViewer() { + m_mantidUI->showSpectrumViewer(); +} + +void QWorkspaceDockView::onClickShowSliceViewer() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowSliceViewer); +} + +void QWorkspaceDockView::showSliceViewer() { m_mantidUI->showSliceViewer(); } + +void QWorkspaceDockView::onClickShowFileLog() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowLogs); +} + +void QWorkspaceDockView::showLogs() { m_mantidUI->showLogFileWindow(); } + +void QWorkspaceDockView::onClickShowSampleMaterial() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowSampleMaterialWindow); +} + +void QWorkspaceDockView::showSampleMaterialWindow() { + m_mantidUI->showSampleMaterialWindow(); +} + +void QWorkspaceDockView::onClickShowAlgHistory() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowAlgorithmHistory); +} + +void QWorkspaceDockView::showAlgorithmHistory() { + m_mantidUI->showAlgorithmHistory(); +} + +void QWorkspaceDockView::onClickShowTransposed() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowTransposed); +} + +void QWorkspaceDockView::showTransposed() { m_mantidUI->importTransposed(); } + +void QWorkspaceDockView::onClickSaveNexusWorkspace() { + m_saveFileType = SaveFileType::Nexus; + m_presenter->notifyFromView(ViewNotifiable::Flag::SaveSingleWorkspace); +} +/** +* Convert selected TableWorkspace to a MatrixWorkspace. +*/ +void QWorkspaceDockView::onClickConvertToMatrixWorkspace() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ConvertToMatrixWorkspace); +} + +/** +* Convert selected MDHistoWorkspace to a MatrixWorkspace. +*/ +void QWorkspaceDockView::onClickConvertMDHistoToMatrixWorkspace() { + m_presenter->notifyFromView( + ViewNotifiable::Flag::ConvertMDHistoToMatrixWorkspace); +} + +void QWorkspaceDockView::convertToMatrixWorkspace() { + m_mantidUI->showAlgorithmDialog("ConvertTableToMatrixWorkspace"); +} + +void QWorkspaceDockView::convertMDHistoToMatrixWorkspace() { + m_mantidUI->showAlgorithmDialog("ConvertMDHistoToMatrixWorkspace"); +} + +/** +* Handler for the clear the UB matrix event. +*/ +void QWorkspaceDockView::onClickClearUB() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ClearUBMatrix); +} + +void QWorkspaceDockView::onClickPlotSurface() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowSurfacePlot); +} + +/** +* Create a 3D surface plot from the selected workspace group +*/ +void QWorkspaceDockView::showSurfacePlot() { m_mantidUI->showSurfacePlot(); } + +void QWorkspaceDockView::onClickPlotContour() { + m_presenter->notifyFromView(ViewNotifiable::Flag::ShowContourPlot); +} + +/** +* Create a contour plot from the selected workspace group +*/ +void QWorkspaceDockView::showContourPlot() { m_mantidUI->showContourPlot(); } + +/** +* Allows asynchronous execution of algorithms. This method is made +* available in the view for access by the presenter in order to +* obviate the dependency on Qt in the Unit tests. +* @param alg : algorithm to be executed +* @param wait : determines whether or not a non-gui blocking wait should occur. +*/ +bool QWorkspaceDockView::executeAlgorithmAsync(Mantid::API::IAlgorithm_sptr alg, + const bool wait) { + return m_mantidUI->executeAlgorithmAsync(alg, wait); +} + +} // namespace MantidWidgets +} // namespace MantidQt diff --git a/MantidQt/MantidWidgets/src/WorkspacePresenter/WorkspacePresenter.cpp b/MantidQt/MantidWidgets/src/WorkspacePresenter/WorkspacePresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8646eab2f6781635b63e76b543981e80f61491dc --- /dev/null +++ b/MantidQt/MantidWidgets/src/WorkspacePresenter/WorkspacePresenter.cpp @@ -0,0 +1,455 @@ +#include "MantidQtMantidWidgets/WorkspacePresenter/WorkspacePresenter.h" +#include "MantidKernel/make_unique.h" +#include "MantidQtMantidWidgets/WorkspacePresenter/ADSAdapter.h" +#include "MantidQtMantidWidgets/WorkspacePresenter/IWorkspaceDockView.h" +#include <MantidAPI/AlgorithmManager.h> + +using namespace Mantid; + +namespace MantidQt { +namespace MantidWidgets { + +WorkspacePresenter::WorkspacePresenter(DockView_wptr view) + : m_view(std::move(view)), m_adapter(Kernel::make_unique<ADSAdapter>()) {} + +WorkspacePresenter::~WorkspacePresenter() {} + +/// Initialises the view weak pointer for the Workspace Provider. +void WorkspacePresenter::init() { + m_adapter->registerPresenter(std::move(m_view.lock()->getPresenterWeakPtr())); +} + +/// Handle WorkspaceProvider (ADS) notifications +void WorkspacePresenter::notifyFromWorkspaceProvider( + WorkspaceProviderNotifiable::Flag flag) { + switch (flag) { + case WorkspaceProviderNotifiable::Flag::WorkspaceLoaded: + workspaceLoaded(); + break; + case WorkspaceProviderNotifiable::Flag::WorkspaceRenamed: + workspaceRenamed(); + break; + case WorkspaceProviderNotifiable::Flag::WorkspacesGrouped: + workspacesGrouped(); + break; + case WorkspaceProviderNotifiable::Flag::WorkspacesUngrouped: + workspacesUngrouped(); + break; + case WorkspaceProviderNotifiable::Flag::WorkspaceGroupUpdated: + workspaceGroupUpdated(); + break; + case WorkspaceProviderNotifiable::Flag::WorkspaceDeleted: + workspacesDeleted(); + break; + case WorkspaceProviderNotifiable::Flag::WorkspacesCleared: + workspacesCleared(); + break; + case WorkspaceProviderNotifiable::Flag::GenericUpdateNotification: + updateView(); + break; + } +} + +/// Handle notifications from the view. +void WorkspacePresenter::notifyFromView(ViewNotifiable::Flag flag) { + switch (flag) { + case ViewNotifiable::Flag::LoadWorkspace: + loadWorkspace(); + break; + case ViewNotifiable::Flag::LoadLiveDataWorkspace: + loadLiveData(); + break; + case ViewNotifiable::Flag::RenameWorkspace: + renameWorkspace(); + break; + case ViewNotifiable::Flag::GroupWorkspaces: + groupWorkspaces(); + break; + case ViewNotifiable::Flag::UngroupWorkspaces: + ungroupWorkspaces(); + break; + case ViewNotifiable::Flag::SortWorkspaces: + sortWorkspaces(); + break; + case ViewNotifiable::Flag::DeleteWorkspaces: + deleteWorkspaces(); + break; + case ViewNotifiable::Flag::SaveSingleWorkspace: + saveSingleWorkspace(); + break; + case ViewNotifiable::Flag::SaveWorkspaceCollection: + saveWorkspaceCollection(); + break; + case ViewNotifiable::Flag::FilterWorkspaces: + filterWorkspaces(); + break; + case ViewNotifiable::Flag::PopulateAndShowWorkspaceContextMenu: + populateAndShowWorkspaceContextMenu(); + break; + case ViewNotifiable::Flag::ShowWorkspaceData: + showWorkspaceData(); + break; + case ViewNotifiable::Flag::ShowInstrumentView: + showInstrumentView(); + break; + case ViewNotifiable::Flag::SaveToProgram: + saveToProgram(); + break; + case ViewNotifiable::Flag::PlotSpectrum: + plotSpectrum(); + break; + case ViewNotifiable::Flag::PlotSpectrumWithErrors: + plotSpectrumWithErrors(); + break; + case ViewNotifiable::Flag::ShowColourFillPlot: + showColourFillPlot(); + break; + case ViewNotifiable::Flag::ShowDetectorsTable: + showDetectorsTable(); + break; + case ViewNotifiable::Flag::ShowBoxDataTable: + showBoxDataTable(); + break; + case ViewNotifiable::Flag::ShowVatesGUI: + showVatesGUI(); + break; + case ViewNotifiable::Flag::ShowMDPlot: + showMDPlot(); + break; + case ViewNotifiable::Flag::ShowListData: + showListData(); + break; + case ViewNotifiable::Flag::ShowSpectrumViewer: + showSpectrumViewer(); + break; + case ViewNotifiable::Flag::ShowSliceViewer: + showSliceViewer(); + break; + case ViewNotifiable::Flag::ShowLogs: + showLogs(); + break; + case ViewNotifiable::Flag::ShowSampleMaterialWindow: + showSampleMaterialWindow(); + break; + case ViewNotifiable::Flag::ShowAlgorithmHistory: + showAlgorithmHistory(); + break; + case ViewNotifiable::Flag::ShowTransposed: + showTransposed(); + break; + case ViewNotifiable::Flag::ConvertToMatrixWorkspace: + convertToMatrixWorkspace(); + break; + case ViewNotifiable::Flag::ConvertMDHistoToMatrixWorkspace: + convertMDHistoToMatrixWorkspace(); + break; + case ViewNotifiable::Flag::ClearUBMatrix: + clearUBMatrix(); + break; + case ViewNotifiable::Flag::ShowSurfacePlot: + showSurfacePlot(); + break; + case ViewNotifiable::Flag::ShowContourPlot: + showContourPlot(); + break; + case ViewNotifiable::Flag::RefreshWorkspaces: + refreshWorkspaces(); + break; + } +} + +void WorkspacePresenter::loadWorkspace() { + auto view = lockView(); + view->showLoadDialog(); +} + +void WorkspacePresenter::loadLiveData() { + auto view = lockView(); + view->showLiveDataDialog(); +} + +void WorkspacePresenter::renameWorkspace() { + auto view = lockView(); + view->showRenameDialog(view->getSelectedWorkspaceNames()); +} + +void WorkspacePresenter::groupWorkspaces() { + auto view = lockView(); + auto selected = view->getSelectedWorkspaceNames(); + + std::string groupName("NewGroup"); + // get selected workspaces + if (selected.size() < 2) { + view->showCriticalUserMessage("Cannot Group Workspaces", + "Select at least two workspaces to group "); + return; + } + + if (m_adapter->doesWorkspaceExist(groupName)) { + if (!view->askUserYesNo("", + "Workspace " + groupName + + " already exists. Do you want to replace it?")) + return; + } + + try { + std::string algName("GroupWorkspaces"); + Mantid::API::IAlgorithm_sptr alg = + Mantid::API::AlgorithmManager::Instance().create(algName, -1); + alg->initialize(); + alg->setProperty("InputWorkspaces", selected); + alg->setPropertyValue("OutputWorkspace", groupName); + // execute the algorithm + bool bStatus = alg->execute(); + if (!bStatus) { + view->showCriticalUserMessage("MantidPlot - Algorithm error", + " Error in GroupWorkspaces algorithm"); + } + } catch (...) { + view->showCriticalUserMessage("MantidPlot - Algorithm error", + " Error in GroupWorkspaces algorithm"); + } +} + +void WorkspacePresenter::ungroupWorkspaces() { + auto view = lockView(); + auto selected = view->getSelectedWorkspaceNames(); + + if (selected.size() == 0) { + view->showCriticalUserMessage("Error Ungrouping Workspaces", + "Select a group workspace to Ungroup."); + return; + } + + try { + // workspace name + auto wsname = selected[0]; + + std::string algName("UnGroupWorkspace"); + Mantid::API::IAlgorithm_sptr alg = + Mantid::API::AlgorithmManager::Instance().create(algName, -1); + alg->initialize(); + alg->setProperty("InputWorkspace", wsname); + + // execute the algorithm + bool bStatus = alg->execute(); + if (!bStatus) { + view->showCriticalUserMessage("MantidPlot - Algorithm error", + " Error in UnGroupWorkspace algorithm"); + } + } catch (...) { + view->showCriticalUserMessage("MantidPlot - Algorithm error", + " Error in UnGroupWorkspace algorithm"); + } +} + +void WorkspacePresenter::sortWorkspaces() { + auto view = lockView(); + + view->sortWorkspaces(view->getSortCriteria(), view->getSortDirection()); +} + +void WorkspacePresenter::deleteWorkspaces() { + auto view = lockView(); + bool deleteWs = true; + auto selected = view->getSelectedWorkspaceNames(); + + // Ensure all workspaces exist in the ADS + if (!std::all_of(selected.cbegin(), selected.cend(), + [=](const std::string &ws) { + return m_adapter->doesWorkspaceExist(ws); + })) { + view->showCriticalUserMessage( + "Delete Workspaces", + "Unabel to delete workspaces. Invalid workspace names provided."); + return; + } + + if (view->isPromptDelete()) + deleteWs = view->deleteConfirmation(); + + if (deleteWs) + view->deleteWorkspaces(selected); +} + +void WorkspacePresenter::saveSingleWorkspace() { + auto view = lockView(); + view->saveWorkspace(view->getSaveFileType()); +} + +void WorkspacePresenter::saveWorkspaceCollection() { + auto view = lockView(); + view->saveWorkspaces(view->getSelectedWorkspaceNames()); +} + +void WorkspacePresenter::filterWorkspaces() { + auto view = lockView(); + view->filterWorkspaces(view->getFilterText()); +} + +void WorkspacePresenter::populateAndShowWorkspaceContextMenu() { + auto view = lockView(); + view->popupContextMenu(); +} + +void WorkspacePresenter::showWorkspaceData() { + auto view = lockView(); + view->showWorkspaceData(); +} + +void WorkspacePresenter::showInstrumentView() { + auto view = lockView(); + view->showInstrumentView(); +} + +void WorkspacePresenter::saveToProgram() { + auto view = lockView(); + view->saveToProgram(); +} + +void WorkspacePresenter::plotSpectrum() { + auto view = lockView(); + view->plotSpectrum(false); +} + +void WorkspacePresenter::plotSpectrumWithErrors() { + auto view = lockView(); + view->plotSpectrum(true); +} + +void WorkspacePresenter::showColourFillPlot() { + auto view = lockView(); + view->showColourFillPlot(); +} + +void WorkspacePresenter::showDetectorsTable() { + auto view = lockView(); + view->showDetectorsTable(); +} + +void WorkspacePresenter::showBoxDataTable() { + auto view = lockView(); + view->showBoxDataTable(); +} + +void WorkspacePresenter::showVatesGUI() { + auto view = lockView(); + view->showVatesGUI(); +} + +void WorkspacePresenter::showMDPlot() { + auto view = lockView(); + view->showMDPlot(); +} + +void WorkspacePresenter::showListData() { + auto view = lockView(); + view->showListData(); +} + +void WorkspacePresenter::showSpectrumViewer() { + auto view = lockView(); + view->showSpectrumViewer(); +} + +void WorkspacePresenter::showSliceViewer() { + auto view = lockView(); + view->showSliceViewer(); +} + +void WorkspacePresenter::showLogs() { + auto view = lockView(); + view->showLogs(); +} + +void WorkspacePresenter::showSampleMaterialWindow() { + auto view = lockView(); + view->showSampleMaterialWindow(); +} + +void WorkspacePresenter::showAlgorithmHistory() { + auto view = lockView(); + view->showAlgorithmHistory(); +} + +void WorkspacePresenter::showTransposed() { + auto view = lockView(); + view->showTransposed(); +} + +void WorkspacePresenter::convertToMatrixWorkspace() { + auto view = lockView(); + view->convertToMatrixWorkspace(); +} + +void WorkspacePresenter::convertMDHistoToMatrixWorkspace() { + auto view = lockView(); + view->convertMDHistoToMatrixWorkspace(); +} + +void WorkspacePresenter::clearUBMatrix() { + auto view = lockView(); + auto wsNames = view->getSelectedWorkspaceNames(); + + for (auto &ws : wsNames) { + auto alg = Mantid::API::AlgorithmManager::Instance().create("ClearUB", -1); + if (alg) { + alg->initialize(); + alg->setPropertyValue("Workspace", ws); + // Run in this manner due to Qt dependencies within this method. + // otherwise it would have been implemented here. + view->executeAlgorithmAsync(alg); + } else + break; + } +} + +void WorkspacePresenter::showSurfacePlot() { + auto view = lockView(); + view->showSurfacePlot(); +} + +void WorkspacePresenter::showContourPlot() { + auto view = lockView(); + view->showContourPlot(); +} + +void WorkspacePresenter::refreshWorkspaces() { updateView(); } + +void WorkspacePresenter::workspaceLoaded() { updateView(); } + +void WorkspacePresenter::workspaceRenamed() { + auto view = lockView(); + view->recordWorkspaceRename(m_adapter->getOldName(), m_adapter->getNewName()); + view->updateTree(m_adapter->topLevelItems()); +} + +void WorkspacePresenter::workspacesGrouped() { updateView(); } +void WorkspacePresenter::workspacesUngrouped() { updateView(); } +void WorkspacePresenter::workspaceGroupUpdated() { updateView(); } + +void WorkspacePresenter::workspacesDeleted() { updateView(); } + +void WorkspacePresenter::workspacesCleared() { + auto view = lockView(); + view->clearView(); +} + +/// Lock the view weak_ptr and return the shared_ptr generated. +DockView_sptr WorkspacePresenter::lockView() { + auto view_sptr = m_view.lock(); + + if (view_sptr == nullptr) + throw std::runtime_error("Could not obtain pointer to DockView."); + + return std::move(view_sptr); +} + +/// Update the view by publishing the ADS contents. +void WorkspacePresenter::updateView() { + auto view = lockView(); + view->updateTree(m_adapter->topLevelItems()); +} + +} // namespace MantidQt +} // namespace MantidWidgets \ No newline at end of file diff --git a/MantidQt/MantidWidgets/test/WorkspacePresenter/ADSAdapterTest.h b/MantidQt/MantidWidgets/test/WorkspacePresenter/ADSAdapterTest.h new file mode 100644 index 0000000000000000000000000000000000000000..6aa92ce63da6c4259520973f87b30423874ecd3c --- /dev/null +++ b/MantidQt/MantidWidgets/test/WorkspacePresenter/ADSAdapterTest.h @@ -0,0 +1,130 @@ +#include "MantidQtMantidWidgets/WorkspacePresenter/WorkspaceDockMockObjects.h" +#include <MantidAPI/AnalysisDataService.h> +#include <MantidAPI/WorkspaceGroup.h> +#include <MantidQtMantidWidgets/WorkspacePresenter/ADSAdapter.h> +#include <MantidTestHelpers/WorkspaceCreationHelper.h> +#include <cxxtest/TestSuite.h> + +using namespace testing; +using namespace MantidQt::MantidWidgets; +using namespace Mantid::API; + +using NotifyFlag = WorkspaceProviderNotifiable::Flag; + +class ADSAdapterTest : public CxxTest::TestSuite { +public: + static ADSAdapterTest *createSuite() { return new ADSAdapterTest(); } + + static void destroySuite(ADSAdapterTest *suite) { delete suite; } + + void setUp() override { + mockPresenter.reset(); + mockPresenter = + boost::make_shared<NiceMock<MockWorkspaceProviderNotifiable>>(); + adapter.registerPresenter(mockPresenter); + AnalysisDataService::Instance().clear(); + } + + void testLoadWorkspaceIntoADS() { + auto wksp = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + + EXPECT_CALL(*mockPresenter.get(), + notifyFromWorkspaceProvider(NotifyFlag::WorkspaceLoaded)) + .Times(Exactly(1)); + + AnalysisDataService::Instance().add("wksp", wksp); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockPresenter)); + } + + void testRemoveWorkspaceFromADS() { + auto wksp = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + + AnalysisDataService::Instance().add("wksp", wksp); + + EXPECT_CALL(*mockPresenter.get(), + notifyFromWorkspaceProvider(NotifyFlag::WorkspaceDeleted)) + .Times(Exactly(1)); + + AnalysisDataService::Instance().remove("wksp"); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockPresenter)); + } + + void testClearADS() { + auto wksp1 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + auto wksp2 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + + AnalysisDataService::Instance().add("wksp1", wksp1); + AnalysisDataService::Instance().add("wksp2", wksp2); + + EXPECT_CALL(*mockPresenter.get(), + notifyFromWorkspaceProvider(NotifyFlag::WorkspacesCleared)) + .Times(Exactly(1)); + + AnalysisDataService::Instance().clear(); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockPresenter)); + } + + void testRenameWorkspace() { + auto wksp = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + AnalysisDataService::Instance().add("wksp", wksp); + EXPECT_CALL(*mockPresenter.get(), + notifyFromWorkspaceProvider(NotifyFlag::WorkspaceRenamed)) + .Times(Exactly(1)); + + AnalysisDataService::Instance().rename("wksp", "myWorkspace"); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockPresenter)); + } + + void testGroupWorkspaces() { + EXPECT_CALL(*mockPresenter.get(), + notifyFromWorkspaceProvider(NotifyFlag::WorkspacesGrouped)) + .Times(Exactly(1)); + + AnalysisDataService::Instance().notificationCenter.postNotification( + new WorkspacesGroupedNotification(std::vector<std::string>())); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockPresenter)); + } + + void testUngroupWorkspaces() { + EXPECT_CALL(*mockPresenter.get(), + notifyFromWorkspaceProvider(NotifyFlag::WorkspacesUngrouped)) + .Times(Exactly(1)); + + AnalysisDataService::Instance().notificationCenter.postNotification( + new Mantid::API::WorkspaceUnGroupingNotification("", nullptr)); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockPresenter)); + } + + void testWorkspaceGroupUpdated() { + auto wksp1 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + auto wksp2 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + auto wksp3 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + + auto group = + WorkspaceCreationHelper::CreateWorkspaceGroup(0, 10, 10, "group"); + + AnalysisDataService::Instance().add("wksp1", wksp1); + AnalysisDataService::Instance().add("wksp2", wksp2); + AnalysisDataService::Instance().add("wksp3", wksp3); + AnalysisDataService::Instance().addToGroup("group", "wksp1"); + AnalysisDataService::Instance().addToGroup("group", "wksp2"); + + EXPECT_CALL(*mockPresenter.get(), + notifyFromWorkspaceProvider(NotifyFlag::WorkspaceGroupUpdated)) + .Times(Exactly(1)); + + AnalysisDataService::Instance().addToGroup("group", "wksp3"); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockPresenter)); + } + +private: + boost::shared_ptr<NiceMock<MockWorkspaceProviderNotifiable>> mockPresenter; + ADSAdapter adapter; +}; \ No newline at end of file diff --git a/MantidQt/MantidWidgets/test/WorkspacePresenter/WorkspacePresenterTest.h b/MantidQt/MantidWidgets/test/WorkspacePresenter/WorkspacePresenterTest.h new file mode 100644 index 0000000000000000000000000000000000000000..e014cfd3f3c222d670ea9e9609e36ca0ecd4fb45 --- /dev/null +++ b/MantidQt/MantidWidgets/test/WorkspacePresenter/WorkspacePresenterTest.h @@ -0,0 +1,681 @@ +#include <cxxtest/TestSuite.h> +#include <gmock/gmock.h> +#include <gtest/gtest.h> + +#include "MantidQtMantidWidgets/WorkspacePresenter/WorkspaceDockMockObjects.h" +#include "MantidQtMantidWidgets/WorkspacePresenter/WorkspacePresenter.h" + +#include <MantidAPI/AlgorithmManager.h> +#include <MantidAPI/AnalysisDataService.h> +#include <MantidAPI/FrameworkManager.h> +#include <MantidTestHelpers/WorkspaceCreationHelper.h> + +#include <algorithm> +#include <boost/make_shared.hpp> +#include <boost/shared_ptr.hpp> + +using namespace testing; +using namespace Mantid::API; +using namespace MantidQt::MantidWidgets; + +class WorkspacePresenterTest : public CxxTest::TestSuite { +public: + static WorkspacePresenterTest *createSuite() { + return new WorkspacePresenterTest(); + } + static void destroySuite(WorkspacePresenterTest *suite) { delete suite; } + + WorkspacePresenterTest() { FrameworkManager::Instance(); } + + void setUp() override { + mockView.reset(); + mockView = boost::make_shared<NiceMock<MockWorkspaceDockView>>(); + mockView->init(); + + presenter = mockView->getPresenterSharedPtr(); + } + + void testLoadWorkspaceFromDock() { + EXPECT_CALL(*mockView.get(), showLoadDialog()).Times(1); + + presenter->notifyFromView(ViewNotifiable::Flag::LoadWorkspace); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testLoadLiveData() { + EXPECT_CALL(*mockView.get(), showLiveDataDialog()).Times(1); + + presenter->notifyFromView(ViewNotifiable::Flag::LoadLiveDataWorkspace); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testLoadWorkspaceExternal() { + auto wksp = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + + EXPECT_CALL(*mockView.get(), updateTree(_)).Times(AtLeast(1)); + + AnalysisDataService::Instance().add("wksp", wksp); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + + AnalysisDataService::Instance().remove("wksp"); + } + + void testDeleteWorkspacesFromDockWithPrompt() { + auto ws1 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + auto ws2 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + AnalysisDataService::Instance().add("ws1", ws1); + AnalysisDataService::Instance().add("ws2", ws2); + + ::testing::DefaultValue<StringList>::Set( + StringList(StringList{"ws1", "ws2"})); + ON_CALL(*mockView.get(), deleteConfirmation()).WillByDefault(Return(true)); + ON_CALL(*mockView.get(), isPromptDelete()).WillByDefault(Return(true)); + + EXPECT_CALL(*mockView.get(), isPromptDelete()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), deleteConfirmation()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), getSelectedWorkspaceNames()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), deleteWorkspaces(StringList{"ws1", "ws2"})) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::DeleteWorkspaces); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + AnalysisDataService::Instance().remove("ws1"); + AnalysisDataService::Instance().remove("ws2"); + } + + void testDeleteWorkspacesFromDockWithPromptUserDecline() { + auto ws1 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + auto ws2 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + AnalysisDataService::Instance().add("ws1", ws1); + AnalysisDataService::Instance().add("ws2", ws2); + + ::testing::DefaultValue<StringList>::Set( + StringList(StringList{"ws1", "ws2"})); + ON_CALL(*mockView.get(), deleteConfirmation()).WillByDefault(Return(false)); + ON_CALL(*mockView.get(), isPromptDelete()).WillByDefault(Return(true)); + + EXPECT_CALL(*mockView.get(), isPromptDelete()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), deleteConfirmation()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), getSelectedWorkspaceNames()).Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::DeleteWorkspaces); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + AnalysisDataService::Instance().remove("ws1"); + AnalysisDataService::Instance().remove("ws2"); + } + + void testDeleteWorkspacesFromDockWithoutPrompt() { + auto ws1 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + auto ws2 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + AnalysisDataService::Instance().add("ws1", ws1); + AnalysisDataService::Instance().add("ws2", ws2); + + ::testing::DefaultValue<StringList>::Set( + StringList(StringList{"ws1", "ws2"})); + ON_CALL(*mockView.get(), isPromptDelete()).WillByDefault(Return(false)); + + EXPECT_CALL(*mockView.get(), isPromptDelete()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), getSelectedWorkspaceNames()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), deleteWorkspaces(StringList{"ws1", "ws2"})) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::DeleteWorkspaces); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + AnalysisDataService::Instance().remove("ws1"); + AnalysisDataService::Instance().remove("ws2"); + } + + void testDeleteWorkspacesInvalidInput() { + ::testing::DefaultValue<StringList>::Set( + StringList(StringList{"ws1", "ws2"})); + + EXPECT_CALL(*mockView.get(), showCriticalUserMessage(_, _)) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::DeleteWorkspaces); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testDeleteWorkspacesExternal() { + auto wksp = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + + AnalysisDataService::Instance().add("wksp", wksp); + + EXPECT_CALL(*mockView.get(), updateTree(_)).Times(Exactly(1)); + + AnalysisDataService::Instance().remove("wksp"); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testADSCleared() { + auto wksp = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + + AnalysisDataService::Instance().add("wksp", wksp); + + EXPECT_CALL(*mockView.get(), clearView()).Times(Exactly(1)); + + AnalysisDataService::Instance().clear(); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testRenameWorkspaceFromDock() { + // Instruct gmock to return empty StringList + ::testing::DefaultValue<StringList>::Set(StringList(StringList())); + + EXPECT_CALL(*mockView.get(), getSelectedWorkspaceNames()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), showRenameDialog(_)).Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::RenameWorkspace); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testRenameWorkspaceExternal() { + auto wksp = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + + AnalysisDataService::Instance().add("wksp", wksp); + + EXPECT_CALL(*mockView.get(), updateTree(_)).Times(AtLeast(1)); + + AnalysisDataService::Instance().rename("wksp", "myWorkspace"); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + + AnalysisDataService::Instance().remove("myWorkspace"); + } + + void testWorkspacesGrouped() { + auto ws1 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + auto ws2 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + AnalysisDataService::Instance().add("ws1", ws1); + AnalysisDataService::Instance().add("ws2", ws2); + ::testing::DefaultValue<StringList>::Set(StringList{"ws1", "ws2"}); + + EXPECT_CALL(*mockView.get(), getSelectedWorkspaceNames()).Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::GroupWorkspaces); + + auto group = boost::dynamic_pointer_cast<WorkspaceGroup>( + AnalysisDataService::Instance().retrieve("NewGroup")); + + TS_ASSERT(group != nullptr); + + if (group) { + auto names = group->getNames(); + TS_ASSERT_EQUALS(names.size(), 2); + TS_ASSERT_EQUALS(names[0], "ws1"); + TS_ASSERT_EQUALS(names[1], "ws2"); + } + + AnalysisDataService::Instance().deepRemoveGroup("NewGroup"); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testInvalidGroupFails() { + ::testing::DefaultValue<StringList>::Set(StringList()); + + EXPECT_CALL(*mockView.get(), getSelectedWorkspaceNames()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), showCriticalUserMessage(_, _)) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::GroupWorkspaces); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testGroupAlreadyExistsUserConfirm() { + createGroup("NewGroup"); + auto ws1 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + auto ws2 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + AnalysisDataService::Instance().add("ws1", ws1); + AnalysisDataService::Instance().add("ws2", ws2); + + ::testing::DefaultValue<StringList>::Set(StringList{"ws1", "ws2"}); + ON_CALL(*mockView.get(), askUserYesNo(_, _)).WillByDefault(Return(true)); + + EXPECT_CALL(*mockView.get(), askUserYesNo(_, _)).Times(1); + EXPECT_CALL(*mockView.get(), getSelectedWorkspaceNames()).Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::GroupWorkspaces); + + auto group = boost::dynamic_pointer_cast<WorkspaceGroup>( + AnalysisDataService::Instance().retrieve("NewGroup")); + auto names = AnalysisDataService::Instance().getObjectNames(); + + // The old "NewGroup" would have been ungrouped in order to create + // the another "NewGroup" so check to make sure previously grouped + // workspaces still exist + TS_ASSERT( + std::any_of(names.cbegin(), names.cend(), [](const std::string name) { + return name.compare("wksp1") == 0; + })); + TS_ASSERT( + std::any_of(names.cbegin(), names.cend(), [](const std::string name) { + return name.compare("wksp2") == 0; + })); + + TS_ASSERT(group != nullptr); + + if (group) { + auto names = group->getNames(); + TS_ASSERT_EQUALS(names.size(), 2); + TS_ASSERT_EQUALS(names[0], "ws1"); + TS_ASSERT_EQUALS(names[1], "ws2"); + } + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + + // Remove group and left over workspaces + removeGroup("NewGroup"); + AnalysisDataService::Instance().remove("wksp1"); + AnalysisDataService::Instance().remove("wksp2"); + } + + void testGroupAlreadyExistsUserDenies() { + createGroup("NewGroup"); + + ::testing::DefaultValue<StringList>::Set(StringList{"ws1", "ws2"}); + ON_CALL(*mockView.get(), askUserYesNo(_, _)).WillByDefault(Return(false)); + + EXPECT_CALL(*mockView.get(), askUserYesNo(_, _)).Times(1); + EXPECT_CALL(*mockView.get(), getSelectedWorkspaceNames()).Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::GroupWorkspaces); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + + removeGroup("NewGroup"); + } + + void testWorkspacesUngrouped() { + createGroup("group"); + ::testing::DefaultValue<StringList>::Set(StringList(StringList{"group"})); + + EXPECT_CALL(*mockView.get(), getSelectedWorkspaceNames()).Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::UngroupWorkspaces); + + auto names = AnalysisDataService::Instance().getObjectNames(); + + TS_ASSERT(std::none_of(names.cbegin(), names.cend(), [](std::string name) { + return name.compare("group") == 0; + })); + TS_ASSERT(std::any_of(names.cbegin(), names.cend(), [](std::string name) { + return name.compare("wksp1") == 0; + })); + TS_ASSERT(std::any_of(names.cbegin(), names.cend(), [](std::string name) { + return name.compare("wksp2") == 0; + })); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + + AnalysisDataService::Instance().clear(); + } + + void testInvalidGroupForUngrouping() { + ::testing::DefaultValue<StringList>::Set(StringList(StringList())); + + EXPECT_CALL(*mockView.get(), getSelectedWorkspaceNames()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), showCriticalUserMessage(_, _)) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::UngroupWorkspaces); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testWorkspacesGroupedExternal() { + EXPECT_CALL(*mockView.get(), updateTree(_)).Times(AtLeast(1)); + + AnalysisDataService::Instance().notificationCenter.postNotification( + new WorkspacesGroupedNotification(std::vector<std::string>())); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testWorkspacesUnGroupedExternal() { + EXPECT_CALL(*mockView.get(), updateTree(_)).Times(AtLeast(1)); + + AnalysisDataService::Instance().notificationCenter.postNotification( + new Mantid::API::WorkspaceUnGroupingNotification("", nullptr)); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testWorkspaceGroupUpdated() { + std::string groupName = "group"; + createGroup(groupName); + + auto wksp = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + AnalysisDataService::Instance().add("wksp", wksp); + + EXPECT_CALL(*mockView.get(), updateTree(_)).Times(AtLeast(1)); + + AnalysisDataService::Instance().addToGroup(groupName, "wksp"); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + + removeGroup(groupName); + } + + void testSortWorkspacesByNameAscending() { + using SortCriteria = IWorkspaceDockView::SortCriteria; + using SortDir = IWorkspaceDockView::SortDirection; + ::testing::DefaultValue<SortCriteria>::Set(SortCriteria::ByName); + ::testing::DefaultValue<SortDir>::Set(SortDir::Ascending); + + EXPECT_CALL(*mockView.get(), getSortCriteria()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), getSortDirection()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), + sortWorkspaces(SortCriteria::ByName, SortDir::Ascending)) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::SortWorkspaces); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testSortWorkspacesByNameDescending() { + using SortCriteria = IWorkspaceDockView::SortCriteria; + using SortDir = IWorkspaceDockView::SortDirection; + ::testing::DefaultValue<SortCriteria>::Set(SortCriteria::ByName); + ::testing::DefaultValue<SortDir>::Set(SortDir::Descending); + + EXPECT_CALL(*mockView.get(), getSortCriteria()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), getSortDirection()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), + sortWorkspaces(SortCriteria::ByName, SortDir::Descending)) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::SortWorkspaces); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testSortWorkspacesByLastModifiedAscending() { + using SortCriteria = IWorkspaceDockView::SortCriteria; + using SortDir = IWorkspaceDockView::SortDirection; + ::testing::DefaultValue<SortCriteria>::Set(SortCriteria::ByLastModified); + ::testing::DefaultValue<SortDir>::Set(SortDir::Ascending); + + EXPECT_CALL(*mockView.get(), getSortCriteria()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), getSortDirection()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), sortWorkspaces(SortCriteria::ByLastModified, + SortDir::Ascending)) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::SortWorkspaces); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testSortWorkspacesByLastModifiedDescending() { + using SortCriteria = IWorkspaceDockView::SortCriteria; + using SortDir = IWorkspaceDockView::SortDirection; + ::testing::DefaultValue<SortCriteria>::Set(SortCriteria::ByLastModified); + ::testing::DefaultValue<SortDir>::Set(SortDir::Descending); + + EXPECT_CALL(*mockView.get(), getSortCriteria()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), getSortDirection()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), sortWorkspaces(SortCriteria::ByLastModified, + SortDir::Descending)) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::SortWorkspaces); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testSaveSingleWorkspaceNexus() { + using SaveFileType = IWorkspaceDockView::SaveFileType; + ::testing::DefaultValue<SaveFileType>::Set(SaveFileType::Nexus); + + EXPECT_CALL(*mockView.get(), getSaveFileType()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), saveWorkspace(SaveFileType::Nexus)) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::SaveSingleWorkspace); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testSaveSingleWorkspaceASCIIv1() { + using SaveFileType = IWorkspaceDockView::SaveFileType; + ::testing::DefaultValue<SaveFileType>::Set(SaveFileType::ASCIIv1); + + EXPECT_CALL(*mockView.get(), getSaveFileType()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), saveWorkspace(SaveFileType::ASCIIv1)) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::SaveSingleWorkspace); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testSaveSingleWorkspaceASCII() { + using SaveFileType = IWorkspaceDockView::SaveFileType; + ::testing::DefaultValue<SaveFileType>::Set(SaveFileType::ASCII); + + EXPECT_CALL(*mockView.get(), getSaveFileType()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), saveWorkspace(SaveFileType::ASCII)) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::SaveSingleWorkspace); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testSaveWorkspaceCollection() { + ::testing::DefaultValue<StringList>::Set(StringList{"ws1", "ws2"}); + EXPECT_CALL(*mockView.get(), getSelectedWorkspaceNames()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), saveWorkspaces(StringList{"ws1", "ws2"})) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::SaveWorkspaceCollection); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testFilterWorkspaces() { + ::testing::DefaultValue<std::string>::Set(std::string()); + EXPECT_CALL(*mockView.get(), getFilterText()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), filterWorkspaces(std::string())) + .Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::FilterWorkspaces); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testRefreshWorkspaces() { + EXPECT_CALL(*mockView.get(), updateTree(_)).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::RefreshWorkspaces); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + // Popup Context Menu Tests + void testShowPopupMenu() { + EXPECT_CALL(*mockView.get(), popupContextMenu()).Times(Exactly(1)); + presenter->notifyFromView( + ViewNotifiable::Flag::PopulateAndShowWorkspaceContextMenu); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowWorkspaceData() { + EXPECT_CALL(*mockView.get(), showWorkspaceData()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowWorkspaceData); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowInstrumentView() { + EXPECT_CALL(*mockView.get(), showInstrumentView()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowInstrumentView); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testSaveToProgram() { + EXPECT_CALL(*mockView.get(), saveToProgram()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::SaveToProgram); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testPlotSpectrum() { + EXPECT_CALL(*mockView.get(), plotSpectrum(false)).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::PlotSpectrum); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testPlotSpectrumWithErrors() { + EXPECT_CALL(*mockView.get(), plotSpectrum(true)).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::PlotSpectrumWithErrors); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowColourFillPlot() { + EXPECT_CALL(*mockView.get(), showColourFillPlot()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowColourFillPlot); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowDetectorsTable() { + EXPECT_CALL(*mockView.get(), showDetectorsTable()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowDetectorsTable); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowBoxDataTable() { + EXPECT_CALL(*mockView.get(), showBoxDataTable()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowBoxDataTable); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowVatesGUI() { + EXPECT_CALL(*mockView.get(), showVatesGUI()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowVatesGUI); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowMDPlot() { + EXPECT_CALL(*mockView.get(), showMDPlot()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowMDPlot); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowListData() { + EXPECT_CALL(*mockView.get(), showListData()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowListData); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowSpectrumViewer() { + EXPECT_CALL(*mockView.get(), showSpectrumViewer()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowSpectrumViewer); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowSliceViewer() { + EXPECT_CALL(*mockView.get(), showSliceViewer()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowSliceViewer); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowLogs() { + EXPECT_CALL(*mockView.get(), showLogs()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowLogs); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowSampleMaterialWindow() { + EXPECT_CALL(*mockView.get(), showSampleMaterialWindow()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowSampleMaterialWindow); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowAlgorithmHistory() { + EXPECT_CALL(*mockView.get(), showAlgorithmHistory()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowAlgorithmHistory); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowTransposed() { + EXPECT_CALL(*mockView.get(), showTransposed()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowTransposed); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testConvertToMatrixWorkspace() { + EXPECT_CALL(*mockView.get(), convertToMatrixWorkspace()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ConvertToMatrixWorkspace); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testConvertMDHistoToMatrixWorkspace() { + EXPECT_CALL(*mockView.get(), convertMDHistoToMatrixWorkspace()) + .Times(Exactly(1)); + presenter->notifyFromView( + ViewNotifiable::Flag::ConvertMDHistoToMatrixWorkspace); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testClearUBMatrix() { + ::testing::DefaultValue<StringList>::Set(StringList{"ws1"}); + auto ws1 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + AnalysisDataService::Instance().add("ws1", ws1); + + // Setup a UB matrix before attempting to remove it + auto setUB = Mantid::API::AlgorithmManager::Instance().create("SetUB"); + setUB->initialize(); + setUB->setProperty("Workspace", "ws1"); + setUB->execute(); + + EXPECT_CALL(*mockView.get(), getSelectedWorkspaceNames()).Times(Exactly(1)); + EXPECT_CALL(*mockView.get(), executeAlgorithmAsync(_, _)).Times(Exactly(1)); + + presenter->notifyFromView(ViewNotifiable::Flag::ClearUBMatrix); + + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + AnalysisDataService::Instance().remove("ws1"); + } + + void testShowSurfacePlot() { + EXPECT_CALL(*mockView.get(), showSurfacePlot()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowSurfacePlot); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + + void testShowContourPlot() { + EXPECT_CALL(*mockView.get(), showContourPlot()).Times(Exactly(1)); + presenter->notifyFromView(ViewNotifiable::Flag::ShowContourPlot); + TS_ASSERT(Mock::VerifyAndClearExpectations(&mockView)); + } + +private: + boost::shared_ptr<NiceMock<MockWorkspaceDockView>> mockView; + WorkspacePresenterVN_sptr presenter; + + void createGroup(std::string groupName) { + auto group = + WorkspaceCreationHelper::CreateWorkspaceGroup(0, 10, 10, groupName); + auto wksp1 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + auto wksp2 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); + + AnalysisDataService::Instance().add("wksp1", wksp1); + AnalysisDataService::Instance().add("wksp2", wksp2); + AnalysisDataService::Instance().addToGroup(groupName, "wksp1"); + AnalysisDataService::Instance().addToGroup(groupName, "wksp2"); + } + + void removeGroup(std::string groupName) { + AnalysisDataService::Instance().deepRemoveGroup(groupName); + } +}; \ No newline at end of file diff --git a/MantidQt/Python/mantidqt.sip b/MantidQt/Python/mantidqt.sip index 0e0ab6ff43c8061464015bb54c9d76f69f0034f3..fc5742a3eb07377e0c3c092aaea7e22381d7851f 100644 --- a/MantidQt/Python/mantidqt.sip +++ b/MantidQt/Python/mantidqt.sip @@ -84,6 +84,33 @@ namespace GraphOptions enum ScaleType {Linear, Log10}; enum Axis{Left, Right, Bottom, Top}; + + enum CurveType { + Line, + Scatter, + LineSymbols, + VerticalBars, + Area, + Pie, + VerticalDropLines, + Spline, + HorizontalSteps, + Histogram, + HorizontalBars, + VectXYXY, + ErrorBars, + Box, + VectXYAM, + VerticalSteps, + ColorMap, + GrayScale, + ColorMapContour, + Contour, + Function, + ImagePlot, + User +}; + }; namespace Mantid