File indexing completed on 2024-05-12 15:54:16

0001 /*
0002  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB.  All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of
0009  * the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef KCHARTGRIDATTRIBUTES_H
0021 #define KCHARTGRIDATTRIBUTES_H
0022 
0023 #include <QMetaType>
0024 #include "KChartGlobal.h"
0025 #include "KChartEnums.h"
0026 
0027 QT_BEGIN_NAMESPACE
0028 class QPen;
0029 QT_END_NAMESPACE
0030 
0031 namespace KChart {
0032 
0033 /**
0034   * @brief A set of attributes controlling the appearance of grids
0035   */
0036 class KCHART_EXPORT GridAttributes
0037 {
0038 public:
0039     GridAttributes();
0040     GridAttributes( const GridAttributes& );
0041     GridAttributes &operator= ( const GridAttributes& );
0042 
0043     ~GridAttributes();
0044 
0045     void setGridVisible( bool visible );
0046     bool isGridVisible() const;
0047 
0048     /**
0049      * When this is enabled, grid lines are drawn only where axis annotations are.
0050      * Otherwise annotations are disregarded as far as the grid is concerned.
0051      *
0052      * The default is false.
0053      */
0054     void setLinesOnAnnotations( bool );
0055     bool linesOnAnnotations() const;
0056 
0057 
0058     /**
0059       * Specifies the step width to be used for calculating
0060       * the grid lines.
0061       *
0062       * \note Step with can be set for Linear axis calculation mode only,
0063       * there is no way to specify a step width for Logarithmic axes.
0064       *
0065       * By default the GridAttributes class does not use a fixed step width,
0066       * but it uses KChartEnums::GranularitySequence_10_20.
0067       *
0068       * \param stepWidth the step width to be used.
0069       * If this parameter is omitted (or set to Zero, resp.)
0070       * the automatic step width calculation will be done,
0071       * using the granularity sequence specified.
0072       * This is the default.
0073       *
0074       * \sa gridStepWidth, setGranularitySequence
0075       */
0076     void setGridStepWidth( qreal stepWidth = 0.0 );
0077 
0078     /**
0079       * Returns the step width to be used for calculating
0080       * the grid lines.
0081       *
0082       * \sa setGridStepWidth
0083       */
0084     qreal gridStepWidth() const;
0085 
0086 
0087     /**
0088       * Specifies the sub-step width to be used for calculating
0089       * the grid sub-lines.
0090       *
0091       *
0092       * \param subStepWidth the sub-step width to be used.
0093       * If this parameter is omitted (or set to Zero, resp.)
0094       * the automatic calculation will be done, using the
0095       * granularity sequence specified.
0096       * This is the default.
0097       *
0098       * \sa gridSubStepWidth
0099       */
0100     void setGridSubStepWidth( qreal subStepWidth = 0.0 );
0101 
0102     /**
0103       * Returns the sub-step width to be used for calculating
0104       * the sub-grid lines.
0105       *
0106       * \sa setGridStepWidth
0107       */
0108     qreal gridSubStepWidth() const;
0109 
0110     /**
0111       * Specifies the granularity sequence to be used for calculating
0112       * the grid lines.
0113       *
0114       * By default the GridAttributes class uses KChartEnums::GranularitySequence_10_20.
0115       *
0116       * \note Granularity can be set for Linear axis calculation mode only,
0117       * there is no way to specify a step width for Logarithmic axes.
0118       *
0119       * \note The sequence specified by this method is ignored, if
0120       * a fixed step width was specified via setStepWidth.
0121       *
0122       * \param sequence one of the sequences declared in
0123       * KChartEnums::GranularitySequence.
0124       *
0125       * \sa gridGranularitySequence, setStepWidth
0126       */
0127     void setGridGranularitySequence( KChartEnums::GranularitySequence sequence );
0128 
0129     /**
0130       * Returns the granularity sequence to be used for calculating
0131       * the grid lines.
0132       *
0133       * \sa setGridGranularitySequence
0134       */
0135     KChartEnums::GranularitySequence gridGranularitySequence() const;
0136 
0137     /**
0138      * By default visible bounds of the data area are adjusted to match
0139      * a main grid line.
0140      * If you set the respective adjust flag to false the bound will
0141      * not start at a grid line's value but it will be the exact value
0142      * of the data range set.
0143      *
0144      * \sa CartesianCoordinatePlane::setHorizontalRange
0145      * \sa CartesianCoordinatePlane::setVerticalRange
0146      */
0147     void setAdjustBoundsToGrid( bool adjustLower, bool adjustUpper );
0148     bool adjustLowerBoundToGrid() const;
0149     bool adjustUpperBoundToGrid() const;
0150 
0151     void setGridPen( const QPen & pen );
0152     QPen gridPen() const;
0153 
0154     void setSubGridVisible( bool visible );
0155     bool isSubGridVisible() const;
0156 
0157     void setSubGridPen( const QPen & pen );
0158     QPen subGridPen() const;
0159 
0160     void setOuterLinesVisible( bool visible );
0161     bool isOuterLinesVisible() const;
0162 
0163     void setZeroLinePen( const QPen & pen );
0164     QPen zeroLinePen() const;
0165 
0166     bool operator==( const GridAttributes& ) const;
0167     inline bool operator!=( const GridAttributes& other ) const { return !operator==(other); }
0168 
0169 private:
0170     KCHART_DECLARE_PRIVATE_BASE_VALUE( GridAttributes )
0171 }; // End of class GridAttributes
0172 
0173 }
0174 
0175 #if !defined(QT_NO_DEBUG_STREAM)
0176 KCHART_EXPORT QDebug operator<<(QDebug, const KChart::GridAttributes& );
0177 #endif /* QT_NO_DEBUG_STREAM */
0178 
0179 KCHART_DECLARE_SWAP_SPECIALISATION( KChart::GridAttributes )
0180 
0181 QT_BEGIN_NAMESPACE
0182 Q_DECLARE_TYPEINFO( KChart::GridAttributes, Q_MOVABLE_TYPE );
0183 QT_END_NAMESPACE
0184 
0185 Q_DECLARE_METATYPE( KChart::GridAttributes )
0186 
0187 #endif // KCHARTGRIDATTRIBUTES_H