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

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 KCHARTBARDIAGRAM_P_H
0010 #define KCHARTBARDIAGRAM_P_H
0011 
0012 //
0013 //  W A R N I N G
0014 //  -------------
0015 //
0016 // This file is not part of the KD Chart API.  It exists purely as an
0017 // implementation detail.  This header file may change from version to
0018 // version without notice, or even be removed.
0019 //
0020 // We mean it.
0021 //
0022 
0023 #include "KChartBarDiagram.h"
0024 
0025 #include <QPainterPath>
0026 
0027 #include "KChartAbstractCartesianDiagram_p.h"
0028 #include "KChartThreeDBarAttributes.h"
0029 #include "KChartMath_p.h"
0030 
0031 
0032 namespace KChart {
0033 
0034 class PaintContext;
0035 
0036 /**
0037  * \internal
0038  */
0039 class Q_DECL_HIDDEN BarDiagram::Private : public AbstractCartesianDiagram::Private
0040 {
0041     friend class BarDiagram;
0042     friend class BarDiagramType;
0043 
0044 public:
0045     Private();
0046     Private( const Private& rhs );
0047     ~Private() override;
0048 
0049     void setOrientationAndType( Qt::Orientation, BarDiagram::BarType );
0050 
0051     Qt::Orientation orientation;
0052 
0053     BarDiagramType* implementor; // the current type
0054     BarDiagramType* normalDiagram;
0055     BarDiagramType* stackedDiagram;
0056     BarDiagramType* percentDiagram;
0057     BarDiagramType* normalLyingDiagram;
0058     BarDiagramType* stackedLyingDiagram;
0059     BarDiagramType* percentLyingDiagram;
0060 };
0061 
0062 KCHART_IMPL_DERIVED_DIAGRAM( BarDiagram, AbstractCartesianDiagram, CartesianCoordinatePlane )
0063 
0064     class BarDiagram::BarDiagramType
0065     {
0066     public:
0067         explicit BarDiagramType( BarDiagram* d )
0068             : m_private( d->d_func() )
0069         {
0070         }
0071         virtual ~BarDiagramType() {}
0072         virtual BarDiagram::BarType type() const = 0;
0073         virtual const QPair<QPointF,  QPointF> calculateDataBoundaries() const = 0;
0074         virtual void paint( PaintContext* ctx ) = 0;
0075         BarDiagram* diagram() const;
0076 
0077     protected:
0078         // make some elements of m_private available to derived classes:
0079         AttributesModel* attributesModel() const;
0080         QModelIndex attributesModelRootIndex() const;
0081         ReverseMapper& reverseMapper();
0082         CartesianDiagramDataCompressor& compressor() const;
0083 
0084         void paintBars( PaintContext* ctx, const QModelIndex& index, const QRectF& bar, qreal maxDepth );
0085         void calculateValueAndGapWidths( int rowCount, int colCount,
0086             qreal groupWidth,
0087             qreal& barWidth,
0088             qreal& spaceBetweenBars,
0089             qreal& spaceBetweenGroups );
0090 
0091         BarDiagram::Private* m_private;
0092     };
0093 }
0094 
0095 #endif /* KCHARTBARDIAGRAM_P_H */