Skip to content

Commit

Permalink
[QgsQuick] External widget changes
Browse files Browse the repository at this point in the history
Simplified callbacks for onSaved/onCanceled form
Some design fixes.
  • Loading branch information
vsklencar authored and wonder-sk committed Apr 24, 2019
1 parent 0375ce4 commit 1b428a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
43 changes: 22 additions & 21 deletions src/quickgui/plugin/editor/qgsquickexternalresource.qml
Expand Up @@ -39,13 +39,11 @@ Item {
// Ment to be use with the save callback - stores image source
property string sourceToDelete

Component.onCompleted: {
callbackOnSave = function() {
externalResourceHandler.onFormSave(fieldItem)
}
callbackOnCancel = function() {
externalResourceHandler.onFormCanceled(fieldItem)
}
function callbackOnSave() {
externalResourceHandler.onFormSave(fieldItem)
}
function callbackOnCancel() {
externalResourceHandler.onFormCanceled(fieldItem)
}

id: fieldItem
Expand Down Expand Up @@ -129,13 +127,14 @@ Item {

Button {
id: deleteButton
visible: !readOnly && fieldItem.state === "valid"
width: fieldItem.iconSize
visible: !readOnly && fieldItem.state !== "notSet"
width: buttonsContainer.itemHeight
height: width
padding: 0

anchors.right: imageContainer.right
anchors.bottom: imageContainer.bottom
anchors.margins: buttonsContainer.itemHeight/4

onClicked: externalResourceHandler.removeImage(fieldItem, homePath + "/" + image.currentValue)

Expand Down Expand Up @@ -163,7 +162,7 @@ Item {
anchors.centerIn: imageContainer
anchors.fill: imageContainer
anchors.margins: fieldItem.textMargin
visible: fieldItem.state !== "valid"
visible: fieldItem.state === "notSet"

anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
Expand Down Expand Up @@ -216,18 +215,20 @@ Item {
}
}

QgsQuick.IconTextItem {
id: infoItem
iconSize: fieldItem.iconSize/2
fontColor: customStyle.fields.fontColor
iconSource: fieldItem.brokenImageIcon
labelText: qsTr("Image is not available: ") + image.currentValue

Text {
id: text
height: parent.height
width: imageContainer.width - 2* fieldItem.textMargin
wrapMode: Text.WordWrap
minimumPixelSize: 50 * QgsQuick.Utils.dp
text: qsTr("Image is not available: ") + image.currentValue
font.pixelSize: buttonsContainer.itemHeight * 0.75
color: customStyle.fields.fontColor
anchors.leftMargin: buttonsContainer.itemHeight + fieldItem.textMargin
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
visible: fieldItem.state === "notAvailable"
height: fieldItem.iconSize/2
anchors.bottom: parent.bottom
anchors.bottomMargin: fieldItem.textMargin
anchors.horizontalCenter: parent.horizontalCenter
}

}
10 changes: 4 additions & 6 deletions src/quickgui/plugin/qgsquickfeatureform.qml
Expand Up @@ -376,8 +376,6 @@ Item {
property var customStyle: form.style
property var externalResourceHandler: form.externalResourceHandler
property bool readOnly: form.state == "ReadOnly" || !AttributeEditable
property var callbackOnSave: undefined
property var callbackOnCancel: undefined

active: widget !== 'Hidden'

Expand All @@ -395,8 +393,8 @@ Item {
target: form
ignoreUnknownSignals: true
onSaved: {
if (attributeEditorLoader.widget === "ExternalResource") {
attributeEditorLoader.callbackOnSave()
if (typeof attributeEditorLoader.item.callbackOnSave === "function") {
attributeEditorLoader.item.callbackOnSave()
}
}
}
Expand All @@ -405,8 +403,8 @@ Item {
target: form
ignoreUnknownSignals: true
onCanceled: {
if (attributeEditorLoader.widget === "ExternalResource") {
attributeEditorLoader.callbackOnCancel()
if (typeof attributeEditorLoader.item.callbackOnCancel === "function") {
attributeEditorLoader.item.callbackOnCancel()
}
}
}
Expand Down

0 comments on commit 1b428a5

Please sign in to comment.