File indexing completed on 2024-05-12 04:20:33

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 KCHARTGRIDATTRIBUTES_H
0010 #define KCHARTGRIDATTRIBUTES_H
0011 
0012 #include <QMetaType>
0013 #include "KChartGlobal.h"
0014 #include "KChartEnums.h"
0015 
0016 QT_BEGIN_NAMESPACE
0017 class QPen;
0018 QT_END_NAMESPACE
0019 
0020 namespace KChart {
0021 
0022 /**
0023   * @brief A set of attributes controlling the appearance of grids
0024   */
0025 class KCHART_EXPORT GridAttributes
0026 {
0027 public:
0028     GridAttributes();
0029     GridAttributes( const GridAttributes& );
0030     GridAttributes &operator= ( const GridAttributes& );
0031 
0032     ~GridAttributes();
0033 
0034     void setGridVisible( bool visible );
0035     bool isGridVisible() const;
0036 
0037     /**
0038      * When this is enabled, grid lines are drawn only where axis annotations are.
0039      * Otherwise annotations are disregarded as far as the grid is concerned.
0040      *
0041      * The default is false.
0042      */
0043     void setLinesOnAnnotations( bool );
0044     bool linesOnAnnotations() const;
0045 
0046 
0047     /**
0048       * Specifies the step width to be used for calculating
0049       * the grid lines.
0050       *
0051       * \note Step with can be set for Linear axis calculation mode only,
0052       * there is no way to specify a step width for Logarithmic axes.
0053       *
0054       * By default the GridAttributes class does not use a fixed step width,
0055       * but it uses KChartEnums::GranularitySequence_10_20.
0056       *
0057       * \param stepWidth the step width to be used.
0058       * If this parameter is omitted (or set to Zero, resp.)
0059       * the automatic step width calculation will be done,
0060       * using the granularity sequence specified.
0061       * This is the default.
0062       *
0063       * \sa gridStepWidth, setGranularitySequence
0064       */
0065     void setGridStepWidth( qreal stepWidth = 0.0 );
0066 
0067     /**
0068       * Returns the step width to be used for calculating
0069       * the grid lines.
0070       *
0071       * \sa setGridStepWidth
0072       */
0073     qreal gridStepWidth() const;
0074 
0075 
0076     /**
0077       * Specifies the sub-step width to be used for calculating
0078       * the grid sub-lines.
0079       *
0080       *
0081       * \param subStepWidth the sub-step width to be used.
0082       * If this parameter is omitted (or set to Zero, resp.)
0083       * the automatic calculation will be done, using the
0084       * granularity sequence specified.
0085       * This is the default.
0086       *
0087       * \sa gridSubStepWidth
0088       */
0089     void setGridSubStepWidth( qreal subStepWidth = 0.0 );
0090 
0091     /**
0092       * Returns the sub-step width to be used for calculating
0093       * the sub-grid lines.
0094       *
0095       * \sa setGridStepWidth
0096       */
0097     qreal gridSubStepWidth() const;
0098 
0099     /**
0100       * Specifies the granularity sequence to be used for calculating
0101       * the grid lines.
0102       *
0103       * By default the GridAttributes class uses KChartEnums::GranularitySequence_10_20.
0104       *
0105       * \note Granularity can be set for Linear axis calculation mode only,
0106       * there is no way to specify a step width for Logarithmic axes.
0107       *
0108       * \note The sequence specified by this method is ignored, if
0109       * a fixed step width was specified via setStepWidth.
0110       *
0111       * \param sequence one of the sequences declared in
0112       * KChartEnums::GranularitySequence.
0113       *
0114       * \sa gridGranularitySequence, setStepWidth
0115       */
0116     void setGridGranularitySequence( KChartEnums::GranularitySequence sequence );
0117 
0118     /**
0119       * Returns the granularity sequence to be used for calculating
0120       * the grid lines.
0121       *
0122       * \sa setGridGranularitySequence
0123       */
0124     KChartEnums::GranularitySequence gridGranularitySequence() const;
0125 
0126     /**
0127      * By default visible bounds of the data area are adjusted to match
0128      * a main grid line.
0129      * If you set the respective adjust flag to false the bound will
0130      * not start at a grid line's value but it will be the exact value
0131      * of the data range set.
0132      *
0133      * \sa CartesianCoordinatePlane::setHorizontalRange
0134      * \sa CartesianCoordinatePlane::setVerticalRange
0135      */
0136     void setAdjustBoundsToGrid( bool adjustLower, bool adjustUpper );
0137     bool adjustLowerBoundToGrid() const;
0138     bool adjustUpperBoundToGrid() const;
0139 
0140     void setGridPen( const QPen & pen );
0141     QPen gridPen() const;
0142 
0143     void setSubGridVisible( bool visible );
0144     bool isSubGridVisible() const;
0145 
0146     void setSubGridPen( const QPen & pen );
0147     QPen subGridPen() const;
0148 
0149     void setOuterLinesVisible( bool visible );
0150     bool isOuterLinesVisible() const;
0151 
0152     void setZeroLinePen( const QPen & pen );
0153     QPen zeroLinePen() const;
0154 
0155     bool operator==( const GridAttributes& ) const;
0156     inline bool operator!=( const GridAttributes& other ) const { return !operator==(other); }
0157 
0158 private:
0159     KCHART_DECLARE_PRIVATE_BASE_VALUE( GridAttributes )
0160 }; // End of class GridAttributes
0161 
0162 }
0163 
0164 #if !defined(QT_NO_DEBUG_STREAM)
0165 KCHART_EXPORT QDebug operator<<(QDebug, const KChart::GridAttributes& );
0166 #endif /* QT_NO_DEBUG_STREAM */
0167 
0168 KCHART_DECLARE_SWAP_SPECIALISATION( KChart::GridAttributes )
0169 
0170 QT_BEGIN_NAMESPACE
0171 Q_DECLARE_TYPEINFO( KChart::GridAttributes, Q_MOVABLE_TYPE );
0172 QT_END_NAMESPACE
0173 
0174 Q_DECLARE_METATYPE( KChart::GridAttributes )
0175 
0176 #endif // KCHARTGRIDATTRIBUTES_H