Tengo un formulario personalizado con algunos de validación.
Uno de estos validación es si el valor de atributo es NULO. El valor de NULL representación en el QGIS es float de acuerdo a la Configuración->Opciones.
Cómo comprobar si el valor en el QLineEdit es NULA de acuerdo con el QGIS valor NULO?
Cuando sé de QGIS representación sin problemas, pero si alguien los cambios de este parámetro... oh, oh!
Im trate de esta manera:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from pyspatialite import dbapi2 as sqlite
fgeocodigo = None
fsittip = None
fbairro = None
fasubn = None
fuca = None
faglom = None
faui = None
fti = None
ftq = None
feuv = None
fedoc = None
feno = None
fecol = None
st_ok = None
fDlg = None
ls = None
def formOpen(dialog,layerid,featureid):
global fDlg
fDlg = dialog
global fgeocodigo
global fsittip
global fbairro
global fasubn
global fuca
global faglom
global faui
global fti
global ftq
global feuv
global fedoc
global feno
global fecol
global buttonBox
global ls
fgeocodigo = dialog.findChild(QLineEdit,"cd_geocodigo")
fsittip = dialog.findChild(QLineEdit,"cd_sit_tip")
fbairro = dialog.findChild(QLineEdit,"bairro")
fasubn = dialog.findChild(QLineEdit,"asubn")
fuca = dialog.findChild(QLineEdit,"uca")
faglom = dialog.findChild(QLineEdit,"aglom")
faui = dialog.findChild(QLineEdit,"aui")
fti = dialog.findChild(QLineEdit,"ti")
ftq = dialog.findChild(QLineEdit,"quilom")
feuv = dialog.findChild(QLineEdit,"ctg_euv")
fedoc = dialog.findChild(QLineEdit,"ctg_edoc")
feno = dialog.findChild(QLineEdit,"ctg_eno")
fecol = dialog.findChild(QLineEdit,"ctg_ecol")
buttonBox = dialog.findChild(QDialogButtonBox,"buttonBox")
file_db_n = QgsProject.instance().readPath("./") + "\\DB\\" + "db.sqlite"
conn = sqlite.connect(file_db_n)
cur = conn.cursor()
cur.execute('SELECT cd_sit_tip FROM T_Sittipo')
st = cur.fetchall()
ls = []
for s in st: ls.append(s[0])
fgeocodigo.textChanged.connect(valida_form)
fsittip.textChanged.connect(valida_form)
fasubn.textChanged.connect(valida_form)
fbairro.textChanged.connect(valida_form)
fuca.textChanged.connect(valida_form)
faglom.textChanged.connect(valida_form)
faui.textChanged.connect(valida_form)
fti.textChanged.connect(valida_form)
ftq.textChanged.connect(valida_form)
feuv.textChanged.connect(valida_form)
fedoc.textChanged.connect(valida_form)
feno.textChanged.connect(valida_form)
fecol.textChanged.connect(valida_form)
def valida_form(text):
flag = True
#---[Valida geocodigo]
if len(str(fgeocodigo.text())) != 15:
fgeocodigo.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
else:
fgeocodigo.setStyleSheet("")
#---[Valida sittip]
if str(fsittip.text()) not in ls:
fsittip.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
else:
fsittip.setStyleSheet("")
#---[Valida asubn]
if len(str(fsittip.text())) == 2:
if str(fsittip.text()) in ['11', '31', '41'] and ((str(fasubn.text()) is None) or (str(fasubn.text()) == '')):
fasubn.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
elif str(fsittip.text()) not in ['11', '31', '41'] and not ((str(fasubn.text()) is None) or (str(fasubn.text()) == '')):
fasubn.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
else:
fasubn.setStyleSheet("")
#---[Valida bairro]
if len(str(fsittip.text())) == 2:
if str(fsittip.text())[0] not in ['1', '3', '4'] and not ((str(fbairro.text()) is None) or (str(fbairro.text()) == '')):
fbairro.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
else:
fbairro.setStyleSheet("")
#---[Valida aglom]
if len(str(fsittip.text())) == 2:
faglom.setStyleSheet("")
if str(fsittip.text())[0] in ['5', '6', '7'] and ((str(faglom.text()) is None) or (str(faglom.text()) == '')):
faglom.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
if str(fsittip.text()) in ['10','11','12','13','14','16','18','20','22','23','24','25','26','27','30','31','32','33','34','36','37','38','40','41','42','43','44','46','47','48','68','80','82','83','84','86','87'] and \
not ((str(faglom.text()) is None) or (str(faglom.text()) == '')):
faglom.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
if str(fsittip.text()) in ['28','88'] and ((str(faglom.text()) is None) or (str(faglom.text()) == '')):
faglom.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
#---[Valida aui]
if len(str(fsittip.text())) == 2:
if str(fsittip.text()) in ['30', '31', '32', '33', '35', '36', '37', '39'] and ((str(faui.text()) is None) or (str(faui.text()) == '')):
faui.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
elif str(fsittip.text()) not in ['30', '31', '32', '33', '35', '36', '37', '39'] and not ((str(faui.text()) is None) or (str(faui.text()) == '')):
faui.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
else:
faui.setStyleSheet("")
#---[Valida ti]
if len(str(fsittip.text())) == 2:
if str(fsittip.text())[1] == '5' and ((str(fti.text()) is None) or (str(fti.text()) == '')):
fti.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
elif str(fsittip.text())[1] != '5' and not ((str(fti.text()) is None) or (str(fti.text()) == '')):
fti.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
else:
fti.setStyleSheet("")
#---[Valida tq]
if len(str(fsittip.text())) == 2:
if str(fsittip.text())[1] == '9' and ((str(ftq.text()) is None) or (str(ftq.text()) == '')):
ftq.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
elif str(fsittip.text())[1] != '9' and not ((str(ftq.text()) is None) or (str(ftq.text()) == '')):
ftq.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
else:
ftq.setStyleSheet("")
#---[Valida qtd dom]
if len(str(fsittip.text())) == 2:
if len(str(feuv.text())) == 0:
feuv.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
else:
feuv.setStyleSheet("")
if len(str(fedoc.text())) == 0:
fedoc.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
else:
fedoc.setStyleSheet("")
if len(str(feno.text())) == 0:
feno.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
else:
feno.setStyleSheet("")
if len(str(fecol.text())) == 0:
fecol.setStyleSheet("background-color: rgba(255, 100, 100, 150);")
flag = False
else:
fecol.setStyleSheet("")
buttonBox.button(QDialogButtonBox.Ok).setEnabled(flag)
Veo que esto de Nathan post pero no puedo poner en práctica.