mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-02 00:02:12 -05:00
use new features model instead of valuerelation model in qml
This commit is contained in:
parent
fa8f2d0b96
commit
2bdff7d44b
@ -26,6 +26,7 @@ ComboBox {
|
||||
id: comboBox
|
||||
|
||||
property var comboStyle
|
||||
signal itemClicked( var index )
|
||||
anchors { left: parent.left; right: parent.right }
|
||||
|
||||
MouseArea {
|
||||
@ -47,8 +48,9 @@ ComboBox {
|
||||
text: model.display
|
||||
font.weight: comboBox.currentIndex === index ? Font.DemiBold : Font.Normal
|
||||
font.pixelSize: comboStyle.fontPixelSize
|
||||
highlighted: comboBox.highlightedIndex == index
|
||||
highlighted: comboBox.highlightedIndex === index
|
||||
leftPadding: 5 * QgsQuick.Utils.dp
|
||||
onClicked: comboBox.itemClicked( model.EmitableIndex ? model.EmitableIndex : index )
|
||||
}
|
||||
|
||||
contentItem: Text {
|
||||
|
@ -26,6 +26,14 @@ import QgsQuick 0.1 as QgsQuick
|
||||
Item {
|
||||
signal valueChanged(var value, bool isNull)
|
||||
|
||||
function itemSelected( index ) {
|
||||
combobox.itemClicked( index )
|
||||
}
|
||||
|
||||
function openCombobox() {
|
||||
combobox.popup.open()
|
||||
}
|
||||
|
||||
id: fieldItem
|
||||
enabled: !readOnly
|
||||
height: customStyle.fields.height
|
||||
@ -36,31 +44,45 @@ Item {
|
||||
}
|
||||
|
||||
QgsQuick.EditorWidgetComboBox {
|
||||
|
||||
id: combobox
|
||||
property var currentEditorValue: value
|
||||
|
||||
comboStyle: customStyle.fields
|
||||
textRole: 'display'
|
||||
height: parent.height
|
||||
|
||||
model: QgsQuick.ValueRelationListModel {
|
||||
id: vrModel
|
||||
model: QgsQuick.FeaturesListModel {
|
||||
id: vrModel
|
||||
modelType: QgsQuick.FeaturesListModel.ValueRelation
|
||||
|
||||
// recalculate index when model changes
|
||||
onModelReset: {
|
||||
combobox.currentIndex = vrModel.rowIndexFromKeyModel( value )
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
vrModel.populate(config)
|
||||
currentIndex = vrModel.rowForKey(value);
|
||||
currentIndex = vrModel.rowIndexFromKeyModel( value )
|
||||
}
|
||||
|
||||
onPressedChanged: {
|
||||
if( pressed )
|
||||
{
|
||||
customWidget.valueRelationOpened( fieldItem, vrModel )
|
||||
pressed = false // we close combobox and let custom handler react, it can open combobox via openCombobox()
|
||||
}
|
||||
}
|
||||
|
||||
// Called when user makes selection in the combo box
|
||||
onCurrentIndexChanged: {
|
||||
valueChanged(vrModel.keyForRow(currentIndex), false)
|
||||
onItemClicked: {
|
||||
currentIndex = vrModel.rowIndexFromKeyModel( index )
|
||||
valueChanged( index, false )
|
||||
}
|
||||
|
||||
// Called when the same form is used for a different feature
|
||||
onCurrentEditorValueChanged: {
|
||||
currentIndex = vrModel.rowForKey(value);
|
||||
currentIndex = vrModel.rowIndexFromKeyModel( value );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,16 @@ Item {
|
||||
*/
|
||||
signal canceled
|
||||
|
||||
/**
|
||||
*/
|
||||
property var customWidgetCallback: QtObject {
|
||||
|
||||
property var valueRelationOpened: function valueRelationOpened( widget, valueRelationModel ) {
|
||||
// by default just open combobox
|
||||
widget.openCombobox()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A handler for extra events in externalSourceWidget.
|
||||
*/
|
||||
@ -396,6 +406,7 @@ Item {
|
||||
property bool readOnly: form.state == "ReadOnly" || !AttributeEditable
|
||||
property var featurePair: form.model.attributeModel.featureLayerPair
|
||||
property var activeProject: form.project
|
||||
property var customWidget: form.customWidgetCallback
|
||||
|
||||
active: widget !== 'Hidden'
|
||||
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "qgsquicksubmodel.h"
|
||||
#include "qgsquickutils.h"
|
||||
#include "qgsquickvaluerelationlistmodel.h"
|
||||
#include "qgsquickfeatureslistmodel.h"
|
||||
|
||||
static QObject *_utilsProvider( QQmlEngine *engine, QJSEngine *scriptEngine )
|
||||
{
|
||||
@ -73,7 +74,6 @@ void QgsQuickPlugin::registerTypes( const char *uri )
|
||||
qRegisterMetaType< QVariant::Type >( "QVariant::Type" );
|
||||
|
||||
qmlRegisterUncreatableType< QgsUnitTypes >( uri, 0, 1, "QgsUnitTypes", "Only enums from QgsUnitTypes can be used" );
|
||||
|
||||
qmlRegisterType< QgsProject >( uri, 0, 1, "Project" );
|
||||
qmlRegisterType< QgsQuickAttributeFormModel >( uri, 0, 1, "AttributeFormModel" );
|
||||
qmlRegisterType< QgsQuickAttributeModel >( uri, 0, 1, "AttributeModel" );
|
||||
@ -89,6 +89,7 @@ void QgsQuickPlugin::registerTypes( const char *uri )
|
||||
qmlRegisterType< QgsQuickSubModel >( uri, 0, 1, "SubModel" );
|
||||
qmlRegisterType< QgsVectorLayer >( uri, 0, 1, "VectorLayer" );
|
||||
qmlRegisterType< QgsQuickValueRelationListModel > ( uri, 0, 1, "ValueRelationListModel" );
|
||||
qmlRegisterType< QgsQuickFeaturesListModel >( uri, 0, 1, "FeaturesListModel" );
|
||||
|
||||
qmlRegisterSingletonType< QgsQuickUtils >( uri, 0, 1, "Utils", _utilsProvider );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user