mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 01:51:49 +08:00
using new JKQTPGraphLineAndFillStyleMixin where appropriate
This commit is contained in:
parent
6875e0ae6c
commit
34fa59ebf4
@ -33,13 +33,12 @@
|
||||
|
||||
JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase(JKQTBasePlotter* parent):
|
||||
JKQTPEvaluatedFunctionWithErrorsGraphBase(parent),
|
||||
drawLine(true),
|
||||
fillCurve(false),
|
||||
drawErrorPolygons(false),
|
||||
drawErrorLines(false)
|
||||
{
|
||||
initLineStyle(parent, parentPlotStyle);
|
||||
initFillStyle(parent, parentPlotStyle);
|
||||
setFillCurve(false);
|
||||
|
||||
errorColor=getLineColor().lighter();
|
||||
errorFillColor=getLineColor().lighter();
|
||||
@ -71,16 +70,6 @@ JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::~JKQTPEvaluatedFunctionWithErr
|
||||
}
|
||||
|
||||
|
||||
void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::setDrawLine(bool __value)
|
||||
{
|
||||
this->drawLine = __value;
|
||||
}
|
||||
|
||||
bool JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::getDrawLine() const
|
||||
{
|
||||
return this->drawLine;
|
||||
}
|
||||
|
||||
void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) {
|
||||
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
||||
QPen p=getLinePen(painter, parent);
|
||||
@ -90,10 +79,10 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawKeyMarker(JKQTPEnhanc
|
||||
QBrush b=getFillBrush(painter, parent);
|
||||
const double y=rect.top()+rect.height()/2.0;
|
||||
painter.setPen(np);
|
||||
if (drawLine) painter.setPen(p);
|
||||
if (getDrawLine()) painter.setPen(p);
|
||||
painter.setBrush(b);
|
||||
if (fillCurve) painter.drawRect(rect);
|
||||
if (!fillCurve && drawLine) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
|
||||
if (getFillCurve()) painter.drawRect(rect);
|
||||
if (!getFillCurve() && getDrawLine()) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
|
||||
|
||||
}
|
||||
|
||||
@ -262,7 +251,7 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawXGraph(JKQTPEnhancedP
|
||||
|
||||
y=qBound(yami, y, yama);
|
||||
|
||||
if (fillCurve) {
|
||||
if (getFillCurve()) {
|
||||
if (!first) filledPolygon<<QPointF(x, y0);
|
||||
filledPolygon<<QPointF(x, y);
|
||||
if (it+1==data.end()) filledPolygon<<QPointF(x, y0);
|
||||
@ -273,7 +262,7 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawXGraph(JKQTPEnhancedP
|
||||
epBottom<<QPointF(x, yme);
|
||||
}
|
||||
|
||||
if (drawLine) {
|
||||
if (getDrawLine()) {
|
||||
linePolygon<<QPointF(x, y);
|
||||
}
|
||||
|
||||
@ -299,13 +288,13 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawXGraph(JKQTPEnhancedP
|
||||
painter.drawPolygon(poly, Qt::OddEvenFill);
|
||||
|
||||
}
|
||||
if (fillCurve) {
|
||||
if (getFillCurve()) {
|
||||
painter.save(); auto __finalpaintfillc=JKQTPFinally([&painter]() {painter.restore();});
|
||||
painter.setBrush(b);
|
||||
painter.setPen(np);
|
||||
painter.drawPolygon(filledPolygon, Qt::OddEvenFill);
|
||||
}
|
||||
if (drawLine) {
|
||||
if (getDrawLine()) {
|
||||
painter.save(); auto __finalpaintline=JKQTPFinally([&painter]() {painter.restore();});
|
||||
painter.setPen(p);
|
||||
painter.drawPolyline(linePolygon);
|
||||
@ -389,7 +378,7 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawYGraph(JKQTPEnhancedP
|
||||
|
||||
x=qBound(xami, x, xama);
|
||||
|
||||
if (fillCurve) {
|
||||
if (getFillCurve()) {
|
||||
if (!first) filledPolygon<<QPointF(x0, y);
|
||||
filledPolygon<<QPointF(x, y);
|
||||
if (it+1==data.end()) filledPolygon<<QPointF(x0, y);
|
||||
@ -400,7 +389,7 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawYGraph(JKQTPEnhancedP
|
||||
epBottom<<QPointF(xme, y);
|
||||
}
|
||||
|
||||
if (drawLine) {
|
||||
if (getDrawLine()) {
|
||||
linePolygon<<QPointF(x, y);
|
||||
}
|
||||
|
||||
@ -425,13 +414,13 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawYGraph(JKQTPEnhancedP
|
||||
}
|
||||
painter.drawPolygon(poly, Qt::OddEvenFill);
|
||||
}
|
||||
if (fillCurve) {
|
||||
if (getFillCurve()) {
|
||||
painter.save(); auto __finalpaintfillc=JKQTPFinally([&painter]() {painter.restore();});
|
||||
painter.setBrush(b);
|
||||
painter.setPen(np);
|
||||
painter.drawPolygon(filledPolygon, Qt::OddEvenFill);
|
||||
}
|
||||
if (drawLine) {
|
||||
if (getDrawLine()) {
|
||||
painter.save(); auto __finalpaintline=JKQTPFinally([&painter]() {painter.restore();});
|
||||
painter.setPen(p);
|
||||
painter.drawPolyline(linePolygon);
|
||||
|
@ -44,7 +44,7 @@
|
||||
*
|
||||
* \see e.g. JKQTPXFunctionLineGraph for a concrete implementation
|
||||
*/
|
||||
class JKQTPLOTTER_LIB_EXPORT JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase: public JKQTPEvaluatedFunctionWithErrorsGraphBase, public JKQTPGraphLineStyleMixin, public JKQTPGraphFillStyleMixin {
|
||||
class JKQTPLOTTER_LIB_EXPORT JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase: public JKQTPEvaluatedFunctionWithErrorsGraphBase, public JKQTPGraphLineAndFillStyleMixin {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
@ -62,8 +62,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase: p
|
||||
/** \brief returns the color to be used for the key label */
|
||||
virtual QColor getKeyLabelColor() const override;
|
||||
|
||||
/*! \copydoc drawLine */
|
||||
bool getDrawLine() const;
|
||||
|
||||
|
||||
/*! \copydoc drawErrorPolygons */
|
||||
@ -89,8 +87,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase: p
|
||||
/*! \brief set color, fill color and error color at the same time */
|
||||
void setColor(QColor c);
|
||||
|
||||
/*! \copydoc drawLine */
|
||||
void setDrawLine(bool __value);
|
||||
|
||||
/*! \copydoc drawErrorPolygons */
|
||||
void setDrawErrorPolygons(bool __value);
|
||||
/*! \copydoc drawErrorLines */
|
||||
@ -115,12 +112,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase: p
|
||||
|
||||
|
||||
|
||||
/** \brief indicates whether to draw a line or not */
|
||||
bool drawLine;
|
||||
/** \brief indicates whether to fill the space between the curve and the x-axis */
|
||||
bool fillCurve;
|
||||
|
||||
|
||||
/** \brief indicates whether an error polygon should be drawn */
|
||||
bool drawErrorPolygons;
|
||||
/** \brief indicates whether error lines should be drawn */
|
||||
|
@ -187,9 +187,12 @@ void JKQTPFilledVerticalRangeGraph::draw(JKQTPEnhancedPainter &painter)
|
||||
poly_all.append(plow[i]);
|
||||
}
|
||||
}
|
||||
painter.setBrush(b);
|
||||
painter.setPen(np);
|
||||
painter.drawPolygon(poly_all);
|
||||
|
||||
if (getFillCurve()) {
|
||||
painter.setBrush(b);
|
||||
painter.setPen(np);
|
||||
painter.drawPolygon(poly_all);
|
||||
}
|
||||
|
||||
|
||||
if (getDrawLine()) {
|
||||
@ -299,9 +302,12 @@ void JKQTPFilledHorizontalRangeGraph::draw(JKQTPEnhancedPainter &painter)
|
||||
poly_all.append(plow[i]);
|
||||
}
|
||||
}
|
||||
painter.setBrush(b);
|
||||
painter.setPen(np);
|
||||
painter.drawPolygon(poly_all);
|
||||
|
||||
if (getFillCurve()) {
|
||||
painter.setBrush(b);
|
||||
painter.setPen(np);
|
||||
painter.drawPolygon(poly_all);
|
||||
}
|
||||
|
||||
|
||||
if (getDrawLine()) {
|
||||
|
@ -39,8 +39,6 @@
|
||||
JKQTPSpecialLineHorizontalGraph::JKQTPSpecialLineHorizontalGraph(JKQTBasePlotter* parent):
|
||||
JKQTPXYGraph(parent)
|
||||
{
|
||||
m_drawLine=true;
|
||||
m_fillCurve=false;
|
||||
m_drawSymbols=false;
|
||||
m_specialLineType=JKQTPStepLeft;
|
||||
m_baseline=0;
|
||||
@ -49,6 +47,7 @@ JKQTPSpecialLineHorizontalGraph::JKQTPSpecialLineHorizontalGraph(JKQTBasePlotter
|
||||
initLineStyle(parent, parentPlotStyle);
|
||||
initFillStyle(parent, parentPlotStyle);
|
||||
initSymbolStyle(parent, parentPlotStyle);
|
||||
setFillCurve(false);
|
||||
}
|
||||
|
||||
|
||||
@ -65,10 +64,10 @@ void JKQTPSpecialLineHorizontalGraph::drawKeyMarker(JKQTPEnhancedPainter& painte
|
||||
QBrush b=getFillBrush(painter, parent);
|
||||
const double y=rect.top()+rect.height()/2.0;
|
||||
painter.setPen(np);
|
||||
if (m_drawLine) painter.setPen(p);
|
||||
if (getDrawLine()) painter.setPen(p);
|
||||
painter.setBrush(b);
|
||||
if (m_fillCurve) painter.drawRect(rect);
|
||||
if (!m_fillCurve && m_drawLine) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
|
||||
if (getFillCurve()) painter.drawRect(rect);
|
||||
if (!getFillCurve() && getDrawLine()) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
|
||||
if (m_drawSymbols) {
|
||||
plotStyledSymbol(parent, painter, rect.center().x(), rect.center().y(), rect.width()*0.5);
|
||||
}
|
||||
@ -79,16 +78,6 @@ QColor JKQTPSpecialLineHorizontalGraph::getKeyLabelColor() const {
|
||||
return getLineColor();
|
||||
}
|
||||
|
||||
void JKQTPSpecialLineHorizontalGraph::setDrawLine(bool __value)
|
||||
{
|
||||
this->m_drawLine = __value;
|
||||
}
|
||||
|
||||
bool JKQTPSpecialLineHorizontalGraph::getDrawLine() const
|
||||
{
|
||||
return this->m_drawLine;
|
||||
}
|
||||
|
||||
void JKQTPSpecialLineHorizontalGraph::setDrawSymbols(bool __value)
|
||||
{
|
||||
m_drawSymbols=__value;
|
||||
@ -99,15 +88,6 @@ bool JKQTPSpecialLineHorizontalGraph::getDrawSymbols() const
|
||||
return m_drawSymbols;
|
||||
}
|
||||
|
||||
void JKQTPSpecialLineHorizontalGraph::setFillCurve(bool __value)
|
||||
{
|
||||
this->m_fillCurve = __value;
|
||||
}
|
||||
|
||||
bool JKQTPSpecialLineHorizontalGraph::getFillCurve() const
|
||||
{
|
||||
return this->m_fillCurve;
|
||||
}
|
||||
|
||||
void JKQTPSpecialLineHorizontalGraph::setSpecialLineType(const JKQTPSpecialLineType &__value)
|
||||
{
|
||||
@ -155,164 +135,159 @@ void JKQTPSpecialLineHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
|
||||
QPen np(Qt::NoPen);
|
||||
QBrush b=getFillBrush(painter, parent);
|
||||
|
||||
int imax=static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn))));
|
||||
int imax=0;
|
||||
int imin=0;
|
||||
|
||||
if (imax<imin) {
|
||||
int h=imin;
|
||||
imin=imax;
|
||||
imax=h;
|
||||
}
|
||||
if (imin<0) imin=0;
|
||||
if (imax<0) imax=0;
|
||||
if (getIndexRange(imin, imax)) {
|
||||
|
||||
QPainterPath pl, pf;
|
||||
QVector<QPointF> ps;
|
||||
|
||||
double xold=-1;
|
||||
double yold=-1;
|
||||
// double xstart=-1;
|
||||
// double ystart=-1;
|
||||
//double x0=transformX(0);
|
||||
//if (parent->getXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin());
|
||||
double y0=transformY(m_baseline);
|
||||
if (parent->getYAxis()->isLogAxis()) {
|
||||
y0=transformY(parent->getYAxis()->getMin());
|
||||
if (m_baseline>0 && m_baseline>parent->getYAxis()->getMin()) y0=transformY(m_baseline);
|
||||
else y0=transformY(parent->getYAxis()->getMin());
|
||||
}
|
||||
bool subsequentItem=false;
|
||||
intSortData();
|
||||
for (int iii=imin; iii<imax; iii++) {
|
||||
int i=qBound(imin, getDataIndex(iii), imax);
|
||||
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
|
||||
double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
|
||||
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
|
||||
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
|
||||
double x=transformX(xv);
|
||||
double y=transformY(yv);
|
||||
if (JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) {
|
||||
ps.append(QPointF(x,y));
|
||||
if (subsequentItem) {
|
||||
//double xl1=xold;
|
||||
//double yl1=yold;
|
||||
//double xl2=x;
|
||||
//double yl2=y;
|
||||
QPainterPath pl, pf;
|
||||
QVector<QPointF> ps;
|
||||
|
||||
if (m_specialLineType==JKQTPStepCenter) {
|
||||
// x/y
|
||||
// |--------*
|
||||
// |
|
||||
// *--------|
|
||||
// xold/yold
|
||||
const double d=(x-xold);
|
||||
pf.lineTo(xold+d/2.0, yold);
|
||||
pf.lineTo(xold+d/2.0, y);
|
||||
double xold=-1;
|
||||
double yold=-1;
|
||||
// double xstart=-1;
|
||||
// double ystart=-1;
|
||||
//double x0=transformX(0);
|
||||
//if (parent->getXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin());
|
||||
double y0=transformY(m_baseline);
|
||||
if (parent->getYAxis()->isLogAxis()) {
|
||||
y0=transformY(parent->getYAxis()->getMin());
|
||||
if (m_baseline>0 && m_baseline>parent->getYAxis()->getMin()) y0=transformY(m_baseline);
|
||||
else y0=transformY(parent->getYAxis()->getMin());
|
||||
}
|
||||
bool subsequentItem=false;
|
||||
intSortData();
|
||||
for (int iii=imin; iii<imax; iii++) {
|
||||
const int i=qBound(imin, getDataIndex(iii), imax);
|
||||
const double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
|
||||
const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
|
||||
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
|
||||
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
|
||||
const double x=transformX(xv);
|
||||
const double y=transformY(yv);
|
||||
if (JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) {
|
||||
ps.append(QPointF(x,y));
|
||||
if (subsequentItem) {
|
||||
//double xl1=xold;
|
||||
//double yl1=yold;
|
||||
//double xl2=x;
|
||||
//double yl2=y;
|
||||
|
||||
if (m_specialLineType==JKQTPStepCenter) {
|
||||
// x/y
|
||||
// |--------*
|
||||
// |
|
||||
// *--------|
|
||||
// xold/yold
|
||||
const double d=(x-xold);
|
||||
pf.lineTo(xold+d/2.0, yold);
|
||||
pf.lineTo(xold+d/2.0, y);
|
||||
pf.lineTo(x, y);
|
||||
if (getDrawLine()) {
|
||||
pl.lineTo(xold+d/2.0, yold);
|
||||
pl.lineTo(xold+d/2.0, y);
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPStepLeft) {
|
||||
// x/y
|
||||
// |----------------*
|
||||
// |
|
||||
// *
|
||||
// xold/yold
|
||||
pf.lineTo(xold, y);
|
||||
pf.lineTo(x, y);
|
||||
if (getDrawLine()) {
|
||||
pl.lineTo(xold, y);
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPStepRight) {
|
||||
// x/y
|
||||
// *
|
||||
// |
|
||||
// *----------------|
|
||||
// xold/yold
|
||||
pf.lineTo(x, yold);
|
||||
pf.lineTo(x, y);
|
||||
if (getDrawLine()) {
|
||||
pl.lineTo(x, yold);
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPStepAverage) {
|
||||
// x/y
|
||||
// *
|
||||
// |
|
||||
// |----------------|
|
||||
// |
|
||||
// *
|
||||
// xold/yold
|
||||
//const double d=(x-xold);
|
||||
const double h=(y-yold);
|
||||
pf.lineTo(xold, yold+h/2.0);
|
||||
pf.lineTo(x, yold+h/2.0);
|
||||
pf.lineTo(x,y);
|
||||
if (getDrawLine()) {
|
||||
pl.lineTo(xold, yold+h/2.0);
|
||||
pl.lineTo(x, yold+h/2.0);
|
||||
pl.lineTo(x,y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPDirectLine) {
|
||||
// x/y
|
||||
// /----*
|
||||
// /----/
|
||||
// *----/
|
||||
// xold/yold
|
||||
pf.lineTo(x, y);
|
||||
if (getDrawLine()) {
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
//std::cout<<"line ("<<xl1<<", "<<yl1<<") -- ("<<xl2<<", "<<yl2<<")"<<std::endl;
|
||||
} else {
|
||||
if (getDrawLine()) pl.moveTo(x,y);
|
||||
pf.moveTo(x, y0);
|
||||
pf.lineTo(x, y);
|
||||
if (m_drawLine) {
|
||||
pl.lineTo(xold+d/2.0, yold);
|
||||
pl.lineTo(xold+d/2.0, y);
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPStepLeft) {
|
||||
// x/y
|
||||
// |----------------*
|
||||
// |
|
||||
// *
|
||||
// xold/yold
|
||||
pf.lineTo(xold, y);
|
||||
pf.lineTo(x, y);
|
||||
if (m_drawLine) {
|
||||
pl.lineTo(xold, y);
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPStepRight) {
|
||||
// x/y
|
||||
// *
|
||||
// |
|
||||
// *----------------|
|
||||
// xold/yold
|
||||
pf.lineTo(x, yold);
|
||||
pf.lineTo(x, y);
|
||||
if (m_drawLine) {
|
||||
pl.lineTo(x, yold);
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPStepAverage) {
|
||||
// x/y
|
||||
// *
|
||||
// |
|
||||
// |----------------|
|
||||
// |
|
||||
// *
|
||||
// xold/yold
|
||||
//const double d=(x-xold);
|
||||
const double h=(y-yold);
|
||||
pf.lineTo(xold, yold+h/2.0);
|
||||
pf.lineTo(x, yold+h/2.0);
|
||||
pf.lineTo(x,y);
|
||||
if (m_drawLine) {
|
||||
pl.lineTo(xold, yold+h/2.0);
|
||||
pl.lineTo(x, yold+h/2.0);
|
||||
pl.lineTo(x,y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPDirectLine) {
|
||||
// x/y
|
||||
// /----*
|
||||
// /----/
|
||||
// *----/
|
||||
// xold/yold
|
||||
pf.lineTo(x, y);
|
||||
if (m_drawLine) {
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
//xstart=x;
|
||||
//ystart=y0;
|
||||
}
|
||||
|
||||
//std::cout<<"line ("<<xl1<<", "<<yl1<<") -- ("<<xl2<<", "<<yl2<<")"<<std::endl;
|
||||
} else {
|
||||
if (m_drawLine) pl.moveTo(x,y);
|
||||
pf.moveTo(x, y0);
|
||||
pf.lineTo(x, y);
|
||||
//xstart=x;
|
||||
//ystart=y0;
|
||||
xold=x;
|
||||
yold=y;
|
||||
subsequentItem=true;
|
||||
}
|
||||
xold=x;
|
||||
yold=y;
|
||||
subsequentItem=true;
|
||||
}
|
||||
}
|
||||
if (getFillCurve()) {
|
||||
pf.lineTo(xold, y0);
|
||||
pf.closeSubpath();
|
||||
}
|
||||
painter.save();
|
||||
auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
||||
|
||||
if (getFillCurve()) {
|
||||
painter.fillPath(pf, b);
|
||||
}
|
||||
|
||||
if (isHighlighted()) {
|
||||
painter.setBrush(QBrush(Qt::transparent));
|
||||
painter.setPen(ph);
|
||||
painter.drawPath(pl);
|
||||
}
|
||||
|
||||
if (getDrawLine()) {
|
||||
painter.setBrush(QBrush(Qt::transparent));
|
||||
painter.setPen(p);
|
||||
painter.drawPath(pl);
|
||||
}
|
||||
|
||||
if (m_drawSymbols) {
|
||||
painter.save();
|
||||
auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();});
|
||||
for (auto& ppoint: ps) {
|
||||
plotStyledSymbol(parent, painter, ppoint.x(), ppoint.y());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_fillCurve) {
|
||||
pf.lineTo(xold, y0);
|
||||
pf.closeSubpath();
|
||||
}
|
||||
painter.save();
|
||||
auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
||||
|
||||
if (m_fillCurve) {
|
||||
painter.fillPath(pf, b);
|
||||
}
|
||||
|
||||
if (isHighlighted()) {
|
||||
painter.setBrush(QBrush(Qt::transparent));
|
||||
painter.setPen(ph);
|
||||
painter.drawPath(pl);
|
||||
}
|
||||
|
||||
if (m_drawLine) {
|
||||
painter.setBrush(QBrush(Qt::transparent));
|
||||
painter.setPen(p);
|
||||
painter.drawPath(pl);
|
||||
}
|
||||
|
||||
if (m_drawSymbols) {
|
||||
painter.save();
|
||||
auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();});
|
||||
for (auto& ppoint: ps) {
|
||||
plotStyledSymbol(parent, painter, ppoint.x(), ppoint.y());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
drawErrorsAfter(painter);
|
||||
}
|
||||
@ -353,136 +328,132 @@ void JKQTPSpecialLineVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
|
||||
QPen np(Qt::NoPen);
|
||||
QBrush b=getFillBrush(painter, parent);
|
||||
|
||||
int imax=static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn))));
|
||||
int imax=0;
|
||||
int imin=0;
|
||||
|
||||
if (imax<imin) {
|
||||
int h=imin;
|
||||
imin=imax;
|
||||
imax=h;
|
||||
}
|
||||
if (imin<0) imin=0;
|
||||
if (imax<0) imax=0;
|
||||
if (getIndexRange(imin, imax)) {
|
||||
|
||||
QPainterPath pl, pf;
|
||||
QVector<QPointF> ps;
|
||||
|
||||
double xold=-1;
|
||||
double yold=-1;
|
||||
double x0=transformX(m_baseline);
|
||||
if (parent->getXAxis()->isLogAxis()) {
|
||||
if (m_baseline>0 && m_baseline>parent->getXAxis()->getMin()) x0=transformX(m_baseline);
|
||||
else x0=transformX(parent->getXAxis()->getMin());
|
||||
}
|
||||
bool first=false;
|
||||
intSortData();
|
||||
for (int iii=imin; iii<imax; iii++) {
|
||||
int i=qBound(imin, getDataIndex(iii), imax);
|
||||
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
|
||||
double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
|
||||
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
|
||||
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
|
||||
double x=transformX(xv);
|
||||
double y=transformY(yv);
|
||||
if (JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) {
|
||||
ps.append(QPointF(x,y));
|
||||
if (first) {
|
||||
//double xl1=xold;
|
||||
//double yl1=yold;
|
||||
//double xl2=x;
|
||||
//double yl2=y;
|
||||
QPainterPath pl, pf;
|
||||
QVector<QPointF> ps;
|
||||
|
||||
if (m_specialLineType==JKQTPStepCenter) {
|
||||
double d=(y-yold);
|
||||
pf.lineTo(xold, yold+d/2.0);
|
||||
pf.lineTo(x, yold+d/2.0);
|
||||
double xold=-1;
|
||||
double yold=-1;
|
||||
double x0=transformX(m_baseline);
|
||||
if (parent->getXAxis()->isLogAxis()) {
|
||||
if (m_baseline>0 && m_baseline>parent->getXAxis()->getMin()) x0=transformX(m_baseline);
|
||||
else x0=transformX(parent->getXAxis()->getMin());
|
||||
}
|
||||
bool first=false;
|
||||
intSortData();
|
||||
for (int iii=imin; iii<imax; iii++) {
|
||||
const int i=qBound(imin, getDataIndex(iii), imax);
|
||||
const double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
|
||||
const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
|
||||
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
|
||||
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
|
||||
const double x=transformX(xv);
|
||||
const double y=transformY(yv);
|
||||
if (JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) {
|
||||
ps.append(QPointF(x,y));
|
||||
if (first) {
|
||||
//double xl1=xold;
|
||||
//double yl1=yold;
|
||||
//double xl2=x;
|
||||
//double yl2=y;
|
||||
|
||||
if (m_specialLineType==JKQTPStepCenter) {
|
||||
double d=(y-yold);
|
||||
pf.lineTo(xold, yold+d/2.0);
|
||||
pf.lineTo(x, yold+d/2.0);
|
||||
pf.lineTo(x, y);
|
||||
if (getDrawLine()) {
|
||||
pl.lineTo(xold, yold+d/2.0);
|
||||
pl.lineTo(x, yold+d/2.0);
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPStepLeft) {
|
||||
pf.lineTo(x, yold);
|
||||
pf.lineTo(x, y);
|
||||
if (getDrawLine()) {
|
||||
pl.lineTo(x, yold);
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPStepRight) {
|
||||
pf.lineTo(xold, y);
|
||||
pf.lineTo(x, y);
|
||||
if (getDrawLine()) {
|
||||
pl.lineTo(xold, y);
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPStepAverage) {
|
||||
// x/y
|
||||
// |-------*
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// *--------|
|
||||
// xold/yold
|
||||
const double d=(x-xold);
|
||||
//const double h=(y-yold);
|
||||
pf.lineTo(xold+d/2.0, yold);
|
||||
pf.lineTo(xold+d/2.0, y);
|
||||
pf.lineTo(x,y);
|
||||
if (getDrawLine()) {
|
||||
pl.lineTo(xold+d/2.0, yold);
|
||||
pl.lineTo(xold+d/2.0, y);
|
||||
pl.lineTo(x,y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPDirectLine) {
|
||||
// x/y
|
||||
// /----*
|
||||
// /----/
|
||||
// *----/
|
||||
// xold/yold
|
||||
pf.lineTo(x, y);
|
||||
if (getDrawLine()) {
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
//std::cout<<"line ("<<xl1<<", "<<yl1<<") -- ("<<xl2<<", "<<yl2<<")"<<std::endl;
|
||||
} else {
|
||||
if (getDrawLine()) pl.moveTo(x,y);
|
||||
pf.moveTo(x0, y);
|
||||
pf.lineTo(x, y);
|
||||
if (m_drawLine) {
|
||||
pl.lineTo(xold, yold+d/2.0);
|
||||
pl.lineTo(x, yold+d/2.0);
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPStepLeft) {
|
||||
pf.lineTo(x, yold);
|
||||
pf.lineTo(x, y);
|
||||
if (m_drawLine) {
|
||||
pl.lineTo(x, yold);
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPStepRight) {
|
||||
pf.lineTo(xold, y);
|
||||
pf.lineTo(x, y);
|
||||
if (m_drawLine) {
|
||||
pl.lineTo(xold, y);
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPStepAverage) {
|
||||
// x/y
|
||||
// |-------*
|
||||
// |
|
||||
// |
|
||||
// |
|
||||
// *--------|
|
||||
// xold/yold
|
||||
const double d=(x-xold);
|
||||
//const double h=(y-yold);
|
||||
pf.lineTo(xold+d/2.0, yold);
|
||||
pf.lineTo(xold+d/2.0, y);
|
||||
pf.lineTo(x,y);
|
||||
if (m_drawLine) {
|
||||
pl.lineTo(xold+d/2.0, yold);
|
||||
pl.lineTo(xold+d/2.0, y);
|
||||
pl.lineTo(x,y);
|
||||
}
|
||||
} else if (m_specialLineType==JKQTPDirectLine) {
|
||||
// x/y
|
||||
// /----*
|
||||
// /----/
|
||||
// *----/
|
||||
// xold/yold
|
||||
pf.lineTo(x, y);
|
||||
if (m_drawLine) {
|
||||
pl.lineTo(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
//std::cout<<"line ("<<xl1<<", "<<yl1<<") -- ("<<xl2<<", "<<yl2<<")"<<std::endl;
|
||||
} else {
|
||||
if (m_drawLine) pl.moveTo(x,y);
|
||||
pf.moveTo(x0, y);
|
||||
pf.lineTo(x, y);
|
||||
xold=x;
|
||||
yold=y;
|
||||
first=true;
|
||||
}
|
||||
xold=x;
|
||||
yold=y;
|
||||
first=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
pf.lineTo(x0, yold);
|
||||
pf.closeSubpath();
|
||||
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
||||
pf.lineTo(x0, yold);
|
||||
pf.closeSubpath();
|
||||
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
||||
|
||||
if (m_fillCurve) {
|
||||
painter.fillPath(pf, b);
|
||||
}
|
||||
if (getFillCurve()) {
|
||||
painter.fillPath(pf, b);
|
||||
}
|
||||
|
||||
if (isHighlighted()) {
|
||||
painter.setBrush(QBrush(Qt::transparent));
|
||||
painter.setPen(ph);
|
||||
painter.drawPath(pl);
|
||||
}
|
||||
if (isHighlighted()) {
|
||||
painter.setBrush(QBrush(Qt::transparent));
|
||||
painter.setPen(ph);
|
||||
painter.drawPath(pl);
|
||||
}
|
||||
|
||||
if (m_drawLine) {
|
||||
painter.setBrush(QBrush(Qt::transparent));
|
||||
painter.setPen(p);
|
||||
painter.drawPath(pl);
|
||||
}
|
||||
if (getDrawLine()) {
|
||||
painter.setBrush(QBrush(Qt::transparent));
|
||||
painter.setPen(p);
|
||||
painter.drawPath(pl);
|
||||
}
|
||||
|
||||
if (m_drawSymbols) {
|
||||
painter.save();
|
||||
auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();});
|
||||
for (auto& point: ps) {
|
||||
plotStyledSymbol(parent, painter, point.x(), point.y());
|
||||
if (m_drawSymbols) {
|
||||
painter.save();
|
||||
auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();});
|
||||
for (auto& point: ps) {
|
||||
plotStyledSymbol(parent, painter, point.x(), point.y());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ class JKQTPDatastore;
|
||||
|
||||
\see JKQTPSpecialLineVerticalGraph, JKQTPFilledCurveXGraph, \ref JKQTPlotterSpecialStepLinePlot
|
||||
*/
|
||||
class JKQTPLOTTER_LIB_EXPORT JKQTPSpecialLineHorizontalGraph: public JKQTPXYGraph, public JKQTPGraphLineStyleMixin, public JKQTPGraphFillStyleMixin, public JKQTPGraphSymbolStyleMixin {
|
||||
class JKQTPLOTTER_LIB_EXPORT JKQTPSpecialLineHorizontalGraph: public JKQTPXYGraph, public JKQTPGraphLineAndFillStyleMixin, public JKQTPGraphSymbolStyleMixin {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/** \brief class constructor */
|
||||
@ -65,18 +65,11 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPSpecialLineHorizontalGraph: public JKQTPXYGrap
|
||||
/** \brief returns the color to be used for the key label */
|
||||
virtual QColor getKeyLabelColor() const override;
|
||||
|
||||
/*! sets whether to draw a line or not */
|
||||
void setDrawLine(bool __value);
|
||||
/*! returns whether the graph line is drawn */
|
||||
bool getDrawLine() const;
|
||||
|
||||
/*! sets whether to draw symbols */
|
||||
void setDrawSymbols(bool __value);
|
||||
/*! returns whether symbols are drawn */
|
||||
bool getDrawSymbols() const;
|
||||
/*! sets whether to fill the space between the curve and the baseline/x-axis */
|
||||
void setFillCurve(bool __value);
|
||||
/*! returns whether the space between the curve and the baseline/x-axis is filled */
|
||||
bool getFillCurve() const;
|
||||
/** \brief set the type of connecting (step-)lines */
|
||||
void setSpecialLineType(const JKQTPSpecialLineType & __value);
|
||||
/** \brief get the type of connecting (step-)lines */
|
||||
@ -88,12 +81,9 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPSpecialLineHorizontalGraph: public JKQTPXYGrap
|
||||
/** \brief set line-color, fill color and symbol color */
|
||||
void setColor(QColor c);
|
||||
protected:
|
||||
/** \brief indicates whether to draw a line or not */
|
||||
bool m_drawLine;
|
||||
|
||||
/** \brief indicates whether to draw a symbols or not */
|
||||
bool m_drawSymbols;
|
||||
/** \brief indicates whether to fill the space between the curve and the baseline/x-axis */
|
||||
bool m_fillCurve;
|
||||
/** \brief type of connecting (step)lines */
|
||||
JKQTPSpecialLineType m_specialLineType;
|
||||
/** \brief baseline of the plot (NOTE: 0 is interpreted as until plot border in log-mode!!!) */
|
||||
|
@ -567,7 +567,7 @@ double JKQTPGraphDecoratedHeadLineStyleMixin::calcHeadDecoratorSize(double line_
|
||||
|
||||
|
||||
JKQTPGraphLineAndFillStyleMixin::JKQTPGraphLineAndFillStyleMixin():
|
||||
m_drawLine(true)
|
||||
m_drawLine(true), m_fillCurve(true)
|
||||
{
|
||||
|
||||
}
|
||||
@ -586,3 +586,18 @@ bool JKQTPGraphLineAndFillStyleMixin::doDrawLine() const
|
||||
{
|
||||
return m_drawLine;
|
||||
}
|
||||
|
||||
void JKQTPGraphLineAndFillStyleMixin::setFillCurve(bool __value)
|
||||
{
|
||||
m_fillCurve=__value;
|
||||
}
|
||||
|
||||
bool JKQTPGraphLineAndFillStyleMixin::getFillCurve() const
|
||||
{
|
||||
return m_fillCurve;
|
||||
}
|
||||
|
||||
bool JKQTPGraphLineAndFillStyleMixin::doFillCurve() const
|
||||
{
|
||||
return m_fillCurve;
|
||||
}
|
||||
|
@ -461,10 +461,22 @@ public:
|
||||
bool getDrawLine() const;
|
||||
/*! \copydoc m_drawLine */
|
||||
bool doDrawLine() const;
|
||||
|
||||
/*! \copydoc m_fillCurve */
|
||||
void setFillCurve(bool __value);
|
||||
/*! \copydoc m_fillCurve */
|
||||
bool getFillCurve() const;
|
||||
/*! \copydoc m_fillCurve */
|
||||
bool doFillCurve() const;
|
||||
|
||||
|
||||
Q_PROPERTY(bool drawLine MEMBER m_drawLine READ getDrawLine WRITE setDrawLine)
|
||||
Q_PROPERTY(bool fillCurve MEMBER m_fillCurve READ getFillCurve WRITE setFillCurve)
|
||||
private:
|
||||
/** \brief indicates whether to draw a line on the circumference of the described area (i.e. along the data points from \c xColumn and \c yColumn as well as \c xColumn and \c yColumn2 or not */
|
||||
bool m_drawLine;
|
||||
/** \brief indicates whether to fill the space between the curve and the x-axis */
|
||||
bool m_fillCurve;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user