From 8e709db29e90b1a4a7f0fbf39c489515587fbfa8 Mon Sep 17 00:00:00 2001
From: Matthew D Jones <Matthew.D.Jones@tessella.com>
Date: Tue, 11 Aug 2015 11:23:23 +0100
Subject: [PATCH] Re #11422 Pass value "n" from GUI to ScaleEngine

---
 Code/Mantid/MantidPlot/src/Graph.cpp                 | 4 +++-
 Code/Mantid/MantidPlot/src/Graph.h                   | 3 ++-
 Code/Mantid/MantidPlot/src/ScaleDetails.cpp          | 3 ++-
 Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.h | 2 +-
 Code/Mantid/MantidPlot/src/plot2D/ScaleEngine.cpp    | 9 ++++++++-
 Code/Mantid/MantidPlot/src/plot2D/ScaleEngine.h      | 5 +++++
 6 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/Code/Mantid/MantidPlot/src/Graph.cpp b/Code/Mantid/MantidPlot/src/Graph.cpp
index fdb1a8138de..56b98e6090e 100644
--- a/Code/Mantid/MantidPlot/src/Graph.cpp
+++ b/Code/Mantid/MantidPlot/src/Graph.cpp
@@ -1152,7 +1152,8 @@ void Graph::setScale(int axis, double start, double end, double step,
     int majorTicks, int minorTicks, int type, bool inverted,
     double left_break, double right_break, int breakPos,
     double stepBeforeBreak, double stepAfterBreak, int minTicksBeforeBreak,
-    int minTicksAfterBreak, bool log10AfterBreak, int breakWidth, bool breakDecoration)
+    int minTicksAfterBreak, bool log10AfterBreak, int breakWidth,
+    bool breakDecoration, double nth_power)
 {
   if (ScaleEngine* se = dynamic_cast<ScaleEngine *>(d_plot->axisScaleEngine(axis))){
     se->setBreakRegion(left_break, right_break);
@@ -1165,6 +1166,7 @@ void Graph::setScale(int axis, double start, double end, double step,
     se->setMinTicksAfterBreak(minTicksAfterBreak);
     se->setLog10ScaleAfterBreak(log10AfterBreak);
     se->setAttribute(QwtScaleEngine::Inverted, inverted);
+    se->setNthPower(nth_power);
   }
 
   setAxisScale(axis, start, end, type, step, majorTicks, minorTicks);
diff --git a/Code/Mantid/MantidPlot/src/Graph.h b/Code/Mantid/MantidPlot/src/Graph.h
index 2f8cd4fed47..7f41d4c9132 100644
--- a/Code/Mantid/MantidPlot/src/Graph.h
+++ b/Code/Mantid/MantidPlot/src/Graph.h
@@ -365,7 +365,8 @@ public slots:
                 int majorTicks = 5, int minorTicks = 5, int type = 0, bool inverted = false,
                 double left_break = -DBL_MAX, double right_break = DBL_MAX, int pos = 50,
                 double stepBeforeBreak = 0.0, double stepAfterBreak = 0.0, int minTicksBeforeBreak = 4,
-                int minTicksAfterBreak = 4, bool log10AfterBreak = false, int breakWidth = 4, bool breakDecoration = true);
+                int minTicksAfterBreak = 4, bool log10AfterBreak = false, int breakWidth = 4,
+                bool breakDecoration = true, double nth_power = 2.0);
   void setScale(QwtPlot::Axis axis, ScaleTransformation::Type scaleType);
   void setScale(QwtPlot::Axis axis, QString logOrLin);
   double axisStep(int axis){return d_user_step[axis];};
