|
1 | 1 | # -*- coding: iso-8859-1 -*- |
2 | | -""" |
| 2 | +""" |
3 | 3 | /*************************************************************************** |
4 | 4 | Name :EasyCustomLabeling |
5 | 5 | Description : plugin allowing a quick duplication of layer, ready to start manual customisation of labels (position, size, colors.. ) based on data fields |
|
35 | 35 |
|
36 | 36 | # load translation libraries |
37 | 37 |
|
38 | | -class EasyCustomLabeling: |
| 38 | +class EasyCustomLabeling(QObject): |
| 39 | +# class EasyCustomLabeling: |
39 | 40 |
|
40 | 41 | def __init__(self, iface): |
41 | 42 | # Save reference to the QGIS interface |
| 43 | + QObject.__init__(self) #init from QObject parent |
42 | 44 | self.iface = iface |
43 | 45 | self.qgsVersion = unicode(QGis.QGIS_VERSION_INT) |
44 | 46 | print '# EasyCustomLabeling debug trace: plugin loaded at ' + str(datetime.datetime.now()) |
@@ -119,6 +121,7 @@ def initGui(self): |
119 | 121 | #disconnects if label layers closed? |
120 | 122 |
|
121 | 123 | def labelLayerChecked(self): |
| 124 | + |
122 | 125 |
|
123 | 126 | # print 'projet chargé: ' |
124 | 127 | # Checks if some labeling layers are already there, and replug, if not already labelLayerModified events |
@@ -162,21 +165,33 @@ def labelLayerChecked(self): |
162 | 165 |
|
163 | 166 | if LblXok and LblYok and LblAlignHok and LblAlignVok and LblShowCOok and LblShowok : |
164 | 167 | # print '-- label layer ok ' |
165 | | - layer.attributeValueChanged.connect(self.labelLayerModified) |
| 168 | + layer.attributeValueChanged.connect(self.labelLayerModified) |
| 169 | + |
166 | 170 |
|
167 | 171 |
|
168 | 172 |
|
169 | 173 |
|
170 | 174 | 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 | + |
172 | 186 | # print 'signal caught by labelLayerModified: layer: '+str(editedLayer.id())+'; FeatureId ' + str(FeatureId) + ' ; idx ' + str(idx) + ' const: ' + str(variant) |
173 | 187 | # do nothing if layer is not a label layer |
174 | | - if not editedLayer: |
175 | | - return |
| 188 | + # if not editedLayer: |
| 189 | + # return |
176 | 190 | # 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 | + |
180 | 195 | dp = editedLayer.dataProvider() |
181 | 196 |
|
182 | 197 | LblXok = False |
@@ -206,9 +221,9 @@ def labelLayerModified(self, FeatureId, idx, variant): |
206 | 221 | LblShowok = True |
207 | 222 | # print 'LblShowok' |
208 | 223 |
|
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 |
212 | 227 | #gets new attrib and geom > retune WKT with new label XY |
213 | 228 | editFeature = QgsFeature() |
214 | 229 | if editedLayer == None or editedLayer.getFeatures(QgsFeatureRequest().setFilterFid(FeatureId)).nextFeature(editFeature) is False : |
@@ -620,6 +635,7 @@ def runLabel(self): |
620 | 635 | # print 'runLabel exception loop ' |
621 | 636 | # if sourceLayer and not keepUserSelection : |
622 | 637 | # sourceLayer.removeSelection() |
| 638 | + print 'exception caught' |
623 | 639 | raise |
624 | 640 |
|
625 | 641 | finally : |
|
0 commit comments