Skip to content

Commit 0375ce4

Browse files
vsklencarwonder-sk
vsklencar
authored andcommitted
[QgsQuick] Added callbacks for qgsquick external source widget
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
1 parent f3dc4c3 commit 0375ce4

File tree

3 files changed

+110
-55
lines changed

3 files changed

+110
-55
lines changed

src/quickgui/plugin/components/qgsquickicontextitem.qml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/***************************************************************************
2+
qgsquickicontextitem.qml
3+
--------------------------------------
4+
Date : 2019
5+
Copyright : (C) 2019 by Viktor Sklencar
6+
Email : viktor.sklencar@lutraconsulting.co.uk
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
116
import QtQuick 2.5
217
import QtGraphicalEffects 1.0
318
import QgsQuick 0.1 as QgsQuick

src/quickgui/plugin/editor/qgsquickexternalresource.qml

Lines changed: 73 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import QtQuick 2.5
1717
import QtQuick.Controls 2.0
1818
import QtGraphicalEffects 1.0
19+
import QtQuick.Layouts 1.3
1920
import QgsQuick 0.1 as QgsQuick
2021

2122
/**
@@ -33,8 +34,19 @@ Item {
3334
property var galleryIcon: customStyle.icons.gallery
3435
property var brokenImageIcon: customStyle.icons.brokenImage
3536
property var notAvailableImageIcon: customStyle.icons.notAvailable
36-
property real iconSize: customStyle.fields.height * 0.75
37+
property real iconSize: customStyle.fields.height
3738
property real textMargin: QgsQuick.Utils.dp * 10
39+
// Ment to be use with the save callback - stores image source
40+
property string sourceToDelete
41+
42+
Component.onCompleted: {
43+
callbackOnSave = function() {
44+
externalResourceHandler.onFormSave(fieldItem)
45+
}
46+
callbackOnCancel = function() {
47+
externalResourceHandler.onFormCanceled(fieldItem)
48+
}
49+
}
3850

3951
id: fieldItem
4052
enabled: true // its interactive widget
@@ -52,9 +64,6 @@ Item {
5264
State {
5365
name: "notSet"
5466
},
55-
State {
56-
name: "broken"
57-
},
5867
State {
5968
name: "notAvailable"
6069
}
@@ -101,7 +110,7 @@ Item {
101110

102111
function getSource() {
103112
if (image.status === Image.Error) {
104-
fieldItem.state = "broken"
113+
fieldItem.state = "notAvailable"
105114
return ""
106115
}
107116
else if (image.currentValue && QgsQuick.Utils.fileExists(homePath + "/" + image.currentValue)) {
@@ -112,10 +121,8 @@ Item {
112121
fieldItem.state = "notSet"
113122
return ""
114123
}
115-
else {
116-
fieldItem.state = "notAvailable"
117-
return homePath + "/" + image.currentValue
118-
}
124+
fieldItem.state = "notAvailable"
125+
return homePath + "/" + image.currentValue
119126
}
120127
}
121128
}
@@ -150,66 +157,77 @@ Item {
150157
}
151158

152159
Item {
160+
property real itemHeight: fieldItem.iconSize/2
161+
153162
id: buttonsContainer
154163
anchors.centerIn: imageContainer
155164
anchors.fill: imageContainer
156-
anchors.margins: 10
165+
anchors.margins: fieldItem.textMargin
157166
visible: fieldItem.state !== "valid"
158167

159-
QgsQuick.IconTextItem {
160-
id: photoButton
161-
iconSize: fieldItem.iconSize
162-
fontColor: customStyle.fields.fontColor
163-
fontPixelSize: fieldItem.iconSize/2
164-
iconSource: fieldItem.cameraIcon
165-
labelText: qsTr("Take a Photo")
168+
anchors.horizontalCenter: parent.horizontalCenter
169+
anchors.verticalCenter: parent.verticalCenter
166170

167-
visible: !readOnly && fieldItem.state !== " valid"
168-
height: fieldItem.iconSize
171+
ColumnLayout {
172+
width: parent.width
173+
height: photoButton.height * 2
169174
anchors.horizontalCenter: parent.horizontalCenter
175+
anchors.verticalCenter: parent.verticalCenter
170176

171-
MouseArea {
172-
anchors.fill: parent
173-
onClicked: {
174-
photoCapturePanel.visible = true
175-
photoCapturePanel.targetDir = homePath
176-
photoCapturePanel.fieldItem = fieldItem
177+
QgsQuick.IconTextItem {
178+
id: photoButton
179+
iconSize: buttonsContainer.itemHeight
180+
fontColor: customStyle.fields.fontColor
181+
fontPixelSize: customStyle.fields.fontPixelSize
182+
iconSource: fieldItem.cameraIcon
183+
labelText: qsTr("Take a Photo")
184+
185+
visible: !readOnly && fieldItem.state !== " valid"
186+
height: buttonsContainer.itemHeight
187+
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
188+
189+
MouseArea {
190+
anchors.fill: parent
191+
onClicked: {
192+
photoCapturePanel.visible = true
193+
photoCapturePanel.targetDir = homePath
194+
photoCapturePanel.fieldItem = fieldItem
195+
}
177196
}
178197
}
179-
}
180-
181-
QgsQuick.IconTextItem {
182-
id: browseButton
183-
iconSize: fieldItem.iconSize
184-
fontColor: customStyle.fields.fontColor
185-
fontPixelSize: fieldItem.iconSize/2
186-
iconSource: fieldItem.galleryIcon
187-
labelText: qsTr("Add From a Gallery")
188-
189-
visible: !readOnly && fieldItem.state !== " valid"
190-
height: fieldItem.iconSize
191-
anchors.top: photoButton.bottom
192-
anchors.horizontalCenter: parent.horizontalCenter
193198

194-
MouseArea {
195-
anchors.fill: parent
196-
onClicked: externalResourceHandler.chooseImage(fieldItem)
199+
QgsQuick.IconTextItem {
200+
id: browseButton
201+
iconSize: buttonsContainer.itemHeight
202+
fontColor: customStyle.fields.fontColor
203+
fontPixelSize: customStyle.fields.fontPixelSize
204+
iconSource: fieldItem.galleryIcon
205+
labelText: qsTr("Add From a Gallery")
206+
207+
visible: !readOnly && fieldItem.state !== " valid"
208+
height: buttonsContainer.itemHeight
209+
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
210+
211+
MouseArea {
212+
anchors.fill: parent
213+
onClicked: externalResourceHandler.chooseImage(fieldItem)
214+
}
197215
}
198216
}
217+
}
199218

200-
QgsQuick.IconTextItem {
201-
id: infoItem
202-
iconSize: fieldItem.iconSize/2
203-
fontColor: customStyle.fields.fontColor
204-
iconSource: fieldItem.brokenImageIcon
205-
labelText: qsTr("Image is broken: ") + image.currentValue
206-
207-
visible: fieldItem.state === "broken" || fieldItem.state === "notAvailable"
208-
height: fieldItem.iconSize/2
209-
anchors.bottom: parent.bottom
210-
anchors.horizontalCenter: parent.horizontalCenter
211-
212-
}
219+
QgsQuick.IconTextItem {
220+
id: infoItem
221+
iconSize: fieldItem.iconSize/2
222+
fontColor: customStyle.fields.fontColor
223+
iconSource: fieldItem.brokenImageIcon
224+
labelText: qsTr("Image is not available: ") + image.currentValue
225+
226+
visible: fieldItem.state === "notAvailable"
227+
height: fieldItem.iconSize/2
228+
anchors.bottom: parent.bottom
229+
anchors.bottomMargin: fieldItem.textMargin
230+
anchors.horizontalCenter: parent.horizontalCenter
213231
}
214232

215233
}

src/quickgui/plugin/qgsquickfeatureform.qml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ Item {
376376
property var customStyle: form.style
377377
property var externalResourceHandler: form.externalResourceHandler
378378
property bool readOnly: form.state == "ReadOnly" || !AttributeEditable
379+
property var callbackOnSave: undefined
380+
property var callbackOnCancel: undefined
379381

380382
active: widget !== 'Hidden'
381383

@@ -388,6 +390,26 @@ Item {
388390
AttributeValue = isNull ? undefined : value
389391
}
390392
}
393+
394+
Connections {
395+
target: form
396+
ignoreUnknownSignals: true
397+
onSaved: {
398+
if (attributeEditorLoader.widget === "ExternalResource") {
399+
attributeEditorLoader.callbackOnSave()
400+
}
401+
}
402+
}
403+
404+
Connections {
405+
target: form
406+
ignoreUnknownSignals: true
407+
onCanceled: {
408+
if (attributeEditorLoader.widget === "ExternalResource") {
409+
attributeEditorLoader.callbackOnCancel()
410+
}
411+
}
412+
}
391413
}
392414

393415
CheckBox {

0 commit comments

Comments
 (0)