From 0a634aabd0759939371b0cbf1ed8dff04bb58402 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Wed, 26 Aug 2020 10:36:07 +0200 Subject: [PATCH] reorganization: split jkqtpgeometric.h/.cpp into several smaller files that group the geomtric shapes by type --- lib/jkqtplotter.pri | 8 + lib/jkqtplotter/CMakeLists.txt | 10 +- .../graphs/jkqtpgeoannotations.cpp | 232 +++ lib/jkqtplotter/graphs/jkqtpgeoannotations.h | 191 +++ lib/jkqtplotter/graphs/jkqtpgeobase.cpp | 252 +++ lib/jkqtplotter/graphs/jkqtpgeobase.h | 257 +++ lib/jkqtplotter/graphs/jkqtpgeolines.cpp | 645 +++++++ lib/jkqtplotter/graphs/jkqtpgeolines.h | 470 +++++ lib/jkqtplotter/graphs/jkqtpgeometric.cpp | 1513 +---------------- lib/jkqtplotter/graphs/jkqtpgeometric.h | 1285 +------------- lib/jkqtplotter/graphs/jkqtpgeoshapes.cpp | 501 ++++++ lib/jkqtplotter/graphs/jkqtpgeoshapes.h | 498 ++++++ 12 files changed, 3068 insertions(+), 2794 deletions(-) create mode 100644 lib/jkqtplotter/graphs/jkqtpgeoannotations.cpp create mode 100644 lib/jkqtplotter/graphs/jkqtpgeoannotations.h create mode 100644 lib/jkqtplotter/graphs/jkqtpgeobase.cpp create mode 100644 lib/jkqtplotter/graphs/jkqtpgeobase.h create mode 100644 lib/jkqtplotter/graphs/jkqtpgeolines.cpp create mode 100644 lib/jkqtplotter/graphs/jkqtpgeolines.h create mode 100644 lib/jkqtplotter/graphs/jkqtpgeoshapes.cpp create mode 100644 lib/jkqtplotter/graphs/jkqtpgeoshapes.h diff --git a/lib/jkqtplotter.pri b/lib/jkqtplotter.pri index 396dc2513b..1934ab8cab 100644 --- a/lib/jkqtplotter.pri +++ b/lib/jkqtplotter.pri @@ -30,6 +30,10 @@ isEmpty(JKQTP_PLOTTER_PRI_INCLUDED) { $$PWD/jkqtplotter/graphs/jkqtpevaluatedfunction.h \ $$PWD/jkqtplotter/graphs/jkqtpfilledcurve.h \ $$PWD/jkqtplotter/graphs/jkqtpgeometric.h \ + $$PWD/jkqtplotter/graphs/jkqtpgeoannotations.h \ + $$PWD/jkqtplotter/graphs/jkqtpgeobase.h \ + $$PWD/jkqtplotter/graphs/jkqtpgeolines.h \ + $$PWD/jkqtplotter/graphs/jkqtpgeoshapes.h \ $$PWD/jkqtplotter/graphs/jkqtpimage.h \ $$PWD/jkqtplotter/graphs/jkqtpimpulses.h \ $$PWD/jkqtplotter/graphs/jkqtpparsedfunction.h \ @@ -75,6 +79,10 @@ isEmpty(JKQTP_PLOTTER_PRI_INCLUDED) { $$PWD/jkqtplotter/graphs/jkqtpevaluatedfunction.cpp \ $$PWD/jkqtplotter/graphs/jkqtpfilledcurve.cpp \ $$PWD/jkqtplotter/graphs/jkqtpgeometric.cpp \ + $$PWD/jkqtplotter/graphs/jkqtpgeoannotations.cpp \ + $$PWD/jkqtplotter/graphs/jkqtpgeobase.cpp \ + $$PWD/jkqtplotter/graphs/jkqtpgeolines.cpp \ + $$PWD/jkqtplotter/graphs/jkqtpgeoshapes.cpp \ $$PWD/jkqtplotter/graphs/jkqtpimage.cpp \ $$PWD/jkqtplotter/graphs/jkqtpimpulses.cpp \ $$PWD/jkqtplotter/graphs/jkqtpparsedfunction.cpp \ diff --git a/lib/jkqtplotter/CMakeLists.txt b/lib/jkqtplotter/CMakeLists.txt index f346e6826b..654f63385b 100644 --- a/lib/jkqtplotter/CMakeLists.txt +++ b/lib/jkqtplotter/CMakeLists.txt @@ -47,7 +47,11 @@ set(SOURCES_GRAPHS graphs/jkqtpevaluatedfunction.cpp graphs/jkqtpfilledcurve.cpp graphs/jkqtpgeometric.cpp - graphs/jkqtpimage.cpp + graphs/jkqtpgeoannotations.cpp + graphs/jkqtpgeobase.cpp + graphs/jkqtpgeolines.cpp + graphs/jkqtpgeoshapes.cpp + graphs/jkqtpimage.cpp graphs/jkqtpimpulses.cpp graphs/jkqtpparsedfunction.cpp graphs/jkqtppeakstream.cpp @@ -95,6 +99,10 @@ set(HEADERS_GRAPHS graphs/jkqtpevaluatedfunction.h graphs/jkqtpfilledcurve.h graphs/jkqtpgeometric.h + graphs/jkqtpgeoannotations.h + graphs/jkqtpgeobase.h + graphs/jkqtpgeolines.h + graphs/jkqtpgeoshapes.h graphs/jkqtpimage.h graphs/jkqtpimpulses.h graphs/jkqtpparsedfunction.h diff --git a/lib/jkqtplotter/graphs/jkqtpgeoannotations.cpp b/lib/jkqtplotter/graphs/jkqtpgeoannotations.cpp new file mode 100644 index 0000000000..0de7da42af --- /dev/null +++ b/lib/jkqtplotter/graphs/jkqtpgeoannotations.cpp @@ -0,0 +1,232 @@ +/* + Copyright (c) 2008-2020 Jan W. Krieger () + + + + This software is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License (LGPL) as published by + the Free Software Foundation, either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License (LGPL) for more details. + + You should have received a copy of the GNU Lesser General Public License (LGPL) + along with this program. If not, see . +*/ + + + +#include "jkqtplotter/graphs/jkqtpgeoannotations.h" +#include "jkqtplotter/jkqtpbaseplotter.h" +#include "jkqtplotter/jkqtplotter.h" +#include +#include +#include +#define SmallestGreaterZeroCompare_xvsgz() if ((xvsgz>10.0*DBL_MIN)&&((smallestGreaterZero<10.0*DBL_MIN) || (xvsgzx=x; + this->y=y; + this->text=text; + setTextFontSize(fontSize); + setTextColor(color); +} + +JKQTPGeoText::JKQTPGeoText(JKQTPlotter* parent, double x, double y, const QString& text, double fontSize, QColor color): + JKQTPGeoText(parent->getPlotter(),x,y,text,fontSize,color) +{ +} + +JKQTPGeoText::JKQTPGeoText(JKQTBasePlotter *parent, double x, double y, const QString &text): + JKQTPPlotObject(parent), JKQTPGraphTextStyleMixin(parent) +{ + this->x=x; + this->y=y; + this->text=text; +} + +JKQTPGeoText::JKQTPGeoText(JKQTPlotter *parent, double x, double y, const QString &text): + JKQTPGeoText(parent->getPlotter(),x,y,text) +{ +} + +void JKQTPGeoText::setText(const QString &__value) +{ + this->text = __value; +} + +QString JKQTPGeoText::getText() const +{ + return this->text; +} + +void JKQTPGeoText::setX(double __value) +{ + this->x = __value; +} + +double JKQTPGeoText::getX() const +{ + return this->x; +} + +void JKQTPGeoText::setY(double __value) +{ + this->y = __value; +} + +double JKQTPGeoText::getY() const +{ + return this->y; +} + +void JKQTPGeoText::setColor(QColor c) +{ + setTextColor(c); +} + +bool JKQTPGeoText::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) { + minx=maxx=x; + smallestGreaterZero=0; + if (x>10.0*DBL_MIN) smallestGreaterZero=x; + return true; +} + +bool JKQTPGeoText::getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) { + miny=maxy=y; + smallestGreaterZero=0; + if (y>10.0*DBL_MIN) smallestGreaterZero=y; + return true; +} + +void JKQTPGeoText::draw(JKQTPEnhancedPainter& painter) { + clearHitTestData(); + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + parent->getMathText()->setFontRomanOrSpecial(getTextFontName()); + parent->getMathText()->setFontSize(getTextFontSize()*parent->getFontSizeMultiplier()); + parent->getMathText()->setFontColor(getTextColor()); + parent->getMathText()->parse(text); + parent->getMathText()->draw(painter, transformX(x), transformY(y)); + +} + +void JKQTPGeoText::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) { + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.setPen(QPen(getTextColor())); + double y=rect.top()+rect.height()/2.0; + if (rect.width()>0) painter.drawLine(QLineF(rect.left(), y, rect.right(), y)); + +} + +QColor JKQTPGeoText::getKeyLabelColor() const { + return getTextColor(); +} + + + + + + +JKQTPGeoSymbol::JKQTPGeoSymbol(JKQTBasePlotter *parent, double x, double y, JKQTPGraphSymbols symbol, double symbolSize, QColor color, QColor fillColor): + JKQTPPlotObject(parent) +{ + this->x=x; + this->y=y; + setSymbolType(symbol); + setSymbolSize(symbolSize); + setSymbolColor(color); + setSymbolFillColor(fillColor); + setSymbolLineWidth(1); +} + +JKQTPGeoSymbol::JKQTPGeoSymbol(JKQTPlotter *parent, double x, double y, JKQTPGraphSymbols symbol, double symbolSize, QColor color, QColor fillColor): + JKQTPPlotObject(parent) +{ + this->x=x; + this->y=y; + setSymbolType(symbol); + setSymbolSize(symbolSize); + setSymbolColor(color); + setSymbolFillColor(fillColor); + setSymbolLineWidth(1); +} + +void JKQTPGeoSymbol::setColor(QColor c) +{ + setSymbolColor(c); + setSymbolFillColor(JKQTPGetDerivedColor(parent->getCurrentPlotterStyle().graphFillColorDerivationMode, c)); +} + +void JKQTPGeoSymbol::setX(double __value) +{ + this->x = __value; +} + +double JKQTPGeoSymbol::getX() const +{ + return this->x; +} + +void JKQTPGeoSymbol::setY(double __value) +{ + this->y = __value; +} + +double JKQTPGeoSymbol::getY() const +{ + return this->y; +} + +bool JKQTPGeoSymbol::getXMinMax(double &minx, double &maxx, double &smallestGreaterZero) +{ + minx=x; + maxx=x; + double xvsgz; + xvsgz=minx; SmallestGreaterZeroCompare_xvsgz(); + xvsgz=maxx; SmallestGreaterZeroCompare_xvsgz(); + return true; +} + +bool JKQTPGeoSymbol::getYMinMax(double &miny, double &maxy, double &smallestGreaterZero) +{ + miny=y; + maxy=y; + double xvsgz; + xvsgz=miny; SmallestGreaterZeroCompare_xvsgz(); + xvsgz=maxy; SmallestGreaterZeroCompare_xvsgz(); + return true; +} + +void JKQTPGeoSymbol::draw(JKQTPEnhancedPainter &painter) +{ + clearHitTestData(); + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + plotStyledSymbol(parent, painter, transformX(x), transformY(y)); + addHitTestData(x,y); +} + +void JKQTPGeoSymbol::drawKeyMarker(JKQTPEnhancedPainter &painter, QRectF &rect) +{ + const double minSize=qMin(rect.width(), rect.height()); + double symbolSize=parent->pt2px(painter, this->getSymbolSize()); + if (symbolSize>minSize*0.9) symbolSize=minSize*0.9; + double symbolWidth=parent->pt2px(painter, this->getSymbolLineWidth()*parent->getLineWidthMultiplier()); + if (symbolWidth>0.3*symbolSize) symbolWidth=0.3*symbolSize; + + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + JKQTPPlotSymbol(painter, rect.left()+rect.width()/2.0, rect.top()+rect.height()/2.0, getSymbolType(), symbolSize, symbolWidth, getSymbolColor(), getSymbolFillColor()); + +} + +QColor JKQTPGeoSymbol::getKeyLabelColor() const +{ + return getSymbolColor(); +} diff --git a/lib/jkqtplotter/graphs/jkqtpgeoannotations.h b/lib/jkqtplotter/graphs/jkqtpgeoannotations.h new file mode 100644 index 0000000000..25815ebf7b --- /dev/null +++ b/lib/jkqtplotter/graphs/jkqtpgeoannotations.h @@ -0,0 +1,191 @@ +/* + Copyright (c) 2008-2020 Jan W. Krieger () + + + + This software is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License (LGPL) as published by + the Free Software Foundation, either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License (LGPL) for more details. + + You should have received a copy of the GNU Lesser General Public License (LGPL) + along with this program. If not, see . +*/ + + +#include +#include +#include +#include "jkqtplotter/graphs/jkqtpgeobase.h" +#include "jkqtplotter/jkqtpgraphsbasestylingmixins.h" +#include "jkqtplotter/jkqtptools.h" +#include "jkqtplotter/jkqtplotter_imexport.h" +#include "jkqtmathtext/jkqtmathtext.h" + +#ifndef jkqtpgeoannotations_H_INCLUDED +#define jkqtpgeoannotations_H_INCLUDED + + + + +/*! \brief This virtual JKQTPGraph descendent may be used to display a single symbol (marker). + \ingroup jkqtplotter_geoplots + + \see \ref JKQTPlotterGeometricGraphs + + */ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoSymbol: public JKQTPPlotObject, public JKQTPGraphSymbolStyleMixin { + Q_OBJECT + public: + /*! \brief class contructor + + \param parent parent plotter widget + \param x x-coordinate of symbol center + \param y y-coordinate of symbol center + \param symbol symbol type + \param symbolSize size of the symbol in pt + \param color color of drawing + \param fillColor fill color of the symbol (if filled) + */ + JKQTPGeoSymbol(JKQTBasePlotter* parent, double x, double y, JKQTPGraphSymbols symbol=JKQTPCross, double symbolSize=10, QColor color=QColor("black"), QColor fillColor=QColor("grey")); + /*! \brief class contructor + + \param parent parent plotter widget + \param x x-coordinate of symbol center + \param y y-coordinate of symbol center + \param symbol symbol type + \param symbolSize size of the symbol in pt + \param color color of drawing + \param fillColor fill color of the symbol (if filled) + */ + JKQTPGeoSymbol(JKQTPlotter* parent, double x, double y, JKQTPGraphSymbols symbol=JKQTPCross, double symbolSize=10, QColor color=QColor("black"), QColor fillColor=QColor("grey")); + + /*! set the symbol color and symbol fill color */ + virtual void setColor(QColor c); + + /*! \copydoc x */ + void setX(double __value); + /*! \copydoc x */ + double getX() const; + /*! \copydoc y */ + void setY(double __value); + /*! \copydoc y */ + double getY() const; + + /** \copydoc JKQTPGraph::getXMinMax() */ + virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; + /** \copydoc JKQTPGraph::getYMinMax() */ + virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; + + /** \brief plots the graph to the plotter object specified as parent */ + virtual void draw(JKQTPEnhancedPainter& painter) override; + + /** \brief plots a key marker inside the specified rectangle \a rect */ + virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) override; + /** \brief returns the color to be used for the key label */ + virtual QColor getKeyLabelColor() const override; + + protected: + /** \brief x-position (in plot coordinates) of the symbol (symbol center) */ + double x; + /** \brief y-position (in plot coordinates) of the symbol (symbol center) */ + double y; + +}; + + +/*! \brief This JKQTPPlotObject is used to display text. It uses the JKQTMathText + class in order to display LaTeX formulas. + \ingroup jkqtplotter_geoplots + + \see \ref JKQTPlotterGeometricGraphs + */ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoText: public JKQTPPlotObject, public JKQTPGraphTextStyleMixin { + Q_OBJECT + public: + /*! \brief class contructor + + \param parent parent plotter widget + \param x x-coordinate of text + \param y y-coordinate of text + \param text the text to display + \param color color of drawing + \param fontSize base font size of text + */ + JKQTPGeoText(JKQTBasePlotter* parent, double x, double y, const QString& text, double fontSize, QColor color); + /*! \brief class contructor + + \param parent parent plotter widget + \param x x-coordinate of text + \param y y-coordinate of text + \param text the text to display + \param color color of drawing + \param fontSize base font size of text + */ + JKQTPGeoText(JKQTPlotter* parent, double x, double y, const QString& text, double fontSize, QColor color); + /*! \brief class contructor + + \param parent parent plotter widget + \param x x-coordinate of text + \param y y-coordinate of text + \param text the text to display + */ + JKQTPGeoText(JKQTBasePlotter* parent, double x, double y, const QString& text); + /*! \brief class contructor + + \param parent parent plotter widget + \param x x-coordinate of text + \param y y-coordinate of text + \param text the text to display + */ + JKQTPGeoText(JKQTPlotter* parent, double x, double y, const QString& text); + + /*! \copydoc text */ + void setText(const QString & __value); + /*! \copydoc text */ + QString getText() const; + /*! \copydoc x */ + void setX(double __value); + /*! \copydoc x */ + double getX() const; + /*! \copydoc y */ + void setY(double __value); + /*! \copydoc y */ + double getY() const; + + /** \brief set line and fill color */ + virtual void setColor(QColor c) ; + + /** \copydoc JKQTPPlotObject::getXMinMax() */ + virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; + /** \copydoc JKQTPPlotObject::getYMinMax() */ + virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; + + /** \brief plots the graph to the plotter object specified as parent */ + virtual void draw(JKQTPEnhancedPainter& painter) override; + + /** \brief plots a key marker inside the specified rectangle \a rect */ + virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) override; + /** \brief returns the color to be used for the key label */ + virtual QColor getKeyLabelColor() const override; + + protected: + /** \brief x-position (in plot coordinates) of the text (left/baseline) */ + double x; + /** \brief y-position (in plot coordinates) of the text (left/baseline) */ + double y; + + /** \brief the text to display */ + QString text; + /** \brief return a pen, that may be used for drawing */ + QPen getPen(JKQTPEnhancedPainter& painter); +}; + + + +#endif // jkqtpgeoannotations_H_INCLUDED diff --git a/lib/jkqtplotter/graphs/jkqtpgeobase.cpp b/lib/jkqtplotter/graphs/jkqtpgeobase.cpp new file mode 100644 index 0000000000..676993d997 --- /dev/null +++ b/lib/jkqtplotter/graphs/jkqtpgeobase.cpp @@ -0,0 +1,252 @@ +/* + Copyright (c) 2008-2020 Jan W. Krieger () + + + + This software is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License (LGPL) as published by + the Free Software Foundation, either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License (LGPL) for more details. + + You should have received a copy of the GNU Lesser General Public License (LGPL) + along with this program. If not, see . +*/ + + + +#include "jkqtplotter/graphs/jkqtpgeobase.h" +#include "jkqtplotter/jkqtpbaseplotter.h" +#include "jkqtplotter/jkqtplotter.h" +#include +#include +#include +#define SmallestGreaterZeroCompare_xvsgz() if ((xvsgz>10.0*DBL_MIN)&&((smallestGreaterZero<10.0*DBL_MIN) || (xvsgzgetPlotter()) +{ +} + +JKQTPGeoBaseLine::JKQTPGeoBaseLine(JKQTBasePlotter *parent): + JKQTPPlotObject(parent) +{ + +} + +JKQTPGeoBaseLine::JKQTPGeoBaseLine(JKQTPlotter *parent): + JKQTPGeoBaseLine(parent->getPlotter()) +{ + +} + +void JKQTPGeoBaseLine::setAlpha(float alpha) +{ + auto color=getLineColor(); + color.setAlphaF(alpha); + setLineColor(color); +} + +void JKQTPGeoBaseLine::setColor(QColor c) +{ + setLineColor(c); +} + + +void JKQTPGeoBaseLine::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) { + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.setPen(getLinePen(painter, parent)); + double y=rect.top()+rect.height()/2.0; + if (rect.width()>0) painter.drawLine(QLineF(rect.left(), y, rect.right(), y)); + +} + +QColor JKQTPGeoBaseLine::getKeyLabelColor() const { + return getLineColor(); +} + + +JKQTPGeoBaseFilled::JKQTPGeoBaseFilled(QColor color, QColor fillColor, double lineWidth, Qt::PenStyle style, Qt::BrushStyle fillStyle, JKQTBasePlotter* parent): + JKQTPGeoBaseLine(color, lineWidth, style, parent) +{ + setFillColor(fillColor); + setFillStyle(fillStyle); +} + +JKQTPGeoBaseFilled::JKQTPGeoBaseFilled(QColor color, QColor fillColor, double lineWidth, Qt::PenStyle style, Qt::BrushStyle fillStyle, JKQTPlotter* parent): + JKQTPGeoBaseLine(color, lineWidth, style, parent) +{ + setFillColor(fillColor); + setFillStyle(fillStyle); +} + +JKQTPGeoBaseFilled::JKQTPGeoBaseFilled(QColor color, QColor fillColor, double lineWidth, Qt::PenStyle style, JKQTPlotter* parent): + JKQTPGeoBaseLine(color, lineWidth, style, parent) +{ + setFillColor(fillColor); + setFillStyle(Qt::SolidPattern); +} + +JKQTPGeoBaseFilled::JKQTPGeoBaseFilled(QColor color, QColor fillColor, double lineWidth, JKQTPlotter* parent): + JKQTPGeoBaseLine(color, lineWidth, Qt::SolidLine, parent) +{ + setFillColor(fillColor); + setFillStyle(Qt::SolidPattern); +} +JKQTPGeoBaseFilled::JKQTPGeoBaseFilled(QColor color, QColor fillColor, JKQTPlotter* parent): + JKQTPGeoBaseLine(color, 2.0, Qt::SolidLine, parent) +{ + setFillColor(fillColor); + setFillStyle(Qt::SolidPattern); +} + +void JKQTPGeoBaseFilled::setAlpha(float alpha) +{ + JKQTPGeoBaseLine::setAlpha(alpha); + auto fillColor=getFillColor(); + fillColor.setAlphaF(alpha); + setFillColor(fillColor); +} + +void JKQTPGeoBaseFilled::setAlpha(float alphaLine, float alphaFill) +{ + JKQTPGeoBaseLine::setAlpha(alphaLine); + auto fillColor=getFillColor(); + fillColor.setAlphaF(alphaFill); + setFillColor(fillColor); +} + +void JKQTPGeoBaseFilled::setColor(QColor c) +{ + JKQTPGeoBaseLine::setColor(c); + setFillColor(JKQTPGetDerivedColor(parent->getCurrentPlotterStyle().graphFillColorDerivationMode, c)); +} + + +void JKQTPGeoBaseFilled::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) { + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.setPen(getLinePen(painter, parent)); + painter.setBrush(getFillBrush(painter, parent)); + painter.drawRect(rect); + +} + + +JKQTPGeoBaseDecoratedHeadLine::JKQTPGeoBaseDecoratedHeadLine(QColor color, double lineWidth, JKQTPLineDecoratorStyle headStyle, Qt::PenStyle style, JKQTBasePlotter *parent): + JKQTPPlotObject(parent) +{ + setLineColor(color); + setLineWidth(lineWidth); + setLineStyle(style); + setHeadDecoratorStyle(headStyle); +} + +JKQTPGeoBaseDecoratedHeadLine::JKQTPGeoBaseDecoratedHeadLine(QColor color, double lineWidth, JKQTPLineDecoratorStyle headStyle, Qt::PenStyle style, JKQTPlotter *parent): + JKQTPGeoBaseDecoratedHeadLine(color, lineWidth, headStyle, style, parent->getPlotter()) +{ + +} + +JKQTPGeoBaseDecoratedHeadLine::JKQTPGeoBaseDecoratedHeadLine(JKQTBasePlotter *parent): + JKQTPPlotObject(parent) +{ + +} + +JKQTPGeoBaseDecoratedHeadLine::JKQTPGeoBaseDecoratedHeadLine(JKQTPlotter *parent): + JKQTPPlotObject(parent->getPlotter()) +{ + +} + +void JKQTPGeoBaseDecoratedHeadLine::setAlpha(float alpha) +{ + auto color=getLineColor(); + color.setAlphaF(alpha); + setLineColor(color); +} + +void JKQTPGeoBaseDecoratedHeadLine::setColor(QColor c) +{ + setLineColor(c); +} + +void JKQTPGeoBaseDecoratedHeadLine::drawKeyMarker(JKQTPEnhancedPainter &painter, QRectF &rect) +{ + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.setPen(getLinePen(painter, parent)); + double y=rect.top()+rect.height()/2.0; + if (rect.width()>0) painter.drawLine(QLineF(rect.left(), y, rect.right(), y)); +} + +QColor JKQTPGeoBaseDecoratedHeadLine::getKeyLabelColor() const +{ + return getLineColor(); +} + + + +JKQTPGeoBaseDecoratedLine::JKQTPGeoBaseDecoratedLine(QColor color, double lineWidth, JKQTPLineDecoratorStyle headStyle, JKQTPLineDecoratorStyle tailStyle, Qt::PenStyle style, JKQTBasePlotter *parent): + JKQTPPlotObject(parent) +{ + setLineColor(color); + setLineWidth(lineWidth); + setLineStyle(style); + setTailDecoratorStyle(tailStyle); + setHeadDecoratorStyle(headStyle); +} + +JKQTPGeoBaseDecoratedLine::JKQTPGeoBaseDecoratedLine(QColor color, double lineWidth, JKQTPLineDecoratorStyle headStyle, JKQTPLineDecoratorStyle tailStyle, Qt::PenStyle style, JKQTPlotter *parent): + JKQTPGeoBaseDecoratedLine(color, lineWidth, headStyle, tailStyle, style, parent->getPlotter()) +{ + +} + +JKQTPGeoBaseDecoratedLine::JKQTPGeoBaseDecoratedLine(JKQTBasePlotter *parent): + JKQTPPlotObject(parent) +{ + +} + +JKQTPGeoBaseDecoratedLine::JKQTPGeoBaseDecoratedLine(JKQTPlotter *parent): + JKQTPPlotObject(parent->getPlotter()) +{ + +} + +void JKQTPGeoBaseDecoratedLine::setAlpha(float alpha) +{ + auto color=getLineColor(); + color.setAlphaF(alpha); + setLineColor(color); +} + +void JKQTPGeoBaseDecoratedLine::setColor(QColor c) +{ + setLineColor(c); +} + +void JKQTPGeoBaseDecoratedLine::drawKeyMarker(JKQTPEnhancedPainter &painter, QRectF &rect) +{ + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.setPen(getLinePen(painter, parent)); + double y=rect.top()+rect.height()/2.0; + if (rect.width()>0) painter.drawLine(QLineF(rect.left(), y, rect.right(), y)); +} + +QColor JKQTPGeoBaseDecoratedLine::getKeyLabelColor() const +{ + return getLineColor(); +} diff --git a/lib/jkqtplotter/graphs/jkqtpgeobase.h b/lib/jkqtplotter/graphs/jkqtpgeobase.h new file mode 100644 index 0000000000..0ea9d9b700 --- /dev/null +++ b/lib/jkqtplotter/graphs/jkqtpgeobase.h @@ -0,0 +1,257 @@ +/* + Copyright (c) 2008-2020 Jan W. Krieger () + + + + This software is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License (LGPL) as published by + the Free Software Foundation, either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License (LGPL) for more details. + + You should have received a copy of the GNU Lesser General Public License (LGPL) + along with this program. If not, see . +*/ + + +#include +#include +#include +#include "jkqtplotter/graphs/jkqtpscatter.h" +#include "jkqtplotter/jkqtpgraphsbasestylingmixins.h" +#include "jkqtplotter/jkqtptools.h" +#include "jkqtplotter/jkqtplotter_imexport.h" +#include "jkqtmathtext/jkqtmathtext.h" + +#ifndef jkqtpgeobase_H_INCLUDED +#define jkqtpgeobase_H_INCLUDED + + +/*! \brief This JKQTPPlotObject is used as base class for geometric drawing + elements that only consist of lines (i.e. no filling of any kind is done) + \ingroup jkqtplotter_geoplots + +*/ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoBaseLine: public JKQTPPlotObject, public JKQTPGraphLineStyleMixin { + Q_OBJECT +public: + /*! \brief class contructor + + \param color color of drawing + \param style line style of drawing + \param lineWidth lineWidth of drawing + \param parent the parent plotter object + */ + explicit JKQTPGeoBaseLine(QColor color, double lineWidth, Qt::PenStyle style=Qt::SolidLine, JKQTBasePlotter* parent=nullptr); + /*! \brief class contructor + + \param color color of drawing + \param style line style of drawing + \param lineWidth lineWidth of drawing + \param parent the parent plotter object + */ + explicit JKQTPGeoBaseLine(QColor color, double lineWidth, Qt::PenStyle style, JKQTPlotter* parent); + /*! \brief class contructor + + */ + explicit JKQTPGeoBaseLine(JKQTBasePlotter* parent); + /*! \brief class contructor + + */ + explicit JKQTPGeoBaseLine(JKQTPlotter* parent); + + + + /** \brief sets the alpha-channel of the \a color (i.e. its transparency) */ + virtual void setAlpha(float alpha); + /** \brief set line color */ + virtual void setColor(QColor c); + + /** \brief plots a key marker inside the specified rectangle \a rect */ + virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) override; + /** \brief returns the color to be used for the key label */ + virtual QColor getKeyLabelColor() const override; + +protected: + +}; + + + + +/*! \brief This JKQTPPlotObject is used as base class for geometric drawing + elements that consist of lines with one decorated end (i.e. no filling of any kind is done) + \ingroup jkqtplotter_geoplots + +*/ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoBaseDecoratedHeadLine: public JKQTPPlotObject, public JKQTPGraphDecoratedHeadLineStyleMixin { + Q_OBJECT +public: + /*! \brief class contructor + + \param color color of drawing + \param lineWidth lineWidth of drawing + \param headStyle style of the head decoration + \param style line style of drawing + \param parent the parent plotter object + */ + explicit JKQTPGeoBaseDecoratedHeadLine(QColor color, double lineWidth, JKQTPLineDecoratorStyle headStyle, Qt::PenStyle style=Qt::SolidLine, JKQTBasePlotter* parent=nullptr); + /*! \brief class contructor + + \param color color of drawing + \param lineWidth lineWidth of drawing + \param headStyle style of the head decoration + \param style line style of drawing + \param parent the parent plotter object + */ + explicit JKQTPGeoBaseDecoratedHeadLine(QColor color, double lineWidth, JKQTPLineDecoratorStyle headStyle, Qt::PenStyle style, JKQTPlotter* parent); + /*! \brief class contructor + + */ + explicit JKQTPGeoBaseDecoratedHeadLine(JKQTBasePlotter* parent); + /*! \brief class contructor + + */ + explicit JKQTPGeoBaseDecoratedHeadLine(JKQTPlotter* parent); + + + + /** \brief sets the alpha-channel of the \a color (i.e. its transparency) */ + virtual void setAlpha(float alpha); + /** \brief set line color */ + virtual void setColor(QColor c); + + /** \brief plots a key marker inside the specified rectangle \a rect */ + virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) override; + /** \brief returns the color to be used for the key label */ + virtual QColor getKeyLabelColor() const override; + +protected: + +}; + + + + +/*! \brief This JKQTPPlotObject is used as base class for geometric drawing + elements that consist of lines with decorated ends (i.e. no filling of any kind is done) + \ingroup jkqtplotter_geoplots + +*/ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoBaseDecoratedLine: public JKQTPPlotObject, public JKQTPGraphDecoratedLineStyleMixin { + Q_OBJECT +public: + /*! \brief class contructor + + \param color color of drawing + \param lineWidth lineWidth of drawing + \param headStyle style of the head decoration + \param tailStyle style of the tail decoration + \param style line style of drawing + \param parent the parent plotter object + */ + explicit JKQTPGeoBaseDecoratedLine(QColor color, double lineWidth, JKQTPLineDecoratorStyle headStyle, JKQTPLineDecoratorStyle tailStyle, Qt::PenStyle style=Qt::SolidLine, JKQTBasePlotter* parent=nullptr); + /*! \brief class contructor + + \param color color of drawing + \param lineWidth lineWidth of drawing + \param headStyle style of the head decoration + \param tailStyle style of the tail decoration + \param style line style of drawing + \param parent the parent plotter object + */ + explicit JKQTPGeoBaseDecoratedLine(QColor color, double lineWidth, JKQTPLineDecoratorStyle headStyle, JKQTPLineDecoratorStyle tailStyle, Qt::PenStyle style, JKQTPlotter* parent); + /*! \brief class contructor */ + explicit JKQTPGeoBaseDecoratedLine(JKQTBasePlotter* parent); + /*! \brief class contructor */ + explicit JKQTPGeoBaseDecoratedLine(JKQTPlotter* parent); + + + + /** \brief sets the alpha-channel of the \a color (i.e. its transparency) */ + virtual void setAlpha(float alpha); + /** \brief set line color */ + virtual void setColor(QColor c); + + /** \brief plots a key marker inside the specified rectangle \a rect */ + virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) override; + /** \brief returns the color to be used for the key label */ + virtual QColor getKeyLabelColor() const override; + +protected: + +}; + + +/*! \brief This JKQTPPlotObject is used as base class for geometric drawing + elements that only consist of lines (i.e. no filling of any kind is done) + \ingroup jkqtplotter_geoplots + + */ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoBaseFilled: public JKQTPGeoBaseLine, public JKQTPGraphFillStyleMixin { + Q_OBJECT + public: + /*! \brief class contructor + + \param color color of drawing + \param fillColor color of the filling in the drawing + \param style line style of drawing + \param fillStyle filling style of the graph + \param lineWidth lineWidth of drawing + \param parent the parent plotter object + */ + JKQTPGeoBaseFilled(QColor color, QColor fillColor, double lineWidth, Qt::PenStyle style=Qt::SolidLine, Qt::BrushStyle fillStyle=Qt::SolidPattern, JKQTBasePlotter* parent=nullptr); + /*! \brief class contructor + + \param color color of drawing + \param fillColor color of the filling in the drawing + \param style line style of drawing + \param fillStyle filling style of the graph + \param lineWidth lineWidth of drawing + \param parent the parent plotter object + */ + JKQTPGeoBaseFilled(QColor color, QColor fillColor, double lineWidth, Qt::PenStyle style, Qt::BrushStyle fillStyle, JKQTPlotter* parent); + /*! \brief class contructor + + \param color color of drawing + \param fillColor color of the filling in the drawing + \param style line style of drawing + \param lineWidth lineWidth of drawing + \param parent the parent plotter object + */ + JKQTPGeoBaseFilled(QColor color, QColor fillColor, double lineWidth, Qt::PenStyle style, JKQTPlotter* parent); + /*! \brief class contructor + + \param color color of drawing + \param fillColor color of the filling in the drawing + \param lineWidth lineWidth of drawing + \param parent the parent plotter object + */ + JKQTPGeoBaseFilled(QColor color, QColor fillColor, double lineWidth, JKQTPlotter* parent); + /*! \brief class contructor + + \param color color of drawing + \param fillColor color of the filling in the drawing + \param parent the parent plotter object + */ + JKQTPGeoBaseFilled(QColor color, QColor fillColor, JKQTPlotter* parent); + + /** \brief sets the alpha-channel of the \a color and \a fillColor (i.e. its transparency) to the same value */ + virtual void setAlpha(float alpha) override; + /** \brief sets the alpha-channel of the \a color and \a fillColor (i.e. its transparency) */ + virtual void setAlpha(float alphaLine, float alphaFill); + /** \brief set line and fill color */ + virtual void setColor(QColor c) override; + + /** \brief plots a key marker inside the specified rectangle \a rect */ + virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) override; + protected: + + +}; + +#endif // jkqtpgeobase_H_INCLUDED diff --git a/lib/jkqtplotter/graphs/jkqtpgeolines.cpp b/lib/jkqtplotter/graphs/jkqtpgeolines.cpp new file mode 100644 index 0000000000..d3f1967850 --- /dev/null +++ b/lib/jkqtplotter/graphs/jkqtpgeolines.cpp @@ -0,0 +1,645 @@ +/* + Copyright (c) 2008-2020 Jan W. Krieger () + + + + This software is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License (LGPL) as published by + the Free Software Foundation, either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License (LGPL) for more details. + + You should have received a copy of the GNU Lesser General Public License (LGPL) + along with this program. If not, see . +*/ + + + +#include "jkqtplotter/graphs/jkqtpgeolines.h" +#include "jkqtplotter/jkqtpbaseplotter.h" +#include "jkqtplotter/jkqtplotter.h" +#include +#include +#include +#define SmallestGreaterZeroCompare_xvsgz() if ((xvsgz>10.0*DBL_MIN)&&((smallestGreaterZero<10.0*DBL_MIN) || (xvsgzx1=x1; + this->y1=y1; + this->x2=x2; + this->y2=y2; +} + +JKQTPGeoLine::JKQTPGeoLine(JKQTPlotter* parent, double x1, double y1, double x2, double y2, QColor color, double lineWidth, Qt::PenStyle style): + JKQTPGeoLine(parent->getPlotter(), x1,y1,x2,y2,color, lineWidth, style) +{ +} + +JKQTPGeoLine::JKQTPGeoLine(JKQTBasePlotter *parent, double x1, double y1, double x2, double y2): + JKQTPGeoBaseDecoratedLine(parent) +{ + this->x1=x1; + this->y1=y1; + this->x2=x2; + this->y2=y2; + setHeadDecoratorStyle(JKQTPNoDecorator); + setTailDecoratorStyle(JKQTPNoDecorator); +} + +JKQTPGeoLine::JKQTPGeoLine(JKQTPlotter *parent, double x1, double y1, double x2, double y2): + JKQTPGeoLine(parent->getPlotter(), x1,y1,x2,y2) +{ +} + +bool JKQTPGeoLine::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) { + minx=qMin(x1, x2); + maxx=qMax(x1, x2); + smallestGreaterZero=0; + double xvsgz; + xvsgz=x1; SmallestGreaterZeroCompare_xvsgz(); + xvsgz=x2; SmallestGreaterZeroCompare_xvsgz(); + return true; +} + +bool JKQTPGeoLine::getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) { + miny=qMin(y1, y2); + maxy=qMax(y1, y2); + smallestGreaterZero=0; + double xvsgz; + xvsgz=y1; SmallestGreaterZeroCompare_xvsgz(); + xvsgz=y2; SmallestGreaterZeroCompare_xvsgz(); + return true; +} + +void JKQTPGeoLine::draw(JKQTPEnhancedPainter& painter) { + clearHitTestData(); + reserveHitTestData(2); + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.setPen(getLinePen(painter, parent)); + painter.setBrush(getLineColor()); + QPointF xx1(transformX(x1),transformY(y1)); + QPointF xx2(transformX(x2), transformY(y2)); + const double angle1=atan2(xx2.y()-xx1.y(), xx2.x()-xx1.x()); + const double angle2=atan2(xx1.y()-xx2.y(), xx1.x()-xx2.x()); + if ( QLineF(xx1, xx2).length()>0) { + QPointF lx1=xx1, lx2=xx2; + JKQTPPlotLineDecorator(painter, xx1.x(), xx1.y(), angle1, getTailDecoratorStyle(), calcTailDecoratorSize(getLinePen(painter, getParent()).widthF()), &lx1); + JKQTPPlotLineDecorator(painter, xx2.x(), xx2.y(), angle2, getHeadDecoratorStyle(), calcHeadDecoratorSize(getLinePen(painter, getParent()).widthF()), &lx2); + // draw corrected line + painter.drawLine(QLineF(lx1, lx2)); + addHitTestData(x1, y1); + addHitTestData(x2, y2); + } +} + +void JKQTPGeoLine::setX1(double __value) +{ + this->x1 = __value; +} + +double JKQTPGeoLine::getX1() const +{ + return this->x1; +} + +void JKQTPGeoLine::setY1(double __value) +{ + this->y1 = __value; +} + +double JKQTPGeoLine::getY1() const +{ + return this->y1; +} + +void JKQTPGeoLine::setX2(double __value) +{ + this->x2 = __value; +} + +double JKQTPGeoLine::getX2() const +{ + return this->x2; +} + +void JKQTPGeoLine::setY2(double __value) +{ + this->y2 = __value; +} + +double JKQTPGeoLine::getY2() const +{ + return this->y2; +} + + + + + + + + +JKQTPGeoArrow::JKQTPGeoArrow(JKQTBasePlotter* parent, double x1, double y1, double x2, double y2, QColor color, JKQTPLineDecoratorStyle headStyle, JKQTPLineDecoratorStyle tailStyle, double lineWidth, Qt::PenStyle style): + JKQTPGeoLine(parent, x1,y1,x2,y2,color, lineWidth, style) +{ + setHeadDecoratorStyle(headStyle); + setTailDecoratorStyle(tailStyle); +} + +JKQTPGeoArrow::JKQTPGeoArrow(JKQTPlotter* parent, double x1, double y1, double x2, double y2, QColor color, JKQTPLineDecoratorStyle headStyle, JKQTPLineDecoratorStyle tailStyle, double lineWidth, Qt::PenStyle style): + JKQTPGeoArrow(parent->getPlotter(), x1,y1,x2,y2,color, headStyle, tailStyle, lineWidth, style) +{ +} + + + + +JKQTPGeoInfiniteLine::JKQTPGeoInfiniteLine(JKQTBasePlotter* parent, double x, double y, double dx, double dy, QColor color, double lineWidth, Qt::PenStyle style): + JKQTPGeoBaseDecoratedHeadLine(color, lineWidth, JKQTPNoDecorator, style, parent) +{ + this->x=x; + this->y=y; + this->dx=dx; + this->dy=dy; + this->two_sided=false; +} + +JKQTPGeoInfiniteLine::JKQTPGeoInfiniteLine(JKQTPlotter* parent, double x, double y, double dx, double dy, QColor color, double lineWidth, Qt::PenStyle style): + JKQTPGeoInfiniteLine(parent->getPlotter(), x, y, dx, dy, color, lineWidth, style) +{ +} + +bool JKQTPGeoInfiniteLine::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) { + minx=x; + maxx=x; + smallestGreaterZero=0; + if (x>10.0*DBL_MIN) smallestGreaterZero=x; + return true; +} + +bool JKQTPGeoInfiniteLine::getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) { + miny=y; + maxy=y; + smallestGreaterZero=0; + if (y>10.0*DBL_MIN) smallestGreaterZero=y; + return true; +} + +void JKQTPGeoInfiniteLine::draw(JKQTPEnhancedPainter& painter) { + clearHitTestData(); + reserveHitTestData(2); + + double xmin=parent->getXAxis()->getMin(); + double xmax=parent->getXAxis()->getMax(); + double ymin=parent->getYAxis()->getMin(); + double ymax=parent->getYAxis()->getMax(); + QRectF bbox(QPointF(xmin, ymin), QPointF(xmax, ymax)); + bool doDraw=false; + double x2=x, y2=y; + double x1=x, y1=y; + + // normalize lengh of direction + double dl=sqrt(dx*dx+dy*dy); + dx=dx/dl; + dy=dy/dl; + + // first catch cases where we are parallel to one coordinate axis + if (dy==0) { + doDraw=((y>=ymin)&&(y<=ymax)); + x1=xmin; + x2=xmax; + if (!two_sided) { + if ((dx>0)&&(x>xmin)) { + x1=x; + } else if ((dx<0)&&(x=xmin)&&(x<=xmax)); + y1=ymin; + y2=ymax; + if (!two_sided) { + if ((dy>0)&&(y>ymin)) { + y1=y; + } else if ((dy<0)&&(yxmin)&&(xymin use it + t1=tymin; + if (two_sided) { + doDraw=true; + } else if (t1>0) { + doDraw=true; + } else { + t1=0; + } + } else if (xymin0) { + doDraw=true; + } else { + t1=0; + } + } else if (xymin>xmax) { + //(xymin,ymin) is on the right, next to the rectangle, so we have to intersect with x=xmax + t1=(xmax-x)/dx; + if (two_sided) { + doDraw=true; + } else if (t1>0) { + doDraw=true; + } else { + t1=0; + } + } + + if ((xymax>xmin)&&(xymax use it + t2=tymax; + if (two_sided) { + doDraw=true; + } else if (t2>0) { + doDraw=true; + } else { + t2=0; + } + } else if (xymax0) { + doDraw=true; + } else { + t2=0; + } + } else if (xymax>xmax) { + //(xymax,ymax) is on the right, next to the rectangle, so we have to intersect with x=xmax + t2=(xmax-x)/dx; + if (two_sided) { + doDraw=true; + } else if (t2>0) { + doDraw=true; + } else { + t2=0; + } + } + + x1=x+t1*dx; + y1=y+t1*dy; + x2=x+t2*dx; + y2=y+t2*dy; + } + + if (doDraw) { + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.setPen(getLinePen(painter, parent)); + QLineF l(QPointF(transformX(x1), transformY(y1)), QPointF(transformX(x2), transformY(y2))); + if (l.length()>0) { + painter.drawLine(l); + addHitTestData(x, y, formatHitTestDefaultLabel(x,y)+ + QString(", \\ensuremath{\\mathrm{\\mathbf{d}}y/\\mathrm{\\mathbf{d}}x\\;=\\;%1/%2\\;=\\;%3\\;=\\;%4\\degree}").arg(jkqtp_floattolatexqstr(dy, 3)).arg(jkqtp_floattolatexqstr(dx, 3)).arg(jkqtp_floattolatexqstr(dy/dx, 3)).arg(jkqtp_floattolatexqstr(atan2(dy,dx), 1))); + addHitTestData(x1, y1); + addHitTestData(x2, y2); + + if (two_sided==false && x>=xmin && x<=xmax && y>=ymin && y<=ymax) { + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.setPen(getLinePen(painter, parent)); + painter.setBrush(getLineColor()); + QPointF xx1(transformX(x),transformY(y)); + const double angle1=atan2(l.dy(), l.dx()); + JKQTPPlotLineDecorator(painter, xx1.x(), xx1.y(), angle1, getHeadDecoratorStyle(), calcHeadDecoratorSize(getLinePen(painter, getParent()).widthF())); + } + } + + } + +} + +void JKQTPGeoInfiniteLine::setX(double __value) +{ + this->x = __value; +} + +double JKQTPGeoInfiniteLine::getX() const +{ + return this->x; +} + +void JKQTPGeoInfiniteLine::setY(double __value) +{ + this->y = __value; +} + +double JKQTPGeoInfiniteLine::getY() const +{ + return this->y; +} + +void JKQTPGeoInfiniteLine::setDx(double __value) +{ + this->dx = __value; +} + +double JKQTPGeoInfiniteLine::getDx() const +{ + return this->dx; +} + +void JKQTPGeoInfiniteLine::setDy(double __value) +{ + this->dy = __value; +} + +double JKQTPGeoInfiniteLine::getDy() const +{ + return this->dy; +} + +void JKQTPGeoInfiniteLine::setTwoSided(bool __value) +{ + this->two_sided = __value; +} + +bool JKQTPGeoInfiniteLine::getTwoSided() const +{ + return this->two_sided; +} + + + + +JKQTPGeoPolyLines::JKQTPGeoPolyLines(JKQTBasePlotter* parent, const QVector& points, QColor color, double lineWidth, Qt::PenStyle style): + JKQTPGeoBaseDecoratedLine(color, lineWidth, JKQTPNoDecorator, JKQTPNoDecorator, style, parent) +{ + this->points=points; +} + +JKQTPGeoPolyLines::JKQTPGeoPolyLines(JKQTPlotter* parent, const QVector& points, QColor color, double lineWidth, Qt::PenStyle style): + JKQTPGeoPolyLines(parent->getPlotter(), points, color, lineWidth, style) +{ +} + +JKQTPGeoPolyLines::JKQTPGeoPolyLines(JKQTBasePlotter *parent, QColor color, double lineWidth, Qt::PenStyle style): + JKQTPGeoBaseDecoratedLine(color, lineWidth, JKQTPNoDecorator, JKQTPNoDecorator, style, parent) +{ + +} + +JKQTPGeoPolyLines::JKQTPGeoPolyLines(JKQTPlotter *parent, QColor color, double lineWidth, Qt::PenStyle style): + JKQTPGeoPolyLines(parent->getPlotter(), color, lineWidth, style) +{ + +} + +bool JKQTPGeoPolyLines::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) { + minx=0; + maxx=0; + smallestGreaterZero=0; + if (points.size()>0) { + minx=points[0].x(); + maxx=points[0].x(); + for (int i=1; imaxx) maxx=x; + if (x0) { + miny=points[0].y(); + maxy=points[0].y(); + for (int i=1; imaxy) maxy=y; + if (y=2) { + reserveHitTestData(points.size()); + + QVector path=transform(points); + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.setPen(getLinePen(painter, parent)); + painter.setBrush(getLineColor()); + + // potentially draw line-end decorators/arrows + const double angle1=atan2(path[1].y()-path[0].y(), path[1].x()-path[0].x()); + const double angle2=atan2(path[path.size()-2].y()-path[path.size()-1].y(), path[path.size()-2].x()-path[path.size()-1].x()); + QPointF xx1=path[0], xx2=path[path.size()-1]; + QPointF lx1=xx1, lx2=xx2; + JKQTPPlotLineDecorator(painter, xx1.x(), xx1.y(), angle1, getTailDecoratorStyle(), calcTailDecoratorSize(getLinePen(painter, getParent()).widthF()), &lx1); + JKQTPPlotLineDecorator(painter, xx2.x(), xx2.y(), angle2, getHeadDecoratorStyle(), calcHeadDecoratorSize(getLinePen(painter, getParent()).widthF()), &lx2); + path[0]=lx1; + path[path.size()-1]=lx2; + + // draw corrected line + painter.drawPolyline(path.data(), path.size()); + for (const auto& p:points) { + addHitTestData(p.x(), p.y()); + } + + } +} + +void JKQTPGeoPolyLines::setPoints(const QVector &__value) +{ + this->points = __value; +} + +QVector JKQTPGeoPolyLines::getPoints() const +{ + return this->points; +} + +void JKQTPGeoPolyLines::appendPoint(const QPointF &p) { + points.append(p); +} + +void JKQTPGeoPolyLines::appendPoint(const double x, const double y) { + points.append(QPointF(x, y)); +} + + + +JKQTPGeoArc::JKQTPGeoArc(JKQTBasePlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color, double lineWidth, Qt::PenStyle style): + JKQTPGeoBaseLine(color, lineWidth, style, parent) +{ + this->angleStart=angleStart; + this->angleStop=angleStop; + this->x=x; + this->y=y; + this->width=width; + this->height=height; + this->angle=0; + this->controlPoints=180; +} + +JKQTPGeoArc::JKQTPGeoArc(JKQTPlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color, double lineWidth, Qt::PenStyle style): + JKQTPGeoArc(parent->getPlotter(), x, y, width, height, angleStart, angleStop, color, lineWidth, style) +{ +} + + +void JKQTPGeoArc::draw(JKQTPEnhancedPainter& painter) { + QPainterPath rect; + rect=transformToLinePath(JKQTPDrawEllipse(x,y,width/2.0, height/2.0,angleStart,angleStop,angle, controlPoints)); + + painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); + painter.setPen(getLinePen(painter, parent)); + painter.drawPath(rect); + +} + +void JKQTPGeoArc::setControlPoints(const unsigned int &__value) +{ + this->controlPoints = __value; +} + +unsigned int JKQTPGeoArc::getControlPoints() const +{ + return this->controlPoints; +} + +void JKQTPGeoArc::setAngleStart(double __value) +{ + this->angleStart = __value; +} + +double JKQTPGeoArc::getAngleStart() const +{ + return this->angleStart; +} + +void JKQTPGeoArc::setAngleStop(double __value) +{ + this->angleStop = __value; +} + +double JKQTPGeoArc::getAngleStop() const +{ + return this->angleStop; +} + +void JKQTPGeoArc::setX(double __value) +{ + this->x = __value; +} + +double JKQTPGeoArc::getX() const +{ + return this->x; +} + +void JKQTPGeoArc::setY(double __value) +{ + this->y = __value; +} + +double JKQTPGeoArc::getY() const +{ + return this->y; +} + +void JKQTPGeoArc::setWidth(double __value) +{ + this->width = __value; +} + +double JKQTPGeoArc::getWidth() const +{ + return this->width; +} + +void JKQTPGeoArc::setHeight(double __value) +{ + this->height = __value; +} + +double JKQTPGeoArc::getHeight() const +{ + return this->height; +} + +void JKQTPGeoArc::setAngle(double __value) +{ + this->angle = __value; +} + +double JKQTPGeoArc::getAngle() const +{ + return this->angle; +} + + +bool JKQTPGeoArc::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) { + QPolygonF rect; + rect=QPolygonF(JKQTPDrawEllipse(x,y,width/2.0, height/2.0,angleStart,angleStop,angle, controlPoints)); + minx=rect.boundingRect().left(); + maxx=rect.boundingRect().right(); + if (minx>maxx) std::swap(minx, maxx); + smallestGreaterZero=0; + double xvsgz; + xvsgz=minx; SmallestGreaterZeroCompare_xvsgz(); + xvsgz=maxx; SmallestGreaterZeroCompare_xvsgz(); + return true; +} + +bool JKQTPGeoArc::getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) { + QPolygonF rect; + rect=QPolygonF(JKQTPDrawEllipse(x,y,width/2.0, height/2.0,angleStart,angleStop,angle, controlPoints)); + miny=rect.boundingRect().bottom(); + maxy=rect.boundingRect().top(); + if (miny>maxy) std::swap(miny, maxy); + smallestGreaterZero=0; + double xvsgz; + xvsgz=miny; SmallestGreaterZeroCompare_xvsgz(); + xvsgz=maxy; SmallestGreaterZeroCompare_xvsgz(); + return true; +} + + + + diff --git a/lib/jkqtplotter/graphs/jkqtpgeolines.h b/lib/jkqtplotter/graphs/jkqtpgeolines.h new file mode 100644 index 0000000000..a69c34a56b --- /dev/null +++ b/lib/jkqtplotter/graphs/jkqtpgeolines.h @@ -0,0 +1,470 @@ +/* + Copyright (c) 2008-2020 Jan W. Krieger () + + + + This software is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License (LGPL) as published by + the Free Software Foundation, either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License (LGPL) for more details. + + You should have received a copy of the GNU Lesser General Public License (LGPL) + along with this program. If not, see . +*/ + + +#include +#include +#include +#include "jkqtplotter/graphs/jkqtpgeobase.h" +#include "jkqtplotter/jkqtpgraphsbasestylingmixins.h" +#include "jkqtplotter/jkqtptools.h" +#include "jkqtplotter/jkqtplotter_imexport.h" +#include "jkqtmathtext/jkqtmathtext.h" + +#ifndef jkqtpgeolines_H_INCLUDED +#define jkqtpgeolines_H_INCLUDED + + + +/*! \brief This JKQTPPlotObject is used to draw a line, optionally line-end decorations (aka arrows) are pssible, but switched off by default. + \ingroup jkqtplotter_geoplots + + \image html JKQTPGeoLine_HeadTail.png + + + \image html plot_geoline.png + + + You can also activate line-end decorators (aka arrows) for this poly-line, by using code like this: + \code + line->setHeadDecoratorStyle(JKQTPFilledDoubleArrow); + line->setTailDecoratorStyle(JKQTPCircleDecorator); + \endcode + + This results in arrows drawn at the start (aka x1/y1, =tail) and end (aka x2/y2, =head) of the line. + + + \note The convenience class JKQTPGeoArrow activates line-end decorations (aka arows) by default and allows to select them in the constructor. + + \see JKQTPGeoArrow, \ref JKQTPlotterGeometricGraphs and \ref JKQTPlotterGeometricArrows + + */ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoLine: public JKQTPGeoBaseDecoratedLine { + Q_OBJECT + public: + /*! \brief class constructor + + \param parent the parent plotter object + \param x1 x-coordinate of first point of line + \param y1 y-coordinate of first point of line + \param x2 x-coordinate of second point of line + \param y2 y-coordinate of second point of line + \param color color of line + \param lineWidth width of line + \param style line style + \param parent the parent plotter object + */ + JKQTPGeoLine(JKQTBasePlotter* parent, double x1, double y1, double x2, double y2, QColor color, double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); + /*! \brief class constructor + + \param parent the parent plotter object + \param x1 x-coordinate of first point of line + \param y1 y-coordinate of first point of line + \param x2 x-coordinate of second point of line + \param y2 y-coordinate of second point of line + \param color color of line + \param lineWidth width of line + \param style line style + \param parent the parent plotter object + */ + JKQTPGeoLine(JKQTPlotter* parent, double x1, double y1, double x2, double y2, QColor color, double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); + /*! \brief class constructor + + \param parent the parent plotter object + \param x1 x-coordinate of first point of line + \param y1 y-coordinate of first point of line + \param x2 x-coordinate of second point of line + \param y2 y-coordinate of second point of line + + */ + JKQTPGeoLine(JKQTBasePlotter* parent, double x1, double y1, double x2, double y2); + /*! \brief class constructor + + \param parent the parent plotter object + \param x1 x-coordinate of first point of line + \param y1 y-coordinate of first point of line + \param x2 x-coordinate of second point of line + \param y2 y-coordinate of second point of line + + */ + JKQTPGeoLine(JKQTPlotter* parent, double x1, double y1, double x2, double y2); + + + /** \copydoc JKQTPPlotObject::getXMinMax() */ + virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; + /** \copydoc JKQTPPlotObject::getYMinMax() */ + virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; + + /** \brief plots the graph to the plotter object specified as parent */ + virtual void draw(JKQTPEnhancedPainter& painter) override; + + /*! \copydoc x1 */ + void setX1(double __value); + /*! \copydoc x1 */ + double getX1() const; + /*! \copydoc y1 */ + void setY1(double __value); + /*! \copydoc y1 */ + double getY1() const; + /*! \copydoc x2 */ + void setX2(double __value); + /*! \copydoc x2 */ + double getX2() const; + /*! \copydoc y2 */ + void setY2(double __value); + /*! \copydoc y2 */ + double getY2() const; + protected: + /** \brief x-coordinate of first point of line */ + double x1; + /** \brief y-coordinate of first point of line */ + double y1; + /** \brief x-coordinate of second point of line */ + double x2; + /** \brief y-coordinate of second point of line */ + double y2; + +}; + + +/*! \brief This convenience specialisation of JKQTPGeoLine is used to draw a line with decorations (e.g. arrows) + \ingroup jkqtplotter_geoplots + + This class does not add any functionality on top of JKQTPGeoLine, just activates line-end markers by default! + + \image html JKQTPGeoLine_HeadTail.png + + \image html plot_geoarrows.png + + \see JKQTPLineDecoratorStyle, JKQTPGeoLine, \ref JKQTPlotterGeometricArrows and \ref JKQTPlotterGeometricGraphs + + */ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoArrow: public JKQTPGeoLine { + Q_OBJECT +public: + /*! \brief class constructor + + \param parent the parent plotter object + \param x1 x-coordinate of first point of line + \param y1 y-coordinate of first point of line + \param x2 x-coordinate of second point of line + \param y2 y-coordinate of second point of line + \param color color of line + \param lineWidth width of line + \param style line style + \param parent the parent plotter object + */ + JKQTPGeoArrow(JKQTBasePlotter* parent, double x1, double y1, double x2, double y2, QColor color, JKQTPLineDecoratorStyle headStyle=JKQTPDefaultLineDecorator, JKQTPLineDecoratorStyle tailStyle=JKQTPNoDecorator, double lineWidth=1.0, Qt::PenStyle style=Qt::SolidLine); + /*! \brief class constructor + + \param parent the parent plotter object + \param x1 x-coordinate of first point of line + \param y1 y-coordinate of first point of line + \param x2 x-coordinate of second point of line + \param y2 y-coordinate of second point of line + \param color color of line + \param lineWidth width of line + \param style line style + \param parent the parent plotter object + */ + JKQTPGeoArrow(JKQTPlotter* parent, double x1, double y1, double x2, double y2, QColor color, JKQTPLineDecoratorStyle headStyle=JKQTPDefaultLineDecorator, JKQTPLineDecoratorStyle tailStyle=JKQTPNoDecorator, double lineWidth=1.0, Qt::PenStyle style=Qt::SolidLine); + +}; + + + + + +/*! \brief This JKQTPPlotObject is used to draw an infinite line + \ingroup jkqtplotter_geoplots + + an infinite line has a starting point and then goes on in a given direction + until the end of the plotting range. + + \image html plot_geoinfiniteline.png + + You can add a decorator to the head of the line (i.e. the given start point (x,y) ) iff this line is one-sided, i.e. two_sided \c ==false . + + \see \ref JKQTPlotterGeometricGraphs and \ref JKQTPlotterGeometricArrows + + */ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoInfiniteLine: public JKQTPGeoBaseDecoratedHeadLine { + Q_OBJECT + public: + /*! \brief class constructor + + \param parent the parent plotter object + \param x x-coordinate of start point of line + \param y y-coordinate of start point of line + \param dx x-direction of the line + \param dy y-direction of the line + \param color color of line + \param lineWidth width of line + \param style line style + */ + JKQTPGeoInfiniteLine(JKQTBasePlotter* parent, double x, double y, double dx, double dy, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); + /*! \brief class constructor + + \param parent the parent plotter object + \param x x-coordinate of start point of line + \param y y-coordinate of start point of line + \param dx x-direction of the line + \param dy y-direction of the line + \param color color of line + \param lineWidth width of line + \param style line style + */ + JKQTPGeoInfiniteLine(JKQTPlotter* parent, double x, double y, double dx, double dy, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); + + + /** \copydoc JKQTPPlotObject::getXMinMax() */ + virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; + /** \copydoc JKQTPPlotObject::getYMinMax() */ + virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; + + /** \brief plots the graph to the plotter object specified as parent */ + virtual void draw(JKQTPEnhancedPainter& painter) override; + + /*! \copydoc x */ + void setX(double __value); + /*! \copydoc x */ + double getX() const; + /*! \copydoc y */ + void setY(double __value); + /*! \copydoc y */ + double getY() const; + /*! \copydoc dx */ + void setDx(double __value); + /*! \copydoc dx */ + double getDx() const; + /*! \copydoc dy */ + void setDy(double __value); + /*! \copydoc dy */ + double getDy() const; + /*! \copydoc two_sided */ + void setTwoSided(bool __value); + /*! \copydoc two_sided */ + bool getTwoSided() const; + protected: + /** \brief x-coordinate of a point on the line */ + double x; + /** \brief y-coordinate of a point on the line */ + double y; + /** \brief x-component of the slope of the line */ + double dx; + /** \brief y-component of the slope of the line */ + double dy; + /** \brief indicates whether the line ends at the given point \f$ (x,y) \f$ (false, default), + * or is infinite in both directions (true) */ + bool two_sided; +}; + + +/*! \brief This JKQTPPlotObject is used to draw a poly line + \ingroup jkqtplotter_geoplots + + \image html plot_geolines.png + + You can also activate line-end decorators (aka arrows) for this poly-line, by using code like this: + \code + polyLine->setHeadDecoratorStyle(JKQTPFilledDoubleArrow); + polyLine->setTailDecoratorStyle(JKQTPCircleDecorator); + \endcode + + This results in arrows drawn at the start (=tail) and end (=head) of the poly-line: + \image html geo_arrow_polylines.png + + \see \ref JKQTPlotterGeometricGraphs and \ref JKQTPlotterGeometricArrows + + */ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoPolyLines: public JKQTPGeoBaseDecoratedLine { + Q_OBJECT + public: + /*! \brief class constructor + + \param parent the parent plotter object + \param points points on the polygon + \param color color of line + \param lineWidth width of line + \param style line style + */ + JKQTPGeoPolyLines(JKQTBasePlotter* parent, const QVector& points, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); + /*! \brief class constructor + + \param parent the parent plotter object + \param points points on the polygon + \param color color of line + \param lineWidth width of line + \param style line style + */ + JKQTPGeoPolyLines(JKQTPlotter* parent, const QVector& points, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); + /*! \brief class constructor + + \param parent the parent plotter object + \param color color of line + \param lineWidth width of line + \param style line style + */ + JKQTPGeoPolyLines(JKQTBasePlotter* parent, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); + /*! \brief class constructor + + \param parent the parent plotter object + \param color color of line + \param lineWidth width of line + \param style line style + */ + JKQTPGeoPolyLines(JKQTPlotter* parent, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); + + + /** \copydoc JKQTPPlotObject::getXMinMax() */ + virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; + /** \copydoc JKQTPPlotObject::getYMinMax() */ + virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; + + /** \brief plots the graph to the plotter object specified as parent */ + virtual void draw(JKQTPEnhancedPainter& painter) override; + + /*! \copydoc points */ + void setPoints(const QVector & __value); + /*! \copydoc points */ + QVector getPoints() const; + + /** \brief append a point to the polygon */ + void appendPoint(const QPointF& p); + + /** \brief append a point to the polygon */ + void appendPoint(const double x, const double y); + protected: + /** \brief list with all points on the poly-line */ + QVector points; +}; + + +/*! \brief This JKQTPPlotObject is used to draw an arc + \ingroup jkqtplotter_geoplots + + \image html plot_geoarc.png + + \see \ref JKQTPlotterGeometricGraphs + */ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoArc: public JKQTPGeoBaseLine { + Q_OBJECT + public: + /*! \brief class constructor + + \param parent the parent plotter object + \param x x-coordinate of center of ellipse + \param y y-coordinate of center of ellipse + \param width width of ellipse (2 * half axis) + \param height of ellipse (2 * half axis) + \param angleStart if we only draw an arc, this is the starting angle in degrees + \param angleStop if we only draw an arc, this is the ending angle in degrees + \param color color of line + \param lineWidth width of line + \param style line style + + */ + JKQTPGeoArc(JKQTBasePlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); + /*! \brief class constructor + + \param parent the parent plotter object + \param x x-coordinate of center of ellipse + \param y y-coordinate of center of ellipse + \param width width of ellipse (2 * half axis) + \param height of ellipse (2 * half axis) + \param angleStart if we only draw an arc, this is the starting angle in degrees + \param angleStop if we only draw an arc, this is the ending angle in degrees + \param color color of line + \param lineWidth width of line + \param style line style + + */ + JKQTPGeoArc(JKQTPlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); + + /** \copydoc JKQTPPlotObject::getXMinMax() */ + virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; + /** \copydoc JKQTPPlotObject::getYMinMax() */ + virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; + + + /** \brief plots the graph to the plotter object specified as parent */ + virtual void draw(JKQTPEnhancedPainter& painter) override; + + /*! \copydoc controlPoints */ + void setControlPoints(const unsigned int & __value); + /*! \copydoc controlPoints */ + unsigned int getControlPoints() const; + /*! \copydoc angleStart */ + void setAngleStart(double __value); + /*! \copydoc angleStart */ + double getAngleStart() const; + /*! \copydoc angleStop */ + void setAngleStop(double __value); + /*! \copydoc angleStop */ + double getAngleStop() const; + /*! \copydoc x */ + void setX(double __value); + /*! \copydoc x */ + double getX() const; + /*! \copydoc y */ + void setY(double __value); + /*! \copydoc y */ + double getY() const; + /*! \copydoc width */ + void setWidth(double __value); + /*! \copydoc width */ + double getWidth() const; + /*! \copydoc height */ + void setHeight(double __value); + /*! \copydoc height */ + double getHeight() const; + /*! \copydoc angle */ + void setAngle(double __value); + /*! \copydoc angle */ + double getAngle() const; + protected: + /** \brief x-coordinate of a center of the rectangle */ + double x; + /** \brief y-coordinate of a center of the rectangle */ + double y; + /** \brief width of a center of the rectangle */ + double width; + /** \brief height of a center of the rectangle */ + double height; + /** \brief rotation angle of rectangle [degrees] around (x,y) */ + double angle; + /** \brief if we only draw an arc, this is the starting angle in degrees */ + double angleStart; + /** \brief if we only draw an arc, this is the ending angle in degrees */ + double angleStop; + /** \brief number of steps/control points to draw the ellipse */ + unsigned int controlPoints; + + /** \brief closing mode for arcs: secand or pie */ + /** \brief returns the transformation matrix used for this rectangle */ + QTransform getTransform(); + /** \brief returns a QPolygonF which represents the rectangle after rotation, but still in the world coordinate system, not in the screen/widget system */ + QPolygonF getPolygon(); + +}; + + + + +#endif // jkqtpgeolines_H_INCLUDED diff --git a/lib/jkqtplotter/graphs/jkqtpgeometric.cpp b/lib/jkqtplotter/graphs/jkqtpgeometric.cpp index fa1749613c..15e9d3fe60 100644 --- a/lib/jkqtplotter/graphs/jkqtpgeometric.cpp +++ b/lib/jkqtplotter/graphs/jkqtpgeometric.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2008-2019 Jan W. Krieger () + Copyright (c) 2008-2020 Jan W. Krieger () @@ -20,1514 +20,3 @@ #include "jkqtplotter/graphs/jkqtpgeometric.h" -#include "jkqtplotter/jkqtpbaseplotter.h" -#include "jkqtplotter/jkqtplotter.h" -#include -#include -#include -#define SmallestGreaterZeroCompare_xvsgz() if ((xvsgz>10.0*DBL_MIN)&&((smallestGreaterZero<10.0*DBL_MIN) || (xvsgzgetPlotter()) -{ -} - -JKQTPGeoBaseLine::JKQTPGeoBaseLine(JKQTBasePlotter *parent): - JKQTPPlotObject(parent) -{ - -} - -JKQTPGeoBaseLine::JKQTPGeoBaseLine(JKQTPlotter *parent): - JKQTPGeoBaseLine(parent->getPlotter()) -{ - -} - -void JKQTPGeoBaseLine::setAlpha(float alpha) -{ - auto color=getLineColor(); - color.setAlphaF(alpha); - setLineColor(color); -} - -void JKQTPGeoBaseLine::setColor(QColor c) -{ - setLineColor(c); -} - - -void JKQTPGeoBaseLine::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); - painter.setPen(getLinePen(painter, parent)); - double y=rect.top()+rect.height()/2.0; - if (rect.width()>0) painter.drawLine(QLineF(rect.left(), y, rect.right(), y)); - -} - -QColor JKQTPGeoBaseLine::getKeyLabelColor() const { - return getLineColor(); -} - - -JKQTPGeoBaseFilled::JKQTPGeoBaseFilled(QColor color, QColor fillColor, double lineWidth, Qt::PenStyle style, Qt::BrushStyle fillStyle, JKQTBasePlotter* parent): - JKQTPGeoBaseLine(color, lineWidth, style, parent) -{ - setFillColor(fillColor); - setFillStyle(fillStyle); -} - -JKQTPGeoBaseFilled::JKQTPGeoBaseFilled(QColor color, QColor fillColor, double lineWidth, Qt::PenStyle style, Qt::BrushStyle fillStyle, JKQTPlotter* parent): - JKQTPGeoBaseLine(color, lineWidth, style, parent) -{ - setFillColor(fillColor); - setFillStyle(fillStyle); -} - -JKQTPGeoBaseFilled::JKQTPGeoBaseFilled(QColor color, QColor fillColor, double lineWidth, Qt::PenStyle style, JKQTPlotter* parent): - JKQTPGeoBaseLine(color, lineWidth, style, parent) -{ - setFillColor(fillColor); - setFillStyle(Qt::SolidPattern); -} - -JKQTPGeoBaseFilled::JKQTPGeoBaseFilled(QColor color, QColor fillColor, double lineWidth, JKQTPlotter* parent): - JKQTPGeoBaseLine(color, lineWidth, Qt::SolidLine, parent) -{ - setFillColor(fillColor); - setFillStyle(Qt::SolidPattern); -} -JKQTPGeoBaseFilled::JKQTPGeoBaseFilled(QColor color, QColor fillColor, JKQTPlotter* parent): - JKQTPGeoBaseLine(color, 2.0, Qt::SolidLine, parent) -{ - setFillColor(fillColor); - setFillStyle(Qt::SolidPattern); -} - -void JKQTPGeoBaseFilled::setAlpha(float alpha) -{ - JKQTPGeoBaseLine::setAlpha(alpha); - auto fillColor=getFillColor(); - fillColor.setAlphaF(alpha); - setFillColor(fillColor); -} - -void JKQTPGeoBaseFilled::setAlpha(float alphaLine, float alphaFill) -{ - JKQTPGeoBaseLine::setAlpha(alphaLine); - auto fillColor=getFillColor(); - fillColor.setAlphaF(alphaFill); - setFillColor(fillColor); -} - -void JKQTPGeoBaseFilled::setColor(QColor c) -{ - JKQTPGeoBaseLine::setColor(c); - setFillColor(JKQTPGetDerivedColor(parent->getCurrentPlotterStyle().graphFillColorDerivationMode, c)); -} - - -void JKQTPGeoBaseFilled::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); - painter.setPen(getLinePen(painter, parent)); - painter.setBrush(getFillBrush(painter, parent)); - painter.drawRect(rect); - -} - - - - - -JKQTPGeoText::JKQTPGeoText(JKQTBasePlotter* parent, double x, double y, const QString& text, double fontSize, QColor color): - JKQTPPlotObject(parent), JKQTPGraphTextStyleMixin(parent) -{ - this->x=x; - this->y=y; - this->text=text; - setTextFontSize(fontSize); - setTextColor(color); -} - -JKQTPGeoText::JKQTPGeoText(JKQTPlotter* parent, double x, double y, const QString& text, double fontSize, QColor color): - JKQTPGeoText(parent->getPlotter(),x,y,text,fontSize,color) -{ -} - -JKQTPGeoText::JKQTPGeoText(JKQTBasePlotter *parent, double x, double y, const QString &text): - JKQTPPlotObject(parent), JKQTPGraphTextStyleMixin(parent) -{ - this->x=x; - this->y=y; - this->text=text; -} - -JKQTPGeoText::JKQTPGeoText(JKQTPlotter *parent, double x, double y, const QString &text): - JKQTPGeoText(parent->getPlotter(),x,y,text) -{ -} - -void JKQTPGeoText::setText(const QString &__value) -{ - this->text = __value; -} - -QString JKQTPGeoText::getText() const -{ - return this->text; -} - -void JKQTPGeoText::setX(double __value) -{ - this->x = __value; -} - -double JKQTPGeoText::getX() const -{ - return this->x; -} - -void JKQTPGeoText::setY(double __value) -{ - this->y = __value; -} - -double JKQTPGeoText::getY() const -{ - return this->y; -} - -void JKQTPGeoText::setColor(QColor c) -{ - setTextColor(c); -} - -bool JKQTPGeoText::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) { - minx=maxx=x; - smallestGreaterZero=0; - if (x>10.0*DBL_MIN) smallestGreaterZero=x; - return true; -} - -bool JKQTPGeoText::getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) { - miny=maxy=y; - smallestGreaterZero=0; - if (y>10.0*DBL_MIN) smallestGreaterZero=y; - return true; -} - -void JKQTPGeoText::draw(JKQTPEnhancedPainter& painter) { - clearHitTestData(); - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); - parent->getMathText()->setFontRomanOrSpecial(getTextFontName()); - parent->getMathText()->setFontSize(getTextFontSize()*parent->getFontSizeMultiplier()); - parent->getMathText()->setFontColor(getTextColor()); - parent->getMathText()->parse(text); - parent->getMathText()->draw(painter, transformX(x), transformY(y)); - -} - -void JKQTPGeoText::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); - painter.setPen(QPen(getTextColor())); - double y=rect.top()+rect.height()/2.0; - if (rect.width()>0) painter.drawLine(QLineF(rect.left(), y, rect.right(), y)); - -} - -QColor JKQTPGeoText::getKeyLabelColor() const { - return getTextColor(); -} - - - - - - -JKQTPGeoLine::JKQTPGeoLine(JKQTBasePlotter* parent, double x1, double y1, double x2, double y2, QColor color, double lineWidth, Qt::PenStyle style): - JKQTPGeoBaseDecoratedLine(color, lineWidth, JKQTPNoDecorator, JKQTPNoDecorator, style, parent) -{ - this->x1=x1; - this->y1=y1; - this->x2=x2; - this->y2=y2; -} - -JKQTPGeoLine::JKQTPGeoLine(JKQTPlotter* parent, double x1, double y1, double x2, double y2, QColor color, double lineWidth, Qt::PenStyle style): - JKQTPGeoLine(parent->getPlotter(), x1,y1,x2,y2,color, lineWidth, style) -{ -} - -JKQTPGeoLine::JKQTPGeoLine(JKQTBasePlotter *parent, double x1, double y1, double x2, double y2): - JKQTPGeoBaseDecoratedLine(parent) -{ - this->x1=x1; - this->y1=y1; - this->x2=x2; - this->y2=y2; - setHeadDecoratorStyle(JKQTPNoDecorator); - setTailDecoratorStyle(JKQTPNoDecorator); -} - -JKQTPGeoLine::JKQTPGeoLine(JKQTPlotter *parent, double x1, double y1, double x2, double y2): - JKQTPGeoLine(parent->getPlotter(), x1,y1,x2,y2) -{ -} - -bool JKQTPGeoLine::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) { - minx=qMin(x1, x2); - maxx=qMax(x1, x2); - smallestGreaterZero=0; - double xvsgz; - xvsgz=x1; SmallestGreaterZeroCompare_xvsgz(); - xvsgz=x2; SmallestGreaterZeroCompare_xvsgz(); - return true; -} - -bool JKQTPGeoLine::getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) { - miny=qMin(y1, y2); - maxy=qMax(y1, y2); - smallestGreaterZero=0; - double xvsgz; - xvsgz=y1; SmallestGreaterZeroCompare_xvsgz(); - xvsgz=y2; SmallestGreaterZeroCompare_xvsgz(); - return true; -} - -void JKQTPGeoLine::draw(JKQTPEnhancedPainter& painter) { - clearHitTestData(); - reserveHitTestData(2); - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); - painter.setPen(getLinePen(painter, parent)); - painter.setBrush(getLineColor()); - QPointF xx1(transformX(x1),transformY(y1)); - QPointF xx2(transformX(x2), transformY(y2)); - const double angle1=atan2(xx2.y()-xx1.y(), xx2.x()-xx1.x()); - const double angle2=atan2(xx1.y()-xx2.y(), xx1.x()-xx2.x()); - if ( QLineF(xx1, xx2).length()>0) { - QPointF lx1=xx1, lx2=xx2; - JKQTPPlotLineDecorator(painter, xx1.x(), xx1.y(), angle1, getTailDecoratorStyle(), calcTailDecoratorSize(getLinePen(painter, getParent()).widthF()), &lx1); - JKQTPPlotLineDecorator(painter, xx2.x(), xx2.y(), angle2, getHeadDecoratorStyle(), calcHeadDecoratorSize(getLinePen(painter, getParent()).widthF()), &lx2); - // draw corrected line - painter.drawLine(QLineF(lx1, lx2)); - addHitTestData(x1, y1); - addHitTestData(x2, y2); - } -} - -void JKQTPGeoLine::setX1(double __value) -{ - this->x1 = __value; -} - -double JKQTPGeoLine::getX1() const -{ - return this->x1; -} - -void JKQTPGeoLine::setY1(double __value) -{ - this->y1 = __value; -} - -double JKQTPGeoLine::getY1() const -{ - return this->y1; -} - -void JKQTPGeoLine::setX2(double __value) -{ - this->x2 = __value; -} - -double JKQTPGeoLine::getX2() const -{ - return this->x2; -} - -void JKQTPGeoLine::setY2(double __value) -{ - this->y2 = __value; -} - -double JKQTPGeoLine::getY2() const -{ - return this->y2; -} - - - - - - - - -JKQTPGeoArrow::JKQTPGeoArrow(JKQTBasePlotter* parent, double x1, double y1, double x2, double y2, QColor color, JKQTPLineDecoratorStyle headStyle, JKQTPLineDecoratorStyle tailStyle, double lineWidth, Qt::PenStyle style): - JKQTPGeoLine(parent, x1,y1,x2,y2,color, lineWidth, style) -{ - setHeadDecoratorStyle(headStyle); - setTailDecoratorStyle(tailStyle); -} - -JKQTPGeoArrow::JKQTPGeoArrow(JKQTPlotter* parent, double x1, double y1, double x2, double y2, QColor color, JKQTPLineDecoratorStyle headStyle, JKQTPLineDecoratorStyle tailStyle, double lineWidth, Qt::PenStyle style): - JKQTPGeoArrow(parent->getPlotter(), x1,y1,x2,y2,color, headStyle, tailStyle, lineWidth, style) -{ -} - - - - -JKQTPGeoInfiniteLine::JKQTPGeoInfiniteLine(JKQTBasePlotter* parent, double x, double y, double dx, double dy, QColor color, double lineWidth, Qt::PenStyle style): - JKQTPGeoBaseDecoratedHeadLine(color, lineWidth, JKQTPNoDecorator, style, parent) -{ - this->x=x; - this->y=y; - this->dx=dx; - this->dy=dy; - this->two_sided=false; -} - -JKQTPGeoInfiniteLine::JKQTPGeoInfiniteLine(JKQTPlotter* parent, double x, double y, double dx, double dy, QColor color, double lineWidth, Qt::PenStyle style): - JKQTPGeoInfiniteLine(parent->getPlotter(), x, y, dx, dy, color, lineWidth, style) -{ -} - -bool JKQTPGeoInfiniteLine::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) { - minx=x; - maxx=x; - smallestGreaterZero=0; - if (x>10.0*DBL_MIN) smallestGreaterZero=x; - return true; -} - -bool JKQTPGeoInfiniteLine::getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) { - miny=y; - maxy=y; - smallestGreaterZero=0; - if (y>10.0*DBL_MIN) smallestGreaterZero=y; - return true; -} - -void JKQTPGeoInfiniteLine::draw(JKQTPEnhancedPainter& painter) { - clearHitTestData(); - reserveHitTestData(2); - - double xmin=parent->getXAxis()->getMin(); - double xmax=parent->getXAxis()->getMax(); - double ymin=parent->getYAxis()->getMin(); - double ymax=parent->getYAxis()->getMax(); - QRectF bbox(QPointF(xmin, ymin), QPointF(xmax, ymax)); - bool doDraw=false; - double x2=x, y2=y; - double x1=x, y1=y; - - // normalize lengh of direction - double dl=sqrt(dx*dx+dy*dy); - dx=dx/dl; - dy=dy/dl; - - // first catch cases where we are parallel to one coordinate axis - if (dy==0) { - doDraw=((y>=ymin)&&(y<=ymax)); - x1=xmin; - x2=xmax; - if (!two_sided) { - if ((dx>0)&&(x>xmin)) { - x1=x; - } else if ((dx<0)&&(x=xmin)&&(x<=xmax)); - y1=ymin; - y2=ymax; - if (!two_sided) { - if ((dy>0)&&(y>ymin)) { - y1=y; - } else if ((dy<0)&&(yxmin)&&(xymin use it - t1=tymin; - if (two_sided) { - doDraw=true; - } else if (t1>0) { - doDraw=true; - } else { - t1=0; - } - } else if (xymin0) { - doDraw=true; - } else { - t1=0; - } - } else if (xymin>xmax) { - //(xymin,ymin) is on the right, next to the rectangle, so we have to intersect with x=xmax - t1=(xmax-x)/dx; - if (two_sided) { - doDraw=true; - } else if (t1>0) { - doDraw=true; - } else { - t1=0; - } - } - - if ((xymax>xmin)&&(xymax use it - t2=tymax; - if (two_sided) { - doDraw=true; - } else if (t2>0) { - doDraw=true; - } else { - t2=0; - } - } else if (xymax0) { - doDraw=true; - } else { - t2=0; - } - } else if (xymax>xmax) { - //(xymax,ymax) is on the right, next to the rectangle, so we have to intersect with x=xmax - t2=(xmax-x)/dx; - if (two_sided) { - doDraw=true; - } else if (t2>0) { - doDraw=true; - } else { - t2=0; - } - } - - x1=x+t1*dx; - y1=y+t1*dy; - x2=x+t2*dx; - y2=y+t2*dy; - } - - if (doDraw) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); - painter.setPen(getLinePen(painter, parent)); - QLineF l(QPointF(transformX(x1), transformY(y1)), QPointF(transformX(x2), transformY(y2))); - if (l.length()>0) { - painter.drawLine(l); - addHitTestData(x, y, formatHitTestDefaultLabel(x,y)+ - QString(", \\ensuremath{\\mathrm{\\mathbf{d}}y/\\mathrm{\\mathbf{d}}x\\;=\\;%1/%2\\;=\\;%3\\;=\\;%4\\degree}").arg(jkqtp_floattolatexqstr(dy, 3)).arg(jkqtp_floattolatexqstr(dx, 3)).arg(jkqtp_floattolatexqstr(dy/dx, 3)).arg(jkqtp_floattolatexqstr(atan2(dy,dx), 1))); - addHitTestData(x1, y1); - addHitTestData(x2, y2); - - if (two_sided==false && x>=xmin && x<=xmax && y>=ymin && y<=ymax) { - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); - painter.setPen(getLinePen(painter, parent)); - painter.setBrush(getLineColor()); - QPointF xx1(transformX(x),transformY(y)); - const double angle1=atan2(l.dy(), l.dx()); - JKQTPPlotLineDecorator(painter, xx1.x(), xx1.y(), angle1, getHeadDecoratorStyle(), calcHeadDecoratorSize(getLinePen(painter, getParent()).widthF())); - } - } - - } - -} - -void JKQTPGeoInfiniteLine::setX(double __value) -{ - this->x = __value; -} - -double JKQTPGeoInfiniteLine::getX() const -{ - return this->x; -} - -void JKQTPGeoInfiniteLine::setY(double __value) -{ - this->y = __value; -} - -double JKQTPGeoInfiniteLine::getY() const -{ - return this->y; -} - -void JKQTPGeoInfiniteLine::setDx(double __value) -{ - this->dx = __value; -} - -double JKQTPGeoInfiniteLine::getDx() const -{ - return this->dx; -} - -void JKQTPGeoInfiniteLine::setDy(double __value) -{ - this->dy = __value; -} - -double JKQTPGeoInfiniteLine::getDy() const -{ - return this->dy; -} - -void JKQTPGeoInfiniteLine::setTwoSided(bool __value) -{ - this->two_sided = __value; -} - -bool JKQTPGeoInfiniteLine::getTwoSided() const -{ - return this->two_sided; -} - - - - -JKQTPGeoPolyLines::JKQTPGeoPolyLines(JKQTBasePlotter* parent, const QVector& points, QColor color, double lineWidth, Qt::PenStyle style): - JKQTPGeoBaseDecoratedLine(color, lineWidth, JKQTPNoDecorator, JKQTPNoDecorator, style, parent) -{ - this->points=points; -} - -JKQTPGeoPolyLines::JKQTPGeoPolyLines(JKQTPlotter* parent, const QVector& points, QColor color, double lineWidth, Qt::PenStyle style): - JKQTPGeoPolyLines(parent->getPlotter(), points, color, lineWidth, style) -{ -} - -JKQTPGeoPolyLines::JKQTPGeoPolyLines(JKQTBasePlotter *parent, QColor color, double lineWidth, Qt::PenStyle style): - JKQTPGeoBaseDecoratedLine(color, lineWidth, JKQTPNoDecorator, JKQTPNoDecorator, style, parent) -{ - -} - -JKQTPGeoPolyLines::JKQTPGeoPolyLines(JKQTPlotter *parent, QColor color, double lineWidth, Qt::PenStyle style): - JKQTPGeoPolyLines(parent->getPlotter(), color, lineWidth, style) -{ - -} - -bool JKQTPGeoPolyLines::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) { - minx=0; - maxx=0; - smallestGreaterZero=0; - if (points.size()>0) { - minx=points[0].x(); - maxx=points[0].x(); - for (int i=1; imaxx) maxx=x; - if (x0) { - miny=points[0].y(); - maxy=points[0].y(); - for (int i=1; imaxy) maxy=y; - if (y=2) { - reserveHitTestData(points.size()); - - QVector path=transform(points); - painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); - painter.setPen(getLinePen(painter, parent)); - painter.setBrush(getLineColor()); - - // potentially draw line-end decorators/arrows - const double angle1=atan2(path[1].y()-path[0].y(), path[1].x()-path[0].x()); - const double angle2=atan2(path[path.size()-2].y()-path[path.size()-1].y(), path[path.size()-2].x()-path[path.size()-1].x()); - QPointF xx1=path[0], xx2=path[path.size()-1]; - QPointF lx1=xx1, lx2=xx2; - JKQTPPlotLineDecorator(painter, xx1.x(), xx1.y(), angle1, getTailDecoratorStyle(), calcTailDecoratorSize(getLinePen(painter, getParent()).widthF()), &lx1); - JKQTPPlotLineDecorator(painter, xx2.x(), xx2.y(), angle2, getHeadDecoratorStyle(), calcHeadDecoratorSize(getLinePen(painter, getParent()).widthF()), &lx2); - path[0]=lx1; - path[path.size()-1]=lx2; - - // draw corrected line - painter.drawPolyline(path.data(), path.size()); - for (const auto& p:points) { - addHitTestData(p.x(), p.y()); - } - - } -} - -void JKQTPGeoPolyLines::setPoints(const QVector &__value) -{ - this->points = __value; -} - -QVector JKQTPGeoPolyLines::getPoints() const -{ - return this->points; -} - -void JKQTPGeoPolyLines::appendPoint(const QPointF &p) { - points.append(p); -} - -void JKQTPGeoPolyLines::appendPoint(const double x, const double y) { - points.append(QPointF(x, y)); -} - - -JKQTPGeoRectangle::JKQTPGeoRectangle(JKQTBasePlotter* parent, double x, double y, double width, double height, QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, Qt::BrushStyle fillStyle): - JKQTPGeoBaseFilled(color, fillColor, lineWidth, style, fillStyle, parent) -{ - this->x=x; - this->y=y; - angle=0; - this->width=width; - this->height=height; -} - -JKQTPGeoRectangle::JKQTPGeoRectangle(JKQTPlotter* parent, double x, double y, double width, double height, QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, Qt::BrushStyle fillStyle): - JKQTPGeoBaseFilled(color, fillColor, lineWidth, style, fillStyle, parent) -{ - this->x=x; - this->y=y; - angle=0; - this->width=width; - this->height=height; -} - -JKQTPGeoRectangle::JKQTPGeoRectangle(JKQTBasePlotter *parent, double x, double y, double width, double height, double angle, QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, Qt::BrushStyle fillStyle): - JKQTPGeoBaseFilled(color, fillColor, lineWidth, style, fillStyle, parent) -{ - this->x=x; - this->y=y; - this->angle=angle; - this->width=width; - this->height=height; -} - -JKQTPGeoRectangle::JKQTPGeoRectangle(JKQTPlotter *parent, double x, double y, double width, double height, double angle, QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, Qt::BrushStyle fillStyle): - JKQTPGeoBaseFilled(color, fillColor, lineWidth, style, fillStyle, parent) -{ - this->x=x; - this->y=y; - this->angle=angle; - this->width=width; - this->height=height; -} - -JKQTPGeoRectangle::JKQTPGeoRectangle(JKQTBasePlotter *parent, QPointF bottomleft, QPointF topright, QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, Qt::BrushStyle fillStyle): - JKQTPGeoBaseFilled(color, fillColor, lineWidth, style, fillStyle, parent) -{ - this->angle=0; - this->width=fabs(topright.x()-bottomleft.x()); - this->height=fabs(topright.y()-bottomleft.y()); - this->x=bottomleft.x()+this->width/2.0; - this->y=bottomleft.y()+this->height/2.0; -} - -JKQTPGeoRectangle::JKQTPGeoRectangle(JKQTPlotter *parent, QPointF bottomleft, QPointF topright, QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, Qt::BrushStyle fillStyle): - JKQTPGeoBaseFilled(color, fillColor, lineWidth, style, fillStyle, parent) -{ - this->angle=0; - this->width=fabs(topright.x()-bottomleft.x()); - this->height=fabs(topright.y()-bottomleft.y()); - this->x=bottomleft.x()+this->width/2.0; - this->y=bottomleft.y()+this->height/2.0; -} - -QTransform JKQTPGeoRectangle::getTransform() { - QTransform trans; - trans.rotate(angle); - return trans; -} - -bool JKQTPGeoRectangle::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) { - QRectF bound=getPolygon().boundingRect(); - //std::cout<<"JKQTPGeoRectangle::getXMinMax: b.left="<setHeadDecoratorStyle(JKQTPFilledDoubleArrow); - line->setTailDecoratorStyle(JKQTPCircleDecorator); - \endcode - - This results in arrows drawn at the start (aka x1/y1, =tail) and end (aka x2/y2, =head) of the line. - - - \note The convenience class JKQTPGeoArrow activates line-end decorations (aka arows) by default and allows to select them in the constructor. - - \see JKQTPGeoArrow, \ref JKQTPlotterGeometricGraphs and \ref JKQTPlotterGeometricArrows - - */ -class JKQTPLOTTER_LIB_EXPORT JKQTPGeoLine: public JKQTPGeoBaseDecoratedLine { - Q_OBJECT - public: - /*! \brief class constructor - - \param parent the parent plotter object - \param x1 x-coordinate of first point of line - \param y1 y-coordinate of first point of line - \param x2 x-coordinate of second point of line - \param y2 y-coordinate of second point of line - \param color color of line - \param lineWidth width of line - \param style line style - \param parent the parent plotter object - */ - JKQTPGeoLine(JKQTBasePlotter* parent, double x1, double y1, double x2, double y2, QColor color, double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); - /*! \brief class constructor - - \param parent the parent plotter object - \param x1 x-coordinate of first point of line - \param y1 y-coordinate of first point of line - \param x2 x-coordinate of second point of line - \param y2 y-coordinate of second point of line - \param color color of line - \param lineWidth width of line - \param style line style - \param parent the parent plotter object - */ - JKQTPGeoLine(JKQTPlotter* parent, double x1, double y1, double x2, double y2, QColor color, double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); - /*! \brief class constructor - - \param parent the parent plotter object - \param x1 x-coordinate of first point of line - \param y1 y-coordinate of first point of line - \param x2 x-coordinate of second point of line - \param y2 y-coordinate of second point of line - - */ - JKQTPGeoLine(JKQTBasePlotter* parent, double x1, double y1, double x2, double y2); - /*! \brief class constructor - - \param parent the parent plotter object - \param x1 x-coordinate of first point of line - \param y1 y-coordinate of first point of line - \param x2 x-coordinate of second point of line - \param y2 y-coordinate of second point of line - - */ - JKQTPGeoLine(JKQTPlotter* parent, double x1, double y1, double x2, double y2); - - - /** \copydoc JKQTPPlotObject::getXMinMax() */ - virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; - /** \copydoc JKQTPPlotObject::getYMinMax() */ - virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; - - /** \brief plots the graph to the plotter object specified as parent */ - virtual void draw(JKQTPEnhancedPainter& painter) override; - - /*! \copydoc x1 */ - void setX1(double __value); - /*! \copydoc x1 */ - double getX1() const; - /*! \copydoc y1 */ - void setY1(double __value); - /*! \copydoc y1 */ - double getY1() const; - /*! \copydoc x2 */ - void setX2(double __value); - /*! \copydoc x2 */ - double getX2() const; - /*! \copydoc y2 */ - void setY2(double __value); - /*! \copydoc y2 */ - double getY2() const; - protected: - /** \brief x-coordinate of first point of line */ - double x1; - /** \brief y-coordinate of first point of line */ - double y1; - /** \brief x-coordinate of second point of line */ - double x2; - /** \brief y-coordinate of second point of line */ - double y2; - -}; - - -/*! \brief This convenience specialisation of JKQTPGeoLine is used to draw a line with decorations (e.g. arrows) - \ingroup jkqtplotter_geoplots - - This class does not add any functionality on top of JKQTPGeoLine, just activates line-end markers by default! - - \image html JKQTPGeoLine_HeadTail.png - - \image html plot_geoarrows.png - - \see JKQTPLineDecoratorStyle, JKQTPGeoLine, \ref JKQTPlotterGeometricArrows and \ref JKQTPlotterGeometricGraphs - - */ -class JKQTPLOTTER_LIB_EXPORT JKQTPGeoArrow: public JKQTPGeoLine { - Q_OBJECT -public: - /*! \brief class constructor - - \param parent the parent plotter object - \param x1 x-coordinate of first point of line - \param y1 y-coordinate of first point of line - \param x2 x-coordinate of second point of line - \param y2 y-coordinate of second point of line - \param color color of line - \param lineWidth width of line - \param style line style - \param parent the parent plotter object - */ - JKQTPGeoArrow(JKQTBasePlotter* parent, double x1, double y1, double x2, double y2, QColor color, JKQTPLineDecoratorStyle headStyle=JKQTPDefaultLineDecorator, JKQTPLineDecoratorStyle tailStyle=JKQTPNoDecorator, double lineWidth=1.0, Qt::PenStyle style=Qt::SolidLine); - /*! \brief class constructor - - \param parent the parent plotter object - \param x1 x-coordinate of first point of line - \param y1 y-coordinate of first point of line - \param x2 x-coordinate of second point of line - \param y2 y-coordinate of second point of line - \param color color of line - \param lineWidth width of line - \param style line style - \param parent the parent plotter object - */ - JKQTPGeoArrow(JKQTPlotter* parent, double x1, double y1, double x2, double y2, QColor color, JKQTPLineDecoratorStyle headStyle=JKQTPDefaultLineDecorator, JKQTPLineDecoratorStyle tailStyle=JKQTPNoDecorator, double lineWidth=1.0, Qt::PenStyle style=Qt::SolidLine); - -}; - - - - - -/*! \brief This JKQTPPlotObject is used to draw an infinite line - \ingroup jkqtplotter_geoplots - - an infinite line has a starting point and then goes on in a given direction - until the end of the plotting range. - - \image html plot_geoinfiniteline.png - - You can add a decorator to the head of the line (i.e. the given start point (x,y) ) iff this line is one-sided, i.e. two_sided \c ==false . - - \see \ref JKQTPlotterGeometricGraphs and \ref JKQTPlotterGeometricArrows - - */ -class JKQTPLOTTER_LIB_EXPORT JKQTPGeoInfiniteLine: public JKQTPGeoBaseDecoratedHeadLine { - Q_OBJECT - public: - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of start point of line - \param y y-coordinate of start point of line - \param dx x-direction of the line - \param dy y-direction of the line - \param color color of line - \param lineWidth width of line - \param style line style - */ - JKQTPGeoInfiniteLine(JKQTBasePlotter* parent, double x, double y, double dx, double dy, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of start point of line - \param y y-coordinate of start point of line - \param dx x-direction of the line - \param dy y-direction of the line - \param color color of line - \param lineWidth width of line - \param style line style - */ - JKQTPGeoInfiniteLine(JKQTPlotter* parent, double x, double y, double dx, double dy, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); - - - /** \copydoc JKQTPPlotObject::getXMinMax() */ - virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; - /** \copydoc JKQTPPlotObject::getYMinMax() */ - virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; - - /** \brief plots the graph to the plotter object specified as parent */ - virtual void draw(JKQTPEnhancedPainter& painter) override; - - /*! \copydoc x */ - void setX(double __value); - /*! \copydoc x */ - double getX() const; - /*! \copydoc y */ - void setY(double __value); - /*! \copydoc y */ - double getY() const; - /*! \copydoc dx */ - void setDx(double __value); - /*! \copydoc dx */ - double getDx() const; - /*! \copydoc dy */ - void setDy(double __value); - /*! \copydoc dy */ - double getDy() const; - /*! \copydoc two_sided */ - void setTwoSided(bool __value); - /*! \copydoc two_sided */ - bool getTwoSided() const; - protected: - /** \brief x-coordinate of a point on the line */ - double x; - /** \brief y-coordinate of a point on the line */ - double y; - /** \brief x-component of the slope of the line */ - double dx; - /** \brief y-component of the slope of the line */ - double dy; - /** \brief indicates whether the line ends at the given point \f$ (x,y) \f$ (false, default), - * or is infinite in both directions (true) */ - bool two_sided; -}; - - -/*! \brief This JKQTPPlotObject is used to draw a poly line - \ingroup jkqtplotter_geoplots - - \image html plot_geolines.png - - You can also activate line-end decorators (aka arrows) for this poly-line, by using code like this: - \code - polyLine->setHeadDecoratorStyle(JKQTPFilledDoubleArrow); - polyLine->setTailDecoratorStyle(JKQTPCircleDecorator); - \endcode - - This results in arrows drawn at the start (=tail) and end (=head) of the poly-line: - \image html geo_arrow_polylines.png - - \see \ref JKQTPlotterGeometricGraphs and \ref JKQTPlotterGeometricArrows - - */ -class JKQTPLOTTER_LIB_EXPORT JKQTPGeoPolyLines: public JKQTPGeoBaseDecoratedLine { - Q_OBJECT - public: - /*! \brief class constructor - - \param parent the parent plotter object - \param points points on the polygon - \param color color of line - \param lineWidth width of line - \param style line style - */ - JKQTPGeoPolyLines(JKQTBasePlotter* parent, const QVector& points, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); - /*! \brief class constructor - - \param parent the parent plotter object - \param points points on the polygon - \param color color of line - \param lineWidth width of line - \param style line style - */ - JKQTPGeoPolyLines(JKQTPlotter* parent, const QVector& points, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); - /*! \brief class constructor - - \param parent the parent plotter object - \param color color of line - \param lineWidth width of line - \param style line style - */ - JKQTPGeoPolyLines(JKQTBasePlotter* parent, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); - /*! \brief class constructor - - \param parent the parent plotter object - \param color color of line - \param lineWidth width of line - \param style line style - */ - JKQTPGeoPolyLines(JKQTPlotter* parent, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); - - - /** \copydoc JKQTPPlotObject::getXMinMax() */ - virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; - /** \copydoc JKQTPPlotObject::getYMinMax() */ - virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; - - /** \brief plots the graph to the plotter object specified as parent */ - virtual void draw(JKQTPEnhancedPainter& painter) override; - - /*! \copydoc points */ - void setPoints(const QVector & __value); - /*! \copydoc points */ - QVector getPoints() const; - - /** \brief append a point to the polygon */ - void appendPoint(const QPointF& p); - - /** \brief append a point to the polygon */ - void appendPoint(const double x, const double y); - protected: - /** \brief list with all points on the poly-line */ - QVector points; -}; - -/*! \brief This JKQTPPlotObject is used to draw a rectangle - \ingroup jkqtplotter_geoplots - - \image html plot_georectangle.png - - \see \ref JKQTPlotterGeometricGraphs - */ -class JKQTPLOTTER_LIB_EXPORT JKQTPGeoRectangle: public JKQTPGeoBaseFilled { - Q_OBJECT - public: - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of rectangle - \param y y-coordinate of center of rectangle - \param width width of rectangle - \param height of rectangle - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of rectangle - \param fillStyle filling style of rectangle - */ - JKQTPGeoRectangle(JKQTBasePlotter* parent, double x, double y, double width, double height, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of rectangle - \param y y-coordinate of center of rectangle - \param width width of rectangle - \param height of rectangle - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of rectangle - \param fillStyle filling style of rectangle - */ - JKQTPGeoRectangle(JKQTPlotter* parent, double x, double y, double width, double height, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of rectangle - \param y y-coordinate of center of rectangle - \param width width of rectangle - \param height of rectangle - \param angle rotation angle of the rectangle - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of rectangle - \param fillStyle filling style of rectangle - */ - JKQTPGeoRectangle(JKQTBasePlotter* parent, double x, double y, double width, double height, double angle, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of rectangle - \param y y-coordinate of center of rectangle - \param width width of rectangle - \param height of rectangle - \param angle rotation angle of the rectangle - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of rectangle - \param fillStyle filling style of rectangle - */ - JKQTPGeoRectangle(JKQTPlotter* parent, double x, double y, double width, double height, double angle, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - /*! \brief class constructor - - \param parent the parent plotter object - \param bottomleft bottom left corner of rectangle - \param topright top right corner of rectangle - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of rectangle - \param fillStyle filling style of rectangle - */ - JKQTPGeoRectangle(JKQTBasePlotter* parent, QPointF bottomleft, QPointF topright, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - /*! \brief class constructor - - \param parent the parent plotter object - \param bottomleft bottom left corner of rectangle - \param topright top right corner of rectangle - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of rectangle - \param fillStyle filling style of rectangle - */ - JKQTPGeoRectangle(JKQTPlotter* parent, QPointF bottomleft, QPointF topright, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - - - - /** \copydoc JKQTPPlotObject::getXMinMax() */ - virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; - /** \copydoc JKQTPPlotObject::getYMinMax() */ - virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; - - /** \brief plots the graph to the plotter object specified as parent */ - virtual void draw(JKQTPEnhancedPainter& painter) override; - - /*! \copydoc x */ - void setX(double __value); - /*! \copydoc x */ - double getX() const; - /*! \copydoc y */ - void setY(double __value); - /*! \copydoc y */ - double getY() const; - /*! \copydoc width */ - void setWidth(double __value); - /*! \copydoc width */ - double getWidth() const; - /*! \copydoc height */ - void setHeight(double __value); - /*! \copydoc height */ - double getHeight() const; - /*! \copydoc angle */ - void setAngle(double __value); - /*! \copydoc angle */ - double getAngle() const; - /** \brief set the rectangle using the bottom-left corner, as well as its width and height */ - void setBottomleftrectangle(double x, double y, double width, double height); -protected: - /** \brief x-coordinate of a center of the rectangle */ - double x; - /** \brief y-coordinate of a center of the rectangle */ - double y; - /** \brief width of a center of the rectangle */ - double width; - /** \brief height of a center of the rectangle */ - double height; - /** \brief rotation angle of rectangle [degrees] around (x,y) */ - double angle; - /** \brief returns the transformation matrix used for this rectangle */ - QTransform getTransform(); - /** \brief returns a QPolygonF which represents the rectangle after rotation, but still in the world coordinate system, not in the screen/widget system */ - QPolygonF getPolygon(); -}; - - -/*! \brief This JKQTPPlotObject is used to draw a polygon - \ingroup jkqtplotter_geoplots - - \image html plot_geopolygon.png - - \see \ref JKQTPlotterGeometricGraphs - - */ -class JKQTPLOTTER_LIB_EXPORT JKQTPGeoPolygon: public JKQTPGeoBaseFilled { - Q_OBJECT - public: - /*! \brief class constructor - - \param parent the parent plotter object - \param points points on the polygon - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor color of the filling - \param fillStyle style of the filling - - */ - JKQTPGeoPolygon(JKQTBasePlotter* parent, const QVector& points, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - /*! \brief class constructor - - \param parent the parent plotter object - \param points points on the polygon - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor color of the filling - \param fillStyle style of the filling - */ - JKQTPGeoPolygon(JKQTPlotter* parent, const QVector& points, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - - /*! \brief class constructor - - \param parent the parent plotter object - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor color of the filling - \param fillStyle style of the filling - - */ - JKQTPGeoPolygon(JKQTBasePlotter* parent, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - /*! \brief class constructor - - \param parent the parent plotter object - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor color of the filling - \param fillStyle style of the filling - */ - JKQTPGeoPolygon(JKQTPlotter* parent, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - - - /** \copydoc JKQTPPlotObject::getXMinMax() */ - virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; - /** \copydoc JKQTPPlotObject::getYMinMax() */ - virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; - - /** \brief plots the graph to the plotter object specified as parent */ - virtual void draw(JKQTPEnhancedPainter& painter) override; - - /*! \copydoc points */ - void setPoints(const QVector & __value); - /*! \copydoc points */ - QVector getPoints() const; - - /** \brief append a point to the polygon */ - void appendPoint(const QPointF& p); - - /** \brief append a point to the polygon */ - void appendPoint(const double x, const double y); - - protected: - /** \brief list with all points on the polygon */ - QVector points; -}; - -/*! \brief This JKQTPPlotObject is used to draw an ellipse - \ingroup jkqtplotter_geoplots - - \image html plot_geoellipse.png - - \see http://www.codeguru.com/cpp/g-m/gdi/article.php/c131 and - http://en.wikipedia.org/wiki/Ellipse#General_parametric_form - - \see \ref JKQTPlotterGeometricGraphs - */ -class JKQTPLOTTER_LIB_EXPORT JKQTPGeoEllipse: public JKQTPGeoRectangle { - Q_OBJECT - public: - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of ellipse - \param y y-coordinate of center of ellipse - \param width width of ellipse (2 * half axis) - \param height of ellipse (2 * half axis) - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of ellipse - \param fillStyle filling style of ellipse - */ - JKQTPGeoEllipse(JKQTBasePlotter* parent, double x, double y, double width, double height, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of ellipse - \param y y-coordinate of center of ellipse - \param width width of ellipse (2 * half axis) - \param height of ellipse (2 * half axis) - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of ellipse - \param fillStyle filling style of ellipse - */ - JKQTPGeoEllipse(JKQTPlotter* parent, double x, double y, double width, double height, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of rectangle - \param y y-coordinate of center of rectangle - \param width width of rectangle - \param height of rectangle - \param angle rotation angle of the rectangle - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of rectangle - \param fillStyle filling style of rectangle - */ - JKQTPGeoEllipse(JKQTBasePlotter* parent, double x, double y, double width, double height, double angle, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of rectangle - \param y y-coordinate of center of rectangle - \param width width of rectangle - \param height of rectangle - \param angle rotation angle of the rectangle - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of rectangle - \param fillStyle filling style of rectangle - */ - JKQTPGeoEllipse(JKQTPlotter* parent, double x, double y, double width, double height, double angle, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - /*! \brief class constructor - - \param parent the parent plotter object - \param bottomleft bottom left corner of rectangle - \param topright top right corner of rectangle - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of rectangle - \param fillStyle filling style of rectangle - */ - JKQTPGeoEllipse(JKQTBasePlotter* parent, QPointF bottomleft, QPointF topright, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - /*! \brief class constructor - - \param parent the parent plotter object - \param bottomleft bottom left corner of rectangle - \param topright top right corner of rectangle - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of rectangle - \param fillStyle filling style of rectangle - */ - JKQTPGeoEllipse(JKQTPlotter* parent, QPointF bottomleft, QPointF topright, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - - - /** \brief plots the graph to the plotter object specified as parent */ - virtual void draw(JKQTPEnhancedPainter& painter) override; - - /*! \copydoc controlPoints */ - void setControlPoints(const unsigned int & __value); - /*! \copydoc controlPoints */ - unsigned int getControlPoints() const; - protected: - /** \brief number of steps/control points to draw the ellipse */ - unsigned int controlPoints; -}; - - -/*! \brief This JKQTPPlotObject is used to draw an arc - \ingroup jkqtplotter_geoplots - - \image html plot_geoarc.png - - \see \ref JKQTPlotterGeometricGraphs - */ -class JKQTPLOTTER_LIB_EXPORT JKQTPGeoArc: public JKQTPGeoBaseLine { - Q_OBJECT - public: - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of ellipse - \param y y-coordinate of center of ellipse - \param width width of ellipse (2 * half axis) - \param height of ellipse (2 * half axis) - \param angleStart if we only draw an arc, this is the starting angle in degrees - \param angleStop if we only draw an arc, this is the ending angle in degrees - \param color color of line - \param lineWidth width of line - \param style line style - - */ - JKQTPGeoArc(JKQTBasePlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of ellipse - \param y y-coordinate of center of ellipse - \param width width of ellipse (2 * half axis) - \param height of ellipse (2 * half axis) - \param angleStart if we only draw an arc, this is the starting angle in degrees - \param angleStop if we only draw an arc, this is the ending angle in degrees - \param color color of line - \param lineWidth width of line - \param style line style - - */ - JKQTPGeoArc(JKQTPlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine); - - /** \copydoc JKQTPPlotObject::getXMinMax() */ - virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; - /** \copydoc JKQTPPlotObject::getYMinMax() */ - virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; - - - /** \brief plots the graph to the plotter object specified as parent */ - virtual void draw(JKQTPEnhancedPainter& painter) override; - - /*! \copydoc controlPoints */ - void setControlPoints(const unsigned int & __value); - /*! \copydoc controlPoints */ - unsigned int getControlPoints() const; - /*! \copydoc angleStart */ - void setAngleStart(double __value); - /*! \copydoc angleStart */ - double getAngleStart() const; - /*! \copydoc angleStop */ - void setAngleStop(double __value); - /*! \copydoc angleStop */ - double getAngleStop() const; - /*! \copydoc x */ - void setX(double __value); - /*! \copydoc x */ - double getX() const; - /*! \copydoc y */ - void setY(double __value); - /*! \copydoc y */ - double getY() const; - /*! \copydoc width */ - void setWidth(double __value); - /*! \copydoc width */ - double getWidth() const; - /*! \copydoc height */ - void setHeight(double __value); - /*! \copydoc height */ - double getHeight() const; - /*! \copydoc angle */ - void setAngle(double __value); - /*! \copydoc angle */ - double getAngle() const; - protected: - /** \brief x-coordinate of a center of the rectangle */ - double x; - /** \brief y-coordinate of a center of the rectangle */ - double y; - /** \brief width of a center of the rectangle */ - double width; - /** \brief height of a center of the rectangle */ - double height; - /** \brief rotation angle of rectangle [degrees] around (x,y) */ - double angle; - /** \brief if we only draw an arc, this is the starting angle in degrees */ - double angleStart; - /** \brief if we only draw an arc, this is the ending angle in degrees */ - double angleStop; - /** \brief number of steps/control points to draw the ellipse */ - unsigned int controlPoints; - - /** \brief closing mode for arcs: secand or pie */ - /** \brief returns the transformation matrix used for this rectangle */ - QTransform getTransform(); - /** \brief returns a QPolygonF which represents the rectangle after rotation, but still in the world coordinate system, not in the screen/widget system */ - QPolygonF getPolygon(); - -}; - - - - -/*! \brief This JKQTPPlotObject is used to draw a pie - \ingroup jkqtplotter_geoplots - - \image html plot_geopie.png - - \see \ref JKQTPlotterGeometricGraphs - */ -class JKQTPLOTTER_LIB_EXPORT JKQTPGeoPie: public JKQTPGeoEllipse { - Q_OBJECT - public: - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of ellipse - \param y y-coordinate of center of ellipse - \param width width of ellipse (2 * half axis) - \param height of ellipse (2 * half axis) - \param angleStart if we only draw an arc, this is the starting angle in degrees - \param angleStop if we only draw an arc, this is the ending angle in degrees - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of ellipse - \param fillStyle filling style of ellipse - */ - JKQTPGeoPie(JKQTBasePlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of ellipse - \param y y-coordinate of center of ellipse - \param width width of ellipse (2 * half axis) - \param height of ellipse (2 * half axis) - \param angleStart if we only draw an arc, this is the starting angle in degrees - \param angleStop if we only draw an arc, this is the ending angle in degrees - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of ellipse - \param fillStyle filling style of ellipse - */ - JKQTPGeoPie(JKQTPlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - - - /** \copydoc JKQTPPlotObject::getXMinMax() */ - virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; - /** \copydoc JKQTPPlotObject::getYMinMax() */ - virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; - - - /** \brief plots the graph to the plotter object specified as parent */ - virtual void draw(JKQTPEnhancedPainter& painter) override; - - /*! \copydoc angleStart */ - void setAngleStart(double __value); - /*! \copydoc angleStart */ - double getAngleStart() const; - /*! \copydoc angleStop */ - void setAngleStop(double __value); - /*! \copydoc angleStop */ - double getAngleStop() const; - protected: - /** \brief if we only draw an arc, this is the starting angle */ - double angleStart; - /** \brief if we only draw an arc, this is the ending angle */ - double angleStop; -}; - - - - -/*! \brief This JKQTPPlotObject is used to draw a chord - \ingroup jkqtplotter_geoplots - - \image html plot_geochord.png - - \see \ref JKQTPlotterGeometricGraphs - */ -class JKQTPLOTTER_LIB_EXPORT JKQTPGeoChord: public JKQTPGeoPie { - Q_OBJECT - public: - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of ellipse - \param y y-coordinate of center of ellipse - \param width width of ellipse (2 * half axis) - \param height of ellipse (2 * half axis) - \param angleStart if we only draw an arc, this is the starting angle in degrees - \param angleStop if we only draw an arc, this is the ending angle in degrees - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of ellipse - \param fillStyle filling style of ellipse - */ - JKQTPGeoChord(JKQTBasePlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - /*! \brief class constructor - - \param parent the parent plotter object - \param x x-coordinate of center of ellipse - \param y y-coordinate of center of ellipse - \param width width of ellipse (2 * half axis) - \param height of ellipse (2 * half axis) - \param angleStart if we only draw an arc, this is the starting angle in degrees - \param angleStop if we only draw an arc, this is the ending angle in degrees - \param color color of line - \param lineWidth width of line - \param style line style - \param fillColor filling color of ellipse - \param fillStyle filling style of ellipse - */ - JKQTPGeoChord(JKQTPlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); - - /** \copydoc JKQTPPlotObject::getXMinMax() */ - virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; - /** \copydoc JKQTPPlotObject::getYMinMax() */ - virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; - - /** \brief plots the graph to the plotter object specified as parent */ - virtual void draw(JKQTPEnhancedPainter& painter) override; -}; +#include "jkqtplotter/graphs/jkqtpgeolines.h" +#include "jkqtplotter/graphs/jkqtpgeoshapes.h" +#include "jkqtplotter/graphs/jkqtpgeoannotations.h" #endif // jkqtpgraphsgeometric_H_INCLUDED diff --git a/lib/jkqtplotter/graphs/jkqtpgeoshapes.cpp b/lib/jkqtplotter/graphs/jkqtpgeoshapes.cpp new file mode 100644 index 0000000000..344c227034 --- /dev/null +++ b/lib/jkqtplotter/graphs/jkqtpgeoshapes.cpp @@ -0,0 +1,501 @@ +/* + Copyright (c) 2008-2020 Jan W. Krieger () + + + + This software is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License (LGPL) as published by + the Free Software Foundation, either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License (LGPL) for more details. + + You should have received a copy of the GNU Lesser General Public License (LGPL) + along with this program. If not, see . +*/ + + + +#include "jkqtplotter/graphs/jkqtpgeoshapes.h" +#include "jkqtplotter/jkqtpbaseplotter.h" +#include "jkqtplotter/jkqtplotter.h" +#include +#include +#include +#define SmallestGreaterZeroCompare_xvsgz() if ((xvsgz>10.0*DBL_MIN)&&((smallestGreaterZero<10.0*DBL_MIN) || (xvsgzx=x; + this->y=y; + angle=0; + this->width=width; + this->height=height; +} + +JKQTPGeoRectangle::JKQTPGeoRectangle(JKQTPlotter* parent, double x, double y, double width, double height, QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, Qt::BrushStyle fillStyle): + JKQTPGeoBaseFilled(color, fillColor, lineWidth, style, fillStyle, parent) +{ + this->x=x; + this->y=y; + angle=0; + this->width=width; + this->height=height; +} + +JKQTPGeoRectangle::JKQTPGeoRectangle(JKQTBasePlotter *parent, double x, double y, double width, double height, double angle, QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, Qt::BrushStyle fillStyle): + JKQTPGeoBaseFilled(color, fillColor, lineWidth, style, fillStyle, parent) +{ + this->x=x; + this->y=y; + this->angle=angle; + this->width=width; + this->height=height; +} + +JKQTPGeoRectangle::JKQTPGeoRectangle(JKQTPlotter *parent, double x, double y, double width, double height, double angle, QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, Qt::BrushStyle fillStyle): + JKQTPGeoBaseFilled(color, fillColor, lineWidth, style, fillStyle, parent) +{ + this->x=x; + this->y=y; + this->angle=angle; + this->width=width; + this->height=height; +} + +JKQTPGeoRectangle::JKQTPGeoRectangle(JKQTBasePlotter *parent, QPointF bottomleft, QPointF topright, QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, Qt::BrushStyle fillStyle): + JKQTPGeoBaseFilled(color, fillColor, lineWidth, style, fillStyle, parent) +{ + this->angle=0; + this->width=fabs(topright.x()-bottomleft.x()); + this->height=fabs(topright.y()-bottomleft.y()); + this->x=bottomleft.x()+this->width/2.0; + this->y=bottomleft.y()+this->height/2.0; +} + +JKQTPGeoRectangle::JKQTPGeoRectangle(JKQTPlotter *parent, QPointF bottomleft, QPointF topright, QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, Qt::BrushStyle fillStyle): + JKQTPGeoBaseFilled(color, fillColor, lineWidth, style, fillStyle, parent) +{ + this->angle=0; + this->width=fabs(topright.x()-bottomleft.x()); + this->height=fabs(topright.y()-bottomleft.y()); + this->x=bottomleft.x()+this->width/2.0; + this->y=bottomleft.y()+this->height/2.0; +} + +QTransform JKQTPGeoRectangle::getTransform() { + QTransform trans; + trans.rotate(angle); + return trans; +} + +bool JKQTPGeoRectangle::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) { + QRectF bound=getPolygon().boundingRect(); + //std::cout<<"JKQTPGeoRectangle::getXMinMax: b.left="<& points, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + /*! \brief class constructor + + \param parent the parent plotter object + \param points points on the polygon + \param color color of line + \param lineWidth width of line + \param style line style + \param fillColor color of the filling + \param fillStyle style of the filling + */ + JKQTPGeoPolygon(JKQTPlotter* parent, const QVector& points, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + + /*! \brief class constructor + + \param parent the parent plotter object + \param color color of line + \param lineWidth width of line + \param style line style + \param fillColor color of the filling + \param fillStyle style of the filling + + */ + JKQTPGeoPolygon(JKQTBasePlotter* parent, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + /*! \brief class constructor + + \param parent the parent plotter object + \param color color of line + \param lineWidth width of line + \param style line style + \param fillColor color of the filling + \param fillStyle style of the filling + */ + JKQTPGeoPolygon(JKQTPlotter* parent, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + + + /** \copydoc JKQTPPlotObject::getXMinMax() */ + virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; + /** \copydoc JKQTPPlotObject::getYMinMax() */ + virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; + + /** \brief plots the graph to the plotter object specified as parent */ + virtual void draw(JKQTPEnhancedPainter& painter) override; + + /*! \copydoc points */ + void setPoints(const QVector & __value); + /*! \copydoc points */ + QVector getPoints() const; + + /** \brief append a point to the polygon */ + void appendPoint(const QPointF& p); + + /** \brief append a point to the polygon */ + void appendPoint(const double x, const double y); + + protected: + /** \brief list with all points on the polygon */ + QVector points; +}; + +/*! \brief This JKQTPPlotObject is used to draw an ellipse + \ingroup jkqtplotter_geoplots + + \image html plot_geoellipse.png + + \see http://www.codeguru.com/cpp/g-m/gdi/article.php/c131 and + http://en.wikipedia.org/wiki/Ellipse#General_parametric_form + + \see \ref JKQTPlotterGeometricGraphs + */ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoEllipse: public JKQTPGeoRectangle { + Q_OBJECT + public: + /*! \brief class constructor + + \param parent the parent plotter object + \param x x-coordinate of center of ellipse + \param y y-coordinate of center of ellipse + \param width width of ellipse (2 * half axis) + \param height of ellipse (2 * half axis) + \param color color of line + \param lineWidth width of line + \param style line style + \param fillColor filling color of ellipse + \param fillStyle filling style of ellipse + */ + JKQTPGeoEllipse(JKQTBasePlotter* parent, double x, double y, double width, double height, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + + /*! \brief class constructor + + \param parent the parent plotter object + \param x x-coordinate of center of ellipse + \param y y-coordinate of center of ellipse + \param width width of ellipse (2 * half axis) + \param height of ellipse (2 * half axis) + \param color color of line + \param lineWidth width of line + \param style line style + \param fillColor filling color of ellipse + \param fillStyle filling style of ellipse + */ + JKQTPGeoEllipse(JKQTPlotter* parent, double x, double y, double width, double height, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + /*! \brief class constructor + + \param parent the parent plotter object + \param x x-coordinate of center of rectangle + \param y y-coordinate of center of rectangle + \param width width of rectangle + \param height of rectangle + \param angle rotation angle of the rectangle + \param color color of line + \param lineWidth width of line + \param style line style + \param fillColor filling color of rectangle + \param fillStyle filling style of rectangle + */ + JKQTPGeoEllipse(JKQTBasePlotter* parent, double x, double y, double width, double height, double angle, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + /*! \brief class constructor + + \param parent the parent plotter object + \param x x-coordinate of center of rectangle + \param y y-coordinate of center of rectangle + \param width width of rectangle + \param height of rectangle + \param angle rotation angle of the rectangle + \param color color of line + \param lineWidth width of line + \param style line style + \param fillColor filling color of rectangle + \param fillStyle filling style of rectangle + */ + JKQTPGeoEllipse(JKQTPlotter* parent, double x, double y, double width, double height, double angle, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + /*! \brief class constructor + + \param parent the parent plotter object + \param bottomleft bottom left corner of rectangle + \param topright top right corner of rectangle + \param color color of line + \param lineWidth width of line + \param style line style + \param fillColor filling color of rectangle + \param fillStyle filling style of rectangle + */ + JKQTPGeoEllipse(JKQTBasePlotter* parent, QPointF bottomleft, QPointF topright, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + /*! \brief class constructor + + \param parent the parent plotter object + \param bottomleft bottom left corner of rectangle + \param topright top right corner of rectangle + \param color color of line + \param lineWidth width of line + \param style line style + \param fillColor filling color of rectangle + \param fillStyle filling style of rectangle + */ + JKQTPGeoEllipse(JKQTPlotter* parent, QPointF bottomleft, QPointF topright, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + + + /** \brief plots the graph to the plotter object specified as parent */ + virtual void draw(JKQTPEnhancedPainter& painter) override; + + /*! \copydoc controlPoints */ + void setControlPoints(const unsigned int & __value); + /*! \copydoc controlPoints */ + unsigned int getControlPoints() const; + protected: + /** \brief number of steps/control points to draw the ellipse */ + unsigned int controlPoints; +}; + + + + +/*! \brief This JKQTPPlotObject is used to draw a pie + \ingroup jkqtplotter_geoplots + + \image html plot_geopie.png + + \see \ref JKQTPlotterGeometricGraphs + */ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoPie: public JKQTPGeoEllipse { + Q_OBJECT + public: + /*! \brief class constructor + + \param parent the parent plotter object + \param x x-coordinate of center of ellipse + \param y y-coordinate of center of ellipse + \param width width of ellipse (2 * half axis) + \param height of ellipse (2 * half axis) + \param angleStart if we only draw an arc, this is the starting angle in degrees + \param angleStop if we only draw an arc, this is the ending angle in degrees + \param color color of line + \param lineWidth width of line + \param style line style + \param fillColor filling color of ellipse + \param fillStyle filling style of ellipse + */ + JKQTPGeoPie(JKQTBasePlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + /*! \brief class constructor + + \param parent the parent plotter object + \param x x-coordinate of center of ellipse + \param y y-coordinate of center of ellipse + \param width width of ellipse (2 * half axis) + \param height of ellipse (2 * half axis) + \param angleStart if we only draw an arc, this is the starting angle in degrees + \param angleStop if we only draw an arc, this is the ending angle in degrees + \param color color of line + \param lineWidth width of line + \param style line style + \param fillColor filling color of ellipse + \param fillStyle filling style of ellipse + */ + JKQTPGeoPie(JKQTPlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + + + /** \copydoc JKQTPPlotObject::getXMinMax() */ + virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; + /** \copydoc JKQTPPlotObject::getYMinMax() */ + virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; + + + /** \brief plots the graph to the plotter object specified as parent */ + virtual void draw(JKQTPEnhancedPainter& painter) override; + + /*! \copydoc angleStart */ + void setAngleStart(double __value); + /*! \copydoc angleStart */ + double getAngleStart() const; + /*! \copydoc angleStop */ + void setAngleStop(double __value); + /*! \copydoc angleStop */ + double getAngleStop() const; + protected: + /** \brief if we only draw an arc, this is the starting angle */ + double angleStart; + /** \brief if we only draw an arc, this is the ending angle */ + double angleStop; +}; + + + + +/*! \brief This JKQTPPlotObject is used to draw a chord + \ingroup jkqtplotter_geoplots + + \image html plot_geochord.png + + \see \ref JKQTPlotterGeometricGraphs + */ +class JKQTPLOTTER_LIB_EXPORT JKQTPGeoChord: public JKQTPGeoPie { + Q_OBJECT + public: + /*! \brief class constructor + + \param parent the parent plotter object + \param x x-coordinate of center of ellipse + \param y y-coordinate of center of ellipse + \param width width of ellipse (2 * half axis) + \param height of ellipse (2 * half axis) + \param angleStart if we only draw an arc, this is the starting angle in degrees + \param angleStop if we only draw an arc, this is the ending angle in degrees + \param color color of line + \param lineWidth width of line + \param style line style + \param fillColor filling color of ellipse + \param fillStyle filling style of ellipse + */ + JKQTPGeoChord(JKQTBasePlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + /*! \brief class constructor + + \param parent the parent plotter object + \param x x-coordinate of center of ellipse + \param y y-coordinate of center of ellipse + \param width width of ellipse (2 * half axis) + \param height of ellipse (2 * half axis) + \param angleStart if we only draw an arc, this is the starting angle in degrees + \param angleStop if we only draw an arc, this is the ending angle in degrees + \param color color of line + \param lineWidth width of line + \param style line style + \param fillColor filling color of ellipse + \param fillStyle filling style of ellipse + */ + JKQTPGeoChord(JKQTPlotter* parent, double x, double y, double width, double height, double angleStart, double angleStop, QColor color=QColor("black"), double lineWidth=1, Qt::PenStyle style=Qt::SolidLine, QColor fillColor=QColor("transparent"), Qt::BrushStyle fillStyle=Qt::SolidPattern); + + /** \copydoc JKQTPPlotObject::getXMinMax() */ + virtual bool getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) override; + /** \copydoc JKQTPPlotObject::getYMinMax() */ + virtual bool getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) override; + + /** \brief plots the graph to the plotter object specified as parent */ + virtual void draw(JKQTPEnhancedPainter& painter) override; +}; + + +#endif // jkqtpgeoshapes_H_INCLUDED