Commit 679610c7 authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Refs #16962 Refactoring and updating documentation

parent ec4a1027
...@@ -40,61 +40,68 @@ InstrumentWindow::InstrumentWindow(const QString &wsName, const QString &label, ...@@ -40,61 +40,68 @@ InstrumentWindow::InstrumentWindow(const QString &wsName, const QString &label,
InstrumentWindow::~InstrumentWindow() {} InstrumentWindow::~InstrumentWindow() {}
/**
* Load instrument window state from a Mantid project file
* @param lines :: lines from the project file to load state from
* @return handle to the created instrument window
*/
IProjectSerialisable *InstrumentWindow::loadFromProject( IProjectSerialisable *InstrumentWindow::loadFromProject(
const std::string &lines, ApplicationWindow *app, const int fileVersion) { const std::string &lines, ApplicationWindow *app, const int fileVersion) {
Q_UNUSED(fileVersion); Q_UNUSED(fileVersion);
TSVSerialiser tsv(lines); TSVSerialiser tsv(lines);
if (tsv.selectLine("WorkspaceName")) {
std::string wsName = tsv.asString(1);
QString name = QString::fromStdString(wsName);
if (!Mantid::API::AnalysisDataService::Instance().doesExist(wsName))
return nullptr;
MatrixWorkspace_const_sptr ws =
boost::dynamic_pointer_cast<const MatrixWorkspace>(
app->mantidUI->getWorkspace(QString::fromStdString(wsName)));
if (!ws)
return nullptr;
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
Mantid::Geometry::Instrument_const_sptr instr = ws->getInstrument();
if (!instr || instr->getName().empty()) {
QApplication::restoreOverrideCursor();
QMessageBox::critical(app, "MantidPlot - Error",
"Instrument view cannot be opened");
return nullptr;
}
// Need a new window if (!tsv.selectLine("WorkspaceName"))
const QString windowName(QString("InstrumentWindow:") + return nullptr;
QString::fromStdString(wsName));
auto iw = const auto name = tsv.asQString(1);
new InstrumentWindow(name, QString("Instrument"), app, windowName); const auto workspace = app->mantidUI->getWorkspace(name);
const auto ws = boost::dynamic_pointer_cast<const MatrixWorkspace>(workspace);
try {
if (tsv.hasLine("geometry")) { if (!ws)
const QString geometry = return nullptr;
QString::fromStdString(tsv.lineAsString("geometry"));
app->restoreWindowGeometry(app, iw, geometry); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
}
auto instr = ws->getInstrument();
iw->m_instrumentWidget->loadFromProject(lines); if (!instr || instr->getName().empty()) {
app->addMdiSubWindow(iw); QApplication::restoreOverrideCursor();
QMessageBox::critical(app, "MantidPlot - Error",
QApplication::restoreOverrideCursor(); "Instrument view cannot be opened");
return iw; return nullptr;
} catch (const std::exception &e) { }
QApplication::restoreOverrideCursor();
QString errorMessage = // Create a new window
"Instrument view cannot be created:\n\n" + QString(e.what()); const QString windowName("InstrumentWindow:" + name);
QMessageBox::critical(app, "MantidPlot - Error", errorMessage); auto iw = new InstrumentWindow(name, "Instrument", app, windowName);
// Populate window properties
try {
if (tsv.hasLine("geometry")) {
const auto geometry = tsv.lineAsQString("geometry");
app->restoreWindowGeometry(app, iw, geometry);
} }
iw->m_instrumentWidget->loadFromProject(lines);
app->addMdiSubWindow(iw);
QApplication::restoreOverrideCursor();
return iw;
} catch (const std::exception &e) {
QApplication::restoreOverrideCursor();
QString errorMessage =
"Instrument view cannot be created:\n\n" + QString(e.what());
QMessageBox::critical(app, "MantidPlot - Error", errorMessage);
} }
return nullptr; return nullptr;
} }
/**
* Save the state of the instrument window to a Mantid project file
* @param app :: handle to the current application window instance
* @return a string representing the state of the instrument window
*/
std::string InstrumentWindow::saveToProject(ApplicationWindow *app) { std::string InstrumentWindow::saveToProject(ApplicationWindow *app) {
TSVSerialiser tsv, window; TSVSerialiser tsv, window;
window.writeRaw(app->windowGeometryInfo(this)); window.writeRaw(app->windowGeometryInfo(this));
......
...@@ -28,9 +28,11 @@ public: ...@@ -28,9 +28,11 @@ public:
const QString &name = QString()); const QString &name = QString());
~InstrumentWindow() override; ~InstrumentWindow() override;
/// Load the state of the instrument window for a Mantid project file
static IProjectSerialisable *loadFromProject(const std::string &lines, static IProjectSerialisable *loadFromProject(const std::string &lines,
ApplicationWindow *app, ApplicationWindow *app,
const int fileVersion); const int fileVersion);
/// Save the state of the instrument window to a Mantid project file
std::string saveToProject(ApplicationWindow *app) override; std::string saveToProject(ApplicationWindow *app) override;
void selectTab(int tab); void selectTab(int tab);
MantidQt::MantidWidgets::InstrumentWidgetTab * MantidQt::MantidWidgets::InstrumentWidgetTab *
......
...@@ -57,6 +57,7 @@ public: ...@@ -57,6 +57,7 @@ public:
std::vector<std::string> sections(const std::string &name) const; std::vector<std::string> sections(const std::string &name) const;
std::string lineAsString(const std::string &name, const size_t i = 0) const; std::string lineAsString(const std::string &name, const size_t i = 0) const;
QString lineAsQString(const std::string &name, const size_t i = 0) const;
bool selectLine(const std::string &name, const size_t i = 0); bool selectLine(const std::string &name, const size_t i = 0);
bool selectSection(const std::string &name, const size_t i = 0); bool selectSection(const std::string &name, const size_t i = 0);
...@@ -66,6 +67,7 @@ public: ...@@ -66,6 +67,7 @@ public:
double asDouble(const size_t i) const; double asDouble(const size_t i) const;
float asFloat(const size_t i) const; float asFloat(const size_t i) const;
std::string asString(const size_t i) const; std::string asString(const size_t i) const;
QString asQString(const size_t i) const;
bool asBool(const size_t i) const; bool asBool(const size_t i) const;
QRect asQRect(const size_t i) const; QRect asQRect(const size_t i) const;
QColor asQColor(const size_t i) const; QColor asQColor(const size_t i) const;
......
...@@ -149,6 +149,11 @@ std::string TSVSerialiser::lineAsString(const std::string &name, ...@@ -149,6 +149,11 @@ std::string TSVSerialiser::lineAsString(const std::string &name,
return lines[i]; return lines[i];
} }
QString TSVSerialiser::lineAsQString(const std::string &name,
const size_t i) const {
return QString::fromStdString(lineAsString(name, i));
}
bool TSVSerialiser::selectLine(const std::string &name, const size_t i) { bool TSVSerialiser::selectLine(const std::string &name, const size_t i) {
if (!hasLine(name)) if (!hasLine(name))
return false; return false;
...@@ -278,6 +283,13 @@ std::string TSVSerialiser::asString(const size_t i) const { ...@@ -278,6 +283,13 @@ std::string TSVSerialiser::asString(const size_t i) const {
return m_curValues.at(i); return m_curValues.at(i);
} }
QString TSVSerialiser::asQString(const size_t i) const {
if (i >= m_curValues.size())
return "";
return QString::fromStdString(m_curValues.at(i));
}
TSVSerialiser &TSVSerialiser::operator>>(int &val) { TSVSerialiser &TSVSerialiser::operator>>(int &val) {
val = asInt(m_curIndex++); val = asInt(m_curIndex++);
return *this; return *this;
......
...@@ -83,9 +83,9 @@ public: ...@@ -83,9 +83,9 @@ public:
bool addToDisplayContextMenu(QMenu &) const override; bool addToDisplayContextMenu(QMenu &) const override;
void selectTool(const ToolType tool); void selectTool(const ToolType tool);
boost::shared_ptr<ProjectionSurface> getSurface() const; boost::shared_ptr<ProjectionSurface> getSurface() const;
/// Load settings for the widget tab from a project file /// Load settings for the pick tab from a project file
virtual void loadFromProject(const std::string &lines) override; virtual void loadFromProject(const std::string &lines) override;
/// Save settings for the widget tab to a project file /// Save settings for the pick tab to a project file
virtual std::string saveToProject() const override; virtual std::string saveToProject() const override;
public slots: public slots:
......
...@@ -38,9 +38,9 @@ public: ...@@ -38,9 +38,9 @@ public:
virtual bool addToDisplayContextMenu(QMenu &) const { return false; } virtual bool addToDisplayContextMenu(QMenu &) const { return false; }
/// Get the projection surface /// Get the projection surface
boost::shared_ptr<ProjectionSurface> getSurface() const; boost::shared_ptr<ProjectionSurface> getSurface() const;
/// Load settings for the widget tab from a project file /// Load state for the widget tab from a project file
virtual void loadFromProject(const std::string &lines) = 0; virtual void loadFromProject(const std::string &lines) = 0;
/// Save settings for the widget tab to a project file /// Save state for the widget tab to a project file
virtual std::string saveToProject() const = 0; virtual std::string saveToProject() const = 0;
protected: protected:
......
...@@ -19,10 +19,10 @@ class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS InstrumentWidgetTreeTab ...@@ -19,10 +19,10 @@ class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS InstrumentWidgetTreeTab
public: public:
explicit InstrumentWidgetTreeTab(InstrumentWidget *instrWidget); explicit InstrumentWidgetTreeTab(InstrumentWidget *instrWidget);
void initSurface() override; void initSurface() override;
/// Load settings for the widget tab from a project file /// Load settings for the tree widget tab from a project file
virtual void loadFromProject(const std::string &lines) override; virtual void loadFromProject(const std::string &lines) override;
; ;
/// Save settings for the widget tab to a project file /// Save settings for the tree widget tab to a project file
virtual std::string saveToProject() const override; virtual std::string saveToProject() const override;
; ;
public slots: public slots:
......
...@@ -44,9 +44,9 @@ public: ...@@ -44,9 +44,9 @@ public:
void getMaskedDetectors(QList<int> &dets) const override; void getMaskedDetectors(QList<int> &dets) const override;
void resize(int, int) override; void resize(int, int) override;
QString getInfoText() const override; QString getInfoText() const override;
/// Load settings for the widget tab from a project file /// Load settings for the 3D projection from a project file
virtual void loadFromProject(const std::string &lines) override; virtual void loadFromProject(const std::string &lines) override;
/// Save settings for the widget tab to a project file /// Save settings for the 3D projection to a project file
virtual std::string saveToProject() const override; virtual std::string saveToProject() const override;
signals: signals:
......
...@@ -136,9 +136,9 @@ public: ...@@ -136,9 +136,9 @@ public:
void requestRedraw(bool resetPeakVisibility = false); void requestRedraw(bool resetPeakVisibility = false);
/// Enable lighting if the implementation allows it /// Enable lighting if the implementation allows it
void enableLighting(bool on); void enableLighting(bool on);
/// Load settings for the widget tab from a project file /// Load settings for the projection surface from a project file
virtual void loadFromProject(const std::string &lines); virtual void loadFromProject(const std::string &lines);
/// Save settings for the widget tab to a project file /// Save settings for the projection surface to a project file
virtual std::string saveToProject() const; virtual std::string saveToProject() const;
//----------------------------------- //-----------------------------------
......
...@@ -180,9 +180,9 @@ protected: ...@@ -180,9 +180,9 @@ protected:
bool m_visible; ///< flag to show or hide the shape bool m_visible; ///< flag to show or hide the shape
private: private:
static Shape2D* loadShape2DRectangle(const std::string &lines); /// Instantiate specifc shapes from a type string
static Shape2D* loadShape2DRing(const std::string &lines); static Shape2D *loadShape2DFromType(const std::string &type,
static Shape2D* loadShape2DFree(const std::string &lines); const std::string &lines);
}; };
/** /**
...@@ -207,9 +207,9 @@ public: ...@@ -207,9 +207,9 @@ public:
QStringList getPointNames() const override { return QStringList("center"); } QStringList getPointNames() const override { return QStringList("center"); }
QPointF getPoint(const QString &prop) const override; QPointF getPoint(const QString &prop) const override;
void setPoint(const QString &prop, const QPointF &value) override; void setPoint(const QString &prop, const QPointF &value) override;
/// Load settings for the shape from a project file /// Load state for the shape from a project file
static Shape2D* loadFromProject(const std::string &lines); static Shape2D* loadFromProject(const std::string &lines);
/// Save settings for the widget tab to a project file /// Save state for the shape to a project file
virtual std::string saveToProject() const override; virtual std::string saveToProject() const override;
protected: protected:
...@@ -233,9 +233,9 @@ public: ...@@ -233,9 +233,9 @@ public:
return m_boundingRect.contains(p); return m_boundingRect.contains(p);
} }
void addToPath(QPainterPath &path) const override; void addToPath(QPainterPath &path) const override;
/// Load settings for the shape from a project file /// Load state for the shape from a project file
static Shape2D* loadFromProject(const std::string &lines); static Shape2D* loadFromProject(const std::string &lines);
/// Save settings for the widget tab to a project file /// Save state for the shape to a project file
virtual std::string saveToProject() const override; virtual std::string saveToProject() const override;
protected: protected:
...@@ -269,9 +269,9 @@ public: ...@@ -269,9 +269,9 @@ public:
void setColor(const QColor &color) override; void setColor(const QColor &color) override;
QColor getColor() const override { return m_outer_shape->getColor(); } QColor getColor() const override { return m_outer_shape->getColor(); }
const Shape2D *getOuterShape() const { return m_outer_shape; } const Shape2D *getOuterShape() const { return m_outer_shape; }
/// Load settings for the shape from a project file /// Load state for the shape from a project file
static Shape2D* loadFromProject(const std::string &lines); static Shape2D* loadFromProject(const std::string &lines);
/// Save settings for the widget tab to a project file /// Save state for the shape to a project file
virtual std::string saveToProject() const override; virtual std::string saveToProject() const override;
protected: protected:
...@@ -304,9 +304,9 @@ public: ...@@ -304,9 +304,9 @@ public:
void addToPath(QPainterPath &path) const override; void addToPath(QPainterPath &path) const override;
void addPolygon(const QPolygonF &polygon); void addPolygon(const QPolygonF &polygon);
void subtractPolygon(const QPolygonF &polygon); void subtractPolygon(const QPolygonF &polygon);
/// Load settings for the shape from a project file /// Load state for the shape from a project file
static Shape2D* loadFromProject(const std::string &lines); static Shape2D* loadFromProject(const std::string &lines);
/// Save settings for the widget tab to a project file /// Save state for the shape to a project file
virtual std::string saveToProject() const override; virtual std::string saveToProject() const override;
protected: protected:
......
...@@ -85,9 +85,9 @@ public: ...@@ -85,9 +85,9 @@ public:
/// Change border color of all shapes. /// Change border color of all shapes.
void changeBorderColor(const QColor &color); void changeBorderColor(const QColor &color);
/// Load settings for the widget tab from a project file /// Load settings for the shape 2D collection from a project file
virtual void loadFromProject(const std::string &lines); virtual void loadFromProject(const std::string &lines);
/// Save settings for the widget tab to a project file /// Save settings for the shape 2D collection to a project file
virtual std::string saveToProject() const override; virtual std::string saveToProject() const override;
signals: signals:
......
...@@ -123,9 +123,9 @@ public: ...@@ -123,9 +123,9 @@ public:
/// Zoom into an area of the screen /// Zoom into an area of the screen
void zoom(const QRectF &area); void zoom(const QRectF &area);
//@} //@}
/// Load settings for the widget tab from a project file /// Load settings for the unwrapped surface from a project file
virtual void loadFromProject(const std::string &lines) override; virtual void loadFromProject(const std::string &lines) override;
/// Save settings for the widget tab to a project file /// Save settings for the unwrapped surface to a project file
virtual std::string saveToProject() const override; virtual std::string saveToProject() const override;
/// Get a handle to a peaks workspace from a name /// Get a handle to a peaks workspace from a name
boost::shared_ptr<Mantid::API::IPeaksWorkspace> boost::shared_ptr<Mantid::API::IPeaksWorkspace>
......
...@@ -36,23 +36,23 @@ ...@@ -36,23 +36,23 @@
#endif #endif
#endif #endif
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPushButton>
#include <QRadioButton>
#include <QTextEdit>
#include <QMenu>
#include <QAction> #include <QAction>
#include <QLabel>
#include <QMessageBox>
#include <QApplication> #include <QApplication>
#include <QCheckBox>
#include <QFileDialog> #include <QFileDialog>
#include <QToolTip> #include <QGridLayout>
#include <QTemporaryFile>
#include <QGroupBox> #include <QGroupBox>
#include <QCheckBox> #include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QRadioButton>
#include <QSettings> #include <QSettings>
#include <QTemporaryFile>
#include <QTextEdit>
#include <QToolTip>
#include <QVBoxLayout>
#include "MantidQtAPI/FileDialogHandler.h" #include "MantidQtAPI/FileDialogHandler.h"
...@@ -1182,46 +1182,46 @@ void InstrumentWidgetMaskTab::changedIntegrationRange(double, double) { ...@@ -1182,46 +1182,46 @@ void InstrumentWidgetMaskTab::changedIntegrationRange(double, double) {
enableApplyButtons(); enableApplyButtons();
} }
/** Load mask tab settings from a Mantid project file /** Load mask tab state from a Mantid project file
*
* @param lines :: lines from the project file to load state from * @param lines :: lines from the project file to load state from
*/ */
void InstrumentWidgetMaskTab::loadFromProject(const std::string &lines) { void InstrumentWidgetMaskTab::loadFromProject(const std::string &lines) {
TSVSerialiser tsv(lines); TSVSerialiser tsv(lines);
if (tsv.selectSection("masktab")) { if (!tsv.selectSection("masktab"))
std::string tabLines; return;
tsv >> tabLines;
TSVSerialiser tab(tabLines);
std::vector<QPushButton *> buttons{ std::string tabLines;
m_move, m_pointer, m_ellipse, m_rectangle, tsv >> tabLines;
m_ring_ellipse, m_ring_rectangle, m_free_draw}; TSVSerialiser tab(tabLines);
tab.selectLine("ActiveTools"); std::vector<QPushButton *> buttons{
for (auto button : buttons) { m_move, m_pointer, m_ellipse, m_rectangle,
bool value; m_ring_ellipse, m_ring_rectangle, m_free_draw};
tab >> value;
button->setChecked(value);
}
std::vector<QRadioButton *> typeButtons{m_masking_on, m_grouping_on, tab.selectLine("ActiveTools");
m_roi_on}; for (auto button : buttons) {
bool value;
tab >> value;
button->setChecked(value);
}
tab.selectLine("ActiveType"); std::vector<QRadioButton *> typeButtons{m_masking_on, m_grouping_on,
for (auto type : typeButtons) { m_roi_on};
bool value;
tab >> value;
type->setChecked(value);
}
if (tab.selectLine("MaskViewWorkspace")) { tab.selectLine("ActiveType");
// the view was masked. We should load reapply this from a cached for (auto type : typeButtons) {
// workspace in the project folder bool value;
std::string maskWSName; tab >> value;
tab >> maskWSName; type->setChecked(value);
loadMaskViewFromProject(maskWSName); }
}
if (tab.selectLine("MaskViewWorkspace")) {
// the view was masked. We should load reapply this from a cached
// workspace in the project folder
std::string maskWSName;
tab >> maskWSName;
loadMaskViewFromProject(maskWSName);
} }
} }
...@@ -1294,7 +1294,6 @@ InstrumentWidgetMaskTab::loadMask(const std::string &fileName) { ...@@ -1294,7 +1294,6 @@ InstrumentWidgetMaskTab::loadMask(const std::string &fileName) {
} }
/** Save the state of the mask tab to a Mantid project file /** Save the state of the mask tab to a Mantid project file
*
* @return a string representing the state of the mask tab * @return a string representing the state of the mask tab
*/ */
std::string InstrumentWidgetMaskTab::saveToProject() const { std::string InstrumentWidgetMaskTab::saveToProject() const {
......
...@@ -696,6 +696,55 @@ void InstrumentWidgetPickTab::savePlotToWorkspace() { ...@@ -696,6 +696,55 @@ void InstrumentWidgetPickTab::savePlotToWorkspace() {
m_plotController->savePlotToWorkspace(); m_plotController->savePlotToWorkspace();
} }