Ejemplo n.º 1
0
    def loaded(self):
        #Asi damos tiempo a que el control se añada al formulario
        self._loaded = True
        value = None
        while True: #Ahora podemos buscar el cursor ... porque ya estamos añadidos al formulario
            parent_cursor = getattr(self._parent,"_cursor", None)
            if parent_cursor: 
                #print("FLFIeldDB(%s):Pariente %s con cursor encontrado" % (self._fieldAlias, self._parent))
                break
            new_parent = self._parent.parentWidget()
            if new_parent is None: 
                print("FLFIeldDB(%s):No se ha encontrado al padre con cursor" % self._fieldAlias)
                break
            self._parent = new_parent
            
        self._cursor = self._parent.parentWidget()._cursor
        if not self._cursor:
            self._cursor = self._parent._cursor
        #Si es un dato externo ...
        if not self._tableName is None and not self._tableName == "":
            self._editable = False
            cursorFr = FLSqlCursor(self._tableName)
            if not cursorFr._model is None and not isinstance(cursorFr._model, DefFun): #Para las tablas qye no existen
                #print("El tipo model es %s" % type(cursorFr._model))
                self._tipo = cursorFr._model.fieldType(self._fieldRelation)
                valueForeignField = self._cursor.valueBuffer(self._foreignField)
                if not valueForeignField is None and not valueForeignField == "":
                    if self._tipo == 'uint':
                        filtro = "%s = %s" % (self._fieldRelation, str(valueForeignField))
                    else:
                        filtro = "%s = '%s'" % (self._fieldRelation, str(valueForeignField))   
                    cursorFr.setMainFilter(filtro)
                    cursorFr.refresh()
                    cursorFr.first()
                    value = cursorFr.valueBuffer(self._fieldName)
                else:
                    value=""
            else:
                print("FLFieldDB: Campo %s.%s no encontrada." % (self._tableName, self._fieldName))
                value=""

        else:
            self._tableName =  self._cursor.table().name
            #print("Solicitando Alias de %s a tabla %s" % (self._fieldName, self._tableName))
            self.setFieldAlias(self._cursor._model.alias(self._fieldName))
            self._tipo = self._cursor._model.fieldType(self._fieldName)
            value = self._cursor.valueBuffer(self._fieldName)
        
        
        #print("\n\nCampo = %s.%s, Tipo = %s\nvalue = \"%s\"\nEditable = %s" % (self._tableName, self.fieldName, self._tipo, value, self._editable))
        if self._tipo == 'string' or self._tipo == 'uint' or self._tipo == 'double' or self._tipo == 'date' or self._tipo == 'serial':
            self._dataControl = QtGui.QLineEdit()
        elif self._tipo == 'bool':
            self._dataControl = QtGui.QCheckBox()
        elif self._tipo == 'stringlist':
            self._dataControl = QtGui.QLineEdit()
        else:
            print("FLFIeldDB(%s):Tipo de dato desconocido (%s) en %s.%s.¿Existe ese campo?" % (self._fieldAlias, self._tipo , self._tableName, self._fieldName ))
            self._dataControl = QtGui.QLineEdit()
        
        self._layout.addWidget(self._dataControl)
        
        if value:
            self.setValue(str(value))
        self.refresh()