Merge remote-tracking branch 'origin/5.0' into 6.0

Change-Id: Ibcf3ada2824dbbaae8aed0903af61bc95c1c7ce7
This commit is contained in:
Eike Ziller
2021-10-20 12:19:31 +02:00
22 changed files with 61 additions and 1 deletions
@@ -267,6 +267,31 @@ void GeneralHelper::delayedPropertySet(QObject *obj, int delay, const QString &p
});
}
// Returns the first valid QQuick3DPickResult from view at (posX, PosY).
QQuick3DPickResult GeneralHelper::pickViewAt(QQuick3DViewport *view, float posX, float posY)
{
if (!view)
return QQuick3DPickResult();
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 1)
// Make sure global picking is on
view->setGlobalPickingEnabled(true);
// With Qt 6.2+, select first suitable result from all picked objects
auto pickResults = view->pickAll(posX, posY);
for (auto pickResult : pickResults) {
if (isPickable(pickResult.objectHit()))
return pickResult;
}
#else
// With older Qt version we'll just pick the single object
auto pickResult = view->pick(posX, posY);
if (isPickable(pickResult.objectHit()))
return pickResult;
#endif
return QQuick3DPickResult();
}
QQuick3DNode *GeneralHelper::resolvePick(QQuick3DNode *pickNode)
{
if (pickNode) {
@@ -315,6 +340,10 @@ bool GeneralHelper::isHidden(QQuick3DNode *node)
return false;
}
bool GeneralHelper::isPickable(QQuick3DNode *node) {
return (node && !isLocked(node) && !isHidden(node) && node->visible());
}
void GeneralHelper::storeToolState(const QString &sceneId, const QString &tool, const QVariant &state,
int delay)
{
@@ -35,6 +35,7 @@
#include <QTimer>
#include <QVariant>
#include <QVector3D>
#include <QtQuick3D/private/qquick3dpickresult_p.h>
QT_BEGIN_NAMESPACE
class QQuick3DCamera;
@@ -74,12 +75,14 @@ public:
Q_INVOKABLE bool fuzzyCompare(double a, double b);
Q_INVOKABLE void delayedPropertySet(QObject *obj, int delay, const QString &property,
const QVariant& value);
Q_INVOKABLE QQuick3DPickResult pickViewAt(QQuick3DViewport *view, float posX, float posY);
Q_INVOKABLE QQuick3DNode *resolvePick(QQuick3DNode *pickNode);
Q_INVOKABLE void registerGizmoTarget(QQuick3DNode *node);
Q_INVOKABLE void unregisterGizmoTarget(QQuick3DNode *node);
Q_INVOKABLE bool isLocked(QQuick3DNode *node);
Q_INVOKABLE bool isHidden(QQuick3DNode *node);
Q_INVOKABLE bool isPickable(QQuick3DNode *node);
Q_INVOKABLE void storeToolState(const QString &sceneId, const QString &tool,
const QVariant &state, int delayEmit = 0);
@@ -2047,8 +2047,10 @@ void Qt5InformationNodeInstanceServer::handleInstanceHidden(const ServerNodeInst
// as changes in the node tree (reparenting, adding new nodes) can make the previously set
// hide status based on ancestor unreliable.
node->setProperty("_edit3dHidden", edit3dHidden);
#if QT_VERSION < QT_VERSION_CHECK(6, 2, 1)
if (auto model = qobject_cast<QQuick3DModel *>(node))
model->setPickable(!edit3dHidden); // allow 3D objects to receive mouse clicks
#endif
const auto childItems = node->childItems();
for (auto childItem : childItems) {
const ServerNodeInstance quick3dInstance = getQuick3DInstanceAndHidden(childItem);
@@ -2070,7 +2072,9 @@ void Qt5InformationNodeInstanceServer::handleInstanceHidden(const ServerNodeInst
value = QVariant::fromValue(node);
// Specify the actual pick target with dynamic property
checkModel->setProperty("_pickTarget", value);
#if QT_VERSION < QT_VERSION_CHECK(6, 2, 1)
checkModel->setPickable(!edit3dHidden);
#endif
}
};
if (auto childNode = qobject_cast<QQuick3DNode *>(childItem))