1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include <QtCore/qdebug.h>
5#include "qabstract3daxis_p.h"
6#include "qgraphs3dlogging_p.h"
7
8QT_BEGIN_NAMESPACE
9
10/*!
11 * \class QAbstract3DAxis
12 * \inmodule QtGraphs
13 * \ingroup graphs_3D
14 * \brief The QAbstract3DAxis class is a base class for the axes of a 3D graph.
15 *
16 * This class specifies the enumerations, properties, and functions shared by
17 * graph axes. It should not be used directly, but one of its subclasses should
18 * be used instead.
19 *
20 * \sa QCategory3DAxis, QValue3DAxis
21 */
22
23/*!
24 * \qmltype Abstract3DAxis
25 * \qmlabstract
26 * \inqmlmodule QtGraphs
27 * \ingroup graphs_qml_3D
28 * \nativetype QAbstract3DAxis
29 * \brief A base type for the axes of a 3D graph.
30 * For Abstract3DAxis enums, see \l QAbstract3DAxis::AxisOrientation and
31 * \l{QAbstract3DAxis::AxisType}.
32 */
33
34/*!
35 * \qmlproperty string Abstract3DAxis::title
36 * The title for the axis.
37 *
38 * \sa titleVisible, titleFixed
39 */
40
41/*!
42 * \qmlproperty list Abstract3DAxis::labels
43 * The labels for the axis.
44 * \note Setting this property for Value3DAxis does nothing, as it generates
45 * labels automatically.
46 */
47
48/*!
49 * \qmlproperty Abstract3DAxis.AxisOrientation Abstract3DAxis::orientation
50 * The orientation of the axis.
51 */
52
53/*!
54 * \qmlproperty Abstract3DAxis.AxisType Abstract3DAxis::type
55 * The type of the axis.
56 */
57
58/*!
59 * \qmlproperty real Abstract3DAxis::min
60 *
61 * The minimum value on the axis.
62 * When setting this property, the maximum value is adjusted if necessary, so
63 * the range remains valid.
64 */
65
66/*!
67 * \qmlproperty real Abstract3DAxis::max
68 *
69 * The maximum value on the axis.
70 * When setting this property, the minimum value is adjusted if necessary, so
71 * the range remains valid.
72 */
73
74/*!
75 * \qmlproperty bool Abstract3DAxis::autoAdjustRange
76 *
77 * Defines whether the axis will automatically adjust the range so that all data
78 * fits in it.
79 */
80
81/*!
82 * \qmlproperty real Abstract3DAxis::labelAutoAngle
83 *
84 * The maximum angle the labels can autorotate when the camera angle changes.
85 * The angle can be between 0 and 90, inclusive. The default value is 0.
86 * If the value is 0, axis labels do not automatically rotate.
87 * If the value is greater than zero, labels attempt to orient themselves toward
88 * the camera, up to the specified angle.
89 */
90
91/*!
92 * \qmlproperty bool Abstract3DAxis::titleVisible
93 *
94 * Defines whether the axis title is visible in the primary graph view.
95 *
96 * The default value is \c{false}.
97 *
98 * \sa title, titleFixed
99 */
100
101/*!
102 * \qmlproperty bool Abstract3DAxis::labelsVisible
103 *
104 * Defines whether the axis labels are visible in the primary graph view.
105 *
106 * The default value is \c{true}.
107 *
108 */
109
110/*!
111 * \qmlproperty bool Abstract3DAxis::titleFixed
112 *
113 * The rotation of axis titles.
114 *
115 * If \c{false}, axis titles in the primary graph view will be rotated towards
116 * the camera similarly to the axis labels. If \c{true}, axis titles are only
117 * rotated around their axis but are not otherwise oriented towards the camera.
118 * This property does not have any effect if the labelAutoAngle property
119 * value is zero.
120 * Default value is \c{true}.
121 *
122 * \sa labelAutoAngle, title, titleVisible
123 */
124
125/*!
126 * \qmlproperty real Abstract3DAxis::titleOffset
127 *
128 * The position of the axis title on the axis.
129 * The value must be between \c -1.0f and \c 1.0f
130 *
131 * Default value is \c{0}.
132 *
133 * \sa title, titleVisible
134 */
135
136/*!
137 * \qmlproperty bool Abstract3DAxis::scaleLabelsByCount
138 * \since 6.9
139 *
140 * Whether the labels will automatically adjust their size based on the total amount of labels.
141 *
142 * \sa labelSize
143 */
144
145/*!
146 * \qmlproperty real Abstract3DAxis::labelSize
147 * \since 6.9
148 *
149 * The size of the label.
150 * The default for this value is \c 1.0.
151 *
152 * \sa scaleLabelsByCount
153 */
154
155/*!
156 \qmlsignal Abstract3DAxis::titleChanged(string newTitle)
157
158 This signal is emitted when \l title changes to \a newTitle.
159*/
160/*!
161 \qmlsignal Abstract3DAxis::labelsChanged()
162
163 This signal is emitted when axis labels change.
164*/
165/*!
166 \qmlsignal Abstract3DAxis::orientationChanged(AxisOrientation orientation)
167
168 This signal is emitted when axis orientation changes to \a orientation.
169*/
170/*!
171 \qmlsignal Abstract3DAxis::minChanged(real value)
172
173 This signal is emitted when the minimum value of the axis changes
174 to \a value.
175*/
176/*!
177 \qmlsignal Abstract3DAxis::maxChanged(real value)
178
179 This signal is emitted when the maximum value of the axis changes
180 to \a value.
181*/
182/*!
183 \qmlsignal Abstract3DAxis::rangeChanged(real min, real max)
184
185 This signal is emitted when the axis range changes. \a min and \a max are
186 the min and max of the new range.
187*/
188/*!
189 \qmlsignal Abstract3DAxis::autoAdjustRangeChanged(bool autoAdjust)
190
191 This signal is emitted when the \l autoAdjustRange property value changes
192 to \a autoAdjust.
193*/
194/*!
195 \qmlsignal Abstract3DAxis::labelAutoAngleChanged(real angle)
196
197 This signal is emitted when the angle of label rotation changes to
198 \a angle.
199*/
200/*!
201 \qmlsignal Abstract3DAxis::titleVisibilityChanged(bool visible)
202
203 This signal is emitted when the title visibility changes to \a visible.
204*/
205/*!
206 \qmlsignal Abstract3DAxis::labelVisibilityChanged(bool visible)
207
208 This signal is emitted when the label visibility changes to \a visible.
209*/
210/*!
211 \qmlsignal Abstract3DAxis::titleFixedChanged(bool fixed)
212
213 This signal is emitted when the titleFixed property value changes to
214 \a fixed.
215*/
216/*!
217 \qmlsignal Abstract3DAxis::titleOffsetChanged(real offset)
218
219 This signal is emitted when the titleOffset property value changes to
220 \a offset.
221*/
222/*!
223 \qmlsignal Abstract3DAxis::scaleLabelsByCountChanged(bool adjust)
224
225 This signal is emitted when the scaleLabelsByCount property value changes to
226 \a adjust.
227*/
228/*!
229 \qmlsignal Abstract3DAxis::labelSizeChanged(real size)
230
231 This signal is emitted when the labelSize property value changes to
232 \a size.
233*/
234
235/*!
236 * \enum QAbstract3DAxis::AxisOrientation
237 *
238 * The orientation of the axis object.
239 *
240 * \value None
241 * \value X
242 * \value Y
243 * \value Z
244 */
245
246/*!
247 * \enum QAbstract3DAxis::AxisType
248 *
249 * The type of the axis object.
250 *
251 * \value None
252 * \value Category
253 * \value Value
254 */
255
256/*!
257 * \internal
258 */
259QAbstract3DAxis::QAbstract3DAxis(QAbstract3DAxisPrivate &d, QObject *parent)
260 : QObject(d, parent)
261
262{}
263
264/*!
265 * Destroys QAbstract3DAxis.
266 */
267QAbstract3DAxis::~QAbstract3DAxis() {}
268
269/*!
270 * \property QAbstract3DAxis::orientation
271 *
272 * \brief The orientation of the axis.
273 *
274 * The value is one of AxisOrientation values.
275 */
276QAbstract3DAxis::AxisOrientation QAbstract3DAxis::orientation() const
277{
278 Q_D(const QAbstract3DAxis);
279 return d->m_orientation;
280}
281
282/*!
283 * \property QAbstract3DAxis::type
284 *
285 * \brief The type of the axis.
286 *
287 * The value is one of AxisType values.
288 */
289QAbstract3DAxis::AxisType QAbstract3DAxis::type() const
290{
291 Q_D(const QAbstract3DAxis);
292 return d->m_type;
293}
294
295/*!
296 * \property QAbstract3DAxis::title
297 *
298 * \brief The title for the axis.
299 *
300 * \sa titleVisible, titleFixed
301 */
302void QAbstract3DAxis::setTitle(const QString &title)
303{
304 Q_D(QAbstract3DAxis);
305 if (d->m_title == title) {
306 qCDebug(lcAProperties3D, "%s title is already set to: %s",
307 qUtf8Printable(QLatin1String(__FUNCTION__)), qUtf8Printable(title));
308 return;
309 }
310
311 d->m_title = title;
312 emit titleChanged(newTitle: title);
313}
314
315QString QAbstract3DAxis::title() const
316{
317 Q_D(const QAbstract3DAxis);
318 return d->m_title;
319}
320
321/*!
322 * \property QAbstract3DAxis::labels
323 *
324 * \brief The labels for the axis.
325 * \note Setting this property for QValue3DAxis does nothing, as it generates
326 * labels automatically.
327 */
328void QAbstract3DAxis::setLabels(const QStringList &labels)
329{
330 Q_UNUSED(labels);
331}
332
333QStringList QAbstract3DAxis::labels() const
334{
335 Q_D(const QAbstract3DAxis);
336 const_cast<QAbstract3DAxisPrivate *>(d)->updateLabels();
337 return const_cast<QAbstract3DAxisPrivate *>(d)->m_labels;
338}
339
340/*!
341 * Sets the value range of the axis from \a min to \a max.
342 * When setting the range, the maximum value is adjusted if necessary, to ensure
343 * that the range remains valid.
344 * \note For QCategory3DAxis, specifies the index range of rows or columns to
345 * show.
346 */
347void QAbstract3DAxis::setRange(float min, float max)
348{
349 Q_D(QAbstract3DAxis);
350 d->setRange(min, max);
351 setAutoAdjustRange(false);
352}
353
354/*!
355 * \property QAbstract3DAxis::labelAutoAngle
356 *
357 * \brief The maximum angle the labels can autorotate when the camera angle
358 * changes.
359 *
360 * The angle can be between 0 and 90, inclusive. The default value is 0.
361 * If the value is 0, axis labels do not automatically rotate.
362 * If the value is greater than zero, labels attempt to orient themselves toward
363 * the camera, up to the specified angle.
364 */
365void QAbstract3DAxis::setLabelAutoAngle(float degree)
366{
367 Q_D(QAbstract3DAxis);
368 if (degree < 0.0f) {
369 qCWarning(lcAProperties3D, "%s invalid angle degree."
370 "degree has been set to 0.0f",
371 qUtf8Printable(QLatin1String(__FUNCTION__)));
372 degree = 0.0f;
373 }
374
375 if (degree > 90.0f) {
376 qCWarning(lcAProperties3D, "%s invalid angle degree."
377 "degree has been set to 90.0f",
378 qUtf8Printable(QLatin1String(__FUNCTION__)));
379 degree = 90.0f;
380 }
381
382 if (qFuzzyCompare(p1: d->m_labelAutoAngle, p2: degree)) {
383 qCDebug(lcAProperties3D, "%s angle value is already: %f",
384 qUtf8Printable(QLatin1String(__FUNCTION__)), degree);
385 return;
386 }
387
388 d->m_labelAutoAngle = degree;
389 emit labelAutoAngleChanged(angle: degree);
390}
391
392float QAbstract3DAxis::labelAutoAngle() const
393{
394 Q_D(const QAbstract3DAxis);
395 return d->m_labelAutoAngle;
396}
397
398/*!
399 * \property QAbstract3DAxis::titleVisible
400 *
401 * \brief Whether the axis title is visible in the primary graph view.
402 *
403 * The default value is \c{false}.
404 *
405 * \sa title, titleFixed
406 */
407void QAbstract3DAxis::setTitleVisible(bool visible)
408{
409 Q_D(QAbstract3DAxis);
410 if (d->m_titleVisible == visible) {
411 qCDebug(lcAProperties3D) << __FUNCTION__
412 << "visibility is already set to:" << visible;
413 return;
414 }
415
416 d->m_titleVisible = visible;
417 emit titleVisibleChanged(visible);
418}
419
420bool QAbstract3DAxis::isTitleVisible() const
421{
422 Q_D(const QAbstract3DAxis);
423 return d->m_titleVisible;
424}
425
426/*!
427 * \property QAbstract3DAxis::labelsVisible
428 *
429 * \brief Whether the axis labels are visible in the primary graph view.
430 *
431 * The default value is \c{true}.
432 *
433 */
434void QAbstract3DAxis::setLabelsVisible(bool visible)
435{
436 Q_D(QAbstract3DAxis);
437 if (d->m_labelsVisible == visible) {
438 qCDebug(lcAProperties3D) << __FUNCTION__
439 << "visibility is already set to:" << visible;
440 return;
441 }
442
443 d->m_labelsVisible = visible;
444 emit labelVisibleChanged(visible);
445}
446
447bool QAbstract3DAxis::labelsVisible() const
448{
449 Q_D(const QAbstract3DAxis);
450 return d->m_labelsVisible;
451}
452
453/*!
454 * \property QAbstract3DAxis::titleFixed
455 *
456 * \brief The rotation of the axis titles.
457 *
458 * If \c{false}, axis titles in the primary graph view will be rotated towards
459 * the camera similarly to the axis labels. If \c{true}, axis titles are only
460 * rotated around their axis but are not otherwise oriented towards the camera.
461 * This property does not have any effect if the labelAutoAngle property
462 * value is zero.
463 * Default value is \c{true}.
464 *
465 * \sa labelAutoAngle, title, titleVisible
466 */
467void QAbstract3DAxis::setTitleFixed(bool fixed)
468{
469 Q_D(QAbstract3DAxis);
470 if (d->m_titleFixed == fixed) {
471 qCDebug(lcAProperties3D) << __FUNCTION__
472 << "value is already set to:" << fixed;
473 return;
474 }
475
476 d->m_titleFixed = fixed;
477 emit titleFixedChanged(fixed);
478}
479
480bool QAbstract3DAxis::isTitleFixed() const
481{
482 Q_D(const QAbstract3DAxis);
483 return d->m_titleFixed;
484}
485
486/*!
487 * \property QAbstract3DAxis::min
488 *
489 * \brief The minimum value on the axis.
490 *
491 * When setting this property, the maximum value is adjusted if necessary, to
492 * ensure that the range remains valid.
493 * \note For QCategory3DAxis, specifies the index of the first row or column to
494 * show.
495 */
496void QAbstract3DAxis::setMin(float min)
497{
498 Q_D(QAbstract3DAxis);
499 d->setMin(min);
500 setAutoAdjustRange(false);
501}
502
503/*!
504 * \property QAbstract3DAxis::max
505 *
506 * \brief The maximum value on the axis.
507 *
508 * When setting this property, the minimum value is adjusted if necessary, to
509 * ensure that the range remains valid.
510 * \note For QCategory3DAxis, specifies the index of the last row or column to
511 * show.
512 */
513void QAbstract3DAxis::setMax(float max)
514{
515 Q_D(QAbstract3DAxis);
516 d->setMax(max);
517 setAutoAdjustRange(false);
518}
519
520float QAbstract3DAxis::min() const
521{
522 Q_D(const QAbstract3DAxis);
523 return d->m_min;
524}
525
526float QAbstract3DAxis::max() const
527{
528 Q_D(const QAbstract3DAxis);
529 return d->m_max;
530}
531
532/*!
533 * \property QAbstract3DAxis::autoAdjustRange
534 *
535 * \brief Whether the axis will automatically adjust the range so that all data
536 * fits in it.
537 *
538 * \sa setRange(), setMin(), setMax()
539 */
540void QAbstract3DAxis::setAutoAdjustRange(bool autoAdjust)
541{
542 Q_D(QAbstract3DAxis);
543 if (d->m_autoAdjust == autoAdjust) {
544 qCDebug(lcAProperties3D) << __FUNCTION__
545 << "value is already set to:" << autoAdjust;
546 return;
547 }
548
549 d->m_autoAdjust = autoAdjust;
550 emit autoAdjustRangeChanged(autoAdjust);
551}
552
553bool QAbstract3DAxis::isAutoAdjustRange() const
554{
555 Q_D(const QAbstract3DAxis);
556 return d->m_autoAdjust;
557}
558
559/*!
560 * \property QAbstract3DAxis::scaleLabelsByCount
561 * \since 6.9
562 * \brief Whether the labels will automatically adjust their size
563 * based on the total amount of labels
564 *
565 * \sa labelSize()
566 */
567void QAbstract3DAxis::setScaleLabelsByCount(bool adjust)
568{
569 Q_D(QAbstract3DAxis);
570 if (d->m_scaleLabelsByCount == adjust) {
571 qCDebug(lcAProperties3D) << __FUNCTION__
572 << "value is already set to:" << adjust;
573 return;
574 }
575
576 d->m_scaleLabelsByCount = adjust;
577 emit scaleLabelsByCountChanged(adjust);
578
579}
580
581bool QAbstract3DAxis::isScaleLabelsByCount() const
582{
583 Q_D(const QAbstract3DAxis);
584 return d->m_scaleLabelsByCount;
585}
586
587/*!
588 * \property QAbstract3DAxis::labelSize
589 * \since 6.9
590 * \brief Size of the label
591 *
592 * The size of the label.
593 * The default for this value is \c 1.0.
594 *
595 * \sa scaleLabelsByCount
596 */
597void QAbstract3DAxis::setLabelSize(qreal size)
598{
599 Q_D(QAbstract3DAxis);
600 if (qFuzzyCompare(p1: d->m_labelSize, p2: size)) {
601 qCDebug(lcAProperties3D, "%s Value is already set to: %f",
602 qUtf8Printable(QLatin1String(__FUNCTION__)), size);
603 return;
604 }
605
606 d->m_labelSize = size;
607 emit labelSizeChanged(size);
608}
609
610qreal QAbstract3DAxis::labelSize() const
611{
612 Q_D(const QAbstract3DAxis);
613 return d->m_labelSize;
614}
615
616/*!
617 * \property QAbstract3DAxis::titleOffset
618 *
619 * The position of the axis title on the axis.
620 * The value must be between \c -1.0f and \c 1.0f
621 *
622 * \sa title, titleFixed
623 */
624void QAbstract3DAxis::setTitleOffset(float offset)
625{
626 Q_D(QAbstract3DAxis);
627 if (qFuzzyCompare(p1: d->m_titleOffset, p2: offset)) {
628 qCDebug(lcAProperties3D, "%s offset value is already set to: %f",
629 qUtf8Printable(QLatin1String(__FUNCTION__)), offset);
630 return;
631 } else if (offset < -1.0f || offset > 1.0f) {
632 qCWarning(lcAProperties3D, "%s invalid value. Valid range for title offset is between "
633 "-1.0f and 1.0f", qUtf8Printable(QLatin1String(__FUNCTION__)));
634 return;
635 }
636
637 d->m_titleOffset = offset;
638 emit titleOffsetChanged(offset);
639}
640
641float QAbstract3DAxis::titleOffset() const
642{
643 Q_D(const QAbstract3DAxis);
644 return d->m_titleOffset;
645}
646
647/*!
648 * \fn QAbstract3DAxis::rangeChanged(float min, float max)
649 *
650 * Emits the minimum and maximum values of the range, \a min and \a max, when
651 * the range changes.
652 */
653
654// QAbstract3DAxisPrivate
655QAbstract3DAxisPrivate::QAbstract3DAxisPrivate(QAbstract3DAxis::AxisType type)
656 : m_orientation(QAbstract3DAxis::AxisOrientation::None)
657 , m_type(type)
658 , m_isDefaultAxis(false)
659 , m_min(0.0f)
660 , m_max(10.0f)
661 , m_autoAdjust(true)
662 , m_scaleLabelsByCount(false)
663 , m_labelSize(1.0)
664 , m_labelAutoAngle(0.0f)
665 , m_titleOffset(0.0f)
666 , m_titleVisible(false)
667 , m_labelsVisible(true)
668 , m_titleFixed(true)
669
670{}
671
672QAbstract3DAxisPrivate::~QAbstract3DAxisPrivate() {}
673
674void QAbstract3DAxisPrivate::setOrientation(QAbstract3DAxis::AxisOrientation orientation)
675{
676 Q_Q(QAbstract3DAxis);
677 if (m_orientation == QAbstract3DAxis::AxisOrientation::None) {
678 m_orientation = orientation;
679 emit q->orientationChanged(orientation);
680 } else {
681 Q_ASSERT("Attempted to reset axis orientation.");
682 }
683}
684
685void QAbstract3DAxisPrivate::updateLabels()
686{
687 // Default implementation does nothing
688}
689
690void QAbstract3DAxisPrivate::setRange(float min, float max, bool suppressWarnings)
691{
692 Q_Q(QAbstract3DAxis);
693 bool adjusted = false;
694 if (!allowNegatives()) {
695 if (allowZero()) {
696 if (min < 0.0f) {
697 min = 0.0f;
698 adjusted = true;
699 }
700 if (max < 0.0f) {
701 max = 0.0f;
702 adjusted = true;
703 }
704 } else {
705 if (min <= 0.0f) {
706 min = 1.0f;
707 adjusted = true;
708 }
709 if (max <= 0.0f) {
710 max = 1.0f;
711 adjusted = true;
712 }
713 }
714 }
715 // If min >= max, we adjust ranges so that
716 // m_max becomes (min + 1.0f)
717 // as axes need some kind of valid range.
718 bool minDirty = false;
719 bool maxDirty = false;
720 if (m_min != min) {
721 m_min = min;
722 minDirty = true;
723 }
724 if (m_max != max || min > max || (!allowMinMaxSame() && min == max)) {
725 if (min > max || (!allowMinMaxSame() && min == max)) {
726 m_max = min + 1.0f;
727 adjusted = true;
728 } else {
729 m_max = max;
730 }
731 maxDirty = true;
732 }
733
734 if (minDirty || maxDirty) {
735 if (adjusted && !suppressWarnings) {
736 qCWarning(lcAProperties3D, "%s tried to set invalid range for axis. Range automatically adjusted "
737 "to a valid one: %f - %f --> %f - %f",
738 qUtf8Printable(QLatin1String(__FUNCTION__)),
739 min,
740 max,
741 m_min,
742 m_max);
743 }
744 emit q->rangeChanged(min: m_min, max: m_max);
745 }
746
747 if (minDirty)
748 emit q->minChanged(value: m_min);
749 if (maxDirty)
750 emit q->maxChanged(value: m_max);
751}
752
753void QAbstract3DAxisPrivate::setMin(float min)
754{
755 Q_Q(QAbstract3DAxis);
756 if (!allowNegatives()) {
757 if (allowZero()) {
758 if (min < 0.0f) {
759 min = 0.0f;
760 qCWarning(lcAProperties3D, "%s tried to set negative minimum for an axis that only"
761 "supports positive values and zero: %f",
762 qUtf8Printable(QLatin1String(__FUNCTION__)),
763 min);
764 }
765 } else {
766 if (min <= 0.0f) {
767 min = 1.0f;
768 qCWarning(lcAProperties3D, "%s tried to set negative or zero minimum for an "
769 "axis that only"
770 "supports positive values: %f",
771 qUtf8Printable(QLatin1String(__FUNCTION__)),
772 min);
773 }
774 }
775 }
776
777 if (m_min != min) {
778 bool maxChanged = false;
779 if (min > m_max || (!allowMinMaxSame() && min == m_max)) {
780 float oldMax = m_max;
781 m_max = min + 1.0f;
782 qCWarning(lcAProperties3D, "%s tried to set minimum to equal or larger than maximum for"
783 " value axis. Maximum automatically adjusted to a valid one: %f --> %f",
784 qUtf8Printable(QLatin1String(__FUNCTION__)),
785 oldMax,
786 m_max);
787 maxChanged = true;
788 }
789 m_min = min;
790
791 emit q->rangeChanged(min: m_min, max: m_max);
792 emit q->minChanged(value: m_min);
793 if (maxChanged)
794 emit q->maxChanged(value: m_max);
795 }
796}
797
798void QAbstract3DAxisPrivate::setMax(float max)
799{
800 Q_Q(QAbstract3DAxis);
801 if (!allowNegatives()) {
802 if (allowZero()) {
803 if (max < 0.0f) {
804 max = 0.0f;
805 qCWarning(lcAProperties3D, "%s tried to set negative maximum for an axis that only"
806 " supports positive values and zero: %f",
807 qUtf8Printable(QLatin1String(__FUNCTION__)),
808 max);
809 }
810 } else {
811 if (max <= 0.0f) {
812 max = 1.0f;
813 qCWarning(lcAProperties3D, "%s tried to set negative or zero maximum for an "
814 "axis that only"
815 " supports positive values: %f",
816 qUtf8Printable(QLatin1String(__FUNCTION__)),
817 max);
818 }
819 }
820 }
821
822 if (m_max != max) {
823 bool minChanged = false;
824 if (m_min > max || (!allowMinMaxSame() && m_min == max)) {
825 float oldMin = m_min;
826 m_min = max - 1.0f;
827 if (!allowNegatives() && m_min < 0.0f) {
828 if (allowZero())
829 m_min = 0.0f;
830 else
831 m_min = max / 2.0f; // Need some positive value smaller than max
832
833 if (!allowMinMaxSame() && max == 0.0f) {
834 m_min = oldMin;
835 qCWarning(lcAProperties3D, "%s unable to set maximum value to zero.",
836 qUtf8Printable(QLatin1String(__FUNCTION__)));
837 return;
838 }
839 }
840 qCWarning(lcAProperties3D, "%s tried to set maximum to equal or smaller than minimum "
841 "for value axis. Minimum automatically adjusted to a valid one: %f --> %f",
842 qUtf8Printable(QLatin1String(__FUNCTION__)),
843 oldMin,
844 m_min);
845 minChanged = true;
846 }
847 m_max = max;
848 emit q->rangeChanged(min: m_min, max: m_max);
849 emit q->maxChanged(value: m_max);
850 if (minChanged)
851 emit q->minChanged(value: m_min);
852 }
853}
854
855QT_END_NAMESPACE
856

source code of qtgraphs/src/graphs3d/axis/qabstract3daxis.cpp