Example #1
0
    def bindValueToControl(self, control, value, index=0):
        """
        Binds a control to the supplied value.

        control - QWidget based control that takes the new value
        value - A QVariant holding the value
        """
        if isinstance(control, QDateTimeEdit):
            # Can be removed after http://hub.qgis.org/issues/7013 is fixed.
            control.setDateTime(QDateTime.fromString(value.toString(), Qt.ISODate))
            button = self.getControl(control.objectName() + "_pick", QPushButton)
            if not button:
                return

            button.setIcon(QIcon(":/icons/calender"))
            button.setText("Pick")
            button.setIconSize(QSize(24, 24))
            button.pressed.connect(partial(self.pickDateTime, control, "DateTime"))

        elif isinstance(control, QPushButton):
            if control.text() == "Drawing":
                control.setIcon(QIcon(":/icons/draw"))
                control.setIconSize(QSize(24, 24))
                control.pressed.connect(partial(self.loadDrawingTool, control))
        else:
            if self.layer.editType(index) == QgsVectorLayer.UniqueValues:
                editable = control.isEditable()

            widget = QgsAttributeEditor.createAttributeEditor(self.forminstance, control, self.layer, index, value)
            wasset = QgsAttributeEditor.setValue(control, self.layer, index, value)
            log(widget)

            try:
                control.setValidator(None)
            except AttributeError:
                pass

            if self.layer.editType(index) == QgsVectorLayer.UniqueValues:
                # Set the control back to the editable state the form says it should be.
                # This is to work around http://hub.qgis.org/issues/7012
                control.setEditable(editable)