Skip to content

Commit

Permalink
- Added some preprocessor ifs to OMPlot and OMEdit to make them compi…
Browse files Browse the repository at this point in the history
…le with QWT 6.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10287 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Nov 3, 2011
1 parent 19d85e5 commit 5754cd4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
11 changes: 11 additions & 0 deletions OMPlot/OMPlotGUI/PlotCurve.cpp
Expand Up @@ -123,9 +123,19 @@ bool PlotCurve::hasCustomColor()
return mCustomColor;
}

void PlotCurve::setData(const double* xData, const double* yData, int size)
{
#if QWT_VERSION >= 0x060000
setRawSamples(xData, yData, size);
#else
setRawData(xData, yData, size);
#endif
}

void PlotCurve::updateLegend(QwtLegend *legend) const
{
QwtPlotCurve::updateLegend(legend);
#if QWT_VERSION < 0x060000
QwtLegendItem *lgdItem = dynamic_cast<QwtLegendItem*>(legend->find(this));
if (lgdItem)
{
Expand All @@ -134,4 +144,5 @@ void PlotCurve::updateLegend(QwtLegend *legend) const
}

QwtPlotItem::updateLegend(legend);
#endif
}
1 change: 1 addition & 0 deletions OMPlot/OMPlotGUI/PlotCurve.h
Expand Up @@ -68,6 +68,7 @@ class PlotCurve : public QwtPlotCurve
QString getYVariable();
void setCustomColor(bool value);
bool hasCustomColor();
void setData(const double* xData, const double* yData, int size);
virtual void updateLegend(QwtLegend *legend) const;
};
}
Expand Down
19 changes: 12 additions & 7 deletions OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -274,7 +274,7 @@ void PlotWindow::plot()
currentLine = mpTextStream->readLine();
}
pPlotCurve->setTitle(currentVariable);
pPlotCurve->setRawData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(),
pPlotCurve->setData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(),
pPlotCurve->getSize());
pPlotCurve->attach(mpPlot);
mpPlot->replot();
Expand Down Expand Up @@ -337,7 +337,7 @@ void PlotWindow::plot()
// plot the curves
for(int i = 0; i < variablesToPlotIndex.size(); i++)
{
pPlotCurve[i]->setRawData(pPlotCurve[i]->getXAxisVector(), pPlotCurve[i]->getYAxisVector(),
pPlotCurve[i]->setData(pPlotCurve[i]->getXAxisVector(), pPlotCurve[i]->getYAxisVector(),
pPlotCurve[i]->getSize());
pPlotCurve[i]->attach(mpPlot);
mpPlot->replot();
Expand Down Expand Up @@ -386,7 +386,7 @@ void PlotWindow::plot()
{
double *vals = omc_matlab4_read_vals(&reader, var->index);
// set plot curve data and attach it to plot
pPlotCurve->setRawData(timeVals, vals, reader.nrows);
pPlotCurve->setData(timeVals, vals, reader.nrows);
pPlotCurve->attach(mpPlot);
mpPlot->replot();
}
Expand All @@ -401,7 +401,7 @@ void PlotWindow::plot()
pPlotCurve->addYAxisValue(val);
pPlotCurve->addXAxisValue(stopTime);
pPlotCurve->addYAxisValue(val);
pPlotCurve->setRawData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(),
pPlotCurve->setData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(),
pPlotCurve->getSize());
pPlotCurve->attach(mpPlot);
mpPlot->replot();
Expand Down Expand Up @@ -480,7 +480,7 @@ void PlotWindow::plotParametric()
if (variablesPlotted.size() == 2)
{
pPlotCurve->setTitle(yVariable + "(" + xVariable + ")");
pPlotCurve->setRawData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(),
pPlotCurve->setData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(),
pPlotCurve->getSize());
pPlotCurve->attach(mpPlot);
mpPlot->replot();
Expand Down Expand Up @@ -539,7 +539,7 @@ void PlotWindow::plotParametric()
pPlotCurve->addYAxisValue(QString(values[yVariableIndex]).toDouble());
}

pPlotCurve->setRawData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(),
pPlotCurve->setData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(),
pPlotCurve->getSize());
pPlotCurve->attach(mpPlot);
mpPlot->replot();
Expand Down Expand Up @@ -573,7 +573,7 @@ void PlotWindow::plotParametric()
if(!var)
throw NoVariableException(QString("Variable doesn't exist : ").append(yVariable).toStdString().c_str());
double *yVals = omc_matlab4_read_vals(&reader,var->index);
pPlotCurve->setRawData(xVals, yVals, reader.nrows);
pPlotCurve->setData(xVals, yVals, reader.nrows);
pPlotCurve->setTitle(yVariable + "(" + xVariable + ")");
pPlotCurve->attach(mpPlot);
mpPlot->replot();
Expand Down Expand Up @@ -686,7 +686,10 @@ void PlotWindow::exportDocument()
generator.setDescription(tr("Generated by OpenModelica Plot Tool"));
generator.setFileName(fileName);
generator.setSize(getPlot()->rect().size());
#if QWT_VERSION < 0x060000
getPlot()->print(generator);
#endif

}
// export png, bmp, jpg
else
Expand All @@ -702,6 +705,7 @@ void PlotWindow::exportDocument()

void PlotWindow::printPlot()
{
#if QWT_VERSION < 0x060000
#if 1
QPrinter printer;
#else
Expand All @@ -726,6 +730,7 @@ void PlotWindow::printPlot()
}
mpPlot->print(printer, filter);
}
#endif
}

void PlotWindow::setGrid(bool on)
Expand Down
3 changes: 3 additions & 0 deletions OMPlot/OMPlotGUI/PlotWindow.h
Expand Up @@ -36,6 +36,9 @@
#include <qwt_plot_zoomer.h>
#include <qwt_plot_panner.h>
#include <qwt_scale_engine.h>
#if QWT_VERSION >= 0x060000
#include <qwt_compat.h>
#endif
#include <stdexcept>
#include "../../c_runtime/read_matlab4.h"
#include "Plot.h"
Expand Down
2 changes: 2 additions & 0 deletions OMPlot/OMPlotGUI/PlotZoomer.cpp
Expand Up @@ -38,7 +38,9 @@ using namespace OMPlot;
PlotZoomer::PlotZoomer(int xAxis, int yAxis, QwtPlotCanvas *pParent)
: QwtPlotZoomer(xAxis, yAxis, pParent)
{
#if QWT_VERSION < 0x060000
setSelectionFlags(QwtPicker::DragSelection | QwtPicker::CornerToCorner);
#endif
setTrackerMode(QwtPicker::AlwaysOff);
setRubberBand(QwtPicker::RectRubberBand);
setRubberBandPen(QPen(Qt::black, 1.0, Qt::DashLine));
Expand Down

0 comments on commit 5754cd4

Please sign in to comment.