Skip to content

Commit

Permalink
Refs #4166. Make clearWindow argument work.
Browse files Browse the repository at this point in the history
Additionally, made it add the curves even if specified window doesn't
have any layers.
  • Loading branch information
arturbekasov committed Nov 7, 2013
1 parent b82508c commit 0fcb06b
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Expand Up @@ -3169,43 +3169,46 @@ MultiLayer* MantidUI::plotSpectraList(const QMultiMap<QString,int>& toPlot, bool

const QString& firstWorkspace = toPlot.constBegin().key();

bool isWindowSpecified = (plotWindow != NULL);
bool newGraphCreated = false;

MultiLayer* ml; // MultiLayer (plot window) to use

if(!isWindowSpecified)
if(plotWindow == NULL)
{
// If plot window is not specified, create a new one
ml = appWindow()->multilayerPlot(appWindow()->generateUniqueName(firstWorkspace+"-"));
ml->setCloseOnEmpty(true);
newGraphCreated = true;
}
else
{
// Otherwise, used specified plot window
ml = plotWindow;
}

Graph *g = ml->activeGraph(); // We use active graph only. No support for proper _multi_ layers yet.

if (!g)
if(clearWindow)
{
// TODO: need to add
QApplication::restoreOverrideCursor();
return NULL;
// Remove all layers if requested
ml->setLayersNumber(0);
}

if (ml->isEmpty())
{ // This will add a new layer in two situations: when we've cleared the window manually,
// or when the window specified didn't actually have any layers
ml->addLayer();
newGraphCreated = true;
}

if(!isWindowSpecified)
Graph *g = ml->activeGraph(); // We use active graph only. No support for proper _multi_ layers yet.

if(newGraphCreated)
{
// If window was not specified, we've created a new one and now need to do some
// initialization
connect(g,SIGNAL(curveRemoved()),ml,SLOT(maybeNeedToClose()), Qt::QueuedConnection);
appWindow()->setPreferences(g);
g->newLegend("");
g->setTitle(tr("Workspace ")+firstWorkspace);
}

// TODO: If window clearing requested, remove previous curves

// Try to add curves to the plot
MantidMatrixCurve* mc;
for(QMultiMap<QString,int>::const_iterator it=toPlot.begin();it!=toPlot.end();++it)
Expand All @@ -3232,10 +3235,8 @@ MultiLayer* MantidUI::plotSpectraList(const QMultiMap<QString,int>& toPlot, bool
return NULL;
}

if(!isWindowSpecified)
if(newGraphCreated)
{
// If new window, we update plot axis

auto workspace = boost::dynamic_pointer_cast<MatrixWorkspace>(
AnalysisDataService::Instance().retrieve(firstWorkspace.toStdString()));

Expand Down Expand Up @@ -3281,10 +3282,8 @@ MultiLayer* MantidUI::plotSpectraList(const QMultiMap<QString,int>& toPlot, bool
// happen, but it does apparently with some muon analyses.
g->checkValuesInAxisRange(mc);
}
else
{
g->replot();
}

g->replot();

QApplication::restoreOverrideCursor();
return ml;
Expand Down

0 comments on commit 0fcb06b

Please sign in to comment.