1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGraphs/QValueAxis>
#include <private/qvalueaxis_p.h>
#include <private/charthelpers_p.h>
#include <QtCore/QtMath>
QT_BEGIN_NAMESPACE
/*!
\class QValueAxis
\inmodule QtGraphs
\ingroup graphs_2D
\brief The QValueAxis class adds values to a graph's axes.
A value axis can be set up to show an axis line with tick marks, grid lines, and shades.
The values on the axis are drawn at the positions of tick marks.
*/
/*!
\qmltype ValueAxis
\nativetype QValueAxis
\inqmlmodule QtGraphs
\ingroup graphs_qml_2D
\inherits AbstractAxis
\brief Adds values to a graph's axes.
The ValueAxis type can be set up to show an axis line with tick marks, grid lines, and shades.
The values on the axis are drawn at the positions of tick marks.
The following example code illustrates how to use the ValueAxis type:
\code
GraphsView {
axisX: ValueAxis {
max: 10
tickInterval: 1
}
axisY: ValueAxis {
min -20
max: 40
}
LineSeries {
// Add a few XYPoint data...
}
}
\endcode
*/
/*!
\property QValueAxis::min
\brief The minimum value on the axis.
When setting this property, the maximum value is adjusted if necessary, to ensure that
the range remains valid.
The default value is 0.0
*/
/*!
\qmlproperty real ValueAxis::min
The minimum value on the axis.
When setting this property, the maximum value is adjusted if necessary, to ensure that
the range remains valid.
The default value is 0.0
*/
/*!
\property QValueAxis::max
\brief The maximum value on the axis.
When setting this property, the minimum value is adjusted if necessary, to ensure that
the range remains valid.
The default value is 10.0
*/
/*!
\qmlproperty real ValueAxis::max
The maximum value on the axis.
When setting this property, the minimum value is adjusted if necessary, to ensure that
the range remains valid.
The default value is 10.0
*/
/*!
\property QValueAxis::subTickCount
\brief The number of subticks on the axis. This indicates how many subticks are drawn
between major lines on the graph. Labels are not drawn for subticks. The default value is 0.
*/
/*!
\qmlproperty int ValueAxis::subTickCount
The number of subticks on the axis. This indicates how many subticks are drawn
between major lines on the graph. Labels are not drawn for subticks. The default value is 0.
*/
/*!
\property QValueAxis::tickAnchor
\brief The base value where the dynamically placed tick marks and labels are started from.
The default value is 0.
*/
/*!
\qmlproperty real ValueAxis::tickAnchor
The base value where the dynamically placed tick marks and labels are started from.
The default value is 0.
*/
/*!
\property QValueAxis::tickInterval
\brief The interval between dynamically placed tick marks and labels.
The default value is 0, which means that intervals are automatically calculated
based on the min and max range.
*/
/*!
\qmlproperty real ValueAxis::tickInterval
The interval between dynamically placed tick marks and labels.
The default value is 0, which means that intervals are automatically calculated
based on the min and max range.
*/
/*!
\property QValueAxis::labelFormat
\brief The label format of the axis.
The format string supports the following conversion specifiers, length modifiers, and flags
provided by \c printf() in the standard C++ library: d, i, o, x, X, f, F, e, E, g, G, c.
The default value is empty, in which case 'f' format is used.
\sa QString::asprintf()
*/
/*!
\qmlproperty string ValueAxis::labelFormat
The format string supports the following conversion specifiers, length modifiers, and flags
provided by \c printf() in the standard C++ library: d, i, o, x, X, f, F, e, E, g, G, c.
The default value is empty, in which case 'f' format is used.
\sa QString::asprintf()
*/
/*!
\property QValueAxis::labelDecimals
\brief The number of decimals used for showing the labels. When set to -1, decimal amount
is adjusted automatically based on the values range. The default value is -1.
*/
/*!
\qmlproperty int ValueAxis::labelDecimals
The number of decimals used for showing the labels. When set to -1, decimal amount
is adjusted automatically based on the values range. The default value is -1.
*/
/*!
\property QValueAxis::zoom
\since 6.9
\brief The zoom value of the axis.
The zoom value enlarges or shrinks the axis and thus the graph without affecting intervals
of grid and labels. The default value is 1.
*/
/*!
\qmlproperty real ValueAxis::zoom
\since 6.9
The zoom value of the axis.
The zoom value enlarges or shrinks the axis and thus the graph without affecting intervals
of grid and labels. The default value is 1.
*/
/*!
\property QValueAxis::pan
\since 6.9
\brief The pan value of the axis.
The pan value moves the center of the axis without affecting intervals
of grid and labels. The default value is 0.
*/
/*!
\qmlproperty real ValueAxis::pan
\since 6.9
The pan value of the axis.
The pan value moves the center of the axis without affecting intervals
of grid and labels. The default value is 0.
*/
/*!
\qmlsignal ValueAxis::minChanged(real min)
This signal is emitted when the minimum value of the axis changes to \a min.
*/
/*!
\qmlsignal ValueAxis::maxChanged(real max)
This signal is emitted when the maximum value of the axis changes to \a max.
*/
/*!
\qmlsignal ValueAxis::subTickCountChanged(int subTickCount)
This signal is emitted when the number of subticks on the axis, specified by
\a subTickCount, changes.
*/
/*!
\qmlsignal ValueAxis::rangeChanged(real min, real max)
This signal is emitted when the minimum or maximum value of the axis
changes to \a min and \a max, respectively.
*/
/*!
\qmlsignal ValueAxis::labelFormatChanged(string format)
This signal is emitted when the format of axis labels changes to \a format.
*/
/*!
\qmlsignal ValueAxis::labelDecimalsChanged(int decimals)
This signal is emitted when the amount of axis label decimals changes to \a decimals.
*/
/*!
\qmlsignal ValueAxis::tickAnchorChanged(real tickAnchor)
This signal is emitted when the tick anchoring value changes to \a tickAnchor.
*/
/*!
\qmlsignal ValueAxis::tickIntervalChanged(real tickInterval)
This signal is emitted when the tick interval value, changes to
\a tickInterval.
*/
/*!
Constructs an axis object that is a child of \a parent.
*/
QValueAxis::QValueAxis(QObject *parent)
: QAbstractAxis(*(new QValueAxisPrivate), parent)
{}
/*!
\internal
*/
QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent)
: QAbstractAxis(d, parent)
{}
/*!
Destroys the object.
*/
QValueAxis::~QValueAxis()
{
}
void QValueAxis::setMin(qreal min)
{
Q_D(QValueAxis);
setRange(min, qMax(d->m_max, min));
}
qreal QValueAxis::min() const
{
Q_D(const QValueAxis);
return d->m_min;
}
void QValueAxis::setMax(qreal max)
{
Q_D(QValueAxis);
setRange(qMin(d->m_min, max), max);
}
qreal QValueAxis::max() const
{
Q_D(const QValueAxis);
return d->m_max;
}
/*!
Sets the range from \a min to \a max on the axis.
If \a min is greater than \a max, this function returns without making any changes.
*/
void QValueAxis::setRange(qreal min, qreal max)
{
Q_D(QValueAxis);
d->setRange(min,max);
emit update();
}
void QValueAxis::setSubTickCount(qsizetype count)
{
Q_D(QValueAxis);
if (d->m_subTickCount != count && count >= 0) {
d->m_subTickCount = count;
emit update();
emit subTickCountChanged(count);
}
}
qsizetype QValueAxis::subTickCount() const
{
Q_D(const QValueAxis);
return d->m_subTickCount;
}
void QValueAxis::setTickAnchor(qreal anchor)
{
Q_D(QValueAxis);
if (d->m_tickAnchor != anchor) {
d->m_tickAnchor = anchor;
emit update();
emit tickAnchorChanged(anchor);
}
}
qreal QValueAxis::tickAnchor() const
{
Q_D(const QValueAxis);
return d->m_tickAnchor;
}
void QValueAxis::setTickInterval(qreal interval)
{
Q_D(QValueAxis);
if (d->m_tickInterval != interval) {
d->m_tickInterval = interval;
emit update();
emit tickIntervalChanged(interval);
}
}
qreal QValueAxis::tickInterval() const
{
Q_D(const QValueAxis);
return d->m_tickInterval;
}
void QValueAxis::setLabelFormat(const QString &format)
{
Q_D(QValueAxis);
d->m_format = format;
emit update();
emit labelFormatChanged(format);
}
QString QValueAxis::labelFormat() const
{
Q_D(const QValueAxis);
return d->m_format;
}
void QValueAxis::setLabelDecimals(int decimals)
{
Q_D(QValueAxis);
if (d->m_decimals != decimals) {
d->m_decimals = decimals;
emit update();
emit labelDecimalsChanged(decimals);
} else {
qCDebug(lcAxis2D, "QValueAxis::setLabelDecimals. Label decimals is already set to: %d",
decimals);
}
}
int QValueAxis::labelDecimals() const
{
Q_D(const QValueAxis);
return d->m_decimals;
}
void QValueAxis::setZoom(qreal zoom)
{
Q_D(QValueAxis);
if (d->m_zoom != zoom) {
d->m_zoom = zoom;
emit update();
emit zoomChanged(zoom);
} else {
qCDebug(lcAxis2D, "QValueAxis::setZoom. Zoom is already set to: %f",
zoom);
}
}
qreal QValueAxis::zoom() const
{
Q_D(const QValueAxis);
return d->m_zoom;
}
void QValueAxis::setPan(qreal pan)
{
Q_D(QValueAxis);
if (d->m_pan != pan) {
d->m_pan = pan;
emit update();
emit panChanged(pan);
} else {
qCDebug(lcAxis2D, "QValueAxis::setPan. Panning is already set to: %f",
pan);
}
}
qreal QValueAxis::pan() const
{
Q_D(const QValueAxis);
return d->m_pan;
}
/*!
Returns the type of the axis.
*/
QAbstractAxis::AxisType QValueAxis::type() const
{
return QAbstractAxis::AxisType::Value;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
QValueAxisPrivate::QValueAxisPrivate()
: m_min(0)
, m_max(10)
, m_subTickCount(0)
, m_format()
, m_decimals(-1)
, m_tickAnchor(0.0)
, m_tickInterval(0.0)
{}
QValueAxisPrivate::~QValueAxisPrivate() {}
void QValueAxisPrivate::setMin(const QVariant &min)
{
Q_Q(QValueAxis);
bool ok;
qreal value = min.toReal(&ok);
if (ok)
q->setMin(value);
}
void QValueAxisPrivate::setMax(const QVariant &max)
{
Q_Q(QValueAxis);
bool ok;
qreal value = max.toReal(&ok);
if (ok)
q->setMax(value);
}
void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
{
Q_Q(QValueAxis);
bool ok1;
bool ok2;
qreal value1 = min.toReal(&ok1);
qreal value2 = max.toReal(&ok2);
if (ok1 && ok2)
q->setRange(value1, value2);
}
void QValueAxisPrivate::setRange(qreal min, qreal max)
{
Q_Q(QValueAxis);
bool changed = false;
if (min > max) {
qCWarning(lcAxis2D, "min value is higher than max vaue.");
return;
}
if (!isValidValue(min, max)) {
qCWarning(lcAxis2D, "attempting to set invalid range for value axis: [%f - %f]", min, max);
return;
}
if (m_min != min) {
m_min = min;
changed = true;
emit q->minChanged(min);
}
if (m_max != max) {
m_max = max;
changed = true;
emit q->maxChanged(max);
}
if (changed)
emit q->rangeChanged(min, max);
}
QT_END_NAMESPACE
#include "moc_qvalueaxis.cpp"
|