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
_______________________________________________
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to