Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[QgsQuick] Value Relation widget
Added a widget for value relation field time of a feature form.
- Loading branch information
Showing
4 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/*************************************************************************** | ||
qgsquickvaluerelation.qml | ||
-------------------------------------- | ||
Date : 2017 | ||
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.7 | ||
import QtQuick.Controls 2.2 | ||
import QtGraphicalEffects 1.0 | ||
import QgsQuick 0.1 as QgsQuick | ||
|
||
/** | ||
* Value Relation for QGIS Attribute Form | ||
* Requires various global properties set to function, see qgsquickfeatureform Loader section | ||
* Do not use directly from Application QML | ||
*/ | ||
Item { | ||
signal valueChanged(var value, bool isNull) | ||
|
||
id: fieldItem | ||
enabled: !readOnly | ||
height: customStyle.height | ||
anchors { | ||
left: parent.left | ||
right: parent.right | ||
rightMargin: 10 * QgsQuick.Utils.dp | ||
} | ||
|
||
ComboBox { | ||
id: comboBox | ||
|
||
property var reverseConfig: ({}) | ||
property var currentValue: value | ||
property var currentMap | ||
property var currentKey | ||
height: parent.height | ||
anchors { left: parent.left; right: parent.right } | ||
currentIndex: find(value) | ||
|
||
ListModel { | ||
id: listModel | ||
} | ||
|
||
Component.onCompleted: { | ||
currentMap = QgsQuick.Utils.createValueRelationCache(config) | ||
var keys = Object.keys(currentMap) | ||
for(var i=0; i< keys.length; i++) | ||
{ | ||
currentKey = keys[i] | ||
var valueText = currentMap[currentKey] | ||
listModel.append( { text: valueText } ) | ||
reverseConfig[valueText] = currentKey; | ||
} | ||
model=listModel | ||
textRole = 'text' | ||
currentIndex = find(currentMap[value]) | ||
} | ||
|
||
onCurrentTextChanged: { | ||
valueChanged(reverseConfig[currentText], false) | ||
} | ||
|
||
// Workaround to get a signal when the value has changed | ||
onCurrentValueChanged: { | ||
currentIndex = find(currentMap[value]) | ||
} | ||
|
||
MouseArea { | ||
anchors.fill: parent | ||
propagateComposedEvents: true | ||
|
||
onClicked: mouse.accepted = false | ||
onPressed: { forceActiveFocus(); mouse.accepted = false; } | ||
onReleased: mouse.accepted = false; | ||
onDoubleClicked: mouse.accepted = false; | ||
onPositionChanged: mouse.accepted = false; | ||
onPressAndHold: mouse.accepted = false; | ||
} | ||
|
||
// [hidpi fixes] | ||
delegate: ItemDelegate { | ||
width: comboBox.width | ||
height: comboBox.height * 0.8 | ||
text: modelData | ||
font.weight: comboBox.currentIndex === index ? Font.DemiBold : Font.Normal | ||
font.pixelSize: customStyle.fontPixelSize | ||
highlighted: comboBox.highlightedIndex == index | ||
leftPadding: 5 * QgsQuick.Utils.dp | ||
} | ||
|
||
contentItem: Text { | ||
height: comboBox.height * 0.8 | ||
text: comboBox.displayText | ||
font.pixelSize: customStyle.fontPixelSize | ||
horizontalAlignment: Text.AlignLeft | ||
verticalAlignment: Text.AlignVCenter | ||
elide: Text.ElideRight | ||
leftPadding: 5 * QgsQuick.Utils.dp | ||
color: customStyle.fontColor | ||
} | ||
|
||
background: Item { | ||
implicitWidth: 120 * QgsQuick.Utils.dp | ||
implicitHeight: comboBox.height * 0.8 | ||
|
||
Rectangle { | ||
anchors.fill: parent | ||
id: backgroundRect | ||
border.color: comboBox.pressed ? customStyle.activeColor : customStyle.normalColor | ||
border.width: comboBox.visualFocus ? 2 : 1 | ||
color: customStyle.backgroundColor | ||
radius: customStyle.cornerRadius | ||
} | ||
} | ||
// [/hidpi fixes] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters