1 | // Copyright (C) 2023 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include <QtGraphs/QAbstractAxis> |
5 | #include <private/qabstractaxis_p.h> |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | /*! |
10 | \class QAbstractAxis |
11 | \inmodule QtGraphs |
12 | \ingroup graphs_2D |
13 | \brief The QAbstractAxis class is a base class used for specialized axis classes. |
14 | |
15 | Each series can be bound to only one horizontal and vertical axis. |
16 | |
17 | The properties and visibility of various axis elements, such as axis line, title, labels, |
18 | and grid lines, can be individually controlled. |
19 | */ |
20 | |
21 | /*! |
22 | \qmltype AbstractAxis |
23 | \nativetype QAbstractAxis |
24 | \inqmlmodule QtGraphs |
25 | \ingroup graphs_qml_2D |
26 | |
27 | \brief A base type used for specialized axis types. |
28 | |
29 | Each series can be bound to only one horizontal and vertical axis. |
30 | |
31 | The properties and visibility of various axis elements, such as axis line, title, labels, |
32 | and grid lines, can be individually controlled. |
33 | */ |
34 | |
35 | /*! |
36 | \enum QAbstractAxis::AxisType |
37 | |
38 | This enum type specifies the type of the axis object. |
39 | |
40 | \value Value |
41 | \value BarCategory |
42 | \value DateTime |
43 | */ |
44 | |
45 | /*! |
46 | \fn void QAbstractAxis::type() const |
47 | Returns the type of the axis. |
48 | */ |
49 | |
50 | /*! |
51 | \property QAbstractAxis::visible |
52 | \brief The visibility of the axis. |
53 | By default, the value is \c true. |
54 | */ |
55 | /*! |
56 | \qmlproperty bool AbstractAxis::visible |
57 | The visibility of the axis. By default, the value is \c true. |
58 | */ |
59 | |
60 | /*! |
61 | \property QAbstractAxis::lineVisible |
62 | \brief The visibility of the axis line. |
63 | By default, the value is \c true. |
64 | */ |
65 | /*! |
66 | \qmlproperty bool AbstractAxis::lineVisible |
67 | The visibility of the axis line. By default, the value is \c true. |
68 | */ |
69 | |
70 | /*! |
71 | \property QAbstractAxis::labelsVisible |
72 | \brief Whether axis labels are visible. |
73 | By default, the value is \c true. |
74 | */ |
75 | /*! |
76 | \qmlproperty bool AbstractAxis::labelsVisible |
77 | The visibility of axis labels. By default, the value is \c true. |
78 | */ |
79 | |
80 | /*! |
81 | \property QAbstractAxis::labelsAngle |
82 | \brief The angle of the axis labels in degrees. |
83 | */ |
84 | /*! |
85 | \qmlproperty qreal AbstractAxis::labelsAngle |
86 | The angle of the axis labels in degrees. |
87 | */ |
88 | |
89 | /*! |
90 | \property QAbstractAxis::labelDelegate |
91 | \brief A custom QML Component used as a label for the axis. |
92 | This component should either be a \a Text component or contain "property string text", |
93 | so that this property will be assigned the value of the label. |
94 | */ |
95 | /*! |
96 | \qmlproperty Component AbstractAxis::labelDelegate |
97 | A custom QML Component used as a label for the axis. |
98 | This component should either be a \a Text component or contain "property string text", |
99 | so that this property will be assigned the value of the label. |
100 | */ |
101 | |
102 | /*! |
103 | \property QAbstractAxis::gridVisible |
104 | \brief The visibility of the grid lines. |
105 | By default, the value is \c true. |
106 | */ |
107 | /*! |
108 | \qmlproperty bool AbstractAxis::gridVisible |
109 | The visibility of the grid lines. By default, the value is \c true. |
110 | */ |
111 | |
112 | /*! |
113 | \property QAbstractAxis::subGridVisible |
114 | \brief The visibility of the subgrid lines. |
115 | |
116 | Applies only to axes that support subgrid lines. |
117 | By default, the value is \c true. |
118 | */ |
119 | /*! |
120 | \qmlproperty bool AbstractAxis::subGridVisible |
121 | The visibility of the subgrid lines. Applies only to axes that support |
122 | subgrid lines. By default, the value is \c true. |
123 | */ |
124 | |
125 | /*! |
126 | \property QAbstractAxis::titleText |
127 | \brief The title of the axis. |
128 | |
129 | Empty by default. Axis titles support HTML formatting. |
130 | */ |
131 | /*! |
132 | \qmlproperty string AbstractAxis::titleText |
133 | The title of the axis. Empty by default. Axis titles support HTML formatting. |
134 | */ |
135 | |
136 | /*! |
137 | \property QAbstractAxis::titleColor |
138 | \brief The color used to draw the title text. |
139 | */ |
140 | /*! |
141 | \qmlproperty color AbstractAxis::titleColor |
142 | The color used to draw the title text. |
143 | */ |
144 | |
145 | /*! |
146 | \property QAbstractAxis::titleVisible |
147 | \brief The visibility of the axis title. |
148 | |
149 | By default, the value is \c true. |
150 | */ |
151 | /*! |
152 | \qmlproperty bool AbstractAxis::titleVisible |
153 | The visibility of the axis title. By default, the value is \c true. |
154 | */ |
155 | |
156 | /*! |
157 | \property QAbstractAxis::titleFont |
158 | \brief The font of the title of the axis. |
159 | */ |
160 | /*! |
161 | \qmlproperty font AbstractAxis::titleFont |
162 | The font of the title of the axis. |
163 | */ |
164 | |
165 | /*! |
166 | \fn void QAbstractAxis::update() |
167 | This signal is emitted when the axis needs to be updated. |
168 | */ |
169 | |
170 | /*! |
171 | \qmlsignal AbstractAxis::visibleChanged(bool visible) |
172 | This signal is emitted when the visibility of the axis changes to \a visible. |
173 | */ |
174 | |
175 | /*! |
176 | \qmlsignal AbstractAxis::lineVisibleChanged(bool visible) |
177 | This signal is emitted when the visibility of the axis line changes to \a visible. |
178 | */ |
179 | |
180 | /*! |
181 | \qmlsignal AbstractAxis::labelsVisibleChanged(bool visible) |
182 | This signal is emitted when the visibility of the labels of the axis changes to \a visible. |
183 | */ |
184 | |
185 | /*! |
186 | \qmlsignal AbstractAxis::labelsAngleChanged(string angle) |
187 | This signal is emitted when the angle of the axis labels changes to \a angle. |
188 | */ |
189 | |
190 | /*! |
191 | \qmlsignal AbstractAxis::gridVisibleChanged(bool visible) |
192 | This signal is emitted when the visibility of the grid lines of the axis changes to \a visible. |
193 | */ |
194 | |
195 | /*! |
196 | \qmlsignal AbstractAxis::minorGridVisibleChanged(bool visible) |
197 | This signal is emitted when the visibility of the minor grid lines of the axis |
198 | changes to \a visible. |
199 | */ |
200 | |
201 | /*! |
202 | \qmlsignal AbstractAxis::titleTextChanged(string text) |
203 | This signal is emitted when the text of the axis title changes to \a text. |
204 | */ |
205 | |
206 | /*! |
207 | \qmlsignal AbstractAxis::titleColorChanged(color color) |
208 | This signal is emitted when the color used to draw the axis title changes to \a color. |
209 | */ |
210 | |
211 | /*! |
212 | \qmlsignal AbstractAxis::titleVisibleChanged(bool visible) |
213 | This signal is emitted when the visibility of the title text of the axis changes to \a visible. |
214 | */ |
215 | |
216 | /*! |
217 | \qmlsignal AbstractAxis::titleFontChanged(Font font) |
218 | This signal is emitted when the font of the axis title changes to \a font. |
219 | */ |
220 | |
221 | /*! |
222 | \qmlsignal AbstractAxis::rangeChanged(string min, string max) |
223 | This signal is emitted when the axis range changes. \a min and \a max are |
224 | the min and max of the new range. |
225 | */ |
226 | |
227 | /*! |
228 | \internal |
229 | Constructs a new axis object that is a child of \a parent. The ownership is taken by |
230 | graph when the axis is added. |
231 | */ |
232 | |
233 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &dd, QObject *parent) |
234 | : QObject(dd, parent) |
235 | {} |
236 | |
237 | /*! |
238 | Destructs the axis object. When the axis is added to a graph, the graph object takes ownership. |
239 | */ |
240 | |
241 | QAbstractAxis::~QAbstractAxis() |
242 | { |
243 | } |
244 | |
245 | /*! |
246 | Determines whether the axis line and tick marks are \a visible. |
247 | */ |
248 | void QAbstractAxis::setLineVisible(bool visible) |
249 | { |
250 | Q_D(QAbstractAxis); |
251 | if (d->m_lineVisible != visible) { |
252 | d->m_lineVisible = visible; |
253 | emit update(); |
254 | emit lineVisibleChanged(visible); |
255 | } |
256 | } |
257 | |
258 | bool QAbstractAxis::isLineVisible() const |
259 | { |
260 | Q_D(const QAbstractAxis); |
261 | return d->m_lineVisible; |
262 | } |
263 | |
264 | void QAbstractAxis::setGridVisible(bool visible) |
265 | { |
266 | Q_D(QAbstractAxis); |
267 | if (d->m_gridVisible != visible) { |
268 | d->m_gridVisible = visible; |
269 | emit update(); |
270 | emit gridVisibleChanged(visible); |
271 | } |
272 | } |
273 | |
274 | bool QAbstractAxis::isGridVisible() const |
275 | { |
276 | Q_D(const QAbstractAxis); |
277 | return d->m_gridVisible; |
278 | } |
279 | |
280 | void QAbstractAxis::setSubGridVisible(bool visible) |
281 | { |
282 | Q_D(QAbstractAxis); |
283 | if (d->m_subGridVisible != visible) { |
284 | d->m_subGridVisible = visible; |
285 | emit update(); |
286 | emit subGridVisibleChanged(visible); |
287 | } |
288 | } |
289 | |
290 | bool QAbstractAxis::isSubGridVisible() const |
291 | { |
292 | Q_D(const QAbstractAxis); |
293 | return d->m_subGridVisible; |
294 | } |
295 | |
296 | void QAbstractAxis::setLabelsVisible(bool visible) |
297 | { |
298 | Q_D(QAbstractAxis); |
299 | if (d->m_labelsVisible != visible) { |
300 | d->m_labelsVisible = visible; |
301 | emit update(); |
302 | emit labelsVisibleChanged(visible); |
303 | } |
304 | } |
305 | |
306 | bool QAbstractAxis::labelsVisible() const |
307 | { |
308 | Q_D(const QAbstractAxis); |
309 | return d->m_labelsVisible; |
310 | } |
311 | |
312 | void QAbstractAxis::setLabelsAngle(qreal angle) |
313 | { |
314 | Q_D(QAbstractAxis); |
315 | if (d->m_labelsAngle != angle) { |
316 | d->m_labelsAngle = angle; |
317 | emit update(); |
318 | emit labelsAngleChanged(angle); |
319 | } |
320 | } |
321 | |
322 | qreal QAbstractAxis::labelsAngle() const |
323 | { |
324 | Q_D(const QAbstractAxis); |
325 | return d->m_labelsAngle; |
326 | } |
327 | |
328 | QQmlComponent *QAbstractAxis::labelDelegate() const |
329 | { |
330 | Q_D(const QAbstractAxis); |
331 | return d->m_labelDelegate; |
332 | } |
333 | |
334 | void QAbstractAxis::setLabelDelegate(QQmlComponent *newLabelDelegate) |
335 | { |
336 | Q_D(QAbstractAxis); |
337 | if (d->m_labelDelegate == newLabelDelegate) |
338 | return; |
339 | d->m_labelDelegate = newLabelDelegate; |
340 | emit labelDelegateChanged(); |
341 | emit update(); |
342 | } |
343 | |
344 | void QAbstractAxis::setTitleVisible(bool visible) |
345 | { |
346 | Q_D(QAbstractAxis); |
347 | if (d->m_titleVisible != visible) { |
348 | d->m_titleVisible = visible; |
349 | emit update(); |
350 | emit titleVisibleChanged(visible); |
351 | } |
352 | } |
353 | |
354 | bool QAbstractAxis::isTitleVisible() const |
355 | { |
356 | Q_D(const QAbstractAxis); |
357 | return d->m_titleVisible; |
358 | } |
359 | |
360 | /*! |
361 | Sets the color used to draw titles to \a color. |
362 | */ |
363 | void QAbstractAxis::setTitleColor(QColor color) |
364 | { |
365 | Q_D(QAbstractAxis); |
366 | if (d->m_titleColor != color) { |
367 | d->m_titleColor = color; |
368 | emit update(); |
369 | emit titleColorChanged(color); |
370 | } |
371 | } |
372 | |
373 | /*! |
374 | Returns the color used to draw titles. |
375 | */ |
376 | QColor QAbstractAxis::titleColor() const |
377 | { |
378 | Q_D(const QAbstractAxis); |
379 | return d->m_titleColor; |
380 | } |
381 | |
382 | /*! |
383 | Sets the font used to draw titles to \a font. |
384 | */ |
385 | void QAbstractAxis::setTitleFont(const QFont &font) |
386 | { |
387 | Q_D(QAbstractAxis); |
388 | if (d->m_titleFont != font) { |
389 | d->m_titleFont = font; |
390 | emit update(); |
391 | emit titleFontChanged(font); |
392 | } |
393 | } |
394 | |
395 | /*! |
396 | Returns the font used to draw titles. |
397 | */ |
398 | QFont QAbstractAxis::titleFont() const |
399 | { |
400 | Q_D(const QAbstractAxis); |
401 | return d->m_titleFont; |
402 | } |
403 | |
404 | void QAbstractAxis::setTitleText(const QString &title) |
405 | { |
406 | Q_D(QAbstractAxis); |
407 | if (d->m_title != title) { |
408 | d->m_title = title; |
409 | emit update(); |
410 | emit titleTextChanged(title); |
411 | } |
412 | } |
413 | |
414 | QString QAbstractAxis::titleText() const |
415 | { |
416 | Q_D(const QAbstractAxis); |
417 | return d->m_title; |
418 | } |
419 | |
420 | bool QAbstractAxis::isVisible() const |
421 | { |
422 | Q_D(const QAbstractAxis); |
423 | return d->m_visible; |
424 | } |
425 | |
426 | /*! |
427 | Sets the visibility of the axis, labels, and grid lines to \a visible. |
428 | */ |
429 | void QAbstractAxis::setVisible(bool visible) |
430 | { |
431 | Q_D(QAbstractAxis); |
432 | if (d->m_visible != visible) { |
433 | d->m_visible = visible; |
434 | emit update(); |
435 | emit visibleChanged(visible); |
436 | } |
437 | } |
438 | |
439 | |
440 | /*! |
441 | Makes the axis, labels, and grid lines visible. |
442 | */ |
443 | void QAbstractAxis::show() |
444 | { |
445 | setVisible(true); |
446 | } |
447 | |
448 | /*! |
449 | Makes the axis, labels, and grid lines invisible. |
450 | */ |
451 | void QAbstractAxis::hide() |
452 | { |
453 | setVisible(false); |
454 | } |
455 | |
456 | /*! |
457 | Sets the minimum value shown on the axis. |
458 | Depending on the actual axis type, the \a min parameter is converted to the appropriate type |
459 | of value. If the conversion is impossible, the function call does nothing. |
460 | */ |
461 | void QAbstractAxis::setMin(const QVariant &min) |
462 | { |
463 | Q_D(QAbstractAxis); |
464 | d->setMin(min); |
465 | } |
466 | |
467 | /*! |
468 | Sets the maximum value shown on the axis. |
469 | Depending on the actual axis type, the \a max parameter is converted to the appropriate type |
470 | of value. If the conversion is impossible, the function call does nothing. |
471 | */ |
472 | void QAbstractAxis::setMax(const QVariant &max) |
473 | { |
474 | Q_D(QAbstractAxis); |
475 | d->setMax(max); |
476 | } |
477 | |
478 | /*! |
479 | Sets the range shown on the axis. |
480 | Depending on the actual axis type, the \a min and \a max parameters are converted to |
481 | appropriate types of values. If the conversion is impossible, the function call does nothing. |
482 | */ |
483 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
484 | { |
485 | Q_D(QAbstractAxis); |
486 | d->setRange(min, max); |
487 | } |
488 | |
489 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
490 | |
491 | QAbstractAxisPrivate::QAbstractAxisPrivate() {} |
492 | |
493 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
494 | { |
495 | Q_Q(QAbstractAxis); |
496 | if (m_graph) |
497 | m_graph->removeAxis(axis: q); |
498 | } |
499 | |
500 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) |
501 | { |
502 | setRange(min,max); |
503 | } |
504 | |
505 | QT_END_NAMESPACE |
506 | |
507 | |
508 |
Definitions
- QAbstractAxis
- ~QAbstractAxis
- setLineVisible
- isLineVisible
- setGridVisible
- isGridVisible
- setSubGridVisible
- isSubGridVisible
- setLabelsVisible
- labelsVisible
- setLabelsAngle
- labelsAngle
- labelDelegate
- setLabelDelegate
- setTitleVisible
- isTitleVisible
- setTitleColor
- titleColor
- setTitleFont
- titleFont
- setTitleText
- titleText
- isVisible
- setVisible
- show
- hide
- setMin
- setMax
- setRange
- QAbstractAxisPrivate
- ~QAbstractAxisPrivate
Start learning QML with our Intro Training
Find out more