improved code (removed code repeats by using getIndexRange(), using const where appropriate)

This commit is contained in:
jkriege2 2020-09-19 15:39:02 +02:00
parent 7e425e7bb5
commit abe1c655ba
5 changed files with 403 additions and 498 deletions

View File

@ -53,27 +53,17 @@ void JKQTPBarVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
JKQTPAutoOutputTimer jkaaot("JKQTPBarHorizontalGraph::draw"); JKQTPAutoOutputTimer jkaaot("JKQTPBarHorizontalGraph::draw");
#endif #endif
if (parent==nullptr) return; if (parent==nullptr) return;
JKQTPDatastore* datastore=parent->getDatastore(); const JKQTPDatastore* datastore=parent->getDatastore();
if (datastore==nullptr) return; if (datastore==nullptr) return;
drawErrorsBefore(painter); drawErrorsBefore(painter);
QPen p=getLinePenForRects(painter, parent); const QPen p=getLinePenForRects(painter, parent);
const QBrush b=getFillBrush(painter, parent);
QBrush b=getFillBrush(painter, parent); int imax=0;
int imax=static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn))));
int imin=0; int imin=0;
if (getIndexRange(imin, imax)) {
if (imax<imin) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
{
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
// double x0=transformX(0); // double x0=transformX(0);
@ -87,9 +77,9 @@ void JKQTPBarVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
const bool hasStackPar=hasStackParent(); const bool hasStackPar=hasStackParent();
for (int iii=imin; iii<imax; iii++) { for (int iii=imin; iii<imax; iii++) {
int i=qBound(imin, getDataIndex(iii), imax); int i=qBound(imin, getDataIndex(iii), imax);
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i)); const double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
int sr=datastore->getNextLowerIndex(xColumn, i); const int sr=datastore->getNextLowerIndex(xColumn, i);
int lr=datastore->getNextHigherIndex(xColumn, i); const int lr=datastore->getNextHigherIndex(xColumn, i);
double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i)); double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
double yv0=y0; double yv0=y0;
if (!qFuzzyIsNull(getBaseline())) yv0=transformY(getBaseline()); if (!qFuzzyIsNull(getBaseline())) yv0=transformY(getBaseline());
@ -114,9 +104,9 @@ void JKQTPBarVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
delta=deltap+deltam; delta=deltap+deltam;
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) { if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
double x=transformX(xv+shift*delta-width*deltam); const double x=transformX(xv+shift*delta-width*deltam);
double y=transformY(yv); double y=transformY(yv);
double xx=transformX(xv+shift*delta+width*deltap); const double xx=transformX(xv+shift*delta+width*deltap);
double yy=yv0; double yy=yv0;
//std::cout<<"delta="<<delta<<" x="<<x<<" y="<<y<<" xx="<<xx<<" yy="<<yy<<std::endl; //std::cout<<"delta="<<delta<<" x="<<x<<" y="<<y<<" xx="<<xx<<" yy="<<yy<<std::endl;
@ -239,24 +229,17 @@ void JKQTPBarHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
JKQTPAutoOutputTimer jkaaot("JKQTPBarVerticalGraph::draw"); JKQTPAutoOutputTimer jkaaot("JKQTPBarVerticalGraph::draw");
#endif #endif
if (parent==nullptr) return; if (parent==nullptr) return;
JKQTPDatastore* datastore=parent->getDatastore(); const JKQTPDatastore* datastore=parent->getDatastore();
if (datastore==nullptr) return; if (datastore==nullptr) return;
drawErrorsBefore(painter); drawErrorsBefore(painter);
QPen p=getLinePenForRects(painter, parent); const QPen p=getLinePenForRects(painter, parent);
const QBrush b=getFillBrush(painter, parent);
QBrush b=getFillBrush(painter, parent); int imax=0;
int imax=static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn))));
int imin=0; int imin=0;
if (imax<imin) { if (getIndexRange(imin, imax)) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
double x0=transformX(0); double x0=transformX(0);
if (parent->getXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin()); if (parent->getXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin());
@ -315,7 +298,7 @@ void JKQTPBarHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
} }
} }
} }
}
} }
drawErrorsAfter(painter); drawErrorsAfter(painter);
} }
@ -363,21 +346,15 @@ bool JKQTPBarHorizontalErrorGraph::getXMinMax(double &minx, double &maxx, double
if (parent==nullptr) return false; if (parent==nullptr) return false;
JKQTPDatastore* datastore=parent->getDatastore(); const JKQTPDatastore* datastore=parent->getDatastore();
int imax=0;
int imin=0; int imin=0;
int imax=static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn)))); if (getIndexRange(imin, imax)) {
if (imax<imin) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
for (int i=imin; i<imax; i++) { for (int i=imin; i<imax; i++) {
double xvsgz; double xvsgz;
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))+getXErrorU(i, datastore); const double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))+getXErrorU(i, datastore);
double xvv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))-getXErrorL(i, datastore); const double xvv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))-getXErrorL(i, datastore);
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(xvv) ) { if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(xvv) ) {
if (start || xv>maxx) maxx=xv; if (start || xv>maxx) maxx=xv;
if (start || xv<minx) minx=xv; if (start || xv<minx) minx=xv;
@ -391,6 +368,8 @@ bool JKQTPBarHorizontalErrorGraph::getXMinMax(double &minx, double &maxx, double
} }
return !start; return !start;
} }
return false;
}
} }
void JKQTPBarHorizontalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter) void JKQTPBarHorizontalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter)
@ -465,15 +444,10 @@ bool JKQTPBarVerticalErrorGraph::getYMinMax(double &miny, double &maxy, double &
if (parent==nullptr) return false; if (parent==nullptr) return false;
JKQTPDatastore* datastore=parent->getDatastore(); JKQTPDatastore* datastore=parent->getDatastore();
int imax=0;
int imin=0; int imin=0;
int imax=static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn)))); if (getIndexRange(imin, imax)) {
if (imax<imin) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
for (int i=imin; i<imax; i++) { for (int i=imin; i<imax; i++) {
double yv=getBaseline(); double yv=getBaseline();
@ -492,6 +466,7 @@ bool JKQTPBarVerticalErrorGraph::getYMinMax(double &miny, double &maxy, double &
} }
} }
return true; return true;
}
} else { } else {
bool start=false; bool start=false;
miny=getBaseline(); miny=getBaseline();
@ -505,21 +480,15 @@ bool JKQTPBarVerticalErrorGraph::getYMinMax(double &miny, double &maxy, double &
if (parent==nullptr) return false; if (parent==nullptr) return false;
JKQTPDatastore* datastore=parent->getDatastore(); const JKQTPDatastore* datastore=parent->getDatastore();
int imax=0;
int imin=0; int imin=0;
int imax=static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn)))); if (getIndexRange(imin, imax)) {
if (imax<imin) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
for (int i=imin; i<imax; i++) { for (int i=imin; i<imax; i++) {
double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))+getYErrorU(i, datastore); const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))+getYErrorU(i, datastore);
double yvv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))-getYErrorL(i, datastore); const double yvv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))-getYErrorL(i, datastore);
if (JKQTPIsOKFloat(yv) && JKQTPIsOKFloat(yvv) ) { if (JKQTPIsOKFloat(yv) && JKQTPIsOKFloat(yvv) ) {
if (start || yv>maxy) maxy=yv; if (start || yv>maxy) maxy=yv;
if (start || yv<miny) miny=yv; if (start || yv<miny) miny=yv;
@ -534,6 +503,8 @@ bool JKQTPBarVerticalErrorGraph::getYMinMax(double &miny, double &maxy, double &
return !start; return !start;
} }
} }
return false;
}
int JKQTPBarVerticalErrorGraph::getBarErrorColumn() const int JKQTPBarVerticalErrorGraph::getBarErrorColumn() const
{ {

View File

@ -93,47 +93,30 @@ void JKQTPImpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
QPen p=getLinePen(painter, parent); QPen p=getLinePen(painter, parent);
p.setCapStyle(Qt::FlatCap); p.setCapStyle(Qt::FlatCap);
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; int imin=0;
if (imax<imin) { if (getIndexRange(imin, imax)) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
//double xold=-1;
//double yold=-1;
double x0=transformX(getBaseline()); double x0=transformX(getBaseline());
if (parent->getXAxis()->isLogAxis()) { if (parent->getXAxis()->isLogAxis()) {
if (getBaseline()>0 && getBaseline()>parent->getXAxis()->getMin()) x0=transformX(getBaseline()); if (getBaseline()>0 && getBaseline()>parent->getXAxis()->getMin()) x0=transformX(getBaseline());
else x0=transformX(parent->getXAxis()->getMin()); else x0=transformX(parent->getXAxis()->getMin());
} }
// double y0=transformY(getBaseline());
// if (parent->getYAxis()->isLogAxis()) {
// y0=transformY(parent->getYAxis()->getMin());
// if (getBaseline()>0 && getBaseline()>parent->getYAxis()->getMin()) y0=transformY(getBaseline());
// else y0=transformY(parent->getYAxis()->getMin());
// }
//bool first=false;
QVector<QLineF> lines; QVector<QLineF> lines;
QVector<QPointF> points; QVector<QPointF> points;
intSortData(); intSortData();
for (int iii=imin; iii<imax; iii++) { for (int iii=imin; iii<imax; iii++) {
int i=qBound(imin, getDataIndex(iii), imax); const int i=qBound(imin, getDataIndex(iii), imax);
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i)); const 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)); const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) { if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
double x=transformX(xv); const double x=transformX(xv);
double y=transformY(yv); const double y=transformY(yv);
lines.append(QLineF(x0, y, x, y)); lines.append(QLineF(x0, y, x, y));
points.append(QPointF(x,y)); points.append(QPointF(x,y));
// xold=x;
// yold=y;
//first=true;
} }
} }
painter.setPen(p); painter.setPen(p);
@ -144,6 +127,7 @@ void JKQTPImpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
plotStyledSymbol(parent, painter, p.x(), p.y()); plotStyledSymbol(parent, painter, p.x(), p.y());
} }
} }
}
} }
drawErrorsAfter(painter); drawErrorsAfter(painter);
@ -210,24 +194,12 @@ void JKQTPImpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
QPen p=getLinePen(painter, parent); QPen p=getLinePen(painter, parent);
p.setCapStyle(Qt::FlatCap); p.setCapStyle(Qt::FlatCap);
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; int imin=0;
if (imax<imin) { if (getIndexRange(imin, imax)) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
//double xold=-1;
//double yold=-1;
//bool first=false;
// double x0=transformX(getBaseline());
// if (parent->getXAxis()->isLogAxis()) {
// if (getBaseline()>0 && getBaseline()>parent->getXAxis()->getMin()) x0=transformX(getBaseline());
// else x0=transformX(parent->getXAxis()->getMin());
// }
double y0=transformY(getBaseline()); double y0=transformY(getBaseline());
if (parent->getYAxis()->isLogAxis()) { if (parent->getYAxis()->isLogAxis()) {
y0=transformY(parent->getYAxis()->getMin()); y0=transformY(parent->getYAxis()->getMin());
@ -238,19 +210,17 @@ void JKQTPImpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
QVector<QPointF> points; QVector<QPointF> points;
intSortData(); intSortData();
for (int iii=imin; iii<imax; iii++) { for (int iii=imin; iii<imax; iii++) {
int i=qBound(imin, getDataIndex(iii), imax); const int i=qBound(imin, getDataIndex(iii), imax);
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i)); const 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)); const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv) ) { if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv) ) {
double x=transformX(xv); const double x=transformX(xv);
double y=transformY(yv); const double y=transformY(yv);
lines.append(QLineF(x, y0, x, y)); lines.append(QLineF(x, y0, x, y));
points.append(QPointF(x,y)); points.append(QPointF(x,y));
//xold=x;
//yold=y;
//first=true;
} }
} }
painter.setPen(p); painter.setPen(p);
@ -262,6 +232,7 @@ void JKQTPImpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
} }
} }
} }
}
drawErrorsAfter(painter); drawErrorsAfter(painter);
} }

