diff options
author | Janne Kangas <janne.kangas@qt.io> | 2019-05-24 12:16:36 +0300 |
---|---|---|
committer | Janne Kangas <janne.kangas@qt.io> | 2019-05-24 13:19:15 +0300 |
commit | 0829b1848d5b162cfc2f2508d5d798241112de99 (patch) | |
tree | c5f65533b7d61239a3c9560b74e158fd116dc21e /src/Runtime/api | |
parent | 08f021f7fa01ab0a458c939ee2af110e410a841a (diff) |
Expose datainput min and max attributes on QML side
For QML, min and max values are initialized at presentation load. Similarly
to datainput "value" attribute, change signals are only generated for
changes made in this QML context. Changes in other QML contexts, or changes
via C++ API are not signaled due to asynchronous separation of QML and
runtime renderer.
Change-Id: I71af0fb8a4231aa02bd62d1903b7d3ec938f9010
Task-id: QT3DS-3530
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src/Runtime/api')
-rw-r--r-- | src/Runtime/api/studio3d/q3dsdatainput.cpp | 15 | ||||
-rw-r--r-- | src/Runtime/api/studio3d/q3dsdatainput.h | 5 | ||||
-rw-r--r-- | src/Runtime/api/studio3d/q3dsdatainput_p.h | 6 | ||||
-rw-r--r-- | src/Runtime/api/studio3d/q3dspresentation.cpp | 46 | ||||
-rw-r--r-- | src/Runtime/api/studio3dqml/q3dsrenderer.cpp | 2 |
5 files changed, 56 insertions, 18 deletions
diff --git a/src/Runtime/api/studio3d/q3dsdatainput.cpp b/src/Runtime/api/studio3d/q3dsdatainput.cpp index 3048613e..b084ee4d 100644 --- a/src/Runtime/api/studio3d/q3dsdatainput.cpp +++ b/src/Runtime/api/studio3d/q3dsdatainput.cpp @@ -94,11 +94,9 @@ QVariant Q3DSDataInput::value() const return d_ptr->m_value; } -// TODO: Min and Max are not currently exposed to QML, as implementation requires -// cumbersome traversal over command queue from QML viewer to renderer. float Q3DSDataInput::min() const { - if (d_ptr->m_presentation) + if (!d_ptr->m_presentation) return 0.0f; return d_ptr->m_presentation->d_ptr->dataInputMin(d_ptr->m_name); @@ -106,7 +104,7 @@ float Q3DSDataInput::min() const float Q3DSDataInput::max() const { - if (d_ptr->m_presentation) + if (!d_ptr->m_presentation) return 0.0f; return d_ptr->m_presentation->d_ptr->dataInputMax(d_ptr->m_name); @@ -122,13 +120,21 @@ bool Q3DSDataInput::isValid() const void Q3DSDataInput::setMin(float min) { + if (!d_ptr->m_presentation) + return; + d_ptr->m_presentation->setDataInputValue(d_ptr->m_name, min, ValueRole::Min); + d_ptr->m_min = min; emit minChanged(); } void Q3DSDataInput::setMax(float max) { + if (!d_ptr->m_presentation) + return; + d_ptr->m_presentation->setDataInputValue(d_ptr->m_name, max, ValueRole::Max); + d_ptr->m_max = max; emit maxChanged(); } @@ -139,6 +145,7 @@ void Q3DSDataInput::setValue(const QVariant &value) // same one it was previously and still consider it a change. // For example, when controlling timeline, the value set to DataInput will only be // the current value for one frame if presentation has a running animation. + // In order to track an element property, see DataOutput API. d_ptr->setValue(value, ValueRole::Value); Q_EMIT valueChanged(); } diff --git a/src/Runtime/api/studio3d/q3dsdatainput.h b/src/Runtime/api/studio3d/q3dsdatainput.h index fc5933fa..d57b5f18 100644 --- a/src/Runtime/api/studio3d/q3dsdatainput.h +++ b/src/Runtime/api/studio3d/q3dsdatainput.h @@ -46,9 +46,8 @@ class Q_STUDIO3D_EXPORT Q3DSDataInput : public QObject Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) - // TODO: QML-side getter/setter for min and max - // Q_PROPERTY(float max READ max WRITE setMax NOTIFY maxChanged) - // Q_PROPERTY(float min READ min WRITE setMin NOTIFY minChanged) + Q_PROPERTY(float max READ max WRITE setMax NOTIFY maxChanged) + Q_PROPERTY(float min READ min WRITE setMin NOTIFY minChanged) public: explicit Q3DSDataInput(QObject *parent = nullptr); explicit Q3DSDataInput(const QString &name, QObject *parent = nullptr); diff --git a/src/Runtime/api/studio3d/q3dsdatainput_p.h b/src/Runtime/api/studio3d/q3dsdatainput_p.h index 855406cd..8f5be06f 100644 --- a/src/Runtime/api/studio3d/q3dsdatainput_p.h +++ b/src/Runtime/api/studio3d/q3dsdatainput_p.h @@ -68,7 +68,13 @@ protected: CommandQueue *m_commandQueue = nullptr; // Not owned Q3DSPresentation *m_presentation = nullptr; // Not owned QString m_name; + // Local cached values, used only when synchronous getter from runtime engine + // is not available (for QML -side that is behind command queue). QVariant m_value; + float m_max = 0; + float m_min = 0; + + friend class Q3DSPresentationPrivate; }; QT_END_NAMESPACE diff --git a/src/Runtime/api/studio3d/q3dspresentation.cpp b/src/Runtime/api/studio3d/q3dspresentation.cpp index 9d2247df..8370dbb6 100644 --- a/src/Runtime/api/studio3d/q3dspresentation.cpp +++ b/src/Runtime/api/studio3d/q3dspresentation.cpp @@ -585,6 +585,8 @@ void Q3DSPresentationPrivate::setViewerApp(Q3DSViewer::Q3DSViewerApp *app, bool const auto dataInputs = m_viewerApp->dataInputs(); for (const auto &name : dataInputs) { if (!m_dataInputs.contains(name)) { + // Name is sufficient for C++ side APIs, as other parameters + // (max/min) are queried synchronously. auto *di = new Q3DSDataInput(name, nullptr); registerDataInput(di); } @@ -669,8 +671,16 @@ void Q3DSPresentationPrivate::requestResponseHandler(CommandType commandType, vo for (int i = 0; i < response->size(); ++i) { // Check and append to QML-side list if the (UIA) presentation has additional datainputs // that are not explicitly defined in QML code. - if (!m_dataInputs.contains(response->at(i).value<QString>())) - registerDataInput(new Q3DSDataInput(response->at(i).value<QString>(), nullptr)); + auto receivedDI = response->at(i).value<Q3DSDataInput *>(); + if (!m_dataInputs.contains(receivedDI->name())) { + // For QML behind async command queue, we cache min/max values in addition + // to name, in order to be able to return values initially set in UIA file (in QML + // setter/getters). + auto newDI = new Q3DSDataInput(receivedDI->name(), nullptr); + newDI->d_ptr->m_min = receivedDI->d_ptr->m_min; + newDI->d_ptr->m_max = receivedDI->d_ptr->m_max; + registerDataInput(newDI); + } } delete response; Q_EMIT q_ptr->dataInputsReady(); @@ -798,25 +808,41 @@ void Q3DSPresentationPrivate::unregisterAllDataInputs() } bool Q3DSPresentationPrivate::isValidDataInput(const Q3DSDataInput *dataInput) const { - if (!m_viewerApp) - return false; + // For QML instance separated from runtime engine by command queue, + // check locally cached list for this datainput (initialised at presentation load). + if (!m_viewerApp) { + if (m_dataInputs.contains(dataInput->name())) + return true; + else + return false; + } return m_viewerApp->dataInputs().contains(dataInput->name()); } float Q3DSPresentationPrivate::dataInputMin(const QString &name) const { - if (!m_viewerApp) - return 0.0f; - + // For QML instance separated from runtime engine by command queue, + // return locally cached value (initialised at presentation load). + if (!m_viewerApp) { + if (m_dataInputs.contains(name)) + return m_dataInputs[name]->d_ptr->m_min; + else + return 0.0f; + } return m_viewerApp->dataInputMin(name); } float Q3DSPresentationPrivate::dataInputMax(const QString &name) const { - if (!m_viewerApp) - return 0.0f; - + // For QML instance separated from runtime engine by command queue, + // return locally cached value (initialised at presentation load). + if (!m_viewerApp) { + if (m_dataInputs.contains(name)) + return m_dataInputs[name]->d_ptr->m_max; + else + return 0.0f; + } return m_viewerApp->dataInputMax(name); } diff --git a/src/Runtime/api/studio3dqml/q3dsrenderer.cpp b/src/Runtime/api/studio3dqml/q3dsrenderer.cpp index 0452bf14..d4be1769 100644 --- a/src/Runtime/api/studio3dqml/q3dsrenderer.cpp +++ b/src/Runtime/api/studio3dqml/q3dsrenderer.cpp @@ -417,7 +417,7 @@ void Q3DSRenderer::processCommands() const auto diList = m_presentation->dataInputs(); for (const auto &it : diList) - requestData->append(QVariant::fromValue(it->name())); + requestData->append(QVariant::fromValue(it)); } Q_EMIT requestResponse(cmd.m_elementPath, cmd.m_commandType, requestData); |