1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB.  All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef KCHARTGRIDATTRIBUTES_H
21 #define KCHARTGRIDATTRIBUTES_H
22 
23 #include <QMetaType>
24 #include "KChartGlobal.h"
25 #include "KChartEnums.h"
26 
27 QT_BEGIN_NAMESPACE
28 class QPen;
29 QT_END_NAMESPACE
30 
31 namespace KChart {
32 
33 /**
34   * @brief A set of attributes controlling the appearance of grids
35   */
36 class KCHART_EXPORT GridAttributes
37 {
38 public:
39     GridAttributes();
40     GridAttributes( const GridAttributes& );
41     GridAttributes &operator= ( const GridAttributes& );
42 
43     ~GridAttributes();
44 
45     void setGridVisible( bool visible );
46     bool isGridVisible() const;
47 
48     /**
49      * When this is enabled, grid lines are drawn only where axis annotations are.
50      * Otherwise annotations are disregarded as far as the grid is concerned.
51      *
52      * The default is false.
53      */
54     void setLinesOnAnnotations( bool );
55     bool linesOnAnnotations() const;
56 
57 
58     /**
59       * Specifies the step width to be used for calculating
60       * the grid lines.
61       *
62       * \note Step with can be set for Linear axis calculation mode only,
63       * there is no way to specify a step width for Logarithmic axes.
64       *
65       * By default the GridAttributes class does not use a fixed step width,
66       * but it uses KChartEnums::GranularitySequence_10_20.
67       *
68       * \param stepWidth the step width to be used.
69       * If this parameter is omitted (or set to Zero, resp.)
70       * the automatic step width calculation will be done,
71       * using the granularity sequence specified.
72       * This is the default.
73       *
74       * \sa gridStepWidth, setGranularitySequence
75       */
76     void setGridStepWidth( qreal stepWidth = 0.0 );
77 
78     /**
79       * Returns the step width to be used for calculating
80       * the grid lines.
81       *
82       * \sa setGridStepWidth
83       */
84     qreal gridStepWidth() const;
85 
86 
87     /**
88       * Specifies the sub-step width to be used for calculating
89       * the grid sub-lines.
90       *
91       *
92       * \param subStepWidth the sub-step width to be used.
93       * If this parameter is omitted (or set to Zero, resp.)
94       * the automatic calculation will be done, using the
95       * granularity sequence specified.
96       * This is the default.
97       *
98       * \sa gridSubStepWidth
99       */
100     void setGridSubStepWidth( qreal subStepWidth = 0.0 );
101 
102     /**
103       * Returns the sub-step width to be used for calculating
104       * the sub-grid lines.
105       *
106       * \sa setGridStepWidth
107       */
108     qreal gridSubStepWidth() const;
109 
110     /**
111       * Specifies the granularity sequence to be used for calculating
112       * the grid lines.
113       *
114       * By default the GridAttributes class uses KChartEnums::GranularitySequence_10_20.
115       *
116       * \note Granularity can be set for Linear axis calculation mode only,
117       * there is no way to specify a step width for Logarithmic axes.
118       *
119       * \note The sequence specified by this method is ignored, if
120       * a fixed step width was specified via setStepWidth.
121       *
122       * \param sequence one of the sequences declared in
123       * KChartEnums::GranularitySequence.
124       *
125       * \sa gridGranularitySequence, setStepWidth
126       */
127     void setGridGranularitySequence( KChartEnums::GranularitySequence sequence );
128 
129     /**
130       * Returns the granularity sequence to be used for calculating
131       * the grid lines.
132       *
133       * \sa setGridGranularitySequence
134       */
135     KChartEnums::GranularitySequence gridGranularitySequence() const;
136 
137     /**
138      * By default visible bounds of the data area are adjusted to match
139      * a main grid line.
140      * If you set the respective adjust flag to false the bound will
141      * not start at a grid line's value but it will be the exact value
142      * of the data range set.
143      *
144      * \sa CartesianCoordinatePlane::setHorizontalRange
145      * \sa CartesianCoordinatePlane::setVerticalRange
146      */
147     void setAdjustBoundsToGrid( bool adjustLower, bool adjustUpper );
148     bool adjustLowerBoundToGrid() const;
149     bool adjustUpperBoundToGrid() const;
150 
151     void setGridPen( const QPen & pen );
152     QPen gridPen() const;
153 
154     void setSubGridVisible( bool visible );
155     bool isSubGridVisible() const;
156 
157     void setSubGridPen( const QPen & pen );
158     QPen subGridPen() const;
159 
160     void setOuterLinesVisible( bool visible );
161     bool isOuterLinesVisible() const;
162 
163     void setZeroLinePen( const QPen & pen );
164     QPen zeroLinePen() const;
165 
166     bool operator==( const GridAttributes& ) const;
167     inline bool operator!=( const GridAttributes& other ) const { return !operator==(other); }
168 
169 private:
170     KCHART_DECLARE_PRIVATE_BASE_VALUE( GridAttributes )
171 }; // End of class GridAttributes
172 
173 }
174 
175 #if !defined(QT_NO_DEBUG_STREAM)
176 KCHART_EXPORT QDebug operator<<(QDebug, const KChart::GridAttributes& );
177 #endif /* QT_NO_DEBUG_STREAM */
178 
179 KCHART_DECLARE_SWAP_SPECIALISATION( KChart::GridAttributes )
180 
181 QT_BEGIN_NAMESPACE
182 Q_DECLARE_TYPEINFO( KChart::GridAttributes, Q_MOVABLE_TYPE );
183 QT_END_NAMESPACE
184 
185 Q_DECLARE_METATYPE( KChart::GridAttributes )
186 
187 #endif // KCHARTGRIDATTRIBUTES_H
188