[Qgis-developer] Troubles with QgsAttributeTableView in a plugin

Radosław Pasiok rpasiok at gmail.com
Sun Jan 19 07:18:09 PST 2014


Hello Devs!

I would like to ask you for help with using a QgsAttributeTableView in a
plugin. I am using QGIS-master on Ubuntu 12.04 but the same applies to
QGIS-dev from OSGeo4W.

There is no problem when I use QGIS python console:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
w = QMainWindow()
cw = QWidget(w)
gridLayout = QGridLayout(cw)
w.setCentralWidget(cw)
tv = QgsAttributeTableView(cw)
gridLayout.addWidget(tv, 0, 0, 1, 1)
xs = iface.mapCanvas().currentLayer()
xsCache = QgsVectorLayerCache(xs, 10)
model = QgsAttributeTableModel(xsCache)
model.loadLayer()
filterModel = QgsAttributeTableFilterModel(iface.mapCanvas(), model)
tv.setModel(filterModel)
w.show()

When using the some code in a plugin :

class TableViewDialog(QMainWindow):
    def __init__(self, parent, iface):
        QMainWindow.__init__(self)
        self.ui = Ui_TableView()
        self.ui.setupUi(self)
        self.iface = iface
        self.ui.refreshButton.clicked.connect(self.refresh)

    def refresh(self):
        tv = self.ui.tableView
        xs = self.iface.mapCanvas().currentLayer()
        xsCache = QgsVectorLayerCache(xs, 10)
        model = QgsAttributeTableModel(xsCache)
        model.loadLayer()
        filterModel = QgsAttributeTableFilterModel(self.iface.mapCanvas(),
model)
        tv.setModel(filterModel)

I cannot get the table populated with features and QGIS crashes
occasionally when refresh() is called. The tableView object is promoted to
QgsAttributeTableView with header 'qgis.gui'.
What could make the difference between those two cases. Am I missing
something in the plugin code?

Thank you for any hint!

Radek



-- 
Używam wolnego oprogramowania:
http://www.gnu.org/philosophy/philosophy.pl.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20140119/d0338c39/attachment.html>


More information about the Qgis-developer mailing list