From 9d2e689e517bc4e0116b9e82e59a687e85d8a6f1 Mon Sep 17 00:00:00 2001 From: Samuel Jackson <samueljackson@outlook.com> Date: Mon, 11 Jul 2016 10:15:15 +0100 Subject: [PATCH] Refs #16768 Make WindowFactory class Also make all subwindows conform to IProjectSerialiseable interface. --- MantidPlot/CMakeLists.txt | 2 + MantidPlot/src/Graph3D.h | 2 +- .../InstrumentWidget/InstrumentWindow.h | 3 +- MantidPlot/src/Mantid/MantidMatrix.h | 4 +- MantidPlot/src/Matrix.h | 3 +- MantidPlot/src/MdiSubWindow.cpp | 14 ++++ MantidPlot/src/MdiSubWindow.h | 9 ++- MantidPlot/src/MultiLayer.h | 2 +- MantidPlot/src/Note.h | 2 +- MantidPlot/src/ProjectSerialiser.cpp | 1 + MantidPlot/src/Table.h | 3 +- MantidPlot/src/WindowFactory.cpp | 8 +++ MantidPlot/src/WindowFactory.h | 67 +++++++++++++++++++ 13 files changed, 107 insertions(+), 13 deletions(-) create mode 100644 MantidPlot/src/WindowFactory.cpp create mode 100644 MantidPlot/src/WindowFactory.h diff --git a/MantidPlot/CMakeLists.txt b/MantidPlot/CMakeLists.txt index 4f616470ce3..10cca32934b 100644 --- a/MantidPlot/CMakeLists.txt +++ b/MantidPlot/CMakeLists.txt @@ -134,6 +134,7 @@ set ( QTIPLOT_SRCS src/ApplicationWindow.cpp src/TSVSerialiser.cpp src/UserFunction.cpp src/VectorCurve.cpp + src/WindowFactory.cpp src/origin/OPJFile.cpp src/plot2D/ImageSymbol.cpp src/analysis/fft2D.cpp @@ -335,6 +336,7 @@ set ( QTIPLOT_HDRS src/ApplicationWindow.h src/TSVSerialiser.h src/UserFunction.h src/VectorCurve.h + src/WindowFactory.h src/analysis/fft2D.h src/origin/OPJFile.h src/plot2D/ImageSymbol.h diff --git a/MantidPlot/src/Graph3D.h b/MantidPlot/src/Graph3D.h index f16fa32ea3c..71da00caaf8 100644 --- a/MantidPlot/src/Graph3D.h +++ b/MantidPlot/src/Graph3D.h @@ -60,7 +60,7 @@ class Function2D; // Mantid *directly to a file, so they * can't be combined with output generated via QPrinter. */ -class Graph3D : public MdiSubWindow, public Mantid::IProjectSerialisable { +class Graph3D : public MdiSubWindow { Q_OBJECT public: diff --git a/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.h b/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.h index 51580e7aea3..5a9a81fb51d 100644 --- a/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.h +++ b/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.h @@ -17,8 +17,7 @@ class InstrumentWidgetTab; } } -class InstrumentWindow : public MdiSubWindow, - public Mantid::IProjectSerialisable { +class InstrumentWindow : public MdiSubWindow { Q_OBJECT public: explicit InstrumentWindow(const QString &wsName, diff --git a/MantidPlot/src/Mantid/MantidMatrix.h b/MantidPlot/src/Mantid/MantidMatrix.h index ce5d6c13c16..19b8c7eed8a 100644 --- a/MantidPlot/src/Mantid/MantidMatrix.h +++ b/MantidPlot/src/Mantid/MantidMatrix.h @@ -9,7 +9,6 @@ #include "MantidMatrixModel.h" #include "MantidMatrixTabExtension.h" -#include "Mantid/IProjectSerialisable.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/FrameworkManager.h" #include "MantidAPI/MatrixWorkspace_fwd.h" @@ -84,8 +83,7 @@ Code Documentation is available at: <http://doxygen.mantidproject.org> */ class MantidMatrix : public MdiSubWindow, - MantidQt::API::WorkspaceObserver, - public Mantid::IProjectSerialisable { + MantidQt::API::WorkspaceObserver { Q_OBJECT public: diff --git a/MantidPlot/src/Matrix.h b/MantidPlot/src/Matrix.h index 2b7c69c300f..b69e3cbebe4 100644 --- a/MantidPlot/src/Matrix.h +++ b/MantidPlot/src/Matrix.h @@ -62,8 +62,7 @@ class QUndoStack; //! Matrix worksheet class class Matrix : public MdiSubWindow, - public Scripted, - public Mantid::IProjectSerialisable { + public Scripted { Q_OBJECT protected: diff --git a/MantidPlot/src/MdiSubWindow.cpp b/MantidPlot/src/MdiSubWindow.cpp index 0767cfb722a..00e210a68cb 100644 --- a/MantidPlot/src/MdiSubWindow.cpp +++ b/MantidPlot/src/MdiSubWindow.cpp @@ -117,6 +117,20 @@ void MdiSubWindow::setLabel(const QString &label) { d_label = label; } +void MdiSubWindow::loadFromProject(const std::string &lines, ApplicationWindow *app, const int fileVersion) +{ + Q_UNUSED(lines); + Q_UNUSED(app); + Q_UNUSED(fileVersion); + throw std::runtime_error("LoadToProject not implemented for raw MdiSubWindow"); +} + +std::string MdiSubWindow::saveToProject(ApplicationWindow *app) +{ + Q_UNUSED(app); + throw std::runtime_error("SaveToProject not implemented for raw MdiSubWindow"); +} + void MdiSubWindow::resizeEvent(QResizeEvent *e) { emit resizedWindow(this); MdiSubWindowParent_t::resizeEvent(e); diff --git a/MantidPlot/src/MdiSubWindow.h b/MantidPlot/src/MdiSubWindow.h index 7bdfcae880b..7189fbc7a97 100644 --- a/MantidPlot/src/MdiSubWindow.h +++ b/MantidPlot/src/MdiSubWindow.h @@ -29,6 +29,7 @@ #ifndef MdiSubWindow_H #define MdiSubWindow_H +#include "Mantid/IProjectSerialisable.h" #include <QMdiSubWindow> #include <QDockWidget> #include <QVBoxLayout> @@ -108,7 +109,8 @@ protected: * * \sa Folder, ApplicationWindow */ -class MdiSubWindow : public MdiSubWindowParent_t { +class MdiSubWindow : public MdiSubWindowParent_t, + public Mantid::IProjectSerialisable { Q_OBJECT public: @@ -271,6 +273,11 @@ public: // non-slot methods ///@} /// Set the label property on the widget void setLabel(const QString &label); + /// Loads the given lines from the project file and applies them. + void loadFromProject(const std::string &lines, ApplicationWindow *app, + const int fileVersion) override; + /// Serialises to a string that can be saved to a project file. + std::string saveToProject(ApplicationWindow *app) override; signals: //! Emitted when the window was closed void closedWindow(MdiSubWindow *); diff --git a/MantidPlot/src/MultiLayer.h b/MantidPlot/src/MultiLayer.h index 109d6f94b70..509567f6fb3 100644 --- a/MantidPlot/src/MultiLayer.h +++ b/MantidPlot/src/MultiLayer.h @@ -72,7 +72,7 @@ class WaterfallFillDialog; *could handle things like creating * tables by calling methods of Project instead of sending signals. */ -class MultiLayer : public MdiSubWindow, public Mantid::IProjectSerialisable { +class MultiLayer : public MdiSubWindow { Q_OBJECT public: diff --git a/MantidPlot/src/Note.h b/MantidPlot/src/Note.h index 0c476ca05a9..6bb569c8eca 100644 --- a/MantidPlot/src/Note.h +++ b/MantidPlot/src/Note.h @@ -41,7 +41,7 @@ class ApplicationWindow; * \section future Future Plans * - Search and replace */ -class Note : public MdiSubWindow, public Mantid::IProjectSerialisable { +class Note : public MdiSubWindow { Q_OBJECT public: diff --git a/MantidPlot/src/ProjectSerialiser.cpp b/MantidPlot/src/ProjectSerialiser.cpp index 60b0afd3635..c76821d1635 100644 --- a/MantidPlot/src/ProjectSerialiser.cpp +++ b/MantidPlot/src/ProjectSerialiser.cpp @@ -8,6 +8,7 @@ #include "TableStatistics.h" #include "Graph3D.h" +#include "WindowFactory.h" #include "Mantid/MantidMatrix.h" #include "Mantid/MantidUI.h" #include "MantidAPI/MatrixWorkspace.h" diff --git a/MantidPlot/src/Table.h b/MantidPlot/src/Table.h index 6a4d8c795c8..59af062b911 100644 --- a/MantidPlot/src/Table.h +++ b/MantidPlot/src/Table.h @@ -88,8 +88,7 @@ private: * [ assigned to thzs ] */ class Table : public MdiSubWindow, - public Scripted, - public Mantid::IProjectSerialisable { + public Scripted { Q_OBJECT public: diff --git a/MantidPlot/src/WindowFactory.cpp b/MantidPlot/src/WindowFactory.cpp new file mode 100644 index 00000000000..ba8cc21dd63 --- /dev/null +++ b/MantidPlot/src/WindowFactory.cpp @@ -0,0 +1,8 @@ +#include "WindowFactory.h" + +using namespace Mantid::API; + +WindowFactoryImpl::WindowFactoryImpl() +{ + +} diff --git a/MantidPlot/src/WindowFactory.h b/MantidPlot/src/WindowFactory.h new file mode 100644 index 00000000000..2cc0776b545 --- /dev/null +++ b/MantidPlot/src/WindowFactory.h @@ -0,0 +1,67 @@ +#ifndef WINDOWFACTORY_H +#define WINDOWFACTORY_H + +//---------------------------------------------------------------------- +// Includes +//---------------------------------------------------------------------- +#include "MantidAPI/DllConfig.h" +#include "MantidKernel/DynamicFactory.h" +#include "MantidKernel/SingletonHolder.h" + +//---------------------------------------------------------------------- +// Forward declarations +//---------------------------------------------------------------------- +class MdiSubWindow; + +namespace Mantid { +namespace API { + +/** The WindowFactory class is in charge of the creation of concrete + instances of MdiSubWindow. It inherits most of its implementation from + the Dynamic Factory base class. + It is implemented as a singleton class. + + @author Samuel Jackson, ISIS Rutherford Appleton Laboratory + @date 11/07/2016 + + Copyright © 2007-2011 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 MANTID_API_DLL WindowFactoryImpl final : public Kernel::DynamicFactory<MdiSubWindow> { +public: + WindowFactoryImpl(); +}; + +/// Forward declaration of a specialisation of SingletonHolder for +/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. +#ifdef _WIN32 +// this breaks new namespace declaraion rules; need to find a better fix +template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<WindowFactoryImpl>; +#endif /* _WIN32 */ + +typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<WindowFactoryImpl> + WindowFactory; + +} +} + +#endif // WINDOWFACTORY_H -- GitLab