diff options
author | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-08-13 18:18:44 +0200 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-08-25 11:18:51 +0000 |
commit | 4eb4a3ada360af152b9403e8a88eb76b9474c4ba (patch) | |
tree | 4a3671e14c782f6f5b45e27460835fa943085b9b | |
parent | ded4d7b006180d12f4f2e7642877ffc6586a5331 (diff) |
Fix QML Camera::supportedViewfinderFrameRateRanges().
Pass the resolution argument as a QJSValue instead of a QSize.
This allows to be more flexible and doesn't require the QML argument
to be an actual QML 'size' value. It can be any object with the
'width' and 'height' properties.
Added missing auto-tests for supportedViewfinderResolutions()
and supportedViewfinderFrameRateRanges().
Change-Id: I6c8ae72e6dab8c9d12bbada5b8e7f45e96e9289d
Task-number: QTBUG-47630
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
-rw-r--r-- | src/imports/multimedia/qdeclarativecamera.cpp | 9 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativecamera_p.h | 3 | ||||
-rw-r--r-- | tests/auto/unit/qdeclarativecamera/tst_qdeclarativecamera.qml | 154 |
3 files changed, 163 insertions, 3 deletions
diff --git a/src/imports/multimedia/qdeclarativecamera.cpp b/src/imports/multimedia/qdeclarativecamera.cpp index 5930b20fb..eac1c0c9b 100644 --- a/src/imports/multimedia/qdeclarativecamera.cpp +++ b/src/imports/multimedia/qdeclarativecamera.cpp @@ -1013,12 +1013,17 @@ QJSValue QDeclarativeCamera::supportedViewfinderResolutions(qreal minimumFrameRa \since 5.5 */ -QJSValue QDeclarativeCamera::supportedViewfinderFrameRateRanges(const QSize &resolution) +QJSValue QDeclarativeCamera::supportedViewfinderFrameRateRanges(const QJSValue &resolution) { QQmlEngine *engine = qmlEngine(this); QCameraViewfinderSettings settings; - settings.setResolution(resolution); + if (!resolution.isUndefined()) { + QJSValue width = resolution.property(QStringLiteral("width")); + QJSValue height = resolution.property(QStringLiteral("height")); + if (width.isNumber() && height.isNumber()) + settings.setResolution(width.toInt(), height.toInt()); + } QList<QCamera::FrameRateRange> frameRateRanges = m_camera->supportedViewfinderFrameRateRanges(settings); QJSValue supportedFrameRateRanges = engine->newArray(frameRateRanges.count()); diff --git a/src/imports/multimedia/qdeclarativecamera_p.h b/src/imports/multimedia/qdeclarativecamera_p.h index 623460c59..b3f199a57 100644 --- a/src/imports/multimedia/qdeclarativecamera_p.h +++ b/src/imports/multimedia/qdeclarativecamera_p.h @@ -57,6 +57,7 @@ #include <QtCore/qdatetime.h> #include <QtQml/qqmlparserstatus.h> #include <QtQml/qqml.h> +#include <QtQml/qjsvalue.h> QT_BEGIN_NAMESPACE @@ -297,7 +298,7 @@ public Q_SLOTS: Q_REVISION(2) QJSValue supportedViewfinderResolutions(qreal minimumFrameRate = 0.0, qreal maximumFrameRate = 0.0); - Q_REVISION(2) QJSValue supportedViewfinderFrameRateRanges(const QSize &resolution = QSize()); + Q_REVISION(2) QJSValue supportedViewfinderFrameRateRanges(const QJSValue &resolution = QJSValue()); Q_SIGNALS: void errorChanged(); diff --git a/tests/auto/unit/qdeclarativecamera/tst_qdeclarativecamera.qml b/tests/auto/unit/qdeclarativecamera/tst_qdeclarativecamera.qml index 833ca522b..02e32f4c9 100644 --- a/tests/auto/unit/qdeclarativecamera/tst_qdeclarativecamera.qml +++ b/tests/auto/unit/qdeclarativecamera/tst_qdeclarativecamera.qml @@ -144,4 +144,158 @@ TestCase { cameraLoader.sourceComponent = undefined; } + + function test_supportedViewfinderResolutions_data() { + // see mockcameraviewfindersettingscontrol.h for expected values + + return [ + { + tag: "all", + minimumFrameRate: 0, maximumFrameRate: 0, + expectedResolutions: [ + { width: 320, height: 240 }, + { width: 640, height: 480 }, + { width: 1280, height: 720 }, + { width: 1920, height: 1080 } + ] + }, + { + tag: "invalid minimumFrameRate", + minimumFrameRate: 2, maximumFrameRate: 0, + expectedResolutions: [ ] + }, + { + tag: "minimumFrameRate=5", + minimumFrameRate: 5, maximumFrameRate: 0, + expectedResolutions: [ + { width: 1920, height: 1080 } + ] + }, + { + tag: "minimumFrameRate=10", + minimumFrameRate: 10, maximumFrameRate: 0, + expectedResolutions: [ + { width: 1280, height: 720 } + ] + }, + { + tag: "minimumFrameRate=30", + minimumFrameRate: 30, maximumFrameRate: 0, + expectedResolutions: [ + { width: 320, height: 240 }, + { width: 640, height: 480 }, + { width: 1280, height: 720 } + ] + }, + { + tag: "invalid maximumFrameRate", + minimumFrameRate: 0, maximumFrameRate: 2, + expectedResolutions: [ ] + }, + { + tag: "maximumFrameRate=10", + minimumFrameRate: 0, maximumFrameRate: 10, + expectedResolutions: [ + { width: 1280, height: 720 }, + { width: 1920, height: 1080 } + ] + }, + { + tag: "minimumFrameRate=10, maximumFrameRate=10", + minimumFrameRate: 10, maximumFrameRate: 10, + expectedResolutions: [ + { width: 1280, height: 720 } + ] + }, + { + tag: "minimumFrameRate=30, maximumFrameRate=30", + minimumFrameRate: 30, maximumFrameRate: 30, + expectedResolutions: [ + { width: 320, height: 240 }, + { width: 640, height: 480 }, + { width: 1280, height: 720 } + ] + } + ] + } + + function test_supportedViewfinderResolutions(data) { + cameraLoader.sourceComponent = cameraComponent; + var camera = cameraLoader.item; + + var actualResolutions = camera.supportedViewfinderResolutions(data.minimumFrameRate, data.maximumFrameRate); + compare(actualResolutions.length, data.expectedResolutions.length); + for (var i = 0; i < actualResolutions.length; ++i) { + compare(actualResolutions[i].width, data.expectedResolutions[i].width); + compare(actualResolutions[i].height, data.expectedResolutions[i].height); + } + + cameraLoader.sourceComponent = undefined; + } + + function test_supportedViewfinderFrameRateRanges_data() { + // see mockcameraviewfindersettingscontrol.h for expected values + return [ + { + tag: "all", + expectedFrameRateRanges: [ + { minimumFrameRate: 5, maximumFrameRate: 10 }, + { minimumFrameRate: 10, maximumFrameRate: 10 }, + { minimumFrameRate: 30, maximumFrameRate: 30 } + ] + }, + { + tag: "invalid", + resolution: { width: 452472, height: 444534 }, + expectedFrameRateRanges: [ ] + }, + { + tag: "320, 240", + resolution: { width: 320, height: 240 }, + expectedFrameRateRanges: [ + { minimumFrameRate: 30, maximumFrameRate: 30 } + ] + }, + { + tag: "1280, 720", + resolution: { width: 1280, height: 720 }, + expectedFrameRateRanges: [ + { minimumFrameRate: 10, maximumFrameRate: 10 }, + { minimumFrameRate: 30, maximumFrameRate: 30 } + ] + }, + { + tag: "1920, 1080", + resolution: { width: 1920, height: 1080 }, + expectedFrameRateRanges: [ + { minimumFrameRate: 5, maximumFrameRate: 10 } + ] + } + ] + } + + function test_supportedViewfinderFrameRateRanges(data) { + cameraLoader.sourceComponent = cameraComponent; + var camera = cameraLoader.item; + + // Pass the resolution as an object + var actualFrameRateRanges = camera.supportedViewfinderFrameRateRanges(data.resolution); + compare(actualFrameRateRanges.length, data.expectedFrameRateRanges.length); + for (var i = 0; i < actualFrameRateRanges.length; ++i) { + compare(actualFrameRateRanges[i].minimumFrameRate, data.expectedFrameRateRanges[i].minimumFrameRate); + compare(actualFrameRateRanges[i].maximumFrameRate, data.expectedFrameRateRanges[i].maximumFrameRate); + } + + // Pass the resolution as a size + if (typeof data.resolution !== 'undefined') { + actualFrameRateRanges = camera.supportedViewfinderFrameRateRanges(Qt.size(data.resolution.width, data.resolution.height)); + compare(actualFrameRateRanges.length, data.expectedFrameRateRanges.length); + for (i = 0; i < actualFrameRateRanges.length; ++i) { + compare(actualFrameRateRanges[i].minimumFrameRate, data.expectedFrameRateRanges[i].minimumFrameRate); + compare(actualFrameRateRanges[i].maximumFrameRate, data.expectedFrameRateRanges[i].maximumFrameRate); + } + } + + cameraLoader.sourceComponent = undefined; + } } |