fix(StatusImageCrop): output an error if trying to set cropRect without image

This commit is contained in:
Stefan 2022-05-03 14:16:22 +02:00 committed by Michał Cieślak
parent 7072665a10
commit 52c8e3e2c1
5 changed files with 26 additions and 10 deletions

View File

@ -150,11 +150,15 @@ Item {
The new rect will be adjusted to account for the zoom [1, StatusImageCrop::maxZoomScale] The new rect will be adjusted to account for the zoom [1, StatusImageCrop::maxZoomScale]
\note the source image must be set and \c sourceSize valid otherwise, an error is logged to \c console
\note If the new rect has a diferent area the crop window will adjust to the new AR \note If the new rect has a diferent area the crop window will adjust to the new AR
*/ */
function setCropRect(newRect /*rect*/) { function setCropRect(newRect /*rect*/) {
if(newRect.width === 0 || newRect.height === 0) if(newRect.width === 0 || newRect.height === 0)
return return
if(root.sourceSize.width === 0 || root.sourceSize.height === 0)
console.error("Wrong source size. Ensure source is set")
let n = newRect let n = newRect
const s = root.sourceSize const s = root.sourceSize
let nZoom = d.currentZoom(s, Qt.size(n.width, n.height)) let nZoom = d.currentZoom(s, Qt.size(n.width, n.height))

View File

@ -7,6 +7,7 @@ import StatusQ.Controls 0.1
import StatusQ.TestHelpers 0.1 import StatusQ.TestHelpers 0.1
Item { Item {
id: root
width: 400 width: 400
height: 300 height: 300
@ -20,6 +21,8 @@ Item {
} }
} }
property url testImageUrl: `${Qt.resolvedUrl(".")}../../sandbox/demoapp/data/logo-test-image.png`
Component { Component {
id: withSourceComponent id: withSourceComponent
@ -27,7 +30,7 @@ Item {
anchors.fill: parent anchors.fill: parent
// TODO: generate test image and break the sandbox dependency // TODO: generate test image and break the sandbox dependency
source: `${Qt.resolvedUrl(".")}../../sandbox/demoapp/data/logo-test-image.png` source: root.testImageUrl
windowStyle: StatusImageCrop.WindowStyle.Rectangular windowStyle: StatusImageCrop.WindowStyle.Rectangular
Component.onCompleted: setCropRect(Qt.rect(10, 0, sourceSize.width - 20, sourceSize.height)) Component.onCompleted: setCropRect(Qt.rect(10, 0, sourceSize.width - 20, sourceSize.height))
} }
@ -43,7 +46,7 @@ Item {
TestCase { TestCase {
id: qmlWarningsTest id: qmlWarningsTest
name: "CheckQmlWarnings" name: "StatusImageCropPanel"
when: windowShown when: windowShown
@ -66,7 +69,6 @@ Item {
testLoader.active = true testLoader.active = true
verify(waitForRendering(testLoader.item)) verify(waitForRendering(testLoader.item))
testLoader.active = false testLoader.active = false
wait(100)
verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`) verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`)
} }
@ -75,7 +77,19 @@ Item {
testLoader.active = true testLoader.active = true
verify(waitForRendering(testLoader.item)) verify(waitForRendering(testLoader.item))
testLoader.active = false testLoader.active = false
wait(100) verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`)
}
function test_setCrop_error_if_no_source_regression() {
testLoader.sourceComponent = noSourceComponent
testLoader.active = true
verify(waitForRendering(testLoader.item))
testLoader.item.setCropRect(Qt.rect(10, 10, 300, 300))
verify(qtOuput.qtOuput().length !== 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`)
qtOuput.restartCapturing()
testLoader.item.source = root.testImageUrl
verify(waitForRendering(testLoader.item))
testLoader.active = false
verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`) verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`)
} }
} }

View File

@ -19,7 +19,7 @@ Item {
TestCase { TestCase {
id: testCase id: testCase
name: "CheckQmlWarnings" name: "StatusBaseInput"
when: windowShown when: windowShown

View File

@ -42,7 +42,7 @@ Item {
TestCase { TestCase {
id: qmlWarningsTest id: qmlWarningsTest
name: "CheckQmlWarnings" name: "StatusImageCrop-CheckQmlWarnings"
when: windowShown when: windowShown
@ -65,7 +65,6 @@ Item {
testLoader.active = true testLoader.active = true
verify(waitForRendering(testLoader.item)) verify(waitForRendering(testLoader.item))
testLoader.active = false testLoader.active = false
wait(100)
verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`) verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`)
} }
@ -74,7 +73,6 @@ Item {
testLoader.active = true testLoader.active = true
verify(waitForRendering(testLoader.item)) verify(waitForRendering(testLoader.item))
testLoader.active = false testLoader.active = false
wait(100)
verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`) verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`)
} }
} }
@ -89,7 +87,7 @@ Item {
} }
TestCase { TestCase {
name: "TestFunctionality" name: "StatusImageCrop-Functionality"
// //
// Test guards // Test guards

View File

@ -91,7 +91,7 @@ Item {
TestCase { TestCase {
id: qmlWarnTC id: qmlWarnTC
name: "CheckQmlWarnings" name: "StatusInput"
when: windowShown when: windowShown