def update(self, cursor): if cursor is None: return try: feature = cursor.feature except NoFeature as ex: utils.exception(ex) return form = cursor.form layer = cursor.layer clear_image_cache() self.countLabel.setText(str(cursor)) info1, results = self.generate_info("info1", self.project, layer, feature.id(), feature, countlabel=str(cursor)) info2, _ = self.generate_info("info2", self.project, layer, feature.id(), feature, lastresults=results[0]) if form: name = "{}".format(layer.name(), form.label) else: name = layer.name() info = dict(TITLE=name, INFO1=info1, INFO2=info2) html = updateTemplate(info, infotemplate) self.attributesView.setHtml(html, templates.baseurl) tools = self.project.layer_tools(layer) hasform = not form is None print tools editattributes = 'edit_attributes' in tools or 'inspection' in tools or hasform print editattributes editgeom = 'edit_geom' in tools and hasform deletefeature = 'delete' in tools and hasform self.deleteFeatureButton.setVisible(deletefeature) self.quickInspectButton.setVisible('inspection' in tools) self.editButton.setVisible(editattributes) self.editGeomButton.setVisible(editgeom) self.featureupdated.emit(layer, feature, cursor.features)
def update(self, cursor): if cursor is None: return try: feature = cursor.feature except NoFeature as ex: utils.exception(ex) return form = cursor.form layer = cursor.layer clear_image_cache() self.countLabel.setText(str(cursor)) info1, results = self.generate_info("info1", self.project, layer, feature.id(), feature, countlabel=str(cursor)) info2, _= self.generate_info("info2", self.project, layer, feature.id(), feature, lastresults=results[0]) if form: name = "{}".format(layer.name(), form.label) else: name = layer.name() info = dict(TITLE=name, INFO1=info1, INFO2=info2) html = updateTemplate(info, infotemplate) self.attributesView.setHtml(html, templates.baseurl) tools = self.project.layer_tools(layer) hasform = not form is None editattributes = 'edit_attributes' in tools or 'inspection' in tools and hasform editgeom = 'edit_geom' in tools and hasform deletefeature = 'delete' in tools and hasform self.deleteFeatureButton.setVisible(deletefeature) self.editButton.setVisible(editattributes) self.editGeomButton.setVisible(editgeom) self.featureupdated.emit(layer, feature, cursor.features)
def setupui(self): """ Setup the widget in the form """ self.geomwidget = self.findcontrol("__geomwidget") widgetsconfig = copy.deepcopy(self.formconfig['widgets']) try: widgetsconfig = self.get_widgets(widgetsconfig) except AttributeError: pass layer = self.form.QGISLayer # Crash in QGIS if you lookup a field that isn't found. # We just make a dict with all fields lower because QgsFields is case sensitive. fields = { field.name().lower(): field for field in layer.fields().toList() } # Build a lookup for events self.events = collections.defaultdict(list) for event in self.form.events: self.events[event['source']].append(event) widgetsconfig = copy.deepcopy(widgetsconfig) self.sectionwidgets = {} currentsection = None for config in widgetsconfig: widgettype = config['widget'] if widgettype == "Section": name = config['name'] currentsection = name self.sectionwidgets[name] = [] continue field = config['field'] if not field: utils.info("Skipping widget. No field defined") continue field = field.lower() if field in self.boundwidgets: utils.warning( "Can't bind the same field ({}) twice.".format(field)) continue widget = self.findcontrol(field) if widget is None: widget = roam.editorwidgets.core.createwidget(widgettype) config['hidden'] = True utils.info( "No widget named {} found so we have made one.".format( field)) label = self.findcontrol("{}_label".format(field)) if label is None: utils.debug("No label found for {}".format(field)) widgetconfig = config.get('config', {}) widgetconfig['formwidget'] = self try: qgsfield = fields[field] except KeyError: utils.log("No field for ({}) found".format(field)) continue context = dict(project=self.form.project, form=self.form, featureform=self) try: widgetwrapper = roam.editorwidgets.core.widgetwrapper( widgettype=widgettype, layer=self.form.QGISLayer, field=qgsfield, widget=widget, label=label, config=widgetconfig, context=context, main_config=config) except EditorWidgetException as ex: utils.exception(ex) continue widgetwrapper.default_events = config.get('default_events', ['capture']) readonlyrules = config.get('read-only-rules', []) if self.editingmode and 'editing' in readonlyrules: widgetwrapper.readonly = True elif 'insert' in readonlyrules or 'always' in readonlyrules: widgetwrapper.readonly = True widgetwrapper.hidden = config.get('hidden', False) widgetwrapper.newstyleform = self.formconfig.get("newstyle", False) widgetwrapper.required = config.get('required', False) # Only connect widgets that have events if widgetwrapper.id in self.events: widgetwrapper.valuechanged.connect( partial(self.check_for_update_events, widgetwrapper)) widgetwrapper.valuechanged.connect(self.updaterequired) try: changedslot = getattr(self, "widget_{}_changed".format(field)) widgetwrapper.valuechanged.connect(changedslot) except AttributeError: pass widgetwrapper.largewidgetrequest.connect( RoamEvents.show_widget.emit) self._bindsavebutton(field) self.boundwidgets[field] = widgetwrapper try: self.widgetidlookup[config['_id']] = widgetwrapper except KeyError: pass if currentsection: self.sectionwidgets[currentsection].append(widgetwrapper)
def setupui(self): """ Setup the widget in the form """ self.geomwidget = self.findcontrol("__geomwidget") widgetsconfig = copy.deepcopy(self.formconfig['widgets']) try: widgetsconfig = self.get_widgets(widgetsconfig) except AttributeError: pass layer = self.form.QGISLayer # Crash in QGIS if you lookup a field that isn't found. # We just make a dict with all fields lower because QgsFields is case sensitive. fields = {field.name().lower():field for field in layer.pendingFields().toList()} # Build a lookup for events self.events = collections.defaultdict(list) for event in self.form.events: self.events[event['source']].append(event) widgetsconfig = copy.deepcopy(widgetsconfig) self.sectionwidgets = {} currentsection = None for config in widgetsconfig: widgettype = config['widget'] if widgettype == "Section": name = config['name'] currentsection = name self.sectionwidgets[name] = [] continue field = config['field'] if not field: utils.info("Skipping widget. No field defined") continue field = field.lower() if field in self.boundwidgets: utils.warning("Can't bind the same field ({}) twice.".format(field)) continue widget = self.findcontrol(field) if widget is None: widget = roam.editorwidgets.core.createwidget(widgettype) config['hidden'] = True utils.info("No widget named {} found so we have made one.".format(field)) label = self.findcontrol("{}_label".format(field)) if label is None: utils.debug("No label found for {}".format(field)) widgetconfig = config.get('config', {}) widgetconfig['formwidget'] = self try: qgsfield = fields[field] except KeyError: utils.log("No field for ({}) found".format(field)) context = dict(project=self.form.project, form=self.form, featureform=self) try: widgetwrapper = roam.editorwidgets.core.widgetwrapper(widgettype=widgettype, layer=self.form.QGISLayer, field=qgsfield, widget=widget, label=label, config=widgetconfig, context=context) except EditorWidgetException as ex: utils.exception(ex) continue widgetwrapper.default_events = config.get('default_events', ['capture']) readonlyrules = config.get('read-only-rules', []) if self.editingmode and 'editing' in readonlyrules: widgetwrapper.readonly = True elif 'insert' in readonlyrules or 'always' in readonlyrules: widgetwrapper.readonly = True widgetwrapper.hidden = config.get('hidden', False) widgetwrapper.newstyleform = self.formconfig.get("newstyle", False) widgetwrapper.required = config.get('required', False) widgetwrapper.id = config.get('_id', '') # Only connect widgets that have events if widgetwrapper.id in self.events: widgetwrapper.valuechanged.connect(partial(self.check_for_update_events, widgetwrapper)) widgetwrapper.valuechanged.connect(self.updaterequired) try: changedslot = getattr(self, "widget_{}_changed".format(field)) widgetwrapper.valuechanged.connect(changedslot) except AttributeError: pass widgetwrapper.largewidgetrequest.connect(RoamEvents.show_widget.emit) self._bindsavebutton(field) self.boundwidgets[field] = widgetwrapper try: self.widgetidlookup[config['_id']] = widgetwrapper except KeyError: pass if currentsection: self.sectionwidgets[currentsection].append(widgetwrapper)
def setupui(self): """ Setup the widget in the form """ widgetsconfig = self.formconfig['widgets'] layer = self.form.QGISLayer # Crash in QGIS if you lookup a field that isn't found. # We just make a dict with all fields lower because QgsFields is case sensitive. fields = {field.name().lower():field for field in layer.pendingFields().toList()} for config in widgetsconfig: widgettype = config['widget'] field = config['field'] if not field: utils.info("Skipping widget. No field defined") continue field = field.lower() if field in self.boundwidgets: utils.warning("Sorry you can't bind the same field ({}) twice.".format(field)) utils.warning("{} for field {} has been ignored in setup".format(widget, field)) continue widget = self.findcontrol(field) if widget is None: widget = roam.editorwidgets.core.createwidget(widgettype) config['hidden'] = True utils.info("No widget named {} found so we have made one.".format(field)) label = self.findcontrol("{}_label".format(field)) if label is None: utils.debug("No label found for {}".format(field)) widgetconfig = config.get('config', {}) qgsfield = fields[field] try: widgetwrapper = roam.editorwidgets.core.widgetwrapper(widgettype=widgettype, layer=self.form.QGISLayer, field=qgsfield, widget=widget, label=label, config=widgetconfig) except EditorWidgetException as ex: utils.exception(ex) continue readonlyrules = config.get('read-only-rules', []) if self.editingmode and 'editing' in readonlyrules: widgetwrapper.readonly = True elif 'insert' in readonlyrules or 'always' in readonlyrules: widgetwrapper.readonly = True widgetwrapper.hidden = config.get('hidden', False) widgetwrapper.required = config.get('required', False) widgetwrapper.valuechanged.connect(self.updaterequired) widgetwrapper.largewidgetrequest.connect(RoamEvents.show_widget.emit) self._bindsavebutton(field) self.boundwidgets[field] = widgetwrapper
def setupui(self): """ Setup the widget in the form """ self.geomwidget = self.findcontrol("__geomwidget") widgetsconfig = self.formconfig['widgets'] layer = self.form.QGISLayer # Crash in QGIS if you lookup a field that isn't found. # We just make a dict with all fields lower because QgsFields is case sensitive. fields = { field.name().lower(): field for field in layer.pendingFields().toList() } for config in widgetsconfig: widgettype = config['widget'] field = config['field'] if not field: utils.info("Skipping widget. No field defined") continue field = field.lower() if field in self.boundwidgets: utils.warning( "Can't bind the same field ({}) twice.".format(field)) continue widget = self.findcontrol(field) if widget is None: widget = roam.editorwidgets.core.createwidget(widgettype) config['hidden'] = True utils.info( "No widget named {} found so we have made one.".format( field)) label = self.findcontrol("{}_label".format(field)) if label is None: utils.debug("No label found for {}".format(field)) widgetconfig = config.get('config', {}) qgsfield = fields[field] try: widgetwrapper = roam.editorwidgets.core.widgetwrapper( widgettype=widgettype, layer=self.form.QGISLayer, field=qgsfield, widget=widget, label=label, config=widgetconfig) except EditorWidgetException as ex: utils.exception(ex) continue readonlyrules = config.get('read-only-rules', []) if self.editingmode and 'editing' in readonlyrules: widgetwrapper.readonly = True elif 'insert' in readonlyrules or 'always' in readonlyrules: widgetwrapper.readonly = True widgetwrapper.hidden = config.get('hidden', False) widgetwrapper.required = config.get('required', False) widgetwrapper.valuechanged.connect(self.updaterequired) widgetwrapper.largewidgetrequest.connect( RoamEvents.show_widget.emit) self._bindsavebutton(field) self.boundwidgets[field] = widgetwrapper