diff --git a/Code/Mantid/MantidPlot/src/ScaleDetails.cpp b/Code/Mantid/MantidPlot/src/ScaleDetails.cpp
index 8fa96658a46..6fa78d4be4b 100644
--- a/Code/Mantid/MantidPlot/src/ScaleDetails.cpp
+++ b/Code/Mantid/MantidPlot/src/ScaleDetails.cpp
@@ -573,7 +573,8 @@ void ScaleDetails::apply()
     m_graph->setScale(m_mappedaxis, start, end, step, m_spnMajorValue->value(), m_cmbMinorValue->currentText().toInt(),
       m_cmbScaleType->currentIndex(), m_chkInvert->isChecked(), breakLeft, breakRight, m_spnBreakPosition->value(),
       m_dspnStepBeforeBreak->value(),m_dspnStepAfterBreak->value(), m_cmbMinorTicksBeforeBreak->currentText().toInt(),
-      m_cmbMinorTicksAfterBreak->currentText().toInt(), m_chkLog10AfterBreak->isChecked(), m_spnBreakWidth->value(), m_chkBreakDecoration->isChecked());
+      m_cmbMinorTicksAfterBreak->currentText().toInt(), m_chkLog10AfterBreak->isChecked(), m_spnBreakWidth->value(),
+      m_chkBreakDecoration->isChecked(), m_dspnN->value());
     m_graph->changeIntensity(true);
     m_graph->notifyChanges();
     m_modified = false;
diff --git a/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.h b/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.h
index 2361afd644d..6937c818556 100644
--- a/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.h
+++ b/Code/Mantid/MantidPlot/src/plot2D/PowerScaleEngine.h
@@ -37,7 +37,7 @@
 class PowerScaleTransformation: public ScaleTransformation
 {
 public:
-	PowerScaleTransformation(const ScaleEngine *engine):ScaleTransformation(engine){nth_power = -1.0;};
+	PowerScaleTransformation(const ScaleEngine *engine):ScaleTransformation(engine), nth_power(engine->nthPower()){};
 	virtual double xForm(double x, double, double, double p1, double p2) const;
 	virtual double invXForm(double x, double s1, double s2, double p1, double p2) const;
 	QwtScaleTransformation* copy() const;
diff --git a/Code/Mantid/MantidPlot/src/plot2D/ScaleEngine.cpp b/Code/Mantid/MantidPlot/src/plot2D/ScaleEngine.cpp
index 56fca1967d9..3d83e0defaf 100644
--- a/Code/Mantid/MantidPlot/src/plot2D/ScaleEngine.cpp
+++ b/Code/Mantid/MantidPlot/src/plot2D/ScaleEngine.cpp
@@ -213,7 +213,8 @@ d_minor_ticks_before(1),
 d_minor_ticks_after(1),
 d_log10_scale_after(false),
 d_break_width(4),
-d_break_decoration(true)
+d_break_decoration(true),
+d_nth_power(2.0)
 {}
 
 bool ScaleEngine::hasBreak() const
@@ -276,6 +277,11 @@ bool ScaleEngine::hasBreakDecoration() const
 	return d_break_decoration;
 }
 
+double ScaleEngine::nthPower() const
+{
+  return d_nth_power;
+}
+
 void ScaleEngine::clone(const ScaleEngine *engine)
 {
 	d_type = engine->type();
@@ -289,6 +295,7 @@ void ScaleEngine::clone(const ScaleEngine *engine)
 	d_log10_scale_after = engine->log10ScaleAfterBreak();
 	d_break_width = engine->breakWidth();
 	d_break_decoration = engine->hasBreakDecoration();
+  d_nth_power = engine->nthPower();
 	setAttributes(engine->attributes());
 	setMargins(engine->lowerMargin(), engine->upperMargin());
 }
diff --git a/Code/Mantid/MantidPlot/src/plot2D/ScaleEngine.h b/Code/Mantid/MantidPlot/src/plot2D/ScaleEngine.h
index 831d3d9fc0c..2143777c9a0 100644
--- a/Code/Mantid/MantidPlot/src/plot2D/ScaleEngine.h
+++ b/Code/Mantid/MantidPlot/src/plot2D/ScaleEngine.h
@@ -86,6 +86,9 @@ public:
     bool log10ScaleAfterBreak() const;
     void setLog10ScaleAfterBreak(bool on){d_log10_scale_after = on;};
 
+    double nthPower() const;
+    void setNthPower(double nth_power){d_nth_power = nth_power;};
+
 	ScaleTransformation::Type type() const;
 	void setType(ScaleTransformation::Type type){d_type = type;};
 
@@ -113,6 +116,8 @@ private:
 	int d_break_width;
 	//! If true draw the break decoration
 	bool d_break_decoration;
+  //! Nth Power for a power scale
+  double d_nth_power;
 };
 
 #endif
-- 
GitLab