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

Refs #16962 Refactoring and updating documentation

parent ec4a1027
......@@ -40,25 +40,30 @@ InstrumentWindow::InstrumentWindow(const QString &wsName, const QString &label,
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(
const std::string &lines, ApplicationWindow *app, const int fileVersion) {
Q_UNUSED(fileVersion);
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))
if (!tsv.selectLine("WorkspaceName"))
return nullptr;
MatrixWorkspace_const_sptr ws =
boost::dynamic_pointer_cast<const MatrixWorkspace>(
app->mantidUI->getWorkspace(QString::fromStdString(wsName)));
const auto name = tsv.asQString(1);
const auto workspace = app->mantidUI->getWorkspace(name);
const auto ws = boost::dynamic_pointer_cast<const MatrixWorkspace>(workspace);
if (!ws)
return nullptr;
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
Mantid::Geometry::Instrument_const_sptr instr = ws->getInstrument();
auto instr = ws->getInstrument();
if (!instr || instr->getName().empty()) {
QApplication::restoreOverrideCursor();
QMessageBox::critical(app, "MantidPlot - Error",
......@@ -66,16 +71,14 @@ IProjectSerialisable *InstrumentWindow::loadFromProject(
return nullptr;
}
// Need a new window
const QString windowName(QString("InstrumentWindow:") +
QString::fromStdString(wsName));
auto iw =
new InstrumentWindow(name, QString("Instrument"), app, windowName);
// Create a new window
const QString windowName("InstrumentWindow:" + name);
auto iw = new InstrumentWindow(name, "Instrument", app, windowName);
// Populate window properties
try {
if (tsv.hasLine("geometry")) {
const QString geometry =
QString::fromStdString(tsv.lineAsString("geometry"));
const auto geometry = tsv.lineAsQString("geometry");
app->restoreWindowGeometry(app, iw, geometry);
}
......@@ -90,11 +93,15 @@ IProjectSerialisable *InstrumentWindow::loadFromProject(
"Instrument view cannot be created:\n\n" + QString(e.what());
QMessageBox::critical(app, "MantidPlot - Error", errorMessage);
}
}
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) {
TSVSerialiser tsv, window;
window.writeRaw(app->windowGeometryInfo(this));
......
......@@ -28,9 +28,11 @@ public:
const QString &name = QString());
~InstrumentWindow() override;
/// Load the state of the instrument window for a Mantid project file
static IProjectSerialisable *loadFromProject(const std::string &lines,
ApplicationWindow *app,
const int fileVersion);
/// Save the state of the instrument window to a Mantid project file
std::string saveToProject(ApplicationWindow *app) override;
void selectTab(int tab);
MantidQt::MantidWidgets::InstrumentWidgetTab *
......
......@@ -57,6 +57,7 @@ public:
std::vector<std::string> sections(const std::string &name) 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 selectSection(const std::string &name, const size_t i = 0);
......@@ -66,6 +67,7 @@ public:
double asDouble(const size_t i) const;
float asFloat(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;
QRect asQRect(const size_t i) const;
QColor asQColor(const size_t i) const;
......
......@@ -149,6 +149,11 @@ std::string TSVSerialiser::lineAsString(const std::string &name,
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) {
if (!hasLine(name))
return false;
......@@ -278,6 +283,13 @@ std::string TSVSerialiser::asString(const size_t i) const {
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) {
val = asInt(m_curIndex++);
return *this;
......
......@@ -83,9 +83,9 @@ public:
bool addToDisplayContextMenu(QMenu &) const override;
void selectTool(const ToolType tool);
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;
/// 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;
public slots:
......
......@@ -38,9 +38,9 @@ public:
virtual bool addToDisplayContextMenu(QMenu &) const { return false; }
/// Get the projection surface
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;
/// 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;
protected:
......
......@@ -19,10 +19,10 @@ class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS InstrumentWidgetTreeTab
public:
explicit InstrumentWidgetTreeTab(InstrumentWidget *instrWidget);
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;
;
/// 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;
;
public slots:
......
......@@ -44,9 +44,9 @@ public:
void getMaskedDetectors(QList<int> &dets) const override;
void resize(int, int) 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;
/// 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;
signals:
......
......@@ -136,9 +136,9 @@ public:
void requestRedraw(bool resetPeakVisibility = false);
/// Enable lighting if the implementation allows it
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);
/// 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;
//-----------------------------------
......
......@@ -180,9 +180,9 @@ protected:
bool m_visible; ///< flag to show or hide the shape
private:
static Shape2D* loadShape2DRectangle(const std::string &lines);
static Shape2D* loadShape2DRing(const std::string &lines);
static Shape2D* loadShape2DFree(const std::string &lines);
/// Instantiate specifc shapes from a type string
static Shape2D *loadShape2DFromType(const std::string &type,
const std::string &lines);
};
/**
......@@ -207,9 +207,9 @@ public:
QStringList getPointNames() const override { return QStringList("center"); }
QPointF getPoint(const QString &prop) const 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);
/// 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;
protected:
......@@ -233,9 +233,9 @@ public:
return m_boundingRect.contains(p);
}
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);
/// 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;
protected:
......@@ -269,9 +269,9 @@ public:
void setColor(const QColor &color) override;
QColor getColor() const override { return m_outer_shape->getColor(); }
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);
/// 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;
protected:
......@@ -304,9 +304,9 @@ public:
void addToPath(QPainterPath &path) const override;
void addPolygon(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);
/// 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;
protected:
......
......@@ -85,9 +85,9 @@ public:
/// Change border color of all shapes.
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);
/// 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;
signals:
......
......@@ -123,9 +123,9 @@ public:
/// Zoom into an area of the screen
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;
/// 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;
/// Get a handle to a peaks workspace from a name
boost::shared_ptr<Mantid::API::IPeaksWorkspace>
......
......@@ -36,23 +36,23 @@
#endif
#endif
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPushButton>
#include <QRadioButton>
#include <QTextEdit>
#include <QMenu>
#include <QAction>
#include <QLabel>
#include <QMessageBox>
#include <QApplication>
#include <QCheckBox>
#include <QFileDialog>
#include <QToolTip>
#include <QTemporaryFile>
#include <QGridLayout>
#include <QGroupBox>
#include <QCheckBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QRadioButton>
#include <QSettings>
#include <QTemporaryFile>
#include <QTextEdit>
#include <QToolTip>
#include <QVBoxLayout>
#include "MantidQtAPI/FileDialogHandler.h"
......@@ -1182,14 +1182,15 @@ void InstrumentWidgetMaskTab::changedIntegrationRange(double, double) {
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
*/
void InstrumentWidgetMaskTab::loadFromProject(const std::string &lines) {
TSVSerialiser tsv(lines);
if (tsv.selectSection("masktab")) {
if (!tsv.selectSection("masktab"))
return;
std::string tabLines;
tsv >> tabLines;
TSVSerialiser tab(tabLines);
......@@ -1222,7 +1223,6 @@ void InstrumentWidgetMaskTab::loadFromProject(const std::string &lines) {
tab >> maskWSName;
loadMaskViewFromProject(maskWSName);
}
}
}
/** Load a mask workspace applied to the instrument actor from the project
......@@ -1294,7 +1294,6 @@ InstrumentWidgetMaskTab::loadMask(const std::string &fileName) {
}
/** Save the state of the mask tab to a Mantid project file
*
* @return a string representing the state of the mask tab
*/
std::string InstrumentWidgetMaskTab::saveToProject() const {
......
......@@ -696,6 +696,55 @@ void InstrumentWidgetPickTab::savePlotToWorkspace() {
m_plotController->savePlotToWorkspace();
}
/** Load pick tab state from a Mantid project file
* @param lines :: lines from the project file to load state from
*/
void InstrumentWidgetPickTab::loadFromProject(const std::string &lines) {
TSVSerialiser tsv(lines);
if (!tsv.selectSection("picktab"))
return;
std::string tabLines;
tsv >> tabLines;
TSVSerialiser tab(tabLines);
// load active push button
std::vector<QPushButton *> buttons{
m_zoom, m_edit, m_ellipse, m_rectangle,
m_ring_ellipse, m_ring_rectangle, m_free_draw, m_one,
m_tube, m_peak, m_peakSelect};
tab.selectLine("ActiveTools");
for (auto button : buttons) {
bool value;
tab >> value;
button->setChecked(value);
}
}
/** Save the state of the pick tab to a Mantid project file
* @return a string representing the state of the pick tab
*/
std::string InstrumentWidgetPickTab::saveToProject() const {
TSVSerialiser tsv;
TSVSerialiser tab;
// save active push button
std::vector<QPushButton *> buttons{
m_zoom, m_edit, m_ellipse, m_rectangle,
m_ring_ellipse, m_ring_rectangle, m_free_draw, m_one,
m_tube, m_peak, m_peakSelect};
tab.writeLine("ActiveTools");
for (auto button : buttons) {
tab << button->isChecked();
}
tsv.writeSection("picktab", tab.outputLines());
return tsv.outputLines();
}
//=====================================================================================//
/**
......@@ -1631,49 +1680,5 @@ void DetectorPlotController::addPeak(double x, double y) {
}
}
void MantidQt::MantidWidgets::InstrumentWidgetPickTab::loadFromProject(
const std::string &lines) {
TSVSerialiser tsv(lines);
if (tsv.selectSection("picktab")) {
std::string tabLines;
tsv >> tabLines;
TSVSerialiser tab(tabLines);
// load active push button
std::vector<QPushButton *> buttons{
m_zoom, m_edit, m_ellipse, m_rectangle,
m_ring_ellipse, m_ring_rectangle, m_free_draw, m_one,
m_tube, m_peak, m_peakSelect};
tab.selectLine("ActiveTools");
for (auto button : buttons) {
bool value;
tab >> value;
button->setChecked(value);
}
}
}
std::string
MantidQt::MantidWidgets::InstrumentWidgetPickTab::saveToProject() const {
TSVSerialiser tsv;
TSVSerialiser tab;
// save active push button
std::vector<QPushButton *> buttons{
m_zoom, m_edit, m_ellipse, m_rectangle,
m_ring_ellipse, m_ring_rectangle, m_free_draw, m_one,
m_tube, m_peak, m_peakSelect};
tab.writeLine("ActiveTools");
for (auto button : buttons) {
tab << button->isChecked();
}
tsv.writeSection("picktab", tab.outputLines());
return tsv.outputLines();
}
} // MantidWidgets
} // MantidQt
......@@ -769,7 +769,9 @@ MantidQt::MantidWidgets::InstrumentWidgetRenderTab::saveToProject() const {
void InstrumentWidgetRenderTab::loadFromProject(const std::string &lines) {
TSVSerialiser tsv(lines);
if (tsv.selectSection("rendertab")) {
if (!tsv.selectSection("rendertab"))
return;
std::string tabLines;
tsv >> tabLines;
TSVSerialiser tab(tabLines);
......@@ -825,7 +827,6 @@ void InstrumentWidgetRenderTab::loadFromProject(const std::string &lines) {
surface->setShowPeakRowsFlag(showRows);
surface->setPeakLabelPrecision(labelPrecision);
surface->setShowPeakRelativeIntensityFlag(showRelativeIntensity);
}
m_colorMapWidget->loadFromProject(lines);
}
......
......@@ -61,11 +61,15 @@ void InstrumentWidgetTreeTab::showEvent(QShowEvent *) {
getSurface()->setInteractionMode(ProjectionSurface::MoveMode);
}
void MantidQt::MantidWidgets::InstrumentWidgetTreeTab::loadFromProject(
const std::string &lines) {
/** Load tree tab state from a Mantid project file
* @param lines :: lines from the project file to load state from
*/
void InstrumentWidgetTreeTab::loadFromProject(const std::string &lines) {
TSVSerialiser tsv(lines);
if (tsv.selectSection("treetab")) {
if (!tsv.selectSection("treetab"))
return;
std::string tabLines;
tsv >> tabLines;
TSVSerialiser tab(tabLines);
......@@ -75,11 +79,12 @@ void MantidQt::MantidWidgets::InstrumentWidgetTreeTab::loadFromProject(
tab >> componentName;
selectComponentByName(QString::fromStdString(componentName));
}
}
}
std::string
MantidQt::MantidWidgets::InstrumentWidgetTreeTab::saveToProject() const {
/** Save the state of the tree tab to a Mantid project file
* @return a string representing the state of the tree tab
*/
std::string InstrumentWidgetTreeTab::saveToProject() const {
TSVSerialiser tsv;
TSVSerialiser tab;
......
......@@ -58,6 +58,9 @@ void MaskBinsData::subtractIntegratedSpectra(
/// Clear the masking data
void MaskBinsData::clear() { m_masks.clear(); }
/** Load mask bins state from a Mantid project file
* @param lines :: lines from the project file to load state from
*/
void MaskBinsData::loadFromProject(const std::string &lines) {
TSVSerialiser tsv(lines);
for (auto &maskLines : tsv.sections("Mask")) {
......@@ -78,6 +81,9 @@ void MaskBinsData::loadFromProject(const std::string &lines) {
}
}
/** Save the state of the mask bins to a Mantid project file
* @return a string representing the state of the mask bins
*/
std::string MaskBinsData::saveToProject() const {
TSVSerialiser tsv;
for (const auto &binMask : m_masks) {
......
......@@ -462,6 +462,9 @@ void Projection3D::setLightingModel(bool picking) const {
}
}
/** Load 3D projection state from a Mantid project file
* @param lines :: lines from the project file to load state from
*/
void Projection3D::loadFromProject(const std::string &lines)
{
ProjectionSurface::loadFromProject(lines);
......@@ -474,6 +477,9 @@ void Projection3D::loadFromProject(const std::string &lines)
}
}
/** Save the state of the 3D projection to a Mantid project file
* @return a string representing the state of the 3D projection
*/
std::string Projection3D::saveToProject() const
{
TSVSerialiser tsv;
......
......@@ -718,8 +718,10 @@ QStringList ProjectionSurface::getPeaksWorkspaceNames() const {
return names;
}
void MantidQt::MantidWidgets::ProjectionSurface::loadFromProject(const std::string &lines)
{
/** Load projection surface state from a Mantid project file
* @param lines :: lines from the project file to load state from
*/
void ProjectionSurface::loadFromProject(const std::string &lines) {
TSVSerialiser tsv(lines);
if (tsv.selectLine("BackgroundColor")) {
......@@ -733,8 +735,10 @@ void MantidQt::MantidWidgets::ProjectionSurface::loadFromProject(const std::stri
}
}
std::string MantidQt::MantidWidgets::ProjectionSurface::saveToProject() const
{
/** Save the state of the projection surface to a Mantid project file
* @return a string representing the state of the projection surface
*/
std::string ProjectionSurface::saveToProject() const {
TSVSerialiser tsv;
tsv.writeLine("BackgroundColor") << m_backgroundColor;
tsv.writeSection("shapes", m_maskShapes.saveToProject());
......