| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "qabstract3dseries_p.h" |
| 5 | #include "qabstractdataproxy_p.h" |
| 6 | #include "qquickgraphsitem_p.h" |
| 7 | #include "utils_p.h" |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | |
| 11 | /*! |
| 12 | * \class QAbstract3DSeries |
| 13 | * \inmodule QtGraphs |
| 14 | * \ingroup graphs_3D |
| 15 | * \brief The QAbstract3DSeries class is a base class for all 3D data series. |
| 16 | * |
| 17 | * There are inherited classes for each supported series type: QBar3DSeries, |
| 18 | * QScatter3DSeries, and QSurface3DSeries. |
| 19 | * |
| 20 | * For more information, see \l{Qt Graphs Data Handling with 3D}. |
| 21 | */ |
| 22 | |
| 23 | /*! |
| 24 | * \class QAbstract3DSeriesChangeBitField |
| 25 | * \internal |
| 26 | */ |
| 27 | |
| 28 | /*! |
| 29 | * \class QAbstract3DSeriesThemeOverrideBitField |
| 30 | * \internal |
| 31 | */ |
| 32 | |
| 33 | /*! |
| 34 | * \qmltype Abstract3DSeries |
| 35 | * \qmlabstract |
| 36 | * \inqmlmodule QtGraphs |
| 37 | * \ingroup graphs_qml_3D |
| 38 | * \nativetype QAbstract3DSeries |
| 39 | * \brief A base type for all 3D data series. |
| 40 | * |
| 41 | * This abstract class serves as a base class for the following subtypes: |
| 42 | * Bar3DSeries, Scatter3DSeries, and Surface3DSeries. |
| 43 | * |
| 44 | * For more information, see \l{Qt Graphs Data Handling with 3D}. |
| 45 | */ |
| 46 | |
| 47 | /*! |
| 48 | * \enum QAbstract3DSeries::SeriesType |
| 49 | * |
| 50 | * Type of the series. |
| 51 | * |
| 52 | * \value None |
| 53 | * No series type. |
| 54 | * \value Bar |
| 55 | * Series type for Q3DBarsWidgetItem. |
| 56 | * \value Scatter |
| 57 | * Series type for Q3DScatterWidgetItem. |
| 58 | * \value Surface |
| 59 | * Series type for Q3DSurfaceWidgetItem. |
| 60 | */ |
| 61 | |
| 62 | /*! |
| 63 | * \enum QAbstract3DSeries::Mesh |
| 64 | * |
| 65 | * Predefined mesh types. All styles are not usable with all graphs types. |
| 66 | * |
| 67 | * \value UserDefined |
| 68 | * User defined mesh, set via QAbstract3DSeries::userDefinedMesh property. |
| 69 | * \value Bar |
| 70 | * Basic rectangular bar. |
| 71 | * \value Cube |
| 72 | * Basic cube. |
| 73 | * \value Pyramid |
| 74 | * Four-sided pyramid. |
| 75 | * \value Cone |
| 76 | * Basic cone. |
| 77 | * \value Cylinder |
| 78 | * Basic cylinder. |
| 79 | * \value BevelBar |
| 80 | * Slightly beveled (rounded) rectangular bar. |
| 81 | * \value BevelCube |
| 82 | * Slightly beveled (rounded) cube. |
| 83 | * \value Sphere |
| 84 | * Sphere. |
| 85 | * \value Minimal |
| 86 | * The minimal 3D mesh: a triangular pyramid. Usable only with Q3DScatterWidgetItem. |
| 87 | * \value Arrow |
| 88 | * Arrow pointing upwards. |
| 89 | * \value Point |
| 90 | * 2D point. Usable only with Q3DScatterWidgetItem. |
| 91 | * Shadows do not affect this style. Color style QGraphsTheme::ColorStyle::ObjectGradient |
| 92 | * is not supported by this style. |
| 93 | */ |
| 94 | |
| 95 | /*! |
| 96 | * \qmlproperty Abstract3DSeries.SeriesType Abstract3DSeries::type |
| 97 | * The type of the series. One of the QAbstract3DSeries::SeriesType values. |
| 98 | * |
| 99 | */ |
| 100 | |
| 101 | /*! |
| 102 | * \qmlproperty string Abstract3DSeries::itemLabelFormat |
| 103 | * |
| 104 | * The label format for data items in this series. This format is used for |
| 105 | * single item labels, for example, when an item is selected. How the format is |
| 106 | * interpreted depends on series type. |
| 107 | * |
| 108 | * \sa Bar3DSeries, Scatter3DSeries, Surface3DSeries. |
| 109 | */ |
| 110 | |
| 111 | /*! |
| 112 | * \qmlproperty bool Abstract3DSeries::visible |
| 113 | * Sets the visibility of the series. If \c false, the series is not rendered. |
| 114 | */ |
| 115 | |
| 116 | /*! |
| 117 | * \qmlproperty Abstract3DSeries.Mesh Abstract3DSeries::mesh |
| 118 | * |
| 119 | * Sets the mesh of the items in the series, or the selection pointer in case of |
| 120 | * Surface3DSeries. If the mesh is |
| 121 | * \l{QAbstract3DSeries::Mesh::UserDefined}{Abstract3DSeries.Mesh.UserDefined}, |
| 122 | * then the userDefinedMesh property must also be set for items to render |
| 123 | * properly. The default value depends on the graph type. |
| 124 | * |
| 125 | * \sa QAbstract3DSeries::Mesh |
| 126 | */ |
| 127 | |
| 128 | /*! |
| 129 | * \qmlproperty bool Abstract3DSeries::meshSmooth |
| 130 | * |
| 131 | * If \c true, smooth versions of predefined meshes set via the \l mesh property |
| 132 | * are used. This property does not affect custom meshes used when the mesh is |
| 133 | * set to |
| 134 | * \l{QAbstract3DSeries::Mesh::UserDefined}{Abstract3DSeries.Mesh.UserDefined}. |
| 135 | * Defaults to \c{false}. |
| 136 | */ |
| 137 | |
| 138 | /*! |
| 139 | * \qmlproperty quaternion Abstract3DSeries::meshRotation |
| 140 | * |
| 141 | * Sets the mesh rotation that is applied to all items of the series. |
| 142 | * The rotation should be a normalized quaternion. |
| 143 | * For those series types that support item specific rotation, the rotations are |
| 144 | * multiplied together. |
| 145 | * Bar3DSeries ignores any rotation that is not around the y-axis. |
| 146 | * Surface3DSeries applies the rotation only to the selection pointer. |
| 147 | * Defaults to no rotation. |
| 148 | */ |
| 149 | |
| 150 | /*! |
| 151 | * \qmlproperty string Abstract3DSeries::userDefinedMesh |
| 152 | * |
| 153 | * Sets the filename for a user defined custom mesh for objects that is used |
| 154 | * when \l mesh is |
| 155 | * \l{QAbstract3DSeries::Mesh::UserDefined}{Abstract3DSeries.Mesh.UserDefined}. |
| 156 | * \note The file needs to be in the QtQuick3D mesh format. Use the \c balsam |
| 157 | * conversion tool to create a mesh from other 3D model formats. |
| 158 | */ |
| 159 | |
| 160 | /*! |
| 161 | * \qmlproperty GraphsTheme.ColorStyle Abstract3DSeries::colorStyle |
| 162 | * |
| 163 | * Sets the color style for the series. |
| 164 | * |
| 165 | * \sa {QGraphsTheme::ColorStyle}{GraphsTheme.ColorStyle} |
| 166 | */ |
| 167 | |
| 168 | /*! |
| 169 | * \qmlproperty color Abstract3DSeries::baseColor |
| 170 | * |
| 171 | * Sets the base color of the series. |
| 172 | * |
| 173 | * \sa colorStyle, {GraphsTheme::seriesColors}{GraphsTheme.seriesColors} |
| 174 | */ |
| 175 | |
| 176 | /*! |
| 177 | * \qmlproperty Gradient Abstract3DSeries::baseGradient |
| 178 | * |
| 179 | * Sets the base gradient of the series. |
| 180 | * |
| 181 | * \sa colorStyle, {GraphsTheme::seriesGradients}{GraphsTheme.seriesGradients} |
| 182 | */ |
| 183 | |
| 184 | /*! |
| 185 | * \qmlproperty color Abstract3DSeries::singleHighlightColor |
| 186 | * |
| 187 | * Sets the single item highlight color of the series. |
| 188 | * |
| 189 | * \sa colorStyle, {GraphsTheme::singleHighlightColor}{GraphsTheme.singleHighlightColor} |
| 190 | */ |
| 191 | |
| 192 | /*! |
| 193 | * \qmlproperty Gradient Abstract3DSeries::singleHighlightGradient |
| 194 | * |
| 195 | * Sets the single item highlight gradient of the series. |
| 196 | * |
| 197 | * \sa colorStyle, |
| 198 | * {GraphsTheme::singleHighlightGradient}{GraphsTheme.singleHighlightGradient} |
| 199 | */ |
| 200 | |
| 201 | /*! |
| 202 | * \qmlproperty color Abstract3DSeries::multiHighlightColor |
| 203 | * |
| 204 | * Sets the multiple item highlight color of the series. |
| 205 | * |
| 206 | * \sa colorStyle, {GraphsTheme::multiHighlightColor}{GraphsTheme.multiHighlightColor} |
| 207 | */ |
| 208 | |
| 209 | /*! |
| 210 | * \qmlproperty Gradient Abstract3DSeries::multiHighlightGradient |
| 211 | * |
| 212 | * Sets the multiple item highlight gradient of the series. |
| 213 | * |
| 214 | * \sa colorStyle, |
| 215 | * {GraphsTheme::multiHighlightGradient}{GraphsTheme.multiHighlightGradient} |
| 216 | */ |
| 217 | |
| 218 | /*! |
| 219 | * \qmlproperty string Abstract3DSeries::name |
| 220 | * |
| 221 | * The series name. |
| 222 | * It can be used in item label format with the tag \c{@seriesName}. |
| 223 | * |
| 224 | * \sa itemLabelFormat |
| 225 | */ |
| 226 | |
| 227 | /*! |
| 228 | * \qmlproperty string Abstract3DSeries::itemLabel |
| 229 | * |
| 230 | * The formatted item label. If there is no selected item or the selected item |
| 231 | * is not visible, returns an empty string. |
| 232 | * |
| 233 | * \sa itemLabelFormat |
| 234 | */ |
| 235 | |
| 236 | /*! |
| 237 | * \qmlproperty bool Abstract3DSeries::itemLabelVisible |
| 238 | * |
| 239 | * If \c true, item labels are drawn as floating labels in the graph. Otherwise, |
| 240 | * item labels are not drawn. To show the item label in an external control, |
| 241 | * this property is set to \c false. Defaults to \c true. |
| 242 | * |
| 243 | * \sa itemLabelFormat, itemLabel |
| 244 | */ |
| 245 | |
| 246 | /*! |
| 247 | * \qmlmethod void Abstract3DSeries::setMeshAxisAndAngle(vector3d axis, real |
| 248 | * angle) |
| 249 | * |
| 250 | * A convenience function to construct a mesh rotation quaternion from \a axis |
| 251 | * and \a angle. |
| 252 | * |
| 253 | * \sa meshRotation |
| 254 | */ |
| 255 | |
| 256 | /*! |
| 257 | \qmlsignal Abstract3DSeries::itemLabelFormatChanged(string format) |
| 258 | |
| 259 | This signal is emitted when itemLabelFormat changes to \a format. |
| 260 | */ |
| 261 | /*! |
| 262 | \qmlsignal Abstract3DSeries::visibilityChanged(bool visible) |
| 263 | |
| 264 | This signal is emitted when the series visibility changes to \a visible. |
| 265 | */ |
| 266 | /*! |
| 267 | \qmlsignal Abstract3DSeries::meshChanged(Abstract3DSeries.Mesh mesh) |
| 268 | |
| 269 | This signal is emitted when \l mesh changes to \a mesh. |
| 270 | */ |
| 271 | /*! |
| 272 | \qmlsignal Abstract3DSeries::meshSmoothChanged(bool enabled) |
| 273 | |
| 274 | This signal is emitted when meshSmooth changes to \a enabled. |
| 275 | */ |
| 276 | /*! |
| 277 | \qmlsignal Abstract3DSeries::meshRotationChanged(quaternion rotation) |
| 278 | |
| 279 | This signal is emitted when meshRotation changes to \a rotation. |
| 280 | */ |
| 281 | /*! |
| 282 | \qmlsignal Abstract3DSeries::userDefinedMeshChanged(string fileName) |
| 283 | |
| 284 | This signal is emitted when userDefinedMesh changes to \a fileName. |
| 285 | */ |
| 286 | /*! |
| 287 | \qmlsignal Abstract3DSeries::colorStyleChanged(GraphsTheme.ColorStyle style) |
| 288 | |
| 289 | This signal is emitted when colorStyle changes to \a style. |
| 290 | */ |
| 291 | /*! |
| 292 | \qmlsignal Abstract3DSeries::baseColorChanged(color color) |
| 293 | |
| 294 | This signal is emitted when baseColor changes to \a color. |
| 295 | */ |
| 296 | /*! |
| 297 | \qmlsignal Abstract3DSeries::baseGradientChanged(Gradient gradient) |
| 298 | |
| 299 | This signal is emitted when baseGradient changes to \a gradient. |
| 300 | */ |
| 301 | /*! |
| 302 | \qmlsignal Abstract3DSeries::singleHighlightColorChanged(color color) |
| 303 | |
| 304 | This signal is emitted when singleHighlightColor changes to \a color. |
| 305 | */ |
| 306 | /*! |
| 307 | \qmlsignal Abstract3DSeries::singleHighlightGradientChanged(Gradient gradient) |
| 308 | |
| 309 | This signal is emitted when singleHighlightGradient changes to \a gradient. |
| 310 | */ |
| 311 | /*! |
| 312 | \qmlsignal Abstract3DSeries::multiHighlightColorChanged(color color) |
| 313 | |
| 314 | This signal is emitted when multiHighlightColor changes to \a color. |
| 315 | */ |
| 316 | /*! |
| 317 | \qmlsignal Abstract3DSeries::multiHighlightGradientChanged(Gradient gradient) |
| 318 | |
| 319 | This signal is emitted when multiHighlightGradient changes to \a gradient. |
| 320 | */ |
| 321 | /*! |
| 322 | \qmlsignal Abstract3DSeries::nameChanged(string name) |
| 323 | |
| 324 | This signal is emitted when \l name changes to \a name. |
| 325 | */ |
| 326 | /*! |
| 327 | \qmlsignal Abstract3DSeries::itemLabelChanged(string label) |
| 328 | |
| 329 | This signal is emitted when itemLabel changes to \a label. |
| 330 | */ |
| 331 | /*! |
| 332 | \qmlsignal Abstract3DSeries::itemLabelVisibilityChanged(bool visible) |
| 333 | |
| 334 | This signal is emitted when itemLabelVisibility changes to \a visible. |
| 335 | */ |
| 336 | |
| 337 | /*! |
| 338 | * \internal |
| 339 | */ |
| 340 | QAbstract3DSeries::QAbstract3DSeries(QAbstract3DSeriesPrivate &d, QObject *parent) |
| 341 | : QObject(d, parent) |
| 342 | {} |
| 343 | |
| 344 | /*! |
| 345 | * Deletes the abstract 3D series. |
| 346 | */ |
| 347 | QAbstract3DSeries::~QAbstract3DSeries() {} |
| 348 | |
| 349 | /*! |
| 350 | * \property QAbstract3DSeries::type |
| 351 | * |
| 352 | * \brief The type of the series. |
| 353 | */ |
| 354 | QAbstract3DSeries::SeriesType QAbstract3DSeries::type() const |
| 355 | { |
| 356 | Q_D(const QAbstract3DSeries); |
| 357 | return d->m_type; |
| 358 | } |
| 359 | |
| 360 | /*! |
| 361 | * \property QAbstract3DSeries::itemLabelFormat |
| 362 | * |
| 363 | * \brief The label format for data items in this series. |
| 364 | * |
| 365 | * This format is used for single item labels, |
| 366 | * for example, when an item is selected. How the format is interpreted depends |
| 367 | * on series type. |
| 368 | * |
| 369 | * \sa QBar3DSeries, QScatter3DSeries, QSurface3DSeries. |
| 370 | */ |
| 371 | void QAbstract3DSeries::setItemLabelFormat(const QString &format) |
| 372 | { |
| 373 | Q_D(QAbstract3DSeries); |
| 374 | if (d->m_itemLabelFormat != format) { |
| 375 | d->setItemLabelFormat(format); |
| 376 | emit itemLabelFormatChanged(format); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | QString QAbstract3DSeries::itemLabelFormat() const |
| 381 | { |
| 382 | Q_D(const QAbstract3DSeries); |
| 383 | return d->m_itemLabelFormat; |
| 384 | } |
| 385 | |
| 386 | /*! |
| 387 | * \property QAbstract3DSeries::visible |
| 388 | * |
| 389 | * \brief The visibility of the series. |
| 390 | * |
| 391 | * If this property is \c false, the series is not rendered. |
| 392 | * Defaults to \c{true}. |
| 393 | */ |
| 394 | void QAbstract3DSeries::setVisible(bool visible) |
| 395 | { |
| 396 | Q_D(QAbstract3DSeries); |
| 397 | if (d->m_visible != visible) { |
| 398 | d->setVisible(visible); |
| 399 | emit visibleChanged(visible); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | bool QAbstract3DSeries::isVisible() const |
| 404 | { |
| 405 | Q_D(const QAbstract3DSeries); |
| 406 | return d->m_visible; |
| 407 | } |
| 408 | |
| 409 | /*! |
| 410 | * \property QAbstract3DSeries::mesh |
| 411 | * |
| 412 | * \brief The mesh of the items in the series. |
| 413 | * |
| 414 | * For QSurface3DSeries, this property holds the selection pointer. |
| 415 | * |
| 416 | * If the mesh is MeshUserDefined, then the userDefinedMesh property |
| 417 | * must also be set for items to render properly. The default value depends on |
| 418 | * the graph type. |
| 419 | */ |
| 420 | void QAbstract3DSeries::setMesh(QAbstract3DSeries::Mesh mesh) |
| 421 | { |
| 422 | Q_D(QAbstract3DSeries); |
| 423 | if ((mesh == QAbstract3DSeries::Mesh::Point || mesh == QAbstract3DSeries::Mesh::Minimal |
| 424 | || mesh == QAbstract3DSeries::Mesh::Arrow) |
| 425 | && type() != QAbstract3DSeries::SeriesType::Scatter) { |
| 426 | qWarning(msg: "Specified style is only supported for QScatter3DSeries." ); |
| 427 | } else if (d->m_mesh != mesh) { |
| 428 | d->setMesh(mesh); |
| 429 | emit meshChanged(mesh); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | QAbstract3DSeries::Mesh QAbstract3DSeries::mesh() const |
| 434 | { |
| 435 | Q_D(const QAbstract3DSeries); |
| 436 | return d->m_mesh; |
| 437 | } |
| 438 | |
| 439 | /*! |
| 440 | * \property QAbstract3DSeries::meshSmooth |
| 441 | * |
| 442 | * \brief Whether smooth versions of predefined meshes are used. |
| 443 | * |
| 444 | * If \c true, smooth versions set via the \l mesh property are used. |
| 445 | * This property does not affect custom meshes used when the mesh is set to |
| 446 | * MeshUserDefined. Defaults to \c{false}. |
| 447 | */ |
| 448 | void QAbstract3DSeries::setMeshSmooth(bool enable) |
| 449 | { |
| 450 | Q_D(QAbstract3DSeries); |
| 451 | if (d->m_meshSmooth != enable) { |
| 452 | d->setMeshSmooth(enable); |
| 453 | emit meshSmoothChanged(enabled: enable); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | bool QAbstract3DSeries::isMeshSmooth() const |
| 458 | { |
| 459 | Q_D(const QAbstract3DSeries); |
| 460 | return d->m_meshSmooth; |
| 461 | } |
| 462 | |
| 463 | /*! |
| 464 | * \property QAbstract3DSeries::meshRotation |
| 465 | * |
| 466 | * \brief The mesh rotation that is applied to all items of the series. |
| 467 | * |
| 468 | * The rotation should be a normalized QQuaternion. |
| 469 | * For those series types that support item specific rotation, the rotations are |
| 470 | * multiplied together. |
| 471 | * QBar3DSeries ignores any rotation that is not around the y-axis. |
| 472 | * QSurface3DSeries applies the rotation only to the selection pointer. |
| 473 | * Defaults to no rotation. |
| 474 | */ |
| 475 | void QAbstract3DSeries::setMeshRotation(const QQuaternion &rotation) |
| 476 | { |
| 477 | Q_D(QAbstract3DSeries); |
| 478 | if (d->m_meshRotation != rotation) { |
| 479 | d->setMeshRotation(rotation); |
| 480 | emit meshRotationChanged(rotation); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | QQuaternion QAbstract3DSeries::meshRotation() const |
| 485 | { |
| 486 | Q_D(const QAbstract3DSeries); |
| 487 | return d->m_meshRotation; |
| 488 | } |
| 489 | |
| 490 | /*! |
| 491 | * A convenience function to construct a mesh rotation quaternion from |
| 492 | * \a axis and \a angle. |
| 493 | * |
| 494 | * \sa meshRotation |
| 495 | */ |
| 496 | void QAbstract3DSeries::setMeshAxisAndAngle(QVector3D axis, float angle) |
| 497 | { |
| 498 | setMeshRotation(QQuaternion::fromAxisAndAngle(axis, angle)); |
| 499 | } |
| 500 | |
| 501 | /*! |
| 502 | * \property QAbstract3DSeries::userDefinedMesh |
| 503 | * |
| 504 | * \brief The filename for a user defined custom mesh for objects. |
| 505 | * |
| 506 | * The custom mesh is used when \l mesh is MeshUserDefined. |
| 507 | * \note The file needs to be in the QtQuick3D mesh format. Use the \c balsam |
| 508 | * conversion tool to create a mesh from other 3D model formats. |
| 509 | */ |
| 510 | void QAbstract3DSeries::setUserDefinedMesh(const QString &fileName) |
| 511 | { |
| 512 | Q_D(QAbstract3DSeries); |
| 513 | if (d->m_userDefinedMesh != fileName) { |
| 514 | d->setUserDefinedMesh(fileName); |
| 515 | emit userDefinedMeshChanged(fileName); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | QString QAbstract3DSeries::userDefinedMesh() const |
| 520 | { |
| 521 | Q_D(const QAbstract3DSeries); |
| 522 | return d->m_userDefinedMesh; |
| 523 | } |
| 524 | |
| 525 | /*! |
| 526 | * \property QAbstract3DSeries::colorStyle |
| 527 | * |
| 528 | * \brief The color style for the series. |
| 529 | * |
| 530 | * \sa QGraphsTheme::ColorStyle |
| 531 | */ |
| 532 | void QAbstract3DSeries::setColorStyle(QGraphsTheme::ColorStyle style) |
| 533 | { |
| 534 | Q_D(QAbstract3DSeries); |
| 535 | if (d->m_colorStyle != style) { |
| 536 | d->setColorStyle(style); |
| 537 | emit colorStyleChanged(style); |
| 538 | } |
| 539 | d->m_themeTracker.colorStyleOverride = true; |
| 540 | } |
| 541 | |
| 542 | QGraphsTheme::ColorStyle QAbstract3DSeries::colorStyle() const |
| 543 | { |
| 544 | Q_D(const QAbstract3DSeries); |
| 545 | return d->m_colorStyle; |
| 546 | } |
| 547 | |
| 548 | /*! |
| 549 | * \property QAbstract3DSeries::baseColor |
| 550 | * |
| 551 | * \brief The base color of the series. |
| 552 | * |
| 553 | * \sa colorStyle, QGraphsTheme::seriesColors |
| 554 | */ |
| 555 | void QAbstract3DSeries::setBaseColor(QColor color) |
| 556 | { |
| 557 | Q_D(QAbstract3DSeries); |
| 558 | if (d->m_baseColor != color) { |
| 559 | d->setBaseColor(color); |
| 560 | emit baseColorChanged(color); |
| 561 | } |
| 562 | d->m_themeTracker.baseColorOverride = true; |
| 563 | } |
| 564 | |
| 565 | QColor QAbstract3DSeries::baseColor() const |
| 566 | { |
| 567 | Q_D(const QAbstract3DSeries); |
| 568 | return d->m_baseColor; |
| 569 | } |
| 570 | |
| 571 | /*! |
| 572 | * \property QAbstract3DSeries::baseGradient |
| 573 | * |
| 574 | * \brief The base gradient of the series. |
| 575 | * |
| 576 | * \sa colorStyle, QGraphsTheme::seriesGradients |
| 577 | */ |
| 578 | void QAbstract3DSeries::setBaseGradient(const QLinearGradient &gradient) |
| 579 | { |
| 580 | Q_D(QAbstract3DSeries); |
| 581 | if (d->m_baseGradient != gradient) { |
| 582 | d->setBaseGradient(gradient); |
| 583 | emit baseGradientChanged(gradient); |
| 584 | } |
| 585 | d->m_themeTracker.baseGradientOverride = true; |
| 586 | } |
| 587 | |
| 588 | QLinearGradient QAbstract3DSeries::baseGradient() const |
| 589 | { |
| 590 | Q_D(const QAbstract3DSeries); |
| 591 | return d->m_baseGradient; |
| 592 | } |
| 593 | |
| 594 | /*! |
| 595 | * \property QAbstract3DSeries::singleHighlightColor |
| 596 | * |
| 597 | * \brief The single item highlight color of the series. |
| 598 | * |
| 599 | * \sa colorStyle, QGraphsTheme::singleHighlightColor |
| 600 | */ |
| 601 | void QAbstract3DSeries::setSingleHighlightColor(QColor color) |
| 602 | { |
| 603 | Q_D(QAbstract3DSeries); |
| 604 | if (d->m_singleHighlightColor != color) { |
| 605 | d->setSingleHighlightColor(color); |
| 606 | emit singleHighlightColorChanged(color); |
| 607 | } |
| 608 | d->m_themeTracker.singleHighlightColorOverride = true; |
| 609 | } |
| 610 | |
| 611 | QColor QAbstract3DSeries::singleHighlightColor() const |
| 612 | { |
| 613 | Q_D(const QAbstract3DSeries); |
| 614 | return d->m_singleHighlightColor; |
| 615 | } |
| 616 | |
| 617 | /*! |
| 618 | * \property QAbstract3DSeries::singleHighlightGradient |
| 619 | * |
| 620 | * \brief The single item highlight gradient of the series. |
| 621 | * |
| 622 | * \sa colorStyle, QGraphsTheme::singleHighlightGradient |
| 623 | */ |
| 624 | void QAbstract3DSeries::setSingleHighlightGradient(const QLinearGradient &gradient) |
| 625 | { |
| 626 | Q_D(QAbstract3DSeries); |
| 627 | if (d->m_singleHighlightGradient != gradient) { |
| 628 | d->setSingleHighlightGradient(gradient); |
| 629 | emit singleHighlightGradientChanged(gradient); |
| 630 | } |
| 631 | d->m_themeTracker.singleHighlightGradientOverride = true; |
| 632 | } |
| 633 | |
| 634 | QLinearGradient QAbstract3DSeries::singleHighlightGradient() const |
| 635 | { |
| 636 | Q_D(const QAbstract3DSeries); |
| 637 | return d->m_singleHighlightGradient; |
| 638 | } |
| 639 | |
| 640 | /*! |
| 641 | * \property QAbstract3DSeries::multiHighlightColor |
| 642 | * |
| 643 | * \brief The multiple item highlight color of the series. |
| 644 | * |
| 645 | * \sa colorStyle, QGraphsTheme::multiHighlightColor |
| 646 | */ |
| 647 | void QAbstract3DSeries::setMultiHighlightColor(QColor color) |
| 648 | { |
| 649 | Q_D(QAbstract3DSeries); |
| 650 | if (d->m_multiHighlightColor != color) { |
| 651 | d->setMultiHighlightColor(color); |
| 652 | emit multiHighlightColorChanged(color); |
| 653 | } |
| 654 | d->m_themeTracker.multiHighlightColorOverride = true; |
| 655 | } |
| 656 | |
| 657 | QColor QAbstract3DSeries::multiHighlightColor() const |
| 658 | { |
| 659 | Q_D(const QAbstract3DSeries); |
| 660 | return d->m_multiHighlightColor; |
| 661 | } |
| 662 | |
| 663 | /*! |
| 664 | * \property QAbstract3DSeries::multiHighlightGradient |
| 665 | * |
| 666 | * \brief The multiple item highlight gradient of the series. |
| 667 | * |
| 668 | * \sa colorStyle, QGraphsTheme::multiHighlightGradient |
| 669 | */ |
| 670 | void QAbstract3DSeries::setMultiHighlightGradient(const QLinearGradient &gradient) |
| 671 | { |
| 672 | Q_D(QAbstract3DSeries); |
| 673 | if (d->m_multiHighlightGradient != gradient) { |
| 674 | d->setMultiHighlightGradient(gradient); |
| 675 | emit multiHighlightGradientChanged(gradient); |
| 676 | } |
| 677 | d->m_themeTracker.multiHighlightGradientOverride = true; |
| 678 | } |
| 679 | |
| 680 | QLinearGradient QAbstract3DSeries::multiHighlightGradient() const |
| 681 | { |
| 682 | Q_D(const QAbstract3DSeries); |
| 683 | return d->m_multiHighlightGradient; |
| 684 | } |
| 685 | |
| 686 | /*! |
| 687 | * \property QAbstract3DSeries::name |
| 688 | * |
| 689 | * \brief The series name. |
| 690 | * |
| 691 | * The series name can be used in item label format with the tag |
| 692 | * \c{@seriesName}. |
| 693 | * |
| 694 | * \sa itemLabelFormat |
| 695 | */ |
| 696 | void QAbstract3DSeries::setName(const QString &name) |
| 697 | { |
| 698 | Q_D(QAbstract3DSeries); |
| 699 | if (d->m_name != name) { |
| 700 | d->setName(name); |
| 701 | emit nameChanged(name); |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | QString QAbstract3DSeries::name() const |
| 706 | { |
| 707 | Q_D(const QAbstract3DSeries); |
| 708 | return d->m_name; |
| 709 | } |
| 710 | |
| 711 | /*! |
| 712 | * \property QAbstract3DSeries::itemLabel |
| 713 | * |
| 714 | * \brief The formatted item label. |
| 715 | * |
| 716 | * If there is no selected item or the selected item is not |
| 717 | * visible, returns an empty string. |
| 718 | * |
| 719 | * \sa itemLabelFormat |
| 720 | */ |
| 721 | QString QAbstract3DSeries::itemLabel() |
| 722 | { |
| 723 | Q_D(QAbstract3DSeries); |
| 724 | return d->itemLabel(); |
| 725 | } |
| 726 | |
| 727 | /*! |
| 728 | * \property QAbstract3DSeries::itemLabelVisible |
| 729 | * |
| 730 | * \brief The visibility of item labels in the graph. |
| 731 | * |
| 732 | * If \c true, item labels are drawn as floating labels in the graph. Otherwise, |
| 733 | * item labels are not drawn. To show the item label in an external control, |
| 734 | * this property is set to \c false. Defaults to \c true. |
| 735 | * |
| 736 | * \sa itemLabelFormat, itemLabel |
| 737 | */ |
| 738 | void QAbstract3DSeries::setItemLabelVisible(bool visible) |
| 739 | { |
| 740 | Q_D(QAbstract3DSeries); |
| 741 | if (d->m_itemLabelVisible != visible) { |
| 742 | d->setItemLabelVisible(visible); |
| 743 | emit itemLabelVisibleChanged(visible); |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | bool QAbstract3DSeries::isItemLabelVisible() const |
| 748 | { |
| 749 | Q_D(const QAbstract3DSeries); |
| 750 | return d->m_itemLabelVisible; |
| 751 | } |
| 752 | |
| 753 | // QAbstract3DSeriesPrivate |
| 754 | |
| 755 | QAbstract3DSeriesPrivate::QAbstract3DSeriesPrivate(QAbstract3DSeries::SeriesType type) |
| 756 | : m_type(type) |
| 757 | , m_dataProxy(0) |
| 758 | , m_visible(true) |
| 759 | , m_graph(0) |
| 760 | , m_mesh(QAbstract3DSeries::Mesh::Cube) |
| 761 | , m_meshSmooth(false) |
| 762 | , m_colorStyle(QGraphsTheme::ColorStyle::Uniform) |
| 763 | , m_baseColor(Qt::black) |
| 764 | , m_singleHighlightColor(Qt::black) |
| 765 | , m_multiHighlightColor(Qt::black) |
| 766 | , m_itemLabelDirty(true) |
| 767 | , m_itemLabelVisible(true) |
| 768 | {} |
| 769 | |
| 770 | QAbstract3DSeriesPrivate::~QAbstract3DSeriesPrivate() {} |
| 771 | |
| 772 | QAbstractDataProxy *QAbstract3DSeriesPrivate::dataProxy() const |
| 773 | { |
| 774 | return m_dataProxy; |
| 775 | } |
| 776 | |
| 777 | void QAbstract3DSeriesPrivate::setDataProxy(QAbstractDataProxy *proxy) |
| 778 | { |
| 779 | Q_Q(QAbstract3DSeries); |
| 780 | Q_ASSERT(proxy && proxy != m_dataProxy && !proxy->d_func()->series()); |
| 781 | |
| 782 | delete m_dataProxy; |
| 783 | m_dataProxy = proxy; |
| 784 | |
| 785 | proxy->d_func()->setSeries(q); // also sets parent |
| 786 | |
| 787 | if (m_graph) { |
| 788 | connectGraphAndProxy(newGraph: m_graph); |
| 789 | m_graph->markDataDirty(); |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | void QAbstract3DSeriesPrivate::setGraph(QQuickGraphsItem *graph) |
| 794 | { |
| 795 | Q_Q(QAbstract3DSeries); |
| 796 | m_graph = graph; |
| 797 | q->setParent(graph); |
| 798 | connectGraphAndProxy(newGraph: graph); |
| 799 | markItemLabelDirty(); |
| 800 | } |
| 801 | |
| 802 | void QAbstract3DSeriesPrivate::setItemLabelFormat(const QString &format) |
| 803 | { |
| 804 | m_itemLabelFormat = format; |
| 805 | markItemLabelDirty(); |
| 806 | } |
| 807 | |
| 808 | void QAbstract3DSeriesPrivate::setVisible(bool visible) |
| 809 | { |
| 810 | m_visible = visible; |
| 811 | markItemLabelDirty(); |
| 812 | } |
| 813 | |
| 814 | void QAbstract3DSeriesPrivate::setMesh(QAbstract3DSeries::Mesh mesh) |
| 815 | { |
| 816 | m_mesh = mesh; |
| 817 | m_changeTracker.meshChanged = true; |
| 818 | if (m_graph) { |
| 819 | m_graph->markSeriesVisualsDirty(); |
| 820 | |
| 821 | if (m_graph->optimizationHint() == QtGraphs3D::OptimizationHint::Default) |
| 822 | m_graph->markDataDirty(); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | void QAbstract3DSeriesPrivate::setMeshSmooth(bool enable) |
| 827 | { |
| 828 | m_meshSmooth = enable; |
| 829 | m_changeTracker.meshSmoothChanged = true; |
| 830 | if (m_graph) { |
| 831 | m_graph->markSeriesVisualsDirty(); |
| 832 | |
| 833 | if (m_graph->optimizationHint() == QtGraphs3D::OptimizationHint::Default) |
| 834 | m_graph->markDataDirty(); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | void QAbstract3DSeriesPrivate::setMeshRotation(const QQuaternion &rotation) |
| 839 | { |
| 840 | m_meshRotation = rotation; |
| 841 | m_changeTracker.meshRotationChanged = true; |
| 842 | if (m_graph) { |
| 843 | m_graph->markSeriesVisualsDirty(); |
| 844 | |
| 845 | if (m_graph->optimizationHint() == QtGraphs3D::OptimizationHint::Default) |
| 846 | m_graph->markDataDirty(); |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | void QAbstract3DSeriesPrivate::setUserDefinedMesh(const QString &meshFile) |
| 851 | { |
| 852 | m_userDefinedMesh = meshFile; |
| 853 | m_changeTracker.userDefinedMeshChanged = true; |
| 854 | if (m_graph) { |
| 855 | m_graph->markSeriesVisualsDirty(); |
| 856 | |
| 857 | if (m_graph->optimizationHint() == QtGraphs3D::OptimizationHint::Default) |
| 858 | m_graph->markDataDirty(); |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | void QAbstract3DSeriesPrivate::setColorStyle(QGraphsTheme::ColorStyle style) |
| 863 | { |
| 864 | m_colorStyle = style; |
| 865 | m_changeTracker.colorStyleChanged = true; |
| 866 | if (m_graph) |
| 867 | m_graph->markSeriesVisualsDirty(); |
| 868 | } |
| 869 | |
| 870 | void QAbstract3DSeriesPrivate::setBaseColor(QColor color) |
| 871 | { |
| 872 | m_baseColor = color; |
| 873 | m_changeTracker.baseColorChanged = true; |
| 874 | if (m_graph) |
| 875 | m_graph->markSeriesVisualsDirty(); |
| 876 | } |
| 877 | |
| 878 | void QAbstract3DSeriesPrivate::setBaseGradient(const QLinearGradient &gradient) |
| 879 | { |
| 880 | m_baseGradient = gradient; |
| 881 | Utils::verifyGradientCompleteness(gradient&: m_baseGradient); |
| 882 | m_changeTracker.baseGradientChanged = true; |
| 883 | if (m_graph) |
| 884 | m_graph->markSeriesVisualsDirty(); |
| 885 | } |
| 886 | |
| 887 | void QAbstract3DSeriesPrivate::setSingleHighlightColor(QColor color) |
| 888 | { |
| 889 | m_singleHighlightColor = color; |
| 890 | m_changeTracker.singleHighlightColorChanged = true; |
| 891 | if (m_graph) |
| 892 | m_graph->markSeriesVisualsDirty(); |
| 893 | } |
| 894 | |
| 895 | void QAbstract3DSeriesPrivate::setSingleHighlightGradient(const QLinearGradient &gradient) |
| 896 | { |
| 897 | m_singleHighlightGradient = gradient; |
| 898 | Utils::verifyGradientCompleteness(gradient&: m_singleHighlightGradient); |
| 899 | m_changeTracker.singleHighlightGradientChanged = true; |
| 900 | if (m_graph) |
| 901 | m_graph->markSeriesVisualsDirty(); |
| 902 | } |
| 903 | |
| 904 | void QAbstract3DSeriesPrivate::setMultiHighlightColor(QColor color) |
| 905 | { |
| 906 | m_multiHighlightColor = color; |
| 907 | m_changeTracker.multiHighlightColorChanged = true; |
| 908 | if (m_graph) |
| 909 | m_graph->markSeriesVisualsDirty(); |
| 910 | } |
| 911 | |
| 912 | void QAbstract3DSeriesPrivate::setMultiHighlightGradient(const QLinearGradient &gradient) |
| 913 | { |
| 914 | m_multiHighlightGradient = gradient; |
| 915 | Utils::verifyGradientCompleteness(gradient&: m_multiHighlightGradient); |
| 916 | m_changeTracker.multiHighlightGradientChanged = true; |
| 917 | if (m_graph) |
| 918 | m_graph->markSeriesVisualsDirty(); |
| 919 | } |
| 920 | |
| 921 | void QAbstract3DSeriesPrivate::setName(const QString &name) |
| 922 | { |
| 923 | m_name = name; |
| 924 | markItemLabelDirty(); |
| 925 | m_changeTracker.nameChanged = true; |
| 926 | } |
| 927 | |
| 928 | void QAbstract3DSeriesPrivate::resetToTheme(const QGraphsTheme &theme, qsizetype seriesIndex, bool force) |
| 929 | { |
| 930 | Q_Q(QAbstract3DSeries); |
| 931 | qsizetype themeIndex = seriesIndex; |
| 932 | if (force || !m_themeTracker.colorStyleOverride) { |
| 933 | q->setColorStyle(theme.colorStyle()); |
| 934 | m_themeTracker.colorStyleOverride = false; |
| 935 | } |
| 936 | if (theme.seriesColors().size() && (force || !m_themeTracker.baseColorOverride)) { |
| 937 | if (theme.seriesColors().size() <= seriesIndex) |
| 938 | themeIndex = seriesIndex % theme.seriesColors().size(); |
| 939 | q->setBaseColor(theme.seriesColors().at(i: themeIndex)); |
| 940 | m_themeTracker.baseColorOverride = false; |
| 941 | } |
| 942 | if (theme.seriesGradients().size() && (force || !m_themeTracker.baseGradientOverride)) { |
| 943 | if (theme.seriesGradients().size() <= seriesIndex) |
| 944 | themeIndex = seriesIndex % theme.seriesGradients().size(); |
| 945 | q->setBaseGradient(theme.seriesGradients().at(i: themeIndex)); |
| 946 | m_themeTracker.baseGradientOverride = false; |
| 947 | } |
| 948 | if (force || !m_themeTracker.singleHighlightColorOverride) { |
| 949 | q->setSingleHighlightColor(theme.singleHighlightColor()); |
| 950 | m_themeTracker.singleHighlightColorOverride = false; |
| 951 | } |
| 952 | if (force || !m_themeTracker.singleHighlightGradientOverride) { |
| 953 | q->setSingleHighlightGradient(theme.singleHighlightGradient()); |
| 954 | m_themeTracker.singleHighlightGradientOverride = false; |
| 955 | } |
| 956 | if (force || !m_themeTracker.multiHighlightColorOverride) { |
| 957 | q->setMultiHighlightColor(theme.multiHighlightColor()); |
| 958 | m_themeTracker.multiHighlightColorOverride = false; |
| 959 | } |
| 960 | if (force || !m_themeTracker.multiHighlightGradientOverride) { |
| 961 | q->setMultiHighlightGradient(theme.multiHighlightGradient()); |
| 962 | m_themeTracker.multiHighlightGradientOverride = false; |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | QString QAbstract3DSeriesPrivate::itemLabel() |
| 967 | { |
| 968 | Q_Q(QAbstract3DSeries); |
| 969 | if (m_itemLabelDirty) { |
| 970 | QString oldLabel = m_itemLabel; |
| 971 | if (m_graph && m_visible) |
| 972 | createItemLabel(); |
| 973 | else |
| 974 | m_itemLabel = QString(); |
| 975 | m_itemLabelDirty = false; |
| 976 | |
| 977 | if (oldLabel != m_itemLabel) |
| 978 | emit q->itemLabelChanged(label: m_itemLabel); |
| 979 | } |
| 980 | |
| 981 | return m_itemLabel; |
| 982 | } |
| 983 | |
| 984 | void QAbstract3DSeriesPrivate::markItemLabelDirty() |
| 985 | { |
| 986 | m_itemLabelDirty = true; |
| 987 | m_changeTracker.itemLabelChanged = true; |
| 988 | } |
| 989 | |
| 990 | void QAbstract3DSeriesPrivate::setItemLabelVisible(bool visible) |
| 991 | { |
| 992 | m_itemLabelVisible = visible; |
| 993 | markItemLabelDirty(); |
| 994 | m_changeTracker.itemLabelVisibilityChanged = true; |
| 995 | } |
| 996 | |
| 997 | bool QAbstract3DSeriesPrivate::isUsingGradient() |
| 998 | { |
| 999 | return m_colorStyle != QGraphsTheme::ColorStyle::Uniform ? true : false; |
| 1000 | } |
| 1001 | |
| 1002 | QT_END_NAMESPACE |
| 1003 | |