diff --git a/doc/dox/whatsnew.dox b/doc/dox/whatsnew.dox index 87a8001645..2452dea3de 100644 --- a/doc/dox/whatsnew.dox +++ b/doc/dox/whatsnew.dox @@ -28,6 +28,7 @@ Changes, compared to \ref page_whatsnew_V2019_11 "v2019.11" include:
  • improved/breaking change: reworked class hierarchy of parsed function plots and declared several setters as slots.
  • improved/breaking change: reworked class hierarchy of bar charts.
  • 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.
  • new: added geometric plot objects JKQTPGeoArrow to draw arrows (aka lines with added line-end decorators, also extended JKQTPGeoLine, JKQTPGeoInfiniteLine, JKQTPGeoPolyLines to draw line-end decorator (aka arrows)
  • new: all geometric objects can either be drawn as graphic element (i.e. lines are straight line, even on non-linear axes), or as mathematical curve (i.e. on non-linear axes, lines become the appropriate curve representing the linear function, connecting the given start/end-points). The only exceptions are ellipses (and the derived arcs,pies,chords), which are always drawn as mathematical curves
  • diff --git a/lib/jkqtplotter/graphs/jkqtpbarchartbase.cpp b/lib/jkqtplotter/graphs/jkqtpbarchartbase.cpp index d7d95900f6..e3686236ea 100644 --- a/lib/jkqtplotter/graphs/jkqtpbarchartbase.cpp +++ b/lib/jkqtplotter/graphs/jkqtpbarchartbase.cpp @@ -173,45 +173,40 @@ bool JKQTPBarGraphBase::getValuesMinMax(double &mmin, double &mmax, double &smal if (getBarPositionColumn()<0 || getBarHeightColumn()<0) return false; - const size_t poscol=static_cast(getBarPositionColumn()); const size_t datacol=static_cast(getBarHeightColumn()); if (parent==nullptr) return false; - JKQTPDatastore* datastore=parent->getDatastore(); - int imin=0; - int imax=static_cast(qMin(datastore->getRows(poscol), datastore->getRows(datacol))); - if (imaxgetDatastore(); + int imin=0, imax=0; + if (getIndexRange(imin, imax)) { - for (int i=imin; immax) mmax=yv; - if (yvget(datacol,static_cast(i)); - if (JKQTPIsOKFloat(yv)) { - if (yv>mmax) mmax=yv; - if (yvmmax) mmax=yv; + if (yvget(datacol,static_cast(i)); + if (JKQTPIsOKFloat(yv)) { + if (yv>mmax) mmax=yv; + if (yv(getBarPositionColumn()); - const size_t datacol=static_cast(getBarHeightColumn()); if (parent==nullptr) return false; - JKQTPDatastore* datastore=parent->getDatastore(); - int imin=0; - int imax=static_cast(qMin(datastore->getRows(poscol), datastore->getRows(datacol))); - if (imaxgetDatastore(); + int imin=0, imax=0; + if (getIndexRange(imin, imax)) { + for (int i=imin; iget(poscol,static_cast(i)); + int sr=datastore->getNextLowerIndex(poscol, i); + int lr=datastore->getNextHigherIndex(poscol, i); + double delta, deltap, deltam; - for (int i=imin; iget(poscol,static_cast(i)); - int sr=datastore->getNextLowerIndex(poscol, i); - int lr=datastore->getNextHigherIndex(poscol, i); - double delta, deltap, deltam; + if (sr<0 && lr<0) { // only one x-value + deltam=0.5; + deltap=0.5; + } else if (lr<0) { // the right-most x-value + deltap=deltam=fabs(xv-datastore->get(poscol,sr))/2.0; + } else if (sr<0) { // the left-most x-value + deltam=deltap=fabs(datastore->get(poscol,lr)-xv)/2.0; + } else { + deltam=fabs(xv-datastore->get(poscol,sr))/2.0; + deltap=fabs(datastore->get(poscol,lr)-xv)/2.0; + } + delta=deltap+deltam; - if (sr<0 && lr<0) { // only one x-value - deltam=0.5; - deltap=0.5; - } else if (lr<0) { // the right-most x-value - deltap=deltam=fabs(xv-datastore->get(poscol,sr))/2.0; - } else if (sr<0) { // the left-most x-value - deltam=deltap=fabs(datastore->get(poscol,lr)-xv)/2.0; - } else { - deltam=fabs(xv-datastore->get(poscol,sr))/2.0; - deltap=fabs(datastore->get(poscol,lr)-xv)/2.0; - } - delta=deltap+deltam; - - if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(delta) ) { - - if (start || xv+shift*delta+width*delta/2.0>mmax) mmax=xv+shift*delta+width*delta/2.0; - if (start || xv+shift*delta-width*delta/2.0mmax) mmax=xv+shift*delta+width*delta/2.0; + if (start || xv+shift*delta-width*delta/2.0& violin_cat, const QVector& violin_freq, double minp, double medianp, double maxp, double meanp=JKQTP_NAN) const; /** \brief draw a small, stylized, vertical symbol into \a rect that symbolizes a boxplot, e.g. in a plot legend */ - void plotVerticalKeyMarker(JKQTBasePlotter* parent, JKQTPEnhancedPainter &painter, const QRectF& rect); + void plotVerticalKeyMarker(JKQTBasePlotter* parent, JKQTPEnhancedPainter &painter, const QRectF& rect) const; /** \brief draw a small, stylized, horizontal symbol into \a rect that symbolizes a boxplot, e.g. in a plot legend */ - void plotHorizontalKeyMarker(JKQTBasePlotter* parent, JKQTPEnhancedPainter &painter, const QRectF& rect); + void plotHorizontalKeyMarker(JKQTBasePlotter* parent, JKQTPEnhancedPainter &painter, const QRectF& rect) const; private: /** \brief which symbol to use for the datapoints */ JKQTPGraphSymbols m_meanSymbolType; diff --git a/lib/jkqtplotter/jkqtpcoordinateaxes.cpp b/lib/jkqtplotter/jkqtpcoordinateaxes.cpp index e910812db6..d37325423e 100644 --- a/lib/jkqtplotter/jkqtpcoordinateaxes.cpp +++ b/lib/jkqtplotter/jkqtpcoordinateaxes.cpp @@ -81,6 +81,10 @@ JKQTMathText* JKQTPCoordinateAxis::getParentMathText() { return parent->getMathText(); } +const JKQTMathText* JKQTPCoordinateAxis::getParentMathText() const { + return parent->getMathText(); +} + void JKQTPCoordinateAxis::clearAxisTickLabels() { tickLabels.clear(); redrawPlot(); @@ -357,7 +361,7 @@ double JKQTPCoordinateAxis::calcLogTickSpacing() { } -QString JKQTPCoordinateAxis::floattolabel(double data) { +QString JKQTPCoordinateAxis::floattolabel(double data) const { int past_comma=axisStyle.labelDigits; const bool remove_trail0=true; QLocale loc=QLocale::system(); @@ -414,7 +418,7 @@ QString JKQTPCoordinateAxis::floattolabel(double data) { return QString(); } -QString JKQTPCoordinateAxis::floattolabel(double data, int past_comma) { +QString JKQTPCoordinateAxis::floattolabel(double data, int past_comma) const { bool remove_trail0=true; QLocale loc=QLocale::system(); loc.setNumberOptions(QLocale::OmitGroupSeparator); diff --git a/lib/jkqtplotter/jkqtpcoordinateaxes.h b/lib/jkqtplotter/jkqtpcoordinateaxes.h index 1e5ead3c94..c77e3401f1 100644 --- a/lib/jkqtplotter/jkqtpcoordinateaxes.h +++ b/lib/jkqtplotter/jkqtpcoordinateaxes.h @@ -565,6 +565,12 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject { protected: /** \brief indicates whether one of the parameters has changed sinse the last recalculation of tickSpacing ... */ bool paramsChanged; + /** \brief can be used to switch off calcPlotScaling() temporarily, while modifying some properties + * + * use setDoUpdateScaling() to set this property + * + * \see setDoUpdateScaling() and getDoUpdateScaling() + */ bool doUpdateScaling; /** \brief simply calls the redrawPlot method of the parent plotter class */ @@ -577,14 +583,16 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject { */ QVector > tickLabels; /** \brief retun parents JKQTMathText* object */ - virtual JKQTMathText* getParentMathText(); + JKQTMathText* getParentMathText(); + /** \brief retun parents JKQTMathText* object */ + const JKQTMathText* getParentMathText() const; /** \brief convert a float to a tick label string */ - QString floattolabel(double data); + QString floattolabel(double data) const; /** \brief convert a float to a tick label string with a given precision */ - QString floattolabel(double data, int past_comma); + QString floattolabel(double data, int past_comma) const; /** \brief parent plotter class */ JKQTBasePlotter* parent; /** \brief current view: minimum of time axis */ diff --git a/lib/jkqtplotter/jkqtpgraphsbase.h b/lib/jkqtplotter/jkqtpgraphsbase.h index 81cc806de2..4967ba30ca 100644 --- a/lib/jkqtplotter/jkqtpgraphsbase.h +++ b/lib/jkqtplotter/jkqtpgraphsbase.h @@ -98,6 +98,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPPlotElement: public QObject { /*! \brief returns whether the graph is shown in a highlighted style in the plot */ bool isHighlighted() const; + /** \brief returns the parent painter class */ + inline const JKQTBasePlotter* getParent() const { return parent; } /** \brief returns the parent painter class */ inline JKQTBasePlotter* getParent() { return parent; } /** \brief sets the parent painter class */ @@ -620,7 +622,7 @@ protected: * * \see setDataSortOrder(), getDataSortOrder() * */ - inline int getDataIndex(int i) { + inline int getDataIndex(int i) const { if (sortData==Unsorted) return i; return sortedIndices.value(i,i); } @@ -688,7 +690,7 @@ protected: * \param[out] imax last usable row-index * \return \c true on success and \c false if the information is not available */ - virtual bool getIndexRange(int &imin, int &imax) const; + virtual bool getIndexRange(int &imin, int &imax) const override; }; @@ -745,7 +747,7 @@ protected: * \param[out] imax last usable row-index * \return \c true on success and \c false if the information is not available */ - virtual bool getIndexRange(int &imin, int &imax) const; + virtual bool getIndexRange(int &imin, int &imax) const override; }; @@ -831,7 +833,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPSingleColumnGraph: public JKQTPGraph { * This function can beu used to get the correct datapoint after sorting the datapoints, * As sorting is done by sorting an index and not reordering the data in the columns themselves. * */ - inline int getDataIndex(int i) { + inline int getDataIndex(int i) const { if (sortData==Unsorted) return i; return sortedIndices.value(i,i); } diff --git a/lib/jkqtplotter/jkqtpgraphsbaseerrors.cpp b/lib/jkqtplotter/jkqtpgraphsbaseerrors.cpp index c87ab9e237..81e2bac6db 100644 --- a/lib/jkqtplotter/jkqtpgraphsbaseerrors.cpp +++ b/lib/jkqtplotter/jkqtpgraphsbaseerrors.cpp @@ -79,21 +79,21 @@ void JKQTPGraphErrorStyleMixin::setErrorColorFromGraphColor(QColor graphColor) //errorColor.setAlphaF(0.5); } -QPen JKQTPGraphErrorStyleMixin::getErrorLinePen(JKQTPEnhancedPainter &painter, JKQTBasePlotter *parent) const +QPen JKQTPGraphErrorStyleMixin::getErrorLinePen(JKQTPEnhancedPainter &painter, const JKQTBasePlotter *parent) const { QPen p=m_errorLinePen; p.setWidthF(qMax(JKQTPlotterDrawingTools::ABS_MIN_LINEWIDTH,parent->pt2px(painter, parent->getLineWidthMultiplier()*m_errorLineWidth))); return p; } -QPen JKQTPGraphErrorStyleMixin::getErrorLinePenForRects(JKQTPEnhancedPainter &painter, JKQTBasePlotter *parent) const +QPen JKQTPGraphErrorStyleMixin::getErrorLinePenForRects(JKQTPEnhancedPainter &painter, const JKQTBasePlotter *parent) const { QPen p=getErrorLinePen(painter, parent); p.setJoinStyle(Qt::MiterJoin); return p; } -QBrush JKQTPGraphErrorStyleMixin::getErrorFillBrush(JKQTPEnhancedPainter &/*painter*/, JKQTBasePlotter * /*parent*/) const +QBrush JKQTPGraphErrorStyleMixin::getErrorFillBrush(JKQTPEnhancedPainter &/*painter*/, const JKQTBasePlotter * /*parent*/) const { return m_errorFillBrush; } @@ -259,10 +259,10 @@ void JKQTPGraphErrorStyleMixin::setErrorFillTransform(const QTransform &b) m_errorFillBrush.setTransform(b); } -void JKQTPGraphErrorStyleMixin::intPlotXYErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph* parentGraph, int xColumn, int yColumn, int xErrorColumn, int yErrorColumn, JKQTPErrorPlotstyle xErrorStyle, JKQTPErrorPlotstyle yErrorStyle, int xErrorColumnLower, int yErrorColumnLower, bool xErrorSymmetric, bool yErrorSymmetric, double xrelshift, double yrelshift, const QVector* dataorder) { +void JKQTPGraphErrorStyleMixin::intPlotXYErrorIndicators(JKQTPEnhancedPainter& painter, const JKQTBasePlotter* parent, const JKQTPGraph* parentGraph, int xColumn, int yColumn, int xErrorColumn, int yErrorColumn, JKQTPErrorPlotstyle xErrorStyle, JKQTPErrorPlotstyle yErrorStyle, int xErrorColumnLower, int yErrorColumnLower, bool xErrorSymmetric, bool yErrorSymmetric, double xrelshift, double yrelshift, const QVector* dataorder) const { //std::cout<<"JKQTPGraphErrors::intPlotXYErrorIndicators(p, "<getDatastore(); + const JKQTPDatastore* datastore=parent->getDatastore(); if (datastore==nullptr) return; if ((yErrorStyle==JKQTPNoError) && (xErrorStyle==JKQTPNoError)) return; @@ -561,7 +561,7 @@ void JKQTPGraphErrorStyleMixin::intPlotXYErrorIndicators(JKQTPEnhancedPainter& p //std::cout<<"end\n"; } -bool JKQTPGraphErrorStyleMixin::intPlotXYErrorIndicatorsGetColor(JKQTPEnhancedPainter &/*painter*/, JKQTBasePlotter * /*parent*/, JKQTPGraph* /*parentGraph*/, int /*xColumn*/, int /*yColumn*/, int /*xErrorColumn*/, int /*yErrorColumn*/, JKQTPErrorPlotstyle /*xErrorStyle*/, JKQTPErrorPlotstyle /*yErrorStyle*/, int /*index*/, QColor &/*errorColor*/, QColor &/*errorFillColor*/) +bool JKQTPGraphErrorStyleMixin::intPlotXYErrorIndicatorsGetColor(JKQTPEnhancedPainter &/*painter*/, const JKQTBasePlotter * /*parent*/, const JKQTPGraph* /*parentGraph*/, int /*xColumn*/, int /*yColumn*/, int /*xErrorColumn*/, int /*yErrorColumn*/, JKQTPErrorPlotstyle /*xErrorStyle*/, JKQTPErrorPlotstyle /*yErrorStyle*/, int /*index*/, QColor &/*errorColor*/, QColor &/*errorFillColor*/) const { return false; } @@ -735,7 +735,7 @@ bool JKQTPXGraphErrors::errorUsesColumn(int c) const return c==(xErrorColumn) || (c==xErrorColumnLower); } -void JKQTPXGraphErrors::plotErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph *parentGraph, int xColumn, int yColumn, double xrelshift, double yrelshift, const QVector* dataorder) { +void JKQTPXGraphErrors::plotErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph *parentGraph, int xColumn, int yColumn, double xrelshift, double yrelshift, const QVector* dataorder) const { 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* dataorder) { +void JKQTPYGraphErrors::plotErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift, double yrelshift, const QVector* dataorder) const { 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* dataorder) { +void JKQTPXYGraphErrors::plotErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift, double yrelshift, const QVector* dataorder) const { this->intPlotXYErrorIndicators(painter, parent, parentGraph, xColumn, yColumn, xErrorColumn, yErrorColumn, xErrorStyle, yErrorStyle, xErrorColumnLower, yErrorColumnLower, xErrorSymmetric, yErrorSymmetric, xrelshift, yrelshift, dataorder); } diff --git a/lib/jkqtplotter/jkqtpgraphsbaseerrors.h b/lib/jkqtplotter/jkqtpgraphsbaseerrors.h index e7a3ccb361..31ca308026 100644 --- a/lib/jkqtplotter/jkqtpgraphsbaseerrors.h +++ b/lib/jkqtplotter/jkqtpgraphsbaseerrors.h @@ -169,20 +169,20 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPGraphErrorStyleMixin { /** \brief constructs a QPen from the error indicator line styling properties */ - QPen getErrorLinePen(JKQTPEnhancedPainter &painter, JKQTBasePlotter* parent) const; + QPen getErrorLinePen(JKQTPEnhancedPainter &painter, const JKQTBasePlotter* parent) const; /** \brief constructs a QPen from the error indicator line styling properties, suitable for drawing rectangles with sharp edges */ - QPen getErrorLinePenForRects(JKQTPEnhancedPainter &painter, JKQTBasePlotter* parent) const; + QPen getErrorLinePenForRects(JKQTPEnhancedPainter &painter, const JKQTBasePlotter* parent) const; /** \brief constructs a QBrush from the error indicator fill styling properties */ - QBrush getErrorFillBrush(JKQTPEnhancedPainter &painter, JKQTBasePlotter* parent) const; + QBrush getErrorFillBrush(JKQTPEnhancedPainter &painter, const JKQTBasePlotter *parent) const; /** \brief draw error indicators with the parameters defined in this class. The position of the datapoints is * given by the \a xColumn and \a yColumn. It is also possible to specify a datarange. */ - void intPlotXYErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph* parentGraph, int xColumn, int yColumn, int xErrorColumn, int yErrorColumn, JKQTPErrorPlotstyle xErrorStyle, JKQTPErrorPlotstyle yErrorStyle, int xErrorColumnLower=-1, int yErrorColumnLower=-1, bool xErrorSymmetric=true, bool yErrorSymmetric=true, double xrelshift=0, double yrelshift=0.0, const QVector *dataorder=nullptr); + void intPlotXYErrorIndicators(JKQTPEnhancedPainter& painter, const JKQTBasePlotter *parent, const JKQTPGraph* parentGraph, int xColumn, int yColumn, int xErrorColumn, int yErrorColumn, JKQTPErrorPlotstyle xErrorStyle, JKQTPErrorPlotstyle yErrorStyle, int xErrorColumnLower=-1, int yErrorColumnLower=-1, bool xErrorSymmetric=true, bool yErrorSymmetric=true, double xrelshift=0, double yrelshift=0.0, const QVector *dataorder=nullptr) const; /** \brief this function can be used to set the color of the error indicators automatically * * return \c true and the colors to use, if applicable, the default implementation returns false */ - virtual bool intPlotXYErrorIndicatorsGetColor(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph* parentGraph, int xColumn, int yColumn, int xErrorColumn, int yErrorColumn, JKQTPErrorPlotstyle xErrorStyle, JKQTPErrorPlotstyle yErrorStyle, int index, QColor& errorLineColor, QColor& errorFillColor); + virtual bool intPlotXYErrorIndicatorsGetColor(JKQTPEnhancedPainter& painter, const JKQTBasePlotter* parent, const JKQTPGraph *parentGraph, int xColumn, int yColumn, int xErrorColumn, int yErrorColumn, JKQTPErrorPlotstyle xErrorStyle, JKQTPErrorPlotstyle yErrorStyle, int index, QColor& errorLineColor, QColor& errorFillColor) const; }; @@ -301,7 +301,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPXGraphErrors: public JKQTPXGraphErrorData, pub protected: /** \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 *dataorder=nullptr) ; + virtual void plotErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift=0, double yrelshift=0.0, const QVector *dataorder=nullptr) const ; }; @@ -323,7 +323,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPYGraphErrors: public JKQTPYGraphErrorData, pub protected: /** \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 *dataorder=nullptr) ; + virtual void plotErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift=0, double yrelshift=0.0, const QVector *dataorder=nullptr) const ; }; @@ -347,7 +347,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPXYGraphErrors: public JKQTPXGraphErrorData, pu protected: /** \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 *dataorder=nullptr) ; + virtual void plotErrorIndicators(JKQTPEnhancedPainter& painter, JKQTBasePlotter* parent, JKQTPGraph* parentGraph, int xColumn, int yColumn, double xrelshift=0, double yrelshift=0.0, const QVector *dataorder=nullptr) const ; };