| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the Qt Data Visualization module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 or (at your option) any later version | 
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by | 
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 | 
| 22 | ** included in the packaging of this file. Please review the following | 
| 23 | ** information to ensure the GNU General Public License requirements will | 
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 25 | ** | 
| 26 | ** $QT_END_LICENSE$ | 
| 27 | ** | 
| 28 | ****************************************************************************/ | 
| 29 |  | 
| 30 | #include "declarativescatter_p.h" | 
| 31 | #include <QtCore/QMutexLocker> | 
| 32 |  | 
| 33 | QT_BEGIN_NAMESPACE_DATAVISUALIZATION | 
| 34 |  | 
| 35 | DeclarativeScatter::DeclarativeScatter(QQuickItem *parent) | 
| 36 |     : AbstractDeclarative(parent), | 
| 37 |       m_scatterController(0) | 
| 38 | { | 
| 39 |     setAcceptedMouseButtons(Qt::AllButtons); | 
| 40 |  | 
| 41 |     // Create the shared component on the main GUI thread. | 
| 42 |     m_scatterController = new Scatter3DController(boundingRect().toRect(), new Declarative3DScene); | 
| 43 |     setSharedController(m_scatterController); | 
| 44 |  | 
| 45 |     QObject::connect(sender: m_scatterController, signal: &Scatter3DController::selectedSeriesChanged, | 
| 46 |                      receiver: this, slot: &DeclarativeScatter::selectedSeriesChanged); | 
| 47 | } | 
| 48 |  | 
| 49 | DeclarativeScatter::~DeclarativeScatter() | 
| 50 | { | 
| 51 |     QMutexLocker locker(m_nodeMutex.data()); | 
| 52 |     const QMutexLocker locker2(mutex()); | 
| 53 |     delete m_scatterController; | 
| 54 | } | 
| 55 |  | 
| 56 | QValue3DAxis *DeclarativeScatter::axisX() const | 
| 57 | { | 
| 58 |     return static_cast<QValue3DAxis *>(m_scatterController->axisX()); | 
| 59 | } | 
| 60 |  | 
| 61 | void DeclarativeScatter::setAxisX(QValue3DAxis *axis) | 
| 62 | { | 
| 63 |     m_scatterController->setAxisX(axis); | 
| 64 | } | 
| 65 |  | 
| 66 | QValue3DAxis *DeclarativeScatter::axisY() const | 
| 67 | { | 
| 68 |     return static_cast<QValue3DAxis *>(m_scatterController->axisY()); | 
| 69 | } | 
| 70 |  | 
| 71 | void DeclarativeScatter::setAxisY(QValue3DAxis *axis) | 
| 72 | { | 
| 73 |     m_scatterController->setAxisY(axis); | 
| 74 | } | 
| 75 |  | 
| 76 | QValue3DAxis *DeclarativeScatter::axisZ() const | 
| 77 | { | 
| 78 |     return static_cast<QValue3DAxis *>(m_scatterController->axisZ()); | 
| 79 | } | 
| 80 |  | 
| 81 | void DeclarativeScatter::setAxisZ(QValue3DAxis *axis) | 
| 82 | { | 
| 83 |     m_scatterController->setAxisZ(axis); | 
| 84 | } | 
| 85 |  | 
| 86 | QScatter3DSeries *DeclarativeScatter::selectedSeries() const | 
| 87 | { | 
| 88 |     return m_scatterController->selectedSeries(); | 
| 89 | } | 
| 90 |  | 
| 91 | QQmlListProperty<QScatter3DSeries> DeclarativeScatter::seriesList() | 
| 92 | { | 
| 93 |     return QQmlListProperty<QScatter3DSeries>(this, this, | 
| 94 |                                               &DeclarativeScatter::appendSeriesFunc, | 
| 95 |                                               &DeclarativeScatter::countSeriesFunc, | 
| 96 |                                               &DeclarativeScatter::atSeriesFunc, | 
| 97 |                                               &DeclarativeScatter::clearSeriesFunc); | 
| 98 | } | 
| 99 |  | 
| 100 | void DeclarativeScatter::appendSeriesFunc(QQmlListProperty<QScatter3DSeries> *list, | 
| 101 |                                           QScatter3DSeries *series) | 
| 102 | { | 
| 103 |     reinterpret_cast<DeclarativeScatter *>(list->data)->addSeries(series); | 
| 104 | } | 
| 105 |  | 
| 106 | int DeclarativeScatter::countSeriesFunc(QQmlListProperty<QScatter3DSeries> *list) | 
| 107 | { | 
| 108 |     return reinterpret_cast<DeclarativeScatter *>(list->data)->m_scatterController->scatterSeriesList().size(); | 
| 109 | } | 
| 110 |  | 
| 111 | QScatter3DSeries *DeclarativeScatter::atSeriesFunc(QQmlListProperty<QScatter3DSeries> *list, int index) | 
| 112 | { | 
| 113 |     return reinterpret_cast<DeclarativeScatter *>(list->data)->m_scatterController->scatterSeriesList().at(i: index); | 
| 114 | } | 
| 115 |  | 
| 116 | void DeclarativeScatter::clearSeriesFunc(QQmlListProperty<QScatter3DSeries> *list) | 
| 117 | { | 
| 118 |     DeclarativeScatter *declScatter = reinterpret_cast<DeclarativeScatter *>(list->data); | 
| 119 |     QList<QScatter3DSeries *> realList = declScatter->m_scatterController->scatterSeriesList(); | 
| 120 |     int count = realList.size(); | 
| 121 |     for (int i = 0; i < count; i++) | 
| 122 |         declScatter->removeSeries(series: realList.at(i)); | 
| 123 | } | 
| 124 |  | 
| 125 | void DeclarativeScatter::addSeries(QScatter3DSeries *series) | 
| 126 | { | 
| 127 |     m_scatterController->addSeries(series); | 
| 128 | } | 
| 129 |  | 
| 130 | void DeclarativeScatter::removeSeries(QScatter3DSeries *series) | 
| 131 | { | 
| 132 |     m_scatterController->removeSeries(series); | 
| 133 |     series->setParent(this); // Reparent as removing will leave series parentless | 
| 134 | } | 
| 135 |  | 
| 136 | void DeclarativeScatter::handleAxisXChanged(QAbstract3DAxis *axis) | 
| 137 | { | 
| 138 |     emit axisXChanged(axis: static_cast<QValue3DAxis *>(axis)); | 
| 139 | } | 
| 140 |  | 
| 141 | void DeclarativeScatter::handleAxisYChanged(QAbstract3DAxis *axis) | 
| 142 | { | 
| 143 |     emit axisYChanged(axis: static_cast<QValue3DAxis *>(axis)); | 
| 144 | } | 
| 145 |  | 
| 146 | void DeclarativeScatter::handleAxisZChanged(QAbstract3DAxis *axis) | 
| 147 | { | 
| 148 |     emit axisZChanged(axis: static_cast<QValue3DAxis *>(axis)); | 
| 149 | } | 
| 150 |  | 
| 151 | QT_END_NAMESPACE_DATAVISUALIZATION | 
| 152 |  |