File indexing completed on 2024-05-26 04:23:58

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 KCHARTRINGDIAGRAM_H
0010 #define KCHARTRINGDIAGRAM_H
0011 
0012 #include "KChartAbstractPieDiagram.h"
0013 
0014 namespace KChart {
0015 
0016 /**
0017   * @brief RingDiagram defines a common ring diagram
0018   */
0019 class KCHART_EXPORT RingDiagram : public AbstractPieDiagram
0020 {
0021     Q_OBJECT
0022 
0023     Q_DISABLE_COPY( RingDiagram )
0024     KCHART_DECLARE_DERIVED_DIAGRAM( RingDiagram, PolarCoordinatePlane )
0025 
0026 public:
0027     explicit RingDiagram(
0028         QWidget* parent = nullptr, PolarCoordinatePlane* plane = nullptr );
0029     ~RingDiagram() override;
0030 
0031 protected:
0032     // Implement AbstractDiagram
0033     /** \reimpl */
0034     void paint( PaintContext* paintContext ) override;
0035 public:
0036     /** \reimpl */
0037     void resize( const QSizeF& area ) override;
0038 
0039     // Implement AbstractPolarDiagram
0040     /** \reimpl */
0041     qreal valueTotals() const override;
0042     /** \reimpl */
0043     qreal numberOfValuesPerDataset() const override;
0044     qreal numberOfDatasets() const override;
0045     /** \reimpl */
0046     qreal numberOfGridRings() const override;
0047 
0048     qreal valueTotals( int dataset ) const;
0049 
0050 
0051     /**
0052       * Creates an exact copy of this diagram.
0053       */
0054    virtual RingDiagram * clone() const;
0055 
0056     /**
0057      * Returns true if both diagrams have the same settings.
0058      */
0059     bool compare( const RingDiagram* other ) const;
0060 
0061     void setRelativeThickness( bool relativeThickness );
0062     bool relativeThickness() const;
0063 
0064     virtual void setExpandWhenExploded( bool expand );
0065     virtual bool expandWhenExploded() const;
0066 
0067 protected:
0068     /** \reimpl */
0069     const QPair<QPointF, QPointF> calculateDataBoundaries() const override;
0070     void paintEvent( QPaintEvent* ) override;
0071     void resizeEvent( QResizeEvent* ) override;
0072 
0073 private:
0074 
0075     /**
0076       \param painter the QPainter to draw in
0077       \param dataset the dataset to draw the slice for
0078       \param slice the slice to draw
0079       */
0080    void drawOneSlice( QPainter* painter, uint dataset, uint slice, qreal granularity );
0081 
0082     /**
0083       Internal method that draws the top surface of one of the slices in a ring chart.
0084 
0085       \param painter the QPainter to draw in
0086       \param dataset the dataset to draw the slice for
0087       \param slice the slice to draw
0088       */
0089    void drawPieSurface( QPainter* painter, uint dataset, uint slice, qreal granularity );
0090 
0091     /**
0092       * Auxiliary method returning a point to a given boundary
0093       * rectangle of the enclosed ellipse and an angle.
0094       */
0095    QPointF pointOnEllipse( const QRectF& rect, int dataset, int slice, bool outer, qreal angle,
0096                             qreal totalGapFactor, qreal totalExplodeFactor );
0097 }; // End of class RingDiagram
0098 
0099 }
0100 
0101 #endif // KCHARTRINGDIAGRAM_H