Example #1
0
def buildfromauto(formconfig):
    widgetsconfig = formconfig['widgets']

    outlayout = QFormLayout()
    outwidget = QWidget()
    outwidget.setLayout(outlayout)
    for config in widgetsconfig:
        widgettype = config['widget']
        field = config['field']
        name = config.get('name', field)
        label = QLabel(name)
        label.setObjectName(field + "_label")
        widgetwrapper = WidgetsRegistry.createwidget(widgettype,
                                                    layer=None,
                                                    field=field,
                                                    widget=None,
                                                    label=label,
                                                    config=None)
        widget = widgetwrapper.widget
        widget.setObjectName(field)
        layoutwidget = QWidget()
        layoutwidget.setLayout(QBoxLayout(QBoxLayout.LeftToRight))
        layoutwidget.layout().addWidget(widget)
        if config.get('rememberlastvalue', False):
            savebutton = QToolButton()
            savebutton.setObjectName('{}_save'.format(field))
            layoutwidget.layout().addWidget(savebutton)

        hidden = config.get('hidden', False)
        if not hidden:
            outlayout.addRow(label, layoutwidget)

    outlayout.addItem(QSpacerItem(10,10))
    return outwidget
Example #2
0
def buildfromauto(formconfig, base):
    widgetsconfig = formconfig['widgets']

    outlayout = QFormLayout()
    outlayout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
    outwidget = base
    outwidget.setLayout(outlayout)
    for config in widgetsconfig:
        widgettype = config['widget']
        field = config['field']
        name = config.get('name', field)
        label = QLabel(name)
        label.setObjectName(field + "_label")
        widget = WidgetsRegistry.createwidget(widgettype, parent=base)
        widget.setObjectName(field)
        layoutwidget = QWidget()
        layoutwidget.setLayout(QBoxLayout(QBoxLayout.LeftToRight))
        layoutwidget.layout().addWidget(widget)
        if config.get('rememberlastvalue', False):
            savebutton = QToolButton()
            savebutton.setObjectName('{}_save'.format(field))
            layoutwidget.layout().addWidget(savebutton)

        outlayout.addRow(label, layoutwidget)

    outlayout.addItem(QSpacerItem(10, 10))
    installflickcharm(outwidget)
    return outwidget
Example #3
0
    def bind(self):
        """
        Binds the given feature to the to the feature form.
        :param feature:
        :param defaults: The lookup containing the default values.  Note: This is only used to toggle
        the save buttons.  Default values should be set before the feature is given to the bind function.
        :return:
        """
        widgetsconfig = self.formconfig['widgets']

        for config in widgetsconfig:
            widgettype = config['widget']
            print widgettype
            field = config['field']
            widget = self.widget.findChild(QWidget, field)
            label = self.widget.findChild(QLabel, "{}_label".format(field))
            widgetconfig = config.get('config', {})
            widgetwrapper = WidgetsRegistry.createwidget(widgettype,
                                                         self.form.QGISLayer,
                                                         field,
                                                         widget,
                                                         label,
                                                         widgetconfig)

            print widgetwrapper
            if widgetwrapper is None:
                print("No widget found for {}".format(widgettype))
                continue

            readonlyrules = config.get('read-only-rules', [])

            if self.editingmode and 'editing' in readonlyrules:
                widgetwrapper.readonly = True
            elif 'insert' in readonlyrules:
                widgetwrapper.readonly = True

            if 'always' in readonlyrules:
                widgetwrapper.readonly = True

            widgetwrapper.hidden = config.get('hidden', False)

            if config.get('required', False) and not widgetwrapper.hidden:
                # All widgets state off as false unless told otherwise
                self.requiredfields[field] = False
                widgetwrapper.setrequired()
                widgetwrapper.validationupdate.connect(self.updaterequired)

            try:
                print "Null Check"
                print self.feature.fields().toList()
                value = nullcheck(self.feature[field])
                print value
            except KeyError:
                utils.warning("Can't find field {}".format(field))
                value = None

            widgetwrapper.setvalue(value)
            self._bindsavebutton(field)
            self.boundwidgets.append(widgetwrapper)

        self.validateall(self.boundwidgets)