Ejemplo n.º 1
0
    def load_feature_form(self,
                          feature,
                          form,
                          editmode,
                          clear=True,
                          callback=None):
        """
        Opens the form for the given feature.
        """
        def _sink(_):
            pass

        if not callback:
            callback = _sink

        if clear:
            # Clear all the other open widgets that might be open.
            self.clear(dontemit=True)

        # One capture geometry, even for sub forms?
        # HACK Remove me and do something smarter
        roam.qgisfunctions.capturegeometry = feature.geometry()

        # Hold a reference to the fields because QGIS will let the
        # go out of scope and we get crashes. Yay!
        layer = form.QGISLayer
        self.fields = feature.fields()
        attributes = feature.attributes()

        fields = [field.name().lower() for field in self.fields]
        # Something is strange with default values and spatilite. Just delete them for now.
        if layer.dataProvider().name() == 'spatialite':
            pkindexes = layer.dataProvider().pkAttributeIndexes()
            for index in pkindexes:
                del fields[index]
                del attributes[index]
        values = CaseInsensitiveDict(zip(fields, attributes))

        defaultvalues = {}
        if not editmode:
            defaultwidgets = form.widgetswithdefaults()
            defaultvalues = defaults.default_values(defaultwidgets, feature,
                                                    layer)
            defaultvalues.update(featureform.loadsavedvalues(layer))

        values.update(defaultvalues)

        initconfig = dict(form=form, canvas=self.canvas, editmode=editmode)

        config = dict(editmode=editmode,
                      layers=QgsMapLayerRegistry.instance().mapLayers(),
                      feature=feature)

        self.add_widget(FeatureFormWidgetEditor,
                        values,
                        callback,
                        config,
                        initconfig=initconfig)
Ejemplo n.º 2
0
    def load_feature_form(self, feature, form, editmode, clear=True, callback=None,
                          cancel_callback=None):
        """
        Opens the form for the given feature.
        """
        def _sink(_):
            pass

        if not callback:
            callback = _sink

        if not cancel_callback:
            cancel_callback = _sink

        if clear:
            # Clear all the other open widgets that might be open.
            self.clear(dontemit=True)

        layer = form.QGISLayer
        attributes = feature.attributes()

        fields = [field.name().lower() for field in layer.pendingFields()]
        # Something is strange with default values and spatilite. Just delete them for now.
        if layer.dataProvider().name() == 'spatialite':
            pkindexes = layer.dataProvider().pkAttributeIndexes()
            for index in pkindexes:
                del fields[index]
                del attributes[index]
        values = CaseInsensitiveDict(zip(fields, attributes))

        savedvalues = {}
        if not editmode:
            savedvalues = featureform.loadsavedvalues(form)
            values.update(savedvalues)
            if form.template_values:
                values.update(form.template_values)

        suppressform = form.suppressform
        if editmode:
            suppressform = False

        initconfig = dict(form=form,
                          canvas=self.canvas,
                          editmode=editmode,
                          defaults=savedvalues,
                          suppressform=suppressform,
                          feature=feature)

        config = dict(editmode=editmode,
                      layers=QgsMapLayerRegistry.instance().mapLayers(),
                      feature=feature)

        if self.project:
            layertools = self.project.layer_tools(layer)
            config['tools'] = layertools
        self.add_widget(FeatureFormWidgetEditor, values, callback, config,
                        initconfig=initconfig,
                        cancel_callback=cancel_callback)
Ejemplo n.º 3
0
    def load_feature_form(self, feature, form, editmode, clear=True, callback=None):
        """
        Opens the form for the given feature.
        """
        def _sink(_):
            pass

        if not callback:
            callback = _sink

        if clear:
            # Clear all the other open widgets that might be open.
            self.clear(dontemit=True)

        # One capture geometry, even for sub forms?
        # HACK Remove me and do something smarter
        roam.qgisfunctions.capturegeometry = feature.geometry()

        # Hold a reference to the fields because QGIS will let the
        # go out of scope and we get crashes. Yay!
        layer = form.QGISLayer
        self.fields = feature.fields()
        attributes = feature.attributes()

        fields = [field.name().lower() for field in self.fields]
        # Something is strange with default values and spatilite. Just delete them for now.
        if layer.dataProvider().name() == 'spatialite':
            pkindexes = layer.dataProvider().pkAttributeIndexes()
            for index in pkindexes:
                del fields[index]
                del attributes[index]
        values = CaseInsensitiveDict(zip(fields, attributes))

        defaultvalues = {}
        if not editmode:
            defaultwidgets = form.widgetswithdefaults()
            defaultvalues = defaults.default_values(defaultwidgets, feature, layer)
            defaultvalues.update(featureform.loadsavedvalues(layer))

        values.update(defaultvalues)

        initconfig = dict(form=form,
                          canvas=self.canvas,
                          editmode=editmode,
                          defaults=defaultvalues)

        config = dict(editmode=editmode,
                      layers=QgsMapLayerRegistry.instance().mapLayers(),
                      feature=feature)

        if self.project:
            layertools = self.project.layer_tools(layer)
            config['tools'] = layertools
        self.add_widget(FeatureFormWidgetEditor, values, callback, config, initconfig=initconfig)
