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 KCHARTLINEDIAGRAM_H 0010 #define KCHARTLINEDIAGRAM_H 0011 0012 #include "KChartAbstractCartesianDiagram.h" 0013 #include "KChartLineAttributes.h" 0014 #include "KChartValueTrackerAttributes.h" 0015 0016 QT_BEGIN_NAMESPACE 0017 class QPainter; 0018 class QPolygonF; 0019 QT_END_NAMESPACE 0020 0021 namespace KChart { 0022 0023 class ThreeDLineAttributes; 0024 0025 /** 0026 * @brief LineDiagram defines a common line diagram. 0027 * 0028 * It provides different subtypes which are set using \a setType. 0029 */ 0030 class KCHART_EXPORT LineDiagram : public AbstractCartesianDiagram 0031 { 0032 Q_OBJECT 0033 0034 Q_DISABLE_COPY( LineDiagram ) 0035 // KCHART_DECLARE_PRIVATE_DERIVED_PARENT( LineDiagram, CartesianCoordinatePlane * ) 0036 0037 KCHART_DECLARE_DERIVED_DIAGRAM( LineDiagram, CartesianCoordinatePlane ) 0038 0039 0040 public: 0041 class LineDiagramType; 0042 friend class LineDiagramType; 0043 0044 explicit LineDiagram( QWidget* parent = nullptr, CartesianCoordinatePlane* plane = nullptr ); 0045 ~LineDiagram() override; 0046 0047 0048 /** 0049 * Creates an exact copy of this diagram. 0050 */ 0051 virtual LineDiagram * clone() const; 0052 0053 /** 0054 * Returns true if both diagrams have the same settings. 0055 */ 0056 bool compare( const LineDiagram* other ) const; 0057 0058 enum LineType { 0059 Normal = 0, 0060 Stacked = 1, 0061 Percent = 2 0062 }; 0063 0064 0065 0066 /** 0067 * Sets the line diagram's type to \a type 0068 * \sa LineDiagram::LineType 0069 */ 0070 void setType( const LineType type ); 0071 0072 /** 0073 * @return the type of the line diagram 0074 */ 0075 LineType type() const; 0076 0077 /** If centerDataPoints() is true, all data points are moved by an 0078 * offset of 0.5 to the right. This is useful in conjunction with 0079 * bar diagrams, since data points are then centered just like bars. 0080 * 0081 * \sa centerDataPoints() 0082 */ 0083 void setCenterDataPoints( bool center ); 0084 /** @return option set by setCenterDataPoints() */ 0085 bool centerDataPoints() const; 0086 0087 /** With this property set to true, data sets in a normal line diagram 0088 * are drawn in reversed order. More clearly, the first (top-most) data set 0089 * in the source model will then appear in front. This is mostly due to 0090 * historical reasons. 0091 */ 0092 void setReverseDatasetOrder( bool reverse ); 0093 /** \see setReverseDatasetOrder */ 0094 bool reverseDatasetOrder() const; 0095 0096 0097 /** 0098 * Sets the global line attributes to \a la 0099 */ 0100 void setLineAttributes( const LineAttributes & a ); 0101 0102 /** 0103 * Sets the line attributes of data set \a column to \a la 0104 */ 0105 void setLineAttributes( int column, const LineAttributes & a ); 0106 0107 /** 0108 * Sets the line attributes for the model index \a index to \a la 0109 */ 0110 void setLineAttributes( const QModelIndex & index, const LineAttributes & a ); 0111 0112 /** 0113 * Resets the line attributes of data set \a column 0114 */ 0115 void resetLineAttributes( int column ); 0116 0117 /** 0118 * Remove any explicit line attributes settings that might have been specified before. 0119 */ 0120 void resetLineAttributes( const QModelIndex & index ); 0121 0122 /** 0123 * @return the global line attribute set 0124 */ 0125 LineAttributes lineAttributes() const; 0126 0127 /** 0128 * @return the line attribute set of data set \a column 0129 */ 0130 LineAttributes lineAttributes( int column ) const; 0131 0132 /** 0133 * @return the line attribute set of the model index \a index 0134 */ 0135 LineAttributes lineAttributes( const QModelIndex & index ) const; 0136 0137 0138 /** 0139 * Sets the global 3D line attributes to \a la 0140 */ 0141 void setThreeDLineAttributes( const ThreeDLineAttributes & a ); 0142 0143 /** 0144 * Sets the 3D line attributes of data set \a column to \a ta 0145 */ 0146 void setThreeDLineAttributes( int column, const ThreeDLineAttributes &ta ); 0147 0148 /** 0149 * Sets the 3D line attributes of model index \a index to \a la 0150 */ 0151 void setThreeDLineAttributes( const QModelIndex & index, 0152 const ThreeDLineAttributes &la ); 0153 0154 0155 /** 0156 * @return the global 3D line attributes 0157 */ 0158 ThreeDLineAttributes threeDLineAttributes() const; 0159 0160 /** 0161 * @return the 3D line attributes of data set \a column 0162 */ 0163 ThreeDLineAttributes threeDLineAttributes( int column ) const; 0164 0165 /** 0166 * @return the 3D line attributes of the model index \a index 0167 */ 0168 ThreeDLineAttributes threeDLineAttributes( const QModelIndex & index ) const; 0169 0170 0171 /** 0172 * Sets the value tracker attributes of the model index \a index to \a va 0173 */ 0174 void setValueTrackerAttributes( const QModelIndex & index, 0175 const ValueTrackerAttributes & a ); 0176 0177 /** 0178 * Returns the value tracker attributes of the model index \a index 0179 */ 0180 ValueTrackerAttributes valueTrackerAttributes( const QModelIndex & index ) const; 0181 0182 #if defined(Q_COMPILER_MANGLES_RETURN_TYPE) 0183 // implement AbstractCartesianDiagram 0184 /* reimpl */ 0185 const int numberOfAbscissaSegments () const; 0186 /* reimpl */ 0187 const int numberOfOrdinateSegments () const; 0188 #else 0189 // implement AbstractCartesianDiagram 0190 /* reimpl */ 0191 int numberOfAbscissaSegments () const override; 0192 /* reimpl */ 0193 int numberOfOrdinateSegments () const override; 0194 #endif 0195 0196 protected: 0197 void paint ( PaintContext* paintContext ) override; 0198 0199 public: 0200 void resize ( const QSizeF& area ) override; 0201 0202 protected: 0203 0204 qreal threeDItemDepth( const QModelIndex & index ) const override; 0205 qreal threeDItemDepth( int column ) const override; 0206 /** \reimpl */ 0207 const QPair<QPointF, QPointF> calculateDataBoundaries() const override; 0208 void paintEvent ( QPaintEvent* ) override; 0209 void resizeEvent ( QResizeEvent* ) override; 0210 }; // End of class KChartLineDiagram 0211 0212 } 0213 0214 #endif // KCHARTLINEDIAGRAM_H