Skip to content

Commit

Permalink
Begin moving MultiLayer parsing into MultiLayer itself.
Browse files Browse the repository at this point in the history
Refs #9970
  • Loading branch information
Harry Jeffery committed Jul 31, 2014
1 parent f9502b8 commit 833ee91
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 82 deletions.
99 changes: 19 additions & 80 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Expand Up @@ -4627,92 +4627,31 @@ void ApplicationWindow::openProjectFolder(Folder* curFolder, std::string lines,
if(multiLayerLines.length() == 0)
continue;

//Scope just to keep this contained for readability's sake.
{
std::vector<std::string> lineVec;
boost::split(lineVec, multiLayerLines, boost::is_any_of("\n"));

std::string firstLine = lineVec.front();
//Remove the first line
lineVec.erase(lineVec.begin());
multiLayerLines = boost::algorithm::join(lineVec, "\n");

//Split the line up into its values
std::vector<std::string> values;
boost::split(values, firstLine, boost::is_any_of("\t"));

g_log.information() << "firstLine: " << firstLine << std::endl;

std::string caption = values[0];
int param1, param2;
std::stringstream(values[1]) >> param1;
std::stringstream(values[2]) >> param2;
std::string birthDate = values[3];

plot = multilayerPlot(QString(caption.c_str()), 0, param2, param1);
plot->setBirthDate(QString(birthDate.c_str()));
setListViewDate(QString(caption.c_str()), QString(birthDate.c_str()));
}

TSVSerialiser tsv(multiLayerLines);

if(tsv.hasLine("geometry"))
restoreWindowGeometry(this, plot, QString(tsv.lineAsString("geometry").c_str()));

plot->blockSignals(true);

if(tsv.selectLine("WindowLabel"))
{
plot->setWindowLabel(QString(tsv.asString(1).c_str()));
plot->setCaptionPolicy((MdiSubWindow::CaptionPolicy)tsv.asInt(2));
}

if(tsv.selectLine("Margins"))
{
int m1, m2, m3, m4;
tsv >> m1 >> m2 >> m3 >> m4;
plot->setMargins(m1, m2, m3, m4);
}
std::vector<std::string> lineVec;
boost::split(lineVec, multiLayerLines, boost::is_any_of("\n"));

if(tsv.selectLine("Spacing"))
{
int s1, s2;
tsv >> s1 >> s2;
plot->setSpacing(s1, s2);
}
std::string firstLine = lineVec.front();
//Remove the first line
lineVec.erase(lineVec.begin());
multiLayerLines = boost::algorithm::join(lineVec, "\n");

if(tsv.selectLine("LayerCanvasSize"))
{
int c1, c2;
tsv >> c1 >> c2;
plot->setLayerCanvasSize(c1, c2);
}
//Split the line up into its values
std::vector<std::string> values;
boost::split(values, firstLine, boost::is_any_of("\t"));

if(tsv.selectLine("Alignement"))
{
int a1, a2;
tsv >> a1 >> a2;
plot->setAlignement(a1, a2);
}
g_log.information() << "firstLine: " << firstLine << std::endl;

if(tsv.hasSection("waterfall"))
{
g_log.error() << "Waterfall parsing has not yet been implemented in ApplicationWindow." << std::endl;
}
std::string caption = values[0];
int param1, param2;
std::stringstream(values[1]) >> param1;
std::stringstream(values[2]) >> param2;
std::string birthDate = values[3];

if(tsv.hasSection("graph"))
{
std::vector<std::string> graphSections = tsv.sections("graph");
for(auto it = graphSections.begin(); it != graphSections.end(); ++it)
{
std::string graphLines = *it;
g_log.error() << "graph_contents: " << graphLines << std::endl;
QStringList sl = QString(graphLines.c_str()).split("\n");
openGraph(this, plot, sl);
}
}
plot = multilayerPlot(QString(caption.c_str()), 0, param2, param1);
plot->setBirthDate(QString(birthDate.c_str()));
setListViewDate(QString(caption.c_str()), QString(birthDate.c_str()));

plot->blockSignals(false);
plot->loadFromProject(multiLayerLines);
}
}

Expand Down
6 changes: 6 additions & 0 deletions Code/Mantid/MantidPlot/src/Graph.cpp
Expand Up @@ -62,6 +62,8 @@
#include "MantidQtAPI/QwtWorkspaceSpectrumData.h"
#include "Mantid/ErrorBarSettings.h"

#include "TSVSerialiser.h"

#ifdef EMF_OUTPUT
#include "EmfEngine.h"
#endif
Expand Down Expand Up @@ -6153,3 +6155,7 @@ void Graph::slotDragMouseMove(QPoint pos)
emit dragMouseMove(pos);
}

