Graphics Reference
In-Depth Information
SIGNAL("valueChanged(int)"),
self.widthChanged)
self.form = QFormLayout()
self.form.addRow('Length', self.lengthField)
self.form.addRow('Width', self.widthField)
self.setLayout(self.form)
def setSymbolLayer(self, layer):
if layer.layerType() == "Cross":
self.layer = layer
self.lengthField.setValue(layer.length)
self.widthField.setValue(layer.width)
def symbolLayer(self):
return self.layer
def lengthChanged(self, n):
self.layer.length = n
self.emit(SIGNAL("changed()"))
def widthChanged(self, n):
self.layer.width = n
self.emit(SIGNAL("changed()"))
We define the contents of our widget using the standard
__init__()
initializer.
As you can see, we define two fields,
lengthField
and
widthField
, which
let the user change the
length
and
width
properties respectively for our sym-
bol layer.
The
setSymbolLayer()
method tells the widget which
QgsSymbolLay-
erV2
object to use, while the
symbolLayer()
method returns the
QgsSym-
bolLayerV2
object this widget is editing. Finally, the two
XXXChanged()
methods are called when the user changes the value of the fields, allowing us to
update the symbol layer's properties to match the value set by the user.
• Finally, you will need to register your symbol layer. To do this, create a subclass
of
QgsSymbolLayerV2AbstractMetadata
and pass it to the
QgsSym-