[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] How to update a relationModel
From: "Stefano Z." <mie.iscrizioni () gmail ! com>
Date: 2009-06-29 15:44:30
Message-ID: 2c242de40906290844n2c599bcbh23b719bdeae4078e () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
hello
i need to know how to update a combobox linked to a datawidgetmapper
when the table in relation with the mapper model is modified by en external
application.
code:
def setupModels(self):
"""
Initialize all the application models
"""
# setup masterModel
self.mModel = QSqlRelationalTableModel(self)
self.mModel.setTable(QString(" fattmaster"))
self.mModel.setSort(MDATA, Qt.AscendingOrder)
self.mModel.setRelation(MIDCLI, QSqlRelation("clienti",
"id", "ragsoc"))
self.mModel.setRelation(MIDTDOC, QSqlRelation("tipofatt",
"id", "tfatt"))
self.mModel.select()
def setupMappers(self):
'''
Initialize all the application mappers
'''
self.mapper = QDataWidgetMapper(self)
self.mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit)
self.mapper.setModel(self.mModel)
self.mapper.setItemDelegate(QSqlRelationalDelegate(self))
self.mapper.addMapping(self.dateEdit, MDATA)
self.mapper.addMapping(self.fattLineEdit, MDOC)
relationModel = self.mModel.relationModel(MIDTDOC)
relationModel.setSort(1, Qt.AscendingOrder)
relationModel.select()
self.tipoFattComboBox.setModel(relationModel)
self.tipoFattComboBox.setModelColumn(relationModel.fieldIndex("tfatt"))
self.mapper.addMapping(self.tipoFattComboBox, MIDTDOC)
relationModel = self.mModel.relationModel(MIDCLI)
relationModel.setSort(CRAGSOC, Qt.AscendingOrder)
relationModel.select()
self.cliComboBox.setModel(relationModel)
self.cliComboBox.setModelColumn(relationModel.fieldIndex("ragsoc"))
self.mapper.addMapping(self.cliComboBox, MIDCLI)
self.mapper.addMapping(self.tipoPagLineEdit, MPAG)
self.mapper.addMapping(self.cauLineEdit, MCAU)
self.mapper.addMapping(self.noteLineEdit, MNOTE)
self.mapper.toFirst()
def editCustomers(self):
# call the 'clienti' table editor
subprocess.call(['python',os.path.join(os.path.dirname(__file__),
"clienti.py")])
# update all controls
self.setupModels()
self.setupMappers()
self.setupTables()
-------------------------
now, if an external application change (eg add a new record on 'clienti'
table) the 'clienti' table,
how to update the self.cliComboBox control ?
actually i'm 'rebuilding' all controls as you can see on the editCustomers
method, is this the only wahy to update the combobox control ?
thanks.
--
"Io oso fare tutto cio' che puo' essere degno di un uomo, chi osa di piu'
non lo e'"
http://blog.zamprogno.it
http://riparazioni.zamprogno.it
http://www.archlinux.it
[Attachment #5 (text/html)]
hello<br><br>i need to know how to update a combobox linked to a \
datawidgetmapper<br>when the table in relation with the mapper model is modified by \
en external application.<br><br>code:<br><br> def setupModels(self):<br>
"""<br> Initialize all the application models<br> \
"""<br> # setup masterModel<br> self.mModel = \
QSqlRelationalTableModel(self)<br> self.mModel.setTable(QString("<div>
fattmaster"))<br>
self.mModel.setSort(MDATA, Qt.AscendingOrder)<br> \
self.mModel.setRelation(MIDCLI, QSqlRelation("clienti",<br> \
"id", "ragsoc"))<br> self.mModel.setRelation(MIDTDOC, \
QSqlRelation("tipofatt",<br>
"id", "tfatt"))<br> \
self.mModel.select()<br><br clear="all"> def setupMappers(self):<br> \
'''<br> Initialize all the application mappers<br>
'''<br> self.mapper = QDataWidgetMapper(self)<br> \
self.mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit)<br> \
self.mapper.setModel(self.mModel)<br> \
self.mapper.setItemDelegate(QSqlRelationalDelegate(self))<br>
self.mapper.addMapping(self.dateEdit, MDATA)<br> \
self.mapper.addMapping(self.fattLineEdit, MDOC)<br><br> relationModel = \
self.mModel.relationModel(MIDTDOC)<br> relationModel.setSort(1, \
Qt.AscendingOrder)<br>
relationModel.select()<br> \
self.tipoFattComboBox.setModel(relationModel)<br> \
self.tipoFattComboBox.setModelColumn(relationModel.fieldIndex("tfatt"))<br> \
self.mapper.addMapping(self.tipoFattComboBox, MIDTDOC)<br>
<br> relationModel = self.mModel.relationModel(MIDCLI)<br> \
relationModel.setSort(CRAGSOC, Qt.AscendingOrder)<br> \
relationModel.select()<br> self.cliComboBox.setModel(relationModel)<br> \
self.cliComboBox.setModelColumn(relationModel.fieldIndex("ragsoc"))<br>
self.mapper.addMapping(self.cliComboBox, MIDCLI)<br><br> \
self.mapper.addMapping(self.tipoPagLineEdit, MPAG)<br> \
self.mapper.addMapping(self.cauLineEdit, MCAU)<br> \
self.mapper.addMapping(self.noteLineEdit, MNOTE)<br>
self.mapper.toFirst()<br><br> def editCustomers(self):<br> # call \
the 'clienti' table editor<br> \
subprocess.call(['python',os.path.join(os.path.dirname(__file__),<br> \
"clienti.py")])<br>
# update all controls<br> self.setupModels()<br>
self.setupMappers()<br> \
self.setupTables()<br>-------------------------<br><br>now, if an external \
application change (eg add a new record on 'clienti' table) the \
'clienti' table,<br>how to update the self.cliComboBox control ?<br>
<br>actually i'm 'rebuilding' all controls as you can see on the \
editCustomers method, is this the only wahy to update the combobox control \
?<br><br>thanks.<br><font color="#888888"><br></font></div><br clear="all">
<br>-- <br>"Io oso fare tutto cio' che puo' essere degno di un uomo, chi \
osa di piu' non lo e'"<br><a href="http://blog.zamprogno.it" \
target="_blank">http://blog.zamprogno.it</a><br><a \
href="http://riparazioni.zamprogno.it" \
target="_blank">http://riparazioni.zamprogno.it</a><br>
<a href="http://www.archlinux.it" target="_blank">http://www.archlinux.it</a><br><br>
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic