1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "qgraphstheme.h"
5#include "utils_p.h"
6
7#include <QGuiApplication>
8#include <QLinearGradient>
9#include <QQmlListProperty>
10#include <QStyleHints>
11#include <QtQuick/private/qquickrectangle_p.h>
12#include <private/qgraphsglobal_p.h>
13#include <private/qgraphstheme_p.h>
14#include <private/qquickgraphscolor_p.h>
15#include <private/qquickrectangle_p.h>
16
17QT_BEGIN_NAMESPACE
18
19/*!
20 * \class QGraphsTheme
21 * \inmodule QtGraphs
22 * \ingroup graphs_common
23 * \brief QGraphsTheme class provides a visual style for graphs.
24 *
25 * Specifies visual properties that affect the whole graph. There are several
26 * built-in themes that can be used as is or modified freely.
27 *
28 * Themes can be created from scratch using the UserDefined enum value.
29 * Creating a theme using the default constructor produces a new user-defined
30 * theme.
31 *
32 * \section1 Customizing Theme
33 *
34 * The default theme is QtGreen, but it is possible to customize each property.
35 *
36 * The following table lists the properties controlled by a theme and the
37 * default values for UserDefined.
38 *
39 * \table
40 * \header
41 * \li Property
42 * \li Default Value
43 * \row
44 * \li backgroundVisible
45 * \li \c true
46 * \row
47 * \li seriesColors
48 * \li Qt::black
49 * \row
50 * \li seriesGradients
51 * \li QLinearGradient. Essentially fully black.
52 * \row
53 * \li colorStyle
54 * \li Uniform
55 * \row
56 * \li \l labelFont
57 * \li QFont
58 * \row
59 * \li gridVisible
60 * \li \c true
61 * \row
62 * \li labelBackgroundVisible
63 * \li \c true
64 * \row
65 * \li labelBorderVisible
66 * \li \c true
67 * \row
68 * \li labelsVisible
69 * \li \c true
70 * \endtable
71 *
72 * \section1 Usage Examples
73 *
74 * Creating a built-in theme without any modifications:
75 *
76 * \snippet doc_src_qgraphstheme.cpp 0
77 *
78 * Creating a built-in theme and modifying some properties:
79 *
80 * \snippet doc_src_qgraphstheme.cpp 1
81 *
82 * Modifying a user-defined theme. The theme has been created the same way it was in the previous
83 * snippets:
84 *
85 * \snippet doc_src_qgraphstheme.cpp 2
86 *
87 * Modifying some properties after theme has been set to a graph:
88 *
89 * \snippet doc_src_qgraphstheme.cpp 3
90 *
91 */
92
93/*!
94 * \enum QGraphsTheme::ColorStyle
95 *
96 * Gradient types.
97 *
98 * \value Uniform
99 * Objects are rendered in a single color. The color used is specified in seriesColors,
100 * singleHighlightColor and multiHighlightColor properties.
101 * \value ObjectGradient
102 * Objects are colored using a full gradient for each object regardless of object height. The
103 * gradient used is specified in seriesGradients, singleHighlightGradient and
104 * multiHighlightGradient properties.
105 * \value RangeGradient
106 * Objects are colored using a portion of the full gradient determined by the object's
107 * height and its position on the Y-axis. The gradient used is specified in seriesGradients,
108 * singleHighlightGradient and multiHighlightGradient properties.
109 */
110
111/*!
112 * \enum QGraphsTheme::Theme
113 *
114 * Built-in themes.
115 *
116 * \value QtGreen
117 * A light theme with green as the base color.
118 * \value QtGreenNeon
119 * A light theme with green neon as the base color.
120 * \value MixSeries
121 * A mixed theme with various colors.
122 * \value OrangeSeries
123 * A theme with Orange as the base color.
124 * \value YellowSeries
125 * A theme with Yellow as the base color.
126 * \value BlueSeries
127 * A theme with Blue as the base color.
128 * \value PurpleSeries
129 * A theme with Purple as the base color.
130 * \value GreySeries
131 * A theme with Grey as the base color.
132 * \value UserDefined
133 * A user-defined theme. For more information, see
134 * \l {QGraphsTheme#Customizing Theme}{Customizing Theme}.
135 */
136
137/*!
138 * \enum QGraphsTheme::ColorScheme
139 *
140 * Represents the color scheme of the graph.
141 *
142 * \value Automatic
143 * The background colors follow the platform color scheme if available.
144 * If unavailable, the Light appearance is used.
145 * \value Light
146 * The background colors are lighter than the text color, i.e. the theme is light.
147 * \value Dark
148 * The background colors are darker than the text color, i.e. the theme is dark.
149 * \sa Qt::ColorScheme
150 */
151
152/*!
153 * \qmlvaluetype graphsline
154 * \ingroup graphs_qml_common
155 * \brief a values for lines based on properties of QGraphsLine.
156 *
157 * The \c graphsline type refers to a line value with the properties of QGraphsLine.
158 *
159 * Properties of type \c graphsline follows the \l {GraphsTheme::}{theme} unless
160 * defined separately.
161 *
162 * When integrating with C++, note that any QGraphsLine value
163 * \l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
164 * converted into a \c graphsline value, and vice-versa.
165 *
166 * This value type is provided by the QtQuick import.
167 *
168 * \sa {QML Value Types}
169 */
170
171/*!
172 \qmlproperty color graphsline::mainColor
173 The color of the main lines.
174*/
175
176/*!
177 \qmlproperty color graphsline::subColor
178 The color of the sub lines.
179*/
180
181/*!
182 \qmlproperty real graphsline::mainWidth
183 The width of the main lines.
184*/
185/*!
186 \qmlproperty real graphsline::subWidth
187 The width of the sub lines.
188*/
189
190/*!
191 \qmlproperty color graphsline::labelTextColor
192 The color of the text used for labels.
193*/
194
195/*!
196 * \qmltype GraphsTheme
197 * \inqmlmodule QtGraphs
198 * \ingroup graphs_qml_common
199 * \nativetype QGraphsTheme
200 * \brief A visual style for graphs.
201 *
202 * This type is used to specify visual properties that affect the whole graph.
203 * There are several built-in themes that can be used as is or modified freely.
204 *
205 *
206 * Themes can be created from scratch by using the
207 * \l{QGraphsTheme::Theme::UserDefined}{GraphsTheme.Theme.UserDefined} enum value.
208 *
209 * \section1 Customizing Theme
210 *
211 * The default theme is QtGreen, but it is possible to customize each property.
212 *
213 * The following table lists the properties controlled by a theme and the
214 * default values for \l{QGraphsTheme::Theme::UserDefined}
215 * {QGraphsTheme.Theme.UserDefined}.
216 *
217 * \table
218 * \header
219 * \li Property
220 * \li Default Value
221 * \row
222 * \li backgroundVisible
223 * \li \c true
224 * \row
225 * \li seriesColors
226 * \li Qt::black
227 * \row
228 * \li baseGradients
229 * \li QLinearGradient. Essentially fully black.
230 * \row
231 * \li colorStyle
232 * \li Uniform
233 * \row
234 * \li \l labelFont
235 * \li QFont
236 * \row
237 * \li gridVisible
238 * \li \c true
239 * \row
240 * \li labelBackgroundVisible
241 * \li \c true
242 * \row
243 * \li labelBorderVisible
244 * \li \c true
245 * \row
246 * \li labelsVisible
247 * \li \c true
248 * \endtable
249 *
250 * \section1 Usage examples
251 *
252 * Using a built-in theme without any modifications:
253 *
254 * \snippet doc_src_qmlgraphstheme.qml scatter
255 * \dots
256 *
257 * Using a built-in theme and modifying some properties:
258 *
259 * \snippet doc_src_qmlgraphstheme.qml bars
260 * \dots
261 *
262 * Using a user-defined theme:
263 *
264 * \snippet doc_src_qmlgraphstheme.qml surface
265 * \dots
266 *
267 * For GraphsTheme enums, see \l GraphsTheme::colorStyle and \l{GraphsTheme::theme}.
268 */
269
270/*!
271 \qmlproperty list<color> GraphsTheme::seriesColors
272
273 The list of colors to be used for all the objects in the graph, series
274 by series. If there are more series than colors, color list wraps and starts
275 again with the first color in the list. Has no immediate effect if \l colorStyle
276 is not \c GraphsTheme.ColorStyle.Uniform.
277
278 Example usage:
279 \badcode
280 seriesColors: [ "red" ]
281 \endcode
282
283 This can be overridden by setting \l{Abstract3DSeries::baseColor}
284 {Abstract3DSeries.baseColor} explicitly in the series.
285 */
286
287/*!
288 \qmlproperty list<Color> GraphsTheme::baseColors
289
290 The list of base colors of type Color to be used for all the objects in the graph, series
291 by series. If there are more series than colors, color list wraps and starts
292 again with the first color in the list. Has no immediate effect if \l colorStyle
293 is not \c GraphsTheme.ColorStyle.Uniform.
294
295 Example usage:
296 \badcode
297 baseColors: [ Color { color: "red" } ]
298 \endcode
299
300 This can be overridden by setting \l{Abstract3DSeries::baseColor}
301 {Abstract3DSeries.baseColor} explicitly in the series.
302 */
303
304/*!
305 * \qmlproperty list<color> GraphsTheme::borderColors
306 *
307 * The list of border colors to be used for all the objects in the graph,
308 * series by series.
309 *
310 * If there are more series than colors, the color list wraps and starts again
311 * with the first color in the list.
312 *
313 * Has no immediate effect if colorStyle is not Uniform.
314 */
315
316/*!
317 * \qmlproperty color GraphsTheme::plotAreaBackgroundColor
318 *
319 * The color of the graph plot area background.
320 * The default value depends on \l colorScheme.
321 */
322
323/*!
324 * \qmlproperty color GraphsTheme::backgroundColor
325 *
326 * The color of the view the graph is drawn into.
327 * The default value depends on \l colorScheme.
328 */
329
330/*!
331 * \qmlproperty color GraphsTheme::labelTextColor
332 *
333 * The color of the font used for labels.
334 * The default value depends on \l colorScheme.
335 */
336
337/*!
338 * \qmlproperty color GraphsTheme::labelBackgroundColor
339 *
340 * The color of the label backgrounds. Has no effect if labelBackgroundVisible
341 * is \c false.
342 * The default value depends on \l colorScheme.
343 */
344
345/*!
346 * \qmlproperty color GraphsTheme::singleHighlightColor
347 *
348 * The highlight color for a selected object. Used if
349 * \l{GraphsItem3D::selectionMode}{selectionMode}
350 * has the \c Graphs3D.SelectionFlag.Item flag set.
351 * The default value depends on \l colorScheme.
352 *
353 * \sa Graphs3D.SelectionFlag
354 */
355
356/*!
357 * \qmlproperty color GraphsTheme::multiHighlightColor
358 *
359 * The highlight color for selected objects. Used if
360 * \l{GraphsItem3D::selectionMode}{selectionMode}
361 * has the \c Graphs3D.SelectionFlag.Row or \c Graphs3D.SelectionFlag.Column
362 * flag set.
363 * The default value depends on \l colorScheme.
364 *
365 * \sa Graphs3D.SelectionFlag
366 */
367
368/*!
369 \qmlproperty list<Gradient> GraphsTheme::baseGradients
370
371 The list of base gradients to be used for all the objects in the graph,
372 series by series. If there are more series than gradients, the gradient list
373 wraps and starts again with the first gradient in the list.
374
375 Has no immediate effect if colorStyle is \l{QGraphsTheme::ColorStyle::Uniform}
376 {GraphsTheme.ColorStyle.Uniform}.
377
378 Example usage:
379 \badcode
380 baseGradients: [ Gradient {
381 GradientStop { position: 1.0; color: "#DBEB00" }
382 GradientStop { position: 0.0; color: "#373F26" }
383 } ]
384 \endcode
385
386 This value can be overridden by setting \l{Abstract3DSeries::baseGradient}
387 {Abstract3DSeries.baseGradient} explicitly in the series.
388 */
389
390/*!
391 * \qmlproperty Gradient GraphsTheme::singleHighlightGradient
392 *
393 * The highlight gradient for a selected object. Used if
394 * \l{GraphsItem3D::selectionMode}{selectionMode}
395 * has the \c Graphs3D.SelectionFlag.Item flag set.
396 * The default value depends on \l colorScheme.
397 *
398 * \sa Graphs3D.SelectionFlag
399 */
400
401/*!
402 * \qmlproperty Gradient GraphsTheme::multiHighlightGradient
403 *
404 * The highlight gradient for selected objects. Used if
405 * \l{GraphsItem3D::selectionMode}{selectionMode}
406 * has the \c Graphs3D.SelectionFlag.Row or \c Graphs3D.SelectionFlag.Column
407 * flag set.
408 * The default value depends on \l colorScheme.
409 *
410 * \sa Graphs3D.SelectionFlag
411 */
412
413/*!
414 * \qmlproperty bool GraphsTheme::labelBorderVisible
415 *
416 * Defines whether label borders are drawn for labels that have a background.
417 * Has no effect if labelBackgroundVisible is \c false.
418 * The default value is \c true.
419 */
420
421/*!
422 * \qmlproperty font GraphsTheme::labelFont
423 *
424 * Sets the font to be used for labels.
425 */
426
427/*!
428 * \qmlproperty font GraphsTheme::axisXLabelFont
429 *
430 * Sets the font to be used for labels on axisX.
431 */
432
433/*!
434 * \qmlproperty font GraphsTheme::axisYLabelFont
435 *
436 * Sets the font to be used for labels on axisY.
437 */
438
439/*!
440 * \qmlproperty font GraphsTheme::axisZLabelFont
441 *
442 * Sets the font to be used for labels on axisZ.
443 */
444
445/*!
446 * \qmlproperty bool GraphsTheme::backgroundVisible
447 *
448 * Defines whether the view background is drawn by using the value of
449 * backgroundColor.
450 * The default value is \c true.
451 */
452
453/*!
454 * \qmlproperty bool GraphsTheme::plotAreaBackgroundVisible
455 *
456 * Defines whether the plot area background is drawn by using the value of
457 * plotAreaBackgroundColor.
458 * The default value is \c true.
459 */
460
461/*!
462 * \qmlproperty bool GraphsTheme::gridVisible
463 *
464 * Defines whether the grid lines are drawn. This value affects all grid lines.
465 * The default value is \c true.
466 */
467
468/*!
469 * \qmlproperty bool GraphsTheme::labelBackgroundVisible
470 *
471 * Defines whether the label is drawn with a background that uses
472 * labelBackgroundColor (including alpha), or with a fully transparent
473 * background. Labels with a background are drawn to equal sizes per axis based
474 * on the longest label, and the text is centered in them. Labels without
475 * a background are drawn as is and are left or right aligned based on their
476 * position in the graph.
477 * The default value is \c true.
478 */
479
480/*!
481 * \qmlproperty GraphsTheme.ColorStyle GraphsTheme::colorStyle
482 *
483 * The style of the graph colors. One of QGraphsTheme::ColorStyle enum values.
484 *
485 * This value can be overridden by setting \l{Abstract3DSeries::colorStyle}
486 * {Abstract3DSeries.colorStyle} explicitly in the series.
487 * \note This property does not have an effect in Qt Graphs for 2D.
488 *
489 * \sa QGraphsTheme::ColorStyle
490 */
491
492/*!
493 * \qmlproperty QGraphsTheme::ColorScheme GraphsTheme::colorScheme
494 *
495 * The color scheme of the graph in use.
496 *
497 * \sa QGraphsTheme::ColorScheme
498 */
499
500/*!
501 * \qmlproperty bool GraphsTheme::labelsVisible
502 *
503 * Defines whether labels are drawn at all. If this is \c{false}, all other
504 * label properties have no effect.
505 * The default value is \c true.
506 */
507
508/*!
509 * \qmlproperty GraphsTheme.Theme GraphsTheme::theme
510 *
511 * The type of the theme. If no type is set, the type is
512 * \l{QGraphsTheme::Theme::QtGreen}{GraphsTheme.Theme.QtGreen}.
513 * Changing the theme type after the item has been constructed will change all
514 * other properties of the theme to what the predefined theme specifies.
515 * Changing the theme type of the active theme of the graph will also reset all
516 * attached series to use the new theme.
517 */
518
519/*!
520 * \qmlproperty GraphsLine GraphsTheme::grid
521 *
522 * Holds the \l{graphsline}{GraphsLine} of the theme.
523 * \sa GraphsLine.mainColor GraphsLine.subColor GraphsLine.mainWidth GraphsLine.subWidth
524 * \sa GraphsLine.labelTextColor
525 */
526
527/*!
528 * \qmlproperty GraphsLine GraphsTheme::axisX
529 *
530 * Holds the \l{graphsline}{GraphsLine} of the X axis.
531 * \sa GraphsLine.mainColor GraphsLine.subColor GraphsLine.mainWidth GraphsLine.subWidth
532 * \sa GraphsLine.labelTextColor
533 */
534
535/*!
536 * \qmlproperty GraphsLine GraphsTheme::axisY
537 *
538 * Holds the \l{graphsline}{GraphsLine} of the Y axis.
539 * \sa GraphsLine.mainColor GraphsLine.subColor GraphsLine.mainWidth GraphsLine.subWidth
540 * \sa GraphsLine.labelTextColor
541 */
542
543/*!
544 * \qmlproperty GraphsLine GraphsTheme::axisZ
545 *
546 * Holds the \l{graphsline}{GraphsLine} of the Z axis.
547 * \sa GraphsLine.mainColor GraphsLine.subColor GraphsLine.mainWidth GraphsLine.subWidth
548 * \sa GraphsLine.labelTextColor
549 */
550
551/*!
552 * \qmlproperty color GraphsTheme::GraphsLine.mainColor
553 *
554 * The color of the main lines.
555 * The default value depends on \l colorScheme.
556 */
557
558/*!
559 * \qmlproperty color GraphsTheme::GraphsLine.subColor
560 *
561 * The color of the sub lines.
562 * The default value depends on \l colorScheme.
563 */
564
565/*!
566 * \qmlproperty real GraphsTheme::GraphsLine.mainWidth
567 *
568 * The width of the main lines.
569 * The default value is \c 2.0.
570 *
571 * If it is set for grid lines, only has effect if
572 * \l{GraphsItem3D::gridLineType} is \c Graphs3D.GridLineType.Shader
573 *
574 * \sa Graphs3D.GridLineType
575 */
576
577/*!
578 * \qmlproperty real GraphsTheme::GraphsLine.subWidth
579 *
580 * The width of the sub lines.
581 * The default value is \c 1.0.
582 *
583 * If it is set for grid lines, only has effect if
584 * \l{GraphsItem3D::gridLineType} is \c Graphs3D.GridLineType.Shader
585 *
586 * \sa Graphs3D.GridLineType
587 */
588
589/*!
590 * \qmlproperty color GraphsTheme::GraphsLine.labelTextColor
591 *
592 * The color of the text used for labels.
593 * The default value depends on \l colorScheme.
594 */
595
596/*!
597 \fn QGraphsLine::QGraphsLine(QGraphsLine &&other)
598
599 Move-constructs a new QGraphsLine from \a other.
600
601 \note The moved-from object \a other is placed in a
602 partially-formed state, in which the only valid operations are
603 destruction and assignment of a new value.
604*/
605
606/*!
607 \fn QGraphsLine &QGraphsLine::operator=(QGraphsLine &&other)
608
609 Move-assigns \a other to this QGraphsLine instance.
610
611 \note The moved-from object \a other is placed in a
612 partially-formed state, in which the only valid operations are
613 destruction and assignment of a new value.
614*/
615
616/*! \fn void QGraphsLine::swap(QGraphsLine &other)
617
618 Swaps QGraphsLine \a other with this QGraphsLine. This operation is very fast and
619 never fails.
620*/
621
622bool comparesEqual(const QGraphsLine &lhs, const QGraphsLine &rhs) noexcept
623{
624 return comparesEqual(lhs: *lhs.d, rhs: *rhs.d);
625}
626
627QGraphsTheme::QGraphsTheme(QObject *parent)
628 : QGraphsTheme(*(new QGraphsThemePrivate()), parent)
629{}
630
631QGraphsTheme::QGraphsTheme(QGraphsThemePrivate &dd, QObject *parent)
632 : QObject(dd, parent)
633{
634 setBackgroundVisible(true);
635 setPlotAreaBackgroundVisible(true);
636 setLabelBackgroundVisible(true);
637 setGridVisible(true);
638 setLabelsVisible(true);
639 setColorScheme(QGraphsTheme::ColorScheme::Automatic);
640 setLabelBorderVisible(true);
641 setTheme(newTheme: Theme::QtGreen, force: ForceTheme::Yes);
642 setLabelFont(QFont(QLatin1String("Arial")));
643 setAxisXLabelFont(QFont());
644 setAxisYLabelFont(QFont());
645 setAxisZLabelFont(QFont());
646}
647
648QGraphsTheme::~QGraphsTheme()
649{
650}
651
652bool QGraphsTheme::themeDirty() const
653{
654 Q_D(const QGraphsTheme);
655 return d->m_themeDirty;
656}
657
658void QGraphsTheme::resetThemeDirty()
659{
660 Q_D(QGraphsTheme);
661 d->m_themeDirty = false;
662}
663
664void QGraphsTheme::resetColorTheme()
665{
666 setTheme(newTheme: QGraphsTheme::Theme::QtGreen);
667}
668
669QGraphsThemeDirtyBitField *QGraphsTheme::dirtyBits()
670{
671 Q_D(QGraphsTheme);
672 return &d->m_dirtyBits;
673}
674
675void QGraphsTheme::resetDirtyBits()
676{
677 Q_D(QGraphsTheme);
678 d->m_dirtyBits.plotAreaBackgroundColorDirty = true;
679 d->m_dirtyBits.plotAreaBackgroundVisibilityDirty = true;
680 d->m_dirtyBits.seriesColorsDirty = true;
681 d->m_dirtyBits.seriesGradientDirty = true;
682 d->m_dirtyBits.colorSchemeDirty = true;
683 d->m_dirtyBits.colorStyleDirty = true;
684 d->m_dirtyBits.labelFontDirty = true;
685 d->m_dirtyBits.gridVisibilityDirty = true;
686 d->m_dirtyBits.gridDirty = true;
687 d->m_dirtyBits.labelBackgroundColorDirty = true;
688 d->m_dirtyBits.labelBackgroundVisibilityDirty = true;
689 d->m_dirtyBits.labelBorderVisibilityDirty = true;
690 d->m_dirtyBits.labelTextColorDirty = true;
691 d->m_dirtyBits.axisXDirty = true;
692 d->m_dirtyBits.axisYDirty = true;
693 d->m_dirtyBits.axisZDirty = true;
694 d->m_dirtyBits.labelsVisibilityDirty = true;
695 d->m_dirtyBits.multiHighlightColorDirty = true;
696 d->m_dirtyBits.multiHighlightGradientDirty = true;
697 d->m_dirtyBits.singleHighlightColorDirty = true;
698 d->m_dirtyBits.singleHighlightGradientDirty = true;
699 d->m_dirtyBits.themeDirty = true;
700 d->m_dirtyBits.backgroundColorDirty = true;
701 d->m_dirtyBits.backgroundVisibilityDirty = true;
702}
703
704/*!
705 * \property QGraphsTheme::colorScheme
706 *
707 * The color scheme of the graph in use.
708 *
709 * \sa Qt::ColorScheme
710 */
711QGraphsTheme::ColorScheme QGraphsTheme::colorScheme() const
712{
713 Q_D(const QGraphsTheme);
714 return d->m_colorScheme;
715}
716
717void QGraphsTheme::setColorScheme(QGraphsTheme::ColorScheme newColorScheme)
718{
719 Q_D(QGraphsTheme);
720 d->m_dirtyBits.colorSchemeDirty = true;
721 d->m_colorScheme = newColorScheme;
722 setColorSchemePalette();
723 d->m_themeDirty = true;
724 Q_EMIT colorSchemeChanged();
725 Q_EMIT update();
726
727 if (d->m_colorScheme == QGraphsTheme::ColorScheme::Automatic) {
728 if (!d->m_autoColorConnection) {
729 d->m_autoColorConnection = QObject::connect(sender: QGuiApplication::styleHints(),
730 signal: &QStyleHints::colorSchemeChanged,
731 context: this,
732 slot: [this]() {
733 this->updateAutomaticColorScheme();
734 });
735 }
736 } else {
737 QObject::disconnect(d->m_autoColorConnection);
738 }
739}
740
741/*!
742 * \property QGraphsTheme::theme
743 *
744 * The type of the theme. If no type is set, the type is
745 * \l{QGraphsTheme::Theme::QtGreen}{GraphsTheme.Theme.QtGreen}.
746 * Changing the theme type after the item has been constructed will change all
747 * other properties of the theme to what the predefined theme specifies.
748 * Changing the theme type of the active theme of the graph will also reset all
749 * attached series to use the new theme.
750 */
751QGraphsTheme::Theme QGraphsTheme::theme() const
752{
753 Q_D(const QGraphsTheme);
754 return d->m_theme;
755}
756
757void QGraphsTheme::setTheme(Theme newTheme, ForceTheme force)
758{
759 Q_D(QGraphsTheme);
760 if (force == ForceTheme::No && d->m_theme == newTheme)
761 return;
762 d->m_dirtyBits.themeDirty = true;
763 d->m_theme = newTheme;
764 d->m_themeDirty = true;
765 setThemePalette();
766 Q_EMIT themeChanged(theme: d->m_theme);
767 Q_EMIT update();
768}
769
770/*!
771 * \property QGraphsTheme::colorStyle
772 *
773 * The style of the graph colors. One of QGraphsTheme::ColorStyle enum values.
774 *
775 * This value can be overridden by setting \l{Abstract3DSeries::colorStyle}
776 * {Abstract3DSeries.colorStyle} explicitly in the series.
777 * \note This property does not have an effect in Qt Graphs for 2D.
778 *
779 * \sa QGraphsTheme::ColorStyle
780 */
781QGraphsTheme::ColorStyle QGraphsTheme::colorStyle() const
782{
783 Q_D(const QGraphsTheme);
784 return d->m_colorStyle;
785}
786
787void QGraphsTheme::setColorStyle(ColorStyle newColorStyle)
788{
789 Q_D(QGraphsTheme);
790 if (d->m_colorStyle == newColorStyle)
791 return;
792 d->m_dirtyBits.colorStyleDirty = true;
793 d->m_colorStyle = newColorStyle;
794 Q_EMIT colorStyleChanged(type: newColorStyle);
795 Q_EMIT update();
796}
797
798/*!
799 * \property QGraphsTheme::axisXLabelFont
800 *
801 * \brief The font to be used for labels on x axis.
802 */
803QFont QGraphsTheme::axisXLabelFont() const
804{
805 Q_D(const QGraphsTheme);
806 return d->m_axisXLabelFont;
807}
808
809void QGraphsTheme::setAxisXLabelFont(const QFont &newAxisXLabelFont)
810{
811 Q_D(QGraphsTheme);
812 d->m_customBits.axisXLabelFontCustom = true;
813 if (d->m_axisXLabelFont == newAxisXLabelFont)
814 return;
815 d->m_axisXLabelFont = newAxisXLabelFont;
816 Q_EMIT axisXLabelFontChanged();
817 Q_EMIT update();
818}
819
820/*!
821 * \property QGraphsTheme::axisYLabelFont
822 *
823 * \brief The font to be used for labels on y axis.
824 */
825QFont QGraphsTheme::axisYLabelFont() const
826{
827 Q_D(const QGraphsTheme);
828 return d->m_axisYLabelFont;
829}
830
831void QGraphsTheme::setAxisYLabelFont(const QFont &newAxisYLabelFont)
832{
833 Q_D(QGraphsTheme);
834 d->m_customBits.axisYLabelFontCustom = true;
835 if (d->m_axisYLabelFont == newAxisYLabelFont)
836 return;
837 d->m_axisYLabelFont = newAxisYLabelFont;
838 Q_EMIT axisYLabelFontChanged();
839 Q_EMIT update();
840}
841
842/*!
843 * \property QGraphsTheme::axisZLabelFont
844 *
845 * \brief The font to be used for labels on z axis.
846 */
847QFont QGraphsTheme::axisZLabelFont() const
848{
849 Q_D(const QGraphsTheme);
850 return d->m_axisZLabelFont;
851}
852
853void QGraphsTheme::setAxisZLabelFont(const QFont &newAxisZLabelFont)
854{
855 Q_D(QGraphsTheme);
856 d->m_customBits.axisZLabelFontCustom = true;
857 if (d->m_axisZLabelFont == newAxisZLabelFont)
858 return;
859 d->m_axisZLabelFont = newAxisZLabelFont;
860 Q_EMIT axisZLabelFontChanged();
861 Q_EMIT update();
862}
863
864/*!
865 * \property QGraphsTheme::plotAreaBackgroundColor
866 *
867 * \brief The color of the graph plot area background.
868 * The default value depends on \l colorScheme.
869 */
870QColor QGraphsTheme::plotAreaBackgroundColor() const
871{
872 Q_D(const QGraphsTheme);
873 if (d->m_customBits.plotAreaBackgroundColorCustom)
874 return d->m_plotAreaBackgroundColor;
875 return d->m_plotAreaBackgroundThemeColor;
876}
877
878void QGraphsTheme::setPlotAreaBackgroundColor(QColor newBackgroundColor)
879{
880 Q_D(QGraphsTheme);
881 d->m_customBits.plotAreaBackgroundColorCustom = true;
882 if (d->m_plotAreaBackgroundColor == newBackgroundColor)
883 return;
884 d->m_dirtyBits.plotAreaBackgroundColorDirty = true;
885 d->m_plotAreaBackgroundColor = newBackgroundColor;
886 Q_EMIT plotAreaBackgroundColorChanged();
887 Q_EMIT update();
888}
889
890/*!
891 * \property QGraphsTheme::plotAreaBackgroundVisible
892 *
893 * \brief Whether the plot area background is visible.
894 *
895 * The background is drawn by using the value of plotAreaBackgroundColor.
896 * The default value is \c true.
897 */
898bool QGraphsTheme::isPlotAreaBackgroundVisible() const
899{
900 Q_D(const QGraphsTheme);
901 return d->m_plotAreaBackgroundVisibility;
902}
903
904void QGraphsTheme::setPlotAreaBackgroundVisible(bool newBackgroundVisibility)
905{
906 Q_D(QGraphsTheme);
907 if (d->m_plotAreaBackgroundVisibility == newBackgroundVisibility)
908 return;
909 d->m_dirtyBits.plotAreaBackgroundVisibilityDirty = true;
910 d->m_plotAreaBackgroundVisibility = newBackgroundVisibility;
911 Q_EMIT plotAreaBackgroundVisibleChanged();
912 Q_EMIT update();
913}
914
915/*!
916 * \property QGraphsTheme::backgroundVisible
917 *
918 * \brief Whether the background is visible.
919 *
920 * The background is drawn by using the value of backgroundColor.
921 * The default value is \c true.
922 */
923bool QGraphsTheme::isBackgroundVisible() const
924{
925 Q_D(const QGraphsTheme);
926 return d->m_backgroundVisibility;
927}
928
929void QGraphsTheme::setBackgroundVisible(bool newBackgroundVisible)
930{
931 Q_D(QGraphsTheme);
932 if (d->m_backgroundVisibility == newBackgroundVisible)
933 return;
934 d->m_dirtyBits.backgroundVisibilityDirty = true;
935 d->m_backgroundVisibility = newBackgroundVisible;
936 Q_EMIT backgroundVisibleChanged();
937 Q_EMIT update();
938}
939
940/*!
941 * \property QGraphsTheme::gridVisible
942 *
943 * \brief Whether the grid lines are drawn.
944 *
945 * This value affects all grid lines.
946 * The default value is \c true.
947 */
948bool QGraphsTheme::isGridVisible() const
949{
950 Q_D(const QGraphsTheme);
951 return d->m_gridVisibility;
952}
953
954void QGraphsTheme::setGridVisible(bool newGridVisibility)
955{
956 Q_D(QGraphsTheme);
957 if (d->m_gridVisibility == newGridVisibility)
958 return;
959 d->m_dirtyBits.gridVisibilityDirty = true;
960 d->m_gridVisibility = newGridVisibility;
961 Q_EMIT gridVisibleChanged();
962 Q_EMIT update();
963}
964
965/*!
966 * \property QGraphsTheme::backgroundColor
967 *
968 * \brief The color of the view the graph is drawn into.
969 * The default value depends on \l colorScheme.
970 */
971QColor QGraphsTheme::backgroundColor() const
972{
973 Q_D(const QGraphsTheme);
974 if (d->m_customBits.backgroundColorCustom)
975 return d->m_backgroundColor;
976 return d->m_backgroundThemeColor;
977}
978
979void QGraphsTheme::setBackgroundColor(QColor newBackgroundColor)
980{
981 Q_D(QGraphsTheme);
982 d->m_customBits.backgroundColorCustom = true;
983 if (d->m_backgroundColor == newBackgroundColor)
984 return;
985 d->m_dirtyBits.backgroundColorDirty = true;
986 d->m_backgroundColor = newBackgroundColor;
987 Q_EMIT backgroundColorChanged();
988 Q_EMIT update();
989}
990
991/*!
992 * \property QGraphsTheme::labelsVisible
993 *
994 * \brief Whether labels are drawn at all.
995 *
996 * If this is \c{false}, all other label properties have no effect.
997 * The default value is \c true.
998 */
999bool QGraphsTheme::labelsVisible() const
1000{
1001 Q_D(const QGraphsTheme);
1002 return d->m_labelsVisibility;
1003}
1004
1005void QGraphsTheme::setLabelsVisible(bool newLabelsVisibility)
1006{
1007 Q_D(QGraphsTheme);
1008 if (d->m_labelsVisibility == newLabelsVisibility)
1009 return;
1010 d->m_dirtyBits.labelsVisibilityDirty = true;
1011 d->m_labelsVisibility = newLabelsVisibility;
1012 Q_EMIT labelsVisibleChanged();
1013 Q_EMIT update();
1014}
1015
1016/*!
1017 * \property QGraphsTheme::labelBackgroundColor
1018 *
1019 * \brief The color of the label backgrounds.
1020 *
1021 * Has no effect if labelBackgroundVisible is \c false.
1022 * The default value depends on \l colorScheme.
1023 */
1024QColor QGraphsTheme::labelBackgroundColor() const
1025{
1026 Q_D(const QGraphsTheme);
1027 if (d->m_customBits.labelBackgroundColorCustom)
1028 return d->m_labelBackgroundColor;
1029 return d->m_labelBackgroundThemeColor;
1030}
1031
1032void QGraphsTheme::setLabelBackgroundColor(QColor newLabelBackgroundColor)
1033{
1034 Q_D(QGraphsTheme);
1035 d->m_customBits.labelBackgroundColorCustom = true;
1036 if (d->m_labelBackgroundColor == newLabelBackgroundColor)
1037 return;
1038 d->m_dirtyBits.labelBackgroundColorDirty = true;
1039 d->m_labelBackgroundColor = newLabelBackgroundColor;
1040 Q_EMIT labelBackgroundColorChanged();
1041 Q_EMIT update();
1042}
1043
1044/*!
1045 * \property QGraphsTheme::labelTextColor
1046 *
1047 * \brief The color of the font used for labels.
1048 * The default value depends on \l colorScheme.
1049 */
1050QColor QGraphsTheme::labelTextColor() const
1051{
1052 Q_D(const QGraphsTheme);
1053 if (d->m_customBits.labelTextColorCustom)
1054 return d->m_labelTextColor;
1055 return d->m_labelTextThemeColor;
1056}
1057
1058void QGraphsTheme::setLabelTextColor(QColor newLabelTextColor)
1059{
1060 Q_D(QGraphsTheme);
1061 d->m_customBits.labelTextColorCustom = true;
1062 if (d->m_labelTextColor == newLabelTextColor)
1063 return;
1064 d->m_dirtyBits.labelTextColorDirty = true;
1065 d->m_labelTextColor = newLabelTextColor;
1066 Q_EMIT labelTextColorChanged();
1067 Q_EMIT update();
1068}
1069
1070/*!
1071 * \property QGraphsTheme::singleHighlightColor
1072 *
1073 * \brief The highlight color for a selected object.
1074 *
1075 * Used if \l{Q3DGraphsWidgetItem::selectionMode}{selectionMode} has the
1076 * \c QtGraphs3D::SelectionFlag::Item flag set.
1077 * The default value depends on \l colorScheme.
1078 */
1079QColor QGraphsTheme::singleHighlightColor() const
1080{
1081 Q_D(const QGraphsTheme);
1082 if (d->m_customBits.singleHighlightColorCustom)
1083 return d->m_singleHighlightColor;
1084 return d->m_singleHighlightThemeColor;
1085}
1086
1087void QGraphsTheme::setSingleHighlightColor(QColor newSingleHighlightColor)
1088{
1089 Q_D(QGraphsTheme);
1090 d->m_customBits.singleHighlightColorCustom = true;
1091 if (d->m_singleHighlightColor == newSingleHighlightColor)
1092 return;
1093 d->m_dirtyBits.singleHighlightColorDirty = true;
1094 d->m_singleHighlightColor = newSingleHighlightColor;
1095 Q_EMIT singleHighlightColorChanged(color: d->m_singleHighlightColor);
1096 Q_EMIT update();
1097}
1098
1099/*!
1100 * \property QGraphsTheme::multiHighlightColor
1101 *
1102 * \brief The highlight color for selected objects.
1103 *
1104 * Used if \l{Q3DGraphsWidgetItem::selectionMode}{selectionMode} has the
1105 * \c QtGraphs3D::SelectionFlag::Row or \c QtGraphs3D::SelectionFlag::Column
1106 * flag set.
1107 * The default value depends on \l colorScheme.
1108 */
1109QColor QGraphsTheme::multiHighlightColor() const
1110{
1111 Q_D(const QGraphsTheme);
1112 if (d->m_customBits.multiHighlightColorCustom)
1113 return d->m_multiHighlightColor;
1114 return d->m_multiHighlightThemeColor;
1115}
1116
1117void QGraphsTheme::setMultiHighlightColor(QColor newMultiHighlightColor)
1118{
1119 Q_D(QGraphsTheme);
1120 d->m_customBits.multiHighlightColorCustom = true;
1121 if (d->m_multiHighlightColor == newMultiHighlightColor)
1122 return;
1123 d->m_dirtyBits.multiHighlightColorDirty = true;
1124 d->m_multiHighlightColor = newMultiHighlightColor;
1125 Q_EMIT multiHighlightColorChanged(color: d->m_multiHighlightColor);
1126 Q_EMIT update();
1127}
1128
1129/*!
1130 * \property QGraphsTheme::singleHighlightGradient
1131 *
1132 * \brief The highlight gradient for a selected object.
1133 *
1134 * Used if \l{Q3DGraphsWidgetItem::selectionMode}{selectionMode}
1135 * has the \c QtGraphs3D::SelectionFlag::Item flag set.
1136 * The default value depends on \l colorScheme.
1137 */
1138void QGraphsTheme::setSingleHighlightGradient(const QLinearGradient &gradient)
1139{
1140 Q_D(QGraphsTheme);
1141 d->m_customBits.singleHighlightGradientCustom = true;
1142 if (d->m_singleHighlightGradient == gradient)
1143 return;
1144
1145 d->m_dirtyBits.singleHighlightGradientDirty = true;
1146 d->m_singleHighlightGradient = gradient;
1147 Q_EMIT singleHighlightGradientChanged(gradient: d->m_singleHighlightGradient);
1148 Q_EMIT update();
1149}
1150
1151QLinearGradient QGraphsTheme::singleHighlightGradient() const
1152{
1153 Q_D(const QGraphsTheme);
1154 if (d->m_customBits.singleHighlightGradientCustom)
1155 return d->m_singleHighlightGradient;
1156 return d->m_singleHighlightThemeGradient;
1157}
1158
1159/*!
1160 * \property QGraphsTheme::multiHighlightGradient
1161 *
1162 * \brief The highlight gradient for selected objects.
1163 *
1164 * Used if \l{Q3DGraphsWidgetItem::selectionMode}{selectionMode}
1165 * has the \c QtGraphs3D::SelectionFlag::Row or
1166 * \c QtGraphs3D::SelectionFlag::Column flag set.
1167 * The default value depends on \l colorScheme.
1168 */
1169void QGraphsTheme::setMultiHighlightGradient(const QLinearGradient &gradient)
1170{
1171 Q_D(QGraphsTheme);
1172 d->m_customBits.multiHighlightGradientCustom = true;
1173 if (d->m_multiHighlightGradient == gradient)
1174 return;
1175
1176 d->m_dirtyBits.multiHighlightGradientDirty = true;
1177 d->m_multiHighlightGradient = gradient;
1178 Q_EMIT multiHighlightGradientChanged(gradient: d->m_multiHighlightGradient);
1179 Q_EMIT update();
1180}
1181
1182QLinearGradient QGraphsTheme::multiHighlightGradient() const
1183{
1184 Q_D(const QGraphsTheme);
1185 ;
1186 if (d->m_customBits.multiHighlightGradientCustom)
1187 return d->m_multiHighlightGradient;
1188 return d->m_multiHighlightThemeGradient;
1189}
1190
1191/*!
1192 * \property QGraphsTheme::labelFont
1193 *
1194 * \brief The font to be used for labels.
1195 */
1196QFont QGraphsTheme::labelFont() const
1197{
1198 Q_D(const QGraphsTheme);
1199 return d->m_labelFont;
1200}
1201
1202void QGraphsTheme::setLabelFont(const QFont &newFont)
1203{
1204 Q_D(QGraphsTheme);
1205 if (d->m_labelFont == newFont)
1206 return;
1207 d->m_dirtyBits.labelFontDirty = true;
1208 d->m_labelFont = newFont;
1209 if (!d->m_customBits.axisXLabelFontCustom)
1210 d->m_axisXLabelFont = newFont;
1211 if (!d->m_customBits.axisYLabelFontCustom)
1212 d->m_axisYLabelFont = newFont;
1213 if (!d->m_customBits.axisZLabelFontCustom)
1214 d->m_axisZLabelFont = newFont;
1215 Q_EMIT labelFontChanged();
1216 Q_EMIT update();
1217}
1218
1219/*!
1220 * \property QGraphsTheme::labelBackgroundVisible
1221 *
1222 *\brief Whether the label is drawn with a color background or with a fully
1223 * transparent background.
1224 *
1225 * The labelBackgroundColor value (including alpha) is used for drawing the
1226 * background.
1227 *
1228 * Labels with a background are drawn to equal sizes per axis based
1229 * on the longest label, and the text is centered in them. Labels without a
1230 * background are drawn as is and are left or right aligned based on their
1231 * position in the graph.
1232 * The default value is \c true.
1233 */
1234bool QGraphsTheme::isLabelBackgroundVisible() const
1235{
1236 Q_D(const QGraphsTheme);
1237 return d->m_labelBackgroundVisibility;
1238}
1239
1240void QGraphsTheme::setLabelBackgroundVisible(bool newLabelBackgroundVisibility)
1241{
1242 Q_D(QGraphsTheme);
1243 if (d->m_labelBackgroundVisibility == newLabelBackgroundVisibility)
1244 return;
1245 d->m_dirtyBits.labelBackgroundVisibilityDirty = true;
1246 d->m_labelBackgroundVisibility = newLabelBackgroundVisibility;
1247 Q_EMIT labelBackgroundVisibleChanged();
1248 Q_EMIT update();
1249}
1250
1251/*!
1252 * \property QGraphsTheme::labelBorderVisible
1253 *
1254 * \brief Whether label borders are drawn for labels that have a background.
1255 *
1256 * Has no effect if labelBackgroundVisible is \c false.
1257 * The default value is \c true.
1258 */
1259bool QGraphsTheme::isLabelBorderVisible() const
1260{
1261 Q_D(const QGraphsTheme);
1262 return d->m_labelBorderVisibility;
1263}
1264
1265void QGraphsTheme::setLabelBorderVisible(bool newLabelBorderVisibility)
1266{
1267 Q_D(QGraphsTheme);
1268 if (d->m_labelBorderVisibility == newLabelBorderVisibility)
1269 return;
1270 d->m_dirtyBits.labelBorderVisibilityDirty = true;
1271 d->m_labelBorderVisibility = newLabelBorderVisibility;
1272 Q_EMIT labelBorderVisibleChanged();
1273 Q_EMIT update();
1274}
1275
1276/*!
1277 * \property QGraphsTheme::seriesColors
1278 *
1279 * \brief The list of base colors to be used for all the objects in the graph,
1280 * series by series.
1281 *
1282 * If there are more series than colors, the color list wraps and starts again
1283 * with the first color in the list.
1284 *
1285 * Has no immediate effect if colorStyle is not Uniform.
1286 *
1287 * This value can be overridden by setting the \l{QAbstract3DSeries::baseColor}
1288 * {baseColor} explicitly in the series.
1289 */
1290QList<QColor> QGraphsTheme::seriesColors() const
1291{
1292 Q_D(const QGraphsTheme);
1293 if (d->m_customBits.seriesColorsCustom && !d->m_seriesColors.isEmpty())
1294 return d->m_seriesColors;
1295 return d->m_seriesThemeColors;
1296}
1297
1298void QGraphsTheme::setSeriesColors(const QList<QColor> &newSeriesColors)
1299{
1300 Q_D(QGraphsTheme);
1301 d->m_customBits.seriesColorsCustom = true;
1302 if (d->m_seriesColors == newSeriesColors)
1303 return;
1304 d->m_dirtyBits.seriesColorsDirty = true;
1305 d->m_seriesColors = newSeriesColors;
1306 Q_EMIT seriesColorsChanged(list: d->m_seriesColors);
1307 Q_EMIT update();
1308}
1309
1310/*!
1311 * \property QGraphsTheme::borderColors
1312 *
1313 * \brief The list of border colors to be used for all the objects in the graph,
1314 * series by series.
1315 *
1316 * If there are more series than colors, the color list wraps and starts again
1317 * with the first color in the list.
1318 *
1319 * Has no immediate effect if colorStyle is not Uniform.
1320 */
1321QList<QColor> QGraphsTheme::borderColors() const
1322{
1323 Q_D(const QGraphsTheme);
1324 if (d->m_customBits.borderColorsCustom && !d->m_borderColors.isEmpty())
1325 return d->m_borderColors;
1326 return d->m_borderThemeColors;
1327}
1328
1329void QGraphsTheme::setBorderColors(const QList<QColor> &newBorderColors)
1330{
1331 Q_D(QGraphsTheme);
1332 d->m_customBits.borderColorsCustom = true;
1333 if (d->m_borderColors == newBorderColors)
1334 return;
1335 d->m_borderColors = newBorderColors;
1336 Q_EMIT borderColorsChanged();
1337 Q_EMIT update();
1338}
1339
1340/*!
1341 Returns the list of series gradients used by theme.
1342 \sa setSeriesGradients()
1343 */
1344QList<QLinearGradient> QGraphsTheme::seriesGradients() const
1345{
1346 Q_D(const QGraphsTheme);
1347 if (d->m_customBits.seriesGradientCustom && !d->m_seriesGradients.isEmpty())
1348 return d->m_seriesGradients;
1349 return d->m_seriesThemeGradients;
1350}
1351
1352/*!
1353 Sets \a newSeriesGradients as the series gradients for the theme.
1354 \sa seriesGradients()
1355 */
1356void QGraphsTheme::setSeriesGradients(const QList<QLinearGradient> &newSeriesGradients)
1357{
1358 Q_D(QGraphsTheme);
1359 d->m_customBits.seriesGradientCustom = true;
1360 if (newSeriesGradients.size()) {
1361 d->m_dirtyBits.seriesGradientDirty = true;
1362 if (d->m_seriesGradients != newSeriesGradients) {
1363 d->m_seriesGradients.clear();
1364 d->m_seriesGradients = newSeriesGradients;
1365 Q_EMIT seriesGradientsChanged(list: newSeriesGradients);
1366 Q_EMIT update();
1367 }
1368 } else {
1369 d->m_seriesGradients.clear();
1370 Q_EMIT update();
1371 }
1372}
1373
1374/*!
1375 * \property QGraphsTheme::borderWidth
1376 *
1377 * \brief The width of borders in graph if any
1378 * The default value is \c 1.0.
1379 */
1380qreal QGraphsTheme::borderWidth() const
1381{
1382 Q_D(const QGraphsTheme);
1383 return d->m_borderWidth;
1384}
1385
1386void QGraphsTheme::setBorderWidth(qreal newBorderWidth)
1387{
1388 Q_D(QGraphsTheme);
1389 if (qFuzzyCompare(p1: d->m_borderWidth, p2: newBorderWidth))
1390 return;
1391 d->m_borderWidth = newBorderWidth;
1392 Q_EMIT borderWidthChanged();
1393 Q_EMIT update();
1394}
1395
1396void QGraphsTheme::handleBaseColorUpdate()
1397{
1398 Q_D(QGraphsTheme);
1399 qsizetype colorCount = d->m_colors.size();
1400 int changed = 0;
1401 // Check which one changed
1402 QQuickGraphsColor *color = qobject_cast<QQuickGraphsColor *>(object: QObject::sender());
1403 for (int i = 0; i < colorCount; i++) {
1404 if (color == d->m_colors.at(i)) {
1405 changed = i;
1406 break;
1407 }
1408 }
1409 // Update the changed one from the list
1410 QList<QColor> list = seriesColors();
1411 list[changed] = d->m_colors.at(i: changed)->color();
1412 // Set the changed list
1413 setSeriesColors(list);
1414}
1415
1416void QGraphsTheme::handleBaseGradientUpdate()
1417{
1418 Q_D(QGraphsTheme);
1419 // Find out which gradient has changed, and update the list with it
1420 qsizetype gradientCount = d->m_gradients.size();
1421 int changed = 0;
1422
1423 // Check which one changed
1424 QQuickGradient *newGradient = qobject_cast<QQuickGradient *>(object: QObject::sender());
1425
1426 for (int i = 0; i < gradientCount; ++i) {
1427 if (newGradient == d->m_gradients.at(i)) {
1428 changed = i;
1429 break;
1430 }
1431 }
1432
1433 // Update the changed one from the list
1434 QList<QLinearGradient> list = seriesGradients();
1435 list[changed] = convertGradient(gradient: newGradient);
1436
1437 // Set the changed list
1438 setSeriesGradients(list);
1439}
1440
1441void QGraphsTheme::classBegin()
1442{
1443}
1444
1445void QGraphsTheme::componentComplete()
1446{
1447 Q_D(QGraphsTheme);
1448 d->m_componentComplete = true;
1449}
1450
1451void QGraphsTheme::updateAutomaticColorScheme()
1452{
1453 setColorSchemePalette();
1454 Q_EMIT update();
1455}
1456
1457void QGraphsTheme::setColorSchemePalette()
1458{
1459 Q_D(QGraphsTheme);
1460 float defaultColorLevel = 0.5f;
1461
1462 Qt::ColorScheme colorScheme = Qt::ColorScheme::Unknown;
1463
1464 if (d->m_colorScheme == QGraphsTheme::ColorScheme::Automatic) {
1465 colorScheme = QGuiApplication::styleHints()->colorScheme();
1466 if (colorScheme == Qt::ColorScheme::Unknown)
1467 colorScheme = Qt::ColorScheme::Light;
1468 } else if (d->m_colorScheme == QGraphsTheme::ColorScheme::Dark) {
1469 colorScheme = Qt::ColorScheme::Dark;
1470 } else if (d->m_colorScheme == QGraphsTheme::ColorScheme::Light) {
1471 colorScheme = Qt::ColorScheme::Light;
1472 }
1473
1474 if (colorScheme == Qt::ColorScheme::Unknown)
1475 return;
1476
1477 if (d->m_componentComplete) {
1478 // Reset all customizations which colorScheme changes
1479 d->m_customBits.backgroundColorCustom = false;
1480 d->m_customBits.plotAreaBackgroundColorCustom = false;
1481 d->m_customBits.labelBackgroundColorCustom = false;
1482 d->m_customBits.labelTextColorCustom = false;
1483 d->m_customBits.multiHighlightColorCustom = false;
1484 d->m_customBits.multiHighlightGradientCustom = false;
1485 d->m_customBits.singleHighlightColorCustom = false;
1486 d->m_customBits.singleHighlightGradientCustom = false;
1487 d->m_grid.d->resetCustomBits();
1488 d->m_axisX.d->resetCustomBits();
1489 d->m_axisY.d->resetCustomBits();
1490 d->m_axisZ.d->resetCustomBits();
1491 }
1492
1493 if (colorScheme == Qt::ColorScheme::Dark) {
1494 d->m_backgroundThemeColor = QColor(QRgb(0x262626));
1495 d->m_plotAreaBackgroundThemeColor = QColor(QRgb(0x1F1F1F));
1496 d->m_labelBackgroundThemeColor = QColor(QRgb(0x2E2E2E));
1497
1498 d->m_grid.d->m_mainThemeColor = QColor(QRgb(0xAEABAB));
1499 d->m_grid.d->m_subThemeColor = QColor(QRgb(0x6A6A6A));
1500 d->m_axisX.d->m_mainThemeColor = QColor(QRgb(0xAEABAB));
1501 d->m_axisX.d->m_subThemeColor = QColor(QRgb(0x6A6A6A));
1502 d->m_axisY.d->m_mainThemeColor = QColor(QRgb(0xAEABAB));
1503 d->m_axisY.d->m_subThemeColor = QColor(QRgb(0x6A6A6A));
1504 d->m_axisZ.d->m_mainThemeColor = QColor(QRgb(0xAEABAB));
1505 d->m_axisZ.d->m_subThemeColor = QColor(QRgb(0x6A6A6A));
1506
1507 d->m_singleHighlightThemeColor = QColor(QRgb(0xDBEB00));
1508 d->m_multiHighlightThemeColor = QColor(QRgb(0x22D489));
1509 d->m_singleHighlightThemeGradient = createGradient(color: QColor(QRgb(0xDBEB00)),
1510 colorLevel: defaultColorLevel);
1511 d->m_multiHighlightThemeGradient = createGradient(color: QColor(QRgb(0x22D489)), colorLevel: defaultColorLevel);
1512
1513 d->m_labelTextThemeColor = QColor(QRgb(0xAEAEAE));
1514 d->m_axisX.d->m_labelTextThemeColor = QColor(QRgb(0xAEAEAE));
1515 d->m_axisY.d->m_labelTextThemeColor = QColor(QRgb(0xAEAEAE));
1516 d->m_axisZ.d->m_labelTextThemeColor = QColor(QRgb(0xAEAEAE));
1517 } else {
1518 d->m_backgroundThemeColor = QColor(QRgb(0xF2F2F2));
1519 d->m_plotAreaBackgroundThemeColor = QColor(QRgb(0xFCFCFC));
1520 d->m_labelBackgroundThemeColor = QColor(QRgb(0xE7E7E7));
1521
1522 d->m_grid.d->m_mainThemeColor = QColor(QRgb(0x545151));
1523 d->m_grid.d->m_subThemeColor = QColor(QRgb(0xAFAFAF));
1524 d->m_axisX.d->m_mainThemeColor = QColor(QRgb(0x545151));
1525 d->m_axisX.d->m_subThemeColor = QColor(QRgb(0xAFAFAF));
1526 d->m_axisY.d->m_mainThemeColor = QColor(QRgb(0x545151));
1527 d->m_axisY.d->m_subThemeColor = QColor(QRgb(0xAFAFAF));
1528 d->m_axisZ.d->m_mainThemeColor = QColor(QRgb(0x545151));
1529 d->m_axisZ.d->m_subThemeColor = QColor(QRgb(0xAFAFAF));
1530
1531 d->m_singleHighlightThemeColor = QColor(QRgb(0xCCDC00));
1532 d->m_multiHighlightThemeColor = QColor(QRgb(0x22D47B));
1533 d->m_singleHighlightThemeGradient = createGradient(color: QColor(QRgb(0xCCDC00)),
1534 colorLevel: defaultColorLevel);
1535 d->m_multiHighlightThemeGradient = createGradient(color: QColor(QRgb(0x22D47B)), colorLevel: defaultColorLevel);
1536
1537 d->m_labelTextThemeColor = QColor(QRgb(0x6A6A6A));
1538 d->m_axisX.d->m_labelTextThemeColor = QColor(QRgb(0x6A6A6A));
1539 d->m_axisY.d->m_labelTextThemeColor = QColor(QRgb(0x6A6A6A));
1540 d->m_axisZ.d->m_labelTextThemeColor = QColor(QRgb(0x6A6A6A));
1541 }
1542
1543 d->m_dirtyBits.backgroundColorDirty = true;
1544 d->m_dirtyBits.plotAreaBackgroundColorDirty = true;
1545 d->m_dirtyBits.labelBackgroundColorDirty = true;
1546 d->m_dirtyBits.gridDirty = true;
1547 d->m_dirtyBits.axisXDirty = true;
1548 d->m_dirtyBits.axisYDirty = true;
1549 d->m_dirtyBits.axisZDirty = true;
1550 d->m_dirtyBits.singleHighlightColorDirty = true;
1551 d->m_dirtyBits.singleHighlightGradientDirty = true;
1552 d->m_dirtyBits.multiHighlightColorDirty = true;
1553 d->m_dirtyBits.multiHighlightGradientDirty = true;
1554 d->m_dirtyBits.labelTextColorDirty = true;
1555 Q_EMIT gridChanged();
1556 Q_EMIT axisXChanged();
1557 Q_EMIT axisYChanged();
1558 Q_EMIT axisZChanged();
1559}
1560
1561void QGraphsTheme::setThemePalette()
1562{
1563 Q_D(QGraphsTheme);
1564 float defaultColorLevel = 0.5f;
1565 d->m_seriesThemeColors.clear();
1566 switch (d->m_theme) {
1567 case Theme::QtGreen:
1568 d->m_seriesThemeColors.append(t: QColor(QRgb(0xD5F8E7)));
1569 d->m_seriesThemeColors.append(t: QColor(QRgb(0xABF2CE)));
1570 d->m_seriesThemeColors.append(t: QColor(QRgb(0x7BE6B1)));
1571 d->m_seriesThemeColors.append(t: QColor(QRgb(0x51E098)));
1572 d->m_seriesThemeColors.append(t: QColor(QRgb(0x22D478)));
1573 break;
1574 case Theme::QtGreenNeon:
1575 d->m_seriesThemeColors.append(t: QColor(QRgb(0x22D478)));
1576 d->m_seriesThemeColors.append(t: QColor(QRgb(0x00AF80)));
1577 d->m_seriesThemeColors.append(t: QColor(QRgb(0x00897B)));
1578 d->m_seriesThemeColors.append(t: QColor(QRgb(0x006468)));
1579 d->m_seriesThemeColors.append(t: QColor(QRgb(0x00414A)));
1580 break;
1581 case Theme::MixSeries:
1582 d->m_seriesThemeColors.append(t: QColor(QRgb(0xFFA615)));
1583 d->m_seriesThemeColors.append(t: QColor(QRgb(0x5E45DF)));
1584 d->m_seriesThemeColors.append(t: QColor(QRgb(0x759F1C)));
1585 d->m_seriesThemeColors.append(t: QColor(QRgb(0xF92759)));
1586 d->m_seriesThemeColors.append(t: QColor(QRgb(0x0128F8)));
1587 break;
1588 case Theme::OrangeSeries:
1589 d->m_seriesThemeColors.append(t: QColor(QRgb(0xFFC290)));
1590 d->m_seriesThemeColors.append(t: QColor(QRgb(0xFF9C4D)));
1591 d->m_seriesThemeColors.append(t: QColor(QRgb(0xFF7200)));
1592 d->m_seriesThemeColors.append(t: QColor(QRgb(0xD86000)));
1593 d->m_seriesThemeColors.append(t: QColor(QRgb(0xA24900)));
1594 break;
1595 case Theme::YellowSeries:
1596 d->m_seriesThemeColors.append(t: QColor(QRgb(0xFFE380)));
1597 d->m_seriesThemeColors.append(t: QColor(QRgb(0xFFC500)));
1598 d->m_seriesThemeColors.append(t: QColor(QRgb(0xE2B000)));
1599 d->m_seriesThemeColors.append(t: QColor(QRgb(0xB88F00)));
1600 d->m_seriesThemeColors.append(t: QColor(QRgb(0x8C6D02)));
1601 break;
1602 case Theme::BlueSeries:
1603 d->m_seriesThemeColors.append(t: QColor(QRgb(0x86AFFF)));
1604 d->m_seriesThemeColors.append(t: QColor(QRgb(0x4A86FC)));
1605 d->m_seriesThemeColors.append(t: QColor(QRgb(0x2B6EF1)));
1606 d->m_seriesThemeColors.append(t: QColor(QRgb(0x0750E9)));
1607 d->m_seriesThemeColors.append(t: QColor(QRgb(0x0023DB)));
1608 break;
1609 case Theme::PurpleSeries:
1610 d->m_seriesThemeColors.append(t: QColor(QRgb(0xE682E7)));
1611 d->m_seriesThemeColors.append(t: QColor(QRgb(0xB646B7)));
1612 d->m_seriesThemeColors.append(t: QColor(QRgb(0x9035B4)));
1613 d->m_seriesThemeColors.append(t: QColor(QRgb(0x6C2BA0)));
1614 d->m_seriesThemeColors.append(t: QColor(QRgb(0x3D2582)));
1615 break;
1616 case Theme::GreySeries:
1617 d->m_seriesThemeColors.append(t: QColor(QRgb(0xCCD0D6)));
1618 d->m_seriesThemeColors.append(t: QColor(QRgb(0xA7AEBB)));
1619 d->m_seriesThemeColors.append(t: QColor(QRgb(0x7A869A)));
1620 d->m_seriesThemeColors.append(t: QColor(QRgb(0x566070)));
1621 d->m_seriesThemeColors.append(t: QColor(QRgb(0x3E4654)));
1622 break;
1623 default: // UserDefined
1624 d->m_seriesThemeColors.append(t: QColor(Qt::black));
1625 break;
1626 }
1627
1628 d->m_borderThemeColors = d->m_seriesThemeColors;
1629
1630 d->m_seriesThemeGradients.clear();
1631 for (QColor color : d->m_seriesThemeColors)
1632 d->m_seriesThemeGradients.append(t: createGradient(color, colorLevel: defaultColorLevel));
1633
1634 d->m_dirtyBits.seriesColorsDirty = true;
1635 d->m_dirtyBits.seriesGradientDirty = true;
1636}
1637
1638QLinearGradient QGraphsTheme::createGradient(QColor color, float colorLevel)
1639{
1640 QColor startColor;
1641 QLinearGradient gradient = QLinearGradient(Utils::maxTextureSize(),
1642 gradientTextureHeight,
1643 0.0,
1644 0.0);
1645 startColor.setRed(color.red() * colorLevel);
1646 startColor.setGreen(color.green() * colorLevel);
1647 startColor.setBlue(color.blue() * colorLevel);
1648 gradient.setColorAt(pos: 0.0, color: startColor);
1649 gradient.setColorAt(pos: 1.0, color);
1650 return gradient;
1651}
1652
1653void QGraphsTheme::setThemeGradient(QQuickGradient *gradient, GradientQMLStyle type)
1654{
1655 QLinearGradient linearGradient = convertGradient(gradient);
1656
1657 switch (type) {
1658 case GradientQMLStyle::SingleHL:
1659 setSingleHighlightGradient(linearGradient);
1660 break;
1661 case GradientQMLStyle::MultiHL:
1662 setMultiHighlightGradient(linearGradient);
1663 break;
1664 default:
1665 qWarning(msg: "Incorrect usage. Type may be GradientQMLStyle::SingleHL or "
1666 "GradientQMLStyle::MultiHL.");
1667 break;
1668 }
1669}
1670
1671QLinearGradient QGraphsTheme::convertGradient(QQuickGradient *gradient)
1672{
1673 // Create QLinearGradient out of QQuickGradient
1674 QLinearGradient newGradient;
1675 newGradient.setStops(gradient->gradientStops());
1676 return newGradient;
1677}
1678
1679QQmlListProperty<QQuickGraphsColor> QGraphsTheme::baseColorsQML()
1680{
1681 return QQmlListProperty<QQuickGraphsColor>(this,
1682 this,
1683 &QGraphsTheme::appendBaseColorsFunc,
1684 &QGraphsTheme::countBaseColorsFunc,
1685 &QGraphsTheme::atBaseColorsFunc,
1686 &QGraphsTheme::clearBaseColorsFunc);
1687}
1688
1689void QGraphsTheme::appendBaseColorsFunc(QQmlListProperty<QQuickGraphsColor> *list,
1690 QQuickGraphsColor *color)
1691{
1692 reinterpret_cast<QGraphsTheme *>(list->data)->addColor(color);
1693}
1694
1695qsizetype QGraphsTheme::countBaseColorsFunc(QQmlListProperty<QQuickGraphsColor> *list)
1696{
1697 return reinterpret_cast<QGraphsTheme *>(list->data)->colorList().size();
1698}
1699
1700QQuickGraphsColor *QGraphsTheme::atBaseColorsFunc(QQmlListProperty<QQuickGraphsColor> *list,
1701 qsizetype index)
1702{
1703 return reinterpret_cast<QGraphsTheme *>(list->data)->colorList().at(i: index);
1704}
1705
1706void QGraphsTheme::clearBaseColorsFunc(QQmlListProperty<QQuickGraphsColor> *list)
1707{
1708 reinterpret_cast<QGraphsTheme *>(list->data)->clearColors();
1709}
1710
1711QQmlListProperty<QQuickGradient> QGraphsTheme::baseGradientsQML()
1712{
1713 return QQmlListProperty<QQuickGradient>(this,
1714 this,
1715 &QGraphsTheme::appendBaseGradientsFunc,
1716 &QGraphsTheme::countBaseGradientsFunc,
1717 &QGraphsTheme::atBaseGradientsFunc,
1718 &QGraphsTheme::clearBaseGradientsFunc);
1719}
1720
1721void QGraphsTheme::appendBaseGradientsFunc(QQmlListProperty<QQuickGradient> *list,
1722 QQuickGradient *gradient)
1723{
1724 reinterpret_cast<QGraphsTheme *>(list->data)->addGradient(gradient);
1725}
1726
1727qsizetype QGraphsTheme::countBaseGradientsFunc(QQmlListProperty<QQuickGradient> *list)
1728{
1729 return reinterpret_cast<QGraphsTheme *>(list->data)->gradientList().size();
1730}
1731
1732QQuickGradient *QGraphsTheme::atBaseGradientsFunc(QQmlListProperty<QQuickGradient> *list,
1733 qsizetype index)
1734{
1735 return reinterpret_cast<QGraphsTheme *>(list->data)->gradientList().at(i: index);
1736}
1737
1738void QGraphsTheme::clearBaseGradientsFunc(QQmlListProperty<QQuickGradient> *list)
1739{
1740 reinterpret_cast<QGraphsTheme *>(list->data)->clearGradients();
1741}
1742
1743QQmlListProperty<QObject> QGraphsTheme::themeChildren()
1744{
1745 return QQmlListProperty<QObject>(this, this, &QGraphsTheme::appendThemeChildren, 0, 0, 0);
1746}
1747
1748void QGraphsTheme::appendThemeChildren(QQmlListProperty<QObject> *list, QObject *element)
1749{
1750 Q_UNUSED(list);
1751 Q_UNUSED(element);
1752}
1753
1754void QGraphsTheme::addColor(QQuickGraphsColor *color)
1755{
1756 if (!color) {
1757 qWarning(msg: "Color is invalid, use Color");
1758 return;
1759 }
1760 clearDummyColors();
1761 Q_D(QGraphsTheme);
1762 d->m_colors.append(t: color);
1763 connect(sender: color, signal: &QQuickGraphsColor::colorChanged, context: this, slot: &QGraphsTheme::handleBaseColorUpdate);
1764 QList<QColor> list = d->m_seriesColors;
1765 list.append(t: color->color());
1766 setSeriesColors(list);
1767}
1768
1769QList<QQuickGraphsColor *> QGraphsTheme::colorList()
1770{
1771 Q_D(QGraphsTheme);
1772 if (d->m_colors.isEmpty()) {
1773 // Create dummy Colors from theme's colors
1774 d->m_dummyColors = true;
1775 QList<QColor> list = seriesColors();
1776 for (const QColor &item : list) {
1777 QQuickGraphsColor *color = new QQuickGraphsColor(this);
1778 color->setColor(item);
1779 d->m_colors.append(t: color);
1780 connect(sender: color, signal: &QQuickGraphsColor::colorChanged, context: this, slot: &QGraphsTheme::handleBaseColorUpdate);
1781 }
1782 }
1783 return d->m_colors;
1784}
1785
1786void QGraphsTheme::clearColors()
1787{
1788 clearDummyColors();
1789 Q_D(QGraphsTheme);
1790 for (QQuickGraphsColor *item : d->m_colors)
1791 disconnect(sender: item, signal: 0, receiver: this, member: 0);
1792 d->m_colors.clear();
1793 setSeriesColors(QList<QColor>());
1794}
1795
1796void QGraphsTheme::clearDummyColors()
1797{
1798 Q_D(QGraphsTheme);
1799 if (d->m_dummyColors) {
1800 for (QQuickGraphsColor *item : d->m_colors)
1801 delete item;
1802 d->m_colors.clear();
1803 d->m_dummyColors = false;
1804 }
1805}
1806
1807void QGraphsTheme::addGradient(QQuickGradient *gradient)
1808{
1809 Q_D(QGraphsTheme);
1810 d->m_gradients.append(t: gradient);
1811
1812 connect(sender: gradient, signal: &QQuickGradient::updated, context: this, slot: &QGraphsTheme::handleBaseGradientUpdate);
1813
1814 QList<QLinearGradient> list = d->m_seriesGradients;
1815 list.append(t: convertGradient(gradient));
1816 setSeriesGradients(list);
1817}
1818
1819QQuickGradient *QGraphsTheme::singleHighlightGradientQML() const
1820{
1821 const Q_D(QGraphsTheme);
1822 return d->m_singleHLQuickGradient;
1823}
1824
1825void QGraphsTheme::setSingleHighlightGradientQML(QQuickGradient *gradient)
1826{
1827 Q_D(QGraphsTheme);
1828 // connect new / disconnect old
1829 if (gradient != d->m_singleHLQuickGradient) {
1830 if (d->m_singleHLQuickGradient)
1831 QObject::disconnect(sender: d->m_singleHLQuickGradient, signal: 0, receiver: this, member: 0);
1832
1833 d->m_singleHLQuickGradient = gradient;
1834
1835 QObject::connect(sender: d->m_singleHLQuickGradient,
1836 signal: &QQuickGradient::updated,
1837 context: this,
1838 slot: &QGraphsTheme::update);
1839
1840 Q_EMIT singleHighlightGradientQMLChanged();
1841 }
1842
1843 if (d->m_singleHLQuickGradient != nullptr)
1844 setThemeGradient(gradient: d->m_singleHLQuickGradient, type: QGraphsTheme::GradientQMLStyle::SingleHL);
1845}
1846
1847void QGraphsTheme::setMultiHighlightGradientQML(QQuickGradient *gradient)
1848{
1849 Q_D(QGraphsTheme);
1850 // connect new / disconnect old
1851 if (gradient != nullptr) {
1852 if (d->m_multiHLQuickGradient)
1853 QObject::disconnect(sender: d->m_multiHLQuickGradient, signal: 0, receiver: this, member: 0);
1854
1855 d->m_multiHLQuickGradient = gradient;
1856
1857 QObject::connect(sender: d->m_multiHLQuickGradient,
1858 signal: &QQuickGradient::updated,
1859 context: this,
1860 slot: &QGraphsTheme::update);
1861
1862 Q_EMIT multiHighlightGradientQMLChanged();
1863 }
1864
1865 if (d->m_multiHLQuickGradient != nullptr)
1866 setThemeGradient(gradient: d->m_multiHLQuickGradient, type: QGraphsTheme::GradientQMLStyle::MultiHL);
1867}
1868
1869QQuickGradient *QGraphsTheme::multiHighlightGradientQML() const
1870{
1871 const Q_D(QGraphsTheme);
1872 return d->m_multiHLQuickGradient;
1873}
1874
1875QList<QQuickGradient *> QGraphsTheme::gradientList()
1876{
1877 Q_D(QGraphsTheme);
1878 return d->m_gradients;
1879}
1880
1881void QGraphsTheme::clearGradients()
1882{
1883 Q_D(QGraphsTheme);
1884 d->m_gradients.clear();
1885 setSeriesGradients(QList<QLinearGradient>());
1886}
1887
1888QGraphsLine QGraphsTheme::grid() const
1889{
1890 Q_D(const QGraphsTheme);
1891 return d->m_grid;
1892}
1893
1894void QGraphsTheme::setGrid(const QGraphsLine &newGrid)
1895{
1896 Q_D(QGraphsTheme);
1897 if (d->m_grid == newGrid)
1898 return;
1899 d->m_grid = newGrid;
1900 d->m_dirtyBits.gridDirty = true;
1901 Q_EMIT gridChanged();
1902 Q_EMIT update();
1903}
1904
1905QGraphsLine QGraphsTheme::axisX() const
1906{
1907 Q_D(const QGraphsTheme);
1908 return d->m_axisX;
1909}
1910
1911void QGraphsTheme::setAxisX(const QGraphsLine &newAxisX)
1912{
1913 Q_D(QGraphsTheme);
1914 if (d->m_axisX == newAxisX)
1915 return;
1916 d->m_axisX = newAxisX;
1917 d->m_dirtyBits.axisXDirty = true;
1918 Q_EMIT axisXChanged();
1919 Q_EMIT update();
1920}
1921
1922QGraphsLine QGraphsTheme::axisY() const
1923{
1924 Q_D(const QGraphsTheme);
1925 return d->m_axisY;
1926}
1927
1928void QGraphsTheme::setAxisY(const QGraphsLine &newAxisY)
1929{
1930 Q_D(QGraphsTheme);
1931 if (d->m_axisY == newAxisY)
1932 return;
1933 d->m_axisY = newAxisY;
1934 d->m_dirtyBits.axisYDirty = true;
1935 Q_EMIT axisYChanged();
1936 Q_EMIT update();
1937}
1938
1939QGraphsLine QGraphsTheme::axisZ() const
1940{
1941 Q_D(const QGraphsTheme);
1942 return d->m_axisZ;
1943}
1944
1945void QGraphsTheme::setAxisZ(const QGraphsLine &newAxisZ)
1946{
1947 Q_D(QGraphsTheme);
1948 if (d->m_axisZ == newAxisZ)
1949 return;
1950 d->m_axisZ = newAxisZ;
1951 d->m_dirtyBits.axisZDirty = true;
1952 Q_EMIT axisZChanged();
1953 Q_EMIT update();
1954}
1955
1956QVariant QGraphsLine::create(const QJSValue &params)
1957{
1958 if (!params.isObject())
1959 return QVariant();
1960
1961 QGraphsLine line;
1962
1963 const QJSValue mainColor = params.property(QStringLiteral("mainColor"));
1964 if (mainColor.isString())
1965 line.setMainColor(QColor::fromString(name: mainColor.toString()));
1966 const QJSValue subColor = params.property(QStringLiteral("subColor"));
1967 if (subColor.isString())
1968 line.setSubColor(QColor::fromString(name: subColor.toString()));
1969 const QJSValue mainWidth = params.property(QStringLiteral("mainWidth"));
1970 if (mainWidth.isNumber())
1971 line.setMainWidth(mainWidth.toNumber());
1972 const QJSValue subWidth = params.property(QStringLiteral("subWidth"));
1973 if (subWidth.isNumber())
1974 line.setSubWidth(subWidth.toNumber());
1975 const QJSValue labelTextColor = params.property(QStringLiteral("labelTextColor"));
1976 if (labelTextColor.isString())
1977 line.setLabelTextColor(QColor::fromString(name: labelTextColor.toString()));
1978
1979 return line;
1980}
1981
1982QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QGraphsLinePrivate)
1983
1984QGraphsLine::QGraphsLine()
1985 : d(new QGraphsLinePrivate)
1986{
1987}
1988
1989QGraphsLine::QGraphsLine(const QGraphsLine &other)
1990 = default;
1991
1992QGraphsLine::~QGraphsLine()
1993 = default;
1994
1995QColor QGraphsLine::mainColor() const
1996{
1997 if (d->m_bits.mainColorCustom)
1998 return d->m_mainColor;
1999 return d->m_mainThemeColor;
2000}
2001
2002void QGraphsLine::setMainColor(QColor newColor)
2003{
2004 d->m_bits.mainColorCustom = true;
2005 if (d->m_mainColor == newColor)
2006 return;
2007 detach();
2008 d->m_mainColor = newColor;
2009}
2010
2011QColor QGraphsLine::subColor() const
2012{
2013 if (d->m_bits.subColorCustom)
2014 return d->m_subColor;
2015 return d->m_subThemeColor;
2016}
2017
2018void QGraphsLine::setSubColor(QColor newColor)
2019{
2020 d->m_bits.subColorCustom = true;
2021 if (d->m_subColor == newColor)
2022 return;
2023 detach();
2024 d->m_subColor = newColor;
2025}
2026
2027qreal QGraphsLine::mainWidth() const
2028{
2029 return d->m_mainWidth;
2030}
2031
2032void QGraphsLine::setMainWidth(qreal newWidth)
2033{
2034 if (qFuzzyCompare(p1: d->m_mainWidth, p2: newWidth))
2035 return;
2036 detach();
2037 d->m_mainWidth = newWidth;
2038}
2039
2040qreal QGraphsLine::subWidth() const
2041{
2042 return d->m_subWidth;
2043}
2044
2045void QGraphsLine::setSubWidth(qreal newWidth)
2046{
2047 if (qFuzzyCompare(p1: d->m_subWidth, p2: newWidth))
2048 return;
2049 detach();
2050 d->m_subWidth = newWidth;
2051}
2052
2053QColor QGraphsLine::labelTextColor() const
2054{
2055 if (d->m_bits.labelTextColorCustom)
2056 return d->m_labelTextColor;
2057 return d->m_labelTextThemeColor;
2058}
2059
2060void QGraphsLine::setLabelTextColor(QColor newColor)
2061{
2062 d->m_bits.labelTextColorCustom = true;
2063 if (d->m_labelTextColor == newColor)
2064 return;
2065 detach();
2066 d->m_labelTextColor = newColor;
2067}
2068
2069void QGraphsLine::detach()
2070{
2071 d.detach();
2072}
2073
2074QGraphsLine &QGraphsLine::operator=(const QGraphsLine &other)
2075{
2076 QGraphsLine temp(other);
2077 swap(other&: temp);
2078 return *this;
2079}
2080
2081QGraphsLine::operator QVariant() const
2082{
2083 return QVariant::fromValue(value: *this);
2084}
2085
2086///////////////////////////////////////////////////////////////////////////
2087
2088QGraphsLinePrivate::QGraphsLinePrivate()
2089 : QSharedData()
2090 , m_mainColor(QColor())
2091 , m_subColor(QColor())
2092 , m_mainWidth(2.0f)
2093 , m_subWidth(1.0f)
2094 , m_labelTextColor(QColor())
2095 , m_mainThemeColor(QColor())
2096 , m_subThemeColor(QColor())
2097 , m_labelTextThemeColor(QColor())
2098 , m_bits(QGraphsLineCustomField())
2099{}
2100
2101QGraphsLinePrivate::QGraphsLinePrivate(const QGraphsLinePrivate &other)
2102 : QSharedData(other)
2103 , m_mainColor(other.m_mainColor)
2104 , m_subColor(other.m_subColor)
2105 , m_mainWidth(other.m_mainWidth)
2106 , m_subWidth(other.m_subWidth)
2107 , m_labelTextColor(other.m_labelTextColor)
2108 , m_mainThemeColor(other.m_mainThemeColor)
2109 , m_subThemeColor(other.m_subThemeColor)
2110 , m_labelTextThemeColor(other.m_labelTextThemeColor)
2111 , m_bits(other.m_bits)
2112{}
2113
2114QGraphsLinePrivate::~QGraphsLinePrivate()
2115 = default;
2116
2117void QGraphsLinePrivate::resetCustomBits()
2118{
2119 m_bits.mainColorCustom = false;
2120 m_bits.subColorCustom = false;
2121 m_bits.labelTextColorCustom = false;
2122}
2123
2124QGraphsThemePrivate::QGraphsThemePrivate() {}
2125
2126QGraphsThemePrivate::~QGraphsThemePrivate() {}
2127bool comparesEqual(const QGraphsLinePrivate &lhs, const QGraphsLinePrivate &rhs) noexcept
2128{
2129 bool ret = true;
2130 ret = ret && (lhs.m_bits.mainColorCustom == rhs.m_bits.mainColorCustom);
2131 if (!ret)
2132 return ret;
2133 ret = ret && (lhs.m_bits.subColorCustom == rhs.m_bits.subColorCustom);
2134 if (!ret)
2135 return ret;
2136 ret = ret && (lhs.m_bits.labelTextColorCustom == rhs.m_bits.labelTextColorCustom);
2137 if (!ret)
2138 return ret;
2139 ret = ret && (lhs.m_mainColor == rhs.m_mainColor);
2140 if (!ret)
2141 return ret;
2142 ret = ret && (lhs.m_subColor == rhs.m_subColor);
2143 if (!ret)
2144 return ret;
2145 ret = ret && qFuzzyCompare(p1: lhs.m_mainWidth, p2: rhs.m_mainWidth);
2146 if (!ret)
2147 return ret;
2148 ret = ret && qFuzzyCompare(p1: lhs.m_subWidth, p2: rhs.m_subWidth);
2149 if (!ret)
2150 return ret;
2151 ret = ret && (lhs.m_labelTextColor == rhs.m_labelTextColor);
2152 if (!ret)
2153 return ret;
2154 ret = ret && (lhs.m_mainThemeColor == rhs.m_mainThemeColor);
2155 if (!ret)
2156 return ret;
2157 ret = ret && (lhs.m_subThemeColor == rhs.m_subThemeColor);
2158 if (!ret)
2159 return ret;
2160 ret = ret && (lhs.m_labelTextThemeColor == rhs.m_labelTextThemeColor);
2161 if (!ret)
2162 return ret;
2163
2164 return ret;
2165}
2166
2167QT_END_NAMESPACE
2168

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtgraphs/src/common/theme/qgraphstheme.cpp