[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>



        &quot;&quot;&quot;<br>            Initialize all the application models<br>   \
&quot;&quot;&quot;<br>        # setup masterModel<br>        self.mModel = \
QSqlRelationalTableModel(self)<br>        self.mModel.setTable(QString(&quot;<div>


fattmaster&quot;))<br>
        self.mModel.setSort(MDATA, Qt.AscendingOrder)<br>        \
self.mModel.setRelation(MIDCLI, QSqlRelation(&quot;clienti&quot;,<br>                 \
&quot;id&quot;, &quot;ragsoc&quot;))<br>        self.mModel.setRelation(MIDTDOC, \
QSqlRelation(&quot;tipofatt&quot;,<br>



                                            &quot;id&quot;, &quot;tfatt&quot;))<br>   \
self.mModel.select()<br><br clear="all">    def setupMappers(self):<br>        \
&#39;&#39;&#39;<br>            Initialize all the application mappers<br>



        &#39;&#39;&#39;<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(&quot;tfatt&quot;))<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(&quot;ragsoc&quot;))<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 &#39;clienti&#39; table editor<br>        \
subprocess.call([&#39;python&#39;,os.path.join(os.path.dirname(__file__),<br>         \
&quot;clienti.py&quot;)])<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 &#39;clienti&#39; table) the \
&#39;clienti&#39; table,<br>how to update the self.cliComboBox control ?<br>



<br>actually i&#39;m &#39;rebuilding&#39; 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>&quot;Io oso fare tutto cio&#39; che puo&#39; essere degno di un uomo, chi \
osa di piu&#39; non lo e&#39;&quot;<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