#ifndef CUSTOMCURVE_H
#define CUSTOMCURVE_H
#include <qwt_plot_curve.h>
/*
*QVector<QPointF> samplesVec()
{
QVector<QPointF> result;
for(int i=0; i<=300; ++i)
result << QPointF(i, 8+i*i); //y=8+x^2
return result;
}
*/
{
public:
{
}
{
const int numOfSegments = m_segColor.size();
if(numOfSegments)
{
p->save();
for(int i=0; i<numOfSegments; ++i)
{
p->setPen(m_segColor[i]);
QwtPlotCurve::drawLines (p, xMap, yMap, canvasRect, m_segStart
[i
], m_segFinish
[i
]);
}
p->restore();
}
else
QwtPlotCurve::drawLines (p, xMap, yMap, canvasRect, from, to
);
}
void setSegmentInfo
(int segmentStartIndex,
int segmentFinisIndex,
const QColor & color
) {
m_segColor.push_back(color);
m_segStart.push_back(segmentStartIndex);
m_segFinish.push_back(segmentFinisIndex);
}
private:
QList<QColor> m_segColor;
QList<int> m_segStart;
QList<int> m_segFinish;
};
#endif // CUSTOMCURVE_H
#ifndef CUSTOMCURVE_H
#define CUSTOMCURVE_H
#include <qwt_plot_curve.h>
/*
*QVector<QPointF> samplesVec()
{
QVector<QPointF> result;
for(int i=0; i<=300; ++i)
result << QPointF(i, 8+i*i); //y=8+x^2
return result;
}
*/
class CustomCurve : public QwtPlotCurve
{
public:
explicit CustomCurve(const QString &title=QString::null):QwtPlotCurve (title)
{
}
virtual void drawLines (QPainter *p, const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
{
const int numOfSegments = m_segColor.size();
if(numOfSegments)
{
p->save();
for(int i=0; i<numOfSegments; ++i)
{
p->setPen(m_segColor[i]);
QwtPlotCurve::drawLines (p, xMap, yMap, canvasRect, m_segStart[i], m_segFinish[i]);
}
p->restore();
}
else
QwtPlotCurve::drawLines (p, xMap, yMap, canvasRect, from, to);
}
void setSegmentInfo(int segmentStartIndex, int segmentFinisIndex, const QColor & color)
{
m_segColor.push_back(color);
m_segStart.push_back(segmentStartIndex);
m_segFinish.push_back(segmentFinisIndex);
}
private:
QList<QColor> m_segColor;
QList<int> m_segStart;
QList<int> m_segFinish;
};
#endif // CUSTOMCURVE_H
To copy to clipboard, switch view to plain text mode
....
curve->setSegmentInfo
(0,
100,
QColor("red"));
curve
->setSegmentInfo
(100,
200,
QColor("green"));
curve
->setSegmentInfo
(200,
300,
QColor("blue"));
...
....
curve->setSegmentInfo(0, 100, QColor("red"));
curve->setSegmentInfo(100, 200, QColor("green"));
curve->setSegmentInfo(200, 300, QColor("blue"));
...
To copy to clipboard, switch view to plain text mode
Bookmarks