1 | |
---|---|
2 | // Copyright (C) 2023 The Qt Company Ltd. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
4 | |
5 | #include <QtGraphsWidgets/q3dgraphswidgetitem.h> |
6 | #include <private/q3dgraphswidgetitem_p.h> |
7 | #include <private/q3dscene_p.h> |
8 | #include <private/qquickgraphsitem_p.h> |
9 | |
10 | #ifdef Q_OS_DARWIN |
11 | #include <QtQuick3D/qquick3d.h> |
12 | #endif |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | /*! |
17 | * \class Q3DGraphsWidgetItem |
18 | * \inmodule QtGraphsWidgets |
19 | * \ingroup graphs_3D_widgets |
20 | * \brief The Q3DGraphsWidgetItem class provides a window and render loop for |
21 | * graphs. |
22 | * |
23 | * This class subclasses a QWindow and provides render loop for graphs |
24 | * inheriting it. |
25 | * |
26 | * You should not need to use this class directly, but one of its subclasses |
27 | * instead. |
28 | * |
29 | * Anti-aliasing is turned on by default on C++, except in OpenGL ES2 |
30 | * environments, where anti-aliasing is not supported by Qt Graphs. |
31 | * To specify non-default anti-aliasing for a graph, give a custom surface |
32 | * format as a constructor parameter. You can use the convenience function \c |
33 | * qDefaultSurfaceFormat() to create the surface format object. |
34 | * |
35 | * \note Q3DGraphsWidgetItem sets window flag \c Qt::FramelessWindowHint on by |
36 | * default. If you want to display graph windows as standalone windows with |
37 | * regular window frame, clear this flag after constructing the graph. For |
38 | * example: |
39 | * |
40 | * \code |
41 | * Q3DBarsWidgetItem *graphWindow = new Q3DBarsWidgetItem; |
42 | * graphWindow->setFlags(graphWindow->flags() ^ Qt::FramelessWindowHint); |
43 | * \endcode |
44 | * |
45 | * \sa Q3DBarsWidgetItem, Q3DScatterWidgetItem, Q3DSurfaceWidgetItem, {Qt Graphs C++ Classes for 3D} |
46 | */ |
47 | |
48 | /*! |
49 | * \internal |
50 | */ |
51 | Q3DGraphsWidgetItem::Q3DGraphsWidgetItem(Q3DGraphsWidgetItemPrivate &dd, |
52 | QObject *parent, |
53 | const QString &graphType) |
54 | : QObject(dd, parent) |
55 | { |
56 | Q_D(Q3DGraphsWidgetItem); |
57 | d->m_graphType = graphType; |
58 | } |
59 | |
60 | /*! |
61 | * Destroys Q3DGraphsWidgetItem. |
62 | */ |
63 | Q3DGraphsWidgetItem::~Q3DGraphsWidgetItem() |
64 | { |
65 | } |
66 | |
67 | /*! |
68 | * Adds the given \a theme to the graph. The themes added via addTheme are not |
69 | * taken in to use directly. Only the ownership of the theme is given to the |
70 | * graph. The \a theme must not be null or already added to another graph. |
71 | * |
72 | * \sa releaseTheme(), setActiveTheme() |
73 | */ |
74 | void Q3DGraphsWidgetItem::addTheme(QGraphsTheme *theme) |
75 | { |
76 | Q_D(Q3DGraphsWidgetItem); |
77 | d->m_graphsItem->addTheme(theme); |
78 | } |
79 | |
80 | /*! |
81 | * Releases the ownership of the \a theme back to the caller, if it was added to |
82 | * this graph. If the released \a theme is in use, a new default theme will be |
83 | * created and set active. |
84 | * |
85 | * If the default theme is released and added back later, it behaves as any |
86 | * other theme would. |
87 | * |
88 | * \sa addTheme(), setActiveTheme() |
89 | */ |
90 | void Q3DGraphsWidgetItem::releaseTheme(QGraphsTheme *theme) |
91 | { |
92 | Q_D(Q3DGraphsWidgetItem); |
93 | d->m_graphsItem->releaseTheme(theme); |
94 | } |
95 | |
96 | /*! |
97 | * \property Q3DGraphsWidgetItem::activeTheme |
98 | * |
99 | * \brief The active theme of the graph. |
100 | * |
101 | * Sets \a activeTheme as the active theme to be used for the graph. Implicitly |
102 | * calls addTheme() to transfer the ownership of the theme to this graph. |
103 | * |
104 | * If \a activeTheme is null, a temporary default theme is created. This |
105 | * temporary theme is destroyed if any theme is explicitly set later. Properties |
106 | * of the theme can be modified even after setting it, and the modifications |
107 | * take effect immediately. |
108 | */ |
109 | QGraphsTheme *Q3DGraphsWidgetItem::activeTheme() const |
110 | { |
111 | Q_D(const Q3DGraphsWidgetItem); |
112 | return d->m_graphsItem->theme(); |
113 | } |
114 | |
115 | void Q3DGraphsWidgetItem::setActiveTheme(QGraphsTheme *activeTheme) |
116 | { |
117 | Q_D(Q3DGraphsWidgetItem); |
118 | d->m_graphsItem->setTheme(activeTheme); |
119 | emit activeThemeChanged(activeTheme); |
120 | } |
121 | |
122 | /*! |
123 | * Returns the list of all added themes. |
124 | * |
125 | * \sa addTheme() |
126 | */ |
127 | QList<QGraphsTheme *> Q3DGraphsWidgetItem::themes() const |
128 | { |
129 | Q_D(const Q3DGraphsWidgetItem); |
130 | return d->m_graphsItem->themes(); |
131 | } |
132 | |
133 | /*! |
134 | * \property Q3DGraphsWidgetItem::selectionMode |
135 | * |
136 | * \brief Item selection mode. |
137 | * |
138 | * A combination of SelectionFlags. By default, \c Item. |
139 | * Different graph types support different selection modes. |
140 | * |
141 | * \sa QtGraphs3D::SelectionFlags |
142 | */ |
143 | QtGraphs3D::SelectionFlags Q3DGraphsWidgetItem::selectionMode() const |
144 | { |
145 | Q_D(const Q3DGraphsWidgetItem); |
146 | return d->m_graphsItem->selectionMode(); |
147 | } |
148 | |
149 | void Q3DGraphsWidgetItem::setSelectionMode(const QtGraphs3D::SelectionFlags &selectionMode) |
150 | { |
151 | Q_D(Q3DGraphsWidgetItem); |
152 | d->m_graphsItem->setSelectionMode(selectionMode); |
153 | emit selectionModeChanged(selectionMode); |
154 | } |
155 | |
156 | /*! |
157 | * \property Q3DGraphsWidgetItem::shadowQuality |
158 | * |
159 | * \brief The quality of the shadow. |
160 | * |
161 | * One of the ShadowQuality enum values. By default, \c Medium. |
162 | * |
163 | * \note If setting the shadow quality to a certain level fails, the level is |
164 | * lowered until it is successfully set. The \c shadowQualityChanged signal is |
165 | * emitted each time a change is made. |
166 | * |
167 | * \sa QtGraphs3D::ShadowQuality |
168 | */ |
169 | QtGraphs3D::ShadowQuality Q3DGraphsWidgetItem::shadowQuality() const |
170 | { |
171 | Q_D(const Q3DGraphsWidgetItem); |
172 | return d->m_graphsItem->shadowQuality(); |
173 | } |
174 | |
175 | void Q3DGraphsWidgetItem::setShadowQuality(const QtGraphs3D::ShadowQuality &shadowQuality) |
176 | { |
177 | Q_D(Q3DGraphsWidgetItem); |
178 | d->m_graphsItem->setShadowQuality(shadowQuality); |
179 | emit shadowQualityChanged(quality: shadowQuality); |
180 | } |
181 | |
182 | /*! |
183 | * \property Q3DGraphsWidgetItem::scene |
184 | * \readonly |
185 | * |
186 | * \brief The Q3DScene pointer that can be used to manipulate the scene and |
187 | * access the scene elements. |
188 | * |
189 | * This property is read-only. |
190 | */ |
191 | Q3DScene *Q3DGraphsWidgetItem::scene() const |
192 | { |
193 | Q_D(const Q3DGraphsWidgetItem); |
194 | return (Q3DScene *) d->m_graphsItem->scene(); |
195 | } |
196 | |
197 | /*! |
198 | * Clears selection from all attached series. |
199 | */ |
200 | void Q3DGraphsWidgetItem::clearSelection() |
201 | { |
202 | Q_D(Q3DGraphsWidgetItem); |
203 | d->m_graphsItem->clearSelection(); |
204 | } |
205 | |
206 | /*! |
207 | * Returns whether the \a series has already been added to the graph. |
208 | */ |
209 | bool Q3DGraphsWidgetItem::hasSeries(QAbstract3DSeries *series) const |
210 | { |
211 | Q_D(const Q3DGraphsWidgetItem); |
212 | return d->m_graphsItem->hasSeries(series); |
213 | } |
214 | |
215 | /*! |
216 | * Adds a QCustom3DItem \a item to the graph. Graph takes ownership of the added |
217 | * item. |
218 | * |
219 | * Returns the index to the added item if the add operation was successful, -1 |
220 | * if trying to add a null item, and the index of the item if trying to add an |
221 | * already added item. |
222 | * |
223 | * Items are rendered in the order they have been inserted. The rendering order |
224 | * needs to be taken into account when having solid and transparent items. |
225 | * |
226 | * \sa removeCustomItems(), removeCustomItem(), removeCustomItemAt(), |
227 | * customItems() |
228 | */ |
229 | qsizetype Q3DGraphsWidgetItem::addCustomItem(QCustom3DItem *item) |
230 | { |
231 | Q_D(Q3DGraphsWidgetItem); |
232 | return d->m_graphsItem->addCustomItem(item); |
233 | } |
234 | |
235 | /*! |
236 | * Removes all custom items. Deletes the resources allocated to them. |
237 | */ |
238 | void Q3DGraphsWidgetItem::removeCustomItems() |
239 | { |
240 | Q_D(Q3DGraphsWidgetItem); |
241 | d->m_graphsItem->removeCustomItems(); |
242 | } |
243 | |
244 | /*! |
245 | * Removes the custom \a {item}. Deletes the resources allocated to it. |
246 | */ |
247 | void Q3DGraphsWidgetItem::removeCustomItem(QCustom3DItem *item) |
248 | { |
249 | Q_D(Q3DGraphsWidgetItem); |
250 | d->m_graphsItem->removeCustomItem(item); |
251 | } |
252 | |
253 | /*! |
254 | * Removes all custom items at \a {position}. Deletes the resources allocated to |
255 | * them. |
256 | */ |
257 | void Q3DGraphsWidgetItem::removeCustomItemAt(QVector3D position) |
258 | { |
259 | Q_D(Q3DGraphsWidgetItem); |
260 | d->m_graphsItem->removeCustomItemAt(position); |
261 | } |
262 | |
263 | /*! |
264 | * Gets ownership of given \a item back and removes the \a item from the graph. |
265 | * |
266 | * \note If the same item is added back to the graph, the texture or the texture |
267 | * file needs to be re-set. |
268 | * |
269 | * \sa QCustom3DItem::setTextureImage(), QCustom3DItem::setTextureFile() |
270 | */ |
271 | void Q3DGraphsWidgetItem::releaseCustomItem(QCustom3DItem *item) |
272 | { |
273 | Q_D(Q3DGraphsWidgetItem); |
274 | return d->m_graphsItem->releaseCustomItem(item); |
275 | } |
276 | |
277 | /*! |
278 | * Returns the list of all added custom items. |
279 | * \sa addCustomItem() |
280 | */ |
281 | QList<QCustom3DItem *> Q3DGraphsWidgetItem::customItems() const |
282 | { |
283 | // TODO: API missing in QQuickGraphsItem (QTBUG-99844) |
284 | return {}; |
285 | // return m_graphsItem->customItems(); |
286 | } |
287 | |
288 | /*! |
289 | * Can be used to query the index of the selected label after receiving \c |
290 | * selectedElementChanged signal with any label type. Selection is valid until |
291 | * the next \c selectedElementChanged signal. |
292 | * |
293 | * Returns the index of the selected label, or -1. |
294 | * |
295 | * \sa selectedElement |
296 | */ |
297 | int Q3DGraphsWidgetItem::selectedLabelIndex() const |
298 | { |
299 | Q_D(const Q3DGraphsWidgetItem); |
300 | return d->m_graphsItem->selectedLabelIndex(); |
301 | } |
302 | |
303 | /*! |
304 | * Can be used to get the selected axis after receiving \c |
305 | * selectedElementChanged signal with any label type. Selection is valid until |
306 | * the next \c selectedElementChanged signal. |
307 | * |
308 | * Returns the pointer to the selected axis, or null. |
309 | * |
310 | * \sa selectedElement |
311 | */ |
312 | QAbstract3DAxis *Q3DGraphsWidgetItem::selectedAxis() const |
313 | { |
314 | Q_D(const Q3DGraphsWidgetItem); |
315 | return d->m_graphsItem->selectedAxis(); |
316 | } |
317 | |
318 | /*! |
319 | * Can be used to query the index of the selected custom item after receiving \c |
320 | * selectedElementChanged signal with Q3DGraphsWidgetItem::ElementType::CustomItem |
321 | * type. Selection is valid until the next \c selectedElementChanged signal. |
322 | * |
323 | * Returns the index of the selected custom item, or -1. |
324 | * |
325 | * \sa selectedElement |
326 | */ |
327 | qsizetype Q3DGraphsWidgetItem::selectedCustomItemIndex() const |
328 | { |
329 | Q_D(const Q3DGraphsWidgetItem); |
330 | return d->m_graphsItem->selectedCustomItemIndex(); |
331 | } |
332 | |
333 | /*! |
334 | * Can be used to get the selected custom item after receiving \c |
335 | * selectedElementChanged signal with Q3DGraphsWidgetItem::ElementType::CustomItem |
336 | * type. Ownership of the item remains with the graph. Selection is valid until |
337 | * the next \c selectedElementChanged signal. |
338 | * |
339 | * Returns the pointer to the selected custom item, or null. |
340 | * |
341 | * \sa selectedElement |
342 | */ |
343 | QCustom3DItem *Q3DGraphsWidgetItem::selectedCustomItem() const |
344 | { |
345 | Q_D(const Q3DGraphsWidgetItem); |
346 | return d->m_graphsItem->selectedCustomItem(); |
347 | } |
348 | |
349 | /*! |
350 | * \property Q3DGraphsWidgetItem::selectedElement |
351 | * \readonly |
352 | * |
353 | * \brief The element selected in the graph. |
354 | * |
355 | * This property can be used to query the selected element type. The type is |
356 | * valid until a new selection is made in the graph and the |
357 | * \c selectedElementChanged signal is emitted. |
358 | * |
359 | * The signal can be used for example for implementing custom input handlers, as |
360 | * demonstrated in the \l {Graph Gallery} example under \uicontrol {Scatter |
361 | * Graph} tab. |
362 | * |
363 | * \sa selectedLabelIndex(), selectedAxis(), selectedCustomItemIndex(), |
364 | * selectedCustomItem(), Q3DBarsWidgetItem::selectedSeries(), |
365 | * Q3DScatterWidgetItem::selectedSeries(), Q3DSurfaceWidgetItem::selectedSeries(), |
366 | * Q3DScene::setSelectionQueryPosition() |
367 | */ |
368 | QtGraphs3D::ElementType Q3DGraphsWidgetItem::selectedElement() const |
369 | { |
370 | Q_D(const Q3DGraphsWidgetItem); |
371 | return d->m_graphsItem->selectedElement(); |
372 | } |
373 | |
374 | /*! |
375 | * Renders current frame to an image of \a imageSize. |
376 | * Returns a shared pointer to grab result which can be used to access the |
377 | * rendered image when it's ready. Image is rendered with the current |
378 | * antialiasing settings. |
379 | * |
380 | * \note OpenGL ES2 does not support anitialiasing. |
381 | * \sa QQuickItem::grabToImage |
382 | */ |
383 | QSharedPointer<QQuickItemGrabResult> Q3DGraphsWidgetItem::renderToImage(QSize imageSize) const |
384 | { |
385 | QSize renderSize = imageSize; |
386 | |
387 | Q_D(const Q3DGraphsWidgetItem); |
388 | if (renderSize.isEmpty()) |
389 | renderSize = d->m_widget->size(); |
390 | |
391 | return d->m_graphsItem->grabToImage(targetSize: renderSize); |
392 | } |
393 | |
394 | QtGraphs3D::CameraPreset Q3DGraphsWidgetItem::cameraPreset() const |
395 | { |
396 | Q_D(const Q3DGraphsWidgetItem); |
397 | return d->m_graphsItem->cameraPreset(); |
398 | } |
399 | |
400 | void Q3DGraphsWidgetItem::setCameraPreset(QtGraphs3D::CameraPreset preset) |
401 | { |
402 | Q_D(Q3DGraphsWidgetItem); |
403 | d->m_graphsItem->setCameraPreset(preset); |
404 | } |
405 | /*! |
406 | * \property Q3DGraphsWidgetItem::cameraXRotation |
407 | * |
408 | * \brief The X-rotation angle of the camera around the target point in degrees. |
409 | */ |
410 | float Q3DGraphsWidgetItem::cameraXRotation() const |
411 | { |
412 | Q_D(const Q3DGraphsWidgetItem); |
413 | return d->m_graphsItem->cameraXRotation(); |
414 | } |
415 | |
416 | void Q3DGraphsWidgetItem::setCameraXRotation(float rotation) |
417 | { |
418 | Q_D(Q3DGraphsWidgetItem); |
419 | d->m_graphsItem->setCameraXRotation(rotation); |
420 | } |
421 | |
422 | /*! |
423 | * \property Q3DGraphsWidgetItem::cameraYRotation |
424 | * |
425 | * \brief The Y-rotation angle of the camera around the target point in degrees. |
426 | */ |
427 | float Q3DGraphsWidgetItem::cameraYRotation() const |
428 | { |
429 | Q_D(const Q3DGraphsWidgetItem); |
430 | return d->m_graphsItem->cameraYRotation(); |
431 | } |
432 | |
433 | void Q3DGraphsWidgetItem::setCameraYRotation(float rotation) |
434 | { |
435 | Q_D(Q3DGraphsWidgetItem); |
436 | d->m_graphsItem->setCameraYRotation(rotation); |
437 | } |
438 | |
439 | /*! |
440 | * \property Q3DGraphsWidgetItem::minCameraXRotation |
441 | * |
442 | * \brief The minimum X-rotation angle of the camera around the target point in degrees. |
443 | */ |
444 | float Q3DGraphsWidgetItem::minCameraXRotation() const |
445 | { |
446 | Q_D(const Q3DGraphsWidgetItem); |
447 | return d->m_graphsItem->minCameraXRotation(); |
448 | } |
449 | |
450 | void Q3DGraphsWidgetItem::setMinCameraXRotation(float rotation) |
451 | { |
452 | Q_D(Q3DGraphsWidgetItem); |
453 | d->m_graphsItem->setMinCameraXRotation(rotation); |
454 | } |
455 | |
456 | /*! |
457 | * \property Q3DGraphsWidgetItem::maxCameraXRotation |
458 | * |
459 | * \brief The maximum X-rotation angle of the camera around the target point in degrees. |
460 | */ |
461 | float Q3DGraphsWidgetItem::maxCameraXRotation() const |
462 | { |
463 | Q_D(const Q3DGraphsWidgetItem); |
464 | return d->m_graphsItem->maxCameraXRotation(); |
465 | } |
466 | |
467 | void Q3DGraphsWidgetItem::setMaxCameraXRotation(float rotation) |
468 | { |
469 | Q_D(Q3DGraphsWidgetItem); |
470 | d->m_graphsItem->setMaxCameraXRotation(rotation); |
471 | } |
472 | |
473 | /*! |
474 | * \property Q3DGraphsWidgetItem::minCameraYRotation |
475 | * |
476 | * \brief The minimum Y-rotation angle of the camera around the target point in degrees. |
477 | */ |
478 | float Q3DGraphsWidgetItem::minCameraYRotation() const |
479 | { |
480 | Q_D(const Q3DGraphsWidgetItem); |
481 | return d->m_graphsItem->minCameraYRotation(); |
482 | } |
483 | |
484 | void Q3DGraphsWidgetItem::setMinCameraYRotation(float rotation) |
485 | { |
486 | Q_D(Q3DGraphsWidgetItem); |
487 | d->m_graphsItem->setMinCameraYRotation(rotation); |
488 | } |
489 | |
490 | /*! |
491 | * \property Q3DGraphsWidgetItem::maxCameraYRotation |
492 | * |
493 | * \brief The maximum Y-rotation angle of the camera around the target point in degrees. |
494 | */ |
495 | float Q3DGraphsWidgetItem::maxCameraYRotation() const |
496 | { |
497 | Q_D(const Q3DGraphsWidgetItem); |
498 | return d->m_graphsItem->maxCameraYRotation(); |
499 | } |
500 | |
501 | void Q3DGraphsWidgetItem::setMaxCameraYRotation(float rotation) |
502 | { |
503 | Q_D(Q3DGraphsWidgetItem); |
504 | d->m_graphsItem->setMaxCameraYRotation(rotation); |
505 | } |
506 | |
507 | /*! |
508 | * \property Q3DGraphsWidgetItem::zoomAtTargetEnabled |
509 | * |
510 | * \brief Whether zooming should change the camera target so that the zoomed point |
511 | * of the graph stays at the same location after the zoom. |
512 | * |
513 | * Defaults to \c{true}. |
514 | */ |
515 | bool Q3DGraphsWidgetItem::isZoomAtTargetEnabled() const |
516 | { |
517 | Q_D(const Q3DGraphsWidgetItem); |
518 | return d->m_graphsItem->zoomAtTargetEnabled(); |
519 | } |
520 | |
521 | void Q3DGraphsWidgetItem::setZoomAtTargetEnabled(bool enable) |
522 | { |
523 | Q_D(Q3DGraphsWidgetItem); |
524 | d->m_graphsItem->setZoomAtTargetEnabled(enable); |
525 | } |
526 | |
527 | /*! |
528 | * \property Q3DGraphsWidgetItem::zoomEnabled |
529 | * |
530 | * \brief Whether this input handler allows graph zooming. |
531 | * |
532 | * Defaults to \c{true}. |
533 | */ |
534 | bool Q3DGraphsWidgetItem::isZoomEnabled() const |
535 | { |
536 | Q_D(const Q3DGraphsWidgetItem); |
537 | return d->m_graphsItem->zoomEnabled(); |
538 | } |
539 | |
540 | void Q3DGraphsWidgetItem::setZoomEnabled(bool enable) |
541 | { |
542 | Q_D(Q3DGraphsWidgetItem); |
543 | d->m_graphsItem->setZoomEnabled(enable); |
544 | } |
545 | |
546 | /*! |
547 | * \property Q3DGraphsWidgetItem::ambientLightStrength |
548 | * |
549 | * \brief The ambient light strength for the whole graph. |
550 | * |
551 | * This value determines how evenly and brightly the colors are shown throughout |
552 | * the graph regardless of the light position. |
553 | * |
554 | * The value must be between \c 0.0f and \c 1.0f. |
555 | */ |
556 | float Q3DGraphsWidgetItem::ambientLightStrength() const |
557 | { |
558 | Q_D(const Q3DGraphsWidgetItem); |
559 | return d->m_graphsItem->ambientLightStrength(); |
560 | } |
561 | |
562 | void Q3DGraphsWidgetItem::setAmbientLightStrength(float newAmbientLightStrength) |
563 | { |
564 | Q_D(Q3DGraphsWidgetItem); |
565 | d->m_graphsItem->setAmbientLightStrength(newAmbientLightStrength); |
566 | } |
567 | |
568 | /*! |
569 | * \property Q3DGraphsWidgetItem::lightStrength |
570 | * |
571 | * \brief The specular light strength for the whole graph. |
572 | * |
573 | * The value must be between \c 0.0f and \c 10.0f. |
574 | * |
575 | * This value affects the light specified in Q3DScene. |
576 | */ |
577 | float Q3DGraphsWidgetItem::lightStrength() const |
578 | { |
579 | Q_D(const Q3DGraphsWidgetItem); |
580 | return d->m_graphsItem->lightStrength(); |
581 | } |
582 | |
583 | void Q3DGraphsWidgetItem::setLightStrength(float newLightStrength) |
584 | { |
585 | Q_D(Q3DGraphsWidgetItem); |
586 | d->m_graphsItem->setLightStrength(newLightStrength); |
587 | } |
588 | |
589 | /*! |
590 | * \property Q3DGraphsWidgetItem::shadowStrength |
591 | * |
592 | * \brief The shadow strength for the whole graph. |
593 | * |
594 | * The higher the number, the darker the shadows will be. The value must be |
595 | * between \c 0.0 and \c 100.0. |
596 | * |
597 | * This value affects the light specified in Q3DScene. |
598 | */ |
599 | float Q3DGraphsWidgetItem::shadowStrength() const |
600 | { |
601 | Q_D(const Q3DGraphsWidgetItem); |
602 | return d->m_graphsItem->shadowStrength(); |
603 | } |
604 | |
605 | void Q3DGraphsWidgetItem::setShadowStrength(float newShadowStrength) |
606 | { |
607 | Q_D(Q3DGraphsWidgetItem); |
608 | d->m_graphsItem->setShadowStrength(newShadowStrength); |
609 | } |
610 | |
611 | /*! |
612 | * \property Q3DGraphsWidgetItem::lightColor |
613 | * |
614 | * \brief The color for the ambient and specular light. |
615 | * |
616 | * This value affects the light specified in Q3DScene. |
617 | */ |
618 | QColor Q3DGraphsWidgetItem::lightColor() const |
619 | { |
620 | Q_D(const Q3DGraphsWidgetItem); |
621 | return d->m_graphsItem->lightColor(); |
622 | } |
623 | |
624 | void Q3DGraphsWidgetItem::setLightColor(QColor newLightColor) |
625 | { |
626 | Q_D(Q3DGraphsWidgetItem); |
627 | d->m_graphsItem->setLightColor(newLightColor); |
628 | } |
629 | |
630 | /*! |
631 | * \property Q3DGraphsWidgetItem::gridLineType |
632 | * |
633 | * \brief Whether the grid lines type is Q3DGraphsWidgetItem::GridLineType::Shader or |
634 | * Q3DGraphsWidgetItem::GridLineType::Geometry. |
635 | * |
636 | * This value affects all grid lines. |
637 | */ |
638 | QtGraphs3D::GridLineType Q3DGraphsWidgetItem::gridLineType() const |
639 | { |
640 | Q_D(const Q3DGraphsWidgetItem); |
641 | return d->m_graphsItem->gridLineType(); |
642 | } |
643 | |
644 | void Q3DGraphsWidgetItem::setGridLineType(const QtGraphs3D::GridLineType &gridLineType) |
645 | { |
646 | Q_D(Q3DGraphsWidgetItem); |
647 | d->m_graphsItem->setGridLineType(gridLineType); |
648 | } |
649 | |
650 | void Q3DGraphsWidgetItem::setWidget(QQuickWidget *widget) |
651 | { |
652 | Q_D(Q3DGraphsWidgetItem); |
653 | d->m_widget = widget; |
654 | if (d->m_widget != nullptr) { |
655 | d->m_widget->installEventFilter(filterObj: this); |
656 | d->createGraph(); |
657 | } |
658 | } |
659 | |
660 | QQuickWidget *Q3DGraphsWidgetItem::widget() const |
661 | { |
662 | Q_D(const Q3DGraphsWidgetItem); |
663 | return d->m_widget; |
664 | } |
665 | |
666 | /*! |
667 | * \property Q3DGraphsWidgetItem::selectionEnabled |
668 | * |
669 | * \brief Whether this input handler allows selection from the graph. |
670 | * |
671 | * Defaults to \c{true}. |
672 | */ |
673 | bool Q3DGraphsWidgetItem::isSelectionEnabled() const |
674 | { |
675 | Q_D(const Q3DGraphsWidgetItem); |
676 | return d->m_graphsItem->selectionEnabled(); |
677 | } |
678 | |
679 | void Q3DGraphsWidgetItem::setSelectionEnabled(bool enable) |
680 | { |
681 | Q_D(Q3DGraphsWidgetItem); |
682 | d->m_graphsItem->setSelectionEnabled(enable); |
683 | } |
684 | |
685 | /*! |
686 | * \property Q3DGraphsWidgetItem::rotationEnabled |
687 | * |
688 | * \brief Whether this input handler allows graph rotation. |
689 | * |
690 | * Defaults to \c{true}. |
691 | */ |
692 | bool Q3DGraphsWidgetItem::isRotationEnabled() const |
693 | { |
694 | Q_D(const Q3DGraphsWidgetItem); |
695 | return d->m_graphsItem->rotationEnabled(); |
696 | } |
697 | |
698 | void Q3DGraphsWidgetItem::setRotationEnabled(bool enable) |
699 | { |
700 | Q_D(Q3DGraphsWidgetItem); |
701 | d->m_graphsItem->setRotationEnabled(enable); |
702 | } |
703 | |
704 | void Q3DGraphsWidgetItem::setDefaultInputHandler() |
705 | { |
706 | Q_D(Q3DGraphsWidgetItem); |
707 | d->m_graphsItem->setDefaultInputHandler(); |
708 | } |
709 | |
710 | void Q3DGraphsWidgetItem::unsetDefaultInputHandler() |
711 | { |
712 | Q_D(Q3DGraphsWidgetItem); |
713 | d->m_graphsItem->unsetDefaultInputHandler(); |
714 | } |
715 | |
716 | void Q3DGraphsWidgetItem::unsetDefaultTapHandler() |
717 | { |
718 | Q_D(Q3DGraphsWidgetItem); |
719 | d->m_graphsItem->unsetDefaultTapHandler(); |
720 | } |
721 | |
722 | void Q3DGraphsWidgetItem::unsetDefaultDragHandler() |
723 | { |
724 | Q_D(Q3DGraphsWidgetItem); |
725 | d->m_graphsItem->unsetDefaultDragHandler(); |
726 | } |
727 | |
728 | void Q3DGraphsWidgetItem::unsetDefaultWheelHandler() |
729 | { |
730 | Q_D(Q3DGraphsWidgetItem); |
731 | d->m_graphsItem->unsetDefaultWheelHandler(); |
732 | } |
733 | |
734 | void Q3DGraphsWidgetItem::unsetDefaultPinchHandler() |
735 | { |
736 | Q_D(Q3DGraphsWidgetItem); |
737 | d->m_graphsItem->unsetDefaultPinchHandler(); |
738 | } |
739 | |
740 | void Q3DGraphsWidgetItem::setDragButton(Qt::MouseButtons button) |
741 | { |
742 | Q_D(Q3DGraphsWidgetItem); |
743 | d->m_graphsItem->setDragButton(button); |
744 | } |
745 | |
746 | /*! |
747 | * \property Q3DGraphsWidgetItem::cameraZoomLevel |
748 | * |
749 | * \brief The camera zoom level in percentage. |
750 | * |
751 | * The default value of \c{100.0f} means there is no zoom in or out set in the |
752 | * camera. The value is limited by the minCameraZoomLevel and maxCameraZoomLevel |
753 | * properties. |
754 | * |
755 | * \sa minCameraZoomLevel, maxCameraZoomLevel |
756 | */ |
757 | float Q3DGraphsWidgetItem::cameraZoomLevel() const |
758 | { |
759 | Q_D(const Q3DGraphsWidgetItem); |
760 | return d->m_graphsItem->cameraZoomLevel(); |
761 | } |
762 | |
763 | void Q3DGraphsWidgetItem::setCameraZoomLevel(float level) |
764 | { |
765 | Q_D(Q3DGraphsWidgetItem); |
766 | d->m_graphsItem->setCameraZoomLevel(level); |
767 | d->m_graphsItem->update(); |
768 | } |
769 | |
770 | /*! |
771 | * \property Q3DGraphsWidgetItem::minCameraZoomLevel |
772 | * |
773 | * \brief The minimum allowed camera zoom level. |
774 | * |
775 | * If the minimum level is set to a new value that is higher than the existing |
776 | * maximum level, the maximum level is adjusted to the new minimum as well. |
777 | * If the current zoomLevel is outside the new bounds, it is adjusted as well. |
778 | * The minCameraZoomLevel cannot be set below \c{1.0f}. |
779 | * Defaults to \c{10.0f}. |
780 | * |
781 | * \sa cameraZoomLevel, maxCameraZoomLevel |
782 | */ |
783 | float Q3DGraphsWidgetItem::minCameraZoomLevel() const |
784 | { |
785 | Q_D(const Q3DGraphsWidgetItem); |
786 | return d->m_graphsItem->minCameraZoomLevel(); |
787 | } |
788 | |
789 | void Q3DGraphsWidgetItem::setMinCameraZoomLevel(float level) |
790 | { |
791 | Q_D(Q3DGraphsWidgetItem); |
792 | d->m_graphsItem->setMinCameraZoomLevel(level); |
793 | } |
794 | |
795 | /*! |
796 | * \property Q3DGraphsWidgetItem::maxCameraZoomLevel |
797 | * |
798 | * \brief The maximum allowed camera zoom level. |
799 | * |
800 | * If the maximum level is set to a new value that is lower than the existing |
801 | * minimum level, the minimum level is adjusted to the new maximum as well. |
802 | * If the current cameraZoomLevel is outside the new bounds, it is adjusted as |
803 | * well. Defaults to \c{500.0f}. |
804 | * |
805 | * \sa cameraZoomLevel, minCameraZoomLevel |
806 | */ |
807 | float Q3DGraphsWidgetItem::maxCameraZoomLevel() const |
808 | { |
809 | Q_D(const Q3DGraphsWidgetItem); |
810 | return d->m_graphsItem->maxCameraZoomLevel(); |
811 | } |
812 | |
813 | void Q3DGraphsWidgetItem::setMaxCameraZoomLevel(float level) |
814 | { |
815 | Q_D(Q3DGraphsWidgetItem); |
816 | d->m_graphsItem->setMaxCameraZoomLevel(level); |
817 | } |
818 | |
819 | /*! |
820 | * \property Q3DGraphsWidgetItem::cameraTargetPosition |
821 | * |
822 | * \brief The camera target position as a vector or vertex in the 3D space. |
823 | * |
824 | * Defaults to \c {QVector3D(0.0, 0.0, 0.0)}. |
825 | * |
826 | * Valid coordinate values are between \c{-1.0...1.0}, where the edge values |
827 | * indicate the edges of the corresponding axis range. Any values outside this |
828 | * range are clamped to the edge. |
829 | * |
830 | * \note For bar graphs, the Y-coordinate is ignored and camera always targets a |
831 | * point on the horizontal background. |
832 | */ |
833 | QVector3D Q3DGraphsWidgetItem::cameraTargetPosition() const |
834 | { |
835 | Q_D(const Q3DGraphsWidgetItem); |
836 | return d->m_graphsItem->cameraTargetPosition(); |
837 | } |
838 | |
839 | void Q3DGraphsWidgetItem::setCameraTargetPosition(QVector3D target) |
840 | { |
841 | QVector3D newTarget = target; |
842 | |
843 | if (newTarget.x() < -1.0f) |
844 | newTarget.setX(-1.0f); |
845 | else if (newTarget.x() > 1.0f) |
846 | newTarget.setX(1.0f); |
847 | |
848 | if (newTarget.y() < -1.0f) |
849 | newTarget.setY(-1.0f); |
850 | else if (newTarget.y() > 1.0f) |
851 | newTarget.setY(1.0f); |
852 | |
853 | if (newTarget.z() < -1.0f) |
854 | newTarget.setZ(-1.0f); |
855 | else if (newTarget.z() > 1.0f) |
856 | newTarget.setZ(1.0f); |
857 | |
858 | if (Q_D(Q3DGraphsWidgetItem); d->m_graphsItem->cameraTargetPosition() != newTarget) { |
859 | if (d->m_graphsItem->cameraPreset() != QtGraphs3D::CameraPreset::NoPreset) |
860 | d->m_graphsItem->setCameraPreset(QtGraphs3D::CameraPreset::NoPreset); |
861 | d->m_graphsItem->setCameraTargetPosition(newTarget); |
862 | } |
863 | } |
864 | |
865 | /*! |
866 | * \property Q3DGraphsWidgetItem::wrapCameraXRotation |
867 | * |
868 | * \brief The behavior of the minimum and maximum limits in the X-rotation. |
869 | * |
870 | * If set to \c true, the X-rotation of the camera is wrapped from minimum to |
871 | * maximum and from maximum to minimum. If set to \c false, the X-rotation of |
872 | * the camera is limited to the sector determined by the minimum and maximum |
873 | * values. Set to \c true by default. |
874 | */ |
875 | bool Q3DGraphsWidgetItem::wrapCameraXRotation() const |
876 | { |
877 | Q_D(const Q3DGraphsWidgetItem); |
878 | return d->m_graphsItem->wrapCameraXRotation(); |
879 | } |
880 | |
881 | void Q3DGraphsWidgetItem::setWrapCameraXRotation(bool wrap) |
882 | { |
883 | Q_D(Q3DGraphsWidgetItem); |
884 | d->m_graphsItem->setCameraXRotation(wrap); |
885 | } |
886 | |
887 | /*! |
888 | * \property Q3DGraphsWidgetItem::wrapCameraYRotation |
889 | * |
890 | * \brief The behavior of the minimum and maximum limits in the Y-rotation. |
891 | * |
892 | * If \c true, the Y-rotation of the camera is wrapped from minimum to maximum |
893 | * and from maximum to minimum. If \c false, the Y-rotation of the camera is |
894 | * limited to the sector determined by the minimum and maximum values. |
895 | * Set to \c true by default. |
896 | */ |
897 | bool Q3DGraphsWidgetItem::wrapCameraYRotation() const |
898 | { |
899 | Q_D(const Q3DGraphsWidgetItem); |
900 | return d->m_graphsItem->wrapCameraYRotation(); |
901 | } |
902 | |
903 | void Q3DGraphsWidgetItem::setWrapCameraYRotation(bool wrap) |
904 | { |
905 | Q_D(Q3DGraphsWidgetItem); |
906 | d->m_graphsItem->setWrapCameraYRotation(wrap); |
907 | } |
908 | |
909 | /*! |
910 | * Utility function that sets the camera rotations and distance.\a horizontal |
911 | * and \a vertical define the camera rotations to be used. Optional \a zoom |
912 | * parameter can be given to set the zoom percentage of the camera within the |
913 | * bounds defined by minCameraZoomLevel and maxCameraZoomLevel properties. |
914 | */ |
915 | void Q3DGraphsWidgetItem::setCameraPosition(float horizontal, float vertical, float zoom) |
916 | { |
917 | Q_D(Q3DGraphsWidgetItem); |
918 | d->m_graphsItem->setCameraPosition(horizontal, vertical, zoom); |
919 | } |
920 | |
921 | /*! |
922 | * \property Q3DGraphsWidgetItem::msaaSamples |
923 | * |
924 | * \brief The number of used samples in MSAA. |
925 | * |
926 | * Sets the number of used MSAA samples to \a samples. The number of samples can |
927 | * be either 0, 2, 4, or 8. |
928 | * |
929 | */ |
930 | int Q3DGraphsWidgetItem::msaaSamples() const |
931 | { |
932 | Q_D(const Q3DGraphsWidgetItem); |
933 | return d->m_graphsItem->msaaSamples(); |
934 | } |
935 | |
936 | void Q3DGraphsWidgetItem::setMsaaSamples(int samples) |
937 | { |
938 | Q_D(Q3DGraphsWidgetItem); |
939 | d->m_graphsItem->setMsaaSamples(samples); |
940 | } |
941 | |
942 | void Q3DGraphsWidgetItem::doPicking(QPoint point) |
943 | { |
944 | Q_D(Q3DGraphsWidgetItem); |
945 | d->m_graphsItem->doPicking(point); |
946 | } |
947 | |
948 | /*! |
949 | * \property Q3DGraphsWidgetItem::measureFps |
950 | * |
951 | * \brief Whether rendering is done continuously instead of on demand. |
952 | * |
953 | * If \c {true}, rendering is continuous and the value of the currentFps |
954 | * property is updated. Defaults to \c{false}. |
955 | * |
956 | * \sa currentFps |
957 | */ |
958 | void Q3DGraphsWidgetItem::setMeasureFps(bool enable) |
959 | { |
960 | Q_D(Q3DGraphsWidgetItem); |
961 | d->m_graphsItem->setMeasureFps(enable); |
962 | if (enable) { |
963 | QObject::connect(sender: d->m_graphsItem.get(), |
964 | signal: &QQuickGraphsItem::currentFpsChanged, |
965 | context: this, |
966 | slot: &Q3DGraphsWidgetItem::currentFpsChanged); |
967 | } else { |
968 | QObject::disconnect(sender: d->m_graphsItem.get(), |
969 | signal: &QQuickGraphsItem::currentFpsChanged, |
970 | receiver: this, |
971 | slot: &Q3DGraphsWidgetItem::currentFpsChanged); |
972 | } |
973 | } |
974 | |
975 | bool Q3DGraphsWidgetItem::measureFps() const |
976 | { |
977 | Q_D(const Q3DGraphsWidgetItem); |
978 | return d->m_graphsItem->measureFps(); |
979 | } |
980 | |
981 | /*! |
982 | * \property Q3DGraphsWidgetItem::currentFps |
983 | * |
984 | * \brief The rendering results for the last second. |
985 | * |
986 | * The results are stored in this read-only property when FPS measuring is |
987 | * enabled. It takes at least a second before this value is updated after |
988 | * measuring is activated. |
989 | * |
990 | * \sa measureFps |
991 | */ |
992 | int Q3DGraphsWidgetItem::currentFps() const |
993 | { |
994 | Q_D(const Q3DGraphsWidgetItem); |
995 | return d->m_graphsItem->currentFps(); |
996 | } |
997 | |
998 | /*! |
999 | * \property Q3DGraphsWidgetItem::orthoProjection |
1000 | * |
1001 | * \brief Whether orthographic projection is used for displaying the graph. |
1002 | * |
1003 | * Defaults to \c{false}. |
1004 | * \note Shadows will be disabled when set to \c{true}. |
1005 | * |
1006 | * \sa QAbstract3DAxis::labelAutoAngle, |
1007 | */ |
1008 | void Q3DGraphsWidgetItem::setOrthoProjection(bool enable) |
1009 | { |
1010 | Q_D(Q3DGraphsWidgetItem); |
1011 | d->m_graphsItem->setOrthoProjection(enable); |
1012 | } |
1013 | |
1014 | bool Q3DGraphsWidgetItem::isOrthoProjection() const |
1015 | { |
1016 | Q_D(const Q3DGraphsWidgetItem); |
1017 | return d->m_graphsItem->isOrthoProjection(); |
1018 | } |
1019 | |
1020 | /*! |
1021 | * \property Q3DGraphsWidgetItem::aspectRatio |
1022 | * |
1023 | * \brief The ratio of the graph scaling between the longest axis on the |
1024 | * horizontal plane and the y-axis. |
1025 | * |
1026 | * Defaults to \c{2.0}. |
1027 | * |
1028 | * \note Has no effect on Q3DBarsWidgetItem. |
1029 | * |
1030 | * \sa horizontalAspectRatio |
1031 | */ |
1032 | void Q3DGraphsWidgetItem::setAspectRatio(qreal ratio) |
1033 | { |
1034 | Q_D(Q3DGraphsWidgetItem); |
1035 | d->m_graphsItem->setAspectRatio(ratio); |
1036 | } |
1037 | |
1038 | qreal Q3DGraphsWidgetItem::aspectRatio() const |
1039 | { |
1040 | Q_D(const Q3DGraphsWidgetItem); |
1041 | return d->m_graphsItem->aspectRatio(); |
1042 | } |
1043 | |
1044 | /*! |
1045 | * \property Q3DGraphsWidgetItem::optimizationHint |
1046 | * |
1047 | * \brief Specifies whether the default or legacy mode is used for rendering |
1048 | * optimization. |
1049 | * |
1050 | * The default mode uses instanced rendering, and provides the full feature set |
1051 | * at the best level of performance on most systems. The static mode optimizes |
1052 | * graph rendering and is ideal for large non-changing data sets. It is slower |
1053 | * with dynamic data changes and item rotations. Selection is not optimized, so |
1054 | * using the static mode with massive data sets is not advisable. Static |
1055 | * optimization works only on scatter graphs. Legacy mode renders all items in |
1056 | * th graph individually, without instancing. It should be used only if default |
1057 | * mode does not work, i.e. if the target system does not support instancing. |
1058 | * Defaults to \l{QtGraphs3D::OptimizationHint::Default}. |
1059 | * |
1060 | * \note On some environments, large graphs using static optimization may not |
1061 | * render, because all of the items are rendered using a single draw call, and |
1062 | * different graphics drivers support different maximum vertice counts per call. |
1063 | * This is mostly an issue on 32bit and OpenGL ES2 platforms. |
1064 | * To work around this issue, choose an item mesh with a low vertex count or use |
1065 | * the point mesh. |
1066 | * |
1067 | * \sa QAbstract3DSeries::mesh |
1068 | */ |
1069 | void Q3DGraphsWidgetItem::setOptimizationHint(QtGraphs3D::OptimizationHint hint) |
1070 | { |
1071 | Q_D(Q3DGraphsWidgetItem); |
1072 | d->m_graphsItem->setOptimizationHint(hint); |
1073 | } |
1074 | |
1075 | QtGraphs3D::OptimizationHint Q3DGraphsWidgetItem::optimizationHint() const |
1076 | { |
1077 | Q_D(const Q3DGraphsWidgetItem); |
1078 | return d->m_graphsItem->optimizationHint(); |
1079 | } |
1080 | |
1081 | /*! |
1082 | * \property Q3DGraphsWidgetItem::polar |
1083 | * |
1084 | * \brief Whether horizontal axes are changed into polar axes. |
1085 | * |
1086 | * If \c {true}, the x-axis becomes the angular axis and the z-axis becomes the |
1087 | * radial axis. |
1088 | * Polar mode is not available for bar graphs. |
1089 | * |
1090 | * Defaults to \c{false}. |
1091 | * |
1092 | * \sa orthoProjection, radialLabelOffset |
1093 | */ |
1094 | void Q3DGraphsWidgetItem::setPolar(bool enable) |
1095 | { |
1096 | Q_D(Q3DGraphsWidgetItem); |
1097 | d->m_graphsItem->setPolar(enable); |
1098 | } |
1099 | |
1100 | bool Q3DGraphsWidgetItem::isPolar() const |
1101 | { |
1102 | Q_D(const Q3DGraphsWidgetItem); |
1103 | return d->m_graphsItem->isPolar(); |
1104 | } |
1105 | |
1106 | /*! |
1107 | * \property Q3DGraphsWidgetItem::labelMargin |
1108 | * |
1109 | * \brief This property specifies the margin for the placement of the axis labels. |
1110 | * |
1111 | * Negative values place the labels inside the plot-area while positive values |
1112 | * place them outside the plot-area. Label automatic rotation is disabled when |
1113 | * the value is negative. Defaults to \c 0.1 |
1114 | * |
1115 | * \sa QAbstract3DAxis::labelAutoAngle |
1116 | * |
1117 | */ |
1118 | void Q3DGraphsWidgetItem::setLabelMargin(float margin) |
1119 | { |
1120 | Q_D(Q3DGraphsWidgetItem); |
1121 | d->m_graphsItem->setLabelMargin(margin); |
1122 | } |
1123 | |
1124 | float Q3DGraphsWidgetItem::labelMargin() const |
1125 | { |
1126 | Q_D(const Q3DGraphsWidgetItem); |
1127 | return d->m_graphsItem->labelMargin(); |
1128 | } |
1129 | /*! |
1130 | * \property Q3DGraphsWidgetItem::radialLabelOffset |
1131 | * |
1132 | * \brief The normalized horizontal offset for the axis labels of the radial |
1133 | * polar axis. |
1134 | * |
1135 | * The value \c 0.0 indicates that the labels should be drawn next to the |
1136 | * 0-angle angular axis grid line. The value \c 1.0 indicates that the labels |
1137 | * are drawn in their usual place at the edge of the graph background. Defaults |
1138 | * to \c 1.0. |
1139 | * |
1140 | * This property is ignored if the \l polar property value is \c{false}. |
1141 | * |
1142 | * \sa polar |
1143 | */ |
1144 | void Q3DGraphsWidgetItem::setRadialLabelOffset(float offset) |
1145 | { |
1146 | Q_D(Q3DGraphsWidgetItem); |
1147 | d->m_graphsItem->setRadialLabelOffset(offset); |
1148 | } |
1149 | |
1150 | float Q3DGraphsWidgetItem::radialLabelOffset() const |
1151 | { |
1152 | Q_D(const Q3DGraphsWidgetItem); |
1153 | return d->m_graphsItem->radialLabelOffset(); |
1154 | } |
1155 | |
1156 | /*! |
1157 | * \property Q3DGraphsWidgetItem::horizontalAspectRatio |
1158 | * |
1159 | * \brief The ratio of the graph scaling between the x-axis and z-axis. |
1160 | * |
1161 | * The value of \c 0.0 indicates automatic scaling according to axis ranges. |
1162 | * Defaults to \c{0.0}. |
1163 | * |
1164 | * Has no effect on Q3DBarsWidgetItem, which handles scaling on the horizontal plane via |
1165 | * the \l{Q3DBarsWidgetItem::barThickness}{barThickness} and |
1166 | * \l{Q3DBarsWidgetItem::barSpacing}{barSpacing} properties. Polar graphs also ignore this |
1167 | * property. |
1168 | * |
1169 | * \sa aspectRatio, polar, Q3DBarsWidgetItem::barThickness, Q3DBarsWidgetItem::barSpacing |
1170 | */ |
1171 | void Q3DGraphsWidgetItem::setHorizontalAspectRatio(qreal ratio) |
1172 | { |
1173 | Q_D(Q3DGraphsWidgetItem); |
1174 | d->m_graphsItem->setHorizontalAspectRatio(ratio); |
1175 | } |
1176 | |
1177 | qreal Q3DGraphsWidgetItem::horizontalAspectRatio() const |
1178 | { |
1179 | Q_D(const Q3DGraphsWidgetItem); |
1180 | return d->m_graphsItem->horizontalAspectRatio(); |
1181 | } |
1182 | |
1183 | /*! |
1184 | * \property Q3DGraphsWidgetItem::locale |
1185 | * |
1186 | * \brief The locale used for formatting various numeric labels. |
1187 | * |
1188 | * Defaults to the \c{"C"} locale. |
1189 | * |
1190 | * \sa QValue3DAxis::labelFormat |
1191 | */ |
1192 | void Q3DGraphsWidgetItem::setLocale(const QLocale &locale) |
1193 | { |
1194 | Q_D(Q3DGraphsWidgetItem); |
1195 | d->m_graphsItem->setLocale(locale); |
1196 | } |
1197 | |
1198 | QLocale Q3DGraphsWidgetItem::locale() const |
1199 | { |
1200 | Q_D(const Q3DGraphsWidgetItem); |
1201 | return d->m_graphsItem->locale(); |
1202 | } |
1203 | |
1204 | /*! |
1205 | * \property Q3DGraphsWidgetItem::queriedGraphPosition |
1206 | * \readonly |
1207 | * |
1208 | * \brief The latest queried graph position values along each axis. |
1209 | * |
1210 | * This read-only property contains the results from |
1211 | * Q3DScene::graphPositionQuery. The values are normalized to the range \c{[-1, |
1212 | * 1]}. If the queried position was outside the graph bounds, the values will |
1213 | * not reflect the real position, but will instead indicate an undefined |
1214 | * position outside the range \c{[-1, 1]}. The value will be undefined until a |
1215 | * query is made. |
1216 | * |
1217 | * There is no single correct 3D coordinate to match a particular screen |
1218 | * position, so to be consistent, the queries are always done against the inner |
1219 | * sides of an invisible box surrounding the graph. |
1220 | * |
1221 | * \note Bar graphs only allow querying graph position at the graph floor level, |
1222 | * so the y-value is always zero for bar graphs and the valid queries can be |
1223 | * only made at screen positions that contain the floor of the graph. |
1224 | * |
1225 | * \sa Q3DScene::graphPositionQuery |
1226 | */ |
1227 | QVector3D Q3DGraphsWidgetItem::queriedGraphPosition() const |
1228 | { |
1229 | Q_D(const Q3DGraphsWidgetItem); |
1230 | return d->m_graphsItem->queriedGraphPosition(); |
1231 | } |
1232 | |
1233 | /*! |
1234 | * \property Q3DGraphsWidgetItem::margin |
1235 | * |
1236 | * \brief The absolute value used for the space left between the edge of the |
1237 | * plottable graph area and the edge of the graph background. |
1238 | * |
1239 | * If the margin value is negative, the margins are determined automatically and |
1240 | * can vary according to the size of the items in the series and the type of the |
1241 | * graph. The value is interpreted as a fraction of the y-axis range if the |
1242 | * graph aspect ratios have not been changed from the default values. Defaults |
1243 | * to \c{-1.0}. |
1244 | * |
1245 | * \note Setting a smaller margin for a scatter graph than the automatically |
1246 | * determined margin can cause the scatter items at the edges of the graph to |
1247 | * overlap with the graph background. |
1248 | * |
1249 | * \note On scatter and surface graphs, if the margin is small in comparison to |
1250 | * the axis label size, the positions of the edge labels of the axes are |
1251 | * adjusted to avoid overlap with the edge labels of the neighboring axes. |
1252 | */ |
1253 | void Q3DGraphsWidgetItem::setMargin(qreal margin) |
1254 | { |
1255 | Q_D(Q3DGraphsWidgetItem); |
1256 | d->m_graphsItem->setMargin(margin); |
1257 | } |
1258 | |
1259 | qreal Q3DGraphsWidgetItem::margin() const |
1260 | { |
1261 | Q_D(const Q3DGraphsWidgetItem); |
1262 | return d->m_graphsItem->margin(); |
1263 | } |
1264 | |
1265 | /*! |
1266 | * \internal |
1267 | */ |
1268 | bool Q3DGraphsWidgetItem::event(QEvent *event) |
1269 | { |
1270 | switch (event->type()) { |
1271 | case QEvent::TouchBegin: |
1272 | case QEvent::TouchCancel: |
1273 | case QEvent::TouchUpdate: |
1274 | case QEvent::TouchEnd: { |
1275 | Q_D(Q3DGraphsWidgetItem); |
1276 | d->m_graphsItem->touchEvent(event: static_cast<QTouchEvent *>(event)); |
1277 | } |
1278 | return true; |
1279 | default: |
1280 | return QObject::event(event); |
1281 | } |
1282 | } |
1283 | |
1284 | bool Q3DGraphsWidgetItem::eventFilter(QObject *obj, QEvent *event) |
1285 | { |
1286 | if (event->type() == QEvent::Resize) { |
1287 | Q_D(Q3DGraphsWidgetItem); |
1288 | auto ev = static_cast<QResizeEvent *>(event); |
1289 | if (d->m_graphsItem) { |
1290 | Q3DScene *scene = (Q3DScene *) d->m_graphsItem->scene(); |
1291 | scene->d_func()->setWindowSize(QSize(ev->size().width(), ev->size().height())); |
1292 | d->m_graphsItem->resizeViewports(viewportSize: ev->size()); |
1293 | if (d->m_graphsItem->sliceView() && d->m_graphsItem->sliceView()->isVisible()) |
1294 | d->m_graphsItem->minimizeMainGraph(); |
1295 | d->m_graphsItem->updateSubViews(); |
1296 | } |
1297 | return false; |
1298 | } |
1299 | return QObject::eventFilter(watched: obj, event); |
1300 | } |
1301 | |
1302 | /*! |
1303 | * \internal |
1304 | */ |
1305 | |
1306 | void Q3DGraphsWidgetItemPrivate::onWheel(QQuickWheelEvent *event) |
1307 | { |
1308 | Q_Q(Q3DGraphsWidgetItem); |
1309 | |
1310 | QWheelEvent *ev = new QWheelEvent(QPointF(event->x(), event->y()), |
1311 | QPointF(event->x(), event->y()), |
1312 | event->pixelDelta(), |
1313 | event->angleDelta(), |
1314 | static_cast<Qt::MouseButton>(event->buttons()), |
1315 | static_cast<Qt::KeyboardModifier>(event->modifiers()), |
1316 | event->phase(), |
1317 | event->inverted(), |
1318 | Qt::MouseEventSynthesizedBySystem, |
1319 | event->pointingDevice()); |
1320 | emit q->wheel(event: ev); |
1321 | } |
1322 | |
1323 | void Q3DGraphsWidgetItemPrivate::createGraph() |
1324 | { |
1325 | Q_Q(Q3DGraphsWidgetItem); |
1326 | if (m_widget == nullptr) |
1327 | return; |
1328 | m_widget->setResizeMode(QQuickWidget::SizeRootObjectToView); |
1329 | |
1330 | #ifdef Q_OS_DARWIN |
1331 | // Take care of widget users (or CI) wanting to use OpenGL backend on macOS |
1332 | if (QQuickWindow::graphicsApi() == QSGRendererInterface::OpenGL) |
1333 | QSurfaceFormat::setDefaultFormat(QQuick3D::idealSurfaceFormat(4)); |
1334 | #endif |
1335 | |
1336 | const QString qmlData = QLatin1StringView(R"QML( |
1337 | import QtQuick; |
1338 | import QtGraphs; |
1339 | |
1340 | %1 |
1341 | { |
1342 | anchors.fill: parent; |
1343 | } |
1344 | )QML") |
1345 | .arg(args&: m_graphType); |
1346 | QQmlComponent *component = new QQmlComponent(m_widget->engine(), q); |
1347 | component->setData(qmlData.toUtf8(), baseUrl: QUrl()); |
1348 | m_graphsItem.reset(p: qobject_cast<QQuickGraphsItem *>(object: component->create())); |
1349 | m_widget->setContent(url: component->url(), component, item: m_graphsItem.get()); |
1350 | |
1351 | QObject::connect(sender: m_graphsItem.get(), |
1352 | signal: &QQuickGraphsItem::selectedElementChanged, |
1353 | context: q, |
1354 | slot: &Q3DGraphsWidgetItem::selectedElementChanged); |
1355 | QObject::connect(sender: m_graphsItem.get(), |
1356 | signal: &QQuickGraphsItem::msaaSamplesChanged, |
1357 | context: q, |
1358 | slot: &Q3DGraphsWidgetItem::msaaSamplesChanged); |
1359 | |
1360 | QObject::connect(sender: m_graphsItem.get(), |
1361 | signal: &QQuickGraphsItem::tapped, |
1362 | context: q, |
1363 | slot: &Q3DGraphsWidgetItem::tapped); |
1364 | QObject::connect(sender: m_graphsItem.get(), |
1365 | signal: &QQuickGraphsItem::doubleTapped, |
1366 | context: q, |
1367 | slot: &Q3DGraphsWidgetItem::doubleTapped); |
1368 | QObject::connect(sender: m_graphsItem.get(), |
1369 | signal: &QQuickGraphsItem::longPressed, |
1370 | context: q, |
1371 | slot: &Q3DGraphsWidgetItem::longPressed); |
1372 | QObject::connect(sender: m_graphsItem.get(), |
1373 | signal: &QQuickGraphsItem::dragged, |
1374 | context: q, |
1375 | slot: &Q3DGraphsWidgetItem::dragged); |
1376 | QObjectPrivate::connect(sender: m_graphsItem.get(), |
1377 | signal: &QQuickGraphsItem::wheel, |
1378 | receiverPrivate: this, |
1379 | slot: &Q3DGraphsWidgetItemPrivate::onWheel); |
1380 | QObject::connect(sender: m_graphsItem.get(), |
1381 | signal: &QQuickGraphsItem::pinch, |
1382 | context: q, |
1383 | slot: &Q3DGraphsWidgetItem::pinch); |
1384 | QObject::connect(sender: m_graphsItem.get(), |
1385 | signal: &QQuickGraphsItem::mouseMove, |
1386 | context: q, |
1387 | slot: &Q3DGraphsWidgetItem::mouseMove); |
1388 | |
1389 | QObject::connect(sender: m_graphsItem.get(), |
1390 | signal: &QQuickGraphsItem::zoomEnabledChanged, |
1391 | context: q, |
1392 | slot: &Q3DGraphsWidgetItem::zoomEnabledChanged); |
1393 | QObject::connect(sender: m_graphsItem.get(), |
1394 | signal: &QQuickGraphsItem::zoomAtTargetEnabledChanged, |
1395 | context: q, |
1396 | slot: &Q3DGraphsWidgetItem::zoomAtTargetEnabledChanged); |
1397 | QObject::connect(sender: m_graphsItem.get(), |
1398 | signal: &QQuickGraphsItem::rotationEnabledChanged, |
1399 | context: q, |
1400 | slot: &Q3DGraphsWidgetItem::rotationEnabledChanged); |
1401 | QObject::connect(sender: m_graphsItem.get(), |
1402 | signal: &QQuickGraphsItem::selectionEnabledChanged, |
1403 | context: q, |
1404 | slot: &Q3DGraphsWidgetItem::selectionEnabledChanged); |
1405 | QObject::connect(sender: m_graphsItem.get(), |
1406 | signal: &QQuickGraphsItem::queriedGraphPositionChanged, |
1407 | context: q, |
1408 | slot: &Q3DGraphsWidgetItem::queriedGraphPositionChanged); |
1409 | |
1410 | QObject::connect(sender: m_graphsItem.get(), |
1411 | signal: &QQuickGraphsItem::ambientLightStrengthChanged, |
1412 | context: q, |
1413 | slot: &Q3DGraphsWidgetItem::ambientLightStrengthChanged); |
1414 | QObject::connect(sender: m_graphsItem.get(), |
1415 | signal: &QQuickGraphsItem::lightStrengthChanged, |
1416 | context: q, |
1417 | slot: &Q3DGraphsWidgetItem::lightStrengthChanged); |
1418 | QObject::connect(sender: m_graphsItem.get(), |
1419 | signal: &QQuickGraphsItem::shadowStrengthChanged, |
1420 | context: q, |
1421 | slot: &Q3DGraphsWidgetItem::shadowStrengthChanged); |
1422 | QObject::connect(sender: m_graphsItem.get(), |
1423 | signal: &QQuickGraphsItem::lightColorChanged, |
1424 | context: q, |
1425 | slot: &Q3DGraphsWidgetItem::lightColorChanged); |
1426 | QObject::connect(sender: m_graphsItem.get(), |
1427 | signal: &QQuickGraphsItem::gridLineTypeChanged, |
1428 | context: q, |
1429 | slot: &Q3DGraphsWidgetItem::gridLineTypeChanged); |
1430 | m_widget->installEventFilter(filterObj: q); |
1431 | } |
1432 | |
1433 | QT_END_NAMESPACE |
1434 |
Definitions
- Q3DGraphsWidgetItem
- ~Q3DGraphsWidgetItem
- addTheme
- releaseTheme
- activeTheme
- setActiveTheme
- themes
- selectionMode
- setSelectionMode
- shadowQuality
- setShadowQuality
- scene
- clearSelection
- hasSeries
- addCustomItem
- removeCustomItems
- removeCustomItem
- removeCustomItemAt
- releaseCustomItem
- customItems
- selectedLabelIndex
- selectedAxis
- selectedCustomItemIndex
- selectedCustomItem
- selectedElement
- renderToImage
- cameraPreset
- setCameraPreset
- cameraXRotation
- setCameraXRotation
- cameraYRotation
- setCameraYRotation
- minCameraXRotation
- setMinCameraXRotation
- maxCameraXRotation
- setMaxCameraXRotation
- minCameraYRotation
- setMinCameraYRotation
- maxCameraYRotation
- setMaxCameraYRotation
- isZoomAtTargetEnabled
- setZoomAtTargetEnabled
- isZoomEnabled
- setZoomEnabled
- ambientLightStrength
- setAmbientLightStrength
- lightStrength
- setLightStrength
- shadowStrength
- setShadowStrength
- lightColor
- setLightColor
- gridLineType
- setGridLineType
- setWidget
- widget
- isSelectionEnabled
- setSelectionEnabled
- isRotationEnabled
- setRotationEnabled
- setDefaultInputHandler
- unsetDefaultInputHandler
- unsetDefaultTapHandler
- unsetDefaultDragHandler
- unsetDefaultWheelHandler
- unsetDefaultPinchHandler
- setDragButton
- cameraZoomLevel
- setCameraZoomLevel
- minCameraZoomLevel
- setMinCameraZoomLevel
- maxCameraZoomLevel
- setMaxCameraZoomLevel
- cameraTargetPosition
- setCameraTargetPosition
- wrapCameraXRotation
- setWrapCameraXRotation
- wrapCameraYRotation
- setWrapCameraYRotation
- setCameraPosition
- msaaSamples
- setMsaaSamples
- doPicking
- setMeasureFps
- measureFps
- currentFps
- setOrthoProjection
- isOrthoProjection
- setAspectRatio
- aspectRatio
- setOptimizationHint
- optimizationHint
- setPolar
- isPolar
- setLabelMargin
- labelMargin
- setRadialLabelOffset
- radialLabelOffset
- setHorizontalAspectRatio
- horizontalAspectRatio
- setLocale
- locale
- queriedGraphPosition
- setMargin
- margin
- event
- eventFilter
- onWheel
Learn to use CMake with our Intro Training
Find out more