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)
Example #2
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.
            if isinstance(value, QDateTime):
                control.setDateTime(value)
            else:
                control.setDateTime(QDateTime.fromString(value, Qt.ISODate))

            try:
                button = self.getControl(control.objectName() + "_pick",
                                         QPushButton)
                button.setIcon(QIcon(":/icons/calender"))
                button.setText("Pick")
                button.setIconSize(QSize(24, 24))
                log("{} : {}".format(control.objectName(),
                                     type(control) is QDateEdit))
                if type(control) is QDateEdit:
                    log("Type is QDateEdit")
                    button.pressed.connect(
                        partial(self.pickDateTime, control, "Date"))
                else:
                    button.pressed.connect(
                        partial(self.pickDateTime, control, "DateTime"))

            except ControlNotFound:
                pass

            self.boundControls.append(control)

        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))
                self.boundControls.append(control)

        elif hasattr(control, 'loadImage'):
            image = value
            control.loadImage(image)
            self.boundControls.append(control)

        else:
            if (isinstance(control, QComboBox) and self.layer.editType(index)
                    == QgsVectorLayer.UniqueValuesEditable):

                for v in self.layer.dataProvider().uniqueValues(index):
                    control.addItem(v, v)

                control.setEditText(value)
                self.boundControls.append(control)

            try:
                # Remove the validator because there seems to be a bug with the
                # MS SQL layers and validators.
                control.setValidator(None)
            except AttributeError:
                pass

            QgsAttributeEditor.setValue(control, self.layer, index, value)
Example #3
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.
            if isinstance(value, QDateTime):
                control.setDateTime(value)
            else:
                control.setDateTime(QDateTime.fromString(value, Qt.ISODate))
                
            try:
                button = self.getControl(control.objectName() + "_pick", QPushButton)
                button.setIcon(QIcon(":/icons/calender"))
                button.setText("Pick")
                button.setIconSize(QSize(24, 24))
                log("{} : {}".format(control.objectName(), type(control) is QDateEdit))
                if type(control) is QDateEdit:
                    log("Type is QDateEdit")
                    button.pressed.connect(partial(self.pickDateTime, control, "Date"))
                else:
                    button.pressed.connect(partial(self.pickDateTime, control, "DateTime"))
                    
            except ControlNotFound:
                pass
            
            self.boundControls.append(control)

        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))
                self.boundControls.append(control)
                
        elif hasattr(control, 'loadImage'):
            image = value
            control.loadImage(image)
            self.boundControls.append(control)
            
        else:
            if (isinstance(control, QComboBox) and
                self.layer.editType(index) == QgsVectorLayer.UniqueValuesEditable):
                
                for v in self.layer.dataProvider().uniqueValues(index):
                    control.addItem(v, v)
                                    
                control.setEditText(value)
                self.boundControls.append(control)
                
            try:
                # Remove the validator because there seems to be a bug with the 
                # MS SQL layers and validators.
                control.setValidator(None)
            except AttributeError:
                pass
            
            QgsAttributeEditor.setValue(control, self.layer, index, value)