From 9e48a2e59e3b602b61708b07d963cdd949d1f561 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Sat, 19 Sep 2020 19:17:35 +0200 Subject: [PATCH] improved/breaking change: reworked class hierarchy of filled line graphs --- doc/dox/whatsnew.dox | 1 + lib/jkqtplotter/graphs/jkqtpfilledcurve.cpp | 218 +++++++++++++++++++- lib/jkqtplotter/graphs/jkqtpfilledcurve.h | 35 +++- 3 files changed, 242 insertions(+), 12 deletions(-) diff --git a/doc/dox/whatsnew.dox b/doc/dox/whatsnew.dox index a26ec32eb7..49eeca55ae 100644 --- a/doc/dox/whatsnew.dox +++ b/doc/dox/whatsnew.dox @@ -29,6 +29,7 @@ Changes, compared to \ref page_whatsnew_V2019_11 "v2019.11" include:
  • improved/breaking change: reworked class hierarchy of bar & impulse charts.
  • improved/breaking change: reworked class hierarchy of range charts.
  • improved/breaking change: reworked class hierarchy of special line (step) graphs.
  • +
  • improved/breaking change: reworked class hierarchy of filled line graphs.
  • improved/breaking change: reworked graph Base-Classes (promoted several setters to slots, added Q_PROPERTY- and Q_ENUM-declarations...)
  • improved/breaking change: made more functions and function parameters const
  • bugfixed/improved: aspect ratio handling in JKQTPlotter.
  • diff --git a/lib/jkqtplotter/graphs/jkqtpfilledcurve.cpp b/lib/jkqtplotter/graphs/jkqtpfilledcurve.cpp index f24f449cbb..a12136fa47 100644 --- a/lib/jkqtplotter/graphs/jkqtpfilledcurve.cpp +++ b/lib/jkqtplotter/graphs/jkqtpfilledcurve.cpp @@ -32,17 +32,50 @@ +JKQTPFilledCurveGraphBase::JKQTPFilledCurveGraphBase(JKQTBasePlotter *parent): + JKQTPXYBaselineGraph(parent) +{ + parentPlotStyle=-1; + initLineStyle(parent, parentPlotStyle); + initFillStyle(parent, parentPlotStyle); + setFillCurve(true); + setDrawLine(true); +} + +QColor JKQTPFilledCurveGraphBase::getKeyLabelColor() const +{ + return getLineColor(); +} + +void JKQTPFilledCurveGraphBase::drawKeyMarker(JKQTPEnhancedPainter &painter, QRectF &rect) +{ + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + QPen p=getLinePen(painter, parent); + QPen np(Qt::NoPen); + QBrush b=getFillBrush(painter, parent); + const double y=rect.top()+rect.height()/2.0; + painter.setPen(np); + if (getDrawLine()) painter.setPen(p); + painter.setBrush(b); + if (getFillCurve()) painter.drawRect(rect); + if (!getFillCurve() && getDrawLine()) painter.drawLine(QLineF(rect.left(), y, rect.right(), y)); +} + +void JKQTPFilledCurveGraphBase::setColor(QColor c) +{ + setLineColor(c); + setFillColor(JKQTPGetDerivedColor(parent->getCurrentPlotterStyle().graphFillColorDerivationMode, c)); + c.setAlphaF(0.5); + setHighlightingLineColor(c); +} JKQTPFilledCurveXGraph::JKQTPFilledCurveXGraph(JKQTBasePlotter* parent): - JKQTPSpecialLineHorizontalGraph(parent) + JKQTPFilledCurveGraphBase(parent) { - setDrawLine(true); - setDrawSymbols(false); - setFillCurve(true); - setSpecialLineType(JKQTPDirectLine); + } JKQTPFilledCurveXGraph::JKQTPFilledCurveXGraph(JKQTPlotter *parent): @@ -51,15 +84,95 @@ JKQTPFilledCurveXGraph::JKQTPFilledCurveXGraph(JKQTPlotter *parent): } +void JKQTPFilledCurveXGraph::draw(JKQTPEnhancedPainter& painter) { +#ifdef JKQTBP_AUTOTIMER + JKQTPAutoOutputTimer jkaaot("JKQTPFilledCurveXGraph::draw"); +#endif + if (parent==nullptr) return; + JKQTPDatastore* datastore=parent->getDatastore(); + if (datastore==nullptr) return; + drawErrorsBefore(painter); + + QPen p=getLinePen(painter, parent); + QPen ph=getHighlightingLinePen(painter, parent); + QPen np(Qt::NoPen); + QBrush b=getFillBrush(painter, parent); + + int imax=0; + int imin=0; + + if (getIndexRange(imin, imax)) { + + + QPainterPath pl, pf; + + double xold=-1; + double yold=-1; + 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 subsequentItem=false; + intSortData(); + for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); + const double yv=datastore->get(static_cast(yColumn),static_cast(i)); + //std::cout<<"(xv, yv) = ( "<getDatastore(); + if (datastore==nullptr) return; + + drawErrorsBefore(painter); + + QPen p=getLinePen(painter, parent); + QPen ph=getHighlightingLinePen(painter, parent); + QPen np(Qt::NoPen); + QBrush b=getFillBrush(painter, parent); + + int imax=0; + int imin=0; + + if (getIndexRange(imin, imax)) { + + + QPainterPath pl, pf; + + double xold=-1; + double yold=-1; + double x0=transformX(getBaseline()); + if (parent->getXAxis()->isLogAxis()) { + if (getBaseline()>0 && getBaseline()>parent->getXAxis()->getMin()) x0=transformX(getBaseline()); + else x0=transformX(parent->getXAxis()->getMin()); + } + bool first=false; + intSortData(); + for (int iii=imin; iiiget(static_cast(xColumn),static_cast(i)); + const double yv=datastore->get(static_cast(yColumn),static_cast(i)); + //std::cout<<"(xv, yv) = ( "<