diff --git a/Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidQwtIMDWorkspaceData.h b/Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidQwtIMDWorkspaceData.h index f7aa0d74d7a3..a59ff3a13f6c 100644 --- a/Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidQwtIMDWorkspaceData.h +++ b/Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidQwtIMDWorkspaceData.h @@ -48,8 +48,8 @@ class EXPORT_OPT_MANTIDQT_API MantidQwtIMDWorkspaceData : public MantidQwtWorksp void setPlotAxisChoice(int choice); void setNormalization(Mantid::API::MDNormalization choice); - std::string getXAxisLabel() const; - std::string getYAxisLabel() const; + QString getXAxisLabel() const; + QString getYAxisLabel() const; int currentPlotXAxis() const; diff --git a/Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidQwtMatrixWorkspaceData.h b/Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidQwtMatrixWorkspaceData.h index 59c25a96f717..d111688c9a8a 100644 --- a/Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidQwtMatrixWorkspaceData.h +++ b/Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidQwtMatrixWorkspaceData.h @@ -51,6 +51,10 @@ class EXPORT_OPT_MANTIDQT_API MantidQwtMatrixWorkspaceData : public MantidQwtWor double getYMin() const; double getYMax() const; + /// Return the label to use for the X axis + QString getXAxisLabel() const; + /// Return the label to use for the Y axis + QString getYAxisLabel() const; bool isHistogram()const{return m_isHistogram;} diff --git a/Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidQwtWorkspaceData.h b/Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidQwtWorkspaceData.h index b6c0a2e2d4a7..7c409a98fbe9 100644 --- a/Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidQwtWorkspaceData.h +++ b/Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidQwtWorkspaceData.h @@ -16,6 +16,9 @@ class EXPORT_OPT_MANTIDQT_API MantidQwtWorkspaceData:public QwtData virtual double ex(size_t i)const = 0; virtual double getYMin() const = 0; virtual double getYMax() const = 0; + virtual QString getXAxisLabel() const = 0; + virtual QString getYAxisLabel() const = 0; + protected: // Assignment operator (virtualized). MantidQwtWorkspaceData& operator=(const MantidQwtWorkspaceData&); diff --git a/Code/Mantid/MantidQt/API/src/MantidQwtIMDWorkspaceData.cpp b/Code/Mantid/MantidQt/API/src/MantidQwtIMDWorkspaceData.cpp index a47255f1f992..8c1bd7791120 100644 --- a/Code/Mantid/MantidQt/API/src/MantidQwtIMDWorkspaceData.cpp +++ b/Code/Mantid/MantidQt/API/src/MantidQwtIMDWorkspaceData.cpp @@ -7,6 +7,7 @@ #include "MantidAPI/NullCoordTransform.h" #include "MantidGeometry/MDGeometry/IMDDimension.h" #include "MantidGeometry/MDGeometry/MDTypes.h" +#include using namespace Mantid::Kernel; using namespace Mantid::Geometry; @@ -443,16 +444,16 @@ int MantidQwtIMDWorkspaceData::currentPlotXAxis() const //----------------------------------------------------------------------------- /// @return the label for the X axis -std::string MantidQwtIMDWorkspaceData::getXAxisLabel() const +QString MantidQwtIMDWorkspaceData::getXAxisLabel() const { - std::string xLabel; + QString xLabel; if ( m_originalWorkspace.expired() ) return xLabel; // Empty string if (m_currentPlotAxis >= 0) { // One of the dimensions of the original IMDDimension_const_sptr dim = m_originalWorkspace.lock()->getDimension(m_currentPlotAxis); - xLabel = dim->getName() + " (" + dim->getUnits() + ")"; + xLabel = QString::fromStdString(dim->getName() + " (" + dim->getUnits() + ")"); } else { @@ -471,7 +472,7 @@ std::string MantidQwtIMDWorkspaceData::getXAxisLabel() const //----------------------------------------------------------------------------- /// @return the label for the Y axis, based on the selected normalization -std::string MantidQwtIMDWorkspaceData::getYAxisLabel() const +QString MantidQwtIMDWorkspaceData::getYAxisLabel() const { switch (m_normalization) { diff --git a/Code/Mantid/MantidQt/API/src/MantidQwtMatrixWorkspaceData.cpp b/Code/Mantid/MantidQt/API/src/MantidQwtMatrixWorkspaceData.cpp index 304beb75889c..af361ad55143 100644 --- a/Code/Mantid/MantidQt/API/src/MantidQwtMatrixWorkspaceData.cpp +++ b/Code/Mantid/MantidQt/API/src/MantidQwtMatrixWorkspaceData.cpp @@ -1,4 +1,5 @@ #include "MantidQtAPI/MantidQwtMatrixWorkspaceData.h" +#include // provides % operator for QString /// Constructor MantidQwtMatrixWorkspaceData::MantidQwtMatrixWorkspaceData(Mantid::API::MatrixWorkspace_const_sptr workspace,int specIndex, const bool logScale, bool distr) @@ -140,6 +141,51 @@ double MantidQwtMatrixWorkspaceData::getYMax() const return temp; } +/** + * @return A string containin the text to use as an X axis label + */ +QString MantidQwtMatrixWorkspaceData::getXAxisLabel() const +{ + // Deal with axis names + Mantid::API::Axis* ax = m_workspace->getAxis(0); + QString xTitle; + if (ax->unit() && ax->unit()->unitID() != "Empty" ) + { + xTitle = QString::fromStdString(ax->unit()->caption()); + if ( !ax->unit()->label().empty() ) + { + xTitle += " (" + QString::fromStdWString(ax->unit()->utf8Label()) + ")"; + } + } + else if (!ax->title().empty()) + { + xTitle = QString::fromStdString(ax->title()); + } + else + { + xTitle = "X axis"; + } + return xTitle; +} + +/** + * @return A string containin the text to use as an Y axis label + */ +QString MantidQwtMatrixWorkspaceData::getYAxisLabel() const +{ + QString yTitle = QString::fromStdString(m_workspace->YUnitLabel()); + Mantid::API::Axis* ax = m_workspace->getAxis(0); + if (m_isDistribution && ax->unit()) + { + const std::string unitID = ax->unit()->unitID(); + if (unitID != "" || unitID != "Empty") + { + yTitle = yTitle % " / " % ax->unit()->label().c_str(); + } + } + return yTitle; +} + void MantidQwtMatrixWorkspaceData::setLogScale(bool on) { m_logScale = on;