Skip to content

Commit

Permalink
Store display unit.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Mar 23, 2016
1 parent 49f69c6 commit b657a9f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
12 changes: 9 additions & 3 deletions OMPlot/OMPlotGUI/PlotCurve.cpp
Expand Up @@ -41,14 +41,15 @@

using namespace OMPlot;

PlotCurve::PlotCurve(QString fileName, QString variableName, QString unit, Plot *pParent)
PlotCurve::PlotCurve(QString fileName, QString variableName, QString unit, QString displayUnit, Plot *pParent)
: mCustomColor(false)
{
mName = variableName;
mNameStructure = fileName + "." + variableName;
mFileName = fileName;
mCustomColor = false;
setUnit(unit);
setDisplayUnit(displayUnit);
setTitleLocal();
mpParentPlot = pParent;
/* set curve width and style */
Expand All @@ -67,10 +68,10 @@ PlotCurve::~PlotCurve()

void PlotCurve::setTitleLocal()
{
if (getUnit().isEmpty()) {
if (getDisplayUnit().isEmpty()) {
QwtPlotItem::setTitle(getName());
} else {
QwtPlotItem::setTitle(getName() + " [" + getUnit() + "]");
QwtPlotItem::setTitle(getName() + " [" + getDisplayUnit() + "]");
}
}

Expand Down Expand Up @@ -158,6 +159,11 @@ void PlotCurve::addYAxisValue(double value)
mYAxisVector.push_back(value);
}

void PlotCurve::updateYAxisValue(int index, double value)
{
mYAxisVector.replace(index, value);
}

const double* PlotCurve::getYAxisVector() const
{
return mYAxisVector.data();
Expand Down
6 changes: 5 additions & 1 deletion OMPlot/OMPlotGUI/PlotCurve.h
Expand Up @@ -50,19 +50,22 @@ class PlotCurve : public QwtPlotCurve
QString mYVariable;
bool mCustomColor;
QString mUnit;
QString mDisplayUnit;
qreal mWidth;
int mStyle;

Plot *mpParentPlot;
public:
PlotCurve(QString fileName, QString variableName, QString unit, Plot *pParent);
PlotCurve(QString fileName, QString variableName, QString unit, QString displayUnit, Plot *pParent);
~PlotCurve();

void setTitleLocal();
Qt::PenStyle getPenStyle(int style);
QwtPlotCurve::CurveStyle getCurveStyle(int style);
void setUnit(QString unit) {mUnit = unit;}
QString getUnit() {return mUnit;}
void setDisplayUnit(QString displayUnit) {mDisplayUnit = displayUnit;}
QString getDisplayUnit() {return mDisplayUnit;}
void setCurveWidth(qreal width);
qreal getCurveWidth() {return mWidth;}
void setCurveStyle(int style);
Expand All @@ -75,6 +78,7 @@ class PlotCurve : public QwtPlotCurve
void setYAxisVector(QVector<double> vector);
QVector<double> getYAxisData();
void addYAxisValue(double value);
void updateYAxisValue(int index, double value);
const double* getYAxisVector() const;
void clearYAxisVector() {mYAxisVector.clear();}
int getSize();
Expand Down
20 changes: 10 additions & 10 deletions OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -104,6 +104,7 @@ void PlotWindow::initializePlot(QStringList arguments)
setXLabel(QString(arguments[7]));
setYLabel(QString(arguments[8]));
setUnit("");
setDisplayUnit("");
setXRange(QString(arguments[9]).toDouble(), QString(arguments[10]).toDouble());
setYRange(QString(arguments[11]).toDouble(), QString(arguments[12]).toDouble());
setCurveWidth(QString(arguments[13]).toDouble());
Expand Down Expand Up @@ -295,7 +296,7 @@ void PlotWindow::plot(PlotCurve *pPlotCurve)
{
variablesPlotted.append(currentVariable);
if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), currentVariable, getUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), currentVariable, getUnit(), getDisplayUnit(), mpPlot);
mpPlot->addPlotCurve(pPlotCurve);
}
// clear previous curve data
Expand All @@ -310,8 +311,7 @@ void PlotWindow::plot(PlotCurve *pPlotCurve)
pPlotCurve->addYAxisValue(QString(values[1]).toDouble());
currentLine = mpTextStream->readLine();
}
pPlotCurve->setData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(),
pPlotCurve->getSize());
pPlotCurve->setData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(), pPlotCurve->getSize());
pPlotCurve->attach(mpPlot);
mpPlot->replot();
}
Expand Down Expand Up @@ -357,7 +357,7 @@ void PlotWindow::plot(PlotCurve *pPlotCurve)
}

