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 Stefan Dunca
parent 934db52126
commit bb9f08155f
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]
\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
*/
function setCropRect(newRect /*rect*/) {
if(newRect.width === 0 || newRect.height === 0)
return
if(root.sourceSize.width === 0 || root.sourceSize.height === 0)
console.error("Wrong source size. Ensure source is set")
let n = newRect
const s = root.sourceSize
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
Item {
id: root
width: 400
height: 300
@ -20,6 +21,8 @@ Item {
}
}
property url testImageUrl: `${Qt.resolvedUrl(".")}../../sandbox/demoapp/data/logo-test-image.png`
Component {
id: withSourceComponent
@ -27,7 +30,7 @@ Item {
anchors.fill: parent
// 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
Component.onCompleted: setCropRect(Qt.rect(10, 0, sourceSize.width - 20, sourceSize.height))
}
@ -43,7 +46,7 @@ Item {
TestCase {
id: qmlWarningsTest
name: "CheckQmlWarnings"
name: "StatusImageCropPanel"
when: windowShown
@ -66,7 +69,6 @@ Item {
testLoader.active = true
verify(waitForRendering(testLoader.item))
testLoader.active = false
wait(100)
verify(qtOuput.qtOuput().length === 0, `No output expected. Found:\n"${qtOuput.qtOuput()}"\n`)
}
@ -75,7 +77,19 @@ Item {
testLoader.active = true
verify(waitForRendering(testLoader.item))
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`)
}
}

View File

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

View File

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

View File

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