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>
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user