Skip to content

Commit

Permalink
[QgsQuick] Added callbacks for qgsquick external source widget
Browse files Browse the repository at this point in the history
Added callbacks functions in external resource handler - if some actions as permanent removal of image suppose to be done on form save.
Some changes in design
  • Loading branch information
vsklencar authored and wonder-sk committed Apr 24, 2019
1 parent f3dc4c3 commit 0375ce4
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 55 deletions.
15 changes: 15 additions & 0 deletions src/quickgui/plugin/components/qgsquickicontextitem.qml
@@ -1,3 +1,18 @@
/***************************************************************************
qgsquickicontextitem.qml
--------------------------------------
Date : 2019
Copyright : (C) 2019 by Viktor Sklencar
Email : viktor.sklencar@lutraconsulting.co.uk
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

import QtQuick 2.5
import QtGraphicalEffects 1.0
import QgsQuick 0.1 as QgsQuick
Expand Down
128 changes: 73 additions & 55 deletions src/quickgui/plugin/editor/qgsquickexternalresource.qml
Expand Up @@ -16,6 +16,7 @@
import QtQuick 2.5
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0
import QtQuick.Layouts 1.3
import QgsQuick 0.1 as QgsQuick

/**
Expand All @@ -33,8 +34,19 @@ Item {
property var galleryIcon: customStyle.icons.gallery
property var brokenImageIcon: customStyle.icons.brokenImage
property var notAvailableImageIcon: customStyle.icons.notAvailable
property real iconSize: customStyle.fields.height * 0.75
property real iconSize: customStyle.fields.height
property real textMargin: QgsQuick.Utils.dp * 10
// 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)
}
}

id: fieldItem
enabled: true // its interactive widget
Expand All @@ -52,9 +64,6 @@ Item {
State {
name: "notSet"
},
State {
name: "broken"
},
State {
name: "notAvailable"
}
Expand Down Expand Up @@ -101,7 +110,7 @@ Item {

function getSource() {
if (image.status === Image.Error) {
fieldItem.state = "broken"
fieldItem.state = "notAvailable"
return ""
}
else if (image.currentValue && QgsQuick.Utils.fileExists(homePath + "/" + image.currentValue)) {
Expand All @@ -112,10 +121,8 @@ Item {
fieldItem.state = "notSet"
return ""
}
else {
fieldItem.state = "notAvailable"
return homePath + "/" + image.currentValue
}
fieldItem.state = "notAvailable"
return homePath + "/" + image.currentValue
}
}
}
Expand Down Expand Up @@ -150,66 +157,77 @@ Item {
}

Item {
property real itemHeight: fieldItem.iconSize/2

id: buttonsContainer
anchors.centerIn: imageContainer
anchors.fill: imageContainer
anchors.margins: 10
anchors.margins: fieldItem.textMargin
visible: fieldItem.state !== "valid"

QgsQuick.IconTextItem {
id: photoButton
iconSize: fieldItem.iconSize
fontColor: customStyle.fields.fontColor
fontPixelSize: fieldItem.iconSize/2
iconSource: fieldItem.cameraIcon
labelText: qsTr("Take a Photo")
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter

visible: !readOnly && fieldItem.state !== " valid"
height: fieldItem.iconSize
ColumnLayout {
width: parent.width
height: photoButton.height * 2
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter

MouseArea {
anchors.fill: parent
onClicked: {
photoCapturePanel.visible = true
photoCapturePanel.targetDir = homePath
photoCapturePanel.fieldItem = fieldItem
QgsQuick.IconTextItem {
id: photoButton
iconSize: buttonsContainer.itemHeight
fontColor: customStyle.fields.fontColor
fontPixelSize: customStyle.fields.fontPixelSize
iconSource: fieldItem.cameraIcon
labelText: qsTr("Take a Photo")

visible: !readOnly && fieldItem.state !== " valid"
height: buttonsContainer.itemHeight
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter

MouseArea {
anchors.fill: parent
onClicked: {
photoCapturePanel.visible = true
photoCapturePanel.targetDir = homePath
photoCapturePanel.fieldItem = fieldItem
}
}
}
}

QgsQuick.IconTextItem {
id: browseButton
iconSize: fieldItem.iconSize
fontColor: customStyle.fields.fontColor
fontPixelSize: fieldItem.iconSize/2
iconSource: fieldItem.galleryIcon
labelText: qsTr("Add From a Gallery")

visible: !readOnly && fieldItem.state !== " valid"
height: fieldItem.iconSize
anchors.top: photoButton.bottom
anchors.horizontalCenter: parent.horizontalCenter

MouseArea {
anchors.fill: parent
onClicked: externalResourceHandler.chooseImage(fieldItem)
QgsQuick.IconTextItem {
id: browseButton
iconSize: buttonsContainer.itemHeight
fontColor: customStyle.fields.fontColor
fontPixelSize: customStyle.fields.fontPixelSize
iconSource: fieldItem.galleryIcon
labelText: qsTr("Add From a Gallery")

visible: !readOnly && fieldItem.state !== " valid"
height: buttonsContainer.itemHeight
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter

MouseArea {
anchors.fill: parent
onClicked: externalResourceHandler.chooseImage(fieldItem)
}
}
}
}

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

visible: fieldItem.state === "broken" || fieldItem.state === "notAvailable"
height: fieldItem.iconSize/2
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter

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

visible: fieldItem.state === "notAvailable"
height: fieldItem.iconSize/2
anchors.bottom: parent.bottom
anchors.bottomMargin: fieldItem.textMargin
anchors.horizontalCenter: parent.horizontalCenter
}

}
22 changes: 22 additions & 0 deletions src/quickgui/plugin/qgsquickfeatureform.qml
Expand Up @@ -376,6 +376,8 @@ 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 @@ -388,6 +390,26 @@ Item {
AttributeValue = isNull ? undefined : value
}
}

Connections {
target: form
ignoreUnknownSignals: true
onSaved: {
if (attributeEditorLoader.widget === "ExternalResource") {
attributeEditorLoader.callbackOnSave()
}
}
}

Connections {
target: form
ignoreUnknownSignals: true
onCanceled: {
if (attributeEditorLoader.widget === "ExternalResource") {
attributeEditorLoader.callbackOnCancel()
}
}
}
}

CheckBox {
Expand Down

0 comments on commit 0375ce4

Please sign in to comment.