"Fossies" - the Fresh Open Source Software Archive

Member "labplot-2.8.2/src/backend/worksheet/plots/cartesian/CartesianPlot.h" (24 Feb 2021, 11811 Bytes) of package /linux/privat/labplot-2.8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "CartesianPlot.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.8.1_vs_2.8.2.

    1 
    2 /***************************************************************************
    3     File                 : CartesianPlot.h
    4     Project              : LabPlot
    5     Description          : Cartesian plot
    6     --------------------------------------------------------------------
    7     Copyright            : (C) 2011-2020 Alexander Semke (alexander.semke@web.de)
    8     Copyright            : (C) 2012-2019 Stefan Gerlach (stefan.gerlach@uni.kn)
    9 
   10  ***************************************************************************/
   11 
   12 /***************************************************************************
   13  *                                                                         *
   14  *  This program is free software; you can redistribute it and/or modify   *
   15  *  it under the terms of the GNU General Public License as published by   *
   16  *  the Free Software Foundation; either version 2 of the License, or      *
   17  *  (at your option) any later version.                                    *
   18  *                                                                         *
   19  *  This program is distributed in the hope that it will be useful,        *
   20  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
   21  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
   22  *  GNU General Public License for more details.                           *
   23  *                                                                         *
   24  *   You should have received a copy of the GNU General Public License     *
   25  *   along with this program; if not, write to the Free Software           *
   26  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
   27  *   Boston, MA  02110-1301  USA                                           *
   28  *                                                                         *
   29  ***************************************************************************/
   30 
   31 #ifndef CARTESIANPLOT_H
   32 #define CARTESIANPLOT_H
   33 
   34 #include "backend/worksheet/plots/AbstractPlot.h"
   35 #include "backend/worksheet/plots/cartesian/Axis.h"
   36 #include "backend/worksheet/plots/cartesian/Histogram.h"
   37 
   38 #include <cmath>
   39 
   40 class QToolBar;
   41 class CartesianPlotPrivate;
   42 class CartesianPlotLegend;
   43 class AbstractColumn;
   44 class XYCurve;
   45 class XYEquationCurve;
   46 class XYDataReductionCurve;
   47 class XYDifferentiationCurve;
   48 class XYIntegrationCurve;
   49 class XYInterpolationCurve;
   50 class XYSmoothCurve;
   51 class XYFitCurve;
   52 class XYFourierFilterCurve;
   53 class XYFourierTransformCurve;
   54 class XYConvolutionCurve;
   55 class XYCorrelationCurve;
   56 class KConfig;
   57 
   58 class CartesianPlot : public AbstractPlot {
   59     Q_OBJECT
   60 
   61 public:
   62     explicit CartesianPlot(const QString &name);
   63     ~CartesianPlot() override;
   64 
   65     enum class Scale {Linear, Log10, Log2, Ln, Log10Abs, Log2Abs, LnAbs, Sqrt, X2};
   66     enum class Type {FourAxes, TwoAxes, TwoAxesCentered, TwoAxesCenteredZero};
   67     enum class RangeFormat {Numeric, DateTime};
   68     enum class RangeType {Free, Last, First};
   69     enum class RangeBreakStyle {Simple, Vertical, Sloped};
   70     enum class MouseMode {Selection, ZoomSelection, ZoomXSelection, ZoomYSelection, Cursor};
   71     enum class NavigationOperation {ScaleAuto, ScaleAutoX, ScaleAutoY, ZoomIn, ZoomOut, ZoomInX, ZoomOutX,
   72                               ZoomInY, ZoomOutY, ShiftLeftX, ShiftRightX, ShiftUpY, ShiftDownY
   73                              };
   74 
   75     struct RangeBreak {
   76         RangeBreak() : start(NAN), end(NAN), position(0.5), style(RangeBreakStyle::Sloped) {}
   77         bool isValid() const {
   78             return (!std::isnan(start) && !std::isnan(end));
   79         }
   80         double start;
   81         double end;
   82         double position;
   83         RangeBreakStyle style;
   84     };
   85 
   86     //simple wrapper for QList<RangeBreaking> in order to get our macros working
   87     struct RangeBreaks {
   88         RangeBreaks() : lastChanged(-1) {
   89             RangeBreak b;
   90             list << b;
   91         };
   92         QList<RangeBreak> list;
   93         int lastChanged;
   94     };
   95 
   96     void setType(Type type);
   97     Type type() const;
   98 
   99     QIcon icon() const override;
  100     QMenu* createContextMenu() override;
  101     QMenu* analysisMenu();
  102     QVector<AbstractAspect*> dependsOn() const override;
  103     void setRect(const QRectF&) override;
  104     QRectF dataRect() const;
  105     void setMouseMode(MouseMode);
  106     void setLocked(bool);
  107     bool isLocked() const;
  108     MouseMode mouseMode() const;
  109     void navigate(NavigationOperation);
  110     void setSuppressDataChangedSignal(bool);
  111     const QList<QColor>& themeColorPalette() const;
  112     void processDropEvent(const QVector<quintptr>&) override;
  113     bool isPanningActive() const;
  114     bool isHovered() const;
  115     bool isPrinted() const;
  116     bool isSelected() const;
  117     void addLegend(CartesianPlotLegend*);
  118     int curveCount();
  119     const XYCurve* getCurve(int index);
  120     double cursorPos(int cursorNumber);
  121 
  122     void save(QXmlStreamWriter*) const override;
  123     bool load(XmlStreamReader*, bool preview) override;
  124     void loadThemeConfig(const KConfig&) override;
  125     void saveTheme(KConfig& config);
  126     void mousePressZoomSelectionMode(QPointF logicPos);
  127     void mousePressCursorMode(int cursorNumber, QPointF logicPos);
  128     void mouseMoveZoomSelectionMode(QPointF logicPos);
  129     void mouseMoveCursorMode(int cursorNumber, QPointF logicPos);
  130     void mouseReleaseZoomSelectionMode();
  131     void mouseHoverZoomSelectionMode(QPointF logicPos);
  132     void mouseHoverOutsideDataRect();
  133 
  134     BASIC_D_ACCESSOR_DECL(CartesianPlot::RangeFormat, xRangeFormat, XRangeFormat)
  135     BASIC_D_ACCESSOR_DECL(CartesianPlot::RangeFormat, yRangeFormat, YRangeFormat)
  136     const QString& xRangeDateTimeFormat() const;
  137     const QString& yRangeDateTimeFormat() const;
  138     BASIC_D_ACCESSOR_DECL(CartesianPlot::RangeType, rangeType, RangeType)
  139     BASIC_D_ACCESSOR_DECL(int, rangeLastValues, RangeLastValues)
  140     BASIC_D_ACCESSOR_DECL(int, rangeFirstValues, RangeFirstValues)
  141     BASIC_D_ACCESSOR_DECL(bool, autoScaleX, AutoScaleX)
  142     BASIC_D_ACCESSOR_DECL(bool, autoScaleY, AutoScaleY)
  143     BASIC_D_ACCESSOR_DECL(double, xMin, XMin)
  144     BASIC_D_ACCESSOR_DECL(double, xMax, XMax)
  145     BASIC_D_ACCESSOR_DECL(double, yMin, YMin)
  146     BASIC_D_ACCESSOR_DECL(double, yMax, YMax)
  147     BASIC_D_ACCESSOR_DECL(CartesianPlot::Scale, xScale, XScale)
  148     BASIC_D_ACCESSOR_DECL(CartesianPlot::Scale, yScale, YScale)
  149     BASIC_D_ACCESSOR_DECL(bool, xRangeBreakingEnabled, XRangeBreakingEnabled)
  150     BASIC_D_ACCESSOR_DECL(bool, yRangeBreakingEnabled, YRangeBreakingEnabled)
  151     CLASS_D_ACCESSOR_DECL(RangeBreaks, xRangeBreaks, XRangeBreaks)
  152     CLASS_D_ACCESSOR_DECL(RangeBreaks, yRangeBreaks, YRangeBreaks)
  153     CLASS_D_ACCESSOR_DECL(QPen, cursorPen, CursorPen);
  154     CLASS_D_ACCESSOR_DECL(bool, cursor0Enable, Cursor0Enable);
  155     CLASS_D_ACCESSOR_DECL(bool, cursor1Enable, Cursor1Enable);
  156 
  157     QString theme() const;
  158 
  159     typedef CartesianPlotPrivate Private;
  160 
  161 public slots:
  162     void setTheme(const QString&);
  163 
  164 private:
  165     void init();
  166     void initActions();
  167     void initMenus();
  168     void setColorPalette(const KConfig&);
  169     const XYCurve* currentCurve() const;
  170     void shift(bool x, bool leftOrDown);
  171     void zoom(bool x, bool in);
  172     void checkAxisFormat(const AbstractColumn*, Axis::Orientation);
  173     void calculateCurvesXMinMax(bool completeRange = true);
  174     void calculateCurvesYMinMax(bool completeRange = true);
  175 
  176     CartesianPlotLegend* m_legend{nullptr};
  177     double m_zoomFactor{1.2};
  178     QList<QColor> m_themeColorPalette;
  179     bool m_menusInitialized{false};
  180 
  181     QAction* visibilityAction;
  182 
  183     //"add new" actions
  184     QAction* addCurveAction;
  185     QAction* addEquationCurveAction;
  186     QAction* addHistogramAction;
  187     QAction* addDataReductionCurveAction;
  188     QAction* addDifferentiationCurveAction;
  189     QAction* addIntegrationCurveAction;
  190     QAction* addInterpolationCurveAction;
  191     QAction* addSmoothCurveAction;
  192     QAction* addFitCurveAction;
  193     QAction* addFourierFilterCurveAction;
  194     QAction* addFourierTransformCurveAction;
  195     QAction* addConvolutionCurveAction;
  196     QAction* addCorrelationCurveAction;
  197 
  198     QAction* addHorizontalAxisAction;
  199     QAction* addVerticalAxisAction;
  200     QAction* addLegendAction;
  201     QAction* addTextLabelAction;
  202     QAction* addImageAction;
  203     QAction* addCustomPointAction;
  204     QAction* addReferenceLineAction;
  205 
  206     //scaling, zooming, navigation actions
  207     QAction* scaleAutoXAction;
  208     QAction* scaleAutoYAction;
  209     QAction* scaleAutoAction;
  210     QAction* zoomInAction;
  211     QAction* zoomOutAction;
  212     QAction* zoomInXAction;
  213     QAction* zoomOutXAction;
  214     QAction* zoomInYAction;
  215     QAction* zoomOutYAction;
  216     QAction* shiftLeftXAction;
  217     QAction* shiftRightXAction;
  218     QAction* shiftUpYAction;
  219     QAction* shiftDownYAction;
  220 
  221     //analysis menu actions
  222     QAction* addDataOperationAction;
  223     QAction* addDataReductionAction;
  224     QAction* addDifferentiationAction;
  225     QAction* addIntegrationAction;
  226     QAction* addInterpolationAction;
  227     QAction* addSmoothAction;
  228     QVector <QAction*> addFitAction;
  229     QAction* addFourierFilterAction;
  230     QAction* addFourierTransformAction;
  231     QAction* addConvolutionAction;
  232     QAction* addCorrelationAction;
  233 
  234     QMenu* addNewMenu{nullptr};
  235     QMenu* addNewAnalysisMenu{nullptr};
  236     QMenu* zoomMenu{nullptr};
  237     QMenu* dataAnalysisMenu{nullptr};
  238     QMenu* themeMenu{nullptr};
  239 
  240     Q_DECLARE_PRIVATE(CartesianPlot)
  241 
  242 public slots:
  243     void addHorizontalAxis();
  244     void addVerticalAxis();
  245     void addCurve();
  246     void addHistogram();
  247     void addEquationCurve();
  248     void addDataReductionCurve();
  249     void addDifferentiationCurve();
  250     void addIntegrationCurve();
  251     void addInterpolationCurve();
  252     void addSmoothCurve();
  253     void addFitCurve();
  254     void addFourierFilterCurve();
  255     void addFourierTransformCurve();
  256     void addConvolutionCurve();
  257     void addCorrelationCurve();
  258 
  259     void addLegend();
  260     void addTextLabel();
  261     void addImage();
  262     void addCustomPoint();
  263     void addReferenceLine();
  264 
  265     void scaleAutoTriggered();
  266     bool scaleAuto();
  267     bool scaleAutoX();
  268     bool scaleAutoY();
  269 
  270     void zoomIn();
  271     void zoomOut();
  272     void zoomInX();
  273     void zoomOutX();
  274     void zoomInY();
  275     void zoomOutY();
  276 
  277     void shiftLeftX();
  278     void shiftRightX();
  279     void shiftUpY();
  280     void shiftDownY();
  281 
  282     void cursor();
  283 
  284     void dataChanged();
  285 
  286 private slots:
  287     void updateLegend();
  288     void childAdded(const AbstractAspect*);
  289     void childRemoved(const AbstractAspect* parent, const AbstractAspect* before, const AbstractAspect* child);
  290     void childHovered();
  291 
  292     void xDataChanged();
  293     void yDataChanged();
  294     void curveLinePenChanged(QPen);
  295     void curveVisibilityChanged();
  296 
  297     //SLOTs for changes triggered via QActions in the context menu
  298     void visibilityChanged();
  299     void loadTheme(const QString&);
  300 
  301 protected:
  302     CartesianPlot(const QString &name, CartesianPlotPrivate *dd);
  303 
  304 signals:
  305     void rangeTypeChanged(CartesianPlot::RangeType);
  306     void xRangeFormatChanged(CartesianPlot::RangeFormat);
  307     void yRangeFormatChanged(CartesianPlot::RangeFormat);
  308     void rangeLastValuesChanged(int);
  309     void rangeFirstValuesChanged(int);
  310     void rectChanged(QRectF&);
  311     void xAutoScaleChanged(bool);
  312     void xMinChanged(double);
  313     void xMaxChanged(double);
  314     void xScaleChanged(CartesianPlot::Scale);
  315     void yAutoScaleChanged(bool);
  316     void yMinChanged(double);
  317     void yMaxChanged(double);
  318     void yScaleChanged(CartesianPlot::Scale);
  319     void xRangeBreakingEnabledChanged(bool);
  320     void xRangeBreaksChanged(const CartesianPlot::RangeBreaks&);
  321     void yRangeBreakingEnabledChanged(bool);
  322     void yRangeBreaksChanged(const CartesianPlot::RangeBreaks&);
  323     void themeChanged(const QString&);
  324     void mousePressZoomSelectionModeSignal(QPointF logicPos);
  325     void mousePressCursorModeSignal(int cursorNumber, QPointF logicPos);
  326     void mouseMoveZoomSelectionModeSignal(QPointF logicPos);
  327     void mouseMoveCursorModeSignal(int cursorNumber, QPointF logicPos);
  328     void mouseReleaseCursorModeSignal();
  329     void mouseReleaseZoomSelectionModeSignal();
  330     void mouseHoverZoomSelectionModeSignal(QPointF logicalPoint);
  331     void mouseHoverOutsideDataRectSignal();
  332     void curveNameChanged(const AbstractAspect* curve);
  333     void cursorPosChanged(int cursorNumber, double xPos);
  334     void curveAdded(const XYCurve*);
  335     void curveRemoved(const XYCurve*);
  336     void curveLinePenChanged(QPen, QString curveName);
  337     void cursorPenChanged(QPen);
  338     void curveDataChanged(const XYCurve*);
  339     void curveVisibilityChangedSignal();
  340     void mouseModeChanged(CartesianPlot::MouseMode);
  341     void cursor0EnableChanged(bool enable);
  342     void cursor1EnableChanged(bool enable);
  343 };
  344 
  345 #endif