File indexing completed on 2024-12-15 04:02:32

0001 /*
0002  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #ifndef KCHARTPLOTTER_H
0010 #define KCHARTPLOTTER_H
0011 
0012 #include "KChartAbstractCartesianDiagram.h"
0013 
0014 #include "KChartLineAttributes.h"
0015 #include "KChartValueTrackerAttributes.h"
0016 
0017 namespace KChart {
0018 
0019     class ThreeDLineAttributes;
0020 
0021 /**
0022   * @brief Plotter defines a diagram type plotting two-dimensional data.
0023   */
0024 class KCHART_EXPORT Plotter : public AbstractCartesianDiagram
0025 {
0026     Q_OBJECT
0027 
0028     Q_DISABLE_COPY( Plotter )
0029 
0030     KCHART_DECLARE_DERIVED_DIAGRAM( Plotter, CartesianCoordinatePlane )
0031     Q_PROPERTY( CompressionMode useDataCompression READ useDataCompression WRITE setUseDataCompression )
0032     Q_PROPERTY( qreal mergeRadiusPercentage READ mergeRadiusPercentage WRITE setMergeRadiusPercentage )
0033 
0034 public:
0035     // SLOPE enables a compression based on minimal slope changes
0036     // DISTANCE is still buggy and can fail, same for BOTH, NONE is the default mode
0037     enum CompressionMode{ SLOPE, DISTANCE, BOTH, NONE };
0038     Q_ENUM( CompressionMode )
0039     class PlotterType;
0040     friend class PlotterType;
0041 
0042     explicit Plotter( QWidget* parent = nullptr, CartesianCoordinatePlane* plane = nullptr );
0043     ~Plotter() override;
0044 
0045 
0046     /**
0047       * Creates an exact copy of this diagram.
0048       */
0049    virtual Plotter* clone() const;
0050 
0051     /**
0052      * Returns true if both diagrams have the same settings.
0053      */
0054     bool compare( const Plotter* other ) const;
0055 
0056     enum PlotType {
0057         Normal =  0,
0058         Percent,
0059         Stacked
0060     };
0061 
0062 
0063 
0064     /**
0065       * Sets the plotter's type to \a type
0066       */
0067    void setType( const PlotType type );
0068 
0069     /**
0070       * @return the type of the plotter
0071       */
0072     PlotType type() const;
0073 
0074     /**
0075       * Sets the global line attributes to \a la
0076       */
0077     void setLineAttributes( const LineAttributes & la );
0078 
0079     /**
0080      * Sets the line attributes of data set \a column to \a la
0081      */
0082     void setLineAttributes( int column, const LineAttributes &la );
0083 
0084     /**
0085     * Sets the line attributes for the model index \a index to \a la
0086     */
0087     void setLineAttributes( const QModelIndex & index, const LineAttributes &la );
0088 
0089     /**
0090       * Resets the line attributes of data set \a column
0091       */
0092     void resetLineAttributes( int column );
0093 
0094     /**
0095     * Remove any explicit line attributes settings that might have been specified before.
0096     */
0097     void resetLineAttributes( const QModelIndex & index );
0098 
0099     /**
0100       * @return the global line attribute set
0101       */
0102     LineAttributes lineAttributes() const;
0103 
0104    /**
0105      * @return the line attribute set of data set \a column
0106      */
0107    LineAttributes lineAttributes( int column ) const;
0108 
0109     /**
0110     * @return the line attribute set of the model index \a index
0111     */
0112     LineAttributes lineAttributes( const QModelIndex & index ) const;
0113 
0114     /**
0115       * Sets the global 3D line attributes to \a la
0116       */
0117     void setThreeDLineAttributes( const ThreeDLineAttributes & la );
0118 
0119     /**
0120      * Sets the 3D line attributes of data set \a column to \a la
0121      */
0122     void setThreeDLineAttributes( int column, const ThreeDLineAttributes & la );
0123 
0124     /**
0125     * Sets the 3D line attributes of model index \a index to \a la
0126     */
0127     void setThreeDLineAttributes( const QModelIndex & index,
0128                                   const ThreeDLineAttributes & la );
0129 
0130     /**
0131       * @return the global 3D line attributes
0132       */
0133     ThreeDLineAttributes threeDLineAttributes() const;
0134 
0135     /**
0136      * @return the 3D line attributes of data set \a column
0137      */
0138     ThreeDLineAttributes threeDLineAttributes( int column ) const;
0139 
0140     /**
0141     * @return the 3D line attributes of the model index \a index
0142     */
0143     ThreeDLineAttributes threeDLineAttributes( const QModelIndex & index ) const;
0144 
0145     /**
0146       * Sets the value tracker attributes of the model index \a index to \a va
0147       */
0148    void setValueTrackerAttributes( const QModelIndex & index,
0149                                     const ValueTrackerAttributes & va );
0150 
0151     /**
0152       * Returns the value tracker attributes of the model index \a index
0153       */
0154    ValueTrackerAttributes valueTrackerAttributes( const QModelIndex & index ) const;
0155 
0156     CompressionMode useDataCompression() const;
0157     void setUseDataCompression( CompressionMode value );
0158 
0159     qreal maxSlopeChange() const;
0160     void setMaxSlopeChange( qreal value );
0161 
0162     qreal mergeRadiusPercentage() const;
0163     void setMergeRadiusPercentage( qreal value );
0164 
0165 #if defined(Q_COMPILER_MANGLES_RETURN_TYPE)
0166     // implement AbstractCartesianDiagram
0167     /* reimpl */
0168     const int numberOfAbscissaSegments () const;
0169     /* reimpl */
0170     const int numberOfOrdinateSegments () const;
0171 #else
0172     // implement AbstractCartesianDiagram
0173     /* reimpl */
0174     int numberOfAbscissaSegments () const override;
0175     /* reimpl */
0176     int numberOfOrdinateSegments () const override;
0177 #endif
0178 
0179 protected Q_SLOTS:
0180     void connectAttributesModel( KChart::AttributesModel* );
0181 
0182 protected:
0183     void paint ( PaintContext* paintContext ) override;
0184 
0185 public:
0186     void resize ( const QSizeF& area ) override;
0187 
0188 protected:
0189     qreal threeDItemDepth( const QModelIndex & index ) const override;
0190     qreal threeDItemDepth( int column ) const override;
0191     /** \reimpl */
0192     const QPair<QPointF, QPointF> calculateDataBoundaries() const override;
0193     void paintEvent ( QPaintEvent* ) override;
0194     void resizeEvent ( QResizeEvent* ) override;
0195 protected Q_SLOTS:
0196     void setDataBoundariesDirty();
0197     void calcMergeRadius();
0198 }; // End of class KChart::Plotter
0199 
0200 }
0201 
0202 #endif // KCHARTLINEDIAGRAM_H