diff options
author | Mike Krus <mike.krus@kdab.com> | 2020-11-23 09:06:01 +0000 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2021-01-08 11:32:08 +0000 |
commit | d2fe37b3480cc55cf301426d7fa40475080cc6f9 (patch) | |
tree | 8c0ef31cdc3d2f75f4eed7d851a6d22e793d4c00 /src/quick3d/quick3dinput/items/quick3dlogicaldevice.cpp | |
parent | eee0fca4abc800883dde40559290403e7e550d14 (diff) |
Update QQMLPropertyList API
Use lambdas with local typedefs for index type
Change-Id: I2876c71d619815e7e777f936e8bb0835b8269336
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/quick3d/quick3dinput/items/quick3dlogicaldevice.cpp')
-rw-r--r-- | src/quick3d/quick3dinput/items/quick3dlogicaldevice.cpp | 116 |
1 files changed, 54 insertions, 62 deletions
diff --git a/src/quick3d/quick3dinput/items/quick3dlogicaldevice.cpp b/src/quick3d/quick3dinput/items/quick3dlogicaldevice.cpp index df52cf8c8..061fe1433 100644 --- a/src/quick3d/quick3dinput/items/quick3dlogicaldevice.cpp +++ b/src/quick3d/quick3dinput/items/quick3dlogicaldevice.cpp @@ -52,72 +52,64 @@ Quick3DLogicalDevice::Quick3DLogicalDevice(QObject *parent) QQmlListProperty<QAxis> Quick3DLogicalDevice::qmlAxes() { - return QQmlListProperty<QAxis>(this, 0, - &Quick3DLogicalDevice::appendAxis, - &Quick3DLogicalDevice::axesCount, - &Quick3DLogicalDevice::axisAt, - &Quick3DLogicalDevice::clearAxes); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QAxis; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *axes) { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + device->parentLogicalDevice()->addAxis(axes); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + return device->parentLogicalDevice()->axes().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + return device->parentLogicalDevice()->axes().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + const auto axes = device->parentLogicalDevice()->axes(); + for (QAxis *axis : axes) + device->parentLogicalDevice()->removeAxis(axis); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QAction> Quick3DLogicalDevice::qmlActions() { - return QQmlListProperty<QAction>(this, 0, - &Quick3DLogicalDevice::appendAction, - &Quick3DLogicalDevice::actionCount, - &Quick3DLogicalDevice::actionAt, - &Quick3DLogicalDevice::clearActions); -} - -void Quick3DLogicalDevice::appendAxis(QQmlListProperty<QAxis> *list, QAxis *axes) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - device->parentLogicalDevice()->addAxis(axes); -} - -QAxis *Quick3DLogicalDevice::axisAt(QQmlListProperty<QAxis> *list, qsizetype index) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - return device->parentLogicalDevice()->axes().at(index); -} - -qsizetype Quick3DLogicalDevice::axesCount(QQmlListProperty<QAxis> *list) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - return device->parentLogicalDevice()->axes().count(); -} - -void Quick3DLogicalDevice::clearAxes(QQmlListProperty<QAxis> *list) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - const auto axes = device->parentLogicalDevice()->axes(); - for (QAxis *axis : axes) - device->parentLogicalDevice()->removeAxis(axis); -} - -void Quick3DLogicalDevice::appendAction(QQmlListProperty<QAction> *list, QAction *action) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - device->parentLogicalDevice()->addAction(action); -} - -QAction *Quick3DLogicalDevice::actionAt(QQmlListProperty<QAction> *list, qsizetype index) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - return device->parentLogicalDevice()->actions().at(index); -} - -qsizetype Quick3DLogicalDevice::actionCount(QQmlListProperty<QAction> *list) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - return device->parentLogicalDevice()->actions().count(); -} - -void Quick3DLogicalDevice::clearActions(QQmlListProperty<QAction> *list) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - const auto actions = device->parentLogicalDevice()->actions(); - for (QAction *action : actions) - device->parentLogicalDevice()->removeAction(action); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QAction; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *action) { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + device->parentLogicalDevice()->addAction(action); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + return device->parentLogicalDevice()->actions().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + return device->parentLogicalDevice()->actions().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + const auto actions = device->parentLogicalDevice()->actions(); + for (QAction *action : actions) + device->parentLogicalDevice()->removeAction(action); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } |