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

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