Skip to content

Commit d1d5017

Browse files
author
Régis Haubourg
committed
1.3 commit
resolves conflicts when multiple labeling layer are active. supports having selected any layer in registry.
1 parent e25b438 commit d1d5017

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

EasyCustomLabeling/EasyCustomLabeling.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: iso-8859-1 -*-
2-
"""
2+
"""
33
/***************************************************************************
44
Name :EasyCustomLabeling
55
Description : plugin allowing a quick duplication of layer, ready to start manual customisation of labels (position, size, colors.. ) based on data fields
@@ -35,10 +35,12 @@
3535

3636
# load translation libraries
3737

38-
class EasyCustomLabeling:
38+
class EasyCustomLabeling(QObject):
39+
# class EasyCustomLabeling:
3940

4041
def __init__(self, iface):
4142
# Save reference to the QGIS interface
43+
QObject.__init__(self) #init from QObject parent
4244
self.iface = iface
4345
self.qgsVersion = unicode(QGis.QGIS_VERSION_INT)
4446
print '# EasyCustomLabeling debug trace: plugin loaded at ' + str(datetime.datetime.now())
@@ -119,6 +121,7 @@ def initGui(self):
119121
#disconnects if label layers closed?
120122

121123
def labelLayerChecked(self):
124+
122125

123126
# print 'projet chargé: '
124127
# Checks if some labeling layers are already there, and replug, if not already labelLayerModified events
@@ -162,21 +165,33 @@ def labelLayerChecked(self):
162165

163166
if LblXok and LblYok and LblAlignHok and LblAlignVok and LblShowCOok and LblShowok :
164167
# print '-- label layer ok '
165-
layer.attributeValueChanged.connect(self.labelLayerModified)
168+
layer.attributeValueChanged.connect(self.labelLayerModified)
169+
166170

167171

168172

169173

170174
def labelLayerModified(self, FeatureId, idx, variant):
171-
editedLayer = self.iface.activeLayer()
175+
sender = self.sender()
176+
# print ' declenche le signal'
177+
# editedLayer = self.iface.activeLayer()
178+
if not sender or not sender.type()==0:
179+
return
180+
print 'no sender caught or non vector layer'
181+
182+
print 'sender : ' + str(sender) +' layer type : ' + str(sender.type())
183+
184+
185+
172186
# print 'signal caught by labelLayerModified: layer: '+str(editedLayer.id())+'; FeatureId ' + str(FeatureId) + ' ; idx ' + str(idx) + ' const: ' + str(variant)
173187
# do nothing if layer is not a label layer
174-
if not editedLayer:
175-
return
188+
# if not editedLayer:
189+
# return
176190
# check for non vector datasources
177-
elif not editedLayer.type() == 0 :
178-
return
179-
191+
# elif not editedLayer.type() == 0 :
192+
# return
193+
editedLayer = sender
194+
180195
dp = editedLayer.dataProvider()
181196

182197
LblXok = False
@@ -206,9 +221,9 @@ def labelLayerModified(self, FeatureId, idx, variant):
206221
LblShowok = True
207222
# print 'LblShowok'
208223

209-
if not ( LblXok and LblYok and LblAlignHok and LblAlignVok and LblShowCOok and LblShowok ):
210-
iface.messageBar().pushMessage("Warning", QtGui.QApplication.translate("EasyCustomLabeling", "If your trying to edit a label with Easycustom labeling, Please keep the layer selected, else Callouts won't be drawn \n if not please ignore this message.", None, QtGui.QApplication.UnicodeUTF8), level=0, duration=3)
211-
return
224+
# if not ( LblXok and LblYok and LblAlignHok and LblAlignVok and LblShowCOok and LblShowok ):
225+
# iface.messageBar().pushMessage("Warning", QtGui.QApplication.translate("EasyCustomLabeling", "If your trying to edit a label with Easycustom labeling plugin, Please keep the label layer selected, else Callouts won't be drawn \n if not please ignore this message.", None, QtGui.QApplication.UnicodeUTF8), level=0, duration=3)
226+
# return
212227
#gets new attrib and geom > retune WKT with new label XY
213228
editFeature = QgsFeature()
214229
if editedLayer == None or editedLayer.getFeatures(QgsFeatureRequest().setFilterFid(FeatureId)).nextFeature(editFeature) is False :
@@ -620,6 +635,7 @@ def runLabel(self):
620635
# print 'runLabel exception loop '
621636
# if sourceLayer and not keepUserSelection :
622637
# sourceLayer.removeSelection()
638+
print 'exception caught'
623639
raise
624640

625641
finally :

EasyCustomLabeling/metadata.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@
99
name=EasyCustomLabeling
1010
qgisMinimumVersion=2.0
1111
description=Allows to quickly duplicate layer into memory layer ready for data defined labeling
12-
version=1.2
12+
version=1.3
1313
changelog=
14-
15-
1.2: add checks for non vector layer on project reload, when trying to reconnect existing labeling layers
14+
1.3: resolves conflicts when multiple labeling layer are active.
15+
supports having selected any layer in registry.
16+
17+
FR: solutionne les conflits d'édition d'étiquettes lorsque plusieurs couche étiquetable sont en édition
18+
résoud les erreurs lorsque la couche sélectionnée n'est pas la couche d'étiquetage
19+
solutionne les messages d'erreurs lorsque des couches non raster sont présentes.
20+
21+
22+
1.2: add checks for non vector layer on project reload and labels modifications, when trying to reconnect existing labeling layers.
23+
Add a warning if currently selected layer is not a labeling layer (Callouts won't be drawn)
24+
1625

1726
1.1: solves bug with selection if many objects are selected
1827
fr translation improvement

0 commit comments

Comments
 (0)