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
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "qvalue3daxis_p.h"
#include "qvalue3daxisformatter_p.h"
QT_BEGIN_NAMESPACE
/*!
* \class QValue3DAxis
* \inmodule QtGraphs
* \ingroup graphs_3D
* \brief The QValue3DAxis class manipulates an axis of a graph.
*
* A value axis can be given a range of values and segment and subsegment
* counts to divide the range into.
*
* Labels are drawn between each segment, and grid lines are drawn between each
* segment and each subsegment. \note If visible, there will always be at least
* two grid lines and labels indicating the minimum and maximum values of
* the range, as there is always at least one segment.
*/
/*!
* \qmltype Value3DAxis
* \inqmlmodule QtGraphs
* \ingroup graphs_qml_3D
* \nativetype QValue3DAxis
* \inherits Abstract3DAxis
* \brief Manipulates an axis of a graph.
*
* This type provides an axis that can be given a range of values and segment
* and subsegment counts to divide the range into.
*/
/*!
* \qmlproperty qsizetype Value3DAxis::segmentCount
*
* The number of segments on the axis. This indicates how many labels are drawn.
* The number of grid lines to be drawn is calculated with the following
* formula: \c {segments * subsegments + 1}. The preset default is \c 5. The
* value cannot be below \c 1.
*/
/*!
* \qmlproperty qsizetype Value3DAxis::subSegmentCount
*
* The number of subsegments inside each segment on the axis. Grid lines are
* drawn between each subsegment, in addition to each segment. The preset
* default is \c 1. The value cannot be below \c 1.
*/
/*!
* \qmlproperty string Value3DAxis::labelFormat
*
* The label format to be used for the labels on this 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.
*
* If GraphsItem3D::locale is anything else than \c{"C"}, the supported
* specifiers are limited to: d, e, E, f, g, G, and i. Also, only the precision
* modifier is supported. The rest of the formatting comes from the default
* \l [QML] Locale of the application.
*
* \sa GraphsItem3D::locale
*/
/*!
* \qmlproperty Value3DAxisFormatter Value3DAxis::formatter
*
* The axis formatter to be used. Any existing formatter is deleted when a new
* formatter is set.
*
*/
/*!
* \qmlproperty bool Value3DAxis::reversed
*
* If \c{true}, the axis will be rendered in reverse. That is, the positions of
* the minimum and maximum values are swapped when the graph is rendered. This
* property does not affect the actual minimum and maximum values of the axis.
*/
/*!
\qmlsignal Value3DAxis::segmentCountChanged(qsizetype count)
This signal is emitted when segmentCount changes to \a count.
*/
/*!
\qmlsignal Value3DAxis::subSegmentCountChanged(qsizetype count)
This signal is emitted when subSegmentCount changes to \a count.
*/
/*!
\qmlsignal Value3DAxis::labelFormatChanged(string format)
This signal is emitted when labelFormat changes to \a format.
*/
/*!
\qmlsignal Value3DAxis::formatterChanged(Value3DAxisFormatter formatter)
This signal is emitted when \l formatter changes to \a formatter.
*/
/*!
\qmlsignal Value3DAxis::reversedChanged(bool enable)
This signal is emitted when \l reversed changes to \a enable.
*/
/*!
* Constructs QValue3DAxis with the given \a parent.
*/
QValue3DAxis::QValue3DAxis(QObject *parent)
: QAbstract3DAxis(*(new QValue3DAxisPrivate()), parent)
{
setFormatter(new QValue3DAxisFormatter);
}
/*!
* Destroys QValue3DAxis.
*/
QValue3DAxis::~QValue3DAxis() {}
/*!
* \property QValue3DAxis::segmentCount
*
* \brief The number of segments on the axis.
*
* This indicates how many labels are drawn. The number
* of grid lines to be drawn is calculated with formula: \c {segments *
* subsegments + 1}. The preset default is \c 5. The value cannot be below \c 1.
*
* \sa setSubSegmentCount()
*/
void QValue3DAxis::setSegmentCount(qsizetype count)
{
Q_D(QValue3DAxis);
if (count <= 0) {
qWarning(
"Warning: Illegal segment count automatically adjusted to a legal one: %" PRIdQSIZETYPE
" --> 1",
count);
count = 1;
}
if (d->m_segmentCount != count) {
d->m_segmentCount = count;
d->emitLabelsChanged();
emit segmentCountChanged(count);
}
}
qsizetype QValue3DAxis::segmentCount() const
{
Q_D(const QValue3DAxis);
return d->m_segmentCount;
}
/*!
* \property QValue3DAxis::subSegmentCount
*
* \brief The number of subsegments inside each segment on the axis.
*
* Grid lines are drawn between
* each subsegment, in addition to each segment.
* The preset default is \c 1. The value cannot be below \c 1.
*
* \sa setSegmentCount()
*/
void QValue3DAxis::setSubSegmentCount(qsizetype count)
{
Q_D(QValue3DAxis);
if (count <= 0) {
qWarning("Warning: Illegal subsegment count automatically adjusted to a legal one: "
"%" PRIdQSIZETYPE " -> 1",
count);
count = 1;
}
if (d->m_subSegmentCount != count) {
d->m_subSegmentCount = count;
emit subSegmentCountChanged(count);
}
}
qsizetype QValue3DAxis::subSegmentCount() const
{
Q_D(const QValue3DAxis);
return d->m_subSegmentCount;
}
/*!
* \property QValue3DAxis::labelFormat
*
* \brief The label format to be used for the labels on this 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.
*
* If Q3DGraphsWidgetItem::locale is anything else than \c{"C"}, the supported
* specifiers are limited to: d, e, E, f, g, G, and i. Also, only the precision
* modifier is supported. The rest of the formatting comes from the default
* QLocale of the application.
*
* Usage example:
*
* \c {axis->setLabelFormat("%.2f mm");}
*
* \sa formatter, Q3DGraphsWidgetItem::locale
*/
void QValue3DAxis::setLabelFormat(const QString &format)
{
Q_D(QValue3DAxis);
if (d->m_labelFormat != format) {
d->m_labelFormat = format;
d->emitLabelsChanged();
emit labelFormatChanged(format);
}
}
QString QValue3DAxis::labelFormat() const
{
Q_D(const QValue3DAxis);
return d->m_labelFormat;
}
/*!
* \property QValue3DAxis::formatter
*
* \brief The axis formatter to be used.
*
* Any existing formatter is deleted when a new formatter
* is set.
*/
void QValue3DAxis::setFormatter(QValue3DAxisFormatter *formatter)
{
Q_ASSERT(formatter);
Q_D(QValue3DAxis);
if (formatter != d->m_formatter) {
delete d->m_formatter;
d->m_formatter = formatter;
formatter->setParent(this);
formatter->setAxis(this);
emit formatterChanged(formatter);
emit formatterDirty();
}
}
QValue3DAxisFormatter *QValue3DAxis::formatter() const
{
Q_D(const QValue3DAxis);
return d->m_formatter;
}
/*!
* \property QValue3DAxis::reversed
*
* \brief Whether the axis is rendered in reverse.
*
* If \c{true}, the axis will be rendered in reverse, which means the positions
* of minimum and maximum values are swapped when the graph is rendered. This
* property doesn't affect the actual minimum and maximum values of the axis.
*/
void QValue3DAxis::setReversed(bool enable)
{
Q_D(QValue3DAxis);
if (d->m_reversed != enable) {
d->m_reversed = enable;
emit reversedChanged(enable);
}
}
bool QValue3DAxis::reversed() const
{
Q_D(const QValue3DAxis);
return d->m_reversed;
}
void QValue3DAxis::recalculate()
{
formatter()->d_func()->recalculate();
}
qsizetype QValue3DAxis::gridSize()
{
return formatter()->gridPositions().size();
}
qsizetype QValue3DAxis::subGridSize()
{
return formatter()->subGridPositions().size();
}
float QValue3DAxis::gridPositionAt(qsizetype gridLine)
{
return formatter()->gridPositions().at(gridLine);
}
float QValue3DAxis::subGridPositionAt(qsizetype gridLine)
{
return formatter()->subGridPositions().at(gridLine);
}
float QValue3DAxis::labelPositionAt(qsizetype index)
{
return formatter()->labelPositions().at(index);
}
float QValue3DAxis::positionAt(float x)
{
return formatter()->positionAt(x);
}
QString QValue3DAxis::stringForValue(float x)
{
return formatter()->stringForValue(x, labelFormat());
}
QValue3DAxisPrivate::QValue3DAxisPrivate()
: QAbstract3DAxisPrivate(QAbstract3DAxis::AxisType::Value)
, m_segmentCount(5)
, m_subSegmentCount(1)
, m_labelFormat(Utils::defaultLabelFormat())
, m_labelsDirty(true)
, m_formatter(0)
, m_reversed(false)
{}
QValue3DAxisPrivate::~QValue3DAxisPrivate() {}
void QValue3DAxisPrivate::setRange(float min, float max, bool suppressWarnings)
{
bool dirty = (min != m_min || max != m_max);
QAbstract3DAxisPrivate::setRange(min, max, suppressWarnings);
if (dirty)
emitLabelsChanged();
}
void QValue3DAxisPrivate::setMin(float min)
{
bool dirty = (min != m_min);
QAbstract3DAxisPrivate::setMin(min);
if (dirty)
emitLabelsChanged();
}
void QValue3DAxisPrivate::setMax(float max)
{
bool dirty = (max != m_max);
QAbstract3DAxisPrivate::setMax(max);
if (dirty)
emitLabelsChanged();
}
void QValue3DAxisPrivate::emitLabelsChanged()
{
Q_Q(QValue3DAxis);
m_labelsDirty = true;
emit q->labelsChanged();
}
void QValue3DAxisPrivate::emitFormatterDirty()
{
Q_Q(QValue3DAxis);
m_labelsDirty = true;
emit q->formatterDirty();
}
void QValue3DAxisPrivate::updateLabels()
{
if (!m_labelsDirty)
return;
m_labelsDirty = false;
m_formatter->d_func()->recalculate();
m_labels = m_formatter->labelStrings();
}
bool QValue3DAxisPrivate::allowZero()
{
return m_formatter->allowZero();
}
bool QValue3DAxisPrivate::allowNegatives()
{
return m_formatter->allowNegatives();
}
bool QValue3DAxisPrivate::allowMinMaxSame()
{
return false;
}
QT_END_NAMESPACE
|