void Graph::loadFromProject(const std::string& lines)
{
}

8 changes: 7 additions & 1 deletion Code/Mantid/MantidPlot/src/Graph.h
Expand Up @@ -46,6 +46,7 @@
#if QWT_VERSION >= 0x050200
#include <qwt_plot_rescaler.h>
#endif
#include "Mantid/IProjectSerialisable.h"
#include "Plot.h"
#include "Table.h"
#include "AxesDialog.h"
Expand Down Expand Up @@ -149,7 +150,7 @@ namespace Mantid
* [ Framework needs to support plug-ins; assigned to ion ]
*/

class Graph: public QWidget
class Graph : public QWidget, public Mantid::IProjectSerialisable
{
Q_OBJECT

Expand Down Expand Up @@ -401,6 +402,11 @@ public slots:
void setAutoScale();
void updateScale();

//! \name Loading from a project
//@{
void loadFromProject(const std::string& lines);
//@}

//! \name Saving to File
//@{
QString saveToString(bool saveAsTemplate = false);
Expand Down
78 changes: 78 additions & 0 deletions Code/Mantid/MantidPlot/src/MultiLayer.cpp
Expand Up @@ -69,6 +69,8 @@
#include "Mantid/MantidMDCurveDialog.h"
#include "MantidQtSliceViewer/LinePlotOptions.h"

#include "TSVSerialiser.h"

namespace
{
/// static logger
Expand Down Expand Up @@ -1653,3 +1655,79 @@ void MultiLayer::setWaterfallFillColor(const QColor& c)
active_graph->setWaterfallFillColor(c);
}

void MultiLayer::loadFromProject(const std::string& lines)
{
TSVSerialiser tsv(lines);

//This should be handled globally
//if(tsv.hasLine("geometry"))
// restoreWindowGeometry(this, plot, QString(tsv.lineAsString("geometry").c_str()));

blockSignals(true);

if(tsv.selectLine("WindowLabel"))
{
setWindowLabel(QString(tsv.asString(1).c_str()));
setCaptionPolicy((MdiSubWindow::CaptionPolicy)tsv.asInt(2));
}

if(tsv.selectLine("Margins"))
{
int m1, m2, m3, m4;
tsv >> m1 >> m2 >> m3 >> m4;
setMargins(m1, m2, m3, m4);
}

if(tsv.selectLine("Spacing"))
{
int s1, s2;
tsv >> s1 >> s2;
setSpacing(s1, s2);
}

if(tsv.selectLine("LayerCanvasSize"))
{
int c1, c2;
tsv >> c1 >> c2;
setLayerCanvasSize(c1, c2);
}

if(tsv.selectLine("Alignement"))
{
int a1, a2;
tsv >> a1 >> a2;
setAlignement(a1, a2);
}

if(tsv.hasSection("waterfall"))
{
g_log.error() << "Waterfall parsing has not yet been implemented in MultiLayer." << std::endl;
}

if(tsv.hasSection("graph"))
{
std::vector<std::string> graphSections = tsv.sections("graph");
for(auto it = graphSections.begin(); it != graphSections.end(); ++it)
{
const std::string graphLines = *it;

TSVSerialiser gtsv(graphLines);

Graph* g = 0;

if(gtsv.selectLine("ggeometry"))
{
int x, y, w, h;
gtsv >> x >> y >> w >> h;
g = dynamic_cast<Graph*>(addLayer(x,y,w,h));
}

if(g)
{
g->loadFromProject(graphLines);
}
}
}

blockSignals(false);
}
5 changes: 4 additions & 1 deletion Code/Mantid/MantidPlot/src/MultiLayer.h
Expand Up @@ -34,6 +34,7 @@

#include "MdiSubWindow.h"
#include "Graph.h"
#include "Mantid/IProjectSerialisable.h"
#include <QPushButton>
#include <QLayout>
#include <QPointer>
Expand Down Expand Up @@ -64,7 +65,7 @@ class QSize;
* If MultiLayer exposes its parent Project to the widgets it manages, they could handle things like creating
* tables by calling methods of Project instead of sending signals.
*/
class MultiLayer: public MdiSubWindow
class MultiLayer: public MdiSubWindow, public Mantid::IProjectSerialisable
{
Q_OBJECT

Expand Down Expand Up @@ -96,6 +97,8 @@ class MultiLayer: public MdiSubWindow

void setWaterfallLayout(bool on = true);

void loadFromProject(const std::string& lines);

public slots:
Graph* addLayer(int x = 0, int y = 0, int width = 0, int height = 0);
void setLayersNumber(int n);
Expand Down

0 comments on commit 833ee91

Please sign in to comment.