View File

@ -61,7 +61,7 @@ void JKQTPXYLineGraph::draw(JKQTPEnhancedPainter& painter) {
JKQTPAutoOutputTimer jkaaot("JKQTPXYLineGraph::draw"); JKQTPAutoOutputTimer jkaaot("JKQTPXYLineGraph::draw");
#endif #endif
if (parent==nullptr) return; if (parent==nullptr) return;
JKQTPDatastore* datastore=parent->getDatastore(); const JKQTPDatastore* datastore=parent->getDatastore();
if (datastore==nullptr) return; if (datastore==nullptr) return;
//qDebug()<<"JKQTPXYLineGraph::draw();"; //qDebug()<<"JKQTPXYLineGraph::draw();";
@ -72,32 +72,24 @@ void JKQTPXYLineGraph::draw(JKQTPEnhancedPainter& painter) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
//qDebug()<<"JKQTPXYLineGraph::draw(): "<<2; //qDebug()<<"JKQTPXYLineGraph::draw(): "<<2;
QPen p=getLinePen(painter, parent); const QPen p=getLinePen(painter, parent);
const QPen penSelection=getHighlightingLinePen(painter, parent);
QPen penSelection=getHighlightingLinePen(painter, parent); int imax=0;
int imax= static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn))));
int imin=0; int imin=0;
if (getIndexRange(imin, imax)) {
if (imax<imin) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
std::vector<QPolygonF> vec_linesP; std::vector<QPolygonF> vec_linesP;
vec_linesP.push_back(QPolygonF()); vec_linesP.push_back(QPolygonF());
intSortData(); intSortData();
for (int iii=imin; iii<imax; iii++) { for (int iii=imin; iii<imax; iii++) {
int i=qBound(imin, getDataIndex(iii), imax); const int i=qBound(imin, getDataIndex(iii), imax);
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i)); const 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)); const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
double x=transformX(xv); const double x=transformX(xv);
double y=transformY(yv); const double y=transformY(yv);
//qDebug()<<"JKQTPXYLineGraph::draw(): (xv, yv) = ( "<<xv<<", "<<yv<<" )"; //qDebug()<<"JKQTPXYLineGraph::draw(): (xv, yv) = ( "<<xv<<", "<<yv<<" )";
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv) && JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) { if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv) && JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) {
@ -130,6 +122,7 @@ void JKQTPXYLineGraph::draw(JKQTPEnhancedPainter& painter) {
} }
//qDebug()<<"JKQTPXYLineGraph::draw(): "<<6; //qDebug()<<"JKQTPXYLineGraph::draw(): "<<6;
} }
}
//qDebug()<<"JKQTPXYLineGraph::draw(): "<<7; //qDebug()<<"JKQTPXYLineGraph::draw(): "<<7;
drawErrorsAfter(painter); drawErrorsAfter(painter);
//qDebug()<<"JKQTPXYLineGraph::draw() ... done"; //qDebug()<<"JKQTPXYLineGraph::draw() ... done";
@ -205,18 +198,10 @@ bool JKQTPXYLineErrorGraph::getXMinMax(double &minx, double &maxx, double &small
if (parent==nullptr) return false; if (parent==nullptr) return false;
JKQTPDatastore* datastore=parent->getDatastore(); const JKQTPDatastore* datastore=parent->getDatastore();
int imax=0;
int imin=0; int imin=0;
int imax= static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn)))); if (getIndexRange(imin, imax)) {
if (imax<imin) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
for (int i=imin; i<imax; i++) { for (int i=imin; i<imax; i++) {
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))+getXErrorU(i, datastore); double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))+getXErrorU(i, datastore);
if (JKQTPIsOKFloat(xv)) { if (JKQTPIsOKFloat(xv)) {
@ -236,6 +221,8 @@ bool JKQTPXYLineErrorGraph::getXMinMax(double &minx, double &maxx, double &small
return !start; return !start;
} }
} }
return false;
}
bool JKQTPXYLineErrorGraph::getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) { bool JKQTPXYLineErrorGraph::getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) {
if (yErrorColumn<0 || yErrorStyle==JKQTPNoError) { if (yErrorColumn<0 || yErrorStyle==JKQTPNoError) {
@ -248,18 +235,10 @@ bool JKQTPXYLineErrorGraph::getYMinMax(double &miny, double &maxy, double &small
if (parent==nullptr) return false; if (parent==nullptr) return false;
JKQTPDatastore* datastore=parent->getDatastore(); const JKQTPDatastore* datastore=parent->getDatastore();
int imax=0;
int imin=0; int imin=0;
int imax= static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn)))); if (getIndexRange(imin, imax)) {
if (imax<imin) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
for (int i=imin; i<imax; i++) { for (int i=imin; i<imax; i++) {
double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))+getYErrorU(i, datastore); double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))+getYErrorU(i, datastore);
if (JKQTPIsOKFloat(yv)) { if (JKQTPIsOKFloat(yv)) {
@ -279,6 +258,8 @@ bool JKQTPXYLineErrorGraph::getYMinMax(double &miny, double &maxy, double &small
return !start; return !start;
} }
} }
return false;
}
bool JKQTPXYLineErrorGraph::usesColumn(int c) const bool JKQTPXYLineErrorGraph::usesColumn(int c) const
{ {
@ -359,21 +340,14 @@ void JKQTPXYParametrizedScatterGraph::draw(JKQTPEnhancedPainter &painter)
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
QPen p=getLinePen(painter, parent); const QPen p=getLinePen(painter, parent);
const QPen penSelection=getHighlightingLinePen(painter, parent);
QPen penSelection=getHighlightingLinePen(painter, parent); int imax=0;
int imax= static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn))));
int imin=0; int imin=0;
if (imax<imin) { if (getIndexRange(imin, imax)) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
QVector<QLineF> lines; QVector<QLineF> lines;
QPolygonF linesP; QPolygonF linesP;
@ -479,6 +453,7 @@ void JKQTPXYParametrizedScatterGraph::draw(JKQTPEnhancedPainter &painter)
} }
} }
}
drawErrorsAfter(painter); drawErrorsAfter(painter);
} }
@ -897,18 +872,10 @@ bool JKQTPXYParametrizedErrorScatterGraph::getXMinMax(double &minx, double &maxx
if (parent==nullptr) return false; if (parent==nullptr) return false;
JKQTPDatastore* datastore=parent->getDatastore(); const JKQTPDatastore* datastore=parent->getDatastore();
int imax=0;
int imin=0; int imin=0;
int imax= static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn)))); if (getIndexRange(imin, imax)) {
if (imax<imin) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
for (int i=imin; i<imax; i++) { for (int i=imin; i<imax; i++) {
const double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))+getXErrorU(i, datastore); const double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))+getXErrorU(i, datastore);
if (JKQTPIsOKFloat(xv) ) { if (JKQTPIsOKFloat(xv) ) {
@ -928,6 +895,8 @@ bool JKQTPXYParametrizedErrorScatterGraph::getXMinMax(double &minx, double &maxx
return !start; return !start;
} }
} }
return false;
}
bool JKQTPXYParametrizedErrorScatterGraph::getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) bool JKQTPXYParametrizedErrorScatterGraph::getYMinMax(double &miny, double &maxy, double &smallestGreaterZero)
{ {
@ -941,18 +910,10 @@ bool JKQTPXYParametrizedErrorScatterGraph::getYMinMax(double &miny, double &maxy
if (parent==nullptr) return false; if (parent==nullptr) return false;
JKQTPDatastore* datastore=parent->getDatastore(); const JKQTPDatastore* datastore=parent->getDatastore();
int imax=0;
int imin=0; int imin=0;
int imax= static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn)))); if (getIndexRange(imin, imax)) {
if (imax<imin) {
int h=imin;
imin=imax;
imax=h;
}
if (imin<0) imin=0;
if (imax<0) imax=0;
for (int i=imin; i<imax; i++) { for (int i=imin; i<imax; i++) {
const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))+getYErrorU(i, datastore); const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))+getYErrorU(i, datastore);
if (JKQTPIsOKFloat(yv)) { if (JKQTPIsOKFloat(yv)) {
@ -972,6 +933,8 @@ bool JKQTPXYParametrizedErrorScatterGraph::getYMinMax(double &miny, double &maxy
return !start; return !start;
} }
} }
return false;
}
bool JKQTPXYParametrizedErrorScatterGraph::usesColumn(int c) const bool JKQTPXYParametrizedErrorScatterGraph::usesColumn(int c) const
{ {

View File

@ -623,7 +623,7 @@ void JKQTPXGraphErrorData::setXErrorColumnLower(int __value) {
} }
double JKQTPXGraphErrorData::getXErrorU(int i, JKQTPDatastore *ds) const double JKQTPXGraphErrorData::getXErrorU(int i, const JKQTPDatastore *ds) const
{ {
if (ds && xErrorColumn>=0 && i>=0 && i<static_cast<int>(ds->getRows(xErrorColumn))) { if (ds && xErrorColumn>=0 && i>=0 && i<static_cast<int>(ds->getRows(xErrorColumn))) {
return ds->get(xErrorColumn, static_cast<size_t>(i)); return ds->get(xErrorColumn, static_cast<size_t>(i));
@ -631,7 +631,7 @@ double JKQTPXGraphErrorData::getXErrorU(int i, JKQTPDatastore *ds) const
return 0.0; return 0.0;
} }
double JKQTPXGraphErrorData::getXErrorL(int i, JKQTPDatastore *ds) const double JKQTPXGraphErrorData::getXErrorL(int i, const JKQTPDatastore *ds) const
{ {
if (ds) { if (ds) {
if (xErrorSymmetric) { if (xErrorSymmetric) {
@ -699,7 +699,7 @@ void JKQTPYGraphErrorData::setYErrorColumnLower(int __value) {
} }
double JKQTPYGraphErrorData::getYErrorU(int i, JKQTPDatastore *ds) const double JKQTPYGraphErrorData::getYErrorU(int i, const JKQTPDatastore *ds) const
{ {
if (ds && yErrorColumn>=0 && i>=0 && i<static_cast<int>(ds->getRows(yErrorColumn))) { if (ds && yErrorColumn>=0 && i>=0 && i<static_cast<int>(ds->getRows(yErrorColumn))) {
return ds->get(yErrorColumn, static_cast<size_t>(i)); return ds->get(yErrorColumn, static_cast<size_t>(i));
@ -707,7 +707,7 @@ double JKQTPYGraphErrorData::getYErrorU(int i, JKQTPDatastore *ds) const
return 0.0; return 0.0;
} }
double JKQTPYGraphErrorData::getYErrorL(int i, JKQTPDatastore *ds) const double JKQTPYGraphErrorData::getYErrorL(int i, const JKQTPDatastore *ds) const
{ {
if (ds) { if (ds) {
if (yErrorSymmetric) { if (yErrorSymmetric) {
@ -735,7 +735,7 @@ bool JKQTPXGraphErrors::errorUsesColumn(int c) const
return c==(xErrorColumn) || (c==xErrorColumnLower); return c==(xErrorColumn) || (c==xErrorColumnLower);
} }
void JKQTPXGraphErrors::plotErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph *parentGraph, int xColumn, int yColumn, double xrelshift, double yrelshift, const QVector<int>* dataorder) const { void JKQTPXGraphErrors::plotErrorIndicators(JKQTPEnhancedPainter& painter, const JKQTBasePlotter* parent, const JKQTPGraph *parentGraph, int xColumn, int yColumn, double xrelshift, double yrelshift, const QVector<int>* dataorder) const {
intPlotXYErrorIndicators(painter, parent, parentGraph, xColumn, yColumn, xErrorColumn, -1, xErrorStyle, JKQTPNoError, xErrorColumnLower, -1, xErrorSymmetric, true, xrelshift, yrelshift, dataorder); intPlotXYErrorIndicators(painter, parent, parentGraph, xColumn, yColumn, xErrorColumn, -1, xErrorStyle, JKQTPNoError, xErrorColumnLower, -1, xErrorSymmetric, true, xrelshift, yrelshift, dataorder);
} }
@ -747,7 +747,7 @@ JKQTPYGraphErrors::JKQTPYGraphErrors()
{ {
} }
void JKQTPYGraphErrors::plotErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift, double yrelshift, const QVector<int>* dataorder) const { void JKQTPYGraphErrors::plotErrorIndicators(JKQTPEnhancedPainter& painter, const JKQTBasePlotter* parent, const JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift, double yrelshift, const QVector<int>* dataorder) const {
intPlotXYErrorIndicators(painter, parent, parentGraph, xColumn, yColumn, -1, yErrorColumn, JKQTPNoError, yErrorStyle, -1, yErrorColumnLower, true, yErrorSymmetric, xrelshift, yrelshift, dataorder); intPlotXYErrorIndicators(painter, parent, parentGraph, xColumn, yColumn, -1, yErrorColumn, JKQTPNoError, yErrorStyle, -1, yErrorColumnLower, true, yErrorSymmetric, xrelshift, yrelshift, dataorder);
} }
@ -767,7 +767,7 @@ JKQTPXYGraphErrors::JKQTPXYGraphErrors()
} }
void JKQTPXYGraphErrors::plotErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift, double yrelshift, const QVector<int>* dataorder) const { void JKQTPXYGraphErrors::plotErrorIndicators(JKQTPEnhancedPainter& painter, const JKQTBasePlotter* parent, const JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift, double yrelshift, const QVector<int>* dataorder) const {
this->intPlotXYErrorIndicators(painter, parent, parentGraph, xColumn, yColumn, xErrorColumn, yErrorColumn, xErrorStyle, yErrorStyle, xErrorColumnLower, yErrorColumnLower, xErrorSymmetric, yErrorSymmetric, xrelshift, yrelshift, dataorder); this->intPlotXYErrorIndicators(painter, parent, parentGraph, xColumn, yColumn, xErrorColumn, yErrorColumn, xErrorStyle, yErrorStyle, xErrorColumnLower, yErrorColumnLower, xErrorSymmetric, yErrorSymmetric, xrelshift, yrelshift, dataorder);
} }

View File

@ -227,9 +227,9 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPXGraphErrorData {
JKQTPErrorPlotstyle xErrorStyle; JKQTPErrorPlotstyle xErrorStyle;
/** \brief returns the upper x-error for the i-th datapoint, read from datastore \a ds */ /** \brief returns the upper x-error for the i-th datapoint, read from datastore \a ds */
virtual double getXErrorU(int i, JKQTPDatastore* ds) const; virtual double getXErrorU(int i, const JKQTPDatastore* ds) const;
/** \brief returns the lower x-error for the i-th datapoint, read from datastore \a ds */ /** \brief returns the lower x-error for the i-th datapoint, read from datastore \a ds */
virtual double getXErrorL(int i, JKQTPDatastore* ds) const; virtual double getXErrorL(int i, const JKQTPDatastore *ds) const;
}; };
@ -277,9 +277,9 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPYGraphErrorData {
JKQTPErrorPlotstyle yErrorStyle; JKQTPErrorPlotstyle yErrorStyle;
/** \brief returns the upper y-error for the i-th datapoint, read from datastore \a ds */ /** \brief returns the upper y-error for the i-th datapoint, read from datastore \a ds */
virtual double getYErrorU(int i, JKQTPDatastore* ds) const; virtual double getYErrorU(int i, const JKQTPDatastore* ds) const;
/** \brief returns the lower y-error for the i-th datapoint, read from datastore \a ds */ /** \brief returns the lower y-error for the i-th datapoint, read from datastore \a ds */
virtual double getYErrorL(int i, JKQTPDatastore* ds) const; virtual double getYErrorL(int i, const JKQTPDatastore* ds) const;
}; };
@ -301,7 +301,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPXGraphErrors: public JKQTPXGraphErrorData, pub
protected: protected:
/** \brief draws the error indicators */ /** \brief draws the error indicators */
virtual void plotErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift=0, double yrelshift=0.0, const QVector<int> *dataorder=nullptr) const ; virtual void plotErrorIndicators(JKQTPEnhancedPainter& painter, const JKQTBasePlotter* parent, const JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift=0, double yrelshift=0.0, const QVector<int> *dataorder=nullptr) const ;
}; };
@ -323,7 +323,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPYGraphErrors: public JKQTPYGraphErrorData, pub
protected: protected:
/** \brief draws the error indicators */ /** \brief draws the error indicators */
virtual void plotErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift=0, double yrelshift=0.0, const QVector<int> *dataorder=nullptr) const ; virtual void plotErrorIndicators(JKQTPEnhancedPainter& painter, const JKQTBasePlotter* parent, const JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift=0, double yrelshift=0.0, const QVector<int> *dataorder=nullptr) const ;
}; };
@ -347,7 +347,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPXYGraphErrors: public JKQTPXGraphErrorData, pu
protected: protected:
/** \brief draws the error indicators */ /** \brief draws the error indicators */
virtual void plotErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift=0, double yrelshift=0.0, const QVector<int> *dataorder=nullptr) const ; virtual void plotErrorIndicators(JKQTPEnhancedPainter& painter, const JKQTBasePlotter* parent, const JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift=0, double yrelshift=0.0, const QVector<int> *dataorder=nullptr) const ;
}; };