Ejemplo n.º 4
0
    def load_feature_form(self,
                          feature,
                          form,
                          editmode,
                          clear=True,
                          callback=None):
        """
        Opens the form for the given feature.
        """
        def _sink(_):
            pass

        if not callback:
            callback = _sink

        if clear:
            # Clear all the other open widgets that might be open.
            self.clear(dontemit=True)

        layer = form.QGISLayer
        attributes = feature.attributes()

        fields = [field.name().lower() for field in layer.pendingFields()]
        # Something is strange with default values and spatilite. Just delete them for now.
        if layer.dataProvider().name() == 'spatialite':
            pkindexes = layer.dataProvider().pkAttributeIndexes()
            for index in pkindexes:
                del fields[index]
                del attributes[index]
        values = CaseInsensitiveDict(zip(fields, attributes))

        savedvalues = {}
        if not editmode:
            savedvalues = featureform.loadsavedvalues(layer)
            values.update(savedvalues)

        initconfig = dict(form=form,
                          canvas=self.canvas,
                          editmode=editmode,
                          defaults=savedvalues)

        config = dict(editmode=editmode,
                      layers=QgsMapLayerRegistry.instance().mapLayers(),
                      feature=feature)

        if self.project:
            layertools = self.project.layer_tools(layer)
            config['tools'] = layertools
        self.add_widget(FeatureFormWidgetEditor,
                        values,
                        callback,
                        config,
                        initconfig=initconfig)
Ejemplo n.º 5
0
    def getvalues(self, no_defaults=False):
        def shouldsave(field):
            name = "{}_save".format(field)
            button = self.findcontrol(name)
            if not button is None:
                return button.isChecked()

        savedvalues = {}
        values = CaseInsensitiveDict(self.bindingvalues)
        for field, wrapper in self.boundwidgets.items():
            if not no_defaults and wrapper.get_default_value_on_save:
                value = self.widget_default(field)
            else:
                value = wrapper.value()
                extradata = wrapper.extraData()
                values.update(extradata)

            # TODO this should put pulled out and unit tested. MOVE ME!
            # NOTE: This is photo widget stuff and really really doesn't belong here.
            if hasattr(
                    wrapper,
                    'savetofile') and wrapper.savetofile and wrapper.saveable:
                if wrapper.filename and self.editingmode:
                    name = os.path.basename(wrapper.filename)
                    name, extension = os.path.splitext(name)

                    if wrapper.modified:
                        if not name.endswith("_edited"):
                            newend = "_edited{}".format(extension)
                            value = name + newend
                        else:
                            value = os.path.basename(wrapper.filename)
                    else:
                        value = os.path.basename(wrapper.filename)
                else:
                    if wrapper.modified:
                        value = wrapper.get_filename()
                    else:
                        value = ''

            if shouldsave(field):
                savedvalues[field] = value
            values[field] = value

        return values, savedvalues
Ejemplo n.º 6
0
    def getvalues(self, no_defaults=False):
        def shouldsave(field):
            name = "{}_save".format(field)
            button = self.findcontrol(name)
            if not button is None:
                return button.isChecked()

        savedvalues = {}
        values = CaseInsensitiveDict(self.bindingvalues)
        for field, wrapper in self.boundwidgets.iteritems():
            if not no_defaults and wrapper.get_default_value_on_save:
                value = self.widget_default(field)
            else:
                value = wrapper.value()
                extradata = wrapper.extraData()
                values.update(extradata)

            # TODO this should put pulled out and unit tested. MOVE ME!
            # NOTE: This is photo widget stuff and really really doesn't belong here.
            if hasattr(wrapper, 'savetofile') and wrapper.savetofile:
                if wrapper.filename and self.editingmode:
                    name = os.path.basename(wrapper.filename)
                    name, extension = os.path.splitext(name)

                    if wrapper.modified:
                        if not name.endswith("_edited"):
                            newend = "_edited{}".format(extension)
                            value = name + newend
                        else:
                            value = os.path.basename(wrapper.filename)
                    else:
                        value = os.path.basename(wrapper.filename)
                else:
                    if wrapper.modified:
                        value = wrapper.get_filename()
                    else:
                        value = ''

            if shouldsave(field):
                savedvalues[field] = value
            values[field] = value

        return values, savedvalues