def __init__(self, gtomain, parent=None): super(GtoDockWidgetAttributeTable, self).__init__(parent) self.gtomain = gtomain self.info = gtomain.info self.debug = gtomain.debug self.iface = gtomain.iface self.layer = self.iface.activeLayer() self.canvas = self.iface.mapCanvas() self.canvas.currentLayerChanged.connect(self.reload) self.setObjectName('GtoAttributeTable') # layout self.dockWidgetContents = QWidget() self.view = QgsAttributeTableView() try: self.layout = QVBoxLayout(self) path = os.path.dirname(__file__) btn_wid = uic.loadUi( os.path.join(path, 'mActionGTOopenGtoTable.ui')) self.btnSelect = btn_wid.btnReload self.btnSelect.clicked.connect(self.reload) self.btnSelectAll = btn_wid.btnSelectAll self.btnSelectAll.clicked.connect(self.select_all) self.btnClose = btn_wid.btnClose self.btnClose.clicked.connect(lambda: self.setHidden(True)) # layout self.layout.addWidget(btn_wid) self.layout.addWidget(self.view) self.dockWidgetContents.setLayout(self.layout) self.setWidget(self.dockWidgetContents) # start self.reload() except Exception as e: self.info.err(e)
def __init__(self, mapCanvas, parent=None): super().__init__(parent) self.mapCanvas = mapCanvas self.resize(600, 400) self.tableView = QgsAttributeTableView(self) self.hl = QHBoxLayout(self) self.hl.addWidget(self.tableView)
class AttributeDialog(QDialog): def __init__(self, mapCanvas, parent=None): super().__init__(parent) self.mapCanvas = mapCanvas self.resize(600, 400) self.tableView = QgsAttributeTableView(self) self.hl = QHBoxLayout(self) self.hl.addWidget(self.tableView) def openAttributeDialog(self, layer): self.layerCache = QgsVectorLayerCache(layer, layer.featureCount()) self.tableModel = QgsAttributeTableModel(self.layerCache) self.tableModel.loadLayer() self.tableFilterModel = QgsAttributeTableFilterModel(self.mapCanvas, self.tableModel, parent=self.tableModel) self.tableFilterModel.setFilterMode(QgsAttributeTableFilterModel.ShowAll) self.tableView.setModel(self.tableFilterModel)
# coding: utf-8 from PyQt4.QtGui import QDialog, QTableView from qgis.core import QgsVectorLayerCache from qgis.gui import (QgsAttributeTableModel, QgsAttributeTableView, QgsAttributeTableFilterModel) from qgis.utils import iface new_dialog = QDialog() new_dialog.resize(800, 600) vector_layer_cache = QgsVectorLayerCache(iface.activeLayer(), 10000) attribute_table_model = QgsAttributeTableModel(vector_layer_cache) attribute_table_model.loadLayer() attribute_table_filter_model = QgsAttributeTableFilterModel( iface.mapCanvas(), attribute_table_model ) attribute_table_view = QgsAttributeTableView(new_dialog) attribute_table_view.setModel(attribute_table_filter_model) new_dialog.show() # Or display the attribute_table_model with QTableView (pure QT solution) table_view = QTableView() table_view.setModel(attribute_table_model) table_view.show()
class GtoDockWidgetAttributeTable(QDockWidget): def __init__(self, gtomain, parent=None): super(GtoDockWidgetAttributeTable, self).__init__(parent) self.gtomain = gtomain self.info = gtomain.info self.debug = gtomain.debug self.iface = gtomain.iface self.layer = self.iface.activeLayer() self.canvas = self.iface.mapCanvas() self.canvas.currentLayerChanged.connect(self.reload) self.setObjectName('GtoAttributeTable') # layout self.dockWidgetContents = QWidget() self.view = QgsAttributeTableView() try: self.layout = QVBoxLayout(self) path = os.path.dirname(__file__) btn_wid = uic.loadUi( os.path.join(path, 'mActionGTOopenGtoTable.ui')) self.btnSelect = btn_wid.btnReload self.btnSelect.clicked.connect(self.reload) self.btnSelectAll = btn_wid.btnSelectAll self.btnSelectAll.clicked.connect(self.select_all) self.btnClose = btn_wid.btnClose self.btnClose.clicked.connect(lambda: self.setHidden(True)) # layout self.layout.addWidget(btn_wid) self.layout.addWidget(self.view) self.dockWidgetContents.setLayout(self.layout) self.setWidget(self.dockWidgetContents) # start self.reload() except Exception as e: self.info.err(e) def select_all(self): try: self.layer.selectByIds( self.attribute_table_filter_model.filteredFeatures()) except Exception as e: self.info.err(e) def reload(self, *args): try: # the table self.layer = self.iface.activeLayer() self.setWindowTitle(self.iface.activeLayer().name() + ":: Ursprünglich selektierte Objekte: {0}". format(self.layer.selectedFeatureCount())) self.vector_layer_cache = QgsVectorLayerCache(self.layer, 10000) self.attribute_table_model = QgsAttributeTableModel( self.vector_layer_cache) self.attribute_table_model.loadLayer() self.attribute_table_filter_model = QgsAttributeTableFilterModel( self.canvas, self.attribute_table_model) # filter self.attribute_table_filter_model.setFilterMode( QgsAttributeTableFilterModel.ShowFilteredList) self.attribute_table_filter_model.setFilteredFeatures( self.layer.selectedFeatureIds()) self.view.setModel(self.attribute_table_filter_model) self.view.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) for f in self.layer.fields(): # if self.debug: self.info.log("editorWidgetSetup:",f.name(),f.editorWidgetSetup().type()) if f.editorWidgetSetup().type() == 'Hidden' and not self.debug: self.view.horizontalHeader().setSectionHidden( self.layer.fields().indexOf(f.name()), True) # only follow selection on the map # self.selectionManager = qgis.QgsVectorLayerSelectionManager(self.layer, self.attribute_table_filter_model) # self.view.setFeatureSelectionManager(self.selectionManager) self.layer.selectionChanged.connect(self._selectionChanged) except Exception as e: self.info.err(e) def _selectionChanged(self, *args): if self.isVisible(): self.gtomain.runcmd("mActionZoomToSelected")
# coding: utf-8 from PyQt4.QtGui import QDialog, QTableView from qgis.core import QgsVectorLayerCache from qgis.gui import (QgsAttributeTableModel, QgsAttributeTableView, QgsAttributeTableFilterModel) from qgis.utils import iface new_dialog = QDialog() new_dialog.resize(800, 600) vector_layer_cache = QgsVectorLayerCache(iface.activeLayer(), 10000) attribute_table_model = QgsAttributeTableModel(vector_layer_cache) attribute_table_model.loadLayer() attribute_table_filter_model = QgsAttributeTableFilterModel( iface.mapCanvas(), attribute_table_model) attribute_table_view = QgsAttributeTableView(new_dialog) attribute_table_view.setModel(attribute_table_filter_model) new_dialog.show() # Or display the attribute_table_model with QTableView (pure QT solution) table_view = QTableView() table_view.setModel(attribute_table_model) table_view.show()
# coding: utf-8 from PyQt4.QtGui import QTableView from qgis.core import QgsVectorLayerCache from qgis.gui import (QgsAttributeTableModel, QgsAttributeTableView, QgsAttributeTableFilterModel) from qgis.utils import iface layer = iface.activeLayer() canvas = iface.mapCanvas() vector_layer_cache = QgsVectorLayerCache(layer, 10000) attribute_table_model = QgsAttributeTableModel(vector_layer_cache) attribute_table_model.loadLayer() attribute_table_filter_model = QgsAttributeTableFilterModel( canvas, attribute_table_model) attribute_table_view = QgsAttributeTableView() attribute_table_view.setModel(attribute_table_filter_model) attribute_table_view.show() # Or display the attribute_table_model with QTableView (pure QT solution) table_view = QTableView() table_view.setModel(attribute_table_model) table_view.show()