mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Summary curves: Turned on anti-aliasing, Showing complete curve appearance in legend. Added Symbol skipping as feature.
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
#include "qwt_symbol.h"
|
||||
#include "RigCurveDataTools.h"
|
||||
#include "qwt_date.h"
|
||||
#include "qwt_point_mapper.h"
|
||||
#include "qwt_painter.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -30,6 +32,13 @@
|
||||
RiuLineSegmentQwtPlotCurve::RiuLineSegmentQwtPlotCurve(const QString &title)
|
||||
: QwtPlotCurve(title)
|
||||
{
|
||||
this->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
|
||||
this->setLegendAttribute(QwtPlotCurve::LegendShowSymbol, true);
|
||||
this->setLegendAttribute(QwtPlotCurve::LegendShowBrush, true);
|
||||
|
||||
this->setRenderHint(QwtPlotItem::RenderAntialiased, true);
|
||||
|
||||
m_symbolSkipPixelDistance = 10.0f;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -111,6 +120,60 @@ void RiuLineSegmentQwtPlotCurve::drawCurve(QPainter* p, int style,
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Drawing symbols but skipping if they are to close to the previous one
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuLineSegmentQwtPlotCurve::drawSymbols(QPainter *painter, const QwtSymbol &symbol,
|
||||
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
|
||||
const QRectF &canvasRect, int from, int to) const
|
||||
{
|
||||
if (m_symbolSkipPixelDistance <= 0)
|
||||
{
|
||||
QwtPlotCurve::drawSymbols(painter, symbol, xMap, yMap, canvasRect, from, to);
|
||||
return;
|
||||
}
|
||||
|
||||
QwtPointMapper mapper;
|
||||
mapper.setFlag(QwtPointMapper::RoundPoints,
|
||||
QwtPainter::roundingAlignment(painter));
|
||||
mapper.setFlag(QwtPointMapper::WeedOutPoints,
|
||||
testPaintAttribute(QwtPlotCurve::FilterPoints));
|
||||
mapper.setBoundingRect(canvasRect);
|
||||
|
||||
const QPolygonF points = mapper.toPointsF(xMap, yMap,
|
||||
data(), from, to);
|
||||
int pointCount = points.size();
|
||||
|
||||
QPolygonF filteredPoints;
|
||||
QPointF lastDrawnSymbolPos;
|
||||
|
||||
if (pointCount > 0)
|
||||
{
|
||||
filteredPoints.push_back(points[0]);
|
||||
lastDrawnSymbolPos = points[0];
|
||||
}
|
||||
|
||||
float sqSkipDist = m_symbolSkipPixelDistance*m_symbolSkipPixelDistance;
|
||||
|
||||
for(int pIdx = 1; pIdx < pointCount -1 ; ++pIdx)
|
||||
{
|
||||
QPointF diff = points[pIdx] - lastDrawnSymbolPos;
|
||||
float sqDistBetweenSymbols = diff.x()*diff.x() + diff.y()*diff.y();
|
||||
|
||||
if(sqDistBetweenSymbols > sqSkipDist)
|
||||
{
|
||||
filteredPoints.push_back(points[pIdx]);
|
||||
lastDrawnSymbolPos = points[pIdx];
|
||||
}
|
||||
}
|
||||
|
||||
if(pointCount > 1) filteredPoints.push_back(points.back());
|
||||
|
||||
|
||||
if(filteredPoints.size() > 0)
|
||||
symbol.drawSymbols(painter, filteredPoints);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -118,3 +181,11 @@ void RiuLineSegmentQwtPlotCurve::setLineSegmentStartStopIndices(const std::vecto
|
||||
{
|
||||
m_polyLineStartStopIndices = lineSegmentStartStopIndices;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuLineSegmentQwtPlotCurve::setSymbolSkipPixelDistance(float distance)
|
||||
{
|
||||
m_symbolSkipPixelDistance = distance >= 0.0f ? distance: 0.0f;
|
||||
}
|
||||
|
@@ -47,15 +47,27 @@ public:
|
||||
explicit RiuLineSegmentQwtPlotCurve(const QString &title = QString::null);
|
||||
virtual ~RiuLineSegmentQwtPlotCurve();
|
||||
|
||||
void setSamplesFromDateAndValues(const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues);
|
||||
void setSamplesFromDateAndValues(const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues);
|
||||
|
||||
void setLineSegmentStartStopIndices(const std::vector< std::pair<size_t, size_t> >& lineSegmentStartStopIndices);
|
||||
|
||||
void setSymbolSkipPixelDistance(float distance);
|
||||
|
||||
void setLineSegmentStartStopIndices(const std::vector< std::pair<size_t, size_t> >& lineSegmentStartStopIndices);
|
||||
|
||||
protected:
|
||||
virtual void drawCurve(QPainter* p, int style,
|
||||
const QwtScaleMap& xMap, const QwtScaleMap& yMap,
|
||||
const QRectF& canvasRect, int from, int to) const;
|
||||
const QRectF& canvasRect,
|
||||
int from, int to) const;
|
||||
|
||||
|
||||
virtual void drawSymbols(QPainter *p, const QwtSymbol &symbol,
|
||||
const QwtScaleMap &xMap,
|
||||
const QwtScaleMap &yMap,
|
||||
const QRectF &canvasRect,
|
||||
int from, int to) const override;
|
||||
|
||||
private:
|
||||
std::vector< std::pair<size_t, size_t> > m_polyLineStartStopIndices;
|
||||
float m_symbolSkipPixelDistance;
|
||||
};
|
||||
|
Reference in New Issue
Block a user