From 4b8c777c257f641f7a4309cdaf1d5e7b29bfe147 Mon Sep 17 00:00:00 2001 From: LOMENEDE Jean-Daniel Date: Tue, 27 Sep 2016 13:42:26 +0200 Subject: [PATCH] add support of virtual and joined fields --- EasyCustomLabeling/EasyCustomLabeling.py | 7 +++++-- EasyCustomLabeling/EasyCustomLabelingDialog.py | 11 +++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/EasyCustomLabeling/EasyCustomLabeling.py b/EasyCustomLabeling/EasyCustomLabeling.py index 67a3c46..904c1cd 100644 --- a/EasyCustomLabeling/EasyCustomLabeling.py +++ b/EasyCustomLabeling/EasyCustomLabeling.py @@ -420,13 +420,16 @@ def runLabel(self): #end of general tests and user interaction -------------------------------------------------- sourceLayerProvider = sourceLayer.dataProvider() - sourceLayerFields = sourceLayerProvider.fields() + if hasattr(sourceLayer, "fields"): + sourceLayerFields = sourceLayer.fields() + else: + sourceLayerFields = sourceLayer.pendingFields() feat = QgsFeature() #asks for default field to use as labeling (thanks to Victor Axbom Layer to labeled layer plugin) # create the dialog - self.dlg = EasyCustomLabelingDialog(sourceLayerProvider) + self.dlg = EasyCustomLabelingDialog(sourceLayerFields) ret_dlg_field = self.dlg.exec_() #cancels if user cancels dialog: if ret_dlg_field == 0 : diff --git a/EasyCustomLabeling/EasyCustomLabelingDialog.py b/EasyCustomLabeling/EasyCustomLabelingDialog.py index 2f2930b..f12ee6b 100644 --- a/EasyCustomLabeling/EasyCustomLabelingDialog.py +++ b/EasyCustomLabeling/EasyCustomLabelingDialog.py @@ -36,15 +36,14 @@ class EasyCustomLabelingDialog(QDialog, Ui_EasyCustomLabeling): - def __init__(self, ldp): + def __init__(self, layerFields): QDialog.__init__(self) # Set up the user interface from Designer. self.setupUi(self) - self.loadFields(ldp) + self.loadFields(layerFields) - def loadFields(self, ldp): - fields = ldp.fieldNameMap() - for fieldname, index in fields.iteritems(): - self.labelfield.addItem(fieldname) + def loadFields(self, layerFields): + for field in layerFields: + self.labelfield.addItem(field.name()) \ No newline at end of file