if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), csvReader->variables[i], getUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), csvReader->variables[i], getUnit(), getDisplayUnit(), mpPlot);
mpPlot->addPlotCurve(pPlotCurve);
}
// clear previous curve data
Expand Down Expand Up @@ -406,7 +406,7 @@ void PlotWindow::plot(PlotCurve *pPlotCurve)
variablesPlotted.append(reader.allInfo[i].name);
// create the plot curve for variable
if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), reader.allInfo[i].name, getUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), reader.allInfo[i].name, getUnit(), getDisplayUnit(), mpPlot);
mpPlot->addPlotCurve(pPlotCurve);
}
// read the variable values
Expand Down Expand Up @@ -520,7 +520,7 @@ void PlotWindow::plotParametric(PlotCurve *pPlotCurve)
if (variablesPlotted.size() == 1)
{
if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), yVariable + " vs " + xVariable, getUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), yVariable + " vs " + xVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve->setXVariable(xVariable);
pPlotCurve->setYVariable(yVariable);
mpPlot->addPlotCurve(pPlotCurve);
Expand Down Expand Up @@ -590,7 +590,7 @@ void PlotWindow::plotParametric(PlotCurve *pPlotCurve)
}

if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), yVariable + " vs " + xVariable, getUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), yVariable + " vs " + xVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve->setXVariable(xVariable);
pPlotCurve->setYVariable(yVariable);
mpPlot->addPlotCurve(pPlotCurve);
Expand Down Expand Up @@ -624,7 +624,7 @@ void PlotWindow::plotParametric(PlotCurve *pPlotCurve)
throw PlotException(msg);

if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), yVariable + " vs " + xVariable, getUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), yVariable + " vs " + xVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve->setXVariable(xVariable);
pPlotCurve->setYVariable(yVariable);
mpPlot->addPlotCurve(pPlotCurve);
Expand Down Expand Up @@ -1185,10 +1185,10 @@ void VariablePageWidget::setCurvePickColorButtonIcon()

void VariablePageWidget::resetLabel()
{
if (mpPlotCurve->getUnit().isEmpty()) {
if (mpPlotCurve->getDisplayUnit().isEmpty()) {
mpLegendTextBox->setText(mpPlotCurve->getName());
} else {
mpLegendTextBox->setText(mpPlotCurve->getName() + " [" + mpPlotCurve->getUnit() + "]");
mpLegendTextBox->setText(mpPlotCurve->getName() + " [" + mpPlotCurve->getDisplayUnit() + "]");
}

}
Expand Down
3 changes: 3 additions & 0 deletions OMPlot/OMPlotGUI/PlotWindow.h
Expand Up @@ -78,6 +78,7 @@ class PlotWindow : public QMainWindow
PlotType mPlotType;
QString mGridType;
QString mUnit;
QString mDisplayUnit;
QString mXRangeMin;
QString mXRangeMax;
QString mYRangeMin;
Expand Down Expand Up @@ -107,6 +108,8 @@ class PlotWindow : public QMainWindow
void setYLabel(QString label);
void setUnit(QString unit) {mUnit = unit;}
QString getUnit() {return mUnit;}
void setDisplayUnit(QString displayUnit) {mDisplayUnit = displayUnit;}
QString getDisplayUnit() {return mDisplayUnit;}
void setXRange(double min, double max);
QString getXRangeMin();
QString getXRangeMax();
Expand Down

0 comments on commit b657a9f

Please sign